summaryrefslogtreecommitdiff
path: root/inc/TopOpeBRepBuild_SplitFace.hxx
blob: cb7a7e0b9320151055e91fe9c5aaf288a0cd9a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
// File:	TopOpeBRepBuild_SplitFace.hxx
// Created:	Tue Sep 12 16:21:36 1995
// Author:	Jean Yves LEBEY
//		<jyl@meteox>

#ifndef _TopOpeBRepBuild_SplitFace_HeaderFile
#define _TopOpeBRepBuild_SplitFace_HeaderFile

#include <TopOpeBRepBuild_WireEdgeSet.hxx>
#include <TopOpeBRepBuild_FaceBuilder.hxx>

#ifdef DEB
Standard_EXPORT void debspf(const Standard_Integer i) {cout<<"++  debspf"<<i<<endl;}
#endif

//=======================================================================
//function : SplitFace
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_Builder::SplitFace(const TopoDS_Shape& Foriented,
					const TopAbs_State ToBuild1,
					const TopAbs_State ToBuild2)
{
#ifdef DEB
  if(TopOpeBRepBuild_GetcontextSF2()){
    SplitFace2(Foriented,ToBuild1,ToBuild2);
    return;
  }
#endif
  SplitFace1(Foriented,ToBuild1,ToBuild2);
  return;
}

//=======================================================================
//function : SplitFace1
//purpose  : tout dans le meme edge set
//=======================================================================

void TopOpeBRepBuild_Builder::SplitFace1(const TopoDS_Shape& Foriented,
					 const TopAbs_State ToBuild1,
					 const TopAbs_State ToBuild2)
{
  //                              process  connect  connect
  // operation tobuild1 tobuild2  face F   to 1     to 2
  // --------- -------- --------  -------  -------  -------
  // common    IN       IN        yes      yes      yes
  // fuse      OUT      OUT       yes      yes      yes
  // cut 1-2   OUT      IN        yes      yes      no
  // cut 2-1   IN       OUT       yes      yes      no           
  //                                                       
  Standard_Boolean tosplit = ToSplit(Foriented,ToBuild1);
  if ( ! tosplit ) return;
  
  Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
  Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
  Standard_Boolean ConnectTo1 = Standard_True;
  Standard_Boolean ConnectTo2 = Standard_False;
  
  // work on a FORWARD face <Fforward>
  TopoDS_Shape Fforward = Foriented; 
  myBuildTool.Orientation(Fforward,TopAbs_FORWARD);
  
  // build the list of faces to split : LF1, LF2
  TopTools_ListOfShape LF1,LF2;
  LF1.Append(Fforward);
  FindSameDomain(LF1,LF2);
  Standard_Integer n1 = LF1.Extent();
  Standard_Integer n2 = LF2.Extent();
  
  // SplitFace on a face having other same domained faces on the
  // other shape : do not reverse orientation of faces in FillFace
  if (!n2) RevOri1 = Standard_False;
  if (!n1) RevOri2 = Standard_False;
  
  // Create an edge set <WES> connected by vertices
  // ----------------------------------------------
  TopOpeBRepBuild_WireEdgeSet WES(Fforward,this);
  
#ifdef DEB
  Standard_Boolean tSPF=TopOpeBRepBuild_GettraceSPF();
  Standard_Integer iFace=myDataStructure->Shape(Foriented);
  if(tSPF){cout<<endl;GdumpSHASTA(Foriented,ToBuild1,"=== SplitFace ");}
  if(tSPF){GdumpSAMDOM(LF1, (char *) "1 : ");GdumpSAMDOM(LF2, (char *) "2 : ");}
  if(tSPF) debspf(iFace);
#endif
    
  TopTools_ListIteratorOfListOfShape itLF1,itLF2;

  for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
    const TopoDS_Shape& Fcur = itLF1.Value();
//                     myDataStructure->Shape(Fcur);//DEB
    FillFace(Fcur,ToBuild1,LF2,ToBuild2,WES,RevOri1);
  }
  
  for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
    const TopoDS_Shape& Fcur = itLF2.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    FillFace(Fcur,ToBuild2,LF1,ToBuild1,WES,RevOri2);
  }
  
  // Add the intersection edges to edge set WES
  // -----------------------------------------
  AddIntersectionEdges(Fforward,ToBuild1,RevOri1,WES);
   
#ifdef DEB
  Standard_Integer iF; Standard_Boolean tSPS = GtraceSPS(Fforward,iF);
  if(tSPS) WES.DumpSS();
