summaryrefslogtreecommitdiff
path: root/src/BOPTools/BOPTools_DEProcessor.cxx
blob: 8ebba3d7624f2324eab4c4bfc918af2c76bc9324 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
// File:	BOPTools_DEProcessor.cxx
// Created:	Wed Sep 12 12:10:52 2001
// Author:	Peter KURNEV
//		<pkv@irinox>

#include <BOPTools_DEProcessor.ixx>


#include <TopoDS_Shape.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Vertex.hxx>
#include <TopoDS_Solid.hxx>

#include <TopExp.hxx>
#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>

#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <gp_Sphere.hxx>

#include <IntRes2d_IntersectionPoint.hxx>

#include <Precision.hxx>

#include <Geom2d_Curve.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2dInt_GInter.hxx>

#include <BRep_Tool.hxx>
#include <BRep_Builder.hxx>
#include <BRepClass3d_SolidClassifier.hxx>
#include <BRepAdaptor_Surface.hxx>

#include <BRepExtrema_DistShapeShape.hxx>

#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <TColStd_ListOfInteger.hxx>

#include <BooleanOperations_ShapesDataStructure.hxx>
#include <BooleanOperations_AncestorsSeqAndSuccessorsSeq.hxx>

#include <IntTools_Range.hxx>
#include <IntTools_Tools.hxx>
#include <IntTools_Context.hxx>

#include <BOPTools_DEInfo.hxx>
#include <BOPTools_ListOfPaveBlock.hxx>
#include <BOPTools_SSInterference.hxx>
#include <BOPTools_PaveBlock.hxx>
#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
#include <BOPTools_SequenceOfCurves.hxx>
#include <BOPTools_Curve.hxx>
#include <BOPTools_PavePool.hxx>
#include <BOPTools_Pave.hxx>
#include <BOPTools_PaveSet.hxx>
#include <BOPTools_Tools3D.hxx>
#include <BOPTools_PaveBlockIterator.hxx>
#include <BOPTools_ListOfPave.hxx>
#include <BOPTools_ListIteratorOfListOfPave.hxx>
#include <BOPTools_InterferencePool.hxx>
#include <BOPTools_CArray1OfSSInterference.hxx>
#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
#include <BOPTools_PaveFiller.hxx>
#include <BOPTools_ListOfPaveBlock.hxx>
#include <BOPTools_SplitShapesPool.hxx>
#include <BOPTools_StateFiller.hxx>

//=======================================================================
// function: BOPTools_DEProcessor::BOPTools_DEProcessor
// purpose: 
//=======================================================================
  BOPTools_DEProcessor::BOPTools_DEProcessor(const BOPTools_PaveFiller& aFiller,
					     const Standard_Integer aDim)
:
   myIsDone(Standard_False)
{
  myFiller=(BOPTools_PaveFiller*) &aFiller;
  myDS=myFiller->DS();
  
  myDim=aDim;
  if (aDim<2 || aDim>3) {
    myDim=3;
  }
  
}

//=======================================================================
// function: IsDone
// purpose: 
//=======================================================================
  Standard_Boolean BOPTools_DEProcessor::IsDone() const
{
  return myIsDone;
}
//=======================================================================
// function:  Do
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::Do()
{
  Standard_Integer aNbE;
  myIsDone=Standard_False;

  FindDegeneratedEdges();
  aNbE=myDEMap.Extent();
  
  if (!aNbE) {
    myIsDone=Standard_True;
    return;
  }
  
  DoPaves();
}

