Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BOPTools / BOPTools_PaveFiller_3.cxx
CommitLineData
7fd59977 1// File: BOPTools_PaveFiller_3.cxx
2// Created: Tue Mar 13 16:12:16 2001
3// Author: Peter KURNEV
4// <pkv@irinox>
5
6
7#include <BOPTools_PaveFiller.ixx>
8
9#include <Geom_Curve.hxx>
10
11#include <gp_Pnt.hxx>
12#include <TColStd_SequenceOfInteger.hxx>
13#include <TColStd_SequenceOfReal.hxx>
14
15#include <TColStd_MapOfInteger.hxx>
16#include <TColStd_ListOfInteger.hxx>
17#include <TColStd_IndexedMapOfInteger.hxx>
18#include <TColStd_ListIteratorOfListOfInteger.hxx>
19#include <TColStd_MapIteratorOfMapOfInteger.hxx>
20
21#include <TopoDS.hxx>
22#include <TopoDS_Face.hxx>
23#include <TopoDS_Edge.hxx>
24#include <TopoDS_Vertex.hxx>
25
26#include <BRep_Tool.hxx>
27#include <BRep_Builder.hxx>
28
29#include <BooleanOperations_ShapesDataStructure.hxx>
30#include <BooleanOperations_OnceExplorer.hxx>
31#include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>
32
33#include <IntTools_FaceFace.hxx>
34#include <IntTools_SequenceOfCurves.hxx>
35#include <IntTools_Curve.hxx>
36#include <IntTools_Tools.hxx>
37#include <IntTools_SequenceOfPntOn2Faces.hxx>
38#include <IntTools_PntOn2Faces.hxx>
39#include <IntTools_PntOnFace.hxx>
40
41#include <BOPTools_IteratorOfCoupleOfShape.hxx>
42#include <BOPTools_CArray1OfSSInterference.hxx>
43#include <BOPTools_SSInterference.hxx>
44#include <BOPTools_ListOfPaveBlock.hxx>
45#include <BOPTools_PaveBlock.hxx>
46#include <BOPTools_Pave.hxx>
47#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
48#include <BOPTools_ListIteratorOfListOfPave.hxx>
49#include <BOPTools_PaveBlockIterator.hxx>
50#include <BOPTools_Tools.hxx>
51#include <BOPTools_SequenceOfCurves.hxx>
52#include <BOPTools_Curve.hxx>
53#include <BOPTools_ListOfPave.hxx>
54#include <BOPTools_PaveSet.hxx>
55#include <BOPTools_CommonBlock.hxx>
56#include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
57#include <BOPTools_ListOfCommonBlock.hxx>
58
59#include <BOPTools_InterferencePool.hxx>
60#include <BOPTools_ListIteratorOfListOfInterference.hxx>
61#include <BOPTools_InterferenceLine.hxx>
62#include <BOPTools_ListOfInterference.hxx>
63#include <BOPTools_Interference.hxx>
64#include <BOPTools_CArray1OfInterferenceLine.hxx>
65
66#include <Precision.hxx>
67#include <BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger.hxx>
68
69#include <TopExp_Explorer.hxx>
70#include <Geom2d_Curve.hxx>
71#include <Geom2dAPI_InterCurveCurve.hxx>
72#include <IntRes2d_IntersectionPoint.hxx>
73#include <BOPTools_ESInterference.hxx>
74#include <BOPTools_VSInterference.hxx>
75#include <BOPTools_VEInterference.hxx>
76#include <BOPTools_VVInterference.hxx>
77#include <BRepAdaptor_Surface.hxx>
78#include <TopTools_ListOfShape.hxx>
79#include <TopTools_ListIteratorOfListOfShape.hxx>
80
81#include <BOPTools_EEInterference.hxx>
82#include <IntTools_CommonPrt.hxx>
83#include <BOPTools_ESInterference.hxx>
84#include <BOPTools_ShapeShapeInterference.hxx>
85
86#include <IntSurf_ListOfPntOn2S.hxx>
87
88#include <GeomAPI_ProjectPointOnSurf.hxx>
89#include <IntSurf_PntOn2S.hxx>
90#include <TopTools_MapOfShape.hxx>
91
92
93static
94 Standard_Boolean IsPaveBlock(const Standard_Integer nV1,
95 const Standard_Integer nV2,
96 const BOPTools_ListOfPaveBlock& aLPBExisting);
97static
98 Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
99 const TColStd_IndexedMapOfInteger& aMapWith);
100static
101 void FMapWith(const Standard_Integer nF,
102 BOPTools_InterferencePool* myIntrPool,
103 TColStd_IndexedMapOfInteger& aMapWith);
104static
105 void FMapWhat(const Standard_Integer nF,
106 BOPTools_InterferencePool* myIntrPool,
107 TColStd_IndexedMapOfInteger& aMapWhat);
108
109//wkar OCC334 f
110static
111 void UnUsedMap(BOPTools_SequenceOfCurves& aSCvs,
112 const BOPTools_PaveSet& aPSF,
113 TColStd_IndexedMapOfInteger& aMapUnUsed);
114static
115 Standard_Boolean VertexRangeTolerance(const Standard_Integer nV,
116 const Standard_Integer nF1,
117 const Standard_Integer nF2,
118 const BOPTools_InterferencePool& anIntrPool,
119 Standard_Real& aTolV);
120static
121 void FaceAndEdgeMap(const Standard_Integer nF,
122 const BOPTools_InterferencePool& anIntrPool,
123 TColStd_IndexedMapOfInteger& aMEF);
124static
125 void ProcessAloneStickVertices(const Standard_Integer nF1,
126 const Standard_Integer nF2,
127 const BOPTools_PaveSet& aPSF,
128 BOPTools_SequenceOfCurves& aSCvs,
129 const BOPTools_InterferencePool& anIntrPool,
130 BOPTools_PaveFiller& aPF,
131 TColStd_SequenceOfInteger& aSeqVx,
132 TColStd_SequenceOfReal& aSeqTolVx);
133
134//wkar OCC334 t
135
136static
137 Standard_Boolean IsPairFound(const Standard_Integer nF1,
138 const Standard_Integer nF2,
139 BOPTools_InterferencePool* myIntrPool,
140 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
141 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith);
142
143static Standard_Boolean CheckNewVertexAndUpdateData(const TopoDS_Vertex& theVertex,
144 const Standard_Real theParamOnE,
145 const TopoDS_Edge& theEdge,
146 const Standard_Real theParamOnCurve,
147 const Standard_Integer theIndexF1,
148 const Standard_Integer theIndexF2,
149 const Standard_Real theTolerance,
150 const BOPTools_PInterferencePool& theIntrPool,
151 const BooleanOperations_PShapesDataStructure& theDS,
152 IntTools_Context* theContext,
153 const BOPTools_PaveSet& theEdgePaveSet,
154 const Standard_Boolean bAddNewVertex,
155 const Standard_Boolean bAddOldVertex,
156 BOPTools_Curve& theBC,
157 BOPTools_Pave& thePaveToPut,
158 Standard_Boolean& bAddNewVertexOut,
159 Standard_Boolean& bAddOldVertexOut);
160
161static void AddInterfForAdjacentFace(const Standard_Integer theEdgeIndex,
162 const Standard_Integer theIndexF1,
163 const Standard_Integer theIndexF2,
164 BOPTools_PInterferencePool theIntrPool,
165 const BooleanOperations_PShapesDataStructure& theDS);
166
167static Standard_Boolean RejectPaveBlock(const IntTools_Curve& theC,
168 const Standard_Real theT1,
169 const Standard_Real theT2,
170 const TopoDS_Vertex& theV,
171 Standard_Real& theRT);
172
173static Standard_Boolean ModifFFTol(const TopoDS_Face& theF1,
174 const TopoDS_Face& theF2,
175 Standard_Real& theTF);
176
177static Standard_Integer RejectBuildingEdge(const IntTools_Curve& theC,
178 const TopoDS_Vertex& theV1,
179 const TopoDS_Vertex& theV2,
180 const Standard_Real theT1,
181 const Standard_Real theT2,
182 const TopTools_ListOfShape& theL,
183 Standard_Real& theTF);
184
185//=======================================================================
186// function: PerformFF
187// purpose:
188//=======================================================================
189 void BOPTools_PaveFiller::PerformFF()
190{
191 myIsDone=Standard_False;
192 Standard_Boolean bIsFound;
193 Standard_Integer n1, n2, anIndexIn=0, nF1, nF2, aNbFFs, aBlockLength;
194 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger aMapWhat, aMapWith;
195 //
196 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
197 //
198 // F/F Interferences [BooleanOperations_SurfaceSurface]
199 myDSIt.Initialize(TopAbs_FACE, TopAbs_FACE);
200 //
201 // BlockLength correction
202 aNbFFs=ExpectedPoolLength();
203 aBlockLength=aFFs.BlockLength();
204 if (aNbFFs > aBlockLength) {
205 aFFs.SetBlockLength(aNbFFs);
206 }
207 //
208 for (; myDSIt.More(); myDSIt.Next()) {
209 Standard_Boolean justaddinterference = Standard_True;
210 myDSIt.Current(n1, n2, justaddinterference);
211
212 if(justaddinterference) {
213 if (!myIntrPool->IsComputed(n1, n2)) {
214
215 if(n1 < n2) {
216 nF1 = n1;
217 nF2 = n2;
218 }
219 else {
220 nF1 = n2;
221 nF2 = n1;
222 }
223 //
224 bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
225 //
226 if (!bIsFound) {
227 myIntrPool->AddInterference (nF1, nF2, BooleanOperations_SurfaceSurface, anIndexIn);
228 }
229 else {
230 IntTools_SequenceOfPntOn2Faces aPnts;
231 IntTools_SequenceOfCurves aCvs;
232
233 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
234 anIndexIn=aFFs.Append(anInterf);
235 myIntrPool->AddInterference (nF1, nF2, BooleanOperations_SurfaceSurface, anIndexIn);
236 }
237 }
238 continue;
239 }
240 //
241 if (myIntrPool->IsComputed(n1, n2)) {
242 continue;
243 }
244 //
245 nF1=n1;
246 nF2=n2;
247 if (nF1 > nF2) {
248 Standard_Integer iTmp;
249 iTmp=nF1;
250 nF1=nF2;
251 nF2=iTmp;
252 }
253 //
254 TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));
255 TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));
256 //
257 IntSurf_ListOfPntOn2S aListOfPnts;
258 GeomAPI_ProjectPointOnSurf& aProj1 = myContext.ProjPS(aF1);
259 GeomAPI_ProjectPointOnSurf& aProj2 = myContext.ProjPS(aF2);
260
261 BOPTools_CArray1OfESInterference& aEFs=myIntrPool->ESInterferences();
262 TColStd_MapOfInteger aMapEdgeIndex1, aMapEdgeIndex2;
263 for(Standard_Integer fIt = 0; fIt < 2; fIt++) {
264 Standard_Integer nF = (fIt == 0) ? nF1 : nF2;
265 for(Standard_Integer sIt1 = 1; sIt1 <= myDS->NumberOfSuccessors(nF); sIt1++) {
266 Standard_Integer nIndexS1 = myDS->GetSuccessor(nF, sIt1);
267 if(myDS->GetShapeType(nIndexS1) == TopAbs_EDGE) {
268 if(fIt == 0)
269 aMapEdgeIndex1.Add(nIndexS1);
270 else
271 aMapEdgeIndex2.Add(nIndexS1);
272 }
273 else {
274 for(Standard_Integer sIt2 = 1; sIt2 <= myDS->NumberOfSuccessors(nIndexS1); sIt2++) {
275 Standard_Integer nIndexS2 = myDS->GetSuccessor(nIndexS1, sIt2);
276
277 if(myDS->GetShapeType(nIndexS2) == TopAbs_EDGE) {
278 if(fIt == 0)
279 aMapEdgeIndex1.Add(nIndexS2);
280 else
281 aMapEdgeIndex2.Add(nIndexS2);
282 }
283 }
284 }
285 }
286
287 TColStd_MapIteratorOfMapOfInteger anIt;
288 if(fIt == 0)
289 anIt.Initialize(aMapEdgeIndex1);
290 else
291 anIt.Initialize(aMapEdgeIndex2);
292
293 Standard_Integer nFOpposite = (fIt == 0) ? nF2 : nF1;
294
295 for(; anIt.More(); anIt.Next()) {
296 Standard_Integer nIndexE = anIt.Key();
297
298 for(Standard_Integer interIt = 1; interIt <= aEFs.Length(); interIt++) {
299 const BOPTools_ESInterference& aEF = aEFs(interIt);
300
301 if((aEF.Index1() == nIndexE) && (nFOpposite == aEF.Index2())) {
302 IntTools_CommonPrt aCP = aEF.CommonPrt();
303
304 if(aCP.Type() == TopAbs_VERTEX) {
305 Standard_Real aPar = aCP.VertexParameter1();
306 // compute points and add to the list
307 Standard_Real f,l;
308 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(myDS->GetShape(nIndexE)), f,l);
309 Handle(Geom2d_Curve) aPCurve;
310 if(fIt == 0) {
311 aPCurve = BRep_Tool::CurveOnSurface(TopoDS::Edge(myDS->GetShape(nIndexE)),
312 aF1, f, l);
313 }
314 else {
315 aPCurve = BRep_Tool::CurveOnSurface(TopoDS::Edge(myDS->GetShape(nIndexE)),
316 aF2, f, l);
317 }
318
319 gp_Pnt aPoint;
320 aCurve->D0(aPar, aPoint);
321 Standard_Real U1,V1,U2,V2;
322 IntSurf_PntOn2S aPnt;
323 if(!aPCurve.IsNull()) {
324 gp_Pnt2d aP2d = aPCurve->Value(aPar);
325 if(fIt == 0) {
326 aProj2.Perform(aPoint);
327 if(aProj2.IsDone()) {
328 aProj2.LowerDistanceParameters(U2,V2);
329 aPnt.SetValue(aP2d.X(),aP2d.Y(),U2,V2);
330 aListOfPnts.Append(aPnt);
331 }
332 }
333 else {
334 aProj1.Perform(aPoint);
335 if(aProj1.IsDone()) {
336 aProj1.LowerDistanceParameters(U1,V1);
337 aPnt.SetValue(U1,V1,aP2d.X(),aP2d.Y());
338 aListOfPnts.Append(aPnt);
339 }
340 }
341 }
342 else {
343 aProj1.Perform(aPoint);
344 aProj2.Perform(aPoint);
345 if(aProj1.IsDone() && aProj2.IsDone()){
346 aProj1.LowerDistanceParameters(U1,V1);
347 aProj2.LowerDistanceParameters(U2,V2);
348 aPnt.SetValue(U1,V1,U2,V2);
349 aListOfPnts.Append(aPnt);
350 }
351 }
352 }
353 }
354 }
355 }
356 }
357 //
358 // FF
359 Standard_Boolean bToApproxC3d, bToApproxC2dOnS1, bToApproxC2dOnS2, bIsDone;
360 Standard_Real anApproxTol, aTolR3D, aTolR2D;
361 //
362 bToApproxC3d = mySectionAttribute.Approximation();
363 bToApproxC2dOnS1 = mySectionAttribute.PCurveOnS1();
364 bToApproxC2dOnS2 = mySectionAttribute.PCurveOnS2();
365 //
366 anApproxTol=1.e-7;
367
368 IntTools_FaceFace aFF;
369 aFF.SetParameters (bToApproxC3d,
370 bToApproxC2dOnS1,
371 bToApproxC2dOnS2,
372 anApproxTol);
373 //
374 if (!aListOfPnts.IsEmpty()) {
375 aFF.SetList(aListOfPnts);
376 }
377 //
378 aFF.Perform(aF1, aF2);
379 //
380 bIsDone=aFF.IsDone();
381 if (bIsDone) {
382 // Add Interference to the Pool
383 aTolR3D=aFF.TolReached3d();
384 aTolR2D=aFF.TolReached2d();
385 if (aTolR3D < 1.e-7){
386 aTolR3D=1.e-7;
387 }
388 aFF.PrepareLines3D();
389 //
390 anIndexIn=0;
391 Standard_Integer aNbCurves, aNbPoints;
392
393 const IntTools_SequenceOfCurves& aCvs=aFF.Lines();
394 aNbCurves=aCvs.Length();
395 //
396 const IntTools_SequenceOfPntOn2Faces& aPnts=aFF.Points();
397 aNbPoints=aPnts.Length();
398
399 if (!aNbCurves && !aNbPoints) {
400 //
401 bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
402 //
403 if (!bIsFound) {
404 myIntrPool->AddInterference (nF1, nF2, BooleanOperations_SurfaceSurface, anIndexIn);
405 continue;
406 }
407 }
408 //
409 BOPTools_SSInterference anInterf (nF1, nF2, aTolR3D, aTolR2D, aCvs, aPnts);
410 anIndexIn=aFFs.Append(anInterf);
411
412 myIntrPool->AddInterference (nF1, nF2, BooleanOperations_SurfaceSurface, anIndexIn);
413 } //if (bIsDone)
414 //
415 else {
416 anIndexIn=0;
417 //
418 bIsFound=IsPairFound(nF1, nF2, myIntrPool, aMapWhat, aMapWith);
419 //
420 if (!bIsFound) {
421 myIntrPool->AddInterference (nF1, nF2, BooleanOperations_SurfaceSurface, anIndexIn);
422 }
423 else {
424 IntTools_SequenceOfPntOn2Faces aPnts;
425 IntTools_SequenceOfCurves aCvs;
426
427 BOPTools_SSInterference anInterf (nF1, nF2, 1.e-07, 1.e-07, aCvs, aPnts);
428 anIndexIn=aFFs.Append(anInterf);
429 myIntrPool->AddInterference (nF1, nF2, BooleanOperations_SurfaceSurface, anIndexIn);
430 }
431 }
432 }// for (; myDSIt.More(); myDSIt.Next())
433 myIsDone=Standard_True;
434}
435//=======================================================================
436// function: MakeBlocks
437// purpose:
438//=======================================================================
439 void BOPTools_PaveFiller::MakeBlocks()
440{
441 Standard_Integer i, j, aNbCurves, aNbFFs, nF1, nF2, aBid=0, nV1, nV2;
442 Standard_Real aTolR3D, aT1, aT2;
443 Standard_Boolean bValid, bCoincide;
444
445 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
446
447 aNbFFs=aFFs.Extent();
448
449 for (i=1; i<=aNbFFs; i++) {
450 BOPTools_SSInterference& aFFi=aFFs(i);
451 //
452 // Curves' tolerance
453 aTolR3D=aFFi.TolR3D();
454 //
455 // Faces
456 nF1=aFFi.Index1();
457 nF2=aFFi.Index2();
458 const TopoDS_Face& aF1=TopoDS::Face(myDS->GetShape(nF1));
459 const TopoDS_Face& aF2=TopoDS::Face(myDS->GetShape(nF2));
460
461 TColStd_MapOfInteger aMap;
462 BOPTools_ListOfPaveBlock aLPB;
463 SplitsInFace (aBid, nF1, nF2, aLPB);
464 SplitsInFace (aBid, nF2, nF1, aLPB);
465 SplitsOnFace (aBid, nF1, nF2, aLPB);
466
467 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
468 for (; anIt.More(); anIt.Next()) {
469 const BOPTools_PaveBlock& aPB=anIt.Value();
470 aFFi.AppendBlock(aPB);
471 nV1=aPB.Pave1().Index();
472 nV2=aPB.Pave2().Index();
473 aMap.Add(nV1);
474 aMap.Add(nV2);
475 }
476 // Put existing paves on curves
477 // BOPTools_PaveSet aPSF;
478 // PrepareSetForFace (nF1, nF2, aPSF);
479
480 BOPTools_SequenceOfCurves& aSCvs = aFFi.Curves();
481 aNbCurves=aSCvs.Length();
482
483 //
484 // Pave Blocks On Curves
485 //
486 Standard_Boolean bIsPaveBlock;
487 Standard_Integer iCheckIntermediatePoint;
488 //
489 for (j=1; j<=aNbCurves; j++) {
490 BOPTools_Curve& aBC=aSCvs(j);
491 const IntTools_Curve& aC= aBC.Curve();
492
493 BOPTools_PaveSet& aPaveSet=aBC.Set();
494 BOPTools_PaveBlockIterator aPBIter(0, aPaveSet);
495 for (; aPBIter.More(); aPBIter.Next()) {
496 BOPTools_PaveBlock& aPBNew=aPBIter.Value();
497 aPBNew.SetCurve(aC);
498 aPBNew.SetFace1(nF1);
499 aPBNew.SetFace2(nF2);
500 //
501 nV1=aPBNew.Pave1().Index();
502 nV2=aPBNew.Pave2().Index();
503
504 if (aMap.Contains(nV1) && aMap.Contains(nV2)) {
505 //
506 const BOPTools_ListOfPaveBlock& aLPBExisting=aFFi.PaveBlocks();
507 bIsPaveBlock=IsPaveBlock(nV1, nV2, aLPBExisting);
508 //
509 iCheckIntermediatePoint=1;
510 if (bIsPaveBlock) {
511 BOPTools_ListIteratorOfListOfPaveBlock anItLPB(aLPBExisting);
512
513 for (; anItLPB.More(); anItLPB.Next()) {
514 const BOPTools_PaveBlock& aPBR=anItLPB.Value();
515 iCheckIntermediatePoint=
516 CheckIntermediatePoint(aPBNew, aPBR, aTolR3D);
517 if (!iCheckIntermediatePoint) {
518 break;
519 }
520 }
521 bIsPaveBlock=bIsPaveBlock && !iCheckIntermediatePoint;
522 }
523 //
524 if (bIsPaveBlock) {
525 continue;
526 }
527 }
528 //
529 else {
530 iCheckIntermediatePoint=0;
531 }
532 //
533 aT1=aPBNew.Pave1().Param();
534 aT2=aPBNew.Pave2().Param();
535 //
536 if((nV1 == nV2) && (Abs(aT2 - aT1) < Precision::PConfusion())) {
537 continue;
538 }
539 //
540 // Checking of validity in 2D
541 //
542 Standard_Real aTolerance = (aTolR3D < 1.e-3) ? 1.e-3 : aTolR3D;
543 bValid=myContext.IsValidBlockForFaces(aT1, aT2, aC, aF1, aF2, aTolerance);
544 //
545 if (!bValid) {
546 continue;
547 }
548 //
549 // Checking the paveblocks for coinsidence with aLPB
550 bCoincide=CheckCoincidence (aPBNew, aFFi);
551 //
552 bCoincide=bCoincide && !iCheckIntermediatePoint;
553 //
554 if (bCoincide) {
555 continue;
556 }
557 //
558 // reject pave block (FF) v1==v2 for too small sect. edge
559 TopoDS_Vertex aV1=TopoDS::Vertex(myDS->GetShape(nV1));
560 TopoDS_Vertex aV2=TopoDS::Vertex(myDS->GetShape(nV2));
561 Standard_Boolean rejectPaveBlock = Standard_False;
562 if(aV1.IsSame(aV2)) {
563 Standard_Real aRT = 1.e-7;
564 rejectPaveBlock = RejectPaveBlock(aC,aT1,aT2,aV1,aRT);
565 if(rejectPaveBlock) {
566 if(aRT > 1.e-7) {
567 BRep_Builder BB;
568 BB.UpdateVertex( aV1, 2*aRT );
569 }
570 continue;
571 }
572 }
573 // -&&
574 //
575 aBC.AppendNewBlock(aPBNew);
576 }
577 } // end of for (j=1; j<=aNbCurves; j++)
578 }// end of for (i=1; i<=aNbFFs; i++)
579}
580//=======================================================================
581// function: MakeAloneVertices
582// purpose:
583//=======================================================================
584 void BOPTools_PaveFiller::MakeAloneVertices()
585{
586 Standard_Integer i, j, k, aNbFFs, aNbCurves, nF1, nF2, nV, aNbAlone, aNbV;
587 Standard_Boolean bFlag=Standard_False;
588
589 BOPTools_ListIteratorOfListOfPave anIt;
590 TColStd_IndexedMapOfInteger aMap;
591 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
592
593 aNbFFs=aFFs.Extent();
594 for (i=1; i<=aNbFFs; i++) {
595 BOPTools_SSInterference& aFFi=aFFs(i);
596
597 const IntTools_SequenceOfPntOn2Faces& aSeqAlonePnts=aFFi.AlonePnts();
598 aNbAlone=aSeqAlonePnts.Length();
599
600 if (!aNbAlone) {
601 continue;
602 }
603
604 nF1=aFFi.Index1();
605 nF2=aFFi.Index2();
606 //
607 TopoDS_Face aF1=TopoDS::Face(myDS->Shape(nF1));
608 TopoDS_Face aF2=TopoDS::Face(myDS->Shape(nF2));
609 //
610 // 1. fill aMap where all indices for (F/F) vertices are
611 aMap.Clear();
612
613 BOPTools_PaveSet aPSF;
614
615 PrepareSetForFace (nF1, nF2, aPSF);
616 const BOPTools_ListOfPave& aLPaves=aPSF.Set();
617 anIt.Initialize(aLPaves);
618 for (; anIt.More(); anIt.Next()) {
619 const BOPTools_Pave& aPave=anIt.Value();
620 nV=aPave.Index();
621 aMap.Add(nV);
622 }
623
624 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
625 aNbCurves=aSCvs.Length();
626 for (j=1; j<=aNbCurves; j++) {
627 BOPTools_Curve& aBC=aSCvs(j);
628 const BOPTools_PaveSet& aCPSF=aBC.Set();
629 const BOPTools_ListOfPave& aLPs=aCPSF.Set();
630 anIt.Initialize(aLPs);
631 for (; anIt.More(); anIt.Next()) {
632 const BOPTools_Pave& aPv=anIt.Value();
633 nV=aPv.Index();
634 aMap.Add(nV);
635 }
636 }
637 //
638 // 2. check alone points on closure with aMap's vertices
639 Standard_Integer iVV;
640 Standard_Real aTolVAlone, aTolF1, aTolF2;
641 TopoDS_Vertex aVAlone;
642 BRep_Builder aBB;
643
644 aTolF1=BRep_Tool::Tolerance(aF1);
645 aTolF2=BRep_Tool::Tolerance(aF2);
646 aTolVAlone=aTolF1+aTolF2;
647
648 aNbV=aMap.Extent();
649 for (j=1; j<=aNbAlone; ++j) {
650 const IntTools_PntOn2Faces& aP2F=aSeqAlonePnts(j);
651 const IntTools_PntOnFace& aPF1=aP2F.P1();
652 const gp_Pnt& aPAlone=aPF1.Pnt();
653 aBB.MakeVertex(aVAlone, aPAlone, aTolVAlone);
654 //
655 bFlag=Standard_True;
656 //
657 for (k=1; k<=aNbV; ++k) {
658 nV=aMap(k);
659 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
660
661 iVV= IntTools_Tools::ComputeVV (aVAlone, aV);
662 if (!iVV) {
663 // It means that aVAlone and aV coinsided so
664 // we do not need to insert aVAlone into the DS
665 bFlag=Standard_False;
666 break;
667 }
668
669 }
670 if (bFlag) {
671 Standard_Boolean bVF;
672 Standard_Integer aNewShape;
673 //
674 bVF=myContext.IsValidPointForFaces (aPAlone, aF1, aF2, 1.e-3);
675 //
676 if (bVF) {
677 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
678 myDS->InsertShapeAndAncestorsSuccessors(aVAlone, anASSeq);
679 aNewShape=myDS->NumberOfInsertedShapes();
680 myDS->SetState (aNewShape, BooleanOperations_ON);
681 //
682 TColStd_ListOfInteger& anAloneVertices=aFFi.AloneVertices();
683 anAloneVertices.Append(aNewShape);
684 }
685 }
686 }
687
688 }
689}
690//=======================================================================
691// function: CheckCoincidence
692// purpose:
693//=======================================================================
694 Standard_Boolean BOPTools_PaveFiller::CheckCoincidence(const BOPTools_PaveBlock& aPB,
695 const BOPTools_SSInterference& aFFi)
696
697{
698 Standard_Real aTolC, aTE, aT11, aT12;
699 Standard_Integer nV11, nV12, nV21, nV22, iVV, iVE, nE2, iCount=0, iCountExt=1;
700 Standard_Integer iV;
701
702 aTolC=aFFi.TolR3D();
703 // V11
704 const BOPTools_Pave& aPave11=aPB.Pave1();
705 nV11=aPave11.Index();
706 const TopoDS_Vertex& aV11=TopoDS::Vertex(myDS->GetShape(nV11));
707 aT11=aPave11.Param();
708 // V12
709 const BOPTools_Pave& aPave12=aPB.Pave2();
710 nV12=aPave12.Index();
711 const TopoDS_Vertex& aV12=TopoDS::Vertex(myDS->GetShape(nV12));
712 aT12=aPave12.Param();
713 //
714 const BOPTools_ListOfPaveBlock& aLPB=aFFi.PaveBlocks();
715 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
716 for (; anIt.More(); anIt.Next()) {
717
718 iCount=0;
719
720 const BOPTools_PaveBlock& aPBR=anIt.Value();
721 // V21
722 const BOPTools_Pave& aPave21=aPBR.Pave1();
723 nV21=aPave21.Index();
724 const TopoDS_Vertex& aV21=TopoDS::Vertex(myDS->GetShape(nV21));
725 // V22
726 const BOPTools_Pave& aPave22=aPBR.Pave2();
727 nV22=aPave22.Index();
728 const TopoDS_Vertex& aV22=TopoDS::Vertex(myDS->GetShape(nV22));
729 // E2
730 nE2=aPBR.Edge();
731 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->GetShape(nE2));
732 //
733 // VV
734 iV=0;
735 iVV=IntTools_Tools::ComputeVV (aV11, aV21);
736 if (!iVV) {
737 iCount++;
738 iV++;
739 if (iCount>iCountExt) {
740 break;
741 }
742 }
743
744 iVV=IntTools_Tools::ComputeVV (aV11, aV22);
745 if (!iVV) {
746 iCount++;
747 iV++;
748 if (iCount>iCountExt) {
749 break;
750 }
751 }
752
753 // VE
754 if (!iV) {
755 iVE=myContext.ComputeVE (aV11, aE2, aTE);
756 if (!iVE) {
757 iCount++;
758 if (iCount>iCountExt) {
759 break;
760 }
761 }
762 }
763 //
764 // VV
765 iV=0;
766 iVV=IntTools_Tools::ComputeVV (aV12, aV21);
767 if (!iVV) {
768 iCount++;
769 iV++;
770 if (iCount>iCountExt) {
771 break;
772 }
773 }
774
775 iVV=IntTools_Tools::ComputeVV (aV12, aV22);
776 if (!iVV) {
777 iCount++;
778 iV++;
779 if (iCount>iCountExt) {
780 break;
781 }
782 }
783 // VE
784 if (!iV) {
785 //
786 iVE=myContext.ComputeVE (aV12, aE2, aTE);
787 //
788 if (!iVE) {
789 iCount++;
790 if (iCount>iCountExt) {
791 break;
792 }
793 }
794 }
795
796 } // next aPBR
797 return (iCount>iCountExt);
798}
799//=======================================================================
800// function: CheckIntermediatePoint
801// purpose:
802//=======================================================================
803 Standard_Integer BOPTools_PaveFiller::CheckIntermediatePoint(const BOPTools_PaveBlock& aPB,
804 const BOPTools_PaveBlock& aPBR,
805 const Standard_Real aTolC)
806
807{
808 Standard_Real aT11, aT12, aTM, aTmp;
809 Standard_Integer iVM, nE2;
810
811 gp_Pnt aPM;
812 BRep_Builder aBB;
813 TopoDS_Vertex aVM;
814 //
815 // Vertex
816 const BOPTools_Pave& aPave11=aPB.Pave1();
817 aT11=aPave11.Param();
818 //
819 const BOPTools_Pave& aPave12=aPB.Pave2();
820 aT12=aPave12.Param();
821 //
822 aTM=IntTools_Tools::IntermediatePoint (aT11, aT12);
823 //
824 const IntTools_Curve& aIC=aPB.Curve();
825 aIC.D0(aTM, aPM);
826 //
827 aBB.MakeVertex (aVM, aPM, aTolC);
828 //
829 //Edge
830 nE2=aPBR.Edge();
831 const TopoDS_Edge& aE2=TopoDS::Edge(myDS->GetShape(nE2));
832 // VE
833 iVM=myContext.ComputeVE(aVM, aE2, aTmp);
834 //
835 return iVM;
836}
837//=======================================================================
838// function: PutBoundPaveOnCurve
839// purpose:
840//=======================================================================
841 void BOPTools_PaveFiller::PutBoundPaveOnCurve(BOPTools_Curve& aBC,
842 BOPTools_SSInterference& aFFi)
843{
844 Standard_Boolean bHasBounds, bVF;
845
846
847 const IntTools_Curve& aIC=aBC.Curve();
848 bHasBounds=aIC.HasBounds ();
849
850 if (!bHasBounds){
851 return;
852 }
853
854 Standard_Integer nF1, nF2;
855 Standard_Real aT1, aT2, aTolR3D;
856 gp_Pnt aP1, aP2;
857 //
858 // Bounds
859 aIC.Bounds (aT1, aT2, aP1, aP2);
860 //
861 // Faces
862 nF1=aFFi.Index1();
863 nF2=aFFi.Index2();
864 //
865 aTolR3D=aFFi.TolR3D();
866 //
867 TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));
868 TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));
869 //
870 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
871 //
872 if (bVF) {
873 PutBoundPaveOnCurve (aP1, aT1, aBC, aFFi);
874 }
875 //
876 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
877 //
878 if (bVF) {
879 PutBoundPaveOnCurve (aP2, aT2, aBC, aFFi);
880 }
881}
882//=======================================================================
883// function: PutBoundPaveOnCurve
884// purpose:
885//=======================================================================
886 void BOPTools_PaveFiller::PutBoundPaveOnCurve(const gp_Pnt& aP,
887 const Standard_Real aT,
888 BOPTools_Curve& aBC,
889 BOPTools_SSInterference& aFFi)
890{
891 Standard_Boolean bFound1, bFound2;
892 Standard_Integer nV;
893 Standard_Real aTolV=aFFi.TolR3D();
894
895 BOPTools_Pave aPave1, aPave2, aPave;
896 BOPTools_PaveSet& aCPS=aBC.Set();
897 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
898 const IntTools_Curve& aIC=aBC.Curve();
899
900 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
901 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
902
903 if (!bFound1 && !bFound2) {
904 TopoDS_Vertex aNewVertex;
905 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
906 //
907 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
908 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
909 nV=myDS->NumberOfInsertedShapes();
910 aPave.SetIndex(nV);
911 aPave.SetParam(aT);
912
913 aCPS.Append(aPave);
914 aFFiPS.Append(aPave);
915 //
916 // Append Techno Vertex to the Curve
917 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
918 aTVs.Append(nV);
919 }
920
921 if (bFound1 && !bFound2) {
922 nV=aPave1.Index();
923 aPave.SetIndex(nV);
924 aPave.SetParam(aT);
925 aFFiPS.Append(aPave);
926 //
927 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
928 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
929 }
930
931 if (!bFound1 && bFound2) {
932 nV=aPave2.Index();
933 aPave.SetIndex(nV);
934 aPave.SetParam(aT);
935 aCPS.Append(aPave);
936 //
937 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
938 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
939 }
940}
941
942//=======================================================================
943// function: PutBoundPaveOnCurveSpec
944// purpose:
945//=======================================================================
946 void BOPTools_PaveFiller::PutBoundPaveOnCurveSpec(BOPTools_Curve& aBC,
947 BOPTools_SSInterference& aFFi)
948{
949 Standard_Boolean bHasBounds, bVF;
950
951
952 const IntTools_Curve& aIC=aBC.Curve();
953 bHasBounds=aIC.HasBounds ();
954
955 if (!bHasBounds){
956 return;
957 }
958
959 Standard_Integer nF1, nF2;
960 Standard_Real aT1, aT2, aTolR3D;
961 gp_Pnt aP1, aP2;
962 //
963 // Bounds
964 aIC.Bounds (aT1, aT2, aP1, aP2);
965 //
966 // Faces
967 nF1=aFFi.Index1();
968 nF2=aFFi.Index2();
969 //
970 aTolR3D=aFFi.TolR3D();
971 //
972 TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));
973 TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));
974 //
975 bVF=myContext.IsValidPointForFaces (aP1, aF1, aF2, aTolR3D);
976 //
977 if (bVF) {
978 PutBoundPaveOnCurveSpec (aP1, aT1, aBC, aFFi);
979 }
980 //
981 bVF=myContext.IsValidPointForFaces (aP2, aF1, aF2, aTolR3D);
982 //
983 if (bVF) {
984 PutBoundPaveOnCurveSpec (aP2, aT2, aBC, aFFi);
985 }
986}
987//=======================================================================
988// function: PutBoundPaveOnCurveSpec
989// purpose:
990//=======================================================================
991 void BOPTools_PaveFiller::PutBoundPaveOnCurveSpec(const gp_Pnt& aP,
992 const Standard_Real aT,
993 BOPTools_Curve& aBC,
994 BOPTools_SSInterference& aFFi)
995{
996 Standard_Boolean bFound1, bFound2;
997 Standard_Integer nV;
998 Standard_Real aTolV=aFFi.TolR3D();
999
1000 BOPTools_Pave aPave1, aPave2, aPave;
1001 BOPTools_PaveSet& aCPS=aBC.Set();
1002 BOPTools_PaveSet& aFFiPS=aFFi.NewPaveSet();
1003 const IntTools_Curve& aIC=aBC.Curve();
1004
1005 bFound1=FindPave(aP, aTolV, aCPS , aPave1);
1006 bFound2=FindPave(aP, aTolV, aFFiPS, aPave2);
1007
1008 if (!bFound1 && !bFound2) {
1009 TopoDS_Vertex aNewVertex;
1010 BOPTools_Tools::MakeNewVertex(aP, aTolV, aNewVertex);
1011 //
1012 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
1013 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
1014 nV=myDS->NumberOfInsertedShapes();
1015 aPave.SetIndex(nV);
1016 aPave.SetParam(aT);
1017
1018 aCPS.Append(aPave);
1019 aFFiPS.Append(aPave);
1020 //
1021 // Append Techno Vertex to the Curve
1022 TColStd_ListOfInteger& aTVs=aBC.TechnoVertices();
1023 aTVs.Append(nV);
1024 //
1025 //To check, if face boundary must be split by new vertex
1026 TopTools_MapOfShape aMap;
1027 Standard_Real aPar;
1028 Standard_Integer anErrStat;
1029 Standard_Integer aWhat, aWith, anIndexIn;
1030 BOPTools_CArray1OfVEInterference& aVEs=myIntrPool->VEInterferences();
1031 // Faces
1032 Standard_Integer nF1=aFFi.Index1();
1033 const TopoDS_Shape aF1 = myDS->GetShape(nF1);
1034 //
1035 Standard_Integer nF2=aFFi.Index2();
1036 const TopoDS_Shape aF2 = myDS->GetShape(nF2);
1037 //
1038 //
1039 Standard_Integer aRank = myDS->Rank(nF1);
1040 TopExp_Explorer anExp(aF1, TopAbs_EDGE);
1041 for(; anExp.More(); anExp.Next()) {
1042
1043 const TopoDS_Shape& anE = anExp.Current();
1044 if (BRep_Tool::Degenerated(TopoDS::Edge(anE))){
1045 continue;
1046 }
1047
1048 if(!aMap.Add(anE)) continue;
1049
1050 anErrStat =
1051 myContext.ComputeVE(aNewVertex, TopoDS::Edge(anE), aPar);
1052 if(anErrStat) continue;
1053 //
1054 Standard_Real aT1, aT2;
1055 gp_Pnt aP1, aP2;
1056 aIC.Bounds(aT1, aT2, aP1, aP2);
1057 //Check if any other point on curve belongs edge
1058 aT1 = 0.5*(aT1+aT2);
1059 aIC.D0(aT1, aP1);
1060 TopoDS_Vertex aNewVertex1;
1061 BOPTools_Tools::MakeNewVertex(aP1, aTolV, aNewVertex1);
1062 anErrStat =
1063 myContext.ComputeVE(aNewVertex1, TopoDS::Edge(anE), aT1);
1064 if(!anErrStat) continue; //curve and edge seem to be coincide
1065
1066 aWhat = nV;
1067 aWith = myDS->ShapeIndex(anE, aRank);
1068 BOPTools_VEInterference anInterf (aWhat, aWith, aPar);
1069 anIndexIn=aVEs.Append(anInterf);
1070 //
1071 // Add Pave to the Edge's myPavePool
1072 BOPTools_Pave aPave3(aWhat, aPar, BooleanOperations_VertexEdge);
1073 aPave3.SetInterference(anIndexIn);
1074 BOPTools_PaveSet& aPaveSet= myPavePool(myDS->RefEdge(aWith));
1075 aPaveSet.Append(aPave3);
1076
1077 //
1078 // State for the Vertex in DS;
1079 myDS->SetState (aWhat, BooleanOperations_ON);
1080 // Insert Vertex in Interference Object
1081 BOPTools_VEInterference& aVE=aVEs(anIndexIn);
1082 aVE.SetNewShape(aWhat);
1083
1084 PreparePaveBlocks(aWith);
1085 RecomputeCommonBlocks(aWith);
1086 }
1087 //
1088 aRank = myDS->Rank(nF2);
1089 anExp.Init(aF2, TopAbs_EDGE);
1090 for(; anExp.More(); anExp.Next()) {
1091 const TopoDS_Shape& anE = anExp.Current();
1092 if (BRep_Tool::Degenerated(TopoDS::Edge(anE))){
1093 continue;
1094 }
1095
1096 if(!aMap.Add(anE)) continue;
1097
1098 anErrStat =
1099 myContext.ComputeVE(aNewVertex, TopoDS::Edge(anE), aPar);
1100 if(anErrStat) continue;
1101 //
1102 Standard_Real aT1, aT2;
1103 gp_Pnt aP1, aP2;
1104 aIC.Bounds(aT1, aT2, aP1, aP2);
1105 //Check if any other point on curve belongs edge
1106 aT1 = 0.5*(aT1+aT2);
1107 aIC.D0(aT1, aP1);
1108 TopoDS_Vertex aNewVertex1;
1109 BOPTools_Tools::MakeNewVertex(aP1, aTolV, aNewVertex1);
1110 anErrStat =
1111 myContext.ComputeVE(aNewVertex1, TopoDS::Edge(anE), aT1);
1112 if(!anErrStat) continue; //curve and edge seem to be coincide
1113
1114 aWhat = nV;
1115 aWith = myDS->ShapeIndex(anE, aRank);
1116 BOPTools_VEInterference anInterf (aWhat, aWith, aPar);
1117 anIndexIn=aVEs.Append(anInterf);
1118 //
1119 // Add Pave to the Edge's myPavePool
1120 BOPTools_Pave aPave3(aWhat, aPar, BooleanOperations_VertexEdge);
1121 aPave3.SetInterference(anIndexIn);
1122 BOPTools_PaveSet& aPaveSet= myPavePool(myDS->RefEdge(aWith));
1123 aPaveSet.Append(aPave3);
1124
1125 //
1126 // State for the Vertex in DS;
1127 myDS->SetState (aWhat, BooleanOperations_ON);
1128 // Insert Vertex in Interference Object
1129 BOPTools_VEInterference& aVE=aVEs(anIndexIn);
1130 aVE.SetNewShape(aWhat);
1131
1132 PreparePaveBlocks(aWith);
1133 RecomputeCommonBlocks(aWith);
1134 }
1135 //
1136 }
1137
1138 if (bFound1 && !bFound2) {
1139 nV=aPave1.Index();
1140 aPave.SetIndex(nV);
1141 aPave.SetParam(aT);
1142 aFFiPS.Append(aPave);
1143 //
1144 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
1145 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1146 }
1147
1148 if (!bFound1 && bFound2) {
1149 nV=aPave2.Index();
1150 aPave.SetIndex(nV);
1151 aPave.SetParam(aT);
1152 aCPS.Append(aPave);
1153 //
1154 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
1155 BOPTools_Tools::UpdateVertex (aIC, aT, aV);
1156 }
1157}
1158//=======================================================================
1159// function: FindPave
1160// purpose:
1161//=======================================================================
1162 Standard_Boolean BOPTools_PaveFiller::FindPave(const gp_Pnt& aP,
1163 const Standard_Real aTolPV,
1164 const BOPTools_PaveSet& aPS,
1165 BOPTools_Pave& aPave)
1166{
1167 Standard_Integer nV;
1168 Standard_Boolean bIsVertex=Standard_False;
1169
1170 const BOPTools_ListOfPave& aLP=aPS.Set();
1171 BOPTools_ListIteratorOfListOfPave anIt(aLP);
1172 for (; anIt.More(); anIt.Next()) {
1173 const BOPTools_Pave& aPC=anIt.Value();
1174 nV=aPC.Index();
1175 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->GetShape(nV));
1176 bIsVertex=IntTools_Tools::IsVertex (aP, aTolPV, aV);
1177 if (bIsVertex) {
1178 aPave=aPC;
1179 return bIsVertex;
1180 }
1181 }
1182 return bIsVertex;
1183}
1184//=======================================================================
1185// function: MakeSectionEdges
1186// purpose:
1187//=======================================================================
1188 void BOPTools_PaveFiller::MakeSectionEdges()
1189{
1190 Standard_Integer i, j, aNbCurves, aNbFFs, nF1, nF2, nV1, nV2, aNbPaveBlocks,
1191 aNewShapeIndex ;
1192 Standard_Real t1, t2;
1193 TopoDS_Edge aESect;
1194 TopoDS_Vertex aV1, aV2;
1195 BRep_Builder BB;
1196
1197 Standard_Integer pbi = 0;
1198
1199
1200 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
1201
1202 aNbFFs=aFFs.Extent();
1203 for (i=1; i<=aNbFFs; i++) {
1204 BOPTools_SSInterference& aFFi=aFFs(i);
1205 nF1=aFFi.Index1();
1206 nF2=aFFi.Index2();
1207 //
1208 Standard_Real aTF = 1.e-7;
1209 TopoDS_Face aF1=TopoDS::Face(myDS->GetShape(nF1));
1210 TopoDS_Face aF2=TopoDS::Face(myDS->GetShape(nF2));
1211 Standard_Boolean isModT = ModifFFTol(aF1,aF2,aTF);
1212 Standard_Real aTolFF = (isModT) ? Max(aTF,aFFi.TolR3D()) : aFFi.TolR3D();
1213 BOPTools_ListOfPaveBlock aFFPBL;
1214 TopTools_ListOfShape aFFSEL;
1215 //
1216 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
1217 aNbCurves=aSCvs.Length();
1218 for (j=1; j<=aNbCurves; j++) {
1219 BOPTools_Curve& aBC=aSCvs(j);
1220 const IntTools_Curve& aIC=aBC.Curve();
1221 //
1222 const BOPTools_ListOfPaveBlock& aSectEdges=aBC.NewPaveBlocks();
1223 aNbPaveBlocks=aSectEdges.Extent();
1224 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges);
1225 pbi = 0;
1226 for (; aPBIt.More(); aPBIt.Next()) {
1227 pbi++;
1228 BOPTools_PaveBlock& aPB=aPBIt.Value();
1229 //
1230 // Pave1
1231 const BOPTools_Pave& aPave1=aPB.Pave1();
1232 nV1=aPave1.Index();
1233 t1=aPave1.Param();
1234 aV1=TopoDS::Vertex(myDS->GetShape(nV1));
1235 aV1.Orientation(TopAbs_FORWARD);
1236 //
1237 // Pave2
1238 const BOPTools_Pave& aPave2=aPB.Pave2();
1239 nV2=aPave2.Index();
1240 t2=aPave2.Param();
1241 aV2=TopoDS::Vertex(myDS->GetShape(nV2));
1242 aV2.Orientation(TopAbs_REVERSED);
1243 //
1244 // MakeSplitEdge
1245 //
1246 // reject building parallel sect. edge on the same pave block,
1247 // if distance between created and this edges is too small
1248 if(IsPaveBlock(nV1,nV2,aFFPBL)) {
1249 Standard_Real diffTol = 1.e-7;
1250 Standard_Integer eI = RejectBuildingEdge(aIC,aV1,aV2,t1,t2,aFFSEL,diffTol);
1251 if(eI != 0) {
1252 Standard_Integer eIndex = 0;
1253 TopTools_ListIteratorOfListOfShape aSEIt(aFFSEL);
1254 for(; aSEIt.More(); aSEIt.Next()) {
1255 eIndex++;
1256 if(eIndex == eI) {
1257 const TopoDS_Edge & aE = TopoDS::Edge(aSEIt.Value());
1258 TopoDS_Edge& anEdge = (TopoDS_Edge &) aE;
1259 BOPTools_ListOfPaveBlock& aListPB = (BOPTools_ListOfPaveBlock&) aSectEdges;
1260 aListPB.Remove(aPBIt);
1261 BB.UpdateEdge( anEdge, 2*(aTolFF+diffTol) );
1262 BB.UpdateVertex( aV1, 2*(aTolFF+diffTol) );
1263 BB.UpdateVertex( aV2, 2*(aTolFF+diffTol) );
1264 break;
1265 }
1266 }
1267 if(aPBIt.More())
1268 continue;
1269 else
1270 break;
1271 }
1272 }
1273
1274 if(fabs(t1-t2) <= 1.e-10) continue;
1275 BOPTools_Tools::MakeSectEdge (aIC, aV1, t1, aV2, t2, aESect);
1276 //
1277 BB.UpdateEdge( aESect, aTolFF );
1278 BB.UpdateVertex( aV1, aTolFF );
1279 BB.UpdateVertex( aV2, aTolFF );
1280 ///////////////////////////////////
1281 // Add Sect Part to the DS
1282 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
1283
1284 anASSeq.SetNewSuccessor(nV1);
1285 anASSeq.SetNewOrientation(aV1.Orientation());
1286
1287 anASSeq.SetNewSuccessor(nV2);
1288 anASSeq.SetNewOrientation(aV2.Orientation());
1289 //
1290 myDS->InsertShapeAndAncestorsSuccessors(aESect, anASSeq);
1291 aNewShapeIndex=myDS->NumberOfInsertedShapes();
1292 //
1293 aPB.SetEdge(aNewShapeIndex);
1294 //
1295 aFFSEL.Append(aESect);
1296 aFFPBL.Append(aPB);
1297 }
1298 }
1299 }
1300
1301}
1302//=======================================================================
1303// function: PutPaveOnCurve
1304// purpose:
1305//=======================================================================
1306 void BOPTools_PaveFiller::PutPaveOnCurve(const BOPTools_PaveSet& aPaveSet,
1307 const Standard_Real aTolR3D,
1308 BOPTools_Curve& aBC)
1309{
1310 const BOPTools_ListOfPave& aLP=aPaveSet.Set();
1311 BOPTools_ListIteratorOfListOfPave anIt(aLP);
1312 for (; anIt.More(); anIt.Next()) {
1313 const BOPTools_Pave& aPave=anIt.Value();
1314 PutPaveOnCurve (aPave, aTolR3D, aBC);
1315 }
1316}
1317//=======================================================================
1318// function: PutPaveOnCurve
1319// purpose:
1320//=======================================================================
1321 void BOPTools_PaveFiller::PutPaveOnCurve (const BOPTools_Pave& aPave,
1322 const Standard_Real aTolR3D,
1323 BOPTools_Curve& aBC)
1324{
1325 Standard_Integer nV;
1326 Standard_Boolean bIsVertexOnLine;
1327 Standard_Real aT, aTolVExt;
1328
1329
1330 nV=aPave.Index();
1331 const TopoDS_Vertex& aV=TopoDS::Vertex(myDS->Shape(nV));
1332 const IntTools_Curve& aC=aBC.Curve();
1333 Handle (Geom_Curve) aC3D= aC.Curve();
1334 //
1335 aTolVExt=BRep_Tool::Tolerance(aV);
1336 ExtendedTolerance(nV, aTolVExt);
1337 bIsVertexOnLine=myContext.IsVertexOnLine(aV, aTolVExt, aC, aTolR3D, aT);
1338 //
1339 if (bIsVertexOnLine) {
1340 BOPTools_Pave aPaveNew(nV, aT, BooleanOperations_SurfaceSurface);
1341 BOPTools_PaveSet& aPaveSet=aBC.Set();
1342 aPaveSet.Append(aPaveNew);
1343 //<-B
1344 BOPTools_Tools::UpdateVertex (aC, aT, aV);
1345 }
1346}
1347//
1348//=======================================================================
1349// function: ExtendedTolerance
1350// purpose:
1351//=======================================================================
1352 Standard_Boolean BOPTools_PaveFiller::ExtendedTolerance(const Standard_Integer nV,
1353 Standard_Real& aTolVExt)
1354{
1355 Standard_Boolean bFound, bIsNewShape;
1356 Standard_Integer k, i, aNbLines, aNewShape;
1357 Standard_Real aT11, aT12, aD1, aD2, aD;
1358 TopoDS_Vertex aV;
1359 gp_Pnt aPV, aP11, aP12;
1360 //
1361 bFound=Standard_False;
1362 //
1363 bIsNewShape=myDS->IsNewShape(nV);
1364 if (!bIsNewShape) {
1365 return bFound;
1366 }
1367 //
1368 aV=TopoDS::Vertex(myDS->Shape(nV));
1369 aPV=BRep_Tool::Pnt(aV);
1370 //
1371 const BOPTools_InterferencePool& anInterferencePool=*myIntrPool;
1372 const BOPTools_CArray1OfEEInterference& aEEInterfs=anInterferencePool.EEInterfs();
1373 const BOPTools_CArray1OfESInterference& aESInterfs=anInterferencePool.ESInterfs();
1374 //
1375 for (k=0; k<2; ++k) {
1376 aNbLines=(!k) ? aEEInterfs.Extent() : aESInterfs.Extent();
1377 for (i=1; i<=aNbLines; ++i) {
1378 BOPTools_ShapeShapeInterference *pI=(!k) ?
1379 (BOPTools_ShapeShapeInterference *)&aEEInterfs(i):
1380 (BOPTools_ShapeShapeInterference *)&aESInterfs(i);
1381 //
1382 aNewShape=pI->NewShape();
1383 if (aNewShape==nV) {
1384 const IntTools_CommonPrt& aCPart=(!k) ?
1385 aEEInterfs(i).CommonPrt() :
1386 aESInterfs(i).CommonPrt();
1387 //
1388 const TopoDS_Edge& aE1=aCPart.Edge1();
1389 aCPart.Range1(aT11, aT12);
1390 BOPTools_Tools::PointOnEdge(aE1, aT11, aP11);
1391 BOPTools_Tools::PointOnEdge(aE1, aT12, aP12);
1392 aD1=aPV.Distance(aP11);
1393 aD2=aPV.Distance(aP12);
1394 aD=(aD1>aD2)? aD1 : aD2;
1395 if (aD>aTolVExt) {
1396 aTolVExt=aD;
1397 }
1398 bFound=!bFound;
1399 return bFound;
1400 }
1401 }
1402 }
1403 //
1404 return bFound;
1405}
1406//
1407//=======================================================================
1408// function: PutPavesOnCurves
1409// purpose:
1410//=======================================================================
1411 void BOPTools_PaveFiller::PutPavesOnCurves ()
1412{
1413 Standard_Integer i, j, aNbCurves, aNbFFs, nF1, nF2, nV;
1414 Standard_Real aTolR3D = 0.;
1415
1416 BOPTools_CArray1OfSSInterference& aFFs=myIntrPool->SSInterferences();
1417
1418 aNbFFs=aFFs.Extent();
1419
1420 for (i=1; i<=aNbFFs; i++) {
1421 BOPTools_SSInterference& aFFi=aFFs(i);
1422 //
1423 // Curves' tolerance
1424 aTolR3D=aFFi.TolR3D();
1425 //
1426 // Faces
1427 nF1=aFFi.Index1();
1428 nF2=aFFi.Index2();
1429
1430 //
1431 // Put existing paves on curves
1432 BOPTools_PaveSet aPSF;
1433 PrepareSetForFace (nF1, nF2, aPSF);
1434
1435 BOPTools_SequenceOfCurves& aSCvs=aFFi.Curves();
1436 aNbCurves=aSCvs.Length();
1437 for (j=1; j<=aNbCurves; j++) {
1438 BOPTools_Curve& aBC=aSCvs(j);
1439 // DEBUG
1440 const IntTools_Curve& aC=aBC.Curve();
1441 Handle (Geom_Curve) aC3D= aC.Curve();
1442 //
1443 PutPaveOnCurve (aPSF, aTolR3D, aBC);
1444 }
1445
1446 //
1447 // Put bounding paves on curves
1448 //Check very specific case of cone-cone intersection (OCC13211)
1449
1450 Standard_Boolean bIsSpecific = Standard_False;
1451 if(aNbCurves >= 4) {
1452 const TopoDS_Shape aF1 = myDS->GetShape(nF1);
1453 BRepAdaptor_Surface aS1(TopoDS::Face(aF1), Standard_False);
1454 GeomAbs_SurfaceType aSType = aS1.GetType();
1455 if(aSType == GeomAbs_Cone) {
1456 const TopoDS_Shape aF2 = myDS->GetShape(nF2);
1457 BRepAdaptor_Surface aS2(TopoDS::Face(aF2), Standard_False);
1458 aSType = aS2.GetType();
1459 if(aSType == GeomAbs_Cone) {
1460 bIsSpecific = Standard_True;
1461 }
1462 }
1463 }
1464 //
1465 if(bIsSpecific) {
1466 for (j=1; j<=aNbCurves; j++) {
1467 BOPTools_Curve& aBC=aSCvs(j);
1468 PutBoundPaveOnCurveSpec (aBC, aFFi);
1469 }
1470 }
1471 else {
1472 for (j=1; j<=aNbCurves; j++) {
1473 BOPTools_Curve& aBC=aSCvs(j);
1474 PutBoundPaveOnCurve (aBC, aFFi);
1475 }
1476 }
1477 //
1478 // xxx
1479 for (j=1; j<=aNbCurves; j++) {
1480 BOPTools_Curve& aBC=aSCvs(j);
1481 BOPTools_ListOfPave anOldList;
1482 anOldList = aBC.Set().Set();
1483
1484 if (aBC.NewPaveBlocks().IsEmpty())
1485 continue;
1486 //
1487
1488 BOPTools_CArray1OfESInterference& aESs = myIntrPool->ESInterferences();
1489 Standard_Integer k, fit;
1490 //
1491 // Among all aESs find those that are between nE1 from nF1(nE2 from nF2) and nF2(nF1)
1492 for(k = 1; k <= aESs.Length(); k++) {
1493 BOPTools_ESInterference& aES = aESs(k);
1494
1495 if(aES.Index1() == nF1 || aES.Index2() == nF2) {
1496 Standard_Integer nE = (aES.Index1() == nF1) ? aES.Index2() : aES.Index1();
1497
1498 // check if it belongs to F1 or F2.begin
1499 Standard_Boolean edgefound = Standard_False;
1500
1501 for(fit = 0; !edgefound && (fit < 2); fit++) {
1502 Standard_Integer nF = (fit == 0) ? nF1 : nF2;
1503 Standard_Integer sit1 = 0, sit2 = 0;
1504
1505 for(sit1 = 1; !edgefound && (sit1 <= myDS->NumberOfSuccessors(nF)); sit1++) {
1506 Standard_Integer asuccessor = myDS->GetSuccessor(nF, sit1);
1507
1508 for(sit2 = 1; sit2 <= myDS->NumberOfSuccessors(asuccessor); sit2++) {
1509 if(nE == myDS->GetSuccessor(asuccessor, sit2)) {
1510 edgefound = Standard_True;
1511 break;
1512 }
1513 }
1514 }
1515 }
1516 // check if it belongs to F1 or F2.end
1517
1518 if(edgefound) {
1519 RestrictCurveIn2d (nE, nF1, nF2, aTolR3D, aBC);// ->
1520 }
1521 }
1522 }// for(k = 1; k <= aESs.Length(); k++)
1523
1524 for(fit = 1; fit <= 2; fit++) {
1525 Standard_Integer nF = (fit == 1) ? nF1 : nF2;
1526 Standard_Integer nFOpposite = (fit == 1) ? nF2 : nF1;
1527 TopExp_Explorer anExp(myDS->Shape(nF), TopAbs_EDGE);
1528
1529 for(; anExp.More(); anExp.Next()) {
1530 Standard_Integer nE = myDS->ShapeIndex(anExp.Current(), fit);
1531
1532 if(nE) {
1533 const BOPTools_ListOfInterference& aList =
1534 myIntrPool->InterferenceTable().Value(nE).GetOnType(BooleanOperations_EdgeSurface);
1535 BOPTools_ListIteratorOfListOfInterference anIt2(aList);
1536 Standard_Boolean bProcessed = Standard_False;
1537
1538 for(; anIt2.More(); anIt2.Next()) {
1539 if(anIt2.Value().With() == nFOpposite) {
1540 if(!bProcessed) {
1541 RestrictCurveIn2d (nE, nF1, nF2, aTolR3D, aBC);
1542 bProcessed = Standard_True;
1543 break;
1544 }
1545 }
1546 }
1547
1548 if(!myCommonBlockPool(myDS->RefEdge(nE)).IsEmpty() &&
1549 !bProcessed) {
1550 RestrictCurveIn2d (nE, nF1, nF2, aTolR3D, aBC);
1551 }
1552 }
1553 }
1554 }
1555 // end for(fit = 1...
1556
1557 // put new paves on other curves.begin
1558 BOPTools_ListOfPave aListOfNewPave;
1559 BOPTools_ListIteratorOfListOfPave anIt1, anIt2;
1560
1561 for(anIt1.Initialize(aBC.Set().Set()); anIt1.More(); anIt1.Next()) {
1562 Standard_Boolean bfound = Standard_False;
1563 for(anIt2.Initialize(anOldList); anIt2.More(); anIt2.Next()) {
1564 if(anIt1.Value().IsEqual(anIt2.Value())) {
1565 bfound = Standard_True;
1566 break;
1567 }
1568 }
1569
1570 if(!bfound) {
1571 aListOfNewPave.Append(anIt1.Value());
1572 }
1573 }
1574
1575 Standard_Integer m = 0, n = 0;
1576 for (m=1; m<=aNbFFs; m++) {
1577 BOPTools_SSInterference& aFFm = aFFs(m);
1578 //
1579 // Curves' tolerance
1580 Standard_Real aTolR3D2 = aFFm.TolR3D();
1581
1582 BOPTools_SequenceOfCurves& aSCvs2 = aFFm.Curves();
1583 Standard_Integer aNbCurves2 = aSCvs2.Length();
1584
1585 for(n = 1; n <= aNbCurves2; n++) {
1586 if((n == j) && (m == i))
1587 continue;
1588 BOPTools_Curve& aBC2 = aSCvs2(n);
1589
1590 for(anIt1.Initialize(aListOfNewPave); anIt1.More(); anIt1.Next()) {
1591 Standard_Boolean bfound = Standard_False;
1592 for(anIt2.Initialize(aBC2.Set().Set()); anIt2.More(); anIt2.Next()) {
1593 if(anIt1.Value().Index() == anIt2.Value().Index()) {
1594 bfound = Standard_True;
1595 break;
1596 }
1597 }
1598
1599 if(!bfound) {
1600 PutPaveOnCurve (anIt1.Value(), aTolR3D2, aBC2);
1601 }
1602 }
1603 }
1604 }
1605 // put new paves on other curves.end
1606 } // xxx for (j=1; j<=aNbCurves; j++)
1607
1608 //wkar OCC334 f
1609 {
1610 Standard_Integer aNbVtx, jx;
1611 Standard_Real aTolVRange;
1612 TColStd_SequenceOfInteger aSeqVx;
1613 TColStd_SequenceOfReal aSeqTolVx;
1614 //
1615 ProcessAloneStickVertices(nF1,
1616 nF2,
1617 aPSF,
1618 aSCvs,
1619 *myIntrPool,
1620 *this,
1621 aSeqVx,
1622 aSeqTolVx);
1623 //
1624 aNbVtx=aSeqVx.Length();
1625 for (jx=1; jx<=aNbVtx; ++jx) {
1626 BOPTools_PaveSet aPSFx;
1627 BOPTools_Pave aPVx;
1628
1629 nV=aSeqVx(jx);
1630 aTolVRange=aSeqTolVx(jx);
1631
1632 aPVx.SetIndex(nV);
1633 aPSFx.Append(aPVx);
1634
1635 for (j=1; j<=aNbCurves; j++) {
1636 BOPTools_Curve& aBC=aSCvs(j);
1637 // DEBUG
1638 const IntTools_Curve& aC=aBC.Curve();
1639 Handle (Geom_Curve) aC3D= aC.Curve();
1640 //
1641 PutPaveOnCurve (aPSFx, aTolVRange, aBC);
1642 }
1643 }
1644 }
1645 //wkar OCC334 t
1646 }
1647}
1648//=======================================================================
1649// function: PrepareSetForFace
1650// purpose:
1651//=======================================================================
1652 void BOPTools_PaveFiller::PrepareSetForFace(const Standard_Integer nF1,
1653 const Standard_Integer nF2,
1654 BOPTools_PaveSet& aPaveSet)
1655{
1656 Standard_Integer i, aNbV, nV;
1657 TColStd_IndexedMapOfInteger aMV;
1658 //
1659 StickVertices(nF1, nF2, aMV);
1660 //
1661 aNbV=aMV.Extent();
1662 for (i=1; i<=aNbV; ++i) {
1663 nV=aMV(i);
1664 BOPTools_Pave aPV;
1665 aPV.SetIndex(nV);
1666 aPaveSet.Append(aPV);
1667 }
1668}
1669//=======================================================================
1670// function: IsPaveBlock
1671// purpose:
1672//=======================================================================
1673Standard_Boolean IsPaveBlock(const Standard_Integer nV1,
1674 const Standard_Integer nV2,
1675 const BOPTools_ListOfPaveBlock& aLPBExisting)
1676{
1677 Standard_Boolean bFlag=Standard_True;
1678 Standard_Integer nVE1, nVE2;
1679
1680 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPBExisting);
1681 for (; anIt.More(); anIt.Next()) {
1682 const BOPTools_PaveBlock& aPBR=anIt.Value();
1683 //
1684 nVE1=aPBR.Pave1().Index();
1685 //
1686 nVE2=aPBR.Pave2().Index();
1687 //
1688 if ((nVE1==nV1 && nVE2==nV2) || (nVE2==nV1 && nVE1==nV2)) {
1689 return bFlag;
1690 }
1691 }
1692 return !bFlag;
1693}
1694
1695//=======================================================================
1696// function: FMapWhat
1697// purpose:
1698//=======================================================================
1699 void FMapWhat(const Standard_Integer nF,
1700 BOPTools_InterferencePool* myIntrPool,
1701 TColStd_IndexedMapOfInteger& aMapWhat)
1702
1703{
1704 Standard_Integer nE, nV;
1705
1706
1707
1708 BooleanOperations_ShapesDataStructure* myDS=myIntrPool->DS();
1709 BooleanOperations_OnceExplorer aExp(*myDS);
1710 //
1711 // What
1712 aMapWhat.Add(nF);
1713 aExp.Init(nF, TopAbs_VERTEX);
1714 for (; aExp.More(); aExp.Next()) {
1715 nV=aExp.Current();
1716 aMapWhat.Add(nV);
1717 }
1718 //
1719 aExp.Init(nF, TopAbs_EDGE);
1720 for (; aExp.More(); aExp.Next()) {
1721 nE=aExp.Current();
1722 aMapWhat.Add(nE);
1723 }
1724}
1725
1726//=======================================================================
1727// function: FMapWith
1728// purpose:
1729//=======================================================================
1730 void FMapWith(const Standard_Integer nF,
1731 BOPTools_InterferencePool* myIntrPool,
1732 TColStd_IndexedMapOfInteger& aMapWith)
1733{
1734 TColStd_IndexedMapOfInteger aMapWhat;
1735
1736 FMapWhat(nF, myIntrPool, aMapWhat);
1737 //
1738 // With
1739 Standard_Integer i, aNb, anIndex, aWhat, aWith;
1740 BOPTools_ListIteratorOfListOfInterference anIt;
1741
1742 const BOPTools_CArray1OfInterferenceLine& anArrIL= myIntrPool->InterferenceTable();
1743
1744 aNb=aMapWhat.Extent();
1745 for (i=1; i<=aNb; i++) {
1746 aWhat=aMapWhat(i);
1747
1748 const BOPTools_InterferenceLine& aWithLine=anArrIL(aWhat);
1749
1750 const BOPTools_ListOfInterference& aLI=aWithLine.List();
1751 anIt.Initialize(aLI);
1752 for (; anIt.More(); anIt.Next()) {
1753 const BOPTools_Interference& anIntf=anIt.Value();
1754 anIndex=anIntf.Index();
1755 if (anIndex) {
1756 aWith=anIntf.With();
1757 aMapWith.Add(aWith);
1758 }
1759 }
1760 }
1761}
1762
1763//=======================================================================
1764// function: IsFound
1765// purpose:
1766//=======================================================================
1767Standard_Boolean IsFound(const TColStd_IndexedMapOfInteger& aMapWhat,
1768 const TColStd_IndexedMapOfInteger& aMapWith)
1769{
1770 Standard_Boolean bFlag=Standard_False;
1771 Standard_Integer i, aNb, aWhat;
1772
1773 aNb=aMapWhat.Extent();
1774 for (i=1; i<=aNb; i++) {
1775 aWhat=aMapWhat(i);
1776 if (aMapWith.Contains(aWhat)) {
1777 return !bFlag;
1778 }
1779 }
1780 return bFlag;
1781}
1782
1783
1784//wkar OCC334 f
1785#include <BOPTools_CArray1OfESInterference.hxx>
1786#include <BOPTools_CArray1OfEEInterference.hxx>
1787#include <BOPTools_ESInterference.hxx>
1788#include <BOPTools_EEInterference.hxx>
1789#include <IntTools_CommonPrt.hxx>
1790#include <gp_Pnt.hxx>
1791#include <Geom_Curve.hxx>
1792#include <GeomAbs_SurfaceType.hxx>
1793#include <Geom_Surface.hxx>
1794#include <GeomAdaptor_Surface.hxx>
1795#include <GeomAPI_ProjectPointOnCurve.hxx>
1796
1797//=======================================================================
1798// function: ProcessAloneStickVertices
1799// purpose:
1800//=======================================================================
1801void ProcessAloneStickVertices(const Standard_Integer nF1,
1802 const Standard_Integer nF2,
1803 const BOPTools_PaveSet& aPSF,
1804 BOPTools_SequenceOfCurves& aSCvs,
1805 const BOPTools_InterferencePool& anIntrPool,
1806 BOPTools_PaveFiller& aPF,
1807 TColStd_SequenceOfInteger& aSeqVx,
1808 TColStd_SequenceOfReal& aSeqTolVx)
1809{
1810 Standard_Boolean bFound;
1811 Standard_Integer aNbVtx, jx, nV;
1812 Standard_Real aTolVRange;
1813 TColStd_IndexedMapOfInteger aMapUnUsed;
1814 GeomAbs_SurfaceType aType1, aType2;
1815 //
1816 BooleanOperations_PShapesDataStructure pDS=anIntrPool.DS();
1817 //
1818 const TopoDS_Face& aF1= TopoDS::Face(pDS->Shape(nF1));
1819 const TopoDS_Face& aF2= TopoDS::Face(pDS->Shape(nF2));
1820 Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1);
1821 Handle(Geom_Surface) aS2=BRep_Tool::Surface(aF2);
1822 GeomAdaptor_Surface aGAS1(aS1);
1823 GeomAdaptor_Surface aGAS2(aS2);
1824
1825 aType1=aGAS1.GetType();
1826 aType2=aGAS2.GetType();
1827
1828 if((aType1==GeomAbs_Cylinder && aType2==GeomAbs_Cylinder)
1829 ||
1830 (aType1==GeomAbs_Plane && aType2==GeomAbs_Plane)) {
1831 //
1832 UnUsedMap(aSCvs, aPSF, aMapUnUsed);
1833 //
1834 aNbVtx=aMapUnUsed.Extent();
1835 for (jx=1; jx<=aNbVtx; ++jx) {
1836 nV=aMapUnUsed(jx);
1837 if (pDS->IsNewShape(nV)) {
1838 bFound=VertexRangeTolerance(nV, nF1, nF2, anIntrPool, aTolVRange);
1839 if (bFound) {
1840 aSeqVx.Append(nV);
1841 aSeqTolVx.Append(aTolVRange);
1842 }
1843 }
1844 }
1845 }
1846 //
1847 //wkar pkv/904/F7
1848 if((aType1==GeomAbs_Torus && aType2==GeomAbs_Plane) ||
1849 (aType1==GeomAbs_Plane && aType2==GeomAbs_Torus)) {
1850 Standard_Integer aNbSCvs, aNbPoints;
1851 Standard_Real aDist, aTolV;
1852 gp_Pnt aPV;
1853 //
1854 UnUsedMap(aSCvs, aPSF, aMapUnUsed);
1855 aNbVtx=aMapUnUsed.Extent();
1856 if (aNbVtx) {
1857 IntTools_Context& aCtx=aPF.ChangeContext();
1858 //
1859 aNbSCvs=aSCvs.Length();
1860 if (aNbSCvs==1) {
1861 BOPTools_Curve& aBC=aSCvs(1);
1862 const IntTools_Curve& aC=aBC.Curve();
1863 Handle (Geom_Curve) aC3D= aC.Curve();
1864 GeomAPI_ProjectPointOnCurve& aProjPT=aCtx.ProjPT(aC3D);
1865 //
1866 for (jx=1; jx<=aNbVtx; ++jx) {
1867 nV=aMapUnUsed(jx);
1868 if (pDS->IsNewShape(nV)) {
1869 const TopoDS_Vertex& aV=*((TopoDS_Vertex*)&pDS->Shape(nV));
1870 aTolV=BRep_Tool::Tolerance(aV);
1871 aPV=BRep_Tool::Pnt(aV);
1872 //
1873 aProjPT.Perform(aPV);
1874 aNbPoints=aProjPT.NbPoints();
1875 if (aNbPoints) {
1876 aDist=aProjPT.LowerDistance();
1877 aDist=(aDist>aTolV)? aDist : aTolV;
1878 aSeqVx.Append(nV);
1879 aSeqTolVx.Append(aDist);
1880 }
1881 }
1882 }
1883 }
1884 }
1885 }
1886}
1887//=======================================================================
1888// function: UnUsedMap
1889// purpose:
1890//=======================================================================
1891void UnUsedMap(BOPTools_SequenceOfCurves& aSCvs,
1892 const BOPTools_PaveSet& aPSF,
1893 TColStd_IndexedMapOfInteger& aMapUnUsed)
1894{
1895 //
1896 // What stick/non-stick vertices we used
1897 TColStd_IndexedMapOfInteger aMapUsed, aMapMustBeUsed;
1898 Standard_Integer j, aNbCurves, aNbVtx, nV1;//, nV2;
1899 BOPTools_ListIteratorOfListOfPave anLPIt;
1900
1901 aNbCurves=aSCvs.Length();
1902 for (j=1; j<=aNbCurves; ++j) {
1903 BOPTools_Curve& aBC=aSCvs(j);
1904 //const IntTools_Curve& aC= aBC.Curve();// Wng in Gcc 3.0
1905
1906 const BOPTools_PaveSet& aPaveSet=aBC.Set();
1907 const BOPTools_ListOfPave& aLPAlreadyUsed=aPaveSet.Set();
1908 anLPIt.Initialize(aLPAlreadyUsed);
1909 for (; anLPIt.More(); anLPIt.Next()) {
1910 const BOPTools_Pave& aPave=anLPIt.Value();
1911 nV1=aPave.Index();
1912 aMapUsed.Add(nV1);
1913 }
1914 }
1915 //
1916 // 2. Stick vertices that must be used
1917 const BOPTools_ListOfPave& aLPMustUsed=aPSF.Set();
1918 anLPIt.Initialize(aLPMustUsed);
1919 for (; anLPIt.More(); anLPIt.Next()) {
1920 const BOPTools_Pave& aPave=anLPIt.Value();
1921 nV1=aPave.Index();
1922 aMapMustBeUsed.Add(nV1);
1923 }
1924 //
1925 // 3.Unused Stick vertices .
1926 aNbVtx=aMapMustBeUsed.Extent();
1927 for (j=1; j<=aNbVtx; ++j) {
1928 nV1=aMapMustBeUsed(j);
1929 if (!aMapUsed.Contains(nV1)) {
1930 aMapUnUsed.Add(nV1);
1931 }
1932 }
1933 //
1934}
1935//=======================================================================
1936// function: VertexRangeTolerance
1937// purpose:
1938//=======================================================================
1939Standard_Boolean VertexRangeTolerance(const Standard_Integer nV,
1940 const Standard_Integer nF1,
1941 const Standard_Integer nF2,
1942 const BOPTools_InterferencePool& anIntrPool,
1943 Standard_Real& aTolV)
1944{
1945 Standard_Boolean bFound=Standard_False;
1946 Standard_Integer i, aNbEFs, iWhat, iWith, iNewShape ;
1947 TColStd_IndexedMapOfInteger aMEF;
1948 //
1949 BooleanOperations_PShapesDataStructure pDS=anIntrPool.DS();
1950 //
1951 const TopoDS_Vertex& aV=TopoDS::Vertex(pDS->Shape(nV));
1952 //
1953 FaceAndEdgeMap(nF1, anIntrPool, aMEF);
1954 FaceAndEdgeMap(nF2, anIntrPool, aMEF);
1955 //
1956 // EF Interferences
1957 const BOPTools_CArray1OfESInterference& aEFs=anIntrPool.ESInterfs();
1958
1959 aNbEFs=aEFs.Extent();
1960 for (i=1; i<=aNbEFs; ++i) {
1961 const BOPTools_ESInterference& aEF=aEFs(i);
1962 iNewShape=aEF.NewShape();
1963 if (iNewShape==nV) {
1964 aEF.Indices(iWhat, iWith);
1965 if (aMEF.Contains(iWhat) && aMEF.Contains(iWith)) {
1966 //...
1967 Standard_Real aTolVWas, aD1, aD2, aDMax;
1968 gp_Pnt aP3DV, aP3DV1, aP3DV2;
1969 //
1970 const IntTools_CommonPrt& aCommonPrt=aEF.CommonPrt();
1971 //const TopoDS_Edge& aE1= aCommonPrt.Edge1();// Wng in Gcc 3.0
1972
1973 aP3DV=BRep_Tool::Pnt(aV);
1974 aTolVWas=BRep_Tool::Tolerance(aV);
1975
1976 aCommonPrt.BoundingPoints(aP3DV1, aP3DV2);
1977 aD1=aP3DV.Distance(aP3DV1);
1978 aD2=aP3DV.Distance(aP3DV2);
1979
1980 aDMax=Max(aD1, aD2);
1981
1982 aTolV=aTolVWas;
1983 if (aDMax>aTolVWas) {
1984 aTolV=aDMax;
1985 }
1986 return !bFound;
1987 }
1988 }
1989 }
1990 //
1991 // EE Interferences
1992 /*
1993 const BOPTools_CArray1OfEEInterference& aEEs=anIntrPool.EEInterfs();
1994 aNbEEs=aEEs.Extent();
1995 for (i=1; i<=aNbEEs; ++i) {
1996 const BOPTools_EEInterference& aEE=aEEs(i);
1997 iNewShape=aEE.NewShape();
1998 if (iNewShape==nV) {
1999 aEE.Indices(iWhat, iWith);
2000 if (aMEF.Contains(iWhat) && aMEF.Contains(iWith)) {
2001 //...
2002 aTolV=0.;
2003 return !bFound;
2004 }
2005 }
2006 }
2007 */
2008 //
2009 return bFound;
2010}
2011
2012//=======================================================================
2013// function: FaceAndEdgeMap
2014// purpose:
2015//=======================================================================
2016void FaceAndEdgeMap(const Standard_Integer nF,
2017 const BOPTools_InterferencePool& anIntrPool,
2018 TColStd_IndexedMapOfInteger& aMEF)
2019{
2020 Standard_Integer nEF;
2021 aMEF.Add(nF);
2022 BooleanOperations_PShapesDataStructure myDS=anIntrPool.DS();
2023 BooleanOperations_OnceExplorer aExp(*myDS);
2024 aExp.Init(nF, TopAbs_EDGE);
2025 for (; aExp.More(); aExp.Next()) {
2026 nEF=aExp.Current();
2027 aMEF.Add(nEF);
2028 }
2029}
2030//wkar OCC334 t
2031
2032//=======================================================================
2033// function: IsPairFound
2034// purpose:
2035//=======================================================================
2036Standard_Boolean IsPairFound(const Standard_Integer nF1,
2037 const Standard_Integer nF2,
2038 BOPTools_InterferencePool* myIntrPool,
2039 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWhat,
2040 BOPTColStd_IndexedDataMapOfIntegerIndexedMapOfInteger& aMapWith)
2041{
2042 Standard_Boolean bIsFound;
2043 //
2044 if (!aMapWhat.Contains(nF1)) {
2045 TColStd_IndexedMapOfInteger aMWhat;
2046 FMapWhat(nF1, myIntrPool, aMWhat);
2047 aMapWhat.Add(nF1, aMWhat);
2048 }
2049 //
2050 if (!aMapWith.Contains(nF2)) {
2051 TColStd_IndexedMapOfInteger aMWith;
2052 FMapWith(nF2, myIntrPool, aMWith);
2053 aMapWith.Add(nF2, aMWith);
2054 }
2055 //
2056 const TColStd_IndexedMapOfInteger& aMWht=aMapWhat.FindFromKey(nF1);
2057 const TColStd_IndexedMapOfInteger& aMWit=aMapWith.FindFromKey(nF2);
2058 //
2059 bIsFound=IsFound(aMWht, aMWit);
2060 //
2061 return bIsFound;
2062}
2063
2064//=======================================================================
2065// function: RestrictCurveIn2d
2066// purpose: Intersects 2d curve of edge nE and 2d curve of theBC.
2067// Splits theBC by new vertex, also splits nE by new vertex.
2068// If nE has same domain with another edge, the same domain
2069// edge is splitted too.
2070//=======================================================================
2071 void BOPTools_PaveFiller::RestrictCurveIn2d(const Standard_Integer nE,
2072 const Standard_Integer nF1,
2073 const Standard_Integer nF2,
2074 const Standard_Real theTolerance,
2075 BOPTools_Curve& theBC)
2076{
2077 myPavePoolNew.Resize (myNbEdges);
2078 TopoDS_Shape atmpShape;
2079
2080 BOPTools_CArray1OfESInterference& aESs = myIntrPool->ESInterferences();
2081
2082 BOPTools_PaveSet& aPS = myPavePool(myDS->RefEdge(nE));
2083 Standard_Boolean bSearchInter = Standard_True;
2084
2085 // 6841
2086 Standard_Integer pvVrtIndex = 0;
2087 //
2088
2089 BOPTools_ListIteratorOfListOfPave anIt1(aPS.Set());
2090 BOPTools_ListIteratorOfListOfPave anIt2;
2091
2092 for(; bSearchInter && anIt1.More(); anIt1.Next()) {
2093
2094 for(anIt2.Initialize(theBC.Set().Set()); anIt2.More(); anIt2.Next()) {
2095
2096 if(anIt1.Value().Index() == anIt2.Value().Index()) { // too hard condition for the algorithm
2097 // 6841
2098 pvVrtIndex = anIt1.Value().Index();
2099 //
2100 bSearchInter = Standard_False;
2101 break;
2102 }
2103 }
2104 }
2105 // -- 6841: test 2d intersection any way, but update vertex only
2106 if((!bSearchInter && pvVrtIndex != 0)) {
2107 Standard_Boolean OnFirst = (myDS->Rank(nE) == 1);
2108 TopoDS_Edge aE = TopoDS::Edge(myDS->Shape(nE));
2109 TopoDS_Face aF = (OnFirst) ? TopoDS::Face(myDS->Shape(nF1)) : TopoDS::Face(myDS->Shape(nF2));
2110 Standard_Real pf2 = 0., pl2 = 0.;
2111 Handle(Geom_Curve) aC2D3 = BRep_Tool::Curve(aE, pf2, pl2);
2112 Handle(Geom2d_Curve) aC2D2 = BRep_Tool::CurveOnSurface(aE, aF, pf2, pl2);
2113 Handle(Geom2d_Curve) aC1D2 = (OnFirst) ? theBC.Curve().FirstCurve2d() : theBC.Curve().SecondCurve2d();
2114 Handle(Geom_Curve) aC1D3 = theBC.Curve().Curve();
2115 if((!aC2D3.IsNull() && !aC2D2.IsNull()) && (!aC1D2.IsNull() && !aC1D3.IsNull())) {
2116 Standard_Real pf1 = aC1D2->FirstParameter();
2117 Standard_Real pl1 = aC1D2->LastParameter();
2118 Geom2dAPI_InterCurveCurve aInt(aC1D2, aC2D2, Precision::PConfusion());
2119 if(aInt.NbPoints() > 0) {
2120 Standard_Integer jj = 1;
2121 for(; jj <= aInt.NbPoints(); jj++) {
2122 Standard_Real t1 = aInt.Intersector().Point(jj).ParamOnFirst();
2123 Standard_Real t2 = aInt.Intersector().Point(jj).ParamOnSecond();
2124 if((t1 >= pf1) && (t1 <= pl1) && (t2 >= pf2) && (t2 <= pl2)) {
2125// gp_Pnt2d aP2d = aInt.Point(jj);
2126 gp_Pnt aP3d = aC2D3->Value(t2);
2127 gp_Pnt aP3d2 = aC1D3->Value(t1);
2128 TopoDS_Vertex & aVrt = (TopoDS_Vertex &) myDS->Shape(pvVrtIndex);
2129 gp_Pnt aVP = BRep_Tool::Pnt(aVrt);
2130 Standard_Real aVTol = BRep_Tool::Tolerance(aVrt);
2131 Standard_Real aD1 = aP3d.Distance(aVP);
2132 Standard_Real aD2 = aP3d2.Distance(aVP);
2133 Standard_Real aFD1 = fabs(aVTol-aD1);
2134 Standard_Real aFD2 = fabs(aVTol-aD2);
2135 if(aD1 > aVTol || aD2 > aVTol) {
2136 if(Max(aFD1,aFD2) <= 1.e-2) {
2137 Standard_Real nTol = aVTol + 2. * Max(aFD1,aFD2) + 1.e-7;
2138 BRep_Builder bb;
2139 bb.UpdateVertex(aVrt, nTol);
2140 }
2141 }
2142 }
2143 }
2144 }
2145 }
2146 }
2147 //-- 6841
2148
2149 if(bSearchInter) {
2150 // search intersection in 2d. begin
2151 BOPTools_ListOfPave aPavesOnCurve, aPavesOnEdge;
2152 Standard_Boolean bIsOnFirst = (myDS->Rank(nE) == 1);
2153
2154 Handle(Geom2d_Curve) aC1 = (bIsOnFirst) ? theBC.Curve().FirstCurve2d() : theBC.Curve().SecondCurve2d();
2155
2156 if(aC1.IsNull())
2157 return;
2158 Standard_Real f1 = aC1->FirstParameter();
2159 Standard_Real l1 = aC1->LastParameter();
2160
2161 // f1 and l1 may not correspond
2162 // to boundary parameters of 3d curve
2163 if(theBC.Curve().HasBounds()) {
2164 gp_Pnt tmpp1, tmpp2;
2165 theBC.Curve().Bounds(f1, l1, tmpp1, tmpp2);
2166 }
2167
2168 atmpShape = myDS->Shape(nE);
2169 TopoDS_Edge anEdge = TopoDS::Edge(atmpShape);
2170 TopoDS_Shape aFace = (bIsOnFirst) ? myDS->Shape(nF1) : myDS->Shape(nF2);
2171 Standard_Real f2=0., l2=0.;
2172 Handle(Geom2d_Curve) aC2 = BRep_Tool::CurveOnSurface(anEdge, TopoDS::Face(aFace), f2, l2);
2173 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, f2, l2);
2174
2175 if(aC2.IsNull() || aCurve.IsNull())
2176 return;
2177
2178 Geom2dAPI_InterCurveCurve anIntersector(aC1, aC2, Precision::PConfusion());
2179
2180 if(anIntersector.NbPoints() > 0) {
2181 Standard_Integer j = 0;
2182
2183 for(j = 1; j <= anIntersector.NbPoints(); j++) {
2184 Standard_Real t1 = anIntersector.Intersector().Point(j).ParamOnFirst();
2185 Standard_Real t2 = anIntersector.Intersector().Point(j).ParamOnSecond();
2186
2187 if((t1 >= f1) && (t1 <= l1) &&
2188 (t2 >= f2) && (t2 <= l2)) {
2189 gp_Pnt2d aP2dOnFace = anIntersector.Point(j);
2190 atmpShape = (!bIsOnFirst) ? myDS->Shape(nF1) : myDS->Shape(nF2);
2191 TopoDS_Face anOtherFace = TopoDS::Face(atmpShape);
2192 gp_Pnt aP3d = aCurve->Value(t2);
2193
2194 if(myContext.IsPointInOnFace(TopoDS::Face(aFace), aP2dOnFace) &&
2195 myContext.IsValidPointForFace(aP3d, anOtherFace, BRep_Tool::Tolerance(anEdge))) {
2196 BOPTools_Pave aPave1;
2197 aPave1.SetParam(t1);
2198 aPave1.SetIndex(-1);
2199 aPavesOnCurve.Append(aPave1);
2200 BOPTools_Pave aPave2;
2201 aPave2.SetParam(t2);
2202 aPave2.SetIndex(-1);
2203 aPavesOnEdge.Append(aPave2);
2204 }
2205 }
2206 }
2207 } // (anIntersector.NbPoints())
2208 // search intersection in 2d. end
2209
2210
2211 BOPTools_ListIteratorOfListOfPave aPaveIt1(aPavesOnCurve);
2212 BOPTools_ListIteratorOfListOfPave aPaveIt2(aPavesOnEdge);
2213
2214 // test common blocks. begin
2215 Standard_Boolean bFaceCBFound = Standard_False;
2216 Standard_Boolean bEdgeCBFound = Standard_False;
2217 const BOPTools_ListOfCommonBlock& aLCBTest = myCommonBlockPool(myDS->RefEdge(nE));
2218 BOPTools_ListIteratorOfListOfCommonBlock aCBListIt(aLCBTest);
2219 Standard_Boolean bHasCBOnFace = Standard_False;
2220 Standard_Boolean bHasCBOnEdge = Standard_False;
2221
2222 for(; aCBListIt.More(); aCBListIt.Next()) {
2223 if((aCBListIt.Value().Face() == nF1) ||
2224 (aCBListIt.Value().Face() == nF2)) {
2225 bHasCBOnFace = Standard_True;
2226 }
2227
2228 if(aCBListIt.Value().Face() == 0) {
2229 bHasCBOnEdge = Standard_True;
2230 }
2231 }
2232
2233 if(!bHasCBOnFace || !bHasCBOnEdge) {
2234 BOPTools_PaveSet aTestPaveSet;
2235 aTestPaveSet.ChangeSet() = aPS.Set();
2236
2237 for(; aPaveIt2.More(); aPaveIt2.Next()) {
2238 aTestPaveSet.Append(aPaveIt2.Value());
2239 }
2240 BOPTools_PaveBlockIterator aPBIter(0, aTestPaveSet);
2241
2242 for (; aPBIter.More(); aPBIter.Next()) {
2243 const BOPTools_PaveBlock& aPB = aPBIter.Value();
2244 Standard_Real aT1=aPB.Pave1().Param();
2245 Standard_Real aT2=aPB.Pave2().Param();
2246 gp_Pnt aPMid = aCurve->Value((aT1 + aT2) * 0.5);
2247 Standard_Integer nFOpposite = (bIsOnFirst) ? nF2 : nF1;
2248 TopoDS_Shape aOppFace = myDS->Shape(nFOpposite);
2249
2250 if(!bHasCBOnFace && !bFaceCBFound &&
2251 myContext.IsValidPointForFace(aPMid, TopoDS::Face(aOppFace),
2252 BRep_Tool::Tolerance(anEdge) +
2253 BRep_Tool::Tolerance(TopoDS::Face(aOppFace)))) {
2254 bFaceCBFound = Standard_True;
2255 }
2256
2257 if(!bHasCBOnEdge && !bEdgeCBFound) {
2258 TopoDS_Vertex aVMid;
2259 BRep_Builder aBB;
2260 aBB.MakeVertex(aVMid, aPMid, BRep_Tool::Tolerance(anEdge));
2261 TopExp_Explorer anExpE(aOppFace, TopAbs_EDGE);
2262
2263 for(; anExpE.More(); anExpE.Next()) {
2264 TopoDS_Shape aTmpEdge = anExpE.Current();
2265 Standard_Real aParameter = 0.;
2266
2267 if(myContext.ComputeVE(aVMid, TopoDS::Edge(aTmpEdge), aParameter) == 0) {
2268 bEdgeCBFound = Standard_True;
2269 break;
2270 }
2271 }
2272 }
2273 }
2274 aPaveIt2.Initialize(aPavesOnEdge);
2275 }
2276 // test common blocks. end
2277
2278 Standard_Boolean bChecknAddPaves = Standard_True;
2279
2280 if(bEdgeCBFound) {
2281 bChecknAddPaves = Standard_False;
2282 }
2283 else {
2284 if(!bHasCBOnEdge) {
2285 bChecknAddPaves = !bFaceCBFound;
2286 }
2287 }
2288
2289 if(bChecknAddPaves) {
2290 // add paves chaking if new pave is equal to existent. begin
2291 for(; aPaveIt1.More() && aPaveIt2.More(); aPaveIt1.Next(), aPaveIt2.Next()) {
2292 BOPTools_Pave& aPaveOnCurve = aPaveIt1.Value();
2293 BOPTools_Pave& aPaveOnEdge = aPaveIt2.Value();
2294
2295 gp_Pnt aP1 = theBC.Curve().Curve()->Value(aPaveOnCurve.Param());
2296 gp_Pnt aP2 = aCurve->Value(aPaveOnEdge.Param());
2297
2298 Standard_Boolean bAddNewVertex = Standard_True;
2299 Standard_Boolean bAddOldVertex = Standard_False;
2300 Standard_Integer oldvertexindex = 0;
2301
2302 for(anIt2.Initialize(theBC.Set().Set()); anIt2.More(); anIt2.Next()) {
2303 atmpShape = myDS->Shape(anIt2.Value().Index());
2304 TopoDS_Vertex aVertex = TopoDS::Vertex(atmpShape);
2305 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
2306 Standard_Real aTolerance = theTolerance + BRep_Tool::Tolerance(aVertex);
2307 if((aPoint.Distance(aP1) < aTolerance) ||
2308 (aPoint.Distance(aP2) < aTolerance)) {
2309 bAddNewVertex = Standard_False;
2310 bAddOldVertex = Standard_True;
2311 oldvertexindex = anIt2.Value().Index();
2312 break;
2313 }
2314 }
2315
2316 // treat equality with other vertices.begin
2317 if(bAddNewVertex || bAddOldVertex) {
2318 TopoDS_Vertex aNewVertex;
2319 BOPTools_Tools::MakeNewVertex(anEdge, aPaveOnEdge.Param(),
2320 TopoDS::Face(aFace), aNewVertex);
2321
2322 BOPTools_Pave aPaveToPut;
2323 Standard_Boolean bAddNewVertextmp = bAddNewVertex, bAddOldVertextmp = bAddOldVertex;
2324
2325 if(!CheckNewVertexAndUpdateData(aNewVertex, aPaveOnEdge.Param(), anEdge, aPaveOnCurve.Param(),
2326 nF1, nF2, theTolerance, myIntrPool, myDS, &myContext, aPS,
2327 bAddNewVertextmp, bAddOldVertextmp, theBC, aPaveToPut,
2328 bAddNewVertex, bAddOldVertex)) {
2329 bAddNewVertex = Standard_False;
2330 bAddOldVertex = Standard_False;
2331 }
2332 else {
2333 if((aPaveToPut.Index() != 0) && (aPaveToPut.Param() != 0.) &&
2334 aPaveToPut.Interference() != 0) {
2335 PutPaveOnCurve(aPaveToPut, theTolerance, theBC);
2336 }
2337 }
2338 // end for(anIt1.Initialize...
2339 }
2340 // treat equality with other vertices.end
2341
2342 if(bAddNewVertex || (bAddOldVertex && oldvertexindex)) {
2343 TopoDS_Vertex aNewVertex;
2344
2345 Standard_Integer aNewShapeIndex = 0;
2346
2347 // reject creation new vertex if there is a created one at a too small distance
2348 BOPTools_Tools::MakeNewVertex(anEdge,aPaveOnEdge.Param(),TopoDS::Face(aFace),aNewVertex);
2349 Standard_Real nvTol = BRep_Tool::Tolerance(aNewVertex);
2350 Standard_Integer chShNb = myDS->NumberOfInsertedShapes(), chShInd = 0;
2351 Standard_Boolean completeSearching = Standard_False;
2352 for(chShInd = 1; chShInd <= chShNb; chShInd++) {
2353 if(myDS->GetShapeType(chShInd) != TopAbs_VERTEX)
2354 continue;
2355 TopoDS_Vertex chV = TopoDS::Vertex(myDS->Shape(chShInd));
2356 Standard_Real distVV = BRep_Tool::Pnt(chV).Distance(BRep_Tool::Pnt(aNewVertex));
2357 if(distVV <= 1.e-5) {
2358 for(anIt1.Initialize(aPS.Set()); anIt1.More(); anIt1.Next()) {
2359 if(anIt1.Value().Index() == chShInd) {
2360 Standard_Real dParam = fabs(aPaveOnEdge.Param()-anIt1.Value().Param());
2361 if(dParam <= 1.e-7) {
2362 bAddNewVertex = Standard_False;
2363 bAddOldVertex = Standard_True;
2364 oldvertexindex = anIt1.Value().Index();
2365 nvTol += BRep_Tool::Tolerance(chV) + distVV;
2366 completeSearching = Standard_True;
2367 break;
2368 }
2369 }
2370 }
2371 }
2372 if(completeSearching)
2373 break;
2374 }
2375 // -&&
2376
2377
2378 if(!bAddOldVertex) {
2379 BOPTools_Tools::MakeNewVertex(anEdge, aPaveOnEdge.Param(),
2380 TopoDS::Face(aFace), aNewVertex);
2381 BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
2382 myDS->InsertShapeAndAncestorsSuccessors(aNewVertex, anASSeq);
2383 aNewShapeIndex = myDS->NumberOfInsertedShapes();
2384 }
2385 else {
2386 aNewShapeIndex = oldvertexindex;
2387 aNewVertex = TopoDS::Vertex(myDS->Shape(aNewShapeIndex));
2388 BRep_Builder aBB;
2389 //
2390 aBB.UpdateVertex(aNewVertex, aPaveOnEdge.Param(), anEdge, nvTol);
2391 }
2392
2393 BOPTools_ListIteratorOfListOfPave anItAll;
2394 Standard_Boolean samePFound = Standard_False;
2395 for(anItAll.Initialize(aPS.Set()); anItAll.More(); anItAll.Next()) {
2396 if(anItAll.Value().Index() == aNewShapeIndex) {
2397 BOPTools_Pave& aPV = anItAll.Value();
2398 aPV.SetParam(aPaveOnEdge.Param());
2399 samePFound = Standard_True;
2400 break;
2401 }
2402 }
2403 if(samePFound)
2404 continue;
2405
2406
2407 myDS->SetState (aNewShapeIndex, BooleanOperations_ON);
2408
2409 IntTools_CommonPrt aCPart;
2410 aCPart.SetEdge1(anEdge);
2411 aCPart.SetType(TopAbs_VERTEX);
2412 aCPart.SetRange1(IntTools_Range(aPaveOnEdge.Param(), aPaveOnEdge.Param()));
2413 aCPart.SetVertexParameter1(aPaveOnEdge.Param());
2414
2415 Standard_Integer nFOpposite = (bIsOnFirst) ? nF2 : nF1;
2416 BOPTools_ESInterference anInterf (nE, nFOpposite, aCPart);
2417 Standard_Integer anIndexIn = aESs.Append(anInterf);
2418 myIntrPool->AddInterference (nE, nFOpposite, BooleanOperations_EdgeSurface, anIndexIn);
2419
2420 BOPTools_ESInterference& aESInterf = aESs(anIndexIn);
2421 aESInterf.SetNewShape(aNewShapeIndex);
2422
2423 // put pave on edge. begin
2424 aPaveOnEdge.SetInterference(anIndexIn);
2425 aPaveOnEdge.SetType (BooleanOperations_EdgeSurface);
2426 aPaveOnEdge.SetIndex(aNewShapeIndex);
2427
2428 BOPTools_PaveSet& aPaveSet1 = myPavePoolNew(myDS->RefEdge(nE));
2429 aPaveSet1.Append(aPaveOnEdge);
2430 // put pave on edge. end
2431
2432 // put pave on curve. begin
2433 aPaveOnCurve.SetIndex(aNewShapeIndex);
2434 aPaveOnCurve.SetType(BooleanOperations_SurfaceSurface);
2435 BOPTools_PaveSet& aPaveSet = theBC.Set();
2436 aPaveSet.Append(aPaveOnCurve);
2437
2438 BOPTools_Tools::UpdateVertex (theBC.Curve(), aPaveOnCurve.Param(), aNewVertex);
2439
2440 // put pave on curve. end
2441
2442 BOPTools_ListOfCommonBlock& aLCB1 = myCommonBlockPool(myDS->RefEdge(nE));
2443
2444 BOPTools_ListIteratorOfListOfCommonBlock anIt(aLCB1);
2445
2446 for(; anIt.More(); anIt.Next()) {
2447 BOPTools_CommonBlock& aCB = anIt.Value();
2448
2449 if(aCB.Face()) {
2450 continue;
2451 }
2452
2453 Standard_Integer anOppIndex = aCB.PaveBlock2().OriginalEdge();
2454 IntTools_Range aRange = aCB.PaveBlock2().Range();
2455
2456 if(anOppIndex == nE) {
2457 anOppIndex = aCB.PaveBlock1().OriginalEdge();
2458 aRange = aCB.PaveBlock1().Range();
2459 }
2460 TopoDS_Edge anOppEdge = TopoDS::Edge(myDS->Shape(anOppIndex));
2461 Standard_Real aOppParameter = 0.;
2462
2463 if(myContext.ComputeVE(aNewVertex, anOppEdge, aOppParameter) == 0) {
2464
2465 if((aOppParameter > aRange.First()) && (aOppParameter < aRange.Last())) {
2466 // put pave on same domain edge. begin
2467 BRep_Builder aBB;
2468 aBB.UpdateVertex(aNewVertex, aOppParameter, anOppEdge, BRep_Tool::Tolerance(aNewVertex));
2469 BOPTools_Pave aPaveOpp;
2470 aPaveOpp.SetParam(aOppParameter);
2471 aPaveOpp.SetIndex(aNewShapeIndex);
2472 BOPTools_PaveSet& aPaveSetOpp = myPavePoolNew(myDS->RefEdge(anOppIndex));
2473 aPaveSetOpp.Append(aPaveOpp);
2474 // put pave on same domain edge. end
2475 }
2476 }
2477 }
2478
2479 // add SS interference for adjacent face.begin
2480 if(aLCB1.IsEmpty()) {
2481 AddInterfForAdjacentFace(nE, nF1, nF2, myIntrPool, myDS);
2482 }
2483 // add SS interference for adjacent face.end
2484
2485 RefinePavePool();
2486 myPavePoolNew.Resize(myNbEdges);
2487 //
2488
2489 RecomputeCommonBlocks(nE);
2490
2491 }
2492 } // end for(; aPaveIt1.More() && aPaveIt2.More()...
2493 // add paves chaking if new pave is equal to existent. end
2494 }
2495 } //(bSearchInter)
2496 myPavePoolNew.Destroy();
2497}
2498//=======================================================================
2499//function : RecomputeCommonBlocks
2500//purpose :
2501//=======================================================================
2502 void BOPTools_PaveFiller::RecomputeCommonBlocks(const Standard_Integer nE)
2503{
2504 TopoDS_Shape atmpShape = myDS->Shape(nE);
2505 TopoDS_Edge anEdge = TopoDS::Edge(atmpShape);
2506 BOPTools_ListOfCommonBlock& aLCB1 = myCommonBlockPool(myDS->RefEdge(nE));
2507
2508 BOPTools_ListOfCommonBlock anOldLCB;
2509 anOldLCB = aLCB1;
2510 aLCB1.Clear();
2511 BOPTools_ListOfCommonBlock aNewLCB1;
2512 Standard_Boolean bReverse = Standard_False;
2513 BOPTools_ListIteratorOfListOfCommonBlock anIt(anOldLCB);
2514
2515 for(; anIt.More(); anIt.Next()) {
2516 BOPTools_CommonBlock& anOldCB = anIt.Value();
2517
2518 Standard_Integer anIndex = anOldCB.PaveBlock1().OriginalEdge();
2519 Standard_Integer anIndexOpp = anOldCB.PaveBlock2().OriginalEdge();
2520 IntTools_Range aCBRange = anOldCB.PaveBlock1().Range();
2521
2522 if(anIndex != nE) {
2523 aCBRange = anOldCB.PaveBlock2().Range();
2524 anIndex = anOldCB.PaveBlock2().OriginalEdge();
2525 anIndexOpp = anOldCB.PaveBlock1().OriginalEdge();
2526 bReverse = Standard_True;
2527 }
2528
2529 BOPTools_ListOfPaveBlock& aSplitEdges1 = mySplitShapesPool(myDS->RefEdge(nE));
2530 BOPTools_ListIteratorOfListOfPaveBlock aLPBIt1(aSplitEdges1);
2531 Standard_Boolean found = Standard_False;
2532 BOPTools_ListOfCommonBlock aNewListOfCommonBlock;
2533
2534 for(; aLPBIt1.More(); aLPBIt1.Next()) {
2535 BOPTools_PaveBlock& aPBCurrent1 = aLPBIt1.Value();
2536 IntTools_Range aCurRange1 = aPBCurrent1.Range();
2537
2538 if((aCurRange1.First() > aCBRange.First() && aCurRange1.First() < aCBRange.Last()) ||
2539 (aCurRange1.Last() > aCBRange.First() && aCurRange1.Last() < aCBRange.Last())) {
2540 BOPTools_CommonBlock aNewCB;
2541
2542 if(!bReverse)
2543 aNewCB.SetPaveBlock1(aPBCurrent1);
2544 else
2545 aNewCB.SetPaveBlock2(aPBCurrent1);
2546
2547 Standard_Boolean foundpaveblock2 = Standard_False;
2548
2549 if(anOldCB.Face()) {
2550 foundpaveblock2 = Standard_True;
2551 aNewCB.SetFace(anOldCB.Face());
2552 }
2553 else {
2554 if(anIndexOpp <= 0)
2555 continue;
2556 BOPTools_ListIteratorOfListOfPaveBlock aLPBIt2(mySplitShapesPool(myDS->RefEdge(anIndexOpp)));
2557
2558 for(; aLPBIt2.More(); aLPBIt2.Next()) {
2559 BOPTools_PaveBlock& aPBCurrent2 = aLPBIt2.Value();
2560 IntTools_Range aCurRange2 = aPBCurrent2.Range();
2561
2562 if(((aPBCurrent1.Pave1().Index() == aPBCurrent2.Pave1().Index()) &&
2563 (aPBCurrent1.Pave2().Index() == aPBCurrent2.Pave2().Index())) ||
2564 ((aPBCurrent1.Pave1().Index() == aPBCurrent2.Pave2().Index()) &&
2565 (aPBCurrent1.Pave2().Index() == aPBCurrent2.Pave1().Index()))) {
2566 Standard_Real f = 0., l = 0.;
2567 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(anEdge, f, l);
2568 Standard_Real aMidPar = (aCurRange1.First() + aCurRange1.Last()) * 0.5;
2569 gp_Pnt aMidPnt = aCurve->Value(aMidPar);
2570 Standard_Real aProjPar = 0.;
2571 TopoDS_Vertex aTestpVertex;
2572 TopoDS_Edge aOppEdge = TopoDS::Edge(myDS->Shape(anIndexOpp));
2573 BRep_Builder aBB;
2574 aBB.MakeVertex(aTestpVertex, aMidPnt, BRep_Tool::Tolerance(anEdge));
2575
2576 if(myContext.ComputeVE(aTestpVertex, aOppEdge, aProjPar) == 0) {
2577 if(aProjPar > aCurRange2.First() && aProjPar < aCurRange2.Last()) {
2578 if(!bReverse)
2579 aNewCB.SetPaveBlock2(aPBCurrent2);
2580 else
2581 aNewCB.SetPaveBlock1(aPBCurrent2);
2582 foundpaveblock2 = Standard_True;
2583 break;
2584 }
2585 }
2586 }
2587 }
2588 }
2589
2590 if(foundpaveblock2) {
2591 found = Standard_True;
2592 aNewListOfCommonBlock.Append(aNewCB);
2593 }
2594 }
2595 }
2596 // end for(; aLPBIt1.More()...
2597
2598 if(!found) {
2599 aNewLCB1.Append(anOldCB);
2600 }
2601 else {
2602 BOPTools_ListOfCommonBlock tmplst;
2603 tmplst = aNewListOfCommonBlock;
2604 aNewLCB1.Append(tmplst);
2605
2606 if((anOldCB.Face() == 0) && (anIndexOpp > 0)) {
2607 tmplst = aNewListOfCommonBlock;
2608 BOPTools_ListOfCommonBlock& aLCB2 = myCommonBlockPool(myDS->RefEdge(anIndexOpp));
2609
2610 BOPTools_ListIteratorOfListOfCommonBlock anItLCB2(aLCB2);
2611
2612 for(; anItLCB2.More(); anItLCB2.Next()) {
2613 BOPTools_CommonBlock& anOldCB2 = anItLCB2.Value();
2614
2615 if(anOldCB2.Face())
2616 continue;
2617
2618 if(anOldCB.PaveBlock1().IsEqual(anOldCB2.PaveBlock1()) &&
2619 anOldCB.PaveBlock2().IsEqual(anOldCB2.PaveBlock2())) {
2620 aLCB2.Remove(anItLCB2);
2621 aLCB2.Append(tmplst);
2622 break;
2623 }
2624 }
2625 }
2626 }
2627 }
2628 // end for(; anIt.More()...
2629 aLCB1 = aNewLCB1;
2630}
2631//=======================================================================
2632//function : CheckNewVertexAndUpdateData
2633//purpose :
2634//=======================================================================
2635Standard_Boolean CheckNewVertexAndUpdateData(const TopoDS_Vertex& theVertex,
2636 const Standard_Real theParamOnE,
2637 const TopoDS_Edge& theEdge,
2638 const Standard_Real theParamOnCurve,
2639 const Standard_Integer theIndexF1,
2640 const Standard_Integer theIndexF2,
2641 const Standard_Real theTolerance,
2642 const BOPTools_PInterferencePool& theIntrPool,
2643 const BooleanOperations_PShapesDataStructure& theDS,
2644 IntTools_Context* theContext,
2645 const BOPTools_PaveSet& theEdgePaveSet,
2646 const Standard_Boolean bAddNewVertex,
2647 const Standard_Boolean bAddOldVertex,
2648 BOPTools_Curve& theBC,
2649 BOPTools_Pave& thePaveToPut,
2650 Standard_Boolean& bAddNewVertexOut,
2651 Standard_Boolean& bAddOldVertexOut) {
2652
2653 thePaveToPut.SetParam(0.);
2654 thePaveToPut.SetIndex(0);
2655 thePaveToPut.SetInterference(0);
2656
2657 bAddNewVertexOut = bAddNewVertex;
2658 bAddOldVertexOut = bAddOldVertex;
2659 TopoDS_Shape atmpShape;
2660 gp_Pnt aP1 = theBC.Curve().Curve()->Value(theParamOnCurve);
2661 Standard_Real f = 0., l = 0.;
2662 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(theEdge, f, l);
2663
2664 if(aCurve.IsNull())
2665 return Standard_False;
2666 gp_Pnt aP2 = aCurve->Value(theParamOnE);
2667
2668 BOPTools_ListIteratorOfListOfPave anIt1, anIt2;
2669
2670 for(anIt1.Initialize(theEdgePaveSet.Set()); anIt1.More(); anIt1.Next()) {
2671 atmpShape = theDS->Shape(anIt1.Value().Index());
2672 TopoDS_Vertex aVertex = TopoDS::Vertex(atmpShape);
2673 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
2674 Standard_Real aTolerance = theTolerance + BRep_Tool::Tolerance(aVertex);
2675 aTolerance *= 4.;
2676
2677 if((aPoint.Distance(aP1) < aTolerance) ||
2678 (aPoint.Distance(aP2) < aTolerance)) {
2679 IntTools_Range aRange(anIt1.Value().Param(), theParamOnE);
2680 TopoDS_Vertex aV1 = aVertex;
2681 TopoDS_Vertex aV2 = theVertex;
2682
2683 if(anIt1.Value().Param() > theParamOnE) {
2684 aRange.SetFirst(theParamOnE);
2685 aRange.SetLast(anIt1.Value().Param());
2686 aV1 = theVertex;
2687 aV2 = aVertex;
2688 }
2689 gp_Pnt ptest1 = aCurve->Value(aRange.First());
2690 gp_Pnt ptest2 = aCurve->Value(aRange.Last());
2691 Standard_Boolean bUpdateVertex = Standard_True;
2692
2693 if(ptest1.Distance(ptest2) > (BRep_Tool::Tolerance(aVertex) + BRep_Tool::Tolerance(theEdge))) {
2694 IntTools_ShrunkRange aSR (theEdge, aV1, aV2, aRange, *theContext);
2695 bUpdateVertex = !aSR.IsDone() || (aSR.ErrorStatus() != 0);
2696 }
2697
2698 if(bUpdateVertex) {
2699 bAddNewVertexOut = Standard_False;
2700
2701 if(bAddOldVertexOut) {
2702 bAddOldVertexOut = Standard_False;
2703 break;
2704 }
2705 BOPTools_Tools::UpdateVertex (theBC.Curve(), theParamOnCurve, aVertex);
2706
2707 Standard_Boolean bPutPave = Standard_True;
2708
2709 for(anIt2.Initialize(theBC.Set().Set()); anIt2.More(); anIt2.Next()) {
2710 if(anIt1.Value().Index() == anIt2.Value().Index()) {
2711 bPutPave = Standard_False;
2712 break;
2713 }
2714 }
2715
2716 Standard_Integer nbbefore = theBC.Set().Set().Extent();
2717
2718 if(bPutPave) {
2719 thePaveToPut = anIt1.Value();
2720 }
2721
2722 if(anIt1.Value().Index() > theDS->NumberOfSourceShapes())
2723 break;
2724
2725 Standard_Integer nbafter = theBC.Set().Set().Extent();
2726
2727 if(nbbefore < nbafter) {
2728 // update interferences.begin
2729 Standard_Integer nF = theIndexF1;
2730
2731 if(theDS->Rank(anIt1.Value().Index()) != theDS->Rank(theIndexF1)) {
2732 nF = theIndexF2;
2733 }
2734 atmpShape = theDS->Shape(nF);
2735 TopoDS_Face aF = TopoDS::Face (atmpShape);
2736 BOPTools_CArray1OfVSInterference& aVSs = theIntrPool->VSInterferences();
2737 Standard_Integer vsit = 0;
2738 Standard_Boolean interffound = Standard_False;
2739
2740 for(vsit = 1; vsit <= aVSs.Length(); vsit++) {
2741 if((aVSs.Value(vsit).Index1() == anIt1.Value().Index()) &&
2742 (aVSs.Value(vsit).Index2() == nF)) {
2743 interffound = Standard_True;
2744 break;
2745 }
2746 }
2747
2748 if(!interffound) {
2749 BOPTools_CArray1OfVEInterference& aVEs = theIntrPool->VEInterferences();
2750
2751 for(vsit = 1; vsit <= aVEs.Length(); vsit++) {
2752 if((aVEs.Value(vsit).Index1() == anIt1.Value().Index())) {
2753 interffound = Standard_True;
2754 break;
2755 }
2756 }
2757 }
2758
2759 if(!interffound) {
2760 BOPTools_CArray1OfVVInterference& aVVs = theIntrPool->VVInterferences();
2761
2762 for(vsit = 1; vsit <= aVVs.Length(); vsit++) {
2763 if((aVVs.Value(vsit).Index1() == anIt1.Value().Index())) {
2764 interffound = Standard_True;
2765 break;
2766 }
2767 }
2768 }
2769
2770 if(!interffound) {
2771 Standard_Real aU = 0., aV = 0.;
2772 Standard_Integer aFlag = theContext->ComputeVS (aVertex, aF, aU, aV);
2773 Standard_Integer anIndexIn = 0;
2774
2775 if (!aFlag) {
2776 //
2777 // Add Interference to the Pool
2778 BOPTools_VSInterference anInterf (anIt1.Value().Index(), nF, aU, aV);
2779 anIndexIn=aVSs.Append(anInterf);
2780 //
2781 // SetState for Vertex in DS;
2782 theDS->SetState (anIt1.Value().Index(), BooleanOperations_ON);
2783 // Insert Vertex in Interference Object
2784 BOPTools_VSInterference& aVS = aVSs(anIndexIn);
2785 aVS.SetNewShape(anIt1.Value().Index());
2786
2787 interffound = Standard_False;
2788 const BOPTools_ListOfInterference& aList1 =
2789 theIntrPool->InterferenceTable().Value(anIt1.Value().Index()).GetOnType(BooleanOperations_EdgeSurface);
2790 BOPTools_ListOfInterference& amodifList1 = *((BOPTools_ListOfInterference*)&aList1); // not very good approach
2791 BOPTools_ListIteratorOfListOfInterference anInterfIt(amodifList1);
2792
2793 for(; anInterfIt.More(); anInterfIt.Next()) {
2794 if(anInterfIt.Value().With() == nF) {
2795 anInterfIt.Value().SetIndex(anIndexIn);
2796 interffound = Standard_True;
2797 }
2798 }
2799 const BOPTools_ListOfInterference& aList2 =
2800 theIntrPool->InterferenceTable().Value(nF).GetOnType(BooleanOperations_EdgeSurface);
2801 BOPTools_ListOfInterference& amodifList2 = *((BOPTools_ListOfInterference*)&aList2); // not very good approach
2802 anInterfIt.Initialize(amodifList2);
2803
2804 for(; anInterfIt.More(); anInterfIt.Next()) {
2805 if(anInterfIt.Value().With() == anIt1.Value().Index()) {
2806 anInterfIt.Value().SetIndex(anIndexIn);
2807 interffound = Standard_True;
2808 }
2809 }
2810
2811 if(!interffound)
2812 theIntrPool->AddInterference(anIt1.Value().Index(), nF, BooleanOperations_VertexSurface, anIndexIn);
2813 }
2814 }
2815 // update interferences.end
2816 }
2817 break;
2818 }
2819 }
2820 }
2821 // end for(anIt1.Initialize...
2822 return Standard_True;
2823}
2824//=======================================================================
2825//function : AddInterfForAdjacentFace
2826//purpose :
2827//=======================================================================
2828void AddInterfForAdjacentFace(const Standard_Integer theEdgeIndex,
2829 const Standard_Integer theIndexF1,
2830 const Standard_Integer theIndexF2,
2831 BOPTools_PInterferencePool theIntrPool,
2832 const BooleanOperations_PShapesDataStructure& theDS) {
2833 Standard_Boolean bIsOnFirst = (theDS->Rank(theEdgeIndex) == 1);
2834
2835 IntTools_SequenceOfPntOn2Faces aPnts;
2836 IntTools_SequenceOfCurves aCvs;
2837 Standard_Integer index1 = (bIsOnFirst) ? theIndexF1 : theIndexF2;
2838 Standard_Integer index2 = (bIsOnFirst) ? theIndexF2 : theIndexF1;
2839 Standard_Integer nbw = theDS->NumberOfAncestors(theEdgeIndex);
2840 Standard_Integer ancwit = 0, ancfit = 0;
2841 Standard_Boolean badjacentfound = Standard_False;
2842
2843 for(ancwit = 1; (!badjacentfound) && (ancwit <= nbw); ancwit++) {
2844 Standard_Integer ancestor1 = theDS->GetAncestor(theEdgeIndex, ancwit);
2845
2846 if(ancestor1 == index1)
2847 continue;
2848
2849 if(theDS->GetShapeType(ancestor1) == TopAbs_WIRE) {
2850 Standard_Integer nbf = theDS->NumberOfAncestors(ancestor1);
2851
2852 for(ancfit = 1; ancfit <= nbf; ancfit++) {
2853 Standard_Integer ancestor2 = theDS->GetAncestor(ancestor1, ancfit);
2854
2855 if(ancestor2 != index1) {
2856 index1 = ancestor2;
2857 badjacentfound = Standard_True;
2858 break;
2859 }
2860 }
2861 }
2862 }
2863
2864 if(index1 > index2) {
2865 Standard_Integer tmp = index1;
2866 index1 = index2;
2867 index2 = tmp;
2868 }
2869 Standard_Boolean bAddInterference = Standard_True;
2870 Standard_Integer ffit = 0;
2871 BOPTools_CArray1OfSSInterference& aFFs = theIntrPool->SSInterferences();
2872
2873 for(ffit = 1; ffit <= aFFs.Extent(); ffit++) {
2874 BOPTools_SSInterference& aFFi3 = aFFs(ffit);
2875
2876 if((index1 == aFFi3.Index1()) && (index2 == aFFi3.Index2())) {
2877 bAddInterference = Standard_False;
2878 }
2879 }
2880
2881 if(bAddInterference) {
2882 BOPTools_SSInterference anInterfSS (index1, index2, 1.e-07, 1.e-07, aCvs, aPnts);
2883 Standard_Integer anIndexInSS = aFFs.Append(anInterfSS);
2884 theIntrPool->AddInterference (index1, index2, BooleanOperations_SurfaceSurface, anIndexInSS);
2885 }
2886}
2887
2888//=======================================================================
2889//function : RejectPaveBlock
2890//purpose :
2891//=======================================================================
2892Standard_Boolean RejectPaveBlock(const IntTools_Curve& theC,
2893 const Standard_Real theT1,
2894 const Standard_Real theT2,
2895 const TopoDS_Vertex& theV,
2896 Standard_Real& theRT)
2897{
2898 theRT = BRep_Tool::Tolerance(theV);
2899 Handle(Geom_Curve) aC = theC.Curve();
2900
2901 Standard_Real pf = aC->FirstParameter();
2902 Standard_Real pl = aC->LastParameter();
2903 Standard_Real dp = fabs(pl-pf);
2904 Standard_Boolean isp = (aC->IsPeriodic() && fabs(aC->Period()-dp) <= 1.e-9);
2905 Standard_Real dt = fabs(theT2-theT1);
2906 isp = (isp || (aC->IsPeriodic() && fabs(aC->Period()-dt) <= 1.e-9));
2907 Standard_Boolean c3d = (aC->IsClosed() || isp);
2908
2909 if(c3d)
2910 return Standard_False;
2911
2912 Standard_Real p1 = Max(pf,theT1);
2913 Standard_Real p2 = Min(pl,theT2);
2914 if(p2 != p1) {
2915 if(p2 < p1) {
2916 Standard_Real tp = p1; p1 = p2; p2 = tp;
2917 }
2918 gp_Pnt pntf, pntl;
2919 aC->D0(p1,pntf);
2920 aC->D0(p2,pntl);
2921 Standard_Real d3d = pntf.Distance(pntl);
2922 if(d3d > theRT)
2923 theRT = d3d;
2924 }
2925 return Standard_True;
2926}
2927
2928//=======================================================================
2929//function : ModifFFTol
2930//purpose :
2931//=======================================================================
2932Standard_Boolean ModifFFTol(const TopoDS_Face& theF1,
2933 const TopoDS_Face& theF2,
2934 Standard_Real& theTF)
2935{
2936 Standard_Real t1 = BRep_Tool::Tolerance(theF1), t2 = BRep_Tool::Tolerance(theF2);
2937 theTF = 2* (t1 + t2);
2938 BRepAdaptor_Surface BAS1(theF1);
2939 BRepAdaptor_Surface BAS2(theF2);
2940
2941 Standard_Boolean isAna1 = (BAS1.GetType() == GeomAbs_Plane ||
2942 BAS1.GetType() == GeomAbs_Cylinder ||
2943 BAS1.GetType() == GeomAbs_Cone ||
2944 BAS1.GetType() == GeomAbs_Sphere);
2945 Standard_Boolean isAna2 = (BAS2.GetType() == GeomAbs_Plane ||
2946 BAS2.GetType() == GeomAbs_Cylinder ||
2947 BAS2.GetType() == GeomAbs_Cone ||
2948 BAS2.GetType() == GeomAbs_Sphere);
2949
2950 isAna1=isAna1||(BAS1.GetType() == GeomAbs_Torus);
2951 isAna2=isAna2||(BAS2.GetType() == GeomAbs_Torus);
2952
2953 if(isAna1 && isAna2)
2954 return Standard_False;
2955
2956 theTF = Max(theTF, 5.e-6);
2957 return Standard_True;
2958}
2959
2960
2961//=======================================================================
2962//function : RejectBuildingEdge
2963//purpose :
2964//=======================================================================
2965Standard_Integer RejectBuildingEdge(const IntTools_Curve& theC,
2966 const TopoDS_Vertex& theV1,
2967 const TopoDS_Vertex& theV2,
2968 const Standard_Real theT1,
2969 const Standard_Real theT2,
2970 const TopTools_ListOfShape& theL,
2971 Standard_Real& theTF)
2972{
2973 theTF = 1.e-7;
2974 if(theL.Extent() == 0)
2975 return 0;
2976
2977 Handle(Geom_Curve) aTCurve;
2978 Standard_Real aTT;
2979
2980 Standard_Integer eIndex = 0;
2981 Standard_Boolean edgeFound = Standard_False;
2982 Handle(Geom_Curve) aCurve = theC.Curve();
2983 TopTools_ListIteratorOfListOfShape anIt(theL);
2984 for(; anIt.More(); anIt.Next()) {
2985 eIndex++;
2986 const TopoDS_Edge & aE = TopoDS::Edge(anIt.Value());
2987 if(aE.IsNull()) continue;
2988 TopExp_Explorer ee(aE,TopAbs_VERTEX);
2989 Standard_Boolean v1Found = Standard_False;
2990 Standard_Boolean v2Found = Standard_False;
2991 Standard_Real v1P = 0., v2P = 0;
2992 for(; ee.More(); ee.Next()) {
2993 const TopoDS_Vertex aV = TopoDS::Vertex(ee.Current());
2994 if(aV.IsNull()) continue;
2995 if(aV.IsEqual(theV1)) {
2996 v1Found = Standard_True;
2997 v1P = BRep_Tool::Parameter(aV,aE);
2998 }
2999 if(aV.IsEqual(theV2)) {
3000 v2Found = Standard_True;
3001 v2P = BRep_Tool::Parameter(aV,aE);
3002 }
3003 }
3004 Standard_Boolean sameParam = Standard_False;
3005 if(v1Found && v2Found) {
3006 if(fabs(theT1-v1P) <= 1.e-8 && fabs(theT2-v2P) <= 1.e-8)
3007 sameParam = Standard_True;
3008 }
3009 if(sameParam) {
3010 Standard_Real f,l;
3011 aTCurve = BRep_Tool::Curve(aE,f,l);
3012 aTT = BRep_Tool::Tolerance(aE);
3013 edgeFound = Standard_True;
3014 }
3015 if(edgeFound)
3016 break;
3017 }
3018
3019 if(!edgeFound)
3020 return 0;
3021
3022 gp_Pnt p1 = aTCurve->Value(theT1);
3023 gp_Pnt p2 = aCurve->Value(theT1);
3024 Standard_Real dpf = p1.Distance(p2);
3025 p1 = aTCurve->Value(theT2);
3026 p2 = aCurve->Value(theT2);
3027 Standard_Real dpl = p1.Distance(p2);
3028 Standard_Real dplf = fabs(dpl-dpf);
3029 Standard_Real dpp = Max(dpl,dpf);
3030
3031 if(dplf > 1.e-7)
3032 return 0;
3033
3034 Standard_Real maxD = Max(dpl,dpf);
3035 Standard_Boolean inTol = Standard_True;
3036 Standard_Real dp = fabs(theT2-theT1)/23.;
3037 Standard_Integer di = 0;
3038 for(di = 1; di <= 21; di++) {
3039 Standard_Real cp = theT1 + dp*((Standard_Real)di);
3040 p1 = aTCurve->Value(cp);
3041 p2 = aCurve->Value(cp);
3042 Standard_Real d12 = p1.Distance(p2);
3043 maxD = Max(maxD,d12);
3044 if(fabs(d12-dpp) > 1.e-7) {
3045 inTol = Standard_False;
3046 break;
3047 }
3048 }
3049
3050 if(!inTol)
3051 return 0;
3052
3053 theTF = maxD;
3054 return eIndex;
3055}