1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and/or modify it under
10 // the terms of the GNU Lesser General Public License version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPAlgo_PaveFiller.ixx>
20 #include <NCollection_IncAllocator.hxx>
22 #include <Bnd_Box.hxx>
24 #include <TopoDS_Vertex.hxx>
25 #include <TopoDS_Edge.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <BRep_Tool.hxx>
29 #include <IntTools_EdgeFace.hxx>
30 #include <IntTools_Range.hxx>
31 #include <IntTools_SequenceOfCommonPrts.hxx>
32 #include <IntTools_CommonPrt.hxx>
33 #include <BOPTools_AlgoTools.hxx>
35 #include <BOPCol_MapOfInteger.hxx>
37 #include <BOPInt_Context.hxx>
39 #include <BOPDS_Interf.hxx>
40 #include <BOPDS_Iterator.hxx>
41 #include <BOPDS_PaveBlock.hxx>
42 #include <BOPDS_MapOfPaveBlock.hxx>
43 #include <BOPDS_DataMapOfPaveBlockListOfInteger.hxx>
44 #include <BOPDS_CommonBlock.hxx>
45 #include <BOPDS_Pave.hxx>
47 #include <BOPTools_AlgoTools.hxx>
48 #include <BOPDS_CoupleOfPaveBlocks.hxx>
49 #include <BRepBndLib.hxx>
50 #include <BOPAlgo_Tools.hxx>
51 #include <BOPInt_Tools.hxx>
52 #include <BRepAdaptor_Curve.hxx>
53 #include <BRep_Builder.hxx>
54 #include <GeomAPI_ProjectPointOnSurf.hxx>
57 //=======================================================================
58 //function : PerformEF
60 //=======================================================================
61 void BOPAlgo_PaveFiller::PerformEF()
63 Standard_Integer iSize;
67 myIterator->Initialize(TopAbs_EDGE, TopAbs_FACE);
68 iSize=myIterator->ExpectedLength();
72 //----------------------------------------------------------------------
73 Standard_Boolean bJustAdd, bV[2];
74 Standard_Integer nE, nF, aDiscretize, i, aNbCPrts, iX, nV[2];
75 Standard_Real aTolE, aTolF, aTS1, aTS2, aT1, aT2, aDeflection;
76 Handle(NCollection_IncAllocator) aAllocator;
77 TopAbs_ShapeEnum aType;
78 BOPDS_ListIteratorOfListOfPaveBlock aIt;
79 //-----------------------------------------------------scope f
83 aAllocator=new NCollection_IncAllocator();
85 BOPCol_MapOfInteger aMIEFC(100, aAllocator);
86 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMVCPB(100, aAllocator);
87 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, aAllocator);
92 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
93 aEFs.SetStartSize(iSize);
94 aEFs.SetIncrement(iSize);
97 for (; myIterator->More(); myIterator->Next()) {
98 myIterator->Value(nE, nF, bJustAdd);
103 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
104 if (aSIE.HasFlag()){//degenerated
108 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
109 const TopoDS_Face& aF=(*(TopoDS_Face *)(&myDS->Shape(nF)));
110 const Bnd_Box& aBBF=myDS->ShapeInfo(nF).Box();
112 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
113 const BOPDS_IndexedMapOfPaveBlock& aMPBF=aFI.PaveBlocksOn();
114 const BOPCol_MapOfInteger& aMIFOn=aFI.VerticesOn();
115 const BOPCol_MapOfInteger& aMIFIn=aFI.VerticesIn();
117 aTolE=BRep_Tool::Tolerance(aE);
118 aTolF=BRep_Tool::Tolerance(aF);
120 BOPDS_ListOfPaveBlock& aLPB=myDS->ChangePaveBlocks(nE);
121 aIt.Initialize(aLPB);
122 for (; aIt.More(); aIt.Next()) {
123 Handle(BOPDS_PaveBlock)& aPB=aIt.ChangeValue();
125 const Handle(BOPDS_PaveBlock) aPBR=myDS->RealPaveBlock(aPB);
126 if (aMPBF.Contains(aPBR)) {
130 if (!aPB->HasShrunkData()) {
132 if (myWarningStatus) {
138 aPB->ShrunkData(aTS1, aTS2, aBBE);
140 if (aBBF.IsOut (aBBE)) {
145 IntTools_EdgeFace aEdgeFace;
147 aEdgeFace.SetEdge (aE);
148 aEdgeFace.SetFace (aF);
149 aEdgeFace.SetTolE (aTolE);
150 aEdgeFace.SetTolF (aTolF);
151 aEdgeFace.SetDiscretize (aDiscretize);
152 aEdgeFace.SetDeflection (aDeflection);
153 aEdgeFace.SetContext(myContext);
155 IntTools_Range aSR(aTS1, aTS2);
156 IntTools_Range anewSR=aSR;
157 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, anewSR);
159 aPB->Range(aT1, aT2);
160 IntTools_Range aPBRange(aT1, aT2);
162 BOPTools_AlgoTools::CorrectRange(aE, aF, aSR, aPBRange);
164 aEdgeFace.SetRange (aPBRange);
167 if (!aEdgeFace.IsDone()) {
171 aPB->Indices(nV[0], nV[1]);
173 const IntTools_SequenceOfCommonPrts& aCPrts=aEdgeFace.CommonParts();
174 aNbCPrts=aCPrts.Length();
175 for (i=1; i<=aNbCPrts; ++i) {
176 const IntTools_CommonPrt& aCPart=aCPrts(i);
179 case TopAbs_VERTEX: {
180 Standard_Boolean bIsOnPave[2];
182 Standard_Real aT, aTolToDecide;
185 BOPInt_Tools::VertexParameter(aCPart, aT);
186 BOPTools_AlgoTools::MakeNewVertex(aE, aT, aF, aVnew);
188 const IntTools_Range& aR=aCPart.Range1();
191 IntTools_Range aR1(aT1, anewSR.First()), aR2(anewSR.Last(), aT2);
193 bIsOnPave[0]=BOPInt_Tools::IsInRange(aR1, aR, aTolToDecide);
194 bIsOnPave[1]=BOPInt_Tools::IsInRange(aR2, aR, aTolToDecide);
196 if (bIsOnPave[0] && bIsOnPave[1]) {
197 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
198 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
199 if (bV[0] && bV[1]) {
201 IntTools_CommonPrt aCP = aCPart;
202 aCP.SetType(TopAbs_EDGE);
203 BOPDS_InterfEF& aEF=aEFs(iX);
204 aEF.SetIndices(nE, nF);
205 aEF.SetCommonPart(aCP);
206 myDS->AddInterf(nE, nF);
208 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
212 for (j=0; j<2; ++j) {
214 bV[j]=CheckFacePaves(nV[j], aMIFOn, aMIFIn);
216 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV[j])));
217 BOPTools_AlgoTools::UpdateVertex(aE, aT, aV);
218 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV[j]);
219 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
220 BRepBndLib::Add(aV, aBoxDS);
223 bIsOnPave[j] = ForceInterfVF(nV[j], nF);
228 if (!bIsOnPave[0] && !bIsOnPave[1]) {
229 if (CheckFacePaves(aVnew, aMIFOn)) {
233 const gp_Pnt& aPnew = BRep_Tool::Pnt(aVnew);
234 if (!myContext->IsValidPointForFace(aPnew, aF, aTolE+aTolF)) {
238 aBB.UpdateVertex(aVnew, aTolE);
243 BOPDS_InterfEF& aEF=aEFs(iX);
244 aEF.SetIndices(nE, nF);
245 aEF.SetCommonPart(aCPart);
247 myDS->AddInterf(nE, nF);
249 BOPDS_CoupleOfPaveBlocks aCPB;
251 aCPB.SetPaveBlocks(aPB, aPB);
252 aCPB.SetIndexInterf(iX);
253 aMVCPB.Add(aVnew, aCPB);
262 BOPDS_InterfEF& aEF=aEFs(iX);
263 aEF.SetIndices(nE, nF);
265 bV[0]=CheckFacePaves(nV[0], aMIFOn, aMIFIn);
266 bV[1]=CheckFacePaves(nV[1], aMIFOn, aMIFIn);
267 if (!bV[0] || !bV[1]) {
268 myDS->AddInterf(nE, nF);
271 //update tolerance of edge if needed
273 myDS->UpdateEdgeTolerance(nE, aTolF);
276 aEF.SetCommonPart(aCPart);
278 myDS->AddInterf(nE, nF);
280 BOPAlgo_Tools::FillMap(aPB, nF, aMPBLI, aAllocator);
287 }//for (i=1; i<=aNbCPrts; ++i) {
289 }//for (; aIt.More(); aIt.Next()) {
290 }//for (; myIterator->More(); myIterator->Next()) {
292 //=========================================
294 //=========================================
295 BOPAlgo_Tools::PerformCommonBlocks(aMPBLI, aAllocator, myDS);
296 PerformVerticesEF(aMVCPB, aAllocator);
298 // Update FaceInfoIn for all faces having EF common parts
299 BOPCol_MapIteratorOfMapOfInteger aItMI;
300 aItMI.Initialize(aMIEFC);
301 for (; aItMI.More(); aItMI.Next()) {
303 myDS->UpdateFaceInfoIn(nF);
305 // Refine FaceInfoOn to remove all formal pave blocks
306 // made during EF processing
307 //myDS->RefineFaceInfoOn();
308 //-----------------------------------------------------scope t
312 aAllocator.Nullify();
316 //=======================================================================
317 //function : PerformVertices1
319 //=======================================================================
320 Standard_Integer BOPAlgo_PaveFiller::PerformVerticesEF
321 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMVCPB,
322 Handle(NCollection_BaseAllocator)& theAllocator)
324 Standard_Integer aNbV, iRet;
327 aNbV=theMVCPB.Extent();
332 Standard_Integer nVx, nVSD, iV, iErr, nE, iFlag, iX, i, aNbPBLI;
335 BOPCol_ListIteratorOfListOfShape aItLS;
336 BOPCol_ListIteratorOfListOfInteger aItLI;
341 BOPCol_ListOfShape aLS(theAllocator);
342 BOPCol_DataMapOfShapeInteger aMVI(100, theAllocator);
343 BOPDS_IndexedDataMapOfPaveBlockListOfInteger aMPBLI(100, theAllocator);
344 BOPAlgo_PaveFiller aPF(theAllocator);
346 aSI.SetShapeType(TopAbs_VERTEX);
347 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
349 // 1 prepare arguments
350 for (i=1; i<=aNbV; ++i) {
351 const TopoDS_Shape& aS=theMVCPB.FindKey(i);
356 aPF.SetArguments(aLS);
358 iErr=aPF.ErrorStatus();
365 // 3 Add new vertices to theDS;
366 // 4 Map PaveBlock/ListOfVertices to add to this PaveBlock ->aMPBLI
367 aItLS.Initialize(aLS);
368 for (; aItLS.More(); aItLS.Next()) {
369 const TopoDS_Shape& aVx=aItLS.Value();
370 nVx=aPDS->Index(aVx);
372 if (aPDS->HasShapeSD(nVx, nVSD)) {
373 aV=aPDS->Shape(nVSD);
378 // index of new vertex in theDS -> iV
379 if (!aMVI.IsBound(aV)) {
381 iV=myDS->Append(aSI);
383 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(iV);
384 Bnd_Box& aBox=aSIDS.ChangeBox();
385 BRepBndLib::Add(aV, aBox);
393 BOPDS_CoupleOfPaveBlocks &aCPB=theMVCPB.ChangeFromKey(aVx);
395 // update EF interference
396 iX=aCPB.IndexInterf();
397 BOPDS_InterfEF& aEF=aEFs(iX);
400 const Handle(BOPDS_PaveBlock)& aPB=aCPB.PaveBlock1();
401 if (aMPBLI.Contains(aPB)) {
402 BOPCol_ListOfInteger& aLI=aMPBLI.ChangeFromKey(aPB);
406 BOPCol_ListOfInteger aLI(theAllocator);
408 aMPBLI.Add(aPB, aLI);
413 // 5.1 Compute Extra Paves and
414 // 5.2. Add Extra Paves to the PaveBlocks
415 aNbPBLI=aMPBLI.Extent();
416 for (i=1; i<=aNbPBLI; ++i) {
417 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
418 const BOPCol_ListOfInteger& aLI=aMPBLI.FindFromIndex(i);
419 nE=aPB->OriginalEdge();
420 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&myDS->Shape(nE)));
422 aItLI.Initialize(aLI);
423 for (; aItLI.More(); aItLI.Next()) {
425 const TopoDS_Vertex& aVx=(*(TopoDS_Vertex *)(&myDS->Shape(nVx)));
427 iFlag=myContext->ComputeVE (aVx, aE, aT);
430 aPave.SetParameter(aT);
431 aPB->AppendExtPave(aPave);
435 // 6 Split PaveBlocksa
436 for (i=1; i<=aNbPBLI; ++i) {
437 Handle(BOPDS_PaveBlock) aPB=aMPBLI.FindKey(i);
438 nE=aPB->OriginalEdge();
440 if (!myDS->IsCommonBlock(aPB)) {
441 myDS->UpdatePaveBlock(aPB);
444 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
445 myDS->UpdateCommonBlock(aCB);
447 }//for (; aItMPBLI.More(); aItMPBLI.Next()) {
451 //=======================================================================
452 // function: CheckFacePaves
454 //=======================================================================
455 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves (const Standard_Integer nVx,
456 const BOPCol_MapOfInteger& aMIFOn,
457 const BOPCol_MapOfInteger& aMIFIn)
459 Standard_Boolean bRet;
461 BOPCol_MapIteratorOfMapOfInteger aIt;
465 aIt.Initialize(aMIFOn);
466 for (; aIt.More(); aIt.Next()) {
473 aIt.Initialize(aMIFIn);
474 for (; aIt.More(); aIt.Next()) {
484 //=======================================================================
485 // function: CheckFacePaves
487 //=======================================================================
488 Standard_Boolean BOPAlgo_PaveFiller::CheckFacePaves (const TopoDS_Vertex& aVnew,
489 const BOPCol_MapOfInteger& aMIF)
491 Standard_Boolean bRet;
492 Standard_Integer nV, iFlag;
493 BOPCol_MapIteratorOfMapOfInteger aIt;
497 aIt.Initialize(aMIF);
498 for (; aIt.More(); aIt.Next()) {
500 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
501 iFlag=BOPTools_AlgoTools::ComputeVV(aVnew, aV);
509 //=======================================================================
510 //function : ForceInterfVF
512 //=======================================================================
513 Standard_Boolean BOPAlgo_PaveFiller::ForceInterfVF(const Standard_Integer nV,
514 const Standard_Integer nF)
516 Standard_Boolean bRet;
518 bRet = Standard_False;
519 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV);
520 const TopoDS_Face& aF = *(TopoDS_Face*) &myDS->Shape(nF);
522 GeomAPI_ProjectPointOnSurf& aProj = myContext->ProjPS(aF);
523 const gp_Pnt& aP = BRep_Tool::Pnt(aV);
525 if (!aProj.IsDone()) {
528 Standard_Real aDist, U, V;
530 aDist=aProj.LowerDistance();
531 aProj.LowerDistanceParameters(U, V);
534 bRet = myContext->IsPointInFace (aF, aP2d);
539 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
541 BOPDS_InterfVF& aVF=aVFs(i);
542 aVF.SetIndices(nV, nF);
545 myDS->AddInterf(nV, nF);
547 aBB.UpdateVertex(aV, aDist);
548 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
549 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
550 BRepBndLib::Add(aV, aBoxDS);
552 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(nF);
553 BOPCol_MapOfInteger& aMVIn=aFI.ChangeVerticesIn();