1 // File: NMTAlgo_Inter3d.cxx
2 // Created: Tue Jan 27 15:14:13 2004
3 // Author: Peter KURNEV
7 #include <NMTAlgo_Builder.ixx>
9 #include <TColStd_IndexedMapOfInteger.hxx>
11 #include <TopoDS_Face.hxx>
13 #include <TopoDS_Compound.hxx>
14 #include <TopoDS_Edge.hxx>
15 #include <TopoDS_Shape.hxx>
18 #include <TopExp_Explorer.hxx>
20 #include <BRep_Builder.hxx>
21 #include <BRep_Tool.hxx>
23 #include <TopTools_IndexedMapOfShape.hxx>
24 #include <TopTools_ListOfShape.hxx>
25 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <BOPTColStd_Dump.hxx>
28 #include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
30 #include <IntTools_Context.hxx>
32 #include <BOPTools_Tools3D.hxx>
33 #include <BOPTools_CArray1OfSSInterference.hxx>
34 #include <BOPTools_InterferencePool.hxx>
35 #include <BOPTools_SSInterference.hxx>
36 #include <BOPTools_SequenceOfCurves.hxx>
37 #include <BOPTools_Curve.hxx>
38 #include <BOPTools_SequenceOfCurves.hxx>
39 #include <BOPTools_SplitShapesPool.hxx>
40 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
41 #include <BOPTools_ListOfPaveBlock.hxx>
42 #include <BOPTools_PaveBlock.hxx>
44 #include <BOP_WireEdgeSet.hxx>
45 #include <BOP_FaceBuilder.hxx>
46 #include <BOP_BuilderTools.hxx>
48 #include <NMTDS_ShapesDataStructure.hxx>
50 #include <NMTTools_PaveFiller.hxx>
51 #include <NMTTools_ListOfCoupleOfShape.hxx>
52 #include <NMTTools_Tools.hxx>
53 #include <NMTTools_CoupleOfShape.hxx>
54 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
55 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
57 #include <TopoDS_Shell.hxx>
58 #include <NMTAlgo_Tools.hxx>
59 #include <TColStd_IndexedMapOfInteger.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopoDS_Iterator.hxx>
63 //=======================================================================
64 // function: NMTAlgo_Inter3d::NMTAlgo_Inter3d()
66 //=======================================================================
67 NMTAlgo_Builder::NMTAlgo_Builder()
72 //=======================================================================
73 // function: ~NMTAlgo_Builder
75 //=======================================================================
76 NMTAlgo_Builder::~NMTAlgo_Builder()
80 //=======================================================================
83 //=======================================================================
84 void NMTAlgo_Builder::Clear()
86 NMTAlgo_Algo::Clear();
88 myImagesEdges.Clear();
89 myImagesFaces.Clear();
91 mySectionParts.Clear();
94 //=======================================================================
95 // function: ComputeWithFiller
97 //=======================================================================
98 void NMTAlgo_Builder::ComputeWithFiller(const NMTTools_DSFiller& aDSF)
101 myIsDone=Standard_False;
112 //=======================================================================
113 // function: FillSDFaces
115 //=======================================================================
116 void NMTAlgo_Builder::FillSDFaces()
118 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
119 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
120 BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
121 BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
122 IntTools_Context& aCtx= pPF->ChangeContext();
124 Standard_Boolean bIsSDF;
125 Standard_Integer i, j, aNbFF, nF1, nF2, aNbPBInOn, aNbC;
126 TopTools_ListIteratorOfListOfShape aItF1, aItF2;
127 NMTTools_ListOfCoupleOfShape aLCS;
131 // 1. For each FF find among images of faces
132 // all pairs of same domain faces (SDF) [=> aLCS]
134 for (i=1; i<=aNbFF; ++i) {
135 BOPTools_SSInterference& aFF=aFFs(i);
136 aFF.Indices(nF1, nF2);
138 const TopoDS_Face& aF1=TopoDS::Face(aDS.Shape(nF1));
139 const TopoDS_Face& aF2=TopoDS::Face(aDS.Shape(nF2));
141 // if there are no in/on 2D split parts the faces nF1, nF2
143 const BOPTools_ListOfPaveBlock& aLPBInOn=aFF.PaveBlocks();
144 aNbPBInOn=aLPBInOn.Extent();
149 // if there is at least one section edge between faces nF1, nF2
150 // they can not be SDF
151 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
157 // the faces are suspected to be SDF.
158 // Try to find SDF among images of nF1, nF2
159 const TopTools_ListOfShape& aLF1=myImagesFaces.Image(aF1);
160 const TopTools_ListOfShape& aLF2=myImagesFaces.Image(aF2);
162 aItF1.Initialize(aLF1);
163 for (; aItF1.More(); aItF1.Next()) {
164 const TopoDS_Face& aF1x=TopoDS::Face(aItF1.Value());
166 aItF2.Initialize(aLF2);
167 for (; aItF2.More(); aItF2.Next()) {
168 const TopoDS_Face& aF2y=TopoDS::Face(aItF2.Value());
169 bIsSDF=NMTTools_Tools::AreFacesSameDomain(aF1x, aF2y, aCtx);
171 NMTTools_CoupleOfShape aCS;
179 }//for (i=1; i<=aNbFF; ++i)
187 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
189 NMTTools_Tools::FindChains(aLCS, aMC);
191 // 3. Fill the map of SDF mySDFaces
193 for (i=1; i<=aNbC; ++i) {
194 const TopoDS_Shape& aF=aMC.FindKey(i);
195 const TopTools_IndexedMapOfShape& aMSDF=aMC(i);
197 aNbFF=aMSDF.Extent();
198 for (j=1; j<=aNbFF; ++j) {
199 const TopoDS_Shape& aFSD=aMSDF(j);
200 mySDFaces.Add(aFSD, aF);
205 //=======================================================================
206 // function: FillImagesFaces
208 //=======================================================================
209 void NMTAlgo_Builder::FillImagesFaces()
211 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
212 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
213 IntTools_Context& aCtx= pPF->ChangeContext();
215 Standard_Integer i, j, aNb, aNbE;
216 TopTools_IndexedMapOfShape aMFence, aME;
217 TColStd_IndexedMapOfInteger aMFP;
219 // 1. Select Faces to process (MFP)
220 aNb=aDS.NumberOfShapesOfTheObject();
221 for (i=1; i<=aNb; ++i) {
222 const TopoDS_Shape& aF=aDS.Shape(i);
223 if (aF.ShapeType()!=TopAbs_FACE) {
226 if (aMFence.Contains(aF)) {
231 if (myIn2DParts.Contains(aF)) {
236 if (mySectionParts.Contains(aF)) {
242 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
245 for(j=1; j<=aNbE; ++j) {
246 const TopoDS_Shape& aE=aME(j);
248 if (myImagesEdges.HasImage(aE)) {
253 }// for (i=1; i<=aNb; ++i)
256 Standard_Boolean bToReverse, bIsClosed, bIsDegenerated;
257 Standard_Integer aNbF, nF;
260 TopExp_Explorer anExp;
261 TopTools_ListIteratorOfListOfShape aIt;
262 BRepAlgo_Image aImagesFaces;
263 TopAbs_Orientation anOriF;
266 for (i=1; i<=aNbF; ++i) {
268 const TopoDS_Face& aF=TopoDS::Face(aDS.Shape(nF));
269 anOriF=aF.Orientation();
271 aFF.Orientation(TopAbs_FORWARD);
276 BOP_WireEdgeSet aWES;
277 aWES.Initialize(aFF);
279 // 2.1.1. Add Split parts
280 anExp.Init(aFF, TopAbs_EDGE);
281 for (; anExp.More(); anExp.Next()) {
282 const TopoDS_Edge& aE=TopoDS::Edge(anExp.Current());
284 if (!myImagesEdges.HasImage(aE)) {
285 aWES.AddStartElement(aE);
289 bIsDegenerated=BRep_Tool::Degenerated(aE);
290 bIsClosed=BRep_Tool::IsClosed(aE, aF);
292 const TopTools_ListOfShape& aLIE=myImagesEdges.Image(aE);
293 aIt.Initialize(aLIE);
294 for (; aIt.More(); aIt.Next()) {
295 aSp=TopoDS::Edge(aIt.Value());
297 if (bIsDegenerated) {
298 aSp.Orientation(aE.Orientation());
299 aWES.AddStartElement(aSp);
304 if (!aMFence.Contains(aSp)){
307 if (!BRep_Tool::IsClosed(aSp, aF)){
308 BOPTools_Tools3D::DoSplitSEAMOnFace(aSp, aF);
311 aSp.Orientation(TopAbs_FORWARD);
312 aWES.AddStartElement(aSp);
314 aSp.Orientation(TopAbs_REVERSED);
315 aWES.AddStartElement(aSp);
320 bToReverse=BOPTools_Tools3D::IsSplitToReverse1(aSp, aE, aCtx);
324 aWES.AddStartElement(aSp);
328 // 2.1.2. Add In2D Parts
329 if (myIn2DParts.Contains(aF)) {
330 const TopTools_ListOfShape& aLE=myIn2DParts.FindFromKey(aF);
332 for (; aIt.More(); aIt.Next()) {
333 aSp=TopoDS::Edge(aIt.Value());
335 aSp.Orientation(TopAbs_FORWARD);
336 aWES.AddStartElement(aSp);
338 aSp.Orientation(TopAbs_REVERSED);
339 aWES.AddStartElement(aSp);
343 // 2.1.3. Add Section Parts
344 if (mySectionParts.Contains(aF)) {
345 const TopTools_ListOfShape& aLE=mySectionParts.FindFromKey(aF);
347 for (; aIt.More(); aIt.Next()) {
348 aSp=TopoDS::Edge(aIt.Value());
350 aSp.Orientation(TopAbs_FORWARD);
351 aWES.AddStartElement(aSp);
353 aSp.Orientation(TopAbs_REVERSED);
354 aWES.AddStartElement(aSp);
358 // 2.2. Build images Faces
361 aFB.SetTreatment(0); // 0-Do Internal Edges
362 aFB.SetTreatSDScales(0); // what is 0 ??
366 TopTools_ListOfShape aLFR;
368 const TopTools_ListOfShape& aLF=aFB.NewFaces();
371 for (; aIt.More(); aIt.Next()) {
372 TopoDS_Shape& aFR=aIt.Value();
373 if (anOriF==TopAbs_REVERSED) {
374 aFR.Orientation(TopAbs_REVERSED);
380 // 2.3. Collect images Faces
381 myImagesFaces.Bind(aF, aLFR);
382 }//for (i=1; i<=aNbF; ++i)
384 //=======================================================================
385 // function: FillIn2DParts
387 //=======================================================================
388 void NMTAlgo_Builder::FillIn2DParts()
390 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
391 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
392 BOPTools_InterferencePool* pIP=(BOPTools_InterferencePool*)&myDSFiller->InterfPool();
393 BOPTools_CArray1OfSSInterference& aFFs=pIP->SSInterferences();
395 Standard_Integer i, j, aNb, nF1, nF2, aNbFF, iFF, nSpIn, nSpSc, aNbCurves;
396 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aFFMap;
397 BOPTools_ListOfPaveBlock aLPBIn, aLPBSc;
398 BOPTools_ListIteratorOfListOfPaveBlock aItPBIn, aItPBSc;
399 TopTools_IndexedMapOfShape aMF, aMFence;
400 TopTools_ListOfShape aLSpIn, aLSpSc;
402 BOP_BuilderTools::DoMap(aFFs, aFFMap);
404 // 1. Collect Splits In 2D (myIn2DParts) and
405 // Section Edges (mySectionParts)
406 // for each source face that involved in FF
408 for (i=1; i<=aNb; ++i) {
409 nF1=aFFMap.FindKey(i);
410 const TopoDS_Shape& aF=aDS.Shape(nF1);
412 if (aMF.Contains(aF)) {
420 const TColStd_IndexedMapOfInteger& aFFIndicesMap=aFFMap.FindFromIndex(i);
422 aNbFF=aFFIndicesMap.Extent();
423 for (j=1; j<=aNbFF; ++j) {
424 iFF=aFFIndicesMap(j);
425 BOPTools_SSInterference& aFF=aFFs(iFF);
426 nF2=aFF.OppositeIndex(nF1);
429 pPF->RealSplitsInFace(0, nF2, nF1, aLPBIn);
432 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
433 aNbCurves=aSC.Length();
438 const BOPTools_Curve& aBC=aSC(1);
439 const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
441 aItPBSc.Initialize(aLPB);
442 for (; aItPBSc.More(); aItPBSc.Next()) {
443 const BOPTools_PaveBlock& aPBSc=aItPBSc.Value();
444 aLPBSc.Append(aPBSc);
446 }// for (j=1; j<=aNbFF; ++j)
452 aItPBIn.Initialize(aLPBIn);
453 for (; aItPBIn.More(); aItPBIn.Next()) {
454 const BOPTools_PaveBlock& aPBR=aItPBIn.Value();
456 const TopoDS_Shape& aSpIn=aDS.Shape(nSpIn);
457 if (!aMFence.Contains(aSpIn)){
459 aLSpIn.Append(aSpIn);
462 myIn2DParts.Add(aF, aLSpIn);
466 aItPBSc.Initialize(aLPBSc);
467 for (; aItPBSc.More(); aItPBSc.Next()) {
468 const BOPTools_PaveBlock& aPBSc=aItPBSc.Value();
470 const TopoDS_Shape& aSpSc=aDS.Shape(nSpSc);
471 if (!aMFence.Contains(aSpSc)){
473 aLSpSc.Append(aSpSc);
476 mySectionParts.Add(aF, aLSpSc);
477 } //for (i=1; i<=aNb; ++i)
480 //=======================================================================
481 // function: FillImagesEdges
483 //=======================================================================
484 void NMTAlgo_Builder::FillImagesEdges()
486 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
487 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
488 const BOPTools_SplitShapesPool& aSSP=pPF->SplitShapesPool();
490 Standard_Integer nE, aNb, aNbSp, nSp;
491 BOPTools_ListIteratorOfListOfPaveBlock aIt;
492 TopTools_IndexedMapOfShape aMFence;
493 TopTools_ListOfShape aLSp;
495 aNb=aDS.NumberOfShapesOfTheObject();
496 for (nE=1; nE<=aNb; ++nE) {
497 const TopoDS_Shape& aE=aDS.Shape(nE);
498 if (aE.ShapeType()!=TopAbs_EDGE) {
501 if (aMFence.Contains(aE)) {
506 const BOPTools_ListOfPaveBlock& aLPB=aSSP(aDS.RefEdge(nE));
509 if (!aNbSp) {// no splits
510 //myImagesEdges.Bind(aE, aE);
514 //modified by NIZNHY-PKV Fri Jan 21 17:01:10 2005 f
516 const BOPTools_PaveBlock& aPB1=aLPB.First();
517 const BOPTools_PaveBlock& aPBR1=pPF->RealPaveBlock(aPB1);
519 const TopoDS_Shape& aSp1=aDS.Shape(nSp);
520 if (aSp1.IsSame(aE)) {
524 //modified by NIZNHY-PKV Fri Jan 21 17:01:14 2005 t
527 aIt.Initialize(aLPB);
528 for (; aIt.More(); aIt.Next()) {
529 const BOPTools_PaveBlock& aPB=aIt.Value();
530 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB);
532 const TopoDS_Shape& aSp=aDS.Shape(nSp);
535 myImagesEdges.Bind(aE, aLSp);
538 //=======================================================================
539 // function: SplitVertices
541 //=======================================================================
542 void NMTAlgo_Builder::SplitVertices()
544 const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
545 NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
546 const BOPTools_SplitShapesPool& aSSP=pPF->SplitShapesPool();
548 Standard_Integer nE, aNb, aNbSp, nV1, nV2;
549 BOPTools_ListIteratorOfListOfPaveBlock aIt;
551 myQueryShapes.Clear();
553 aNb=aDS.NumberOfShapesOfTheObject();
554 for (nE=1; nE<=aNb; ++nE) {
555 const TopoDS_Shape& aE=aDS.Shape(nE);
556 if (aE.ShapeType()!=TopAbs_EDGE) {
560 const BOPTools_ListOfPaveBlock& aLPB=aSSP(aDS.RefEdge(nE));
563 if (!aNbSp) {// no splits
567 aIt.Initialize(aLPB);
568 for (; aIt.More(); aIt.Next()) {
569 const BOPTools_PaveBlock& aPB=aIt.Value();
570 const BOPTools_PaveBlock& aPBR=pPF->RealPaveBlock(aPB);
572 nV1=aPBR.Pave1().Index();
573 if (aDS.IsNewShape(nV1)) {
574 const TopoDS_Shape& aV1=aDS.Shape(nV1);
575 myQueryShapes.Add(aV1);
578 nV2=aPBR.Pave2().Index();
579 if (aDS.IsNewShape(nV2)) {
580 const TopoDS_Shape& aV2=aDS.Shape(nV2);
581 myQueryShapes.Add(aV2);
586 //=======================================================================
587 // function: IsSectionEdge
589 //=======================================================================
590 Standard_Boolean NMTAlgo_Builder::IsSectionEdge(const TopoDS_Edge& aE)const
592 return myImagesEdges.HasImage(aE);
594 //=======================================================================
595 // function: IsSameDomainF
597 //=======================================================================
598 Standard_Boolean NMTAlgo_Builder::HasSameDomainF(const TopoDS_Face& aF1)const
600 Standard_Boolean bFlag=Standard_False;
601 TopTools_ListIteratorOfListOfShape aItF1;
603 const TopTools_ListOfShape& aLF1=myImagesFaces.Image(aF1);
604 aItF1.Initialize(aLF1);
605 for (; aItF1.More(); aItF1.Next()) {
606 const TopoDS_Shape& aF1x=aItF1.Value();
608 if (mySDFaces.Contains(aF1x)){
614 //=======================================================================
615 // function: IsSameDomainF
617 //=======================================================================
618 Standard_Boolean NMTAlgo_Builder::IsSameDomainF(const TopoDS_Face& aF1,
619 const TopoDS_Face& aF2)const
621 Standard_Boolean bFlag=Standard_False;
622 TopTools_ListIteratorOfListOfShape aItF1, aItF2;
624 const TopTools_ListOfShape& aLF1=myImagesFaces.Image(aF1);
625 const TopTools_ListOfShape& aLF2=myImagesFaces.Image(aF2);
627 aItF1.Initialize(aLF1);
628 for (; aItF1.More(); aItF1.Next()) {
629 const TopoDS_Shape& aF1x=aItF1.Value();
631 if (!mySDFaces.Contains(aF1x)){
634 const TopoDS_Shape& aFSD1x=mySDFaces.FindFromKey(aF1x);
636 aItF2.Initialize(aLF2);
637 for (; aItF2.More(); aItF2.Next()) {
638 const TopoDS_Shape& aF2y=aItF2.Value();
639 if (!mySDFaces.Contains(aF2y)){
642 const TopoDS_Shape& aFSD2y=mySDFaces.FindFromKey(aF2y);
643 if (aFSD1x.IsSame(aFSD2y)) {