//=======================================================================
// function:  FindDegeneratedEdges
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::FindDegeneratedEdges()
{
  const BooleanOperations_ShapesDataStructure& aDS=*myDS;
  const BOPTools_PaveFiller& aPaveFiller=*myFiller;

  Standard_Integer i, aNbSourceShapes, nV, nF, nVx, ip, iRankE;
  TopAbs_ShapeEnum aType;

  const TopoDS_Shape& anObj=aDS.Object();
  const TopoDS_Shape& aTool=aDS.Tool();
  
  TopTools_IndexedDataMapOfShapeListOfShape aMEF;
  TopExp::MapShapesAndAncestors (anObj, TopAbs_EDGE, TopAbs_FACE, aMEF);
  TopExp::MapShapesAndAncestors (aTool, TopAbs_EDGE, TopAbs_FACE, aMEF);

  aNbSourceShapes=aDS.NumberOfSourceShapes();
  for (i=1; i<=aNbSourceShapes; i++) {
    const TopoDS_Shape& aS=aDS.Shape(i);
    aType=aS.ShapeType();
    if (aType==TopAbs_EDGE) {
      const TopoDS_Edge& aE=TopoDS::Edge(aS);
      if (BRep_Tool::Degenerated(aE)) {

	iRankE=aDS.Rank(i);

	TopoDS_Vertex aV=TopExp::FirstVertex(aE);

	nVx=aDS.ShapeIndex(aV, iRankE);
	//
	nV=nVx;
	ip=aPaveFiller.FindSDVertex(nV);
	if (ip) {
	  nV=ip;
	}
	//
	TColStd_ListOfInteger aLFn;
	const TopTools_ListOfShape& aLF=aMEF.FindFromKey(aE);
	TopTools_ListIteratorOfListOfShape anIt(aLF);
	for (; anIt.More(); anIt.Next()) {
	  const TopoDS_Shape& aF=anIt.Value();

	  nF=aDS.ShapeIndex(aF, iRankE);

	  aLFn.Append(nF);
	}
	BOPTools_DEInfo aDEInfo;
	aDEInfo.SetVertex(nV);
	aDEInfo.SetFaces(aLFn);

	myDEMap.Add (i, aDEInfo);

      }
    }
  }
  
}
//=======================================================================
// function:  DoPaves
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::DoPaves()
{

  Standard_Integer i, aNbE, nED, nVD, nFD=0;
  
  aNbE=myDEMap.Extent();
  for (i=1; i<=aNbE; i++) {
    nED=myDEMap.FindKey(i);
    
    const BOPTools_DEInfo& aDEInfo=myDEMap(i);
    nVD=aDEInfo.Vertex();
    // Fill PaveSet for the edge nED
    const TColStd_ListOfInteger& nLF=aDEInfo.Faces();
    TColStd_ListIteratorOfListOfInteger anIt(nLF);
    for (; anIt.More(); anIt.Next()) {
      nFD=anIt.Value();
      
      BOPTools_ListOfPaveBlock aLPB;
      FindPaveBlocks(nED, nVD, nFD, aLPB);
      FillPaveSet (nED, nVD, nFD, aLPB);
    }
    // 
    // Fill aSplitEdges for the edge nED
    FillSplitEdgesPool(nED);
    //
    // MakeSplitEdges
    MakeSplitEdges(nED, nFD);
    //
    // Compute States for Split parts
    if (myDim==3) {
      DoStates(nED, nFD);
    }
    if (myDim==2) {
      DoStates2D(nED, nFD);
    }
  }// next nED
}

