1 // File: NMTAlgo_Splitter_2.cxx
2 // Created: Mon Feb 9 15:07:51 2004
3 // Author: Igor FEOKTISTOV
4 // <ifv@philipox.nnov.matra-dtv.fr>
7 #include <NMTAlgo_Splitter.ixx>
9 #include <TopoDS_Shape.hxx>
10 #include <TopoDS_Compound.hxx>
11 #include <TopoDS_Solid.hxx>
12 #include <TopoDS_Shell.hxx>
13 #include <TopoDS_Face.hxx>
15 #include <TopoDS_Wire.hxx>
16 #include <TopoDS_Iterator.hxx>
19 #include <TopExp_Explorer.hxx>
21 #include <TopTools_IndexedMapOfShape.hxx>
22 #include <TopTools_MapIteratorOfMapOfShape.hxx>
23 #include <TopTools_ListOfShape.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
25 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
27 #include <BOPTools_PInterferencePool.hxx>
28 #include <BOPTools_InterferencePool.hxx>
29 #include <BOPTools_CArray1OfEEInterference.hxx>
30 #include <BOPTools_EEInterference.hxx>
31 #include <BOPTools_CArray1OfESInterference.hxx>
32 #include <BOPTools_ESInterference.hxx>
34 #include <NMTDS_ShapesDataStructure.hxx>
35 #include <NMTTools_PaveFiller.hxx>
36 #include <NMTTools_DSFiller.hxx>
37 #include <NMTAlgo_Tools.hxx>
39 //=======================================================================
40 //function : KeepShapesInside
41 //purpose : remove shapes that are outside of S from result
42 //=======================================================================
43 void NMTAlgo_Splitter::KeepShapesInside (const TopoDS_Shape& S)
46 if (S.ShapeType() < TopAbs_SOLID) { // compound or compsolid
47 for (it.Initialize( S ); it.More(); it.Next())
48 KeepShapesInside( it.Value());
52 Standard_Boolean isTool = Standard_False;
53 if (!myImageShape.HasImage( S )) {
54 //isTool = CheckTool( S );
55 //if (!isTool) return;
59 // build map of internal faces
60 TopTools_IndexedMapOfShape MIF;
61 TopoDS_Shape IntFacesComp = FindFacesInside( S, Standard_False, Standard_True);
62 TopExp::MapShapes( IntFacesComp, TopAbs_FACE, MIF );
65 myBuilder.MakeCompound(C);
67 TopAbs_ShapeEnum anInternalShapeType = TopAbs_SHAPE;
70 // leave in the result only those shapes having a face in MIF
71 for (it.Initialize( myShape ); it.More(); it.Next()) {
72 const TopoDS_Shape & aResShape = it.Value();
73 TopExp_Explorer expResF( aResShape, TopAbs_FACE );
74 for (; expResF.More(); expResF.Next()) {
75 if ( MIF.Contains( expResF.Current())) {
76 myBuilder.Add( C, aResShape );
77 if (aResShape.ShapeType() < anInternalShapeType)
78 anInternalShapeType = aResShape.ShapeType();
85 // may be S was not split by internal faces then it is missing
88 (anInternalShapeType > TopAbs_SOLID || S.ShapeType() > TopAbs_SOLID))
90 TopTools_IndexedMapOfShape MSF; // map of split faces of S
91 TopExp::MapShapes( myImageShape.Image(S).First(), TopAbs_FACE, MSF);
93 // find a shape having all faces in MSF
94 for (it.Initialize( myShape ); it.More(); it.Next()) {
95 TopExp_Explorer expResF( it.Value(), TopAbs_FACE );
96 for (; expResF.More(); expResF.Next()) {
97 if (! MSF.Contains( expResF.Current()))
100 if (! expResF.More()) {
101 myBuilder.Add( C, it.Value() );
110 //=======================================================================
111 //function : RemoveShapesInside
112 //purpose : remove shapes that are inside S from result
113 //=======================================================================
114 void NMTAlgo_Splitter::RemoveShapesInside (const TopoDS_Shape& S)
117 if (S.ShapeType() < TopAbs_SOLID) { // compound or compsolid
119 for (; it.More(); it.Next()) {
120 RemoveShapesInside( it.Value());
125 Standard_Boolean isTool;
126 TopoDS_Shape IntFacesComp;
128 TopTools_IndexedMapOfShape MIF; // map of internal faces
129 TopTools_MapOfShape RFM;
130 TopTools_MapIteratorOfMapOfShape itF;
132 isTool=myToolShapes.Contains(S);
133 //isTool = Standard_False;
134 if (!myImageShape.HasImage( S )) {
138 IntFacesComp = FindFacesInside( S, Standard_False, Standard_True);
140 TopExp::MapShapes( IntFacesComp, TopAbs_FACE, MIF);
144 // add to MIF split faces of S
145 const TopoDS_Shape& aSIm=myImageShape.Image(S).First();
146 TopExp::MapShapes(aSIm, TopAbs_FACE, MIF);
148 // leave in the result only those shapes not having all face in MIF
149 myBuilder.MakeCompound(C);
151 // RFM : faces of removed shapes that encounter once
152 it.Initialize(myShape);
153 for (; it.More(); it.Next()) {
154 TopExp_Explorer expResF;
156 const TopoDS_Shape& aSR=it.Value();
158 expResF.Init(aSR, TopAbs_FACE);
159 for (; expResF.More(); expResF.Next()) {
160 const TopoDS_Shape& aFR=expResF.Current();
161 if (!MIF.Contains(aFR)) {
166 if (expResF.More()) {
167 // add shape to result
168 myBuilder.Add(C, aSR);
171 // add faces of a removed shape to RFM
172 for (expResF.ReInit(); expResF.More(); expResF.Next()) {
173 const TopoDS_Shape& aF = expResF.Current();
174 if (!RFM.Remove(aF)) {
179 }// for (; it.More(); it.Next())
184 myBuilder.MakeCompound(aCx);
185 itF.Initialize (RFM);
186 for (; itF.More(); itF.Next()) {
187 const TopoDS_Shape& aF=itF.Key();
188 myBuilder.Add(aCx, aF);
192 // rebuild S, it must remain in the result
193 Standard_Boolean isClosed = Standard_False;
194 switch (S.ShapeType()) {
196 isClosed = Standard_True; break;
198 TopTools_IndexedDataMapOfShapeListOfShape MEF;
199 TopExp::MapShapesAndAncestors(S, TopAbs_EDGE, TopAbs_FACE, MEF);
201 for (i=1; isClosed && i<=MEF.Extent(); ++i) {
202 isClosed = ( MEF(i).Extent() != 1 );
207 isClosed = Standard_False;
211 // add to a new shape external faces of removed shapes, ie those in RFM
213 myBuilder.MakeShell(Shell);
214 // exclude redundant internal face with edges encounterd only once
215 TopTools_IndexedDataMapOfShapeListOfShape MEF;
217 itF.Initialize (RFM);
218 for ( ; itF.More(); itF.Next()) {
219 const TopoDS_Shape& aF=itF.Key();
220 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, MEF);
222 // add only faces forming a closed shell
223 for (itF.Reset() ; itF.More(); itF.Next()) {
224 const TopoDS_Shape& aF=itF.Key();
225 TopExp_Explorer expE (aF, TopAbs_EDGE);
226 for (; expE.More(); expE.Next()) {
227 if (MEF.FindFromKey(expE.Current()).Extent() == 1) {
232 myBuilder.Add( Shell, aF);
239 if (S.ShapeType() == TopAbs_SOLID) {
241 myBuilder.MakeSolid( Solid );
242 myBuilder.Add (Solid, Shell);
243 myBuilder.Add (C, Solid);
246 myBuilder.Add (C, Shell);
251 for (; it.More(); it.Next()) {
252 myBuilder.Add (C, it.Value());
260 //modified by NIZNHY-PKV Tue Feb 1 16:02:29 2005 f
261 //=======================================================================
262 //function : Modified
264 //=======================================================================
265 const TopTools_ListOfShape& NMTAlgo_Splitter::Modified (const TopoDS_Shape& S)
268 TopAbs_ShapeEnum aType;
279 FindImage(S, myGenerated);
294 //modified by NIZNHY-PKV Tue Feb 1 16:02:33 2005 t
295 //=======================================================================
296 //function : IsDeleted
298 //=======================================================================
299 Standard_Boolean NMTAlgo_Splitter::IsDeleted (const TopoDS_Shape& S)
302 const TopTools_ListOfShape& aL = Modified(S);
303 if(aL.Extent() != 0) return Standard_False;
305 TopTools_MapOfShape aMap;
306 TopExp_Explorer anExp;
308 TopAbs_ShapeEnum aType = S.ShapeType();
310 if(aType == TopAbs_VERTEX ||
311 aType == TopAbs_EDGE ||
312 aType == TopAbs_FACE ) {
314 anExp.Init(myShape, aType);
315 for(; anExp.More(); anExp.Next()) {
316 if(S.IsSame(anExp.Current())) return Standard_False;
321 return Standard_True;
323 //=======================================================================
324 //function : Generated
326 //=======================================================================
327 const TopTools_ListOfShape& NMTAlgo_Splitter::Generated(const TopoDS_Shape& S)
330 TopTools_ListIteratorOfListOfShape it;
331 TopTools_MapOfShape aMap;
332 TopExp_Explorer anExp;
333 Standard_Boolean bCheckVert = Standard_False;
335 if(S.ShapeType() == TopAbs_FACE) {
336 if (mySectionParts.Contains(S)) {
337 it.Initialize(mySectionParts.FindFromKey(S));
338 anExp.Init(myShape, TopAbs_EDGE);
340 for(; anExp.More(); anExp.Next()) {
341 aMap.Add(anExp.Current());
344 for (; it.More(); it.Next()) {
345 if(aMap.Contains(it.Value())) {
346 myGenerated.Append(it.Value());
351 NMTTools_PaveFiller& aPF = myDSFiller->ChangePaveFiller();
352 const NMTDS_ShapesDataStructure& aDS = myDSFiller->DS();
353 const BOPTools_PInterferencePool& anIP = aPF.InterfPool();
355 Standard_Integer aNbS = aDS.NumberOfSourceShapes();
356 Standard_Integer anIndex = 0, i;
358 for(i = 1; i <= aNbS; ++i) {
360 const TopoDS_Shape& aS = aDS.Shape(i);
368 if(anIndex == 0) return myGenerated;
369 if(!anIP->HasInterference(anIndex)) return myGenerated;
371 const BOPTools_CArray1OfESInterference& aESs = anIP->ESInterferences();
372 Standard_Integer aNbI = aESs.Extent();
374 if(aNbI == 0) return myGenerated;
376 for(i = 1; i <= aNbI; ++i) {
378 const BOPTools_ESInterference& aES = aESs(i);
379 Standard_Integer ind1, ind2;
380 aES.Indices(ind1, ind2);
382 if(ind1 == anIndex || ind2 == anIndex) {
384 Standard_Integer aNSI = aES.NewShape();
385 if(aDS.GetShapeType(aNSI) == TopAbs_VERTEX) {
386 myGenerated.Append(aDS.Shape(aNSI));
387 bCheckVert = Standard_True;
396 anExp.Init(myShape, TopAbs_VERTEX);
398 for(; anExp.More(); anExp.Next()) {
399 aMap.Add(anExp.Current());
402 it.Initialize(myGenerated);
403 for (; it.More(); it.Next()) {
405 if(it.Value().ShapeType() != TopAbs_VERTEX) continue;
407 if(!aMap.Contains(it.Value())) {
408 myGenerated.Remove(it);
417 if(S.ShapeType() == TopAbs_EDGE) {
419 NMTTools_PaveFiller& aPF = myDSFiller->ChangePaveFiller();
420 const NMTDS_ShapesDataStructure& aDS = myDSFiller->DS();
421 const BOPTools_PInterferencePool& anIP = aPF.InterfPool();
423 Standard_Integer aNbS = aDS.NumberOfSourceShapes();
424 Standard_Integer anIndex = 0, i;
426 for(i = 1; i <= aNbS; ++i) {
428 const TopoDS_Shape& aS = aDS.Shape(i);
436 if(anIndex == 0) return myGenerated;
437 if(!anIP->HasInterference(anIndex)) return myGenerated;
439 const BOPTools_CArray1OfEEInterference& aEEs = anIP->EEInterferences();
440 Standard_Integer aNbI = aEEs.Extent();
442 for(i = 1; i <= aNbI; ++i) {
444 const BOPTools_EEInterference& aEE = aEEs(i);
445 Standard_Integer ind1, ind2;
446 aEE.Indices(ind1, ind2);
448 if(ind1 == anIndex || ind2 == anIndex) {
450 Standard_Integer aNSI = aEE.NewShape();
451 if(aDS.GetShapeType(aNSI) == TopAbs_VERTEX) {
452 myGenerated.Append(aDS.Shape(aNSI));
453 bCheckVert = Standard_True;
460 const BOPTools_CArray1OfESInterference& aESs = anIP->ESInterferences();
461 aNbI = aESs.Extent();
463 for(i = 1; i <= aNbI; ++i) {
465 const BOPTools_ESInterference& aES = aESs(i);
466 Standard_Integer ind1, ind2;
467 aES.Indices(ind1, ind2);
469 if(ind1 == anIndex || ind2 == anIndex) {
471 Standard_Integer aNSI = aES.NewShape();
472 if(aDS.GetShapeType(aNSI) == TopAbs_VERTEX) {
473 myGenerated.Append(aDS.Shape(aNSI));
474 bCheckVert = Standard_True;
483 anExp.Init(myShape, TopAbs_VERTEX);
485 for(; anExp.More(); anExp.Next()) {
486 aMap.Add(anExp.Current());
489 it.Initialize(myGenerated);
490 for (; it.More(); it.Next()) {
492 if(!aMap.Contains(it.Value())) {
493 myGenerated.Remove(it);
501 //modified by NIZNHY-PKV Tue Feb 1 10:26:18 2005f
502 //=======================================================================
503 //function : FindImage
505 //=======================================================================
506 void NMTAlgo_Splitter::FindImage(const TopoDS_Shape& aS,
507 TopTools_ListOfShape& aLIms)
509 TopAbs_ShapeEnum aType;
511 aType=aS.ShapeType();
513 if (aType==TopAbs_SOLID) {
514 Standard_Boolean bHasImage, bHasInternalFaces;
515 Standard_Integer i, aNbSd;
516 TopTools_IndexedMapOfShape aMSo, aMSd;
518 TopTools_IndexedDataMapOfShapeListOfShape aMFS;
519 TopTools_ListIteratorOfListOfShape aItLS;
521 bHasInternalFaces=myMapSIFC.IsBound(aS);
522 if (bHasInternalFaces){
523 TopExp::MapShapesAndAncestors(myShape, TopAbs_FACE, TopAbs_SOLID, aMFS);
525 const TopoDS_Shape& aIFC=myMapSIFC.Find(aS);
527 aIt.Initialize(aIFC);
528 for (; aIt.More(); aIt.Next()) {
529 const TopoDS_Shape& aIF=aIt.Value();
530 if (aMFS.Contains(aIF)) {
531 const TopTools_ListOfShape& aLS=aMFS.FindFromKey(aIF);
533 aItLS.Initialize(aLS);
534 for (; aItLS.More(); aItLS.Next()) {
535 const TopoDS_Shape& aSx=aItLS.Value();
543 for (i=1; i<=aNbSd; ++i) {
544 const TopoDS_Shape& aSx=aMSd(i);
545 if (!aSx.IsSame(aS)) {
553 bHasImage=myImageShape.HasImage(aS);
560 TopExp::MapShapes(myShape, TopAbs_SOLID, aMSo);
562 const TopoDS_Shape& aFC=myImageShape.Image(aS).First();
563 bHasImage=NMTAlgo_Tools::FindImageSolid(aFC, aMSo, aSd);
565 if (!aSd.IsSame(aS)) {
569 } //if (aType==TopAbs_SOLID) {
571 else if (aType==TopAbs_FACE) {
572 TopTools_MapOfShape aMap;
573 TopTools_ListIteratorOfListOfShape aIt;
574 TopExp_Explorer anExp;
576 if (myModifiedFaces.IsBound(aS)) {
577 anExp.Init(myShape, aType);
578 for(; anExp.More(); anExp.Next()) {
579 aMap.Add(anExp.Current());
582 const TopTools_ListOfShape& aLS=myModifiedFaces.Find(aS);
584 for (; aIt.More(); aIt.Next()) {
585 const TopoDS_Shape& aFx=aIt.Value();
586 if (!aFx.IsSame(aS)) {
587 if (aMap.Contains(aFx)) {
593 } // else if (aType==TopAbs_FACE)
595 else if (aType==TopAbs_EDGE) {
596 TopTools_MapOfShape aMap;
597 TopTools_ListIteratorOfListOfShape aIt;
598 TopExp_Explorer anExp;
600 if (myImagesEdges.HasImage(aS)) {
601 anExp.Init(myShape, aType);
602 for(; anExp.More(); anExp.Next()) {
603 aMap.Add(anExp.Current());
606 const TopTools_ListOfShape& aLE=myImagesEdges.Image(aS);
608 for (; aIt.More(); aIt.Next()) {
609 const TopoDS_Shape& aEx=aIt.Value();
610 if (!aEx.IsSame(aS)) {
611 if(aMap.Contains(aEx)) {
617 }// else if (aType==TopAbs_EDGE)
619 else if (aType==TopAbs_VERTEX) {
620 Standard_Integer aNbS, anIndex, i, aSDVInd;
621 TopExp_Explorer anExp;
623 const NMTTools_DSFiller& aDSF = Filler();
624 const NMTTools_PaveFiller& aPF = aDSF.PaveFiller();
625 const NMTDS_ShapesDataStructure& aDS = aDSF.DS();
627 aNbS = aDS.NumberOfSourceShapes();
630 for(i=1; i<=aNbS; ++i) {
631 const TopoDS_Shape& aSx = aDS.Shape(i);
642 aSDVInd=aPF.FindSDVertex(anIndex);
647 const TopoDS_Shape& aSDV=aDS.Shape(aSDVInd);
649 anExp.Init(myShape, aType);
650 for(; anExp.More(); anExp.Next()) {
651 const TopoDS_Shape& aVx=anExp.Current();
652 if(aSDV.IsSame(aVx)) {
657 }// else if (aType==TopAbs_VERTEX)
659 //modified by NIZNHY-PKV Tue Feb 1 10:26:22 2005t