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>
8 #include <TopoDS_Iterator.hxx>
9 #include <TopTools_IndexedMapOfShape.hxx>
10 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Compound.hxx>
13 #include <TopExp_Explorer.hxx>
14 #include <TopoDS_Solid.hxx>
15 #include <TopoDS_Shell.hxx>
16 #include <TopTools_MapIteratorOfMapOfShape.hxx>
17 #include <TopoDS_Face.hxx>
19 #include <TopoDS_Wire.hxx>
20 #include <TopTools_ListOfShape.hxx>
21 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <NMTTools_DSFiller.hxx>
23 #include <NMTDS_ShapesDataStructure.hxx>
24 #include <NMTTools_PaveFiller.hxx>
25 #include <BOPTools_PInterferencePool.hxx>
26 #include <BOPTools_InterferencePool.hxx>
27 #include <BOPTools_CArray1OfEEInterference.hxx>
28 #include <BOPTools_EEInterference.hxx>
29 #include <BOPTools_CArray1OfESInterference.hxx>
30 #include <BOPTools_ESInterference.hxx>
32 //=======================================================================
33 //function : KeepShapesInside
34 //purpose : remove shapes that are outside of S from result
35 //=======================================================================
36 void NMTAlgo_Splitter::KeepShapesInside (const TopoDS_Shape& S)
39 if (S.ShapeType() < TopAbs_SOLID) { // compound or compsolid
40 for (it.Initialize( S ); it.More(); it.Next())
41 KeepShapesInside( it.Value());
45 Standard_Boolean isTool = Standard_False;
46 if (!myImageShape.HasImage( S )) {
47 //isTool = CheckTool( S );
48 //if (!isTool) return;
52 // build map of internal faces
53 TopTools_IndexedMapOfShape MIF;
54 TopoDS_Shape IntFacesComp = FindFacesInside( S, Standard_False, Standard_True);
55 TopExp::MapShapes( IntFacesComp, TopAbs_FACE, MIF );
58 myBuilder.MakeCompound(C);
60 TopAbs_ShapeEnum anInternalShapeType = TopAbs_SHAPE;
63 // leave in the result only those shapes having a face in MIF
64 for (it.Initialize( myShape ); it.More(); it.Next()) {
65 const TopoDS_Shape & aResShape = it.Value();
66 TopExp_Explorer expResF( aResShape, TopAbs_FACE );
67 for (; expResF.More(); expResF.Next()) {
68 if ( MIF.Contains( expResF.Current())) {
69 myBuilder.Add( C, aResShape );
70 if (aResShape.ShapeType() < anInternalShapeType)
71 anInternalShapeType = aResShape.ShapeType();
78 // may be S was not split by internal faces then it is missing
81 (anInternalShapeType > TopAbs_SOLID || S.ShapeType() > TopAbs_SOLID))
83 TopTools_IndexedMapOfShape MSF; // map of split faces of S
84 TopExp::MapShapes( myImageShape.Image(S).First(), TopAbs_FACE, MSF);
86 // find a shape having all faces in MSF
87 for (it.Initialize( myShape ); it.More(); it.Next()) {
88 TopExp_Explorer expResF( it.Value(), TopAbs_FACE );
89 for (; expResF.More(); expResF.Next()) {
90 if (! MSF.Contains( expResF.Current()))
93 if (! expResF.More()) {
94 myBuilder.Add( C, it.Value() );
103 //=======================================================================
104 //function : RemoveShapesInside
105 //purpose : remove shapes that are inside S from result
106 //=======================================================================
107 void NMTAlgo_Splitter::RemoveShapesInside (const TopoDS_Shape& S)
110 if (S.ShapeType() < TopAbs_SOLID) { // compound or compsolid
112 for (; it.More(); it.Next()) {
113 RemoveShapesInside( it.Value());
118 Standard_Boolean isTool;
119 TopoDS_Shape IntFacesComp;
121 TopTools_IndexedMapOfShape MIF; // map of internal faces
122 TopTools_MapOfShape RFM;
123 TopTools_MapIteratorOfMapOfShape itF;
125 //modified by NIZNHY-PKV Wed Dec 22 18:56:27 2004 f
126 isTool=myToolShapes.Contains(S);
127 //modified by NIZNHY-PKV Wed Dec 22 18:56:31 2004 t
129 //isTool = Standard_False;
130 if (!myImageShape.HasImage( S )) {
134 IntFacesComp = FindFacesInside( S, Standard_False, Standard_True);
136 TopExp::MapShapes( IntFacesComp, TopAbs_FACE, MIF);
140 // add to MIF split faces of S
141 const TopoDS_Shape& aSIm=myImageShape.Image(S).First();
142 TopExp::MapShapes(aSIm, TopAbs_FACE, MIF);
144 // leave in the result only those shapes not having all face in MIF
145 myBuilder.MakeCompound(C);
147 // RFM : faces of removed shapes that encounter once
148 it.Initialize(myShape);
149 for (; it.More(); it.Next()) {
150 TopExp_Explorer expResF;
152 const TopoDS_Shape& aSR=it.Value();
154 expResF.Init(aSR, TopAbs_FACE);
155 for (; expResF.More(); expResF.Next()) {
156 const TopoDS_Shape& aFR=expResF.Current();
157 if (!MIF.Contains(aFR)) {
162 if (expResF.More()) {
163 // add shape to result
164 myBuilder.Add(C, aSR);
167 // add faces of a removed shape to RFM
168 for (expResF.ReInit(); expResF.More(); expResF.Next()) {
169 const TopoDS_Shape& aF = expResF.Current();
170 if (!RFM.Remove(aF)) {
175 }// for (; it.More(); it.Next())
177 //modified by NIZNHY-PKV Wed Dec 22 18:59:46 2004 f
180 myBuilder.MakeCompound(aCx);
181 itF.Initialize (RFM);
182 for (; itF.More(); itF.Next()) {
183 const TopoDS_Shape& aF=itF.Key();
184 myBuilder.Add(aCx, aF);
186 //modified by NIZNHY-PKV Wed Dec 22 18:59:48 2004 t
189 // rebuild S, it must remain in the result
190 Standard_Boolean isClosed = Standard_False;
191 switch (S.ShapeType()) {
193 isClosed = Standard_True; break;
195 TopTools_IndexedDataMapOfShapeListOfShape MEF;
196 TopExp::MapShapesAndAncestors(S, TopAbs_EDGE, TopAbs_FACE, MEF);
198 for (i=1; isClosed && i<=MEF.Extent(); ++i) {
199 isClosed = ( MEF(i).Extent() != 1 );
204 isClosed = Standard_False;
208 // add to a new shape external faces of removed shapes, ie those in RFM
210 myBuilder.MakeShell(Shell);
211 // exclude redundant internal face with edges encounterd only once
212 TopTools_IndexedDataMapOfShapeListOfShape MEF;
214 itF.Initialize (RFM);
215 for ( ; itF.More(); itF.Next()) {
216 const TopoDS_Shape& aF=itF.Key();
217 TopExp::MapShapesAndAncestors(aF, TopAbs_EDGE, TopAbs_FACE, MEF);
219 // add only faces forming a closed shell
220 for (itF.Reset() ; itF.More(); itF.Next()) {
221 const TopoDS_Shape& aF=itF.Key();
222 TopExp_Explorer expE (aF, TopAbs_EDGE);
223 for (; expE.More(); expE.Next()) {
224 if (MEF.FindFromKey(expE.Current()).Extent() == 1) {
229 myBuilder.Add( Shell, aF);
236 if (S.ShapeType() == TopAbs_SOLID) {
238 myBuilder.MakeSolid( Solid );
239 myBuilder.Add (Solid, Shell);
240 myBuilder.Add (C, Solid);
243 myBuilder.Add (C, Shell);
248 for (; it.More(); it.Next()) {
249 myBuilder.Add (C, it.Value());
256 //modified by NIZNHY-PKV Mon Jan 24 10:19:30 2005 f
257 //=======================================================================
258 //function : Modified
260 //=======================================================================
261 const TopTools_ListOfShape& NMTAlgo_Splitter::Modified (const TopoDS_Shape& S)
264 TopAbs_ShapeEnum aType;
265 TopTools_ListIteratorOfListOfShape it;
266 TopTools_MapOfShape aMap;
267 TopExp_Explorer anExp;
274 if (myModifiedFaces.IsBound(S)) {
275 anExp.Init(myShape, aType);
276 for(; anExp.More(); anExp.Next()) {
277 aMap.Add(anExp.Current());
280 const TopTools_ListOfShape& aLS=myModifiedFaces.Find(S);
282 for (; it.More(); it.Next()) {
283 const TopoDS_Shape& aFx=it.Value();
284 if (!aFx.IsSame(S)) {
285 if (aMap.Contains(aFx)) {
286 myGenerated.Append(aFx);
295 if (myImagesEdges.HasImage(S)) {
296 anExp.Init(myShape, aType);
297 for(; anExp.More(); anExp.Next()) {
298 aMap.Add(anExp.Current());
301 const TopTools_ListOfShape& aLE=myImagesEdges.Image(S);
303 for (; it.More(); it.Next()) {
304 const TopoDS_Shape& aEx=it.Value();
305 if (!aEx.IsSame(S)) {
306 if(aMap.Contains(aEx)) {
307 myGenerated.Append(aEx);
315 case TopAbs_VERTEX: {
316 Standard_Integer aNbS, anIndex, i, aSDVInd;
318 const NMTTools_DSFiller& aDSF = Filler();
319 const NMTTools_PaveFiller& aPF = aDSF.PaveFiller();
320 const NMTDS_ShapesDataStructure& aDS = aDSF.DS();
322 aNbS = aDS.NumberOfSourceShapes();
325 for(i=1; i<=aNbS; ++i) {
326 const TopoDS_Shape& aS = aDS.Shape(i);
334 break;//return myGenerated;
337 aSDVInd=aPF.FindSDVertex(anIndex);
339 break;//return myGenerated;
342 const TopoDS_Shape& aSDV=aDS.Shape(aSDVInd);
344 anExp.Init(myShape, aType);
345 for(; anExp.More(); anExp.Next()) {
346 const TopoDS_Shape& aVx=anExp.Current();
347 if(aSDV.IsSame(aVx)) {
348 myGenerated.Append(aSDV);
357 } // switch (aType) {
361 //modified by NIZNHY-PKV Mon Jan 24 10:28:40 2005 t
362 //=======================================================================
363 //function : Generated
365 //=======================================================================
366 const TopTools_ListOfShape& NMTAlgo_Splitter::Generated(const TopoDS_Shape& S)
369 TopTools_ListIteratorOfListOfShape it;
370 TopTools_MapOfShape aMap;
371 TopExp_Explorer anExp;
372 Standard_Boolean bCheckVert = Standard_False;
374 if(S.ShapeType() == TopAbs_FACE) {
375 if (mySectionParts.Contains(S)) {
376 it.Initialize(mySectionParts.FindFromKey(S));
377 anExp.Init(myShape, TopAbs_EDGE);
379 for(; anExp.More(); anExp.Next()) {
380 aMap.Add(anExp.Current());
383 for (; it.More(); it.Next()) {
384 if(aMap.Contains(it.Value())) {
385 myGenerated.Append(it.Value());
390 NMTTools_PaveFiller& aPF = myDSFiller->ChangePaveFiller();
391 const NMTDS_ShapesDataStructure& aDS = myDSFiller->DS();
392 const BOPTools_PInterferencePool& anIP = aPF.InterfPool();
394 Standard_Integer aNbS = aDS.NumberOfSourceShapes();
395 Standard_Integer anIndex = 0, i;
397 for(i = 1; i <= aNbS; ++i) {
399 const TopoDS_Shape& aS = aDS.Shape(i);
407 if(anIndex == 0) return myGenerated;
408 if(!anIP->HasInterference(anIndex)) return myGenerated;
410 const BOPTools_CArray1OfESInterference& aESs = anIP->ESInterferences();
411 Standard_Integer aNbI = aESs.Extent();
413 if(aNbI == 0) return myGenerated;
415 for(i = 1; i <= aNbI; ++i) {
417 const BOPTools_ESInterference& aES = aESs(i);
418 Standard_Integer ind1, ind2;
419 aES.Indices(ind1, ind2);
421 if(ind1 == anIndex || ind2 == anIndex) {
423 Standard_Integer aNSI = aES.NewShape();
424 if(aDS.GetShapeType(aNSI) == TopAbs_VERTEX) {
425 myGenerated.Append(aDS.Shape(aNSI));
426 bCheckVert = Standard_True;
435 anExp.Init(myShape, TopAbs_VERTEX);
437 for(; anExp.More(); anExp.Next()) {
438 aMap.Add(anExp.Current());
441 it.Initialize(myGenerated);
442 for (; it.More(); it.Next()) {
444 if(it.Value().ShapeType() != TopAbs_VERTEX) continue;
446 if(!aMap.Contains(it.Value())) {
447 myGenerated.Remove(it);
456 if(S.ShapeType() == TopAbs_EDGE) {
458 NMTTools_PaveFiller& aPF = myDSFiller->ChangePaveFiller();
459 const NMTDS_ShapesDataStructure& aDS = myDSFiller->DS();
460 const BOPTools_PInterferencePool& anIP = aPF.InterfPool();
462 Standard_Integer aNbS = aDS.NumberOfSourceShapes();
463 Standard_Integer anIndex = 0, i;
465 for(i = 1; i <= aNbS; ++i) {
467 const TopoDS_Shape& aS = aDS.Shape(i);
475 if(anIndex == 0) return myGenerated;
476 if(!anIP->HasInterference(anIndex)) return myGenerated;
478 const BOPTools_CArray1OfEEInterference& aEEs = anIP->EEInterferences();
479 Standard_Integer aNbI = aEEs.Extent();
481 for(i = 1; i <= aNbI; ++i) {
483 const BOPTools_EEInterference& aEE = aEEs(i);
484 Standard_Integer ind1, ind2;
485 aEE.Indices(ind1, ind2);
487 if(ind1 == anIndex || ind2 == anIndex) {
489 Standard_Integer aNSI = aEE.NewShape();
490 if(aDS.GetShapeType(aNSI) == TopAbs_VERTEX) {
491 myGenerated.Append(aDS.Shape(aNSI));
492 bCheckVert = Standard_True;
499 const BOPTools_CArray1OfESInterference& aESs = anIP->ESInterferences();
500 aNbI = aESs.Extent();
502 for(i = 1; i <= aNbI; ++i) {
504 const BOPTools_ESInterference& aES = aESs(i);
505 Standard_Integer ind1, ind2;
506 aES.Indices(ind1, ind2);
508 if(ind1 == anIndex || ind2 == anIndex) {
510 Standard_Integer aNSI = aES.NewShape();
511 if(aDS.GetShapeType(aNSI) == TopAbs_VERTEX) {
512 myGenerated.Append(aDS.Shape(aNSI));
513 bCheckVert = Standard_True;
522 anExp.Init(myShape, TopAbs_VERTEX);
524 for(; anExp.More(); anExp.Next()) {
525 aMap.Add(anExp.Current());
528 it.Initialize(myGenerated);
529 for (; it.More(); it.Next()) {
531 if(!aMap.Contains(it.Value())) {
532 myGenerated.Remove(it);
545 //=======================================================================
546 //function : IsDeleted
548 //=======================================================================
549 Standard_Boolean NMTAlgo_Splitter::IsDeleted (const TopoDS_Shape& S)
552 const TopTools_ListOfShape& aL = Modified(S);
553 if(aL.Extent() != 0) return Standard_False;
555 TopTools_MapOfShape aMap;
556 TopExp_Explorer anExp;
558 TopAbs_ShapeEnum aType = S.ShapeType();
560 if(aType == TopAbs_VERTEX ||
561 aType == TopAbs_EDGE ||
562 aType == TopAbs_FACE ) {
564 anExp.Init(myShape, aType);
565 for(; anExp.More(); anExp.Next()) {
566 if(S.IsSame(anExp.Current())) return Standard_False;
571 return Standard_True;