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 <TColStd_IndexedMapOfInteger.hxx>
32 #include <BRep_Tool.hxx>
33 #include <BRep_Builder.hxx>
35 #include <Bnd_Box.hxx>
37 #include <TopAbs_ShapeEnum.hxx>
40 #include <TopoDS_Face.hxx>
41 #include <TopoDS_Edge.hxx>
42 #include <TopoDS_Vertex.hxx>
43 #include <TopoDS_Compound.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <IntTools_ShrunkRange.hxx>
50 #include <IntTools_Range.hxx>
51 #include <IntTools_EdgeFace.hxx>
52 #include <IntTools_PContext.hxx>
53 #include <IntTools_SequenceOfCommonPrts.hxx>
54 #include <IntTools_CommonPrt.hxx>
55 #include <IntTools_Tools.hxx>
57 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
58 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
59 #include <BooleanOperations_OnceExplorer.hxx>
61 #include <BOPTools_Tools.hxx>
62 #include <BOPTools_Pave.hxx>
63 #include <BOPTools_PaveSet.hxx>
64 #include <BOPTools_ListOfPave.hxx>
65 #include <BOPTools_ListIteratorOfListOfPave.hxx>
66 #include <BOPTools_PaveBlock.hxx>
67 #include <BOPTools_ListOfPaveBlock.hxx>
68 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
69 #include <BOPTools_ESInterference.hxx>
71 #include <BOPTools_CArray1OfVVInterference.hxx>
72 #include <BOPTools_CArray1OfESInterference.hxx>
73 #include <BOPTools_VVInterference.hxx>
74 #include <BOPTools_ESInterference.hxx>
75 #include <BOPTools_IDMapOfPaveBlockIMapOfInteger.hxx>
76 #include <BOPTools_IMapOfPaveBlock.hxx>
78 #include <NMTDS_ShapesDataStructure.hxx>
79 #include <NMTDS_Iterator.hxx>
80 #include <NMTDS_InterfPool.hxx>
82 #include <NMTTools_ListOfCommonBlock.hxx>
83 #include <NMTTools_CommonBlockAPI.hxx>
84 #include <NMTTools_IndexedDataMapOfIndexedMapOfInteger.hxx>
85 #include <NMTTools_CommonBlockAPI.hxx>
86 #include <NMTTools_ListOfCommonBlock.hxx>
90 void VertexParameter(const IntTools_CommonPrt& aCPart,
93 Standard_Boolean IsOnPave(const Standard_Real& aTR,
94 const IntTools_Range& aCPRange,
95 const Standard_Real& aTolerance);
97 //=======================================================================
98 // function: PerformEF
100 //=======================================================================
101 void NMTTools_PaveFiller::PerformEF()
103 Standard_Boolean bJustAdd;
104 Standard_Integer n1, n2, anIndexIn, nE, nF, aNbEFs, aBlockLength;
105 Standard_Integer aDiscretize;
106 Standard_Real aTolE, aTolF, aDeflection;
107 BooleanOperations_IndexedDataMapOfShapeInteger aMapVI;
108 BOPTools_IDMapOfPaveBlockIMapOfInteger aMapCB;
109 BOPTools_IMapOfPaveBlock aIMPBx;
111 myIsDone=Standard_False;
115 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
117 myDSIt->Initialize(TopAbs_EDGE, TopAbs_FACE);
119 // BlockLength correction
120 aNbEFs=myDSIt->BlockLength();
121 aBlockLength=aEFs.BlockLength();
122 if (aNbEFs > aBlockLength) {
123 aEFs.SetBlockLength(aNbEFs);
126 for (; myDSIt->More(); myDSIt->Next()) {
127 myDSIt->Current(n1, n2, bJustAdd);
137 if (myDS->GetShapeType(n2)==TopAbs_EDGE) {
142 // all Common Blocks for face nF
143 NMTTools_ListOfCommonBlock aLCBF;
144 CommonBlocksFace(nF, aLCBF);
145 NMTTools_CommonBlockAPI aCBAPIF(aLCBF);
148 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));
149 if (BRep_Tool::Degenerated(aE)){
154 const TopoDS_Face aF=TopoDS::Face(myDS->Shape(nF));
156 TopTools_IndexedMapOfShape aME;
157 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
158 if (aME.Contains(aE)) {
162 aTolF=BRep_Tool::Tolerance(aF);
163 aTolE=BRep_Tool::Tolerance(aE);
165 const Bnd_Box& aBBF=myDS->GetBoundingBox(nF);
167 // Process each PaveBlock on edge nE
168 BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
170 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
171 for (; anIt.More(); anIt.Next()) {
172 BOPTools_PaveBlock& aPB=anIt.Value();
173 if (aCBAPIF.IsCommonBlock(aPB)) {
177 const IntTools_ShrunkRange& aShrunkRange=aPB.ShrunkRange();
178 const IntTools_Range& aSR =aShrunkRange.ShrunkRange();
179 const Bnd_Box& aBBE=aShrunkRange.BndBox();
181 if (aBBF.IsOut (aBBE)) {
186 IntTools_EdgeFace aEF;
191 aEF.SetDiscretize (aDiscretize);
192 aEF.SetDeflection (aDeflection);
194 aEF.SetContext((IntTools_PContext)&myContext);
196 IntTools_Range anewSR = aSR;
198 // Correction of the Shrunk Range
199 BOPTools_Tools::CorrectRange(aE, aF, aSR, anewSR);
200 aEF.SetRange (anewSR);
205 Standard_Boolean bCoinsideFlag;
206 Standard_Integer i, aNbCPrts;
207 TopAbs_ShapeEnum aType;
209 const IntTools_SequenceOfCommonPrts& aCPrts=aEF.CommonParts();
211 aNbCPrts=aCPrts.Length();
212 for (i=1; i<=aNbCPrts; ++i) {
215 const IntTools_CommonPrt& aCPart=aCPrts(i);
220 case TopAbs_VERTEX: {
221 Standard_Boolean bIsOnPave1, bIsOnPave2;
222 Standard_Integer nVF;
223 Standard_Real aT, aTolToDecide;
224 TopoDS_Vertex aNewVertex;
226 const IntTools_Range& aR=aCPart.Range1();
229 VertexParameter(aCPart, aT);
230 BOPTools_Tools::MakeNewVertex(aE, aT, aF, aNewVertex);
232 //decide to add pave or not
234 bIsOnPave1=IsOnPave(anewSR.First(), aR, aTolToDecide);
235 bIsOnPave2=IsOnPave(anewSR.Last() , aR, aTolToDecide);
237 if (!bIsOnPave1 && !bIsOnPave2) {
238 nVF=CheckFacePaves(aNewVertex, nF);
241 // Add Interference to the Pool
242 BOPTools_ESInterference anInterf (nE, nF, aCPart);
243 anIndexIn=aEFs.Append(anInterf);
244 anInterf.SetNewShape(0);
246 aMapVI.Add(aNewVertex, anIndexIn);
249 myIP->Add(nE, nF, Standard_True, NMTDS_TI_EF);
252 }// if (!bIsOnPave1 && !bIsOnPave2)
254 //modified by NIZNHY-PKV Fri Apr 18 10:55:38 2008f
256 const BOPTools_Pave& aPave=(bIsOnPave1)? aPB.Pave1() : aPB.Pave2();
258 const TopoDS_Vertex& aVF=TopoDS::Vertex(myDS->Shape(nVF));
259 BOPTools_Tools::UpdateVertex (aVF, aNewVertex);
261 //modified by NIZNHY-PKV Fri Apr 18 10:55:40 2008t
263 }// case TopAbs_VERTEX:
267 bCoinsideFlag=BOPTools_Tools::IsBlockInOnFace(aPB, aF, myContext);
268 if (!bCoinsideFlag) {
273 if (aMapCB.Contains(aPB)) {
274 TColStd_IndexedMapOfInteger& aMapF=aMapCB.ChangeFromKey(aPB);
278 TColStd_IndexedMapOfInteger aMapF;
280 aMapCB.Add(aPB, aMapF);
284 myIP->Add(nE, nF, Standard_True, NMTDS_TI_EF);
285 }// case TopAbs_EDGE:
291 } // for (i=1; i<=aNbCPrts; i++)
292 } //if (aEF.IsDone())
293 } // for (; anIt.More(); anIt.Next())
294 }// for (; myDSIt.More(); myDSIt.Next())
296 // Treat New vertices
297 EFNewVertices(aMapVI);
299 // Add draft Common Blocks of EF type
300 EFCommonBlocks(aMapCB);
302 // Collect all CB we suspected to split by new vertices
303 NMTTools_ListOfCommonBlock aLCBx;
305 Standard_Integer i, aNbPBx, nEx;
306 BOPTools_IMapOfPaveBlock aMx;
308 aNbPBx=aIMPBx.Extent();
309 for (i=1; i<=aNbPBx; ++i) {
310 const BOPTools_PaveBlock& aPBx=aIMPBx(i);
311 nEx=aPBx.OriginalEdge();
312 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nEx));
314 NMTTools_CommonBlockAPI aCBAPIx(aLCB);
315 if (aCBAPIx.IsCommonBlock(aPBx)) {
316 NMTTools_CommonBlock& aCBx=aCBAPIx.CommonBlock(aPBx);
317 const BOPTools_PaveBlock& aPB1=aCBx.PaveBlock1();
318 if (!aMx.Contains(aPB1)){
327 // Split the common blocks above
328 if (aLCBx.Extent()) {
329 ReplaceCommonBlocks(aLCBx);
332 myIsDone=Standard_True;
334 //=======================================================================
335 // function:EFCommonBlocks
337 //=======================================================================
338 void NMTTools_PaveFiller::EFCommonBlocks
339 (const BOPTools_IDMapOfPaveBlockIMapOfInteger& aMapCB)
341 Standard_Integer i, aNbPB, nE, j, aNbF, nF;
343 aNbPB=aMapCB.Extent();
344 for (i=1; i<=aNbPB; ++i) {
345 const BOPTools_PaveBlock& aPB=aMapCB.FindKey(i);
346 const TColStd_IndexedMapOfInteger& aMapF=aMapCB.FindFromIndex(i);
349 nE=aPB.OriginalEdge();
351 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
353 NMTTools_CommonBlockAPI aCBAPI(aLCB);
354 if (aCBAPI.IsCommonBlock(aPB)) {
355 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
356 for (j=1; j<=aNbF; ++j) {
362 NMTTools_CommonBlock aCB;
364 aCB.AddPaveBlock(aPB);
365 for (j=1; j<=aNbF; ++j) {
373 //=======================================================================
374 // function:EFNewVertices
376 //=======================================================================
377 void NMTTools_PaveFiller::EFNewVertices
378 (const BooleanOperations_IndexedDataMapOfShapeInteger& aMapVI)
380 Standard_Integer i, j, aNb, aNewShape, aFlag, iX, aNbVV, aNbSimple;
381 Standard_Integer aWhat, aWith, nE, nF, nV, aNbIEF, aNbEdges, iTmp;
383 TopoDS_Compound aCompound;
384 TopoDS_Vertex aNewVertex;
387 NMTTools_IndexedDataMapOfIndexedMapOfInteger aMNVE, aMNVIEF;
388 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
389 TopTools_IndexedMapOfShape aMNVComplex, aMNVSimple;
392 if (!aNb) { // no new vertices, no new problems
396 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
400 aNewVertex=TopoDS::Vertex(aMapVI.FindKey(1));
401 EFNewVertices(aNewVertex, aMapVI);
405 // 1. Make compound from new vertices
406 aBB.MakeCompound(aCompound);
407 for (i=1; i<=aNb; ++i) {
408 const TopoDS_Shape& aV=aMapVI.FindKey(i);
409 aBB.Add(aCompound, aV);
412 // 2. VV intersection between these vertices
413 // using the auxiliary Filler
414 NMTTools_PaveFiller tPF;
416 tPF.SetCompositeShape(aCompound);
421 NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
422 NMTDS_InterfPool& tInterfPool=*(tPF.IP());
423 BOPTools_CArray1OfVVInterference& aVVInterfs=tInterfPool.VVInterferences();
425 // 3. Separate Comlex and Simple new vertices
426 aNbVV=aVVInterfs.Extent();
427 for (i=1; i<=aNbVV; ++i) {
428 const BOPTools_VVInterference& aVV=aVVInterfs(i);
429 aVV.Indices(aWhat, aWith);
430 const TopoDS_Shape& aV1=tDS.Shape(aWhat);
431 const TopoDS_Shape& aV2=tDS.Shape(aWith);
432 aMNVComplex.Add(aV1);
433 aMNVComplex.Add(aV2);
436 for (i=1; i<=aNb; ++i) {
437 const TopoDS_Shape& aV=aMapVI.FindKey(i);
438 if (!aMNVComplex.Contains(aV)) {
443 // 4. Treat Simple new Vertices
444 aNbSimple=aMNVSimple.Extent();
445 for (i=1; i<=aNbSimple; ++i) {
446 const TopoDS_Vertex& aV=TopoDS::Vertex(aMNVSimple(i));
447 EFNewVertices(aV, aMapVI);
450 // 3. Fill Maps : NewVertex-edges (aMNVE)
451 // NewVertex-interferences (aMNVIEE)
452 aNb=aVVInterfs.Extent();
453 for (i=1; i<=aNb; ++i) {
454 const BOPTools_VVInterference& aVV=aVVInterfs(i);
455 aNewShape=aVV.NewShape();
460 if (!aMNVE.Contains(aNewShape)) {
461 TColStd_IndexedMapOfInteger aMx;
462 aMNVE.Add(aNewShape, aMx);
464 if (!aMNVIEF.Contains(aNewShape)) {
465 TColStd_IndexedMapOfInteger aMx;
466 aMNVIEF.Add(aNewShape, aMx);
469 TColStd_IndexedMapOfInteger& aME=aMNVE.ChangeFromKey(aNewShape);
470 TColStd_IndexedMapOfInteger& aMIEF=aMNVIEF.ChangeFromKey(aNewShape);
472 aVV.Indices(aWhat, aWith);
474 const TopoDS_Shape& aV1=tDS.Shape(aWhat);
475 iX=aMapVI.FindFromKey(aV1);
476 const BOPTools_ESInterference& aEF1=aEFs(iX);
477 aEF1.Indices(nE, nF);
479 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
487 const TopoDS_Shape& aV2=tDS.Shape(aWith);
488 iX=aMapVI.FindFromKey(aV2);
489 const BOPTools_ESInterference& aEF2=aEFs(iX);
490 aEF2.Indices(nE, nF);
492 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
499 }// for (i=1; i<=aNb; ++i) {
501 // 4. Process new vertices
503 for (i=1; i<=aNb; ++i) { // xx
507 aNewVertex=TopoDS::Vertex(tDS.Shape(nV));
509 // Insert New Vertex in DS;
510 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
511 aNewShape=myDS->NumberOfInsertedShapes();
512 myDS->SetState (aNewShape, BooleanOperations_ON);
514 // Update index of NewShape in EF interferences
515 const TColStd_IndexedMapOfInteger& aMIEF=aMNVIEF.FindFromKey(nV);
516 aNbIEF=aMIEF.Extent();
517 for (j=1; j<=aNbIEF; ++j) {
519 BOPTools_ESInterference& aEF=aEFs(iX);
520 aEF.SetNewShape(aNewShape);
523 // Update Paves on all edges
524 const TColStd_IndexedMapOfInteger& aME=aMNVE(i);
525 aNbEdges=aME.Extent();
526 for (j=1; j<=aNbEdges; ++j) {
528 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
530 aFlag=myContext.ComputeVE (aNewVertex, aE, aT);
533 aPave.SetInterference(-1);
534 aPave.SetType (BooleanOperations_EdgeSurface);
535 aPave.SetIndex(aNewShape);
538 BOPTools_PaveSet& aPaveSet=myPavePoolNew(myDS->RefEdge(nE));
539 aPaveSet.Append(aPave);
544 //=======================================================================
545 // function:EFNewVertices
547 //=======================================================================
548 void NMTTools_PaveFiller::EFNewVertices
549 (const TopoDS_Vertex& aNewVertex,
550 const BooleanOperations_IndexedDataMapOfShapeInteger& aMapVI)
552 Standard_Integer i, aNewShape, nE, nF;
555 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
557 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
559 // Insert New Vertex in DS;
560 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
561 aNewShape=myDS->NumberOfInsertedShapes();
562 myDS->SetState (aNewShape, BooleanOperations_ON);
564 // Insert New Vertex in EFInterference
565 i=aMapVI.FindFromKey(aNewVertex);
566 BOPTools_ESInterference& aEFInterf= aEFs(i);
567 aEFInterf.SetNewShape(aNewShape);
568 // Extract interference info
569 aEFInterf.Indices(nE, nF);
570 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
573 const IntTools_CommonPrt& aCPart=aEFInterf.CommonPrt();
574 VertexParameter(aCPart, aT);
577 aPave.SetInterference(i);
578 aPave.SetType (BooleanOperations_EdgeSurface);
579 aPave.SetIndex(aNewShape);
581 // Append the Pave to the myPavePoolNew
582 BOPTools_PaveSet& aPaveSet=myPavePoolNew(myDS->RefEdge(nE));
583 aPaveSet.Append(aPave);
586 //=======================================================================
587 // function: CheckFacePaves
589 //=======================================================================
590 Standard_Integer NMTTools_PaveFiller::CheckFacePaves
591 (const TopoDS_Vertex& aNewVertex,
592 const Standard_Integer nF)
594 Standard_Integer nEF, nVF, iFlag, i, aNbV, iRet;
595 BOPTools_ListIteratorOfListOfPave anIt;
596 TColStd_IndexedMapOfInteger aMVF;
600 BooleanOperations_OnceExplorer aExp(*myDS);
601 aExp.Init(nF, TopAbs_EDGE);
602 for (; aExp.More(); aExp.Next()) {
604 BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(nEF));
605 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
606 anIt.Initialize(aLP);
607 for (; anIt.More(); anIt.Next()) {
608 const BOPTools_Pave& aPave=anIt.Value();
615 for (i=1; i<=aNbV; ++i) {
617 const TopoDS_Vertex aVF=TopoDS::Vertex(myDS->Shape(nVF));
618 iFlag=IntTools_Tools::ComputeVV(aNewVertex, aVF);
626 //=======================================================================
627 // function: VertexParameter
629 //=======================================================================
630 void VertexParameter(const IntTools_CommonPrt& aCPart,
633 const IntTools_Range& aR=aCPart.Range1();
634 aT=0.5*(aR.First()+aR.Last());
635 if((aCPart.VertexParameter1() >= aR.First()) &&
636 (aCPart.VertexParameter1() <= aR.Last())) {
637 aT = aCPart.VertexParameter1();
640 //=======================================================================
641 // function: IsOnPave
643 //=======================================================================
644 Standard_Boolean IsOnPave(const Standard_Real& aTR,
645 const IntTools_Range& aCPRange,
646 const Standard_Real& aTolerance)
648 Standard_Boolean bIsOnPave;
649 Standard_Real aT1, aT2, dT1, dT2;
651 aT1=aCPRange.First();
653 bIsOnPave=(aTR>=aT1 && aTR<=aT1);
660 bIsOnPave=(dT1<=aTolerance || dT2<=aTolerance);