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_3.cxx
24 // Author : Peter KURNEV
26 #include <GEOMAlgo_Builder.hxx>
28 #include <TopAbs_State.hxx>
31 #include <TopoDS_Iterator.hxx>
32 #include <TopoDS_Solid.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Solid.hxx>
36 #include <TopoDS_Iterator.hxx>
37 #include <TopoDS_Shell.hxx>
38 #include <TopoDS_Compound.hxx>
41 #include <TopExp_Explorer.hxx>
43 #include <BRep_Builder.hxx>
44 #include <BRepTools.hxx>
45 #include <BRepClass3d_SolidClassifier.hxx>
47 #include <TopTools_ListOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TopTools_ListIteratorOfListOfShape.hxx>
50 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
51 #include <TopTools_IndexedMapOfShape.hxx>
52 #include <TopTools_MapIteratorOfMapOfShape.hxx>
53 #include <TopTools_DataMapOfShapeShape.hxx>
54 #include <TopTools_DataMapOfShapeInteger.hxx>
55 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
56 #include <TopTools_MapOfShape.hxx>
58 #include <IntTools_Context.hxx>
60 #include <NMTDS_ShapesDataStructure.hxx>
61 #include <NMTTools_PaveFiller.hxx>
63 #include <GEOMAlgo_Tools3D.hxx>
64 #include <GEOMAlgo_BuilderSolid.hxx>
65 #include <GEOMAlgo_ShapeSet.hxx>
66 #include <GEOMAlgo_DataMapOfShapeShapeSet.hxx>
67 #include <GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet.hxx>
72 void OwnInternalShapes(const TopoDS_Shape& ,
73 TopTools_IndexedMapOfShape& );
75 //=======================================================================
76 //function : FillImagesSolids
78 //=======================================================================
79 void GEOMAlgo_Builder::FillImagesSolids()
87 //=======================================================================
88 //function : BuildDraftSolid
90 //=======================================================================
91 void GEOMAlgo_Builder::BuildDraftSolid (const TopoDS_Shape& theSolid,
92 TopoDS_Shape& theDraftSolid,
93 TopTools_ListOfShape& theLIF)
97 NMTTools_PaveFiller* pPF=myPaveFiller;
98 const Handle(IntTools_Context)& aCtx= pPF->Context();
100 Standard_Boolean bToReverse;
101 Standard_Integer iFlag;
102 TopAbs_Orientation aOrF, aOrSh, aOrSd;
103 TopoDS_Iterator aIt1, aIt2;
104 TopTools_ListIteratorOfListOfShape aItS;
107 TopoDS_Shape aFSDx, aFx;
109 aOrSd=theSolid.Orientation();
110 theDraftSolid.Orientation(aOrSd);
112 aIt1.Initialize(theSolid);
113 for (; aIt1.More(); aIt1.Next()) {
114 const TopoDS_Shape& aSh=aIt1.Value();
115 if(aSh.ShapeType()!=TopAbs_SHELL) {
116 continue; // mb internal edges,vertices
119 aOrSh=aSh.Orientation();
121 aShD.Orientation(aOrSh);
124 aIt2.Initialize(aSh);
125 for (; aIt2.More(); aIt2.Next()) {
126 const TopoDS_Shape& aF=aIt2.Value();
127 aOrF=aF.Orientation();
129 if (myImages.HasImage(aF)) {
130 const TopTools_ListOfShape& aLSp=myImages.Image(aF);
131 aItS.Initialize(aLSp);
132 for (; aItS.More(); aItS.Next()) {
135 if (mySameDomainShapes.Contains(aFx)) {
136 aFSDx=mySameDomainShapes.FindFromKey(aFx);
138 if (aOrF==TopAbs_INTERNAL) {
139 aFSDx.Orientation(aOrF);
140 theLIF.Append(aFSDx);
143 bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFSDx, aF, aCtx);
149 aBB.Add(aShD, aFSDx);
151 }// if (mySameDomainShapes.Contains(aFx)) {
153 aFx.Orientation(aOrF);
154 if (aOrF==TopAbs_INTERNAL) {
163 } //if (myImages.HasImage(aF)) {
166 if (aOrF==TopAbs_INTERNAL) {
174 } //for (; aIt2.More(); aIt2.Next()) {
177 aBB.Add(theDraftSolid, aShD);
179 } //for (; aIt1.More(); aIt1.Next()) {
181 //=======================================================================
182 //function : FillIn3DParts
184 //=======================================================================
185 void GEOMAlgo_Builder::FillIn3DParts()
189 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
190 NMTTools_PaveFiller* pPF=myPaveFiller;
191 const Handle(IntTools_Context)& aCtx= pPF->Context();
193 Standard_Boolean bIsIN, bHasImage;
194 Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF;
195 TopAbs_ShapeEnum aType;
197 TopTools_IndexedMapOfShape aMSolids, aMS, aMFaces, aMFIN;
198 TopTools_MapOfShape aMFDone;
199 TopTools_IndexedDataMapOfShapeListOfShape aMEF;
200 TopTools_ListIteratorOfListOfShape aItS;
201 TopoDS_Iterator aIt, aItF;
203 TopoDS_Solid aSolidSp;
206 myDraftSolids.Clear();
208 aNbS=aDS.NumberOfShapesOfTheObject();
209 for (i=1; i<=aNbS; ++i) {
210 const TopoDS_Shape& aS=aDS.Shape(i);
212 aType=aS.ShapeType();
213 if (aType==TopAbs_SOLID) {
214 // all solids from DS
217 else if (aType==TopAbs_FACE) {
218 // all faces (originals from DS or theirs images)
219 if (myImages.HasImage(aS)) {
220 const TopTools_ListOfShape& aLS=myImages.Image(aS);
221 aItS.Initialize(aLS);
222 for (; aItS.More(); aItS.Next()) {
223 const TopoDS_Shape& aFx=aItS.Value();
225 if (mySameDomainShapes.Contains(aFx)) {
226 const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aFx);
235 if (mySameDomainShapes.Contains(aS)) {
236 const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aS);
246 aNbFaces=aMFaces.Extent();
247 aNbSolids=aMSolids.Extent();
249 for (i=1; i<=aNbSolids; ++i) {
250 const TopoDS_Solid& aSolid=TopoDS::Solid(aMSolids(i));
255 aBB.MakeSolid(aSolidSp);
257 TopTools_ListOfShape aLIF;
259 BuildDraftSolid(aSolid, aSolidSp, aLIF);
260 aNbLIF=aLIF.Extent();
262 // 1 all faces/edges from aSolid [ aMS ]
263 bHasImage=Standard_False;
265 aIt.Initialize(aSolid);
266 for (; aIt.More(); aIt.Next()) {
267 const TopoDS_Shape& aShell=aIt.Value();
269 if (myImages.HasImage(aShell)) {
270 bHasImage=Standard_True;
272 const TopTools_ListOfShape& aLS=myImages.Image(aShell);
273 aItS.Initialize(aLS);
274 for (; aItS.More(); aItS.Next()) {
275 const TopoDS_Shape& aSx=aItS.Value();
277 TopExp::MapShapes(aSx, TopAbs_FACE, aMS);
278 TopExp::MapShapes(aSx, TopAbs_EDGE, aMS);
279 TopExp::MapShapesAndAncestors(aSx, TopAbs_EDGE, TopAbs_FACE, aMEF);
284 TopExp::MapShapes(aShell, TopAbs_FACE, aMS);
285 TopExp::MapShapes(aShell, TopAbs_EDGE, aMS);
286 TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF);
290 // 2 all faces that are not from aSolid [ aLFP1 ]
291 Standard_Integer aNbEFP;
292 TopTools_IndexedDataMapOfShapeListOfShape aMEFP;
293 TopTools_ListIteratorOfListOfShape aItFP, aItEx;
294 TopTools_MapOfShape aMFence;
295 TopTools_ListOfShape aLFP1, aLFP2, aLFP, aLCBF, aLFIN, aLEx;//*pLFP,
297 // for all non-solid faces build EF map [ aMEFP ]
298 for (j=1; j<=aNbFaces; ++j) {
299 const TopoDS_Shape& aFace=aMFaces(j);
300 if (!aMS.Contains(aFace)) {
301 TopExp::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP);
305 // among all faces from aMEFP select these that have same edges
306 // with the solid (i.e aMEF). These faces will be treated first
307 // to prevent the usage of 3D classifier.
308 // The full list of faces to process is aLFP1.
309 aNbEFP=aMEFP.Extent();
310 for (j=1; j<=aNbEFP; ++j) {
311 const TopoDS_Shape& aE=aMEFP.FindKey(j);
313 if (aMEF.Contains(aE)) { // !!
314 const TopTools_ListOfShape& aLF=aMEFP(j);
315 aItFP.Initialize(aLF);
316 for (; aItFP.More(); aItFP.Next()) {
317 const TopoDS_Shape& aF=aItFP.Value();
318 if (aMFence.Add(aF)) {
328 aItEx.Initialize(aLEx);
329 for (; aItEx.More(); aItEx.Next()) {
330 const TopoDS_Shape& aE=aItEx.Value();
331 const TopTools_ListOfShape& aLF=aMEFP.FindFromKey(aE);
332 aItFP.Initialize(aLF);
333 for (; aItFP.More(); aItFP.Next()) {
334 const TopoDS_Shape& aF=aItFP.Value();
335 if (aMFence.Add(aF)) {
343 // 3 Process faces aLFP1
344 aNbFP=aLFP1.Extent();
345 aItFP.Initialize(aLFP1);
346 for (; aItFP.More(); aItFP.Next()) {
347 const TopoDS_Shape& aSP=aItFP.Value();
348 if (!aMFDone.Add(aSP)) {
353 // first face to process
354 aFP=TopoDS::Face(aSP);
355 bIsIN= GEOMAlgo_Tools3D::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, aCtx);
356 aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT;
358 // collect faces to process [ aFP is the first ]
361 aItS.Initialize(aLFP1);
362 for (; aItS.More(); aItS.Next()) {
363 const TopoDS_Shape& aSk=aItS.Value();
364 if (!aMFDone.Contains(aSk)) {
369 // Connexity Block that spreads from aFP the Bound
370 // or till the end of the block itself
372 GEOMAlgo_Tools3D::MakeConnexityBlock(aLFP, aMS, aLCBF);
374 // fill states for the Connexity Block
375 aItS.Initialize(aLCBF);
376 for (; aItS.More(); aItS.Next()) {
377 const TopoDS_Shape& aSx=aItS.Value();
379 if (aState==TopAbs_IN) {
384 aNbFPx=aMFDone.Extent();
388 }//for (; aItFP.More(); aItFP.Next())
390 // faces Inside aSolid
392 aNbFIN=aMFIN.Extent();
393 if (aNbFIN || aNbLIF) {
394 for (j=1; j<=aNbFIN; ++j) {
395 const TopoDS_Shape& aFIN=aMFIN(j);
399 aItS.Initialize(aLIF);
400 for (; aItS.More(); aItS.Next()) {
401 const TopoDS_Shape& aFIN=aItS.Value();
405 myInParts.Add(aSolid, aLFIN);
407 if (aNbFIN || bHasImage) {
408 myDraftSolids.Add(aSolid, aSolidSp);
410 }//for (i=1; i<=aNbSolids; ++i) { // next solid
412 //=======================================================================
413 //function : BuildSplitSolids
415 //=======================================================================
416 void GEOMAlgo_Builder::BuildSplitSolids()
420 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
421 NMTTools_PaveFiller* pPF=myPaveFiller;
422 const Handle(IntTools_Context)& aCtx= pPF->Context();
424 Standard_Integer i, aNbS, iErr;
425 TopExp_Explorer aExp;
426 TopTools_ListOfShape aSFS, aLSEmpty;
427 TopTools_MapOfShape aMFence;
428 TopTools_ListIteratorOfListOfShape aIt;
429 GEOMAlgo_BuilderSolid aSB;
430 GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet aItSS;
431 GEOMAlgo_DataMapOfShapeShapeSet aMSS;
432 GEOMAlgo_ShapeSet aSSi;
434 // 0. Find same domain solids for non-interferred solids
435 aNbS=aDS.NumberOfShapesOfTheObject();
436 for (i=1; i<=aNbS; ++i) {
437 const TopoDS_Shape& aS=aDS.Shape(i);
438 if (aS.ShapeType()!=TopAbs_SOLID) {
441 if (!aMFence.Add(aS)) {
444 if(myDraftSolids.Contains(aS)) {
449 aSSi.Add(aS, TopAbs_FACE);
452 } //for (i=1; i<=aNbS; ++i)
454 // 1. Build solids for interferred source solids
455 aSB.SetContext(aCtx);
456 aSB.ComputeInternalShapes(myComputeInternalShapes);
457 aNbS=myDraftSolids.Extent();
458 for (i=1; i<=aNbS; ++i) {
459 const TopoDS_Shape& aS =myDraftSolids.FindKey(i);
460 const TopoDS_Shape& aSD=myDraftSolids.FindFromIndex(i);
461 const TopTools_ListOfShape& aLFIN=
462 (myInParts.Contains(aS)) ? myInParts.FindFromKey(aS) : aLSEmpty;
464 // 1.1 Fill Shell Faces Set
467 aExp.Init(aSD, TopAbs_FACE);
468 for (; aExp.More(); aExp.Next()) {
469 const TopoDS_Shape& aF=aExp.Current();
473 aIt.Initialize(aLFIN);
474 for (; aIt.More(); aIt.Next()) {
475 TopoDS_Shape aF=aIt.Value();
477 aF.Orientation(TopAbs_FORWARD);
479 aF.Orientation(TopAbs_REVERSED);
483 Standard_Integer aNbSFS;
484 aNbSFS=aSFS.Extent();
487 // Check whether aSFS contains a subsets of faces
488 // of solids that have been already built.
489 // If yes, shrink aSFS by these subsets.
493 aItSS.Initialize(aMSS);
494 for (; aItSS.More(); aItSS.Next()) {
495 const TopoDS_Shape& aSR=aItSS.Key();
496 const GEOMAlgo_ShapeSet& aSSR=aItSS.Value();
497 if (aSSi.Contains(aSSR)) {
498 // the aSR is SD solid for aS
501 if(myImages.HasImage(aS)) {
502 myImages.Add(aS, aSR);
505 myImages.Bind(aS, aSR);
509 mySameDomainShapes.Add(aSR, aSR);
512 const TopTools_ListOfShape& aSFS1=aSSi.GetSet();
513 aNbSFS=aSFS1.Extent();
518 // 1.3 Build new solids
519 aSB.SetContext(aCtx);
520 aSB.SetShapes(aSFS1);
522 iErr=aSB.ErrorStatus();
524 myErrorStatus=30; // SolidBuilder failed
528 const TopTools_ListOfShape& aLSR=aSB.Areas();
530 // 1.4 Collect resulting solids and theirs set of faces
531 aIt.Initialize(aLSR);
532 for (; aIt.More(); aIt.Next()) {
533 const TopoDS_Shape& aSR=aIt.Value();
536 aExp.Init(aSR, TopAbs_FACE);
537 for (; aExp.More(); aExp.Next()) {
538 const TopoDS_Shape& aF=aExp.Current();
541 aMSS.Bind(aSR, aSSi);
545 if (myImages.HasImage(aS)) {
546 myImages.Add(aS, aLSR);
549 myImages.Bind(aS, aLSR);
551 } // for (i=1; i<=aNbS; ++i) {
553 //=======================================================================
554 //function :FillInternalShapes
556 //=======================================================================
557 void GEOMAlgo_Builder::FillInternalShapes()
561 const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
562 NMTTools_PaveFiller* pPF=myPaveFiller;
563 const Handle(IntTools_Context)& aCtx= pPF->Context();
565 //Standard_Boolean bHasImage;
566 Standard_Integer i, j, jT, aNbS, aNbSI, aNbSx, aNbSd;
567 TopAbs_ShapeEnum aType, aT[]={ TopAbs_VERTEX, TopAbs_EDGE };
569 TopTools_ListIteratorOfListOfShape aIt, aIt1;
570 TopTools_IndexedDataMapOfShapeListOfShape aMSx;
571 TopTools_IndexedMapOfShape aMx;
572 TopTools_MapOfShape aMSI, aMFence, aMSOr;
573 TopTools_MapIteratorOfMapOfShape aItM;
574 TopTools_ListOfShape aLSI, aLSd;
575 TopoDS_Iterator aItS;
578 // 1. Shapes to process
580 // 1.1 Shapes from pure arguments aMSI
581 // 1.1.1 vertex, edge
582 for (i=0; i<2; ++i) {
583 jT=(Standard_Integer)aT[i];
584 const TopTools_ListOfShape &aLS=myShapes1[jT];
586 for (; aIt.More(); aIt.Next()) {
587 const TopoDS_Shape& aS=aIt.Value();
588 if (aMFence.Add(aS)) {
595 jT=(Standard_Integer)TopAbs_WIRE;
596 const TopTools_ListOfShape &aLW=myShapes1[jT];
598 for (; aIt.More(); aIt.Next()) {
599 const TopoDS_Shape& aW=aIt.Value();
601 for (; aItS.More(); aItS.Next()) {
602 const TopoDS_Shape& aE=aItS.Value();
603 if (aMFence.Add(aE)) {
609 // 1.1.3 theirs images/sources
610 aIt1.Initialize(aLSI);
611 for (; aIt1.More(); aIt1.Next()) {
612 const TopoDS_Shape& aS=aIt1.Value();
613 if (myImages.HasImage(aS)) {
614 const TopTools_ListOfShape &aLSp=myImages.Image(aS);
615 aIt.Initialize(aLSp);
616 for (; aIt.More(); aIt.Next()) {
617 const TopoDS_Shape& aSI=aIt.Value();
628 // 2. Internal vertices, edges from source solids
632 aNbS=aDS.NumberOfShapesOfTheObject();
633 for (i=1; i<=aNbS; ++i) {
634 const TopoDS_Shape& aS=aDS.Shape(i);
635 aType=aS.ShapeType();
636 if (aType==TopAbs_SOLID) {
639 OwnInternalShapes(aS, aMx);
642 for (j=1; j<=aNbSx; ++j) {
643 const TopoDS_Shape& aSI=aMx(j);
644 if (myImages.HasImage(aSI)) {
645 const TopTools_ListOfShape &aLSp=myImages.Image(aSI);
646 aIt.Initialize(aLSp);
647 for (; aIt.More(); aIt.Next()) {
648 const TopoDS_Shape& aSp=aIt.Value();
657 // build aux map from splits of solids
658 if (myImages.HasImage(aS)) {
659 const TopTools_ListOfShape &aLSp=myImages.Image(aS);
660 aIt.Initialize(aLSp);
661 for (; aIt.More(); aIt.Next()) {
662 const TopoDS_Shape& aSp=aIt.Value();
663 if (aMFence.Add(aSp)) {
664 TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
665 TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx);
666 TopExp::MapShapesAndAncestors(aSp, TopAbs_EDGE , TopAbs_FACE, aMSx);
672 if (aMFence.Add(aS)) {
673 TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
674 TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx);
675 TopExp::MapShapesAndAncestors(aS, TopAbs_EDGE , TopAbs_FACE, aMSx);
680 }//if (aType==TopAbs_SOLID)
685 // 3. Some shapes of aMSI can be already tied with faces of
687 aItM.Initialize(aMSI);
688 for (; aItM.More(); aItM.Next()) {
689 const TopoDS_Shape& aSI=aItM.Key();
690 if (aMSx.Contains(aSI)) {
691 const TopTools_ListOfShape &aLSx=aMSx.FindFromKey(aSI);
694 //modified by NIZNHY-PKV Wed Mar 27 11:39:15 2013f
696 if (aMSI.Remove(aSI)) {
697 aItM.Initialize(aMSI);
699 //modified by NIZNHY-PKV Wed Mar 27 11:39:18 2013t
710 // 5 Settle internal vertices and edges into solids
712 aIt.Initialize(aLSd);
713 for (; aIt.More(); aIt.Next()) {
714 TopoDS_Solid aSd=TopoDS::Solid(aIt.Value());
716 aItM.Initialize(aMSI);
717 for (; aItM.More(); aItM.Next()) {
718 TopoDS_Shape aSI=aItM.Key();
719 aSI.Orientation(TopAbs_INTERNAL);
721 aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
722 if (aState==TopAbs_IN) {
724 if(aMSOr.Contains(aSd)) {
729 aItS.Initialize(aSd);
730 for (; aItS.More(); aItS.Next()) {
731 const TopoDS_Shape& aSh=aItS.Value();
737 myImages.Bind(aSd, aSdx);
746 } //if (aState==TopAbs_IN) {
747 }// for (; aItM.More(); aItM.Next()) {
748 }//for (; aIt1.More(); aIt1.Next()) {
750 //=======================================================================
751 //function : OwnInternalShapes
753 //=======================================================================
754 void OwnInternalShapes(const TopoDS_Shape& theS,
755 TopTools_IndexedMapOfShape& theMx)
759 aIt.Initialize(theS);
760 for (; aIt.More(); aIt.Next()) {
761 const TopoDS_Shape& aSx=aIt.Value();
762 if (aSx.ShapeType()!=TopAbs_SHELL) {
769 // 30 - SolidBuilder failed