1 // Copyright (C) 2007-2008 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: NMTTools_PaveFiller_5.cxx
23 // Created: Mon Dec 15 11:28:33 2003
24 // Author: Peter KURNEV
27 #include <NMTTools_PaveFiller.ixx>
29 #include <TColStd_IndexedMapOfInteger.hxx>
31 #include <BRep_Tool.hxx>
32 #include <BRep_Builder.hxx>
34 #include <Bnd_Box.hxx>
36 #include <TopAbs_ShapeEnum.hxx>
39 #include <TopoDS_Face.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <TopoDS_Vertex.hxx>
42 #include <TopoDS_Compound.hxx>
46 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <IntTools_ShrunkRange.hxx>
49 #include <IntTools_Range.hxx>
50 #include <IntTools_EdgeFace.hxx>
51 #include <IntTools_PContext.hxx>
52 #include <IntTools_SequenceOfCommonPrts.hxx>
53 #include <IntTools_CommonPrt.hxx>
54 #include <IntTools_Tools.hxx>
56 #include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
57 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
58 #include <BooleanOperations_OnceExplorer.hxx>
60 #include <BOPTools_Tools.hxx>
61 #include <BOPTools_Pave.hxx>
62 #include <BOPTools_PaveSet.hxx>
63 #include <BOPTools_ListOfPave.hxx>
64 #include <BOPTools_ListIteratorOfListOfPave.hxx>
65 #include <BOPTools_PaveBlock.hxx>
66 #include <BOPTools_ListOfPaveBlock.hxx>
67 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
68 #include <BOPTools_ESInterference.hxx>
70 #include <BOPTools_CArray1OfVVInterference.hxx>
71 #include <BOPTools_CArray1OfESInterference.hxx>
72 #include <BOPTools_VVInterference.hxx>
73 #include <BOPTools_ESInterference.hxx>
74 #include <BOPTools_IDMapOfPaveBlockIMapOfInteger.hxx>
75 #include <BOPTools_IMapOfPaveBlock.hxx>
77 #include <NMTDS_ShapesDataStructure.hxx>
78 #include <NMTDS_Iterator.hxx>
79 #include <NMTDS_InterfPool.hxx>
81 #include <NMTTools_ListOfCommonBlock.hxx>
82 #include <NMTTools_CommonBlockAPI.hxx>
83 #include <NMTTools_IndexedDataMapOfIndexedMapOfInteger.hxx>
84 #include <NMTTools_CommonBlockAPI.hxx>
85 #include <NMTTools_ListOfCommonBlock.hxx>
89 void VertexParameter(const IntTools_CommonPrt& aCPart,
92 Standard_Boolean IsOnPave(const Standard_Real& aTR,
93 const IntTools_Range& aCPRange,
94 const Standard_Real& aTolerance);
96 //=======================================================================
97 // function: PerformEF
99 //=======================================================================
100 void NMTTools_PaveFiller::PerformEF()
102 Standard_Boolean bJustAdd;
103 Standard_Integer n1, n2, anIndexIn, nE, nF, aNbEFs, aBlockLength;
104 Standard_Integer aDiscretize;
105 Standard_Real aTolE, aTolF, aDeflection;
106 BooleanOperations_IndexedDataMapOfShapeInteger aMapVI;
107 BOPTools_IDMapOfPaveBlockIMapOfInteger aMapCB;
108 BOPTools_IMapOfPaveBlock aIMPBx;
110 myIsDone=Standard_False;
114 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
116 myDSIt->Initialize(TopAbs_EDGE, TopAbs_FACE);
118 // BlockLength correction
119 aNbEFs=myDSIt->BlockLength();
120 aBlockLength=aEFs.BlockLength();
121 if (aNbEFs > aBlockLength) {
122 aEFs.SetBlockLength(aNbEFs);
125 for (; myDSIt->More(); myDSIt->Next()) {
126 myDSIt->Current(n1, n2, bJustAdd);
136 if (myDS->GetShapeType(n2)==TopAbs_EDGE) {
141 // all Common Blocks for face nF
142 NMTTools_ListOfCommonBlock aLCBF;
143 CommonBlocksFace(nF, aLCBF);
144 NMTTools_CommonBlockAPI aCBAPIF(aLCBF);
147 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));
148 if (BRep_Tool::Degenerated(aE)){
153 const TopoDS_Face aF=TopoDS::Face(myDS->Shape(nF));
155 TopTools_IndexedMapOfShape aME;
156 TopExp::MapShapes(aF, TopAbs_EDGE, aME);
157 if (aME.Contains(aE)) {
161 aTolF=BRep_Tool::Tolerance(aF);
162 aTolE=BRep_Tool::Tolerance(aE);
164 const Bnd_Box& aBBF=myDS->GetBoundingBox(nF);
166 // Process each PaveBlock on edge nE
167 BOPTools_ListOfPaveBlock& aLPB=mySplitShapesPool(myDS->RefEdge(nE));
169 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
170 for (; anIt.More(); anIt.Next()) {
171 BOPTools_PaveBlock& aPB=anIt.Value();
172 if (aCBAPIF.IsCommonBlock(aPB)) {
176 const IntTools_ShrunkRange& aShrunkRange=aPB.ShrunkRange();
177 const IntTools_Range& aSR =aShrunkRange.ShrunkRange();
178 const Bnd_Box& aBBE=aShrunkRange.BndBox();
180 if (aBBF.IsOut (aBBE)) {
185 IntTools_EdgeFace aEF;
190 aEF.SetDiscretize (aDiscretize);
191 aEF.SetDeflection (aDeflection);
193 aEF.SetContext((IntTools_PContext)&myContext);
195 IntTools_Range anewSR = aSR;
197 // Correction of the Shrunk Range
198 BOPTools_Tools::CorrectRange(aE, aF, aSR, anewSR);
199 aEF.SetRange (anewSR);
204 Standard_Boolean bCoinsideFlag;
205 Standard_Integer i, aNbCPrts;
206 TopAbs_ShapeEnum aType;
208 const IntTools_SequenceOfCommonPrts& aCPrts=aEF.CommonParts();
210 aNbCPrts=aCPrts.Length();
211 for (i=1; i<=aNbCPrts; ++i) {
214 const IntTools_CommonPrt& aCPart=aCPrts(i);
219 case TopAbs_VERTEX: {
220 Standard_Boolean bIsOnPave1, bIsOnPave2;
221 Standard_Integer nVF;
222 Standard_Real aT, aTolToDecide;
223 TopoDS_Vertex aNewVertex;
225 const IntTools_Range& aR=aCPart.Range1();
228 VertexParameter(aCPart, aT);
229 BOPTools_Tools::MakeNewVertex(aE, aT, aF, aNewVertex);
231 //decide to add pave or not
233 bIsOnPave1=IsOnPave(anewSR.First(), aR, aTolToDecide);
234 bIsOnPave2=IsOnPave(anewSR.Last() , aR, aTolToDecide);
236 if (!bIsOnPave1 && !bIsOnPave2) {
237 nVF=CheckFacePaves(aNewVertex, nF);
240 // Add Interference to the Pool
241 BOPTools_ESInterference anInterf (nE, nF, aCPart);
242 anIndexIn=aEFs.Append(anInterf);
243 anInterf.SetNewShape(0);
245 aMapVI.Add(aNewVertex, anIndexIn);
248 myIP->Add(nE, nF, Standard_True, NMTDS_TI_EF);
251 }// if (!bIsOnPave1 && !bIsOnPave2)
253 //modified by NIZNHY-PKV Fri Apr 18 10:55:38 2008f
255 const BOPTools_Pave& aPave=(bIsOnPave1)? aPB.Pave1() : aPB.Pave2();
257 const TopoDS_Vertex& aVF=TopoDS::Vertex(myDS->Shape(nVF));
258 BOPTools_Tools::UpdateVertex (aVF, aNewVertex);
260 //modified by NIZNHY-PKV Fri Apr 18 10:55:40 2008t
262 }// case TopAbs_VERTEX:
266 bCoinsideFlag=BOPTools_Tools::IsBlockInOnFace(aPB, aF, myContext);
267 if (!bCoinsideFlag) {
272 if (aMapCB.Contains(aPB)) {
273 TColStd_IndexedMapOfInteger& aMapF=aMapCB.ChangeFromKey(aPB);
277 TColStd_IndexedMapOfInteger aMapF;
279 aMapCB.Add(aPB, aMapF);
283 myIP->Add(nE, nF, Standard_True, NMTDS_TI_EF);
284 }// case TopAbs_EDGE:
290 } // for (i=1; i<=aNbCPrts; i++)
291 } //if (aEF.IsDone())
292 } // for (; anIt.More(); anIt.Next())
293 }// for (; myDSIt.More(); myDSIt.Next())
295 // Treat New vertices
296 EFNewVertices(aMapVI);
298 // Add draft Common Blocks of EF type
299 EFCommonBlocks(aMapCB);
301 // Collect all CB we suspected to split by new vertices
302 NMTTools_ListOfCommonBlock aLCBx;
304 Standard_Integer i, aNbPBx, nEx;
305 BOPTools_IMapOfPaveBlock aMx;
307 aNbPBx=aIMPBx.Extent();
308 for (i=1; i<=aNbPBx; ++i) {
309 const BOPTools_PaveBlock& aPBx=aIMPBx(i);
310 nEx=aPBx.OriginalEdge();
311 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nEx));
313 NMTTools_CommonBlockAPI aCBAPIx(aLCB);
314 if (aCBAPIx.IsCommonBlock(aPBx)) {
315 NMTTools_CommonBlock& aCBx=aCBAPIx.CommonBlock(aPBx);
316 const BOPTools_PaveBlock& aPB1=aCBx.PaveBlock1();
317 if (!aMx.Contains(aPB1)){
326 // Split the common blocks above
327 if (aLCBx.Extent()) {
328 ReplaceCommonBlocks(aLCBx);
331 myIsDone=Standard_True;
333 //=======================================================================
334 // function:EFCommonBlocks
336 //=======================================================================
337 void NMTTools_PaveFiller::EFCommonBlocks
338 (const BOPTools_IDMapOfPaveBlockIMapOfInteger& aMapCB)
340 Standard_Integer i, aNbPB, nE, j, aNbF, nF;
342 aNbPB=aMapCB.Extent();
343 for (i=1; i<=aNbPB; ++i) {
344 const BOPTools_PaveBlock& aPB=aMapCB.FindKey(i);
345 const TColStd_IndexedMapOfInteger& aMapF=aMapCB.FindFromIndex(i);
348 nE=aPB.OriginalEdge();
350 NMTTools_ListOfCommonBlock& aLCB=myCommonBlockPool(myDS->RefEdge(nE));
352 NMTTools_CommonBlockAPI aCBAPI(aLCB);
353 if (aCBAPI.IsCommonBlock(aPB)) {
354 NMTTools_CommonBlock& aCB=aCBAPI.CommonBlock(aPB);
355 for (j=1; j<=aNbF; ++j) {
361 NMTTools_CommonBlock aCB;
363 aCB.AddPaveBlock(aPB);
364 for (j=1; j<=aNbF; ++j) {
372 //=======================================================================
373 // function:EFNewVertices
375 //=======================================================================
376 void NMTTools_PaveFiller::EFNewVertices
377 (const BooleanOperations_IndexedDataMapOfShapeInteger& aMapVI)
379 Standard_Integer i, j, aNb, aNewShape, aFlag, iX, aNbVV, aNbSimple;
380 Standard_Integer aWhat, aWith, nE, nF, nV, aNbIEF, aNbEdges, iTmp;
382 TopoDS_Compound aCompound;
383 TopoDS_Vertex aNewVertex;
386 NMTTools_IndexedDataMapOfIndexedMapOfInteger aMNVE, aMNVIEF;
387 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
388 TopTools_IndexedMapOfShape aMNVComplex, aMNVSimple;
391 if (!aNb) { // no new vertices, no new problems
395 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
399 aNewVertex=TopoDS::Vertex(aMapVI.FindKey(1));
400 EFNewVertices(aNewVertex, aMapVI);
404 // 1. Make compound from new vertices
405 aBB.MakeCompound(aCompound);
406 for (i=1; i<=aNb; ++i) {
407 const TopoDS_Shape& aV=aMapVI.FindKey(i);
408 aBB.Add(aCompound, aV);
411 // 2. VV intersection between these vertices
412 // using the auxiliary Filler
413 NMTTools_PaveFiller tPF;
415 tPF.SetCompositeShape(aCompound);
420 NMTDS_ShapesDataStructure& tDS=*(tPF.DS());
421 NMTDS_InterfPool& tInterfPool=*(tPF.IP());
422 BOPTools_CArray1OfVVInterference& aVVInterfs=tInterfPool.VVInterferences();
424 // 3. Separate Comlex and Simple new vertices
425 aNbVV=aVVInterfs.Extent();
426 for (i=1; i<=aNbVV; ++i) {
427 const BOPTools_VVInterference& aVV=aVVInterfs(i);
428 aVV.Indices(aWhat, aWith);
429 const TopoDS_Shape& aV1=tDS.Shape(aWhat);
430 const TopoDS_Shape& aV2=tDS.Shape(aWith);
431 aMNVComplex.Add(aV1);
432 aMNVComplex.Add(aV2);
435 for (i=1; i<=aNb; ++i) {
436 const TopoDS_Shape& aV=aMapVI.FindKey(i);
437 if (!aMNVComplex.Contains(aV)) {
442 // 4. Treat Simple new Vertices
443 aNbSimple=aMNVSimple.Extent();
444 for (i=1; i<=aNbSimple; ++i) {
445 const TopoDS_Vertex& aV=TopoDS::Vertex(aMNVSimple(i));
446 EFNewVertices(aV, aMapVI);
449 // 3. Fill Maps : NewVertex-edges (aMNVE)
450 // NewVertex-interferences (aMNVIEE)
451 aNb=aVVInterfs.Extent();
452 for (i=1; i<=aNb; ++i) {
453 const BOPTools_VVInterference& aVV=aVVInterfs(i);
454 aNewShape=aVV.NewShape();
459 if (!aMNVE.Contains(aNewShape)) {
460 TColStd_IndexedMapOfInteger aMx;
461 aMNVE.Add(aNewShape, aMx);
463 if (!aMNVIEF.Contains(aNewShape)) {
464 TColStd_IndexedMapOfInteger aMx;
465 aMNVIEF.Add(aNewShape, aMx);
468 TColStd_IndexedMapOfInteger& aME=aMNVE.ChangeFromKey(aNewShape);
469 TColStd_IndexedMapOfInteger& aMIEF=aMNVIEF.ChangeFromKey(aNewShape);
471 aVV.Indices(aWhat, aWith);
473 const TopoDS_Shape& aV1=tDS.Shape(aWhat);
474 iX=aMapVI.FindFromKey(aV1);
475 const BOPTools_ESInterference& aEF1=aEFs(iX);
476 aEF1.Indices(nE, nF);
478 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
486 const TopoDS_Shape& aV2=tDS.Shape(aWith);
487 iX=aMapVI.FindFromKey(aV2);
488 const BOPTools_ESInterference& aEF2=aEFs(iX);
489 aEF2.Indices(nE, nF);
491 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
498 }// for (i=1; i<=aNb; ++i) {
500 // 4. Process new vertices
502 for (i=1; i<=aNb; ++i) { // xx
506 aNewVertex=TopoDS::Vertex(tDS.Shape(nV));
508 // Insert New Vertex in DS;
509 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
510 aNewShape=myDS->NumberOfInsertedShapes();
511 myDS->SetState (aNewShape, BooleanOperations_ON);
513 // Update index of NewShape in EF interferences
514 const TColStd_IndexedMapOfInteger& aMIEF=aMNVIEF.FindFromKey(nV);
515 aNbIEF=aMIEF.Extent();
516 for (j=1; j<=aNbIEF; ++j) {
518 BOPTools_ESInterference& aEF=aEFs(iX);
519 aEF.SetNewShape(aNewShape);
522 // Update Paves on all edges
523 const TColStd_IndexedMapOfInteger& aME=aMNVE(i);
524 aNbEdges=aME.Extent();
525 for (j=1; j<=aNbEdges; ++j) {
527 const TopoDS_Edge aE=TopoDS::Edge(myDS->Shape(nE));//mpv
529 aFlag=myContext.ComputeVE (aNewVertex, aE, aT);
532 aPave.SetInterference(-1);
533 aPave.SetType (BooleanOperations_EdgeSurface);
534 aPave.SetIndex(aNewShape);
537 BOPTools_PaveSet& aPaveSet=myPavePoolNew(myDS->RefEdge(nE));
538 aPaveSet.Append(aPave);
543 //=======================================================================
544 // function:EFNewVertices
546 //=======================================================================
547 void NMTTools_PaveFiller::EFNewVertices
548 (const TopoDS_Vertex& aNewVertex,
549 const BooleanOperations_IndexedDataMapOfShapeInteger& aMapVI)
551 Standard_Integer i, aNewShape, nE, nF;
554 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
556 BOPTools_CArray1OfESInterference& aEFs=myIP->ESInterferences();
558 // Insert New Vertex in DS;
559 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
560 aNewShape=myDS->NumberOfInsertedShapes();
561 myDS->SetState (aNewShape, BooleanOperations_ON);
563 // Insert New Vertex in EFInterference
564 i=aMapVI.FindFromKey(aNewVertex);
565 BOPTools_ESInterference& aEFInterf= aEFs(i);
566 aEFInterf.SetNewShape(aNewShape);
567 // Extract interference info
568 aEFInterf.Indices(nE, nF);
569 if (myDS->GetShapeType(nF)==TopAbs_EDGE) {
572 const IntTools_CommonPrt& aCPart=aEFInterf.CommonPrt();
573 VertexParameter(aCPart, aT);
576 aPave.SetInterference(i);
577 aPave.SetType (BooleanOperations_EdgeSurface);
578 aPave.SetIndex(aNewShape);
580 // Append the Pave to the myPavePoolNew
581 BOPTools_PaveSet& aPaveSet=myPavePoolNew(myDS->RefEdge(nE));
582 aPaveSet.Append(aPave);
585 //=======================================================================
586 // function: CheckFacePaves
588 //=======================================================================
589 Standard_Integer NMTTools_PaveFiller::CheckFacePaves
590 (const TopoDS_Vertex& aNewVertex,
591 const Standard_Integer nF)
593 Standard_Integer nEF, nVF, iFlag, i, aNbV, iRet;
594 BOPTools_ListIteratorOfListOfPave anIt;
595 TColStd_IndexedMapOfInteger aMVF;
599 BooleanOperations_OnceExplorer aExp(*myDS);
600 aExp.Init(nF, TopAbs_EDGE);
601 for (; aExp.More(); aExp.Next()) {
603 BOPTools_PaveSet& aPaveSet=myPavePool(myDS->RefEdge(nEF));
604 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
605 anIt.Initialize(aLP);
606 for (; anIt.More(); anIt.Next()) {
607 const BOPTools_Pave& aPave=anIt.Value();
614 for (i=1; i<=aNbV; ++i) {
616 const TopoDS_Vertex aVF=TopoDS::Vertex(myDS->Shape(nVF));
617 iFlag=IntTools_Tools::ComputeVV(aNewVertex, aVF);
625 //=======================================================================
626 // function: VertexParameter
628 //=======================================================================
629 void VertexParameter(const IntTools_CommonPrt& aCPart,
632 const IntTools_Range& aR=aCPart.Range1();
633 aT=0.5*(aR.First()+aR.Last());
634 if((aCPart.VertexParameter1() >= aR.First()) &&
635 (aCPart.VertexParameter1() <= aR.Last())) {
636 aT = aCPart.VertexParameter1();
639 //=======================================================================
640 // function: IsOnPave
642 //=======================================================================
643 Standard_Boolean IsOnPave(const Standard_Real& aTR,
644 const IntTools_Range& aCPRange,
645 const Standard_Real& aTolerance)
647 Standard_Boolean bIsOnPave;
648 Standard_Real aT1, aT2, dT1, dT2;
650 aT1=aCPRange.First();
652 bIsOnPave=(aTR>=aT1 && aTR<=aT1);
659 bIsOnPave=(dT1<=aTolerance || dT2<=aTolerance);