0025242: Wrong result of cut operation.
[occt.git] / src / BOPAlgo / BOPAlgo_PaveFiller_6.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 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
6//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
d5f74e42 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
973c2be1 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.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
18#include <BOPAlgo_PaveFiller.ixx>
465d1fba 19//
4e57c75e 20#include <Precision.hxx>
21#include <NCollection_IncAllocator.hxx>
22#include <Bnd_Box.hxx>
23
24#include <Geom_Curve.hxx>
25#include <Geom2d_Curve.hxx>
26
27#include <GeomAPI_ProjectPointOnCurve.hxx>
28#include <GeomAPI_ProjectPointOnSurf.hxx>
29
30#include <TopoDS_Edge.hxx>
31#include <TopoDS_Face.hxx>
32#include <TopoDS_Vertex.hxx>
33#include <TopoDS_Compound.hxx>
34
35#include <TopExp_Explorer.hxx>
36
37#include <BRep_Builder.hxx>
38#include <BRep_Tool.hxx>
39
40#include <BRepBndLib.hxx>
41#include <BRepTools.hxx>
42
43#include <BRepAdaptor_Curve.hxx>
44#include <BRepAdaptor_Surface.hxx>
45
46#include <IntTools_FaceFace.hxx>
47#include <IntTools_SequenceOfCurves.hxx>
48#include <IntTools_SequenceOfPntOn2Faces.hxx>
49#include <IntTools_Curve.hxx>
50#include <IntTools_PntOn2Faces.hxx>
51#include <IntTools_Tools.hxx>
52
53#include <IntSurf_ListOfPntOn2S.hxx>
54#include <IntSurf_PntOn2S.hxx>
55
56#include <BOPTools_AlgoTools.hxx>
57#include <BOPTools_AlgoTools3D.hxx>
58
59#include <BOPCol_MapOfInteger.hxx>
60#include <BOPCol_ListOfShape.hxx>
61#include <BOPCol_DataMapOfShapeInteger.hxx>
62#include <BOPCol_ListOfInteger.hxx>
63#include <BOPCol_IndexedMapOfInteger.hxx>
b4109929 64#include <BOPCol_DataMapOfIntegerReal.hxx>
a2098360 65#include <BOPCol_NCVector.hxx>
66#include <BOPCol_TBB.hxx>
4e57c75e 67
1e143abb 68#include <IntTools_Context.hxx>
69#include <IntTools_Tools.hxx>
4e57c75e 70
71#include <BOPDS_Interf.hxx>
72#include <BOPDS_Iterator.hxx>
73#include <BOPDS_Curve.hxx>
74#include <BOPDS_Point.hxx>
75#include <BOPDS_FaceInfo.hxx>
76#include <BOPDS_Curve.hxx>
77#include <BOPDS_MapOfPaveBlock.hxx>
78#include <BOPDS_PaveBlock.hxx>
79#include <BOPDS_VectorOfCurve.hxx>
80#include <BOPDS_VectorOfPoint.hxx>
81#include <BOPDS_ShapeInfo.hxx>
82#include <BOPDS_PaveBlock.hxx>
83#include <BOPDS_ListOfPave.hxx>
84#include <BOPDS_ListOfPaveBlock.hxx>
85#include <BOPDS_CoupleOfPaveBlocks.hxx>
86#include <BOPDS_FaceInfo.hxx>
87#include <BOPDS_CommonBlock.hxx>
88
89#include <BOPAlgo_Tools.hxx>
90#include <BRepBuilderAPI_MakeVertex.hxx>
91#include <TopExp.hxx>
1e143abb 92#include <IntTools_ShrunkRange.hxx>
4e57c75e 93#include <BOPDS_DataMapOfPaveBlockListOfPaveBlock.hxx>
94
b4109929 95static void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
96 const BRepAdaptor_Surface& aBAS2,
4e57c75e 97 Standard_Real& aTolFF);
98
a2098360 99/////////////////////////////////////////////////////////////////////////
100//=======================================================================
101//class : BOPAlgo_FaceFace
102//purpose :
103//=======================================================================
36f4947b 104class BOPAlgo_FaceFace :
105 public IntTools_FaceFace,
106 public BOPAlgo_Algo {
107
a2098360 108 public:
36f4947b 109 DEFINE_STANDARD_ALLOC
110
111 BOPAlgo_FaceFace() :
112 IntTools_FaceFace(),
113 BOPAlgo_Algo(),
114 myIF1(-1), myIF2(-1), myTolFF(1.e-7) {
a2098360 115 }
116 //
36f4947b 117 virtual ~BOPAlgo_FaceFace() {
a2098360 118 }
119 //
120 void SetIndices(const Standard_Integer nF1,
121 const Standard_Integer nF2) {
122 myIF1=nF1;
123 myIF2=nF2;
124 }
125 //
126 void Indices(Standard_Integer& nF1,
127 Standard_Integer& nF2) const {
128 nF1=myIF1;
129 nF2=myIF2;
130 }
131 //
132 void SetFaces(const TopoDS_Face& aF1,
133 const TopoDS_Face& aF2) {
134 myF1=aF1;
135 myF2=aF2;
136 }
137 //
138 const TopoDS_Face& Face1()const {
139 return myF1;
140 }
141 //
142 const TopoDS_Face& Face2()const {
143 return myF2;
144 }
145 //
146 void SetTolFF(const Standard_Real aTolFF) {
147 myTolFF=aTolFF;
148 }
149 //
150 Standard_Real TolFF() const{
151 return myTolFF;
152 }
153 //
36f4947b 154 virtual void Perform() {
155 BOPAlgo_Algo::UserBreak();
a2098360 156 IntTools_FaceFace::Perform(myF1, myF2);
157 }
158 //
159 protected:
160 Standard_Integer myIF1;
161 Standard_Integer myIF2;
162 Standard_Real myTolFF;
163 TopoDS_Face myF1;
164 TopoDS_Face myF2;
165};
166//
167//=======================================================================
168typedef BOPCol_NCVector
169 <BOPAlgo_FaceFace> BOPAlgo_VectorOfFaceFace;
170//
171typedef BOPCol_TBBFunctor
172 <BOPAlgo_FaceFace,
173 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceFunctor;
174//
175typedef BOPCol_TBBCnt
176 <BOPAlgo_FaceFaceFunctor,
177 BOPAlgo_VectorOfFaceFace> BOPAlgo_FaceFaceCnt;
178/////////////////////////////////////////////////////////////////////////
4e57c75e 179//=======================================================================
180//function : PerformFF
181//purpose :
182//=======================================================================
7ff8f019 183void BOPAlgo_PaveFiller::PerformFF()
4e57c75e 184{
185 Standard_Integer iSize;
186 Standard_Boolean bValid;
187 //
188 myErrorStatus=0;
189 //
190 myIterator->Initialize(TopAbs_FACE, TopAbs_FACE);
191 iSize=myIterator->ExpectedLength();
192 if (!iSize) {
193 return;
194 }
195 //
196 Standard_Boolean bJustAdd, bApp, bCompC2D1, bCompC2D2, bIsDone;
7ff8f019 197 Standard_Boolean bToSplit, bTangentFaces;
4e57c75e 198 Standard_Integer nF1, nF2, aNbCurves, aNbPoints, iX, i, iP, iC, aNbLP;
a2098360 199 Standard_Integer aNbFaceFace, k;
4e57c75e 200 Standard_Real aApproxTol, aTolR3D, aTolR2D, aTolFF;
b4109929 201 BRepAdaptor_Surface aBAS1, aBAS2;
af4e6dab 202 BOPCol_MapOfInteger aMI;
a2098360 203 BOPAlgo_VectorOfFaceFace aVFaceFace;
4e57c75e 204 //
205 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
206 aFFs.SetStartSize(iSize);
207 aFFs.SetIncrement(iSize);
208 aFFs.Init();
209 //
210 bApp=mySectionAttribute.Approximation();
211 bCompC2D1=mySectionAttribute.PCurveOnS1();
212 bCompC2D2=mySectionAttribute.PCurveOnS2();
213 aApproxTol=1.e-7;
214 bToSplit = Standard_False;
215 //
216 for (; myIterator->More(); myIterator->Next()) {
217 myIterator->Value(nF1, nF2, bJustAdd);
218 if(bJustAdd) {
219 continue;
220 }
221 //
222 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
223 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
224 //
b4109929 225 aBAS1.Initialize(aF1, Standard_False);
226 aBAS2.Initialize(aF2, Standard_False);
227 //
228 if (aBAS1.GetType() == GeomAbs_Plane &&
229 aBAS2.GetType() == GeomAbs_Plane) {
230 Standard_Boolean bToIntersect;
231 //
af4e6dab 232 if (aMI.Add(nF1)) {
78c66ef1 233 myDS->UpdateFaceInfoOn(nF1);
234 myDS->UpdateFaceInfoIn(nF1);
af4e6dab 235 }
236 if (aMI.Add(nF2)) {
78c66ef1 237 myDS->UpdateFaceInfoOn(nF2);
238 myDS->UpdateFaceInfoIn(nF2);
af4e6dab 239 }
240 //
b4109929 241 bToIntersect = CheckPlanes(nF1, nF2);
242 if (!bToIntersect) {
243 myDS->AddInterf(nF1, nF2);
244 iX=aFFs.Append()-1;
245 BOPDS_InterfFF& aFF=aFFs(iX);
246 aFF.SetIndices(nF1, nF2);
247 aFF.Init(0, 0);
248 continue;
249 }
250 }
251 //
a2098360 252 ToleranceFF(aBAS1, aBAS2, aTolFF);
253 //
254 BOPAlgo_FaceFace& aFaceFace=aVFaceFace.Append1();
255 //
256 aFaceFace.SetIndices(nF1, nF2);
257 aFaceFace.SetFaces(aF1, aF2);
258 aFaceFace.SetTolFF(aTolFF);
4e57c75e 259 //
260 IntSurf_ListOfPntOn2S aListOfPnts;
261 GetEFPnts(nF1, nF2, aListOfPnts);
262 aNbLP = aListOfPnts.Extent();
263 if (aNbLP) {
264 aFaceFace.SetList(aListOfPnts);
265 }
a2098360 266 //
4e57c75e 267 aFaceFace.SetParameters(bApp, bCompC2D1, bCompC2D2, aApproxTol);
36f4947b 268 aFaceFace.SetProgressIndicator(myProgressIndicator);
a2098360 269 }//for (; myIterator->More(); myIterator->Next()) {
270 //
271 aNbFaceFace=aVFaceFace.Extent();
272 //======================================================
273 BOPAlgo_FaceFaceCnt::Perform(myRunParallel, aVFaceFace);
274 //======================================================
275 //
276 for (k=0; k < aNbFaceFace; ++k) {
277 BOPAlgo_FaceFace& aFaceFace=aVFaceFace(k);
278 //
279 aFaceFace.Indices(nF1, nF2);
280 aTolFF=aFaceFace.TolFF();
4e57c75e 281 //
282 bIsDone=aFaceFace.IsDone();
283 if (bIsDone) {
284 aTolR3D=aFaceFace.TolReached3d();
285 aTolR2D=aFaceFace.TolReached2d();
7ff8f019 286 bTangentFaces=aFaceFace.TangentFaces();
4e57c75e 287 //
4e57c75e 288 if (aTolR3D < aTolFF){
289 aTolR3D=aTolFF;
290 }
291 if (aTolR2D < 1.e-7){
292 aTolR2D=1.e-7;
293 }
294 //
295 aFaceFace.PrepareLines3D(bToSplit);
296 //
297 const IntTools_SequenceOfCurves& aCvsX=aFaceFace.Lines();
298 const IntTools_SequenceOfPntOn2Faces& aPntsX=aFaceFace.Points();
299 //
300 aNbCurves=aCvsX.Length();
301 aNbPoints=aPntsX.Length();
302 //
955b3e71 303 if (aNbCurves || aNbPoints) {
304 myDS->AddInterf(nF1, nF2);
305 }
4e57c75e 306 //
307 iX=aFFs.Append()-1;
308 BOPDS_InterfFF& aFF=aFFs(iX);
309 aFF.SetIndices(nF1, nF2);
310 //
311 aFF.SetTolR3D(aTolR3D);
312 aFF.SetTolR2D(aTolR2D);
7ff8f019 313 aFF.SetTangentFaces(bTangentFaces);
4e57c75e 314 //
315 // Curves, Points
316 aFF.Init(aNbCurves, aNbPoints);
317 //
318 // Curves
319 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
320 for (i=1; i<=aNbCurves; ++i) {
321 Bnd_Box aBox;
322 //
323 const IntTools_Curve& aIC=aCvsX(i);
324 const Handle(Geom_Curve)& aC3D= aIC.Curve();
1e143abb 325 bValid=IntTools_Tools::CheckCurve(aC3D, aTolR3D, aBox);
4e57c75e 326 if (bValid) {
327 iC=aVNC.Append()-1;
328 BOPDS_Curve& aNC=aVNC(iC);
329 aNC.SetCurve(aIC);
330 aNC.SetBox(aBox);
331 }
332 }
333 //
334 // Points
335 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
336 for (i=1; i<=aNbPoints; ++i) {
337 const IntTools_PntOn2Faces& aPi=aPntsX(i);
338 const gp_Pnt& aP=aPi.P1().Pnt();
339 //
340 iP=aVNP.Append()-1;
341 BOPDS_Point& aNP=aVNP(iP);
342 aNP.SetPnt(aP);
343 }
344 //}// if (aNbCs || aNbPs)
345 }// if (bIsDone) {
346 else {// 904/L1
347 iX=aFFs.Append()-1;
348 BOPDS_InterfFF& aFF=aFFs(iX);
349 aFF.SetIndices(nF1, nF2);
350 aNbCurves=0;
351 aNbPoints=0;
352 aFF.Init(aNbCurves, aNbPoints);
353 }
a2098360 354 }// for (k=0; k < aNbFaceFace; ++k) {
4e57c75e 355}
356//=======================================================================
357//function : MakeBlocks
358//purpose :
359//=======================================================================
78c66ef1 360void BOPAlgo_PaveFiller::MakeBlocks()
4e57c75e 361{
362 Standard_Integer aNbFF;
363 //
364 myErrorStatus=0;
365 //
366 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
367 aNbFF=aFFs.Extent();
368 if (!aNbFF) {
369 return;
370 }
371 //
372 Standard_Boolean bExist, bValid2D;
373 Standard_Integer i, nF1, nF2, aNbC, aNbP, j;
374 Standard_Integer nV1, nV2;
96a95605 375 Standard_Real aTolR3D, aT1, aT2, aTol;
4e57c75e 376 Handle(NCollection_IncAllocator) aAllocator;
377 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
378 TopoDS_Edge aES;
379 Handle(BOPDS_PaveBlock) aPBOut;
380 //
381 //-----------------------------------------------------scope f
382 aAllocator=new NCollection_IncAllocator();
383 //
384 BOPCol_ListOfInteger aLSE(aAllocator);
385 BOPCol_MapOfInteger aMVOnIn(100, aAllocator), aMF(100, aAllocator),
386 aMVStick(100,aAllocator), aMVEF(100, aAllocator),
78c66ef1 387 aMVB(100, aAllocator), aMI(100, aAllocator);
decdfc94 388 BOPDS_IndexedMapOfPaveBlock aMPBOnIn(100, aAllocator);
389 BOPDS_MapOfPaveBlock aMPBAdd(100, aAllocator);
4e57c75e 390 BOPDS_ListOfPaveBlock aLPB(aAllocator);
391 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks aMSCPB(100, aAllocator);
392 BOPCol_DataMapOfShapeInteger aMVI(100, aAllocator);
78c66ef1 393 BOPDS_DataMapOfPaveBlockListOfPaveBlock aDMExEdges(100, aAllocator);
b4109929 394 BOPCol_DataMapOfIntegerReal aMVTol(100, aAllocator);
395 BOPCol_DataMapIteratorOfDataMapOfIntegerReal aItMV;
78c66ef1 396 BOPCol_DataMapOfIntegerInteger aDMI(100, aAllocator);
4e57c75e 397 //
398 for (i=0; i<aNbFF; ++i) {
36f4947b 399 //
400 UserBreak();
401 //
4e57c75e 402 BOPDS_InterfFF& aFF=aFFs(i);
403 aFF.Indices(nF1, nF2);
404 //
405 BOPDS_VectorOfPoint& aVP=aFF.ChangePoints();
406 aNbP=aVP.Extent();
407 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
408 aNbC=aVC.Extent();
409 if (!aNbP && !aNbC) {
410 continue;
411 }
412 //
413 const TopoDS_Face& aF1=(*(TopoDS_Face *)(&myDS->Shape(nF1)));
414 const TopoDS_Face& aF2=(*(TopoDS_Face *)(&myDS->Shape(nF2)));
415 //
416 aTolR3D=aFF.TolR3D();
4e57c75e 417 //
418 // Update face info
419 if (aMF.Add(nF1)) {
420 myDS->UpdateFaceInfoOn(nF1);
421 }
422 if (aMF.Add(nF2)) {
423 myDS->UpdateFaceInfoOn(nF2);
424 }
425
426 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
427 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
428 //
429 aMVOnIn.Clear();
430 aMPBOnIn.Clear();
431 aMVB.Clear();
b4109929 432 aMVTol.Clear();
4e57c75e 433 //
434 myDS->VerticesOnIn(nF1, nF2, aMVOnIn, aMPBOnIn);
435 myDS->SharedEdges(nF1, nF2, aLSE, aAllocator);
436
437 // 1. Treat Points
438 for (j=0; j<aNbP; ++j) {
439 TopoDS_Vertex aV;
440 BOPDS_CoupleOfPaveBlocks aCPB;
441 //
442 BOPDS_Point& aNP=aVP.ChangeValue(j);
443 const gp_Pnt& aP=aNP.Pnt();
444 //
445 bExist=IsExistingVertex(aP, aTolR3D, aMVOnIn);
446 if (!bExist) {
447 BOPTools_AlgoTools::MakeNewVertex(aP, aTolR3D, aV);
448 //
449 aCPB.SetIndexInterf(i);
450 aCPB.SetIndex(j);
451 aMSCPB.Add(aV, aCPB);
452 }
453 }
454 //
455 // 2. Treat Curves
456 aMVStick.Clear();
457 aMVEF.Clear();
78c66ef1 458 GetStickVertices(nF1, nF2, aMVStick, aMVEF, aMI);
4e57c75e 459 //
460 for (j=0; j<aNbC; ++j) {
461 BOPDS_Curve& aNC=aVC.ChangeValue(j);
462 const IntTools_Curve& aIC=aNC.Curve();
4e57c75e 463 // DEBt
464 aNC.InitPaveBlock1();
465 //
78c66ef1 466 PutPavesOnCurve(aMVOnIn, aTolR3D, aNC, nF1, nF2, aMI, aMVEF, aMVTol);
4e57c75e 467 //
78c66ef1 468 PutStickPavesOnCurve(aF1, aF2, aMI, aNC, aMVStick, aMVTol);
7ff8f019 469 //904/F7
4e57c75e 470 if (aNbC == 1) {
78c66ef1 471 PutEFPavesOnCurve(aNC, aMI, aMVEF, aMVTol);
4e57c75e 472 }
473 //
474 if (aIC.HasBounds()) {
b6a21c7e 475 PutBoundPaveOnCurve(aF1, aF2, aTolR3D, aNC, aMVB);
4e57c75e 476 }
477 }//for (j=0; j<aNbC; ++j) {
478 //
479 // Put closing pave if needed
480 for (j=0; j<aNbC; ++j) {
481 BOPDS_Curve& aNC=aVC.ChangeValue(j);
482 PutClosingPaveOnCurve (aNC);
483 }
484 //
485 // 3. Make section edges
486 for (j=0; j<aNbC; ++j) {
487 BOPDS_Curve& aNC=aVC.ChangeValue(j);
488 const IntTools_Curve& aIC=aNC.Curve();
489 //
490 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
491 Handle(BOPDS_PaveBlock)& aPB1=aNC.ChangePaveBlock1();
492 //
493 aLPB.Clear();
494 aPB1->Update(aLPB, Standard_False);
495 //
496 aItLPB.Initialize(aLPB);
497 for (; aItLPB.More(); aItLPB.Next()) {
498 Handle(BOPDS_PaveBlock)& aPB=aItLPB.ChangeValue();
499 aPB->Indices(nV1, nV2);
500 aPB->Range (aT1, aT2);
501 //
502 if (fabs(aT1 - aT2) < Precision::PConfusion()) {
503 continue;
504 }
505 //
465d1fba 506 bValid2D=myContext->IsValidBlockForFaces(aT1, aT2, aIC,
507 aF1, aF2, aTolR3D);
4e57c75e 508 if (!bValid2D) {
509 continue;
510 }
511 //
512 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aLSE);
513 if (bExist) {
514 continue;
515 }
516 //
517 bExist=IsExistingPaveBlock(aPB, aNC, aTolR3D, aMPBOnIn, aPBOut);
518 if (bExist) {
519 if (aMPBAdd.Add(aPBOut)) {
520 Standard_Boolean bInBothFaces = Standard_True;
5a77460e 521 if (!myDS->IsCommonBlock(aPBOut)) {
4e57c75e 522 Standard_Integer nE;
523 Standard_Real aTolE;
524 //
525 nE = aPBOut->Edge();
526 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(nE);
527 aTolE = BRep_Tool::Tolerance(aE);
528 if (aTolR3D > aTolE) {
529 myDS->UpdateEdgeTolerance(nE, aTolR3D);
530 }
531 bInBothFaces = Standard_False;
532 } else {
533 bInBothFaces = (aFI1.PaveBlocksOn().Contains(aPBOut) ||
534 aFI1.PaveBlocksIn().Contains(aPBOut))&&
535 (aFI2.PaveBlocksOn().Contains(aPBOut) ||
536 aFI2.PaveBlocksIn().Contains(aPBOut));
537 }
538 if (!bInBothFaces) {
539 PreparePostTreatFF(i, aPBOut, aMSCPB, aMVI, aVC);
540 }
541 }
542 continue;
543 }
544 //
545 // Make Edge
546 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
547 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
548 //
465d1fba 549 BOPTools_AlgoTools::MakeEdge (aIC, aV1, aT1,
550 aV2, aT2, aTolR3D, aES);
4e57c75e 551 BOPTools_AlgoTools::MakePCurve(aES, aF1, aF2, aIC,
552 mySectionAttribute.PCurveOnS1(),
553 mySectionAttribute.PCurveOnS2());
554 //
555 if (BOPTools_AlgoTools::IsMicroEdge(aES, myContext)) {
556 continue;
557 }
558 //
559 // Append the Pave Block to the Curve j
560 aLPBC.Append(aPB);
561 //
562 // Keep info for post treatment
563 BOPDS_CoupleOfPaveBlocks aCPB;
564 aCPB.SetIndexInterf(i);
565 aCPB.SetIndex(j);
566 aCPB.SetPaveBlock1(aPB);
567 //
568 aMSCPB.Add(aES, aCPB);
569 aMVI.Bind(aV1, nV1);
570 aMVI.Bind(aV2, nV2);
b4109929 571 //
572 aMVTol.UnBind(nV1);
573 aMVTol.UnBind(nV2);
4e57c75e 574 }
575 //
576 aLPBC.RemoveFirst();
577 }//for (j=0; j<aNbC; ++j) {
b4109929 578 //back to previous tolerance values for unused vertices
579 aItMV.Initialize(aMVTol);
580 for (; aItMV.More(); aItMV.Next()) {
581 nV1 = aItMV.Key();
582 aTol = aItMV.Value();
583 //
584 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&myDS->Shape(nV1);
465d1fba 585 const Handle(BRep_TVertex)& TV =
586 *((Handle(BRep_TVertex)*)&aV.TShape());
b4109929 587 TV->Tolerance(aTol);
588 }
589 //
4e57c75e 590 ProcessExistingPaveBlocks(i, aMPBOnIn, aMSCPB, aMVI, aMVB, aMPBAdd);
591 }//for (i=0; i<aNbFF; ++i) {
592 //
593 // post treatment
78c66ef1 594 myErrorStatus=PostTreatFF(aMSCPB, aMVI, aDMExEdges, aDMI, aAllocator);
4e57c75e 595 if (myErrorStatus) {
596 return;
597 }
598 //
599 // update face info
600 UpdateFaceInfo(aDMExEdges);
78c66ef1 601 //Update all pave blocks
602 UpdatePaveBlocks(aDMI);
4e57c75e 603 //-----------------------------------------------------scope t
604 aMF.Clear();
605 aMVStick.Clear();
606 aMPBOnIn.Clear();
607 aMVOnIn.Clear();
608 aDMExEdges.Clear();
78c66ef1 609 aMI.Clear();
610 aDMI.Clear();
4e57c75e 611 aAllocator.Nullify();
612}
613
614//=======================================================================
615//function : PostTreatFF
616//purpose :
617//=======================================================================
a942f2da 618Standard_Integer BOPAlgo_PaveFiller::PostTreatFF
4e57c75e 619 (BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& theMSCPB,
620 BOPCol_DataMapOfShapeInteger& aMVI,
621 BOPDS_DataMapOfPaveBlockListOfPaveBlock& aDMExEdges,
78c66ef1 622 BOPCol_DataMapOfIntegerInteger& aDMI,
4e57c75e 623 Handle(NCollection_BaseAllocator)& theAllocator)
624{
625 Standard_Integer iRet, aNbS;
626 //
627 iRet=0;
628 aNbS=theMSCPB.Extent();
629 if (!aNbS) {
630 return iRet;
631 }
632 //
633 Standard_Boolean bHasPaveBlocks, bOld;
1d47d8d0 634 Standard_Integer iErr, nSx, nVSD, iX, iP, iC, j, nV, iV = 0, iE, k;
af4e6dab 635 Standard_Integer jx, aNbLPBx;
4e57c75e 636 Standard_Real aT;
4e57c75e 637 TopAbs_ShapeEnum aType;
638 TopoDS_Shape aV, aE;
639 BOPCol_ListIteratorOfListOfShape aItLS;
640 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
641 BOPDS_PDS aPDS;
642 Handle(BOPDS_PaveBlock) aPB1;
643 BOPDS_Pave aPave[2], aPave1[2];
644 BOPDS_ShapeInfo aSI;
645 //
646 BOPCol_ListOfShape aLS(theAllocator);
647 BOPAlgo_PaveFiller aPF(theAllocator);
648 //
649 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
650 //
4e57c75e 651 // 0
652 if (aNbS==1) {
653 const TopoDS_Shape& aS=theMSCPB.FindKey(1);
654 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromIndex(1);
655
656 //
657 aType=aS.ShapeType();
658 if (aType==TopAbs_VERTEX) {
659 aSI.SetShapeType(aType);
660 aSI.SetShape(aS);
661 iV=myDS->Append(aSI);
662 //
663 iX=aCPB.IndexInterf();
664 iP=aCPB.Index();
665 BOPDS_InterfFF& aFF=aFFs(iX);
666 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
667 BOPDS_Point& aNP=aVNP(iP);
668 aNP.SetIndex(iV);
669 }
670 else if (aType==TopAbs_EDGE) {
671 aPB1=aCPB.PaveBlock1();
672 //
673 if (aPB1->HasEdge()) {
674 BOPDS_ListOfPaveBlock aLPBx;
675 aLPBx.Append(aPB1);
676 aDMExEdges.Bind(aPB1, aLPBx);
677 } else {
678 aSI.SetShapeType(aType);
679 aSI.SetShape(aS);
680 iE=myDS->Append(aSI);
681 //
682 aPB1->SetEdge(iE);
683 }
684 }
685 return iRet;
686 }
687 //
688 // 1 prepare arguments
689 for (k=1; k<=aNbS; ++k) {
690 const TopoDS_Shape& aS=theMSCPB.FindKey(k);
691 aLS.Append(aS);
692 }
693 //
694 // 2 Fuse shapes
36f4947b 695 aPF.SetProgressIndicator(myProgressIndicator);
a942f2da 696 aPF.SetRunParallel(myRunParallel);
4e57c75e 697 aPF.SetArguments(aLS);
698 aPF.Perform();
699 iErr=aPF.ErrorStatus();
700 if (iErr) {
465d1fba 701 //iRet=1; //PKVft
4e57c75e 702 return iRet;
703 }
704 aPDS=aPF.PDS();
705 //
706 aItLS.Initialize(aLS);
707 for (; aItLS.More(); aItLS.Next()) {
708 const TopoDS_Shape& aSx=aItLS.Value();
709 nSx=aPDS->Index(aSx);
710 const BOPDS_ShapeInfo& aSIx=aPDS->ShapeInfo(nSx);
711 //
712 aType=aSIx.ShapeType();
713 //
714 if (aType==TopAbs_VERTEX) {
715 if (aPDS->HasShapeSD(nSx, nVSD)) {
716 aV=aPDS->Shape(nVSD);
717 }
718 else {
719 aV=aSx;
720 }
721 // index of new vertex in theDS -> iV
722 if (!aMVI.IsBound(aV)) {
723 aSI.SetShapeType(aType);
724 aSI.SetShape(aV);
725 iV=myDS->Append(aSI);
726 //
727 aMVI.Bind(aV, iV);
728 }
729 else {
730 iV=aMVI.Find(aV);
731 }
732 // update FF interference
733 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
734 iX=aCPB.IndexInterf();
735 iP=aCPB.Index();
736 BOPDS_InterfFF& aFF=aFFs(iX);
737 BOPDS_VectorOfPoint& aVNP=aFF.ChangePoints();
738 BOPDS_Point& aNP=aVNP(iP);
739 aNP.SetIndex(iV);
740 }//if (aType==TopAbs_VERTEX) {
741 //
742 else if (aType==TopAbs_EDGE) {
743 bHasPaveBlocks=aPDS->HasPaveBlocks(nSx);
744 const BOPDS_CoupleOfPaveBlocks &aCPB=theMSCPB.FindFromKey(aSx);
745 iX=aCPB.IndexInterf();
746 iC=aCPB.Index();
747 aPB1=aCPB.PaveBlock1();
748 //
749 bOld = aPB1->HasEdge();
750 if (bOld) {
751 BOPDS_ListOfPaveBlock aLPBx;
752 aDMExEdges.Bind(aPB1, aLPBx);
753 }
754 //
755 if (!bHasPaveBlocks) {
756 if (bOld) {
757 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
758 } else {
759 aSI.SetShapeType(aType);
760 aSI.SetShape(aSx);
761 iE=myDS->Append(aSI);
762 //
763 aPB1->SetEdge(iE);
764 }
765 }
766 else {
767 BOPDS_InterfFF& aFF=aFFs(iX);
768 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
769 BOPDS_Curve& aNC=aVNC(iC);
770 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
771 //
772 const BOPDS_ListOfPaveBlock& aLPBx=aPDS->PaveBlocks(nSx);
773 aNbLPBx=aLPBx.Extent();
774 //
775 if (bOld && !aNbLPBx) {
776 aDMExEdges.ChangeFind(aPB1).Append(aPB1);
777 continue;
778 }
779 //
780 if (!bOld) {
781 aItLPB.Initialize(aLPBC);
782 for (; aItLPB.More(); aItLPB.Next()) {
783 const Handle(BOPDS_PaveBlock)& aPBC=aItLPB.Value();
784 if (aPBC==aPB1) {
785 aLPBC.Remove(aItLPB);
786 break;
787 }
788 }
789 }
790 //
791 if (!aNbLPBx) {
792 aE=aSx;
793 //
794 if (!aMVI.IsBound(aE)) {
795 aSI.SetShapeType(aType);
796 aSI.SetShape(aE);
797 iE=myDS->Append(aSI);
798 aMVI.Bind(aE, iE);
799 }
800 else {
801 iE=aMVI.Find(aE);
802 }
803 // append new PaveBlock to aLPBC
4e57c75e 804 aPB1->SetEdge(iE);
805 aLPBC.Append(aPB1);
806 } // if (!aNbLPBx) {
807 //
808 else {
809 aItLPB.Initialize(aLPBx);
810 if (bOld) {
811 aPave1[0] = aPB1->Pave1();
812 aPave1[1] = aPB1->Pave2();
813 }
814 for (; aItLPB.More(); aItLPB.Next()) {
815 const Handle(BOPDS_PaveBlock)& aPBx=aItLPB.Value();
5a77460e 816 const Handle(BOPDS_PaveBlock) aPBRx=aPDS->RealPaveBlock(aPBx);
4e57c75e 817 //
818 // update vertices of paves
819 aPave[0]=aPBx->Pave1();
820 aPave[1]=aPBx->Pave2();
821 for (j=0; j<2; ++j) {
822 jx = 0;
823 if (bOld) {
824 aT = aPave[j].Parameter();
825 if (aT == aPave1[0].Parameter()) {
826 jx = 1;
827 } else if (aT == aPave1[1].Parameter()) {
828 jx = 2;
829 }
830 //
831 if (jx) {
832 iV = aPave1[jx-1].Index();
833 }
834 }
835 if (!jx) {
836 nV=aPave[j].Index();
837 aV=aPDS->Shape(nV);
838 //
465d1fba 839 if (!aMVI.IsBound(aV)) {
840 // index of new vertex in theDS -> iV
4e57c75e 841 aSI.SetShapeType(TopAbs_VERTEX);
842 aSI.SetShape(aV);
843 iV=myDS->Append(aSI);
844 aMVI.Bind(aV, iV);
845 }
846 else {
847 iV=aMVI.Find(aV);
848 }
849 }
78c66ef1 850 const BOPDS_Pave& aP1 = !j ? aPB1->Pave1() : aPB1->Pave2();
465d1fba 851 if (aP1.Parameter() == aPave[j].Parameter() &&
852 aP1.Index() != iV) {
78c66ef1 853 aDMI.Bind(aP1.Index(), iV);
6a43d224 854 myDS->AddShapeSD(aP1.Index(), iV);
78c66ef1 855 }
856 //
4e57c75e 857 aPave[j].SetIndex(iV);
858 }
859 //
860 // add edge
861 aE=aPDS->Shape(aPBRx->Edge());
862 //
863 if (!aMVI.IsBound(aE)) {
864 aSI.SetShapeType(aType);
865 aSI.SetShape(aE);
866 iE=myDS->Append(aSI);
867 aMVI.Bind(aE, iE);
868 }
869 else {
870 iE=aMVI.Find(aE);
871 }
872 // append new PaveBlock to aLPBC
873 Handle(BOPDS_PaveBlock) aPBC=new BOPDS_PaveBlock();
874 //
875 aPBC->SetPave1(aPave[0]);
876 aPBC->SetPave2(aPave[1]);
877 aPBC->SetEdge(iE);
878 if (bOld) {
879 aPBC->SetOriginalEdge(aPB1->OriginalEdge());
880 aDMExEdges.ChangeFind(aPB1).Append(aPBC);
881 }
882 else {
883 aLPBC.Append(aPBC);
884 }
885 }
886 }
887 }
888 }//else if (aType==TopAbs_EDGE)
889 }//for (; aItLS.More(); aItLS.Next()) {
890 return iRet;
891}
892
893//=======================================================================
894//function : UpdateFaceInfo
895//purpose :
896//=======================================================================
465d1fba 897void BOPAlgo_PaveFiller::UpdateFaceInfo
898 (BOPDS_DataMapOfPaveBlockListOfPaveBlock& theDME)
4e57c75e 899{
900 Standard_Integer i, j, nV1, nF1, nF2,
901 aNbFF, aNbC, aNbP, aNbS, aNbPBIn;
902 BOPDS_IndexedMapOfPaveBlock aMPBCopy;
903 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
904 //
905 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
906 aNbFF=aFFs.Extent();
907 //
908 //1. Sections (curves, points);
909 for (i=0; i<aNbFF; ++i) {
910 BOPDS_InterfFF& aFF=aFFs(i);
911 aFF.Indices(nF1, nF2);
912 //
913 BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
914 BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
915 //
916 BOPDS_VectorOfCurve& aVNC=aFF.ChangeCurves();
917 aNbC=aVNC.Extent();
918 for (j=0; j<aNbC; ++j) {
919 BOPDS_Curve& aNC=aVNC(j);
920 BOPDS_ListOfPaveBlock& aLPBC=aNC.ChangePaveBlocks();
921 aItLPB.Initialize(aLPBC);
922 //
923 if (aItLPB.More() && theDME.IsBound(aLPBC.First())) {
924 const Handle(BOPDS_PaveBlock)& aPB=aLPBC.First();
925 BOPDS_ListOfPaveBlock& aLPB = theDME.ChangeFind(aPB);
926 UpdateExistingPaveBlocks(aPB, aLPB, nF1, nF2);
927 aLPBC.Clear();
928 continue;
929 }
930 //
931 for(; aItLPB.More(); aItLPB.Next()) {
932 const Handle(BOPDS_PaveBlock)& aPB=aItLPB.Value();
933 aFI1.ChangePaveBlocksSc().Add(aPB);
934 aFI2.ChangePaveBlocksSc().Add(aPB);
935 }
936 }
937 // VerticesSc
938 const BOPDS_VectorOfPoint& aVNP=aFF.Points();
939 aNbP=aVNP.Extent();
940 for (j=0; j<aNbP; ++j) {
941 const BOPDS_Point& aNP=aVNP(j);
942 nV1=aNP.Index();
943 aFI1.ChangeVerticesSc().Add(nV1);
944 aFI2.ChangeVerticesSc().Add(nV1);
945 }
946 }
947 //
948 //2. PaveBlocksIn
949 if (theDME.IsEmpty()) {
950 return;
951 }
952 //
953 aNbS=myDS->NbSourceShapes();
954 for (i=0; i<aNbS; ++i) {
955 const BOPDS_ShapeInfo& aSI=myDS->ShapeInfo(i);
956 if (aSI.ShapeType()!=TopAbs_FACE) {
957 continue;
958 }
4e57c75e 959 if(!myDS->HasFaceInfo(i)) {
960 continue;
961 }
962 BOPDS_FaceInfo& aFI=myDS->ChangeFaceInfo(i);
963 //
964 BOPDS_IndexedMapOfPaveBlock& aMPBIn=aFI.ChangePaveBlocksIn();
965 aMPBCopy.Assign(aMPBIn);
966 aMPBIn.Clear();
967 //
968 aNbPBIn=aMPBCopy.Extent();
969 for (j=1; j<=aNbPBIn; ++j) {
970 const Handle(BOPDS_PaveBlock)& aPB = aMPBCopy(j);
971 if (theDME.IsBound(aPB)) {
972 const BOPDS_ListOfPaveBlock& aLPB = theDME.Find(aPB);
973 aItLPB.Initialize(aLPB);
974 for (; aItLPB.More(); aItLPB.Next()) {
975 const Handle(BOPDS_PaveBlock)& aPB1 = aItLPB.Value();
976 aMPBIn.Add(aPB1);
977 }
978 } else {
979 aMPBIn.Add(aPB);
980 }
981 }//for (j=1; j<=aNbPBIn; ++j) {
982 }//for (i=0; i<aNbS; ++i) {
983}
4e57c75e 984//=======================================================================
985//function : IsExistingVertex
986//purpose :
987//=======================================================================
988 Standard_Boolean BOPAlgo_PaveFiller::IsExistingVertex
989 (const gp_Pnt& aP,
990 const Standard_Real theTolR3D,
991 const BOPCol_MapOfInteger& aMVOnIn)const
992{
993 Standard_Boolean bRet;
994 Standard_Integer nV, iFlag;
995 Standard_Real aTolV;
996 gp_Pnt aPV;
997 Bnd_Box aBoxP;
998 BOPCol_MapIteratorOfMapOfInteger aIt;
999 //
1000 bRet=Standard_True;
1001 //
1002 aBoxP.Add(aP);
1003 aBoxP.Enlarge(theTolR3D);
1004 //
1005 aIt.Initialize(aMVOnIn);
1006 for (; aIt.More(); aIt.Next()) {
1007 Bnd_Box aBoxV;
1008 //
1009 nV=aIt.Value();
1010 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1011 aPV=BRep_Tool::Pnt(aV);
1012 aTolV=BRep_Tool::Tolerance(aV);
1013 aBoxV.Add(aP);
1014 aBoxV.Enlarge(aTolV);
1015 //
1016 if (!aBoxP.IsOut(aBoxV)) {
1017 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP, theTolR3D);
1018 if (!iFlag) {
1019 return bRet;
1020 }
1021 }
1022 }
1023 return !bRet;
1024}
1025//=======================================================================
1026//function : IsExistingPaveBlock
1027//purpose :
1028//=======================================================================
1029 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1030 (const Handle(BOPDS_PaveBlock)& thePB,
1031 const BOPDS_Curve& theNC,
1032 const Standard_Real theTolR3D,
1033 const BOPCol_ListOfInteger& theLSE)
1034{
1035 Standard_Boolean bRet=Standard_True;
1036 //
1037 if (theLSE.IsEmpty()) {
1038 return !bRet;
1039 }
1040 //
1041 Standard_Real aT1, aT2, aTm, aTx, aTol;
1042 Standard_Integer nE, iFlag;
1043 gp_Pnt aPm;
1044 Bnd_Box aBoxPm;
1045 BOPCol_ListIteratorOfListOfInteger aItLI;
1046 //
1047 thePB->Range(aT1, aT2);
1048 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1049 theNC.Curve().D0(aTm, aPm);
1050 aBoxPm.Add(aPm);
1051 aBoxPm.Enlarge(theTolR3D);
1052 //
1053 aItLI.Initialize(theLSE);
1054 for (; aItLI.More(); aItLI.Next()) {
1055 nE=aItLI.Value();
1056 const BOPDS_ShapeInfo& aSIE=myDS->ChangeShapeInfo(nE);
1057 const Bnd_Box& aBoxE=aSIE.Box();
1058 if (!aBoxE.IsOut(aBoxPm)) {
1059 const TopoDS_Edge& aE=(*(TopoDS_Edge *)(&aSIE.Shape()));
1060 aTol = BRep_Tool::Tolerance(aE);
1061 aTol = aTol > theTolR3D ? aTol : theTolR3D;
1062 iFlag=myContext->ComputePE(aPm, aTol, aE, aTx);
1063 if (!iFlag) {
1064 return bRet;
1065 }
1066 }
1067 }
1068 return !bRet;
1069}
1070
1071//=======================================================================
1072//function : IsExistingPaveBlock
1073//purpose :
1074//=======================================================================
1075 Standard_Boolean BOPAlgo_PaveFiller::IsExistingPaveBlock
1076 (const Handle(BOPDS_PaveBlock)& thePB,
1077 const BOPDS_Curve& theNC,
1078 const Standard_Real theTolR3D,
decdfc94 1079 const BOPDS_IndexedMapOfPaveBlock& theMPBOnIn,
4e57c75e 1080 Handle(BOPDS_PaveBlock&) aPBOut)
1081{
1082 Standard_Boolean bRet;
1083 Standard_Real aT1, aT2, aTm, aTx;
decdfc94 1084 Standard_Integer nSp, iFlag1, iFlag2, nV11, nV12, nV21, nV22, i, aNbPB;
4e57c75e 1085 gp_Pnt aP1, aPm, aP2;
1086 Bnd_Box aBoxP1, aBoxPm, aBoxP2;
4e57c75e 1087 //
78c66ef1 1088 bRet=Standard_False;
4e57c75e 1089 const IntTools_Curve& aIC=theNC.Curve();
1090 //
1091 thePB->Range(aT1, aT2);
1092 thePB->Indices(nV11, nV12);
1093 //first point
1094 aIC.D0(aT1, aP1);
1095 aBoxP1.Add(aP1);
1096 aBoxP1.Enlarge(theTolR3D);
1097 //intermediate point
1098 aTm=IntTools_Tools::IntermediatePoint (aT1, aT2);
1099 aIC.D0(aTm, aPm);
1100 aBoxPm.Add(aPm);
1101 aBoxPm.Enlarge(theTolR3D);
1102 //last point
1103 aIC.D0(aT2, aP2);
1104 aBoxP2.Add(aP2);
1105 aBoxP2.Enlarge(theTolR3D);
1106 //
decdfc94 1107 aNbPB = theMPBOnIn.Extent();
1108 for (i = 1; i <= aNbPB; ++i) {
1109 const Handle(BOPDS_PaveBlock)& aPB = theMPBOnIn(i);
4e57c75e 1110 aPB->Indices(nV21, nV22);
1111 nSp=aPB->Edge();
1112 const BOPDS_ShapeInfo& aSISp=myDS->ChangeShapeInfo(nSp);
78c66ef1 1113 const TopoDS_Edge& aSp=(*(TopoDS_Edge *)(&aSISp.Shape()));
4e57c75e 1114 const Bnd_Box& aBoxSp=aSISp.Box();
78c66ef1 1115 //
465d1fba 1116 iFlag1 = (nV11 == nV21 || nV11 == nV22) ? 2 :
1117 (!aBoxSp.IsOut(aBoxP1) ? 1 : 0);
1118 iFlag2 = (nV12 == nV21 || nV12 == nV22) ? 2 :
1119 (!aBoxSp.IsOut(aBoxP2) ? 1 : 0);
78c66ef1 1120 if (iFlag1 && iFlag2) {
465d1fba 1121 if (aBoxSp.IsOut(aBoxPm) || myContext->ComputePE(aPm,
1122 theTolR3D,
1123 aSp,
1124 aTx)) {
78c66ef1 1125 continue;
1126 }
1127 //
1128 if (iFlag1 == 1) {
1129 iFlag1 = !myContext->ComputePE(aP1, theTolR3D, aSp, aTx);
1130 }
1131 //
1132 if (iFlag2 == 1) {
1133 iFlag2 = !myContext->ComputePE(aP2, theTolR3D, aSp, aTx);
1134 }
1135 //
1136 if (iFlag1 && iFlag2) {
1137 aPBOut = aPB;
1138 bRet=Standard_True;
1139 break;
4e57c75e 1140 }
1141 }
1142 }
78c66ef1 1143 return bRet;
4e57c75e 1144}
4e57c75e 1145//=======================================================================
1146//function : PutBoundPaveOnCurve
1147//purpose :
1148//=======================================================================
1149 void BOPAlgo_PaveFiller::PutBoundPaveOnCurve(const TopoDS_Face& aF1,
1150 const TopoDS_Face& aF2,
1151 const Standard_Real aTolR3D,
1152 BOPDS_Curve& aNC,
4e57c75e 1153 BOPCol_MapOfInteger& aMVB)
1154{
1155 Standard_Boolean bVF;
1156 Standard_Integer nV, iFlag, nVn, j, aNbEP;
1157 Standard_Real aT[2], aTmin, aTmax, aTV, aTol, aTolVnew;
1158 gp_Pnt aP[2];
1159 TopoDS_Vertex aVn;
1160 BOPDS_ListIteratorOfListOfPave aItLP;
1161 BOPDS_Pave aPn, aPMM[2];
1162 //
1163 aTolVnew = Precision::Confusion();
1164 //
1165 const IntTools_Curve& aIC=aNC.Curve();
1166 aIC.Bounds(aT[0], aT[1], aP[0], aP[1]);
1167 //
1168 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1169 const BOPDS_ListOfPave& aLP=aPB->ExtPaves();
1170 //
1171 aNbEP=aLP.Extent();
1172 if (aNbEP) {
1173 aTmin=1.e10;
1174 aTmax=-aTmin;
1175 //
1176 aItLP.Initialize(aLP);
1177 for (; aItLP.More(); aItLP.Next()) {
1178 const BOPDS_Pave& aPv=aItLP.Value();
1179 aPv.Contents(nV, aTV);
1180 if (aTV<aTmin) {
1181 aPMM[0]=aPv;
1182 aTmin=aTV;
1183 }
1184 if (aTV>aTmax) {
1185 aPMM[1]=aPv;
1186 aTmax=aTV;
1187 }
1188 }
1189 }
1190 //
1191 for (j=0; j<2; ++j) {
1192 //if curve is closed, process only one bound
1193 if (j && aP[1].IsEqual(aP[0], aTolVnew)) {
1194 continue;
1195 }
1196 //
1197 iFlag=1;
1198 //
1199 if (aNbEP) {
1200 Bnd_Box aBoxP;
1201 //
1202 aBoxP.Set(aP[j]);
1203 aTol = aTolR3D+Precision::Confusion();
1204 aBoxP.Enlarge(aTol);
1205 const BOPDS_Pave& aPV=aPMM[j];
1206 nV=aPV.Index();
1207 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1208 const TopoDS_Vertex& aV=(*(TopoDS_Vertex *)(&aSIV.Shape()));
1209 const Bnd_Box& aBoxV=aSIV.Box();
1210 if (!aBoxP.IsOut(aBoxV)){
1211 iFlag=BOPTools_AlgoTools::ComputeVV(aV, aP[j], aTol);
1212 }
1213 }
1214 if (iFlag) {
1215 // 900/L5
1216 bVF=myContext->IsValidPointForFaces (aP[j], aF1, aF2, aTolR3D);
1217 if (!bVF) {
1218 continue;
1219 }
1220 //
1221 BOPDS_ShapeInfo aSIVn;
1222 //
1223 BOPTools_AlgoTools::MakeNewVertex(aP[j], aTolR3D, aVn);
1224 aSIVn.SetShapeType(TopAbs_VERTEX);
1225 aSIVn.SetShape(aVn);
1226 //
1227 nVn=myDS->Append(aSIVn);
1228 //
1229 aPn.SetIndex(nVn);
1230 aPn.SetParameter(aT[j]);
1231 aPB->AppendExtPave(aPn);
1232 //
1233 aVn=(*(TopoDS_Vertex *)(&myDS->Shape(nVn)));
1234 BOPTools_AlgoTools::UpdateVertex (aIC, aT[j], aVn);
1235 //
1236 aTolVnew = BRep_Tool::Tolerance(aVn);
1237 //
1238 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nVn);
1239 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1240 BRepBndLib::Add(aVn, aBoxDS);
4e57c75e 1241 aMVB.Add(nVn);
1242 }
1243 }
1244}
1245
1246//=======================================================================
78c66ef1 1247//function : PutPavesOnCurve
4e57c75e 1248//purpose :
1249//=======================================================================
465d1fba 1250 void BOPAlgo_PaveFiller::PutPavesOnCurve
1251 (const BOPCol_MapOfInteger& aMVOnIn,
1252 const Standard_Real aTolR3D,
1253 BOPDS_Curve& aNC,
1254 const Standard_Integer nF1,
1255 const Standard_Integer nF2,
1256 const BOPCol_MapOfInteger& aMI,
1257 const BOPCol_MapOfInteger& aMVEF,
1258 BOPCol_DataMapOfIntegerReal& aMVTol)
4e57c75e 1259{
78c66ef1 1260 Standard_Boolean bInBothFaces;
4e57c75e 1261 Standard_Integer nV;
4e57c75e 1262 BOPCol_MapIteratorOfMapOfInteger aIt;
1263 //
4e57c75e 1264 const Bnd_Box& aBoxC=aNC.Box();
1265 //
78c66ef1 1266 //Put EF vertices first
1267 aIt.Initialize(aMVEF);
1268 for (; aIt.More(); aIt.Next()) {
1269 nV=aIt.Value();
1270 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 2);
1271 }
1272 //Put all other vertices
4e57c75e 1273 aIt.Initialize(aMVOnIn);
1274 for (; aIt.More(); aIt.Next()) {
1275 nV=aIt.Value();
78c66ef1 1276 if (aMVEF.Contains(nV)) {
1277 continue;
4e57c75e 1278 }
1279 //
78c66ef1 1280 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1281 const Bnd_Box& aBoxV=aSIV.Box();
4e57c75e 1282 //
78c66ef1 1283 if (aBoxC.IsOut(aBoxV)){
1284 continue;
1285 }
1286 if (!myDS->IsNewShape(nV)) {
1287 const BOPDS_FaceInfo& aFI1 = myDS->FaceInfo(nF1);
1288 const BOPDS_FaceInfo& aFI2 = myDS->FaceInfo(nF2);
b4109929 1289 //
78c66ef1 1290 bInBothFaces = (aFI1.VerticesOn().Contains(nV) ||
1291 aFI1.VerticesIn().Contains(nV))&&
1292 (aFI2.VerticesOn().Contains(nV) ||
1293 aFI2.VerticesIn().Contains(nV));
1294 if (!bInBothFaces) {
1295 continue;
b4109929 1296 }
4e57c75e 1297 }
78c66ef1 1298 //
1299 PutPaveOnCurve(nV, aTolR3D, aNC, aMI, aMVTol, 1);
4e57c75e 1300 }
1301}
1302
1303//=======================================================================
1304//function : ExtendedTolerance
1305//purpose :
1306//=======================================================================
465d1fba 1307Standard_Boolean BOPAlgo_PaveFiller::ExtendedTolerance
1308 (const Standard_Integer nV,
1309 const BOPCol_MapOfInteger& aMI,
1310 Standard_Real& aTolVExt,
1311 const Standard_Integer aType)
4e57c75e 1312{
1313 Standard_Boolean bFound = Standard_False;
1314 if (!(myDS->IsNewShape(nV))) {
1315 return bFound;
1316 }
78c66ef1 1317 //
1318 Standard_Integer i, k, aNbLines, aNbInt;
4e57c75e 1319 Standard_Real aT11, aT12, aD1, aD2, aD;
1320 TopoDS_Vertex aV;
1321 gp_Pnt aPV, aP11, aP12;
78c66ef1 1322 //
1323 k = 0;
1324 aNbInt = 2;
1325 if (aType == 1) {
1326 aNbInt = 1;
1327 } else if (aType == 2) {
1328 k = 1;
1329 }
1330 //
4e57c75e 1331 aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1332 aPV=BRep_Tool::Pnt(aV);
1333 //
1334 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1335 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
78c66ef1 1336 //
1337 for (; k<aNbInt; ++k) {
4e57c75e 1338 aNbLines = !k ? aEEs.Extent() : aEFs.Extent();
1339 for (i = 0; i < aNbLines; ++i) {
1340 BOPDS_Interf *aInt = !k ? (BOPDS_Interf*) (&aEEs(i)) :
78c66ef1 1341 (BOPDS_Interf*) (&aEFs(i));
4e57c75e 1342 if (aInt->IndexNew() == nV) {
465d1fba 1343 if (aMI.Contains(aInt->Index1()) &&
1344 aMI.Contains(aInt->Index2())) {
4e57c75e 1345 const IntTools_CommonPrt& aComPrt = !k ? aEEs(i).CommonPart() :
78c66ef1 1346 aEFs(i).CommonPart();
4e57c75e 1347 //
1348 const TopoDS_Edge& aE1=aComPrt.Edge1();
1349 aComPrt.Range1(aT11, aT12);
1350 BOPTools_AlgoTools::PointOnEdge(aE1, aT11, aP11);
1351 BOPTools_AlgoTools::PointOnEdge(aE1, aT12, aP12);
1352 aD1=aPV.Distance(aP11);
1353 aD2=aPV.Distance(aP12);
1354 aD=(aD1>aD2)? aD1 : aD2;
1355 if (aD>aTolVExt) {
1356 aTolVExt=aD;
1357 }
1358 return !bFound;
1359 }//if (aMI.Contains(aEF.Index1()) && aMI.Contains(aEF.Index2())) {
1360 }//if (aInt->IndexNew() == nV) {
1361 }//for (i = 0; i < aNbLines; ++i) {
1362 }//for (k=0; k<2; ++k) {
4e57c75e 1363 return bFound;
1364}
1365
1366//=======================================================================
1367//function : GetEFPnts
1368//purpose :
1369//=======================================================================
1370 void BOPAlgo_PaveFiller::GetEFPnts(const Standard_Integer nF1,
1371 const Standard_Integer nF2,
1372 IntSurf_ListOfPntOn2S& aListOfPnts)
1373{
1374 Standard_Integer nE, nF, nFOpposite, aNbEFs, i;
1375 Standard_Real U1, U2, V1, V2, f, l;
78c66ef1 1376 BOPCol_MapOfInteger aMI;
4e57c75e 1377 //
1378 //collect indexes of all shapes from nF1 and nF2.
78c66ef1 1379 GetFullShapeMap(nF1, aMI);
1380 GetFullShapeMap(nF2, aMI);
4e57c75e 1381 //
1382 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1383 aNbEFs = aEFs.Extent();
1384 //
1385 for(i = 0; i < aNbEFs; ++i) {
1386 const BOPDS_InterfEF& aEF = aEFs(i);
78c66ef1 1387 if (aEF.HasIndexNew()) {
1388 aEF.Indices(nE, nFOpposite);
1389 if(aMI.Contains(nE) && aMI.Contains(nFOpposite)) {
1390 const IntTools_CommonPrt& aCP = aEF.CommonPart();
4e57c75e 1391 Standard_Real aPar = aCP.VertexParameter1();
1392 const TopoDS_Edge& aE = (*(TopoDS_Edge*)(&myDS->Shape(nE)));
465d1fba 1393 const TopoDS_Face& aFOpposite =
1394 (*(TopoDS_Face*)(&myDS->Shape(nFOpposite)));
4e57c75e 1395 //
1396 const Handle(Geom_Curve)& aCurve = BRep_Tool::Curve(aE, f, l);
1397 //
1398 nF = (nFOpposite == nF1) ? nF2 : nF1;
1399 const TopoDS_Face& aF = (*(TopoDS_Face*)(&myDS->Shape(nF)));
465d1fba 1400 Handle(Geom2d_Curve) aPCurve =
1401 BRep_Tool::CurveOnSurface(aE, aF, f, l);
4e57c75e 1402 //
465d1fba 1403 GeomAPI_ProjectPointOnSurf& aProj=myContext->ProjPS(aFOpposite);
4e57c75e 1404 //
1405 gp_Pnt aPoint;
1406 aCurve->D0(aPar, aPoint);
1407 IntSurf_PntOn2S aPnt;
1408 if(!aPCurve.IsNull()) {
1409 gp_Pnt2d aP2d = aPCurve->Value(aPar);
1410 aProj.Perform(aPoint);
1411 if(aProj.IsDone()) {
1412 aProj.LowerDistanceParameters(U1,V1);
1413 if (nF == nF1) {
1414 aPnt.SetValue(aP2d.X(),aP2d.Y(),U1,V1);
1415 } else {
1416 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
1417 }
1418 aListOfPnts.Append(aPnt);
1419 }
1420 }
1421 else {
1422 GeomAPI_ProjectPointOnSurf& aProj1 = myContext->ProjPS(aF);
1423 aProj1.Perform(aPoint);
1424 aProj.Perform(aPoint);
1425 if(aProj1.IsDone() && aProj.IsDone()){
1426 aProj1.LowerDistanceParameters(U1,V1);
1427 aProj.LowerDistanceParameters(U2,V2);
1428 if (nF == nF1) {
1429 aPnt.SetValue(U1,V1,U2,V2);
1430 } else {
1431 aPnt.SetValue(U2,V2,U1,V1);
1432 }
1433 aListOfPnts.Append(aPnt);
1434 }
1435 }
1436 }
1437 }
1438 }
1439}
1440
1441//=======================================================================
1442//function : ProcessUnUsedVertices
1443//purpose :
1444//=======================================================================
465d1fba 1445 void BOPAlgo_PaveFiller::PutEFPavesOnCurve
1446 (BOPDS_Curve& aNC,
1447 const BOPCol_MapOfInteger& aMI,
1448 const BOPCol_MapOfInteger& aMVEF,
1449 BOPCol_DataMapOfIntegerReal& aMVTol)
4e57c75e 1450{
1451 if (!aMVEF.Extent()) {
1452 return;
1453 }
1454 //
1455 const IntTools_Curve& aIC=aNC.Curve();
1456 GeomAbs_CurveType aTypeC;
1457 aTypeC=aIC.Type();
1458 if (!(aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve)) {
1459 return;
1460 }
1461 //
1462 Standard_Integer nV;
1463 BOPCol_MapOfInteger aMV;
1464 //
1465 aMV.Assign(aMVEF);
1466 RemoveUsedVertices(aNC, aMV);
1467 if (!aMV.Extent()) {
1468 return;
1469 }
1470 //
1471 Standard_Real aDist;
1472 BOPDS_Pave aPave;
1473 //
1474 const Handle(Geom_Curve)& aC3D=aIC.Curve();
4e57c75e 1475 GeomAPI_ProjectPointOnCurve& aProjPT = myContext->ProjPT(aC3D);
78c66ef1 1476 //
4e57c75e 1477 BOPCol_MapIteratorOfMapOfInteger aItMI;
1478 aItMI.Initialize(aMV);
1479 for (; aItMI.More(); aItMI.Next()) {
1480 nV = aItMI.Value();
1481 const TopoDS_Vertex& aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
1482 gp_Pnt aPV = BRep_Tool::Pnt(aV);
1483 aProjPT.Perform(aPV);
1484 Standard_Integer aNbPoints = aProjPT.NbPoints();
1485 if (aNbPoints) {
1486 aDist = aProjPT.LowerDistance();
78c66ef1 1487 PutPaveOnCurve(nV, aDist, aNC, aMI, aMVTol);
4e57c75e 1488 }
1489 }
1490}
1491
1492//=======================================================================
1493//function : ProcessUnUsedVertices
1494//purpose :
1495//=======================================================================
465d1fba 1496 void BOPAlgo_PaveFiller::PutStickPavesOnCurve
1497 (const TopoDS_Face& aF1,
1498 const TopoDS_Face& aF2,
1499 const BOPCol_MapOfInteger& aMI,
1500 BOPDS_Curve& aNC,
1501 const BOPCol_MapOfInteger& aMVStick,
1502 BOPCol_DataMapOfIntegerReal& aMVTol)
4e57c75e 1503{
1504 BOPCol_MapOfInteger aMV;
1505 aMV.Assign(aMVStick);
1506 RemoveUsedVertices(aNC, aMV);
1507 //
1508 if (!aMV.Extent()) {
1509 return;
1510 }
1511 //
1512 GeomAbs_SurfaceType aType1, aType2;
4e57c75e 1513 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1514 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1515 GeomAdaptor_Surface aGAS1(aS1);
1516 GeomAdaptor_Surface aGAS2(aS2);
4e57c75e 1517 //
1518 aType1=aGAS1.GetType();
1519 aType2=aGAS2.GetType();
1520 //
ec0cdc0e 1521 //if (aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
1522 GeomAbs_CurveType aTypeC;
1523 //
1524 const IntTools_Curve& aIC=aNC.Curve();
1525 aTypeC=aIC.Type();
1526 //if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1527 Handle(Geom2d_Curve) aC2D[2];
1528 //
1529 aC2D[0]=aIC.FirstCurve2d();
1530 aC2D[1]=aIC.SecondCurve2d();
1531 if (!aC2D[0].IsNull() && !aC2D[1].IsNull()) {
1532 Standard_Integer nV, m, n;
1533 Standard_Real aTC[2], aD, aD2, u, v, aDT2, aScPr, aDScPr;
1534 gp_Pnt aPC[2], aPV;
1535 gp_Dir aDN[2];
1536 gp_Pnt2d aP2D;
1537 BOPCol_MapIteratorOfMapOfInteger aItMI, aItMI1;
1538 //
1539 aDT2=2e-7; // the rich criteria
1540 aDScPr=5.e-9; // the creasing criteria
1541 aIC.Bounds(aTC[0], aTC[1], aPC[0], aPC[1]);
4e57c75e 1542 //
ec0cdc0e 1543 aItMI.Initialize(aMV);
1544 for (; aItMI.More(); aItMI.Next()) {
1545 nV = aItMI.Value();
1546 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&myDS->Shape(nV));
1547 aPV=BRep_Tool::Pnt(aV);
4e57c75e 1548 //
ec0cdc0e 1549 for (m=0; m<2; ++m) {
1550 aD2=aPC[m].SquareDistance(aPV);
1551 if (aD2>aDT2) {// no rich
1552 continue;
1553 }
78c66ef1 1554 //
ec0cdc0e 1555 for (n=0; n<2; ++n) {
1556 Handle(Geom_Surface)& aS=(!n)? aS1 : aS2;
1557 aC2D[n]->D0(aTC[m], aP2D);
1558 aP2D.Coord(u, v);
1559 BOPTools_AlgoTools3D::GetNormalToSurface(aS, u, v, aDN[n]);
1560 }
1561 //
1562 aScPr=aDN[0]*aDN[1];
1563 if (aScPr<0.) {
1564 aScPr=-aScPr;
1565 }
1566 aScPr=1.-aScPr;
78c66ef1 1567 //
ec0cdc0e 1568 if (aScPr>aDScPr) {
1569 continue;
1570 }
1571 //
1572 // The intersection curve aIC is vanishing curve (the crease)
1573 aD=sqrt(aD2);
1574 //
1575 PutPaveOnCurve(nV, aD, aNC, aMI, aMVTol);
4e57c75e 1576 }
ec0cdc0e 1577 }//for (jVU=1; jVU=aNbVU; ++jVU) {
1578 }
1579 //}//if (aTypeC==GeomAbs_BezierCurve || aTypeC==GeomAbs_BSplineCurve) {
1580 //}//if(aType1==GeomAbs_Torus || aType2==GeomAbs_Torus) {
4e57c75e 1581}
1582
1583//=======================================================================
1584//function : GetStickVertices
1585//purpose :
1586//=======================================================================
1587 void BOPAlgo_PaveFiller::GetStickVertices(const Standard_Integer nF1,
1588 const Standard_Integer nF2,
1589 BOPCol_MapOfInteger& aMVStick,
78c66ef1 1590 BOPCol_MapOfInteger& aMVEF,
1591 BOPCol_MapOfInteger& aMI)
4e57c75e 1592{
78c66ef1 1593 Standard_Integer nS1, nS2, nVNew, aTypeInt, i;
4e57c75e 1594 //
1595 BOPDS_VectorOfInterfVV& aVVs=myDS->InterfVV();
1596 BOPDS_VectorOfInterfVE& aVEs=myDS->InterfVE();
1597 BOPDS_VectorOfInterfEE& aEEs=myDS->InterfEE();
1598 BOPDS_VectorOfInterfVF& aVFs=myDS->InterfVF();
1599 BOPDS_VectorOfInterfEF& aEFs=myDS->InterfEF();
1600 //
465d1fba 1601 Standard_Integer aNbLines[5] = {
1602 aVVs.Extent(), aVEs.Extent(), aEEs.Extent(),
1603 aVFs.Extent(), aEFs.Extent()
1604 };
78c66ef1 1605 //collect indices of all shapes from nF1 and nF2.
1606 aMI.Clear();
1607 GetFullShapeMap(nF1, aMI);
1608 GetFullShapeMap(nF2, aMI);
1609 //
1610 //collect VV, VE, EE, VF interferences
1611 for (aTypeInt = 0; aTypeInt < 4; ++aTypeInt) {
1612 for (i = 0; i < aNbLines[aTypeInt]; ++i) {
1613 BOPDS_Interf* aInt = (aTypeInt==0) ? (BOPDS_Interf*)(&aVVs(i)) :
1614 ((aTypeInt==1) ? (BOPDS_Interf*)(&aVEs(i)) :
465d1fba 1615 ((aTypeInt==2) ? (BOPDS_Interf*)(&aEEs(i)) :
1616 (BOPDS_Interf*)(&aVFs(i))));
78c66ef1 1617 if (aInt->HasIndexNew()) {
1618 aInt->Indices(nS1, nS2);
1619 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1620 nVNew = aInt->IndexNew();
1621 aMVStick.Add(nVNew);
1622 }
4e57c75e 1623 }
1624 }
1625 }
4e57c75e 1626 //collect EF interferences
78c66ef1 1627 for (i = 0; i < aNbLines[4]; ++i) {
1628 const BOPDS_InterfEF& aInt = aEFs(i);
1629 if (aInt.HasIndexNew()) {
1630 aInt.Indices(nS1, nS2);
1631 if(aMI.Contains(nS1) && aMI.Contains(nS2)) {
1632 nVNew = aInt.IndexNew();
4e57c75e 1633 aMVStick.Add(nVNew);
1634 aMVEF.Add(nVNew);
1635 }
1636 }
1637 }
1638}
1639
1640//=======================================================================
78c66ef1 1641// function: GetFullShapeMap
4e57c75e 1642// purpose:
1643//=======================================================================
78c66ef1 1644void BOPAlgo_PaveFiller::GetFullShapeMap(const Standard_Integer nF,
1645 BOPCol_MapOfInteger& aMI)
4e57c75e 1646{
78c66ef1 1647 BOPCol_ListIteratorOfListOfInteger aIt;
1648 Standard_Integer nS;
1649 //
1650 const BOPDS_ShapeInfo& aSI = myDS->ShapeInfo(nF);
1651 const BOPCol_ListOfInteger& aLI = aSI.SubShapes();
1652 //
4e57c75e 1653 aMI.Add(nF);
78c66ef1 1654 aIt.Initialize(aLI);
1655 for (; aIt.More(); aIt.Next()) {
1656 nS = aIt.Value();
1657 aMI.Add(nS);
4e57c75e 1658 }
1659}
1660
1661//=======================================================================
1662// function: RemoveUsedVertices
1663// purpose:
1664//=======================================================================
1665void BOPAlgo_PaveFiller::RemoveUsedVertices(BOPDS_Curve& aNC,
1666 BOPCol_MapOfInteger& aMV)
1667{
1668 if (!aMV.Extent()) {
1669 return;
1670 }
1671 Standard_Integer nV;
1672 BOPDS_Pave aPave;
1673 BOPDS_ListIteratorOfListOfPave aItLP;
1674 //
1675 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1676 const BOPDS_ListOfPave& aLP = aPB->ExtPaves();
1677 aItLP.Initialize(aLP);
1678 for (;aItLP.More();aItLP.Next()) {
1679 aPave = aItLP.Value();
1680 nV = aPave.Index();
1681 aMV.Remove(nV);
1682 }
1683}
1684
1685//=======================================================================
1686//function : PutPaveOnCurve
1687//purpose :
1688//=======================================================================
465d1fba 1689 void BOPAlgo_PaveFiller::PutPaveOnCurve
1690 (const Standard_Integer nV,
1691 const Standard_Real aTolR3D,
1692 BOPDS_Curve& aNC,
1693 const BOPCol_MapOfInteger& aMI,
1694 BOPCol_DataMapOfIntegerReal& aMVTol,
1695 const Standard_Integer iCheckExtend)
4e57c75e 1696{
1697 Standard_Boolean bIsVertexOnLine;
b4109929 1698 Standard_Real aT, aTol, aTolNew;
4e57c75e 1699 BOPDS_Pave aPave;
1700 //
1701 const TopoDS_Vertex aV = (*(TopoDS_Vertex *)(&myDS->Shape(nV)));
78c66ef1 1702 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
4e57c75e 1703 const IntTools_Curve& aIC = aNC.Curve();
1704 //
1705 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aIC, aTolR3D, aT);
78c66ef1 1706 if (!bIsVertexOnLine && iCheckExtend) {
1707 aTol = BRep_Tool::Tolerance(aV);
1708 //
1709 ExtendedTolerance(nV, aMI, aTol, iCheckExtend);
1710 bIsVertexOnLine=myContext->IsVertexOnLine(aV, aTol, aIC, aTolR3D, aT);
1711 }
1712 //
4e57c75e 1713 if (bIsVertexOnLine) {
1714 aPave.SetIndex(nV);
1715 aPave.SetParameter(aT);
1716 //
1717 aPB->AppendExtPave(aPave);
1718 //
b4109929 1719 aTol = BRep_Tool::Tolerance(aV);
1720 //
4e57c75e 1721 BOPTools_AlgoTools::UpdateVertex (aIC, aT, aV);
b4109929 1722 //
1723 if (!aMVTol.IsBound(nV)) {
1724 aTolNew = BRep_Tool::Tolerance(aV);
1725 if (aTolNew > aTol) {
1726 aMVTol.Bind(nV, aTol);
1727 }
1728 }
4e57c75e 1729 //
1730 BOPDS_ShapeInfo& aSIDS=myDS->ChangeShapeInfo(nV);
1731 Bnd_Box& aBoxDS=aSIDS.ChangeBox();
1732 BRepBndLib::Add(aV, aBoxDS);
1733 }
1734}
1735
1736//=======================================================================
1737//function : ProcessOldPaveBlocks
1738//purpose :
1739//=======================================================================
1740 void BOPAlgo_PaveFiller::ProcessExistingPaveBlocks
1741 (const Standard_Integer theInt,
decdfc94 1742 const BOPDS_IndexedMapOfPaveBlock& aMPBOnIn,
4e57c75e 1743 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
1744 BOPCol_DataMapOfShapeInteger& aMVI,
1745 const BOPCol_MapOfInteger& aMVB,
1746 BOPDS_MapOfPaveBlock& aMPB)
1747{
decdfc94 1748 Standard_Integer nV, nE, iFlag, i, aNbPB;
4e57c75e 1749 Standard_Real aT;
1750 BOPCol_MapIteratorOfMapOfInteger aItB;
4e57c75e 1751 //
1752 BOPDS_VectorOfInterfFF& aFFs=myDS->InterfFF();
1753 BOPDS_InterfFF& aFF = aFFs(theInt);
1754 BOPDS_VectorOfCurve& aVC=aFF.ChangeCurves();
1755 //
1756 aItB.Initialize(aMVB);
1757 for (; aItB.More(); aItB.Next()) {
1758 nV = aItB.Value();
1759 const BOPDS_ShapeInfo& aSIV=myDS->ShapeInfo(nV);
1760 const Bnd_Box& aBoxV=aSIV.Box();
1761 const TopoDS_Vertex& aV = *(TopoDS_Vertex*)&aSIV.Shape();
1762 if (!aMVI.IsBound(aV)) {
1763 continue;
1764 }
1765 //
decdfc94 1766 aNbPB = aMPBOnIn.Extent();
1767 for (i = 1; i <= aNbPB; ++i) {
1768 const Handle(BOPDS_PaveBlock)& aPB = aMPBOnIn(i);
4e57c75e 1769 if (aPB->Pave1().Index() == nV || aPB->Pave2().Index() == nV) {
1770 continue;
1771 }
1772 //
1773 if (aMPB.Contains(aPB)) {
1774 continue;
1775 }
1776 nE=aPB->Edge();
1777 const BOPDS_ShapeInfo& aSIE=myDS->ShapeInfo(nE);
1778 const Bnd_Box& aBoxE=aSIE.Box();
1779 //
1780 if (!aBoxV.IsOut(aBoxE)) {
1781 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aSIE.Shape();
1782 //
1783 iFlag=myContext->ComputeVE (aV, aE, aT);
1784 if (!iFlag) {
1785 aMPB.Add(aPB);
1786 //
1787 PreparePostTreatFF(theInt, aPB, aMSCPB, aMVI, aVC);
1788 }
1789 }
1790 }
1791 }
1792}
4e57c75e 1793//=======================================================================
1794//function : UpdateExistingPaveBlocks
1795//purpose :
1796//=======================================================================
1797 void BOPAlgo_PaveFiller::UpdateExistingPaveBlocks
1798 (const Handle(BOPDS_PaveBlock)& aPBf,
1799 BOPDS_ListOfPaveBlock& aLPB,
1800 const Standard_Integer nF1,
1801 const Standard_Integer nF2)
1802{
1803 Standard_Integer nE;
1804 Standard_Boolean bCB;
1805 Handle(BOPDS_PaveBlock) aPB, aPB1, aPB2, aPB2n;
1806 Handle(BOPDS_CommonBlock) aCB;
1807 BOPDS_ListIteratorOfListOfPaveBlock aIt, aIt1, aIt2;
1808 BOPDS_IndexedMapOfPaveBlock aMPB;
1809 //
1810 //remove micro edges from aLPB
1811 aIt.Initialize(aLPB);
1812 for (; aIt.More();) {
1813 aPB = aIt.Value();
1814 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1815 if (BOPTools_AlgoTools::IsMicroEdge(aE, myContext)) {
1816 aLPB.Remove(aIt);
1817 continue;
1818 }
1819 aIt.Next();
1820 }
1821 //
1822 if (!aLPB.Extent()) {
1823 return;
1824 }
1825 //update face info
1826 myDS->UpdateFaceInfoOn(nF1);
1827 //
1828 myDS->UpdateFaceInfoOn(nF2);
1829 //
1830 BOPDS_FaceInfo& aFI1 = myDS->ChangeFaceInfo(nF1);
1831 BOPDS_FaceInfo& aFI2 = myDS->ChangeFaceInfo(nF2);
1832 //
1833 BOPDS_IndexedMapOfPaveBlock& aMPBOn1 = aFI1.ChangePaveBlocksOn();
1834 BOPDS_IndexedMapOfPaveBlock& aMPBIn1 = aFI1.ChangePaveBlocksIn();
1835 BOPDS_IndexedMapOfPaveBlock& aMPBOn2 = aFI2.ChangePaveBlocksOn();
1836 BOPDS_IndexedMapOfPaveBlock& aMPBIn2 = aFI2.ChangePaveBlocksIn();
1837 //
1838 // remove old pave blocks
5a77460e 1839 const Handle(BOPDS_CommonBlock)& aCB1 = myDS->CommonBlock(aPBf);
4e57c75e 1840 bCB = !aCB1.IsNull();
1841 BOPDS_ListOfPaveBlock aLPB1;
1842 //
1843 if (bCB) {
1844 aLPB1.Assign(aCB1->PaveBlocks());
1845 } else {
1846 aLPB1.Append(aPBf);
1847 }
1848 aIt1.Initialize(aLPB1);
1849 for (; aIt1.More(); aIt1.Next()) {
1850 aPB1 = aIt1.Value();
1851 nE = aPB1->OriginalEdge();
1852 //
1853 BOPDS_ListOfPaveBlock& aLPB2 = myDS->ChangePaveBlocks(nE);
1854 aIt2.Initialize(aLPB2);
1855 for (; aIt2.More(); aIt2.Next()) {
1856 aPB2 = aIt2.Value();
1857 if (aPB1 == aPB2) {
1858 aLPB2.Remove(aIt2);
1859 break;
1860 }
1861 }
1862 }
1863 //
1864 if (bCB) {
1865 //create new pave blocks
1866 const BOPCol_ListOfInteger& aFaces = aCB1->Faces();
1867 aIt.Initialize(aLPB);
1868 for (; aIt.More(); aIt.Next()) {
1869 Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
1870 //
1871 aCB = new BOPDS_CommonBlock;
1872 aIt1.Initialize(aLPB1);
1873 for (; aIt1.More(); aIt1.Next()) {
1874 aPB2 = aIt1.Value();
1875 nE = aPB2->OriginalEdge();
1876 //
1877 aPB2n = new BOPDS_PaveBlock;
1878 aPB2n->SetPave1(aPB->Pave1());
1879 aPB2n->SetPave2(aPB->Pave2());
1880 aPB2n->SetEdge(aPB->Edge());
1881 aPB2n->SetOriginalEdge(nE);
1882 aCB->AddPaveBlock(aPB2n);
5a77460e 1883 myDS->SetCommonBlock(aPB2n, aCB);
4e57c75e 1884 myDS->ChangePaveBlocks(nE).Append(aPB2n);
1885 }
1886 aCB->AddFaces(aFaces);
1887 myDS->SortPaveBlocks(aCB);
1888 //
1889 aPB=aCB->PaveBlocks().First();
1890 }
1891 }
1892 //
1893 aIt.Initialize(aLPB);
1894 for (; aIt.More(); aIt.Next()) {
1895 Handle(BOPDS_PaveBlock)& aPB = aIt.ChangeValue();
1896 nE = aPB->OriginalEdge();
1897 //
1898 Standard_Integer nF = (aMPBOn1.Contains(aPBf) ||
1899 aMPBIn1.Contains(aPBf)) ? nF2 : nF1;
1900 const TopoDS_Face& aF = *(TopoDS_Face*)&myDS->Shape(nF);
465d1fba 1901 IntTools_Range aShrR(aPB->Pave1().Parameter(),
1902 aPB->Pave2().Parameter());
4e57c75e 1903 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
1904 //
465d1fba 1905 Standard_Boolean bCom =
1906 BOPTools_AlgoTools::IsBlockInOnFace(aShrR, aF, aE, myContext);
4e57c75e 1907 if (bCom) {
1908 if (bCB) {
5a77460e 1909 aCB = myDS->CommonBlock(aPB);
4e57c75e 1910 aCB->AddFace(nF);
1911 } else {
1912 aCB = new BOPDS_CommonBlock;
1913 aCB->AddPaveBlock(aPB);
1914 aCB->AddFace(nF1);
1915 aCB->AddFace(nF2);
1916 //
5a77460e 1917 myDS->SetCommonBlock(aPB, aCB);
4e57c75e 1918 }
1919 aMPB.Add(aPB);
1920 }
1921 if (!bCB) {
1922 myDS->ChangePaveBlocks(nE).Append(aPB);
1923 }
1924 }
1925 //
1926 Standard_Integer i, aNbPB;
1927 Standard_Boolean bIn1, bIn2;
1928 //
1929 bIn1 = aMPBOn1.Contains(aPBf) || aMPBIn1.Contains(aPBf);
1930 bIn2 = aMPBOn2.Contains(aPBf) || aMPBIn2.Contains(aPBf);
1931 //
1932 aNbPB=aMPB.Extent();
1933 for (i=1; i<=aNbPB; ++i) {
1934 aPB = aMPB(i);
1935 if (!bIn1) {
1936 aMPBIn1.Add(aPB);
1937 }
1938 //
1939 if (!bIn2) {
1940 aMPBIn2.Add(aPB);
1941 }
1942 }
1943}
4e57c75e 1944//=======================================================================
1945// function: PutClosingPaveOnCurve
1946// purpose:
1947//=======================================================================
1948 void BOPAlgo_PaveFiller::PutClosingPaveOnCurve(BOPDS_Curve& aNC)
1949{
1950 Standard_Boolean bIsClosed, bHasBounds, bAdded;
1951 Standard_Integer nVC, j;
1952 Standard_Real aT[2], aTC, dT, aTx;
1953 gp_Pnt aP[2] ;
1954 BOPDS_Pave aPVx;
1955 BOPDS_ListIteratorOfListOfPave aItLP;
1956 //
1957 const IntTools_Curve& aIC=aNC.Curve();
1958 const Handle(Geom_Curve)& aC3D=aIC.Curve();
1959 if(aC3D.IsNull()) {
1960 return;
1961 }
1962 //
1963 bIsClosed=IntTools_Tools::IsClosed(aC3D);
1964 if (!bIsClosed) {
1965 return;
1966 }
1967 //
1968 bHasBounds=aIC.HasBounds ();
1969 if (!bHasBounds){
1970 return;
1971 }
1972 //
1973 bAdded=Standard_False;
1974 dT=Precision::PConfusion();
1975 aIC.Bounds (aT[0], aT[1], aP[0], aP[1]);
1976 //
1977 Handle(BOPDS_PaveBlock)& aPB=aNC.ChangePaveBlock1();
1978 BOPDS_ListOfPave& aLP=aPB->ChangeExtPaves();
1979 //
1980 aItLP.Initialize(aLP);
1981 for (; aItLP.More() && !bAdded; aItLP.Next()) {
1982 const BOPDS_Pave& aPC=aItLP.Value();
1983 nVC=aPC.Index();
1984 aTC=aPC.Parameter();
1985 //
1986 for (j=0; j<2; ++j) {
1987 if (fabs(aTC-aT[j]) < dT) {
1988 aTx=(!j) ? aT[1] : aT[0];
1989 aPVx.SetIndex(nVC);
1990 aPVx.SetParameter(aTx);
1991 aLP.Append(aPVx);
1992 //
1993 bAdded=Standard_True;
1994 break;
1995 }
1996 }
1997 }
1998}
4e57c75e 1999//=======================================================================
2000//function : PreparePostTreatFF
2001//purpose :
2002//=======================================================================
2003 void BOPAlgo_PaveFiller::PreparePostTreatFF
2004 (const Standard_Integer aInt,
2005 const Handle(BOPDS_PaveBlock)& aPB,
2006 BOPDS_IndexedDataMapOfShapeCoupleOfPaveBlocks& aMSCPB,
2007 BOPCol_DataMapOfShapeInteger& aMVI,
2008 BOPDS_VectorOfCurve& aVC)
2009{
2010 Standard_Integer nV1, nV2;
2011 //
2012 Standard_Integer iC=aVC.Append()-1;
2013 BOPDS_ListOfPaveBlock& aLPBC = aVC(iC).ChangePaveBlocks();
2014 aLPBC.Append(aPB);
2015 //
2016 aPB->Indices(nV1, nV2);
2017 const TopoDS_Vertex& aV1=(*(TopoDS_Vertex *)(&myDS->Shape(nV1)));
2018 const TopoDS_Vertex& aV2=(*(TopoDS_Vertex *)(&myDS->Shape(nV2)));
2019 const TopoDS_Edge& aE = *(TopoDS_Edge*)&myDS->Shape(aPB->Edge());
2020 // Keep info for post treatment
2021 BOPDS_CoupleOfPaveBlocks aCPB;
2022 aCPB.SetIndexInterf(aInt);
2023 aCPB.SetIndex(iC);
2024 aCPB.SetPaveBlock1(aPB);
2025 //
2026 aMSCPB.Add(aE, aCPB);
2027 aMVI.Bind(aV1, nV1);
2028 aMVI.Bind(aV2, nV2);
2029}
2030
2031//=======================================================================
b4109929 2032//function : CheckPlanes
2033//purpose :
2034//=======================================================================
465d1fba 2035Standard_Boolean BOPAlgo_PaveFiller::CheckPlanes
2036 (const Standard_Integer nF1,
2037 const Standard_Integer nF2)const
b4109929 2038{
2039 Standard_Boolean bToIntersect;
af4e6dab 2040 Standard_Integer i, nV2, iCnt;
b4109929 2041 BOPCol_MapIteratorOfMapOfInteger aIt;
2042 //
af4e6dab 2043 bToIntersect=Standard_False;
b4109929 2044 //
af4e6dab 2045 const BOPDS_FaceInfo& aFI1=myDS->ChangeFaceInfo(nF1);
2046 const BOPDS_FaceInfo& aFI2=myDS->ChangeFaceInfo(nF2);
b4109929 2047 //
af4e6dab 2048 const BOPCol_MapOfInteger& aMVIn1=aFI1.VerticesIn();
2049 const BOPCol_MapOfInteger& aMVOn1=aFI1.VerticesOn();
b4109929 2050 //
af4e6dab 2051 iCnt=0;
2052 for (i=0; (i<2 && !bToIntersect); ++i) {
2053 const BOPCol_MapOfInteger& aMV2=(!i) ? aFI2.VerticesIn()
2054 : aFI2.VerticesOn();
2055 //
2056 aIt.Initialize(aMV2);
b4109929 2057 for (; aIt.More(); aIt.Next()) {
af4e6dab 2058 nV2=aIt.Value();
2059 if (aMVIn1.Contains(nV2) || aMVOn1.Contains(nV2)) {
78c66ef1 2060 ++iCnt;
2061 if (iCnt>1) {
2062 bToIntersect=!bToIntersect;
2063 break;
2064 }
b4109929 2065 }
2066 }
2067 }
b4109929 2068 //
2069 return bToIntersect;
2070}
b4109929 2071//=======================================================================
78c66ef1 2072//function : UpdatePaveBlocks
2073//purpose :
2074//=======================================================================
465d1fba 2075void BOPAlgo_PaveFiller::UpdatePaveBlocks
2076 (const BOPCol_DataMapOfIntegerInteger& aDMI)
78c66ef1 2077{
2078 if (aDMI.IsEmpty()) {
2079 return;
2080 }
2081 //
2082 Standard_Integer nSp, aNbPBP, nV[2], i, j;
2083 Standard_Real aT[2];
2084 Standard_Boolean bCB, bRebuild;
2085 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
2086 BOPDS_MapOfPaveBlock aMPB;
2087 //
2088 BOPDS_VectorOfListOfPaveBlock& aPBP=myDS->ChangePaveBlocksPool();
2089 aNbPBP = aPBP.Extent();
2090 for (i=0; i<aNbPBP; ++i) {
2091 BOPDS_ListOfPaveBlock& aLPB=aPBP(i);
2092 //
2093 aItPB.Initialize(aLPB);
2094 for (; aItPB.More(); aItPB.Next()) {
2095 Handle(BOPDS_PaveBlock) aPB=aItPB.Value();
2096 const Handle(BOPDS_CommonBlock)& aCB=myDS->CommonBlock(aPB);
2097 bCB = !aCB.IsNull();
2098 if (bCB) {
2099 aPB=aCB->PaveBlock1();
2100 }
2101 //
2102 if (aMPB.Add(aPB)) {
2103 bRebuild = Standard_False;
2104 aPB->Indices(nV[0], nV[1]);
2105 aPB->Range(aT[0], aT[1]);
2106 //
2107 for (j = 0; j < 2; ++j) {
2108 if (aDMI.IsBound(nV[j])) {
2109 BOPDS_Pave aPave;
2110 //
2111 nV[j] = aDMI.Find(nV[j]);
2112 aPave.SetIndex(nV[j]);
2113 aPave.SetParameter(aT[j]);
2114 //
2115 bRebuild = Standard_True;
2116 if (!j) {
2117 aPB->SetPave1(aPave);
2118 } else {
2119 aPB->SetPave2(aPave);
2120 }
2121 }
2122 }
2123 //
2124 if (bRebuild) {
2125 nSp = SplitEdge(aPB->Edge(), nV[0], aT[0], nV[1], aT[1]);
2126 if (bCB) {
2127 aCB->SetEdge(nSp);
2128 }
2129 else {
2130 aPB->SetEdge(nSp);
2131 }
2132 }// if (bRebuild) {
2133 }// if (aMPB.Add(aPB)) {
2134 }// for (; aItPB.More(); aItPB.Next()) {
2135 }// for (i=0; i<aNbPBP; ++i) {
2136 aMPB.Clear();
2137}
2138//=======================================================================
4e57c75e 2139//function : ToleranceFF
2140//purpose : Computes the TolFF according to the tolerance value and
2141// types of the faces.
2142//=======================================================================
b4109929 2143 void ToleranceFF(const BRepAdaptor_Surface& aBAS1,
2144 const BRepAdaptor_Surface& aBAS2,
4e57c75e 2145 Standard_Real& aTolFF)
2146{
2147 Standard_Real aTol1, aTol2;
2148 Standard_Boolean isAna1, isAna2;
2149 //
b4109929 2150 aTol1 = aBAS1.Tolerance();
2151 aTol2 = aBAS2.Tolerance();
4e57c75e 2152 aTolFF = Max(aTol1, aTol2);
2153 //
b4109929 2154 isAna1 = (aBAS1.GetType() == GeomAbs_Plane ||
2155 aBAS1.GetType() == GeomAbs_Cylinder ||
2156 aBAS1.GetType() == GeomAbs_Cone ||
2157 aBAS1.GetType() == GeomAbs_Sphere ||
2158 aBAS1.GetType() == GeomAbs_Torus);
4e57c75e 2159 //
b4109929 2160 isAna2 = (aBAS2.GetType() == GeomAbs_Plane ||
2161 aBAS2.GetType() == GeomAbs_Cylinder ||
2162 aBAS2.GetType() == GeomAbs_Cone ||
2163 aBAS2.GetType() == GeomAbs_Sphere ||
2164 aBAS2.GetType() == GeomAbs_Torus);
4e57c75e 2165 //
b4109929 2166 if (!isAna1 || !isAna2) {
2167 aTolFF = Max(aTolFF, 5.e-6);
2168 }
4e57c75e 2169}