//=======================================================================
// function:  DoStates
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::DoStates (const Standard_Integer nED, 
				       const Standard_Integer nFD)
{
  
  
  const BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->SplitShapesPool();
  const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(myDS->RefEdge(nED));

  const TopoDS_Edge& aDE=TopoDS::Edge(myDS->Shape(nED));
  const TopoDS_Face& aDF=TopoDS::Face(myDS->Shape(nFD));
  
  Standard_Integer nSp, iRank;
  Standard_Real aT, aT1, aT2, aTol=1e-7;
  TopoDS_Face aF;
  gp_Pnt2d aPx2DNear;
  gp_Pnt aPxNear;

  iRank=myDS->Rank(nED);
  const TopoDS_Shape& aReference=(iRank==1) ? myDS->Tool() : myDS->Object();

  BRepExtrema_DistShapeShape aDSS;
  aDSS.LoadS1(aReference);

  aF=aDF;
  aF.Orientation(TopAbs_FORWARD);

  BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);

  for (; aPBIt.More(); aPBIt.Next()) {
    BOPTools_PaveBlock& aPB=aPBIt.Value();
    
    nSp=aPB.Edge();
    const TopoDS_Edge& aSp=TopoDS::Edge(myDS->Shape(nSp));
    
    aPB.Parameters(aT1, aT2);
    aT=IntTools_Tools::IntermediatePoint(aT1, aT2);

    TopoDS_Edge aDERight, aSpRight;
    aDERight=aDE;
    aSpRight=aSp;

    BOPTools_Tools3D::OrientEdgeOnFace (aDE, aF, aDERight);
    aSpRight.Orientation(aDERight.Orientation());
    //
    {
      BRepAdaptor_Surface aBAS;
      aBAS.Initialize (aDF, Standard_False);

      if (aBAS.GetType()==GeomAbs_Sphere) {
	Standard_Real aDt2D, aR, aDelta=1.e-14;
	
	gp_Sphere aSphere=aBAS.Sphere();
	aR=aSphere.Radius();
	//
	aDt2D=acos (1.-4.*aTol/aR)+aDelta ;
	//
	BOPTools_Tools3D::PointNearEdge(aSpRight, aF, aT, aDt2D, aPx2DNear, aPxNear);
      }
      else {
	BOPTools_Tools3D::PointNearEdge(aSpRight, aF, aT, aPx2DNear, aPxNear);
      }
    }
    // 
    TopAbs_State aState;
    //
    TopAbs_ShapeEnum aTypeReference;
    aTypeReference=aReference.ShapeType();

    if (aTypeReference==TopAbs_SOLID) {
      // ... \ Solid processing 
      IntTools_Context& aContext=myFiller->ChangeContext();
      const TopoDS_Solid& aReferenceSolid=TopoDS::Solid(aReference);
      BRepClass3d_SolidClassifier& SC=aContext.SolidClassifier(aReferenceSolid);
      //
      SC.Perform(aPxNear, aTol);
      //
      aState=SC.State();
    }
    //
    
    else if (aTypeReference==TopAbs_SHELL || 
	     aTypeReference==TopAbs_FACE) {
      // ... \ Shell processing 
      TopoDS_Vertex aVxNear;
      BRep_Builder BB;
      
      BB.MakeVertex(aVxNear, aPxNear, aTol);

      aDSS.LoadS2(aVxNear);
      aDSS.Perform();
      
      aState=TopAbs_OUT;
      if (aDSS.IsDone()) {
	Standard_Real aDist=aDSS.Value();
	if (aDist < aTol) {
	  aState=TopAbs_ON;
	}
      }
    }
    else {
      // unknown aTypeReference
      aState=TopAbs_OUT;
    }
    //
    BooleanOperations_StateOfShape aSt;

    aSt=BOPTools_StateFiller::ConvertState(aState);

    myDS->SetState(nSp, aSt);
  }
}
//=======================================================================
// function:  DoStates2D
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::DoStates2D (const Standard_Integer nED, 
					 const Standard_Integer nFD)
{
  
  
  const BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->SplitShapesPool();
  const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(myDS->RefEdge(nED));

  const TopoDS_Edge& aDE=TopoDS::Edge(myDS->Shape(nED));
  const TopoDS_Face& aDF=TopoDS::Face(myDS->Shape(nFD));
  
  Standard_Integer nSp, iRank;
  Standard_Real aT, aT1, aT2;
  TopoDS_Face aF;
  gp_Pnt2d aPx2DNear;
  gp_Pnt aPxNear;

  iRank=myDS->Rank(nED);
  const TopoDS_Shape& aReference=(iRank==1) ? myDS->Tool() : myDS->Object();
  const TopoDS_Face& aFaceReference=TopoDS::Face(aReference);

  aF=aDF;
  aF.Orientation(TopAbs_FORWARD);

  BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);

  for (; aPBIt.More(); aPBIt.Next()) {
    BOPTools_PaveBlock& aPB=aPBIt.Value();
    
    nSp=aPB.Edge();
    const TopoDS_Edge& aSp=TopoDS::Edge(myDS->Shape(nSp));
    
    aPB.Parameters(aT1, aT2);
    aT=IntTools_Tools::IntermediatePoint(aT1, aT2);

    TopoDS_Edge aDERight, aSpRight;
    aDERight=aDE;
    aSpRight=aSp;

    BOPTools_Tools3D::OrientEdgeOnFace (aDE, aF, aDERight);
    aSpRight.Orientation(aDERight.Orientation());
    //
    BOPTools_Tools3D::PointNearEdge(aSpRight, aDF, aT, aPx2DNear, aPxNear);
    //
    Standard_Boolean bIsValidPoint;
    TopAbs_State aState=TopAbs_OUT;
    //
    IntTools_Context& aContext=myFiller->ChangeContext();
    bIsValidPoint=aContext.IsValidPointForFace(aPxNear, aFaceReference, 1.e-3);
    //
    if (bIsValidPoint) {
      aState=TopAbs_IN;
    }
    //
    BooleanOperations_StateOfShape aSt;
    
    aSt=BOPTools_StateFiller::ConvertState(aState);

    myDS->SetState(nSp, aSt);
  }
}

