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