1 // Copyright (C) 2007-2011 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
23 // File: NMTTools_PaveFiller_5.cxx
24 // Created: Mon Dec 15 11:28:33 2003
25 // Author: Peter KURNEV
28 #include <NMTTools_PaveFiller.ixx>
30 #include <Basics_OCCTVersion.hxx>
32 #include <TColStd_IndexedMapOfInteger.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRep_Builder.hxx>
37 #include <Bnd_Box.hxx>
39 #include <TopAbs_ShapeEnum.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Vertex.hxx>
45 #include <TopoDS_Compound.hxx>
49 #include <TopTools_IndexedMapOfShape.hxx>
51 #include <IntTools_ShrunkRange.hxx>
52 #include <IntTools_Range.hxx>
53 #include <IntTools_EdgeFace.hxx>
54 #if OCC_VERSION_LARGE <= 0x06050200
55 #include <IntTools_PContext.hxx>
57 #include <IntTools_SequenceOfCommonPrts.hxx>
58 #include <IntTools_CommonPrt.hxx>
59 #include <IntTools_Tools.hxx>
61 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
62 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
63 #include <BooleanOperations_OnceExplorer.hxx>
65 #include <BOPTools_Tools.hxx>
66 #include <BOPTools_Pave.hxx>
67 #include <BOPTools_PaveSet.hxx>
68 #include <BOPTools_ListOfPave.hxx>
69 #include <BOPTools_ListIteratorOfListOfPave.hxx>
70 #include <BOPTools_PaveBlock.hxx>
71 #include <BOPTools_ListOfPaveBlock.hxx>
72 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
73 #include <BOPTools_ESInterference.hxx>
75 #include <BOPTools_CArray1OfVVInterference.hxx>
76 #include <BOPTools_CArray1OfESInterference.hxx>
77 #include <BOPTools_VVInterference.hxx>
78 #include <BOPTools_ESInterference.hxx>
79 #include <BOPTools_IDMapOfPaveBlockIMapOfInteger.hxx>
80 #include <BOPTools_IMapOfPaveBlock.hxx>
82 #include <NMTDS_ShapesDataStructure.hxx>
83 #include <NMTDS_Iterator.hxx>
84 #include <NMTDS_InterfPool.hxx>
86 #include <NMTTools_ListOfCommonBlock.hxx>
87 #include <NMTTools_CommonBlockAPI.hxx>
88 #include <NMTTools_IndexedDataMapOfIndexedMapOfInteger.hxx>
89 #include <NMTTools_CommonBlockAPI.hxx>
90 #include <NMTTools_ListOfCommonBlock.hxx>
94 void VertexParameter(const IntTools_CommonPrt& aCPart,
97 Standard_Boolean IsOnPave(const Standard_Real& aTR,
98 const IntTools_Range& aCPRange,
99 const Standard_Real& aTolerance);
101 //=======================================================================
102 // function: PerformEF
104 //=======================================================================
105 void NMTTools_PaveFiller::PerformEF()
107 Standard_Boolean bJustAdd;
108 Standard_Integer n1, n2, anIndexIn, nE, nF, aNbEFs, aBlockLength;
109 Standard_Integer aDiscretize;
110 Standard_Real aTolE, aTolF, aDeflection;
111 BooleanOperations_IndexedDataMapOfShapeInteger aMapVI;
112 BOPTools_IDMapOfPaveBlockIMapOfInteger aMapCB;
113 BOPTools_IMapOfPaveBlock aIMPBx;
115 myIsDone=Standard_False;
119 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
121 myDSIt->Initialize(TopAbs_EDGE, TopAbs_FACE);
123 // BlockLength correction
124 aNbEFs=myDSIt->BlockLength();
125 aBlockLength=aEFs.BlockLength();
126 if (aNbEFs > aBlockLength) {
127 aEFs.SetBlockLength(aNbEFs);
130 for (; myDSIt->More(); myDSIt->Next()) {
131 myDSIt->Current(n1, n2, bJustAdd);
141 if (myDS->GetShapeType(n2)==TopAbs_EDGE) {
146 // all Common Blocks for face nF
147 NMTTools_ListOfCommonBlock aLCBF;
148 CommonBlocksFace(nF, aLCBF);
149 NMTTools_CommonBlockAPI aCBAPIF(aLCBF);
152 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));
153 if (BRep_Tool::Degenerated(aE)){
158 const TopoDS_Face aF=TopoDS::Face(myDS->Shape(nF));
160 TopTools_IndexedMapOfShape aME;
161 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
162 if (aME.Contains(aE)) {
166 aTolF=BRep_Tool::Tolerance(aF);
167 aTolE=BRep_Tool::Tolerance(aE);
169 const Bnd_Box& aBBF=myDS->GetBoundingBox(nF);
171 // Process each PaveBlock on edge nE
172 BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
174 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
175 for (; anIt.More(); anIt.Next()) {
176 BOPTools_PaveBlock& aPB=anIt.Value();
177 if (aCBAPIF.IsCommonBlock(aPB)) {
181 const IntTools_ShrunkRange& aShrunkRange=aPB.ShrunkRange();
182 const IntTools_Range& aSR =aShrunkRange.ShrunkRange();
183 const Bnd_Box& aBBE=aShrunkRange.BndBox();
185 if (aBBF.IsOut (aBBE)) {
190 IntTools_EdgeFace aEF;
195 aEF.SetDiscretize (aDiscretize);
196 aEF.SetDeflection (aDeflection);
198 #if OCC_VERSION_LARGE > 0x06050200
199 aEF.SetContext(myContext);
201 aEF.SetContext((IntTools_PContext)&myContext);
204 IntTools_Range anewSR = aSR;
206 // Correction of the Shrunk Range
207 BOPTools_Tools::CorrectRange(aE, aF, aSR, anewSR);
208 aEF.SetRange (anewSR);
213 Standard_Boolean bCoinsideFlag;
214 Standard_Integer i, aNbCPrts;
215 TopAbs_ShapeEnum aType;
217 const IntTools_SequenceOfCommonPrts& aCPrts=aEF.CommonParts();
219 aNbCPrts=aCPrts.Length();
220 for (i=1; i<=aNbCPrts; ++i) {
223 const IntTools_CommonPrt& aCPart=aCPrts(i);
228 case TopAbs_VERTEX: {
229 Standard_Boolean bIsOnPave1, bIsOnPave2;
230 Standard_Integer nVF;
231 Standard_Real aT, aTolToDecide;
232 TopoDS_Vertex aNewVertex;
234 const IntTools_Range& aR=aCPart.Range1();
237 VertexParameter(aCPart, aT);
238 BOPTools_Tools::MakeNewVertex(aE, aT, aF, aNewVertex);
240 //decide to add pave or not
242 bIsOnPave1=IsOnPave(anewSR.First(), aR, aTolToDecide);
243 bIsOnPave2=IsOnPave(anewSR.Last() , aR, aTolToDecide);
245 if (!bIsOnPave1 && !bIsOnPave2) {
246 nVF=CheckFacePaves(aNewVertex, nF);
249 // Add Interference to the Pool
250 BOPTools_ESInterference anInterf (nE, nF, aCPart);
251 anIndexIn=aEFs.Append(anInterf);
252 anInterf.SetNewShape(0);
254 aMapVI.Add(aNewVertex, anIndexIn);
257 myIP->Add(nE, nF, Standard_True, NMTDS_TI_EF);
260 }// if (!bIsOnPave1 && !bIsOnPave2)
262 //modified by NIZNHY-PKV Fri Apr 18 10:55:38 2008f
264 const BOPTools_Pave& aPave=(bIsOnPave1)? aPB.Pave1() : aPB.Pave2();
266 const TopoDS_Vertex& aVF=TopoDS::Vertex(myDS->Shape(nVF));
267 BOPTools_Tools::UpdateVertex (aVF, aNewVertex);
269 //modified by NIZNHY-PKV Fri Apr 18 10:55:40 2008t
271 }// case TopAbs_VERTEX:
275 bCoinsideFlag=BOPTools_Tools::IsBlockInOnFace(aPB, aF, myContext);
276 if (!bCoinsideFlag) {
281 if (aMapCB.Contains(aPB)) {
282 TColStd_IndexedMapOfInteger& aMapF=aMapCB.ChangeFromKey(aPB);
286 TColStd_IndexedMapOfInteger aMapF;
288 aMapCB.Add(aPB, aMapF);
292 myIP->Add(nE, nF, Standard_True, NMTDS_TI_EF);
293 }// case TopAbs_EDGE:
299 } // for (i=1; i<=aNbCPrts; i++)
300 } //if (aEF.IsDone())
301 } // for (; anIt.More(); anIt.Next())
302 }// for (; myDSIt.More(); myDSIt.Next())
304 // Treat New vertices
305 EFNewVertices(aMapVI);
307 // Add draft Common Blocks of EF type
308 EFCommonBlocks(aMapCB);
310 // Collect all CB we suspected to split by new vertices
311 NMTTools_ListOfCommonBlock aLCBx;
313 Standard_Integer i, aNbPBx, nEx;
314 BOPTools_IMapOfPaveBlock aMx;
316 aNbPBx=aIMPBx.Extent();
317 for (i=1; i<=aNbPBx; ++i) {
318 const BOPTools_PaveBlock& aPBx=aIMPBx(i);
319 nEx=aPBx.OriginalEdge();
320 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nEx));
322 NMTTools_CommonBlockAPI aCBAPIx(aLCB);
323 if (aCBAPIx.IsCommonBlock(aPBx)) {
324 NMTTools_CommonBlock& aCBx=aCBAPIx.CommonBlock(aPBx);
325 const BOPTools_PaveBlock& aPB1=aCBx.PaveBlock1();
326 if (!aMx.Contains(aPB1)){
335 // Split the common blocks above
336 if (aLCBx.Extent()) {
337 ReplaceCommonBlocks(aLCBx);
340 myIsDone=Standard_True;
342 //=======================================================================
343 // function:EFCommonBlocks
345 //=======================================================================
346 void NMTTools_PaveFiller::EFCommonBlocks
347 (const BOPTools_IDMapOfPaveBlockIMapOfInteger& aMapCB)
349 Standard_Integer i, aNbPB, nE, j, aNbF, nF;
351 aNbPB=aMapCB.Extent();
352 for (i=1; i<=aNbPB; ++i) {
353 const BOPTools_PaveBlock& aPB=aMapCB.FindKey(i);
354 const TColStd_IndexedMapOfInteger& aMapF=aMapCB.FindFromIndex(i);
357 nE=aPB.OriginalEdge();
359 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
361 NMTTools_CommonBlockAPI aCBAPI(aLCB);
362 if (aCBAPI.IsCommonBlock(aPB)) {
363 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
364 for (j=1; j<=aNbF; ++j) {
370 NMTTools_CommonBlock aCB;
372 aCB.AddPaveBlock(aPB);
373 for (j=1; j<=aNbF; ++j) {
381 //=======================================================================
382 // function:EFNewVertices
384 //=======================================================================
385 void NMTTools_PaveFiller::EFNewVertices
386 (const BooleanOperations_IndexedDataMapOfShapeInteger& aMapVI)
388 Standard_Integer i, j, aNb, aNewShape, aFlag, iX, aNbVV, aNbSimple;
389 Standard_Integer aWhat, aWith, nE, nF, nV, aNbIEF, aNbEdges, iTmp;
391 TopoDS_Compound aCompound;
392 TopoDS_Vertex aNewVertex;
395 NMTTools_IndexedDataMapOfIndexedMapOfInteger aMNVE, aMNVIEF;
396 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
397 TopTools_IndexedMapOfShape aMNVComplex, aMNVSimple;
400 if (!aNb) { // no new vertices, no new problems
404 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
408 aNewVertex=TopoDS::Vertex(aMapVI.FindKey(1));
409 EFNewVertices(aNewVertex, aMapVI);
413 // 1. Make compound from new vertices
414 aBB.MakeCompound(aCompound);
415 for (i=1; i<=aNb; ++i) {
416 const TopoDS_Shape& aV=aMapVI.FindKey(i);
417 aBB.Add(aCompound, aV);
420 // 2. VV intersection between these vertices
421 // using the auxiliary Filler
422 NMTTools_PaveFiller tPF;
424 tPF.SetCompositeShape(aCompound);
429 NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
430 NMTDS_InterfPool& tInterfPool=*(tPF.IP());
431 BOPTools_CArray1OfVVInterference& aVVInterfs=tInterfPool.VVInterferences();
433 // 3. Separate Comlex and Simple new vertices
434 aNbVV=aVVInterfs.Extent();
435 for (i=1; i<=aNbVV; ++i) {
436 const BOPTools_VVInterference& aVV=aVVInterfs(i);
437 aVV.Indices(aWhat, aWith);
438 const TopoDS_Shape& aV1=tDS.Shape(aWhat);
439 const TopoDS_Shape& aV2=tDS.Shape(aWith);
440 aMNVComplex.Add(aV1);
441 aMNVComplex.Add(aV2);
444 for (i=1; i<=aNb; ++i) {
445 const TopoDS_Shape& aV=aMapVI.FindKey(i);
446 if (!aMNVComplex.Contains(aV)) {
451 // 4. Treat Simple new Vertices
452 aNbSimple=aMNVSimple.Extent();
453 for (i=1; i<=aNbSimple; ++i) {
454 const TopoDS_Vertex& aV=TopoDS::Vertex(aMNVSimple(i));
455 EFNewVertices(aV, aMapVI);
458 // 3. Fill Maps : NewVertex-edges (aMNVE)
459 // NewVertex-interferences (aMNVIEE)
460 aNb=aVVInterfs.Extent();
461 for (i=1; i<=aNb; ++i) {
462 const BOPTools_VVInterference& aVV=aVVInterfs(i);
463 aNewShape=aVV.NewShape();
468 if (!aMNVE.Contains(aNewShape)) {
469 TColStd_IndexedMapOfInteger aMx;
470 aMNVE.Add(aNewShape, aMx);
472 if (!aMNVIEF.Contains(aNewShape)) {
473 TColStd_IndexedMapOfInteger aMx;
474 aMNVIEF.Add(aNewShape, aMx);
477 TColStd_IndexedMapOfInteger& aME=aMNVE.ChangeFromKey(aNewShape);
478 TColStd_IndexedMapOfInteger& aMIEF=aMNVIEF.ChangeFromKey(aNewShape);
480 aVV.Indices(aWhat, aWith);
482 const TopoDS_Shape& aV1=tDS.Shape(aWhat);
483 iX=aMapVI.FindFromKey(aV1);
484 const BOPTools_ESInterference& aEF1=aEFs(iX);
485 aEF1.Indices(nE, nF);
487 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
495 const TopoDS_Shape& aV2=tDS.Shape(aWith);
496 iX=aMapVI.FindFromKey(aV2);
497 const BOPTools_ESInterference& aEF2=aEFs(iX);
498 aEF2.Indices(nE, nF);
500 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
507 }// for (i=1; i<=aNb; ++i) {
509 // 4. Process new vertices
511 for (i=1; i<=aNb; ++i) { // xx
515 aNewVertex=TopoDS::Vertex(tDS.Shape(nV));
517 // Insert New Vertex in DS;
518 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
519 aNewShape=myDS->NumberOfInsertedShapes();
520 myDS->SetState (aNewShape, BooleanOperations_ON);
522 // Update index of NewShape in EF interferences
523 const TColStd_IndexedMapOfInteger& aMIEF=aMNVIEF.FindFromKey(nV);
524 aNbIEF=aMIEF.Extent();
525 for (j=1; j<=aNbIEF; ++j) {
527 BOPTools_ESInterference& aEF=aEFs(iX);
528 aEF.SetNewShape(aNewShape);
531 // Update Paves on all edges
532 const TColStd_IndexedMapOfInteger& aME=aMNVE(i);
533 aNbEdges=aME.Extent();
534 for (j=1; j<=aNbEdges; ++j) {
536 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
538 #if OCC_VERSION_LARGE > 0x06050200
539 aFlag=myContext->ComputeVE (aNewVertex, aE, aT);
541 aFlag=myContext.ComputeVE (aNewVertex, aE, aT);
545 aPave.SetInterference(-1);
546 aPave.SetType (BooleanOperations_EdgeSurface);
547 aPave.SetIndex(aNewShape);
550 BOPTools_PaveSet& aPaveSet=myPavePoolNew(myDS->RefEdge(nE));
551 aPaveSet.Append(aPave);
556 //=======================================================================
557 // function:EFNewVertices
559 //=======================================================================
560 void NMTTools_PaveFiller::EFNewVertices
561 (const TopoDS_Vertex& aNewVertex,
562 const BooleanOperations_IndexedDataMapOfShapeInteger& aMapVI)
564 Standard_Integer i, aNewShape, nE, nF;
567 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
569 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
571 // Insert New Vertex in DS;
572 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
573 aNewShape=myDS->NumberOfInsertedShapes();
574 myDS->SetState (aNewShape, BooleanOperations_ON);
576 // Insert New Vertex in EFInterference
577 i=aMapVI.FindFromKey(aNewVertex);
578 BOPTools_ESInterference& aEFInterf= aEFs(i);
579 aEFInterf.SetNewShape(aNewShape);
580 // Extract interference info
581 aEFInterf.Indices(nE, nF);
582 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
585 const IntTools_CommonPrt& aCPart=aEFInterf.CommonPrt();
586 VertexParameter(aCPart, aT);
589 aPave.SetInterference(i);
590 aPave.SetType (BooleanOperations_EdgeSurface);
591 aPave.SetIndex(aNewShape);
593 // Append the Pave to the myPavePoolNew
594 BOPTools_PaveSet& aPaveSet=myPavePoolNew(myDS->RefEdge(nE));
595 aPaveSet.Append(aPave);
598 //=======================================================================
599 // function: CheckFacePaves
601 //=======================================================================
602 Standard_Integer NMTTools_PaveFiller::CheckFacePaves
603 (const TopoDS_Vertex& aNewVertex,
604 const Standard_Integer nF)
606 Standard_Integer nEF, nVF, iFlag, i, aNbV, iRet;
607 BOPTools_ListIteratorOfListOfPave anIt;
608 TColStd_IndexedMapOfInteger aMVF;
612 BooleanOperations_OnceExplorer aExp(*myDS);
613 aExp.Init(nF, TopAbs_EDGE);
614 for (; aExp.More(); aExp.Next()) {
616 BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(nEF));
617 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
618 anIt.Initialize(aLP);
619 for (; anIt.More(); anIt.Next()) {
620 const BOPTools_Pave& aPave=anIt.Value();
627 for (i=1; i<=aNbV; ++i) {
629 const TopoDS_Vertex aVF=TopoDS::Vertex(myDS->Shape(nVF));
630 iFlag=IntTools_Tools::ComputeVV(aNewVertex, aVF);
638 //=======================================================================
639 // function: VertexParameter
641 //=======================================================================
642 void VertexParameter(const IntTools_CommonPrt& aCPart,
645 const IntTools_Range& aR=aCPart.Range1();
646 aT=0.5*(aR.First()+aR.Last());
647 if((aCPart.VertexParameter1() >= aR.First()) &&
648 (aCPart.VertexParameter1() <= aR.Last())) {
649 aT = aCPart.VertexParameter1();
652 //=======================================================================
653 // function: IsOnPave
655 //=======================================================================
656 Standard_Boolean IsOnPave(const Standard_Real& aTR,
657 const IntTools_Range& aCPRange,
658 const Standard_Real& aTolerance)
660 Standard_Boolean bIsOnPave;
661 Standard_Real aT1, aT2, dT1, dT2;
663 aT1=aCPRange.First();
665 bIsOnPave=(aTR>=aT1 && aTR<=aT1);
672 bIsOnPave=(dT1<=aTolerance || dT2<=aTolerance);