#endif

  // Create a Face Builder FBU
  // ------------------------
  TopOpeBRepBuild_FaceBuilder FBU;
  FBU.InitFaceBuilder(WES,Fforward,Standard_False); //forceclass = False

  // Build the new faces
  // -------------------
  TopTools_ListOfShape& FaceList = ChangeMerged(Fforward,ToBuild1);
  MakeFaces(Fforward,FBU,FaceList);

  // connect new faces as faces built <ToBuild1> on LF1 faces
  // --------------------------------------------------------
  for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
    TopoDS_Shape Fcur = itLF1.Value();
    MarkSplit(Fcur,ToBuild1);
    TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild1);
    if ( ConnectTo1 ) FL = FaceList;
  }
  
  // connect new faces as faces built <ToBuild2> on LF2 faces
  // --------------------------------------------------------
  for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
    TopoDS_Shape Fcur = itLF2.Value();
    MarkSplit(Fcur,ToBuild2);
    TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild2);
    if ( ConnectTo2 ) FL = FaceList;
  }

} // SplitFace1

//=======================================================================
//function : SplitFace2
//purpose  : 
//=======================================================================

void TopOpeBRepBuild_Builder::SplitFace2(const TopoDS_Shape& Foriented,
					 const TopAbs_State ToBuild1,
					 const TopAbs_State ToBuild2)
{
  //                              process  connect  connect
  // operation tobuild1 tobuild2  face F   to 1     to 2
  // --------- -------- --------  -------  -------  -------
  // common    IN       IN        yes      yes      yes
  // fuse      OUT      OUT       yes      yes      yes
  // cut 1-2   OUT      IN        yes      yes      no
  // cut 2-1   IN       OUT       yes      yes      no           
  //                                                       
  Standard_Boolean tosplit = ToSplit(Foriented,ToBuild1);
  if ( ! tosplit ) return;
  
  Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
  Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
  Standard_Boolean ConnectTo1 = Standard_True;
  Standard_Boolean ConnectTo2 = Standard_False;

  // work on a FORWARD face <Fforward>
  TopoDS_Shape Fforward = Foriented; 
  myBuildTool.Orientation(Fforward,TopAbs_FORWARD);

  TopTools_ListOfShape LF1 ; //liste des faces de 1   samedomain
  TopTools_ListOfShape LF2 ; //liste des faces de   2 samedomain
  LF1.Append(Fforward);
  FindSameDomain(LF1,LF2);
  Standard_Integer n1 = LF1.Extent();
  Standard_Integer n2 = LF2.Extent();
  
#ifdef DEB
  Standard_Boolean tSPF = TopOpeBRepBuild_GettraceSPF();
//  Standard_Integer iFace = myDataStructure->Shape(Foriented);
  if (tSPF) {
    cout<<endl;
    GdumpSHASTA(Foriented,ToBuild1,"=== SplitFace ");
    GdumpSAMDOM(LF1, (char *) "samedomain 1 : ");
    GdumpSAMDOM(LF2, (char *) "samedomain 2 : ");
  }
#endif
  
  // SplitFace on a face having other same domained faces on the
  // other shape : do not reverse orientation of faces in FillFace
  if (!n2) RevOri1 = Standard_False;
  if (!n1) RevOri2 = Standard_False;

  TopTools_ListOfShape LFSO; //liste des faces de 1,2 samedomainsameorientation
  TopTools_ListOfShape LFOO; //liste des faces de 1,2 samedomainoppositeorient

  // LFSO : faces des shapes 1 ou 2, de meme orientation que Fforward.
  // LFOO : faces des shapes 1 ou 2, d'orientation contraire que Fforward.
  LFSO.Append(Fforward);
  FindSameDomainSameOrientation(LFSO,LFOO);

  TopTools_ListOfShape LFSO1,LFOO1; // same domain, same orientation, et du shape de F
  TopTools_ListOfShape LFSO2,LFOO2; // "" "",du shape autre que celui de F

  // on construit les parties ToBuild1 de F
  Standard_Integer rankF = ShapeRank(Foriented);
  Standard_Integer rankX = (rankF) ? ((rankF == 1) ? 2 : 1) : 0;

  FindSameRank(LFSO,rankF,LFSO1);
  FindSameRank(LFOO,rankF,LFOO1);
  FindSameRank(LFSO,rankX,LFSO2);
  FindSameRank(LFOO,rankX,LFOO2);

#ifdef DEB
  if ( tSPF ) {
    GdumpSAMDOM(LFSO1, (char *) "LFSO1 : ");
    GdumpSAMDOM(LFOO1, (char *) "LFOO1 : ");
    GdumpSAMDOM(LFSO2, (char *) "LFSO2 : ");
    GdumpSAMDOM(LFOO2, (char *) "LFOO2 : ");
  }
#endif

  TopAbs_State tob1 = ToBuild1;
  TopAbs_State tob2 = ToBuild2;
  TopAbs_State tob1comp = (ToBuild1 == TopAbs_IN) ? TopAbs_OUT : TopAbs_IN;
  TopAbs_State tob2comp = (ToBuild2 == TopAbs_IN) ? TopAbs_OUT : TopAbs_IN;
  TopTools_ListIteratorOfListOfShape itLF ;
  
  // --------------------------------------------------------------------
  // traitement des faces de meme orientation que Fforward dans WireEdgeSet WES1
  // --------------------------------------------------------------------
  TopOpeBRepBuild_WireEdgeSet WES1(Fforward,this);

  // traitement des faces de 1 same domain, same orientation que F : LFSO1
  for (itLF.Initialize(LFSO1); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 2
    FillFace(Fcur,tob1,LF2,tob2,WES1,RevOri1);
  }

  // traitement des faces de 2 same domain, same orientation que F : LFSO2
  for (itLF.Initialize(LFSO2); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 1
    FillFace(Fcur,tob2,LF1,tob1,WES1,RevOri2);
  }

  // traitement des faces de 1 same domain, oppo orientation que F : LFOO1
  for (itLF.Initialize(LFOO1); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 2
    FillFace(Fcur,tob1comp,LF2,ToBuild2,WES1,!RevOri1);
  }

  // traitement des faces de 2 same domain, oppo orientation que F : LFOO2
  for (itLF.Initialize(LFOO2); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                      myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 1
    FillFace(Fcur,tob2comp,LF1,ToBuild1,WES1,!RevOri2);
  }
  
  // Add the intersection edges to edge set WES1
  // ------------------------------------------
  AddIntersectionEdges(Fforward,ToBuild1,RevOri1,WES1);

  // Create a Face Builder FBU1
  // ------------------------
  TopOpeBRepBuild_FaceBuilder FBU1(WES1,Fforward);

  // Build the new faces
  // -------------------
  TopTools_ListOfShape& FaceList1 = ChangeMerged(Fforward,ToBuild1);
  MakeFaces(Fforward,FBU1,FaceList1);

  // connect new faces as faces built <ToBuild1> on LF1 faces
  // --------------------------------------------------------
  for (itLF.Initialize(LF1); itLF.More(); itLF.Next()) {
    TopoDS_Shape Fcur = itLF.Value();
    MarkSplit(Fcur,ToBuild1);
    TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild1);
    if ( ConnectTo1 ) FL = FaceList1;
  }

  // --------------------------------------------------------------------
  // traitement des faces de meme orientation que Fforward dans WireEdgeSet WES2
  // --------------------------------------------------------------------
  TopOpeBRepBuild_WireEdgeSet WES2(Fforward,this);

  // traitement des faces de 1 same domain, same orientation que F : LFSO1
  for (itLF.Initialize(LFSO1); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 2
    FillFace(Fcur,tob1comp,LF2,tob2,WES2,!RevOri1);
  }

  // traitement des faces de 2 same domain, same orientation que F : LFSO2
  for (itLF.Initialize(LFSO2); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 1
    FillFace(Fcur,tob2comp,LF1,tob1,WES2,!RevOri2);
  }

  // traitement des faces de 1 same domain, oppo orientation que F : LFOO1
  for (itLF.Initialize(LFOO1); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 2
    FillFace(Fcur,tob1,LF2,ToBuild2,WES2,RevOri1);
  }

  // traitement des faces de 2 same domain, oppo orientation que F : LFOO2
  for (itLF.Initialize(LFOO2); itLF.More(); itLF.Next()) {
    const TopoDS_Shape& Fcur = itLF.Value();
//                            myDataStructure->Shape(Fcur);//DEB
    // les wires de Fcur sont a comparer avec les faces de 1
    FillFace(Fcur,tob2,LF1,ToBuild1,WES2,RevOri2);
  }
  
  // Add the intersection edges to edge set WES2
  // ------------------------------------------
  AddIntersectionEdges(Fforward,ToBuild2,RevOri2,WES2);
   
  // Create a Face Builder FBU2
  // -------------------------
  TopOpeBRepBuild_FaceBuilder FBU2(WES2,Fforward);

  // Build the new faces
  // -------------------
  TopTools_ListOfShape& FaceList2 = ChangeMerged(Fforward,ToBuild2);
  MakeFaces(Fforward,FBU2,FaceList2);

  // connect new faces as faces built <ToBuild2> on LF2 faces
  // --------------------------------------------------------
  for (itLF.Initialize(LF2); itLF.More(); itLF.Next()) {
    TopoDS_Shape Fcur = itLF.Value();
    MarkSplit(Fcur,ToBuild2);
    TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild2);
    if ( ConnectTo2 ) FL = FaceList2;
  }

} // SplitFace2