//=======================================================================
// function:  FillSplitEdgesPool
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::FillSplitEdgesPool (const Standard_Integer nED)
{
  BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->ChangeSplitShapesPool();
  //
  BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool.ChangeValue(myDS->RefEdge(nED));
  //
  aSplitEdges.Clear();
  //
  const BOPTools_PavePool& aPavePool=myFiller->PavePool();
  BOPTools_PavePool* pPavePool=(BOPTools_PavePool*) &aPavePool;
  BOPTools_PaveSet& aPaveSet= pPavePool->ChangeValue(myDS->RefEdge(nED));
  
  BOPTools_PaveBlockIterator aPBIt(nED, aPaveSet);
  for (; aPBIt.More(); aPBIt.Next()) {
    BOPTools_PaveBlock& aPB=aPBIt.Value();
    aSplitEdges.Append(aPB);
  }
}

//=======================================================================
// function:  MakeSplitEdges
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::MakeSplitEdges (const Standard_Integer nED,
					     const Standard_Integer nFD)
{
  const BOPTools_SplitShapesPool& aSplitShapesPool=myFiller->SplitShapesPool();
  const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(myDS->RefEdge(nED));

  Standard_Integer nV1, nV2, aNewShapeIndex;
  Standard_Real    t1, t2;
  TopoDS_Edge aE, aESplit;
  TopoDS_Vertex aV1, aV2;

  const TopoDS_Edge aDE=TopoDS::Edge(myDS->Shape(nED));
  const TopoDS_Face aDF=TopoDS::Face(myDS->Shape(nFD));

  BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);

  for (; aPBIt.More(); aPBIt.Next()) {
    BOPTools_PaveBlock& aPB=aPBIt.Value();
    
    const BOPTools_Pave& aPave1=aPB.Pave1();
    nV1=aPave1.Index();
    t1=aPave1.Param();
    aV1=TopoDS::Vertex(myDS->GetShape(nV1));
    aV1.Orientation(TopAbs_FORWARD);
    
    const BOPTools_Pave& aPave2=aPB.Pave2();
    nV2=aPave2.Index();
    t2=aPave2.Param();
    aV2=TopoDS::Vertex(myDS->GetShape(nV2));
    aV2.Orientation(TopAbs_REVERSED);
    
    MakeSplitEdge(aDE, aDF, aV1, t1, aV2, t2, aESplit); 
    //
    // Add Split Part of the Original Edge to the DS
    BooleanOperations_AncestorsSeqAndSuccessorsSeq anASSeq;
    
    anASSeq.SetNewSuccessor(nV1);
    anASSeq.SetNewOrientation(aV1.Orientation());
    
    anASSeq.SetNewSuccessor(nV2);
    anASSeq.SetNewOrientation(aV2.Orientation());
    
    myDS->InsertShapeAndAncestorsSuccessors(aESplit, anASSeq);
    aNewShapeIndex=myDS->NumberOfInsertedShapes();
    myDS->SetState(aNewShapeIndex, BooleanOperations_UNKNOWN);
    //
    // Fill Split Set for the Original Edge
    aPB.SetEdge(aNewShapeIndex);
    //
  }
}
//=======================================================================
// function:  MakeSplitEdge
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::MakeSplitEdge (const TopoDS_Edge&   aE,
					    const TopoDS_Face&   aF,
					    const TopoDS_Vertex& aV1,
					    const Standard_Real  aP1,
					    const TopoDS_Vertex& aV2,
					    const Standard_Real  aP2,
					    TopoDS_Edge& aNewEdge)
{
  Standard_Real aTol=1.e-7;

  TopoDS_Edge E=aE;

  E.EmptyCopy();
  BRep_Builder BB;
  BB.Add  (E, aV1);
  BB.Add  (E, aV2);

  BB.Range(E, aF, aP1, aP2);

  BB.Degenerated(E, Standard_True);

  BB.UpdateEdge(E, aTol);
  aNewEdge=E;
}


			
//=======================================================================
// function:  FillPaveSet
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::FillPaveSet (const Standard_Integer nED,
					  const Standard_Integer nVD,
					  const Standard_Integer nFD,
					  BOPTools_ListOfPaveBlock& aLPB)
{
  Standard_Boolean bIsDone, bXDir;
  Standard_Integer nE, aNbPoints, j;
  Standard_Real aTD1, aTD2, aT1, aT2, aTolInter, aX, aDT;
  //
  aDT=Precision::PConfusion();
  //
  BOPTools_PaveSet& aPaveSet= (myFiller->ChangePavePool()).ChangeValue(myDS->RefEdge(nED));
  //
  // Clear aPaveSet, aSplitEdges
  aPaveSet.ChangeSet().Clear();
  //
  const TopoDS_Edge& aDE=TopoDS::Edge(myDS->Shape(nED));
  const TopoDS_Face& aDF=TopoDS::Face(myDS->Shape(nFD));
  //
  // 2D Curve of degenerated edge on the face aDF
  Handle(Geom2d_Curve) aC2DDE=BRep_Tool::CurveOnSurface(aDE, aDF, aTD1, aTD2);
  //
  // Choose direction for Degenerated Edge
  gp_Pnt2d aP2d1, aP2d2;
  aC2DDE->D0(aTD1, aP2d1);
  aC2DDE->D0(aTD2, aP2d2);

  bXDir=Standard_False;
  if (fabs(aP2d1.Y()-aP2d2.Y()) < aDT){
    bXDir=!bXDir;
  }
  //
  // Prepare bounding Paves
  BOPTools_Pave aPave1 (nVD, aTD1, BooleanOperations_UnknownInterference);
  aPaveSet.Append(aPave1);
  BOPTools_Pave aPave2 (nVD, aTD2, BooleanOperations_UnknownInterference);
  aPaveSet.Append(aPave2);
  //
  // Fill other paves 
  BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
  for (; anIt.More(); anIt.Next()) {
    const BOPTools_PaveBlock& aPB=anIt.Value();
    nE=aPB.Edge();
    const TopoDS_Edge& aE=TopoDS::Edge(myDS->Shape(nE));
    
    Handle(Geom2d_Curve) aC2D=BRep_Tool::CurveOnSurface(aE, aDF, aT1, aT2);
    //
    // Intersection
    aTolInter=0.001;
    
    
    Geom2dAdaptor_Curve aGAC1, aGAC2;
    
    aGAC1.Load(aC2DDE, aTD1, aTD2);
    Handle(Geom2d_Line) aL2D= Handle(Geom2d_Line)::DownCast(aC2D);
    if (!aL2D.IsNull()) {
      aGAC2.Load(aC2D);
    }
    else {
      aGAC2.Load(aC2D, aT1, aT2);
    }
    
    Geom2dInt_GInter aGInter(aGAC1, aGAC2, aTolInter, aTolInter);
    
    bIsDone=aGInter.IsDone();
    if(bIsDone) {
      aNbPoints=aGInter.NbPoints();
      if (aNbPoints) { 
	for (j=1; j<=aNbPoints; ++j) {
	  gp_Pnt2d aP2D=aGInter.Point(j).Value();
	  //
	  aX=(bXDir) ? aP2D.X(): aP2D.Y();
	  //
	  if (fabs (aX-aTD1) < aDT || fabs (aX-aTD2) < aDT) {
	    continue; 
	  }
	  if (aX < aTD1 || aX > aTD2) {
	    continue; 
	  }
	  //
	  Standard_Boolean bRejectFlag=Standard_False;
	  const BOPTools_ListOfPave& aListOfPave=aPaveSet.Set();
	  BOPTools_ListIteratorOfListOfPave aPaveIt(aListOfPave);
	  for (; aPaveIt.More(); aPaveIt.Next()) {
	    const BOPTools_Pave& aPavex=aPaveIt.Value();
	    Standard_Real aXx=aPavex.Param();
	    if (fabs (aX-aXx) < aDT) {
	      bRejectFlag=Standard_True;
	      break;
	    }
	  }
	  if (bRejectFlag) {
	    continue; 
	  }
	  //
	  BOPTools_Pave aPave(nVD, aX, BooleanOperations_UnknownInterference);
	  aPaveSet.Append(aPave);
	}
      }
    }
  }
}

