1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File: GEOMAlgo_Builder_2.cxx
23 // Author: Peter KURNEV
25 #include <GEOMAlgo_Builder.hxx>
27 #include <TColStd_IndexedMapOfInteger.hxx>
28 #include <TColStd_ListOfInteger.hxx>
30 #include <TopAbs_Orientation.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Compound.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TopExp_Explorer.hxx>
46 #include <BRep_Tool.hxx>
47 #include <BRep_Builder.hxx>
48 #include <BRepAlgo_Image.hxx>
49 #include <BRepTools.hxx>
51 #include <IntTools_Context.hxx>
52 #include <IntTools_FClass2d.hxx>
54 #include <BooleanOperations_OnceExplorer.hxx>
55 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
56 #include <BOPTools_ListOfPaveBlock.hxx>
57 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
58 #include <BOPTools_CArray1OfSSInterference.hxx>
59 #include <BOPTools_SSInterference.hxx>
60 #include <BOPTools_SequenceOfCurves.hxx>
61 #include <BOPTools_Curve.hxx>
62 #include <BOPTools_ListOfPaveBlock.hxx>
63 #include <BOPTools_PaveBlock.hxx>
64 #include <BOPTools_Tools3D.hxx>
65 #include <BOPTools_CArray1OfVSInterference.hxx>
66 #include <BOPTools_VSInterference.hxx>
67 #include <BOPTools_ESInterference.hxx>
68 #include <BOPTools_CArray1OfESInterference.hxx>
70 #include <NMTDS_ShapesDataStructure.hxx>
71 #include <NMTDS_InterfPool.hxx>
73 #include <NMTTools_PaveFiller.hxx>
74 #include <NMTTools_ListOfCoupleOfShape.hxx>
75 #include <NMTTools_Tools.hxx>
76 #include <NMTTools_CoupleOfShape.hxx>
77 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
78 #include <NMTTools_Tools.hxx>
79 #include <NMTTools_ListIteratorOfListOfCommonBlock.hxx>
80 #include <NMTTools_ListOfCommonBlock.hxx>
81 #include <NMTTools_CommonBlock.hxx>
82 #include <NMTTools_IndexedDataMapOfIndexedMapOfInteger.hxx>
84 #include <GEOMAlgo_Tools3D.hxx>
85 #include <GEOMAlgo_WireEdgeSet.hxx>
86 #include <GEOMAlgo_BuilderFace.hxx>
88 #include <GEOMAlgo_ShapeSet.hxx>
90 #include <NMTDS_BoxBndTree.hxx>
91 #include <NCollection_UBTreeFiller.hxx>
92 #include <Bnd_Box.hxx>
93 #include <BRepBndLib.hxx>
94 #include <TopTools_DataMapOfIntegerShape.hxx>
95 #include <TColStd_ListOfInteger.hxx>
96 #include <TColStd_ListIteratorOfListOfInteger.hxx>
97 #include <TopTools_DataMapOfShapeInteger.hxx>
100 void UpdateCandidates(const Standard_Integer ,
101 const Standard_Integer ,
102 NMTTools_IndexedDataMapOfIndexedMapOfInteger& );
105 Standard_Boolean IsClosed(const TopoDS_Edge& ,
109 //=======================================================================
110 //function : FillImagesFaces
112 //=======================================================================
113 void GEOMAlgo_Builder::FillImagesFaces()
119 FillSameDomainFaces();
121 FillInternalVertices();
124 //=======================================================================
125 // function: FillIn2DParts
127 //=======================================================================
128 void GEOMAlgo_Builder::FillIn2DParts()
130 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
131 NMTTools_PaveFiller* pPF=myPaveFiller;
132 NMTDS_InterfPool* pIP=pPF->IP();
133 BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
134 NMTTools_CommonBlockPool& aCBP=pPF->ChangeCommonBlockPool();
136 Standard_Integer j, nSpIn, nSpSc, aNbCurves;
137 Standard_Integer aNbS, nF, aNbCBP, n1, n2, aNbFFs, aNbSpIn;
138 TopTools_MapOfShape aMFence;
139 TopTools_ListOfShape aLSpIn;
141 NMTTools_ListIteratorOfListOfCommonBlock aItCB;
142 BOPTools_ListIteratorOfListOfPaveBlock aItPB;
146 aNbFFs=aFFs.Extent();
147 aNbCBP=aCBP.Extent();
149 aNbS=aDS.NumberOfShapesOfTheObject();
150 for (nF=1; nF<=aNbS; ++nF) {
151 if (aDS.GetShapeType(nF)!=TopAbs_FACE) {
155 aF=TopoDS::Face(aDS.Shape(nF));
161 BOPTools_ListOfPaveBlock aLPBIn;
163 pPF->RealSplitsInFace(nF, aLPBIn);
165 aItPB.Initialize(aLPBIn);
166 for (; aItPB.More(); aItPB.Next()) {
167 const BOPTools_PaveBlock& aPB1=aItPB.Value();
169 const TopoDS_Shape& aSpIn=aDS.Shape(nSpIn);
170 aLSpIn.Append(aSpIn);
174 for (j=1; j<=aNbFFs; ++j) {
175 BOPTools_SSInterference& aFF=aFFs(j);
177 if (!(n1==nF || n2==nF)) {
180 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
181 aNbCurves=aSC.Length();
186 const BOPTools_Curve& aBC=aSC(1);
187 const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
188 aItPB.Initialize(aLPB);
189 for (; aItPB.More(); aItPB.Next()) {
190 const BOPTools_PaveBlock& aPBSc=aItPB.Value();
192 const TopoDS_Shape& aSpSc=aDS.Shape(nSpSc);
193 if (aMFence.Add(aSpSc)){
194 aLSpIn.Append(aSpSc);
198 aNbSpIn=aLSpIn.Extent();
200 myInParts.Add(aF, aLSpIn);
202 }//for (nF=1; nF<=aNbS; ++nF) {
205 //=======================================================================
206 // function: BuildSplitFaces
208 //=======================================================================
209 void GEOMAlgo_Builder::BuildSplitFaces()
211 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
212 NMTTools_PaveFiller* pPF=myPaveFiller;
213 NMTDS_InterfPool* pIP=pPF->IP();
214 BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
215 const Handle(IntTools_Context)& aCtx= pPF->Context();
217 Standard_Boolean bToReverse, bIsClosed, bIsDegenerated;
218 Standard_Boolean bFlagClosed;
219 Standard_Integer i, aNb, aNbF, nF;
220 TopTools_MapOfShape aMFence;
221 TColStd_IndexedMapOfInteger aMFP;
222 TopExp_Explorer anExp;
224 TopoDS_Edge aSp, aEE;
225 TopTools_ListIteratorOfListOfShape aIt;
226 TopAbs_Orientation anOriF, anOriE;
228 mySplitFaces.Clear();
230 // 1. Select Faces to process (MFP)
231 aNb=aDS.NumberOfShapesOfTheObject();
232 for (i=1; i<=aNb; ++i) {
233 const TopoDS_Shape& aF=aDS.Shape(i);
234 if (aF.ShapeType()!=TopAbs_FACE) {
237 if (!aMFence.Add(aF)) {
241 if (myInParts.Contains(aF)) {
246 anExp.Init(aF, TopAbs_EDGE);
247 for (; anExp.More(); anExp.Next()) {
248 const TopoDS_Shape& aE=anExp.Current();
249 if (myImages.HasImage(aE)) {
257 Standard_Integer aNbFFs, aNbSE, j, n1, n2;
259 aNbFFs=aFFs.Extent();
260 for (j=1; j<=aNbFFs; ++j) {
261 BOPTools_SSInterference& aFFj=aFFs(j);
262 aFFj.Indices(n1, n2);
263 if (!(n1==i || n2==i)) {
267 const TColStd_ListOfInteger& aLSE=aFFj.SharedEdges();
277 }// for (i=1; i<=aNb; ++i)
281 for (i=1; i<=aNbF; ++i) {
283 const TopoDS_Face& aF=TopoDS::Face(aDS.Shape(nF));
284 anOriF=aF.Orientation();
286 aFF.Orientation(TopAbs_FORWARD);
291 GEOMAlgo_WireEdgeSet aWES;
294 // 2.1.1. Add Split parts
295 anExp.Init(aFF, TopAbs_EDGE);
296 for (; anExp.More(); anExp.Next()) {
297 const TopoDS_Edge& aE=TopoDS::Edge(anExp.Current());
298 anOriE=aE.Orientation();
300 if (!myImages.HasImage(aE)) {
301 if (anOriE==TopAbs_INTERNAL) {
303 aEE.Orientation(TopAbs_FORWARD);
304 aWES.AddStartElement(aEE);
305 aEE.Orientation(TopAbs_REVERSED);
306 aWES.AddStartElement(aEE);
309 aWES.AddStartElement(aE);
314 bIsDegenerated=BRep_Tool::Degenerated(aE);
315 bIsClosed=IsClosed(aE, aF, bFlagClosed);
317 const TopTools_ListOfShape& aLIE=myImages.Image(aE);
318 aIt.Initialize(aLIE);
319 for (; aIt.More(); aIt.Next()) {
320 aSp=TopoDS::Edge(aIt.Value());
322 if (bIsDegenerated) {
323 aSp.Orientation(anOriE);
324 aWES.AddStartElement(aSp);
328 if (anOriE==TopAbs_INTERNAL) {
329 aSp.Orientation(TopAbs_FORWARD);
330 aWES.AddStartElement(aSp);
331 aSp.Orientation(TopAbs_REVERSED);
332 aWES.AddStartElement(aSp);
337 if (aMFence.Add(aSp)) {
339 if (!BRep_Tool::IsClosed(aSp, aF)){
340 BOPTools_Tools3D::DoSplitSEAMOnFace(aSp, aF);
343 aSp.Orientation(TopAbs_FORWARD);
344 aWES.AddStartElement(aSp);
345 aSp.Orientation(TopAbs_REVERSED);
346 aWES.AddStartElement(aSp);
351 //modified by NIZNHY-PKV Wed Nov 28 13:50:34 2012f
352 if (!bIsClosed && bFlagClosed) {
353 if (!BRep_Tool::IsClosed(aSp, aF)){
354 BOPTools_Tools3D::DoSplitSEAMOnFace(aSp, aF);
357 //modified by NIZNHY-PKV Wed Nov 28 13:50:36 2012t
360 aSp.Orientation(anOriE);
361 bToReverse=BOPTools_Tools3D::IsSplitToReverse1(aSp, aE, aCtx);
365 aWES.AddStartElement(aSp);
366 }// for (; aIt.More(); aIt.Next()) {
367 }// for (; anExp.More(); anExp.Next()) {
369 // 2.1.2. Add In2D Parts
370 if (myInParts.Contains(aF)) {
371 const TopTools_ListOfShape& aLE=myInParts.FindFromKey(aF);
373 for (; aIt.More(); aIt.Next()) {
374 aSp=TopoDS::Edge(aIt.Value());
376 aSp.Orientation(TopAbs_FORWARD);
377 aWES.AddStartElement(aSp);
379 aSp.Orientation(TopAbs_REVERSED);
380 aWES.AddStartElement(aSp);
384 // 2.2. Build images Faces
385 TopTools_ListOfShape aLFR;
386 GEOMAlgo_ShapeSet aS1, aS2;
388 const TopTools_ListOfShape& aSE=aWES.StartElements();
390 aS2.Add(aFF, TopAbs_EDGE);
391 if (aS1.IsEqual(aS2)) {
395 GEOMAlgo_BuilderFace aBF;
398 aBF.SetContext(aCtx);
403 const TopTools_ListOfShape& aLF=aBF.Areas();
405 for (; aIt.More(); aIt.Next()) {
406 TopoDS_Shape& aFR=aIt.Value();
407 if (anOriF==TopAbs_REVERSED) {
408 aFR.Orientation(TopAbs_REVERSED);
414 // 2.3. Collect draft images Faces
415 mySplitFaces.Bind(aF, aLFR);
416 }//for (i=1; i<=aNbF; ++i)
419 //=======================================================================
420 // function: FillSameDomainFaces
422 //=======================================================================
423 void GEOMAlgo_Builder::FillSameDomainFaces()
425 Standard_Boolean bIsSDF, bHasImage1, bHasImage2, bForward;
426 Standard_Integer i, j, aNbFF, nF1, nF2, aNbPBInOn, aNbC, aNbSE;
427 Standard_Integer aNbF1, aNbF2, i2s, aNbSD;
428 TopTools_MapOfShape aMFence;
429 TopTools_ListOfShape aLX1, aLX2;
430 TopTools_ListIteratorOfListOfShape aItF1, aItF2;
431 NMTTools_ListOfCoupleOfShape aLCS;
433 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
434 NMTTools_PaveFiller* pPF=myPaveFiller;
435 NMTDS_InterfPool* pIP=pPF->IP();
436 BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
437 const Handle(IntTools_Context)& aCtx= pPF->Context();
440 //mySameDomainShapes.Clear();
442 // 1. For each FF find among images of faces
443 // all pairs of same domain faces (SDF) [=> aLCS]
445 for (i=1; i<=aNbFF; ++i) {
446 BOPTools_SSInterference& aFF=aFFs(i);
447 aFF.Indices(nF1, nF2);
449 const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF1));
450 const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));
452 // if there are no in/on 2D split parts the faces nF1, nF2
454 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
455 aNbPBInOn=aLPBInOn.Extent();
458 const TColStd_ListOfInteger& aLSE=aFF.SharedEdges();
460 if (!aNbPBInOn && !aNbSE) {
465 // if there is at least one section edge between faces nF1, nF2
466 // they can not be SDF
467 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
473 // the faces are suspected to be SDF.
474 // Try to find SDF among images of nF1, nF2
477 //--------------------------------------------------------
478 bHasImage1=mySplitFaces.HasImage(aF1);
479 bHasImage2=mySplitFaces.HasImage(aF2);
491 const TopTools_ListOfShape& aLF1r=(bHasImage1)? mySplitFaces.Image(aF1) : aLX1;
492 const TopTools_ListOfShape& aLF2r=(bHasImage2)? mySplitFaces.Image(aF2) : aLX2;
494 TopTools_DataMapOfIntegerShape aMIS;
495 TColStd_ListIteratorOfListOfInteger aItLI;
496 NMTDS_BoxBndTreeSelector aSelector;
497 NMTDS_BoxBndTree aBBTree;
498 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
500 aNbF1=aLF1r.Extent();
501 aNbF2=aLF2r.Extent();
502 bForward=(aNbF1<aNbF2);
504 const TopTools_ListOfShape& aLF1=bForward ? aLF1r : aLF2r;
505 const TopTools_ListOfShape& aLF2=bForward ? aLF2r : aLF1r;
508 aItF2.Initialize(aLF2);
509 for (i2s=1; aItF2.More(); aItF2.Next(), ++i2s) {
512 const TopoDS_Face& aF2s=*((TopoDS_Face*)(&aItF2.Value()));
514 BRepBndLib::Add(aF2s, aBoxF2s);
516 aMIS.Bind(i2s, aF2s);
518 aTreeFiller.Add(i2s, aBoxF2s);
519 }//for (i2s=1; aItF2.More(); aItF2.Next(), ++i2s) {
524 aItF1.Initialize(aLF1);
525 for (j=1; aItF1.More(); aItF1.Next(), ++j) {
528 const TopoDS_Face& aF1x=*((TopoDS_Face*)(&aItF1.Value()));
530 BRepBndLib::Add(aF1x, aBoxF1x);
533 aSelector.SetBox(aBoxF1x);
534 aNbSD=aBBTree.Select(aSelector);
539 const TColStd_ListOfInteger& aLI=aSelector.Indices();
540 aItLI.Initialize(aLI);
541 for (; aItLI.More(); aItLI.Next()) {
543 const TopoDS_Face& aF2y=*((TopoDS_Face*)(&aMIS.Find(i2s)));
545 bIsSDF=NMTTools_Tools::AreFacesSameDomain(aF1x, aF2y, aCtx);
547 if (aMFence.Contains(aF1x) || aMFence.Contains(aF2y)) {
553 NMTTools_CoupleOfShape aCS;
561 if (!mySplitFaces.HasImage(aF1)) {
562 mySplitFaces.Bind(aF1, aF1);
566 if (!mySplitFaces.HasImage(aF2)) {
567 mySplitFaces.Bind(aF2, aF2);
573 if (!mySplitFaces.HasImage(aF2)) {
574 mySplitFaces.Bind(aF2, aF2);
578 if (!mySplitFaces.HasImage(aF1)) {
579 mySplitFaces.Bind(aF1, aF1);
586 }//for (; aItLI.More(); aItLI.Next()) {
587 }//for (; aItF1.More(); aItF1.Next()) {
588 }//for (i=1; i<=aNbFF; ++i)
589 //-------------------------------------------------------------
596 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
598 NMTTools_Tools::FindChains(aLCS, aMC);
600 Standard_Boolean bIsImage;
601 Standard_Integer aIx, aIxMin, aNbMSDF, k, aNbMFj;
602 TopoDS_Shape aFOld, aFSDmin;
603 TopTools_IndexedMapOfShape aMFj;
604 TopTools_DataMapOfShapeInteger aDMSI;
606 aItF1.Initialize(myShapes);
607 for (j=1; aItF1.More(); aItF1.Next(), ++j) {
608 const TopoDS_Shape& aSj=aItF1.Value();
610 TopExp::MapShapes(aSj, TopAbs_FACE, aMFj);
611 aNbMFj=aMFj.Extent();
612 for (k=1; k<=aNbMFj; ++k) {
613 const TopoDS_Shape& aFk=aMFj(k);
614 if (!aDMSI.IsBound(aFk)) {
620 // 3. Fill the map of SDF mySameDomainFaces
622 for (i=1; i<=aNbC; ++i) {
623 // const TopoDS_Shape& aF=aMC.FindKey(i);
624 const TopTools_IndexedMapOfShape& aMSDF=aMC(i);
626 aNbMSDF=aMSDF.Extent();
627 for (j=1; j<=aNbMSDF; ++j) {
628 const TopoDS_Shape& aFSD=aMSDF(j);
629 bIsImage=mySplitFaces.IsImage(aFSD);
632 aFOld=mySplitFaces.ImageFrom(aFSD);
635 aIx=aDMSI.Find(aFOld);
649 for (j=1; j<=aNbMSDF; ++j) {
650 const TopoDS_Shape& aFSD=aMSDF(j);
651 mySameDomainShapes.Add(aFSD, aFSDmin);
657 //=======================================================================
658 // function: FillImagesFaces1
660 //=======================================================================
661 void GEOMAlgo_Builder::FillImagesFaces1()
663 Standard_Integer i, aNb, iSense, aNbLFx;
664 TopoDS_Face aF, aFSp, aFSD;
665 TopTools_ListOfShape aLFx;
666 TopTools_ListIteratorOfListOfShape aIt;
668 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
670 aNb=aDS.NumberOfShapesOfTheObject();
671 for (i=1; i<=aNb; ++i) {
672 const TopoDS_Shape& aS=aDS.Shape(i);
673 if (aS.ShapeType()!=TopAbs_FACE) {
677 if (!mySplitFaces.HasImage(aS)) {
681 aF=*((TopoDS_Face*)&aS);
684 const TopTools_ListOfShape& aLF=mySplitFaces.Image(aF);
686 for (; aIt.More(); aIt.Next()) {
687 aFSp=*((TopoDS_Face*)(&aIt.Value()));
688 if (!mySameDomainShapes.Contains(aFSp)) {
692 const TopoDS_Shape& aSx=mySameDomainShapes.FindFromKey(aFSp);
693 aFSD=*((TopoDS_Face*)(&aSx));
694 iSense=GEOMAlgo_Tools3D::Sense(aFSp, aFSD);
702 if (!myImages.HasImage(aF)) {
703 aNbLFx=aLFx.Extent();
705 const TopoDS_Shape& aFx=aLFx.First();
706 if (aF.IsSame(aFx)) {
710 myImages.Bind(aF, aLFx);
715 //=======================================================================
716 // function: FillInternalVertices
718 //=======================================================================
719 void GEOMAlgo_Builder::FillInternalVertices()
721 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
722 NMTTools_PaveFiller* pPF=myPaveFiller;
723 NMTDS_InterfPool* pIP=pPF->IP();
724 const Handle(IntTools_Context)& aCtx= pPF->Context();
726 BOPTools_CArray1OfVSInterference& aVFs=pIP->VSInterferences();
727 BOPTools_CArray1OfESInterference& aEFs=pIP->ESInterferences();
728 const NMTTools_IndexedDataMapOfIndexedMapOfInteger& aMAV=pPF->AloneVertices();
730 Standard_Boolean bHasImage;
731 Standard_Integer i, j, nF, aNbS, nV, nVSD, n1, n2, iFlag;
732 Standard_Integer aNbVFs, aNbAVF, aNbEFs, aNbVC, aNbE, aNbV;
733 Standard_Real aU1, aU2, aTol;
734 NMTTools_IndexedDataMapOfIndexedMapOfInteger aMFMV;
735 TopTools_MapOfShape aMFence;
736 TopTools_ListIteratorOfListOfShape aIt, aItV;
739 // 1. Collect face-vertex candidates [aMFMV]
742 aNbVFs=aVFs.Extent();
743 for (i=1; i<=aNbVFs; ++i) {
744 const BOPTools_VSInterference& aVS=aVFs(i);
748 if (aDS.Shape(n1).ShapeType()==TopAbs_FACE) {
752 nVSD=pPF->FindSDVertex(nV);
757 UpdateCandidates(nF, nV, aMFMV);
761 aNbEFs=aEFs.Extent();
762 for (i=1; i<=aNbEFs; ++i) {
763 const BOPTools_ESInterference& aEF=aEFs(i);
769 const TopoDS_Shape& aSnew=aDS.Shape(nV);
770 if (aSnew.ShapeType()!=TopAbs_VERTEX) {
774 nF=(aDS.Shape(n1).ShapeType()==TopAbs_FACE) ? n1 : n2;
775 nVSD=pPF->FindSDVertex(nV);
779 UpdateCandidates(nF, nV, aMFMV);
782 aNbS=aDS.NumberOfShapesOfTheObject();
783 for (nF=1; nF<=aNbS; ++nF) {
784 const TopoDS_Shape& aF=aDS.Shape(nF);
786 if (aF.ShapeType()!=TopAbs_FACE) {
789 if (!aMFence.Add(aF)) {
793 const TopoDS_Face& aFF=TopoDS::Face(aF);
794 aTol=BRep_Tool::Tolerance(aFF);
797 if (aMAV.Contains(nF)) {
798 const TColStd_IndexedMapOfInteger& aMAVF=aMAV.FindFromKey(nF);
799 aNbAVF=aMAVF.Extent();
800 for (j=1; j<=aNbAVF; ++j) {
802 nVSD=pPF->FindSDVertex(nV);
807 UpdateCandidates(nF, nV, aMFMV);
811 // 1.4 Internal vertices of the face nF
812 BooleanOperations_OnceExplorer aExp(aDS);
813 aExp.Init(nF, TopAbs_VERTEX);
814 for (; aExp.More(); aExp.Next()) {
816 const TopoDS_Shape& aV=aDS.Shape(nV);
817 if (aV.Orientation()==TopAbs_INTERNAL) {
818 nVSD=pPF->FindSDVertex(nV);
823 UpdateCandidates(nF, nV, aMFMV);
827 // 2. Process face nF
828 if (!aMFMV.Contains(nF)) {
832 const TColStd_IndexedMapOfInteger& aMVC=aMFMV.FindFromKey(nF);
838 // 2.1 Refine candidates
839 TopTools_IndexedDataMapOfShapeListOfShape aMVE;
840 TopTools_ListOfShape aLV;
842 bHasImage=myImages.HasImage(aF);
844 const TopTools_ListOfShape& aLFx=myImages.Image(aF);
845 aIt.Initialize(aLFx);
846 for (; aIt.More(); aIt.Next()) {
847 const TopoDS_Shape& aFx=aIt.Value();
848 TopExp::MapShapesAndAncestors(aFx, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
852 Standard_Boolean bFaceToProcess;
854 TopExp::MapShapesAndAncestors(aF, TopAbs_VERTEX, TopAbs_EDGE, aMVE);
855 bFaceToProcess=Standard_False;
856 for (j=1; j<=aNbVC; ++j) {
858 const TopoDS_Shape& aV=aDS.Shape(nV);
859 if (!aMVE.Contains(aV)) {
860 bFaceToProcess=!bFaceToProcess;
864 if (!bFaceToProcess) {
869 for (j=1; j<=aNbVC; ++j) {
871 const TopoDS_Shape& aV=aDS.Shape(nV);
872 if (aMVE.Contains(aV)) {
873 const TopTools_ListOfShape& aLE=aMVE.FindFromKey(aV);
884 // 3. Try to put vertices into the face(s)
885 aItV.Initialize(aLV);
886 for (; aItV.More(); aItV.Next()) {
887 TopoDS_Vertex aV=TopoDS::Vertex(aItV.Value());
888 aV.Orientation(TopAbs_INTERNAL);
890 bHasImage=myImages.HasImage(aF);
892 const TopTools_ListOfShape& aLFx=myImages.Image(aF);
893 aIt.Initialize(aLFx);
894 for (; aIt.More(); aIt.Next()) {
895 TopoDS_Face aFx=TopoDS::Face(aIt.Value());
897 IntTools_FClass2d& aClsf=aCtx->FClass2d(aFx);
898 aClsf.Init(aFx, aTol);
900 iFlag=aCtx->ComputeVS (aV, aFx, aU1, aU2);
908 const TopoDS_Face& aFx=TopoDS::Face(aF);
910 IntTools_FClass2d& aClsf=aCtx->FClass2d(aFx);
911 aClsf.Init(aFx, aTol);
913 iFlag=aCtx->ComputeVS (aV, aFx, aU1, aU2);
917 GEOMAlgo_Tools3D::CopyFace(aFx, aFz);
919 myImages.Bind(aF, aFz);
922 }// for (; aItV.More(); aItV.Next()) {
924 }// for (nF=1; nF<=aNb; ++nF) {
927 //=======================================================================
928 // function: UpdateCandidates
930 //=======================================================================
931 void UpdateCandidates(const Standard_Integer theNF,
932 const Standard_Integer theNV,
933 NMTTools_IndexedDataMapOfIndexedMapOfInteger& theMFMV)
935 if (theMFMV.Contains(theNF)) {
936 TColStd_IndexedMapOfInteger& aMV=theMFMV.ChangeFromKey(theNF);
940 TColStd_IndexedMapOfInteger aMV;
942 theMFMV.Add(theNF, aMV);
946 //=======================================================================
947 //function : IsClosed
949 //=======================================================================
950 Standard_Boolean IsClosed(const TopoDS_Edge& aE,
951 const TopoDS_Face& aF,
952 Standard_Boolean& bFlag)
954 Standard_Boolean bRet;
956 bRet=BRep_Tool::IsClosed(aE, aF);
959 Standard_Integer iCnt;
964 TopExp_Explorer aExp(aF, TopAbs_EDGE);
965 for (; aExp.More(); aExp.Next()) {
966 const TopoDS_Shape& aEx=aExp.Current();
968 if (aEx.IsSame(aE)) {
988 TopTools_ListIteratorOfListOfShape aItx;
990 aBBx.MakeCompound(aCx);
992 aItx.Initialize(aSE);
993 for (; aItx.More(); aItx.Next()) {
994 TopoDS_Shape& aEx=aItx.Value();