#if 0
//=======================================================================
//function : SplitFaceOK
//purpose  : tout dans le meme edge set
//=======================================================================

void TopOpeBRepBuild_Builder::SplitFaceOK(const TopoDS_Shape& Foriented,
					  const TopAbs_State ToBuild1,
					  const TopAbs_State ToBuild2)
{
  //                              process  connect  connect
  // operation tobuild1 tobuild2  face F   to 1     to 2
  // --------- -------- --------  -------  -------  -------
  // common    IN       IN        yes      yes      yes
  // fuse      OUT      OUT       yes      yes      yes
  // cut 1-2   OUT      IN        yes      yes      no
  // cut 2-1   IN       OUT       yes      yes      no           
  //                                                       
  Standard_Boolean tosplit = ToSplit(Foriented,ToBuild1);
  if ( ! tosplit ) return;
  
  Standard_Boolean RevOri1 = Reverse(ToBuild1,ToBuild2);
  Standard_Boolean RevOri2 = Reverse(ToBuild2,ToBuild1);
  Standard_Boolean ConnectTo1 = Standard_True;
  Standard_Boolean ConnectTo2 = Standard_False;

  // work on a FORWARD face <Fforward>
  TopoDS_Shape Fforward = Foriented; 
  myBuildTool.Orientation(Fforward,TopAbs_FORWARD);
  
  // build the list of faces to split : LF1, LF2
  TopTools_ListOfShape LF1,LF2;
  LF1.Append(Fforward);
  FindSameDomain(LF1,LF2);
  Standard_Integer n1 = LF1.Extent();
  Standard_Integer n2 = LF2.Extent();
  
  // SplitFace on a face having other same domained faces on the
  // other shape : do not reverse orientation of faces in FillFace
  if (!n2) RevOri1 = Standard_False;
  if (!n1) RevOri2 = Standard_False;
  
  // Create an edge set <WES> connected by vertices
  // ---------------------------------------------
  TopOpeBRepBuild_WireEdgeSet WES(Fforward,this);

#ifdef DEB
  Standard_Boolean tSPF = TopOpeBRepBuild_GettraceSPF();
  Standard_Integer iFace = myDataStructure->Shape(Foriented);
  if(tSPF){cout<<endl;GdumpSHASTA(Foriented,ToBuild1,"=== SplitFaceOK ");}
  if(tSPF){GdumpSAMDOM(LF1,"1 : ");GdumpSAMDOM(LF2,"2 : ");}
#endif
    
  TopTools_ListIteratorOfListOfShape itLF1,itLF2;

  for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
    const TopoDS_Shape& Fcur = itLF1.Value();
    Standard_Integer icur = myDataStructure->Shape(Fcur);//DEB
    FillFace(Fcur,ToBuild1,LF2,ToBuild2,WES,RevOri1);
  }
  
  for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
    const TopoDS_Shape& Fcur = itLF2.Value();
    Standard_Integer icur = myDataStructure->Shape(Fcur);//DEB
    FillFace(Fcur,ToBuild2,LF1,ToBuild1,WES,RevOri2);
  }
  
  // Add the intersection edges to edge set WES
  // -----------------------------------------
  AddIntersectionEdges(Fforward,ToBuild1,RevOri1,WES);
   
  // Create a Face Builder FBU
  // ------------------------
  TopOpeBRepBuild_FaceBuilder FBU(WES,Fforward);

  // Build the new faces
  // -------------------
  TopTools_ListOfShape& FaceList = ChangeMerged(Fforward,ToBuild1);
  MakeFaces(Fforward,FBU,FaceList);

  // connect new faces as faces built <ToBuild1> on LF1 faces
  // --------------------------------------------------------
  for (itLF1.Initialize(LF1); itLF1.More(); itLF1.Next()) {
    TopoDS_Shape Fcur = itLF1.Value();
    MarkSplit(Fcur,ToBuild1);
    TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild1);
    if ( ConnectTo1 ) FL = FaceList;
  }
  
  // connect new faces as faces built <ToBuild2> on LF2 faces
  // --------------------------------------------------------
  for (itLF2.Initialize(LF2); itLF2.More(); itLF2.Next()) {
    TopoDS_Shape Fcur = itLF2.Value();
    MarkSplit(Fcur,ToBuild2);
    TopTools_ListOfShape& FL = ChangeSplit(Fcur,ToBuild2);
    if ( ConnectTo2 ) FL = FaceList;
  }

} // SplitFaceOK

// #if 0
#endif

//#ifndef _TopOpeBRepBuild_SplitFace_HeaderFile
#endif