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
|
// File: BRepFill_TrimEdgeTool.cxx
// Created: Mon Apr 24 16:40:33 1995
// Author: Bruno DUMORTIER
// <dub@fuegox>
#include <BRepFill_TrimEdgeTool.ixx>
#include <BRep_Tool.hxx>
#include <Bisector_BisecAna.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom_Curve.hxx>
#include <GeomProjLib.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom2dAPI_ProjectPointOnCurve.hxx>
#include <Geom2dInt_GInter.hxx>
#include <gp_Pnt.hxx>
#include <TopLoc_Location.hxx>
#include <TopoDS.hxx>
#include <Precision.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <IntRes2d_IntersectionSegment.hxx>
#include <StdFail_NotDone.hxx>
#ifdef DRAW
#include <DrawTrSurf.hxx>
#include <DBRep.hxx>
static Standard_Boolean Affich = Standard_False;
#endif
//=======================================================================
//function : SimpleExpression
//purpose :
//=======================================================================
static void SimpleExpression (const Bisector_Bisec& B,
Handle(Geom2d_Curve)& Bis)
{
Bis = B.Value();
Handle(Standard_Type) BT = Bis->DynamicType();
if (BT == STANDARD_TYPE(Geom2d_TrimmedCurve)) {
Handle(Geom2d_TrimmedCurve) TrBis
= Handle(Geom2d_TrimmedCurve)::DownCast(Bis);
Handle(Geom2d_Curve) BasBis = TrBis->BasisCurve();
BT = BasBis->DynamicType();
if (BT == STANDARD_TYPE(Bisector_BisecAna)) {
Bis = Handle(Bisector_BisecAna)::DownCast(BasBis)->Geom2dCurve();
Bis = new Geom2d_TrimmedCurve (Bis,
TrBis->FirstParameter(),
TrBis->LastParameter());
}
}
}
//=======================================================================
//function : BRepFill_TrimEdgeTool
//purpose :
//=======================================================================
BRepFill_TrimEdgeTool::BRepFill_TrimEdgeTool()
{
}
//=======================================================================
//function : BRepFill_TrimEdgeTool
//purpose :
//=======================================================================
BRepFill_TrimEdgeTool::BRepFill_TrimEdgeTool
(const Bisector_Bisec& Bisec,
const Handle(Geom2d_Geometry)& S1,
const Handle(Geom2d_Geometry)& S2,
const Standard_Real Offset) :
myOffset(Offset),
myBisec(Bisec)
{
isPoint1 = (S1->DynamicType() == STANDARD_TYPE(Geom2d_CartesianPoint));
isPoint2 = (S2->DynamicType() == STANDARD_TYPE(Geom2d_CartesianPoint));
// recuperation des geometries des shapes.
// Standard_Real f,l;
if (isPoint1) {
myP1 = Handle(Geom2d_Point)::DownCast(S1)->Pnt2d();
}
else {
myC1 = Handle(Geom2d_Curve)::DownCast(S1);
#ifdef DRAW
if ( Affich) {
//POP pour NT
char* myC1name = "myC1";
DrawTrSurf::Set(myC1name,myC1);
// DrawTrSurf::Set("myC1",myC1);
}
#endif
}
if (isPoint2) {
myP2 = Handle(Geom2d_Point)::DownCast(S2)->Pnt2d();
}
else {
myC2 = Handle(Geom2d_Curve)::DownCast(S2);
#ifdef DRAW
if ( Affich) {
char* myC2name = "myC2";
DrawTrSurf::Set(myC2name,myC2);
// DrawTrSurf::Set("myC2",myC2);
}
#endif
}
// recuperer l expression simple de la bisectrice
Handle(Geom2d_Curve) Bis;
SimpleExpression(myBisec, Bis);
myBis = Geom2dAdaptor_Curve(Bis);
#ifdef DRAW
if ( Affich) {
char* myBisname = "myBis";
DrawTrSurf::Set(myBisname,Bis);
}
#endif
}
//=======================================================================
//function : Bubble
//purpose : Ordonne la sequence de point en x croissant.
//=======================================================================
static void Bubble(TColgp_SequenceOfPnt& Seq)
{
Standard_Boolean Invert = Standard_True;
Standard_Integer NbPoints = Seq.Length();
while (Invert) {
Invert = Standard_False;
for ( Standard_Integer i = 1; i < NbPoints; i++) {
gp_Pnt P1 = Seq.Value(i);
gp_Pnt P2 = Seq.Value(i+1);
if (P2.X()<P1.X()) {
Seq.Exchange(i,i+1);
Invert = Standard_True;
}
}
}
}
//=======================================================================
//function : EvalParameters (lbr le 8 juillet, je duplique pour modifier)
//purpose :
//=======================================================================
static void EvalParameters(const Geom2dAdaptor_Curve& Bis,
const Geom2dAdaptor_Curve& AC,
TColgp_SequenceOfPnt& Params)
{
Geom2dInt_GInter Intersector;
Standard_Real Tol = Precision::Intersection();
// Standard_Real TolC = 1.e-9;
Geom2dAdaptor_Curve CBis(Bis);
Geom2dAdaptor_Curve CAC (AC);
if(AC.GetType() != GeomAbs_Circle || AC.GetType() != GeomAbs_Line) {
Tol *= 100.;
}
//Intersector = Geom2dInt_GInter(CBis, CAC, TolC, Tol);
Intersector = Geom2dInt_GInter(CAC, CBis, Tol, Tol);
Standard_Integer NbPoints, NbSegments;
Standard_Real U1, U2;
gp_Pnt P;
if ( !Intersector.IsDone()) {
StdFail_NotDone::Raise("BRepFill_TrimSurfaceTool::IntersectWith");
}
NbPoints = Intersector.NbPoints();
if (NbPoints > 0) {
for ( Standard_Integer i = 1; i <= NbPoints; i++) {
U1 = Intersector.Point(i).ParamOnSecond();
U2 = Intersector.Point(i).ParamOnFirst();
P = gp_Pnt(U1,U2,0.);
Params.Append(P);
}
}
NbSegments = Intersector.NbSegments();
if (NbSegments > 0) {
IntRes2d_IntersectionSegment Seg;
for ( Standard_Integer i = 1; i <= NbSegments; i++) {
Seg = Intersector.Segment(i);
U1 = Seg.FirstPoint().ParamOnSecond();
Standard_Real Ulast = Seg.LastPoint().ParamOnSecond();
if ( Abs(U1 - CBis.FirstParameter()) <= Tol &&
Abs(Ulast - CBis.LastParameter()) <= Tol ) {
P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.);
Params.Append(P);
P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.);
Params.Append(P);
}
else {
U1 += Seg.LastPoint().ParamOnSecond();
U1 /= 2.;
U2 = Seg.FirstPoint().ParamOnFirst();
U2 += Seg.LastPoint().ParamOnFirst();
U2 /= 2.;
P = gp_Pnt(U1,U2,0.);
Params.Append(P);
}
}
}
// Ordonne la sequence en param croissant sur la bissectrice.
Bubble( Params);
}
static void EvalParametersBis(const Geom2dAdaptor_Curve& Bis,
const Geom2dAdaptor_Curve& AC,
TColgp_SequenceOfPnt& Params,
const Standard_Real Tol)
{
Geom2dInt_GInter Intersector;
Standard_Real TolC = Tol;
Geom2dAdaptor_Curve CBis(Bis);
Geom2dAdaptor_Curve CAC (AC);
Intersector = Geom2dInt_GInter(CAC, CBis, TolC, Tol);
Standard_Integer NbPoints, NbSegments;
Standard_Real U1, U2;
gp_Pnt P;
if ( !Intersector.IsDone()) {
StdFail_NotDone::Raise("BRepFill_TrimSurfaceTool::IntersectWith");
}
NbPoints = Intersector.NbPoints();
if (NbPoints > 0) {
for ( Standard_Integer i = 1; i <= NbPoints; i++) {
U1 = Intersector.Point(i).ParamOnSecond();
U2 = Intersector.Point(i).ParamOnFirst();
P = gp_Pnt(U1,U2,0.);
Params.Append(P);
}
}
NbSegments = Intersector.NbSegments();
if (NbSegments > 0) {
IntRes2d_IntersectionSegment Seg;
for ( Standard_Integer i = 1; i <= NbSegments; i++) {
Seg = Intersector.Segment(i);
U1 = Seg.FirstPoint().ParamOnSecond();
Standard_Real Ulast = Seg.LastPoint().ParamOnSecond();
if ( Abs(U1 - CBis.FirstParameter()) <= Tol &&
Abs(Ulast - CBis.LastParameter()) <= Tol ) {
P = gp_Pnt(U1,Seg.FirstPoint().ParamOnFirst(),0.);
Params.Append(P);
P = gp_Pnt(Ulast,Seg.LastPoint().ParamOnFirst(),0.);
Params.Append(P);
}
else {
U1 += Seg.LastPoint().ParamOnSecond();
U1 /= 2.;
U2 = Seg.FirstPoint().ParamOnFirst();
U2 += Seg.LastPoint().ParamOnFirst();
U2 /= 2.;
P = gp_Pnt(U1,U2,0.);
Params.Append(P);
}
}
}
// Ordonne la sequence en param croissant sur la bissectrice.
Bubble( Params);
}
//=======================================================================
//function : IntersectWith
//purpose :
//=======================================================================
void BRepFill_TrimEdgeTool::IntersectWith(const TopoDS_Edge& Edge1,
const TopoDS_Edge& Edge2,
TColgp_SequenceOfPnt& Params)
{
Params.Clear();
// recuperer les courbes associees aux edges.
TopLoc_Location L;
Standard_Real f,l;
Handle(Geom_Surface) Surf;
Handle(Geom2d_Curve) C1;
BRep_Tool::CurveOnSurface(Edge1,C1,Surf,L,f,l);
Geom2dAdaptor_Curve AC1(C1,f,l);
Handle(Geom2d_Curve) C2;
BRep_Tool::CurveOnSurface(Edge2,C2,Surf,L,f,l);
Geom2dAdaptor_Curve AC2(C2,f,l);
#ifdef DRAW
if ( Affich) {
f = AC1.FirstParameter();
l = AC1.LastParameter();
char* CURVE1name = "CURVE1";
DrawTrSurf::Set(CURVE1name, new Geom2d_TrimmedCurve(C1,f,l));
f = AC2.FirstParameter();
l = AC2.LastParameter();
char* CURVE2name = "CURVE2";
DrawTrSurf::Set(CURVE2name, new Geom2d_TrimmedCurve(C2,f,l));
f = myBis.FirstParameter();
l = myBis.LastParameter();
char* bisname = "BIS";
DrawTrSurf::Set(bisname, new Geom2d_TrimmedCurve(myBis.Curve(),f,l));
char* Edge1name = "E1";
DBRep::Set(Edge1name, Edge1);
char* Edge2name = "E2";
DBRep::Set(Edge2name, Edge2);
}
#endif
// Calcul intersection
TColgp_SequenceOfPnt Points2;
gp_Pnt PSeq;
EvalParameters (myBis,AC1,Params);
EvalParameters (myBis,AC2,Points2);
Standard_Integer SeanceDeRattrapage=0;
Standard_Real TolInit= 1.e-9;
Standard_Integer nn = 7;
if(AC1.GetType() != GeomAbs_Circle ||
AC1.GetType() != GeomAbs_Line ||
AC2.GetType() != GeomAbs_Circle ||
AC2.GetType() != GeomAbs_Line ) {
TolInit = 1.e-8;
nn = 6;
}
while ( SeanceDeRattrapage < nn // TolInit <= 0.01
&& ( Points2.Length() != Params.Length() ||
(Points2.Length() == 0 && Params.Length() == 0) ) ) {
#ifdef DEB
cout << "BRepFill_TrimEdgeTool: incoherent intersection. On essaie avec une tol plus grande" << endl;
#endif
Params.Clear();
Points2.Clear();
TolInit*=10.0;
EvalParametersBis(myBis,AC1,Params,TolInit);
EvalParametersBis(myBis,AC2,Points2,TolInit);
SeanceDeRattrapage++;
}
#ifdef DEB
if(SeanceDeRattrapage != 0) cout << "SeanceDeRattrapage = " << SeanceDeRattrapage << endl;
if(SeanceDeRattrapage == nn) {
cout << "BRepFill_TrimEdgeTool: incoherent intersection" << endl;
}
#endif
if(Params.Length() == 0 && Points2.Length() == 1) {
//cout << "Params.Length() == 0 && Points2.Length() == 1" << endl;
Standard_Real dmin;
Standard_Real tBis = Points2(1).X();
gp_Pnt2d PBis = myBis.Value(tBis);
Standard_Real t = AC1.FirstParameter();
gp_Pnt2d PC = AC1.Value(t);
dmin = PC.SquareDistance(PBis);
gp_Pnt P(tBis, t, 0.);
Params.Append(P);
t = AC1.LastParameter();
PC = AC1.Value(t);
if(dmin > PC.SquareDistance(PBis)) {
P.SetY(t);
Params.SetValue(1,P);
}
}
else if(Params.Length() == 1 && Points2.Length() == 0) {
//cout << "Params.Length() == 1 && Points2.Length() == 0" << endl;
Standard_Real dmin;
Standard_Real tBis = Params(1).X();
gp_Pnt2d PBis = myBis.Value(tBis);
Standard_Real t = AC2.FirstParameter();
gp_Pnt2d PC = AC2.Value(t);
dmin = PC.SquareDistance(PBis);
gp_Pnt P(tBis, t, 0.);
Points2.Append(P);
t = AC2.LastParameter();
PC = AC2.Value(t);
if(dmin > PC.SquareDistance(PBis)) {
P.SetY(t);
Points2.SetValue(1,P);
}
}
// petite manip destinee a eliminer les intersections incoherentes:
// on ne renvoie que les intersections communes ( meme parametre sur
// la bissectrice.).
// La tolerance pourra eventuellement etre reglee.
gp_Pnt P1,P2;
Standard_Real Tol = 4 * 100 * Precision::PConfusion();
Standard_Integer i = 1;
Standard_Integer NbPoints = Params.Length();
if(NbPoints == 1 && Points2.Length() == 1) {
//cout << "NbPoints == 1 && Points2.Length() == 1" << endl;
for ( i = 1; i <= NbPoints; i++) {
PSeq = Params(i);
PSeq.SetZ((Points2.Value(i)).Y());
Params.SetValue(i,PSeq);
}
return;
}
i = 1;
while ( i <= Min( Params.Length(), Points2.Length())) {
P1 = Params(i);
P2 = Points2(i);
Standard_Real P1xP2x=Abs( P1.X() - P2.X());
if ( P1xP2x > Tol ) {
#ifdef DEB
cout << "BRepFill_TrimEdgeTool: Pas le meme parametre sur la bissectrice" << endl;
#endif
if(P1xP2x>TolInit) {
#ifdef DEB
cout << "BRepFill_TrimEdgeTool: On continue quand meme" << endl;
#endif
i++;
}
else {
if ( P1.X() < P2.X()) Params.Remove(i);
else Points2.Remove(i);
}
}
else i++;
}
if ( Params.Length() > Points2.Length()) {
Params.Remove(Points2.Length()+1, Params.Length());
}
else if ( Params.Length() < Points2.Length()) {
Points2.Remove(Params.Length()+1, Points2.Length());
}
NbPoints = Params.Length();
for ( i = 1; i <= NbPoints; i++) {
PSeq = Params(i);
PSeq.SetZ((Points2.Value(i)).Y());
Params.SetValue(i,PSeq);
}
}
//=======================================================================
//function : AddOrConfuse
//purpose : le premier ou le dernier point de la bissectrice est sur la
// parallele si on ne l a pas trouve dans les intersections on
// le projette sur les paralleles et on l ajoute dans les params
//=======================================================================
void BRepFill_TrimEdgeTool::AddOrConfuse(const Standard_Boolean Start,
const TopoDS_Edge& Edge1,
const TopoDS_Edge& Edge2,
TColgp_SequenceOfPnt& Params)
const
{
Standard_Boolean ToProj = Standard_True;
gp_Pnt2d PBis;
Standard_Real Tol = 10*Precision::Confusion();
// recuperer les courbes associees aux edges.
TopLoc_Location L;
Standard_Real f,l;
Handle(Geom_Surface) Surf;
Handle(Geom2d_Curve) C1;
BRep_Tool::CurveOnSurface(Edge1,C1,Surf,L,f,l);
Geom2dAdaptor_Curve AC1(C1,f,l);
if (Start) PBis = myBis.Value(myBis.FirstParameter());
else PBis = myBis.Value(myBis.LastParameter ());
// Test si le bout de la bissectrice est dans l ensemble des points d intersection.
if (!Params.IsEmpty()) {
gp_Pnt2d P;
if (Start) P = AC1.Value(Params.First().Y());
else P = AC1.Value(Params.Last ().Y());
ToProj = !PBis.IsEqual(P,Tol);
}
if (ToProj) {
#ifdef DEB
cout << " projection extremite bissectrice sur parallele."<<endl;
#endif
// Projection du point sur les paralleles et ajout dans Params
Standard_Real f2,l2;
Handle(Geom2d_Curve) C2;
BRep_Tool::CurveOnSurface(Edge2,C2,Surf,L,f2,l2);
Geom2dAPI_ProjectPointOnCurve Projector1(PBis,C1,f,l);
Geom2dAPI_ProjectPointOnCurve Projector2(PBis,C2,f2,l2);
if (Projector1.NbPoints() == 0) {
#ifdef DEB
cout << "Echec projection dans BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
#endif
return;
}
if (!Projector1.NearestPoint().IsEqual(PBis,Tol)) {
#ifdef DEB
cout <<" Mauvaisesolution dans BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
#endif
return;
}
if (Projector2.NbPoints() == 0) {
#ifdef DEB
cout << "Echec projection dans BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
#endif
return;
}
if (!Projector2.NearestPoint().IsEqual(PBis,Tol)) {
#ifdef DEB
cout <<" Mauvaisesolution dans BRepFill_TrimEdgeTool::AddOrConfuse"<<endl;
#endif
return;
}
gp_Pnt PInt (0,
Projector1.LowerDistanceParameter(),
Projector2.LowerDistanceParameter());
if (Start) {
PInt.SetX (myBis.FirstParameter());
Params.Prepend(PInt);
}
else {
PInt.SetX (myBis.LastParameter());
Params.Append(PInt);
}
}
}
//=======================================================================
//function : IsInside
//purpose :
//=======================================================================
Standard_Boolean BRepFill_TrimEdgeTool::IsInside(const gp_Pnt2d& P) const
{
// Modified by Sergey KHROMOV - Fri Sep 27 11:43:12 2002 Begin
// Standard_Real Dist;
Standard_Real Dist = RealLast();
// Modified by Sergey KHROMOV - Fri Sep 27 11:43:12 2002 End
if (isPoint1)
Dist = P.Distance(myP1);
else if (isPoint2)
Dist = P.Distance(myP2);
else {
Geom2dAPI_ProjectPointOnCurve Projector(P,myC1);
if (Projector.NbPoints() > 0) {
Dist = Projector.LowerDistance();
}
// Modified by Sergey KHROMOV - Fri Sep 27 11:43:43 2002 Begin
// else {
// gp_Pnt2d PF = myC1->Value(myC1->FirstParameter());
// gp_Pnt2d PL = myC1->Value(myC1->LastParameter());
// Dist = Min (P.Distance(PF),P.Distance(PL));
// }
// Check of distances between P and first and last point of the first curve
// should be performed in any case, despite of the results of projection.
gp_Pnt2d PF = myC1->Value(myC1->FirstParameter());
gp_Pnt2d PL = myC1->Value(myC1->LastParameter());
Standard_Real aDistMin = Min (P.Distance(PF),P.Distance(PL));
if (Dist > aDistMin)
Dist = aDistMin;
// Modified by Sergey KHROMOV - Fri Sep 27 11:43:44 2002 End
}
// return (Dist < Abs(myOffset);
// return (Dist < Abs(myOffset) + Precision::Confusion());
return (Dist < Abs(myOffset) - Precision::Confusion());
}
|