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