//=======================================================================
// function:  FindPaveBlocks
// purpose: 
//=======================================================================
  void BOPTools_DEProcessor::FindPaveBlocks(const Standard_Integer ,
					    const Standard_Integer nVD,
					    const Standard_Integer nFD,
					    BOPTools_ListOfPaveBlock& aLPBOut)
{

  BOPTools_CArray1OfSSInterference& aFFs=(myFiller->InterfPool())->SSInterferences();
  
  BOPTools_ListIteratorOfListOfPaveBlock anIt;
  Standard_Integer i, aNb, nF2, nV;

  //ZZ const TopoDS_Edge& aDE=TopoDS::Edge(myDS->Shape(nED));
  
  aNb=aFFs.Extent();
  for (i=1; i<=aNb; i++) {
    BOPTools_SSInterference& aFF=aFFs(i);
    //
    nF2=aFF.OppositeIndex(nFD);
    if (!nF2) {
      continue;
    }
    //
    // Split Parts 
    const BOPTools_ListOfPaveBlock& aLPBSplits=aFF.PaveBlocks();
    anIt.Initialize(aLPBSplits);
    for (; anIt.More(); anIt.Next()) {
      const BOPTools_PaveBlock& aPBSp=anIt.Value();
      
      const BOPTools_Pave& aPave1=aPBSp.Pave1();
      nV=aPave1.Index();
      if (nV==nVD) {
	aLPBOut.Append(aPBSp);
	continue;
      }
      
      const BOPTools_Pave& aPave2=aPBSp.Pave2();
      nV=aPave2.Index();
      if (nV==nVD) {
	aLPBOut.Append(aPBSp);
	continue;
      }
    }
    //
    // Section Parts
    Standard_Integer j, aNbCurves;   
    BOPTools_SequenceOfCurves& aSC=aFF.Curves();
    aNbCurves=aSC.Length();
    
    for (j=1; j<=aNbCurves; j++) {
      const BOPTools_Curve& aBC=aSC(j);
      const BOPTools_ListOfPaveBlock& aLPBSe=aBC.NewPaveBlocks();

      anIt.Initialize(aLPBSe);
      for (; anIt.More(); anIt.Next()) {
	const BOPTools_PaveBlock& aPBSe=anIt.Value();
	
	const BOPTools_Pave& aPv1=aPBSe.Pave1();
	nV=aPv1.Index();
	if (nV==nVD) {
	  aLPBOut.Append(aPBSe);
	  continue;
	}
	
	const BOPTools_Pave& aPv2=aPBSe.Pave2();
	nV=aPv2.Index();
	if (nV==nVD) {
	  aLPBOut.Append(aPBSe);
	  continue;
	}
      }
    }

  } // for (i=1; i<=aNb; i++) Next FF interference
  
}