1 // File: BRepOffset_Inter2d.cxx
2 // Created: Tue Sep 3 16:37:35 1996
3 // Author: Yves FRICAUD
4 // <yfr@claquox.paris1.matra-dtv.fr>
6 // Modified by skv - Wed Dec 24 18:08:39 2003 OCC4455
10 #include <BRepOffset_Inter2d.ixx>
11 #include <BRepAlgo_AsDes.hxx>
12 #include <BRepOffset_Offset.hxx>
13 #include <BRepOffset_Tool.hxx>
15 #include <BRep_Builder.hxx>
16 #include <BRep_Tool.hxx>
17 #include <BRepLib_MakeVertex.hxx>
18 #include <BRepAdaptor_Curve.hxx>
19 #include <BRepAdaptor_Surface.hxx>
20 #include <BRepTools_WireExplorer.hxx>
22 #include <TopExp_Explorer.hxx>
23 #include <TopoDS_Iterator.hxx>
26 #include <TopoDS_Edge.hxx>
27 #include <TopoDS_Vertex.hxx>
28 #include <TopoDS_Wire.hxx>
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
33 #include <BRep_TEdge.hxx>
34 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
35 #include <BRep_CurveRepresentation.hxx>
36 #include <BRep_GCurve.hxx>
43 extern Standard_Integer AffichInt2d;
45 Standard_IMPORT Standard_Boolean AffichInt2d;
47 static Standard_Integer NbF2d = 0;
48 static Standard_Integer NbE2d = 0;
49 static Standard_Integer NbNewVertices = 0;
52 #include <Geom_Line.hxx>
53 #include <Geom_TrimmedCurve.hxx>
54 #include <GeomConvert_CompCurveToBSplineCurve.hxx>
55 #include <Precision.hxx>
56 #include <Geom2d_TrimmedCurve.hxx>
57 #include <Geom2d_BezierCurve.hxx>
58 #include <Geom2d_BSplineCurve.hxx>
59 #include <Geom2d_Line.hxx>
60 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
62 #include <BRepLib.hxx>
63 #include <BRepAdaptor_Curve2d.hxx>
64 #include <Adaptor3d_HSurface.hxx>
65 #include <Adaptor3d_CurveOnSurface.hxx>
66 #include <Geom_BSplineSurface.hxx>
67 #include <Geom_CylindricalSurface.hxx>
68 #include <Geom_ConicalSurface.hxx>
69 #include <Adaptor2d_HCurve2d.hxx>
70 #include <TColGeom2d_SequenceOfCurve.hxx>
71 #include <Geom2dInt_GInter.hxx>
72 #include <IntRes2d_IntersectionPoint.hxx>
73 #include <IntRes2d_IntersectionSegment.hxx>
74 #include <GeomAPI_ProjectPointOnCurve.hxx>
75 #include <GeomAdaptor_Surface.hxx>
76 #include <Geom2dAdaptor_HCurve.hxx>
77 #include <GeomAdaptor_HSurface.hxx>
78 #include <GeomLib.hxx>
79 #include <GeomProjLib.hxx>
80 #include <TColgp_SequenceOfPnt.hxx>
81 #include <TColgp_Array1OfPnt2d.hxx>
82 #include <Bnd_Box.hxx>
83 #include <BndLib_Add3dCurve.hxx>
84 #include <BRepTools.hxx>
87 //=======================================================================
88 //function : CommonVertex
90 //=======================================================================
92 static TopoDS_Vertex CommonVertex(TopoDS_Edge& E1,
95 TopoDS_Vertex V1[2],V2[2],V;
96 // Modified by skv - Wed Dec 24 18:08:39 2003 OCC4455 Begin
97 // TopExp::Vertices(E1,V1[0],V1[1]);
98 // TopExp::Vertices(E2,V2[0],V2[1]);
100 TopExp::Vertices(E1,V1[0],V1[1], Standard_True);
101 TopExp::Vertices(E2,V2[0],V2[1], Standard_True);
102 // The first edge is the current one, the second edge is the next one.
103 // We check last vertex of the first edge first.
104 // if (V1[0].IsSame(V2[0]) || V1[0].IsSame(V2[1])) return V1[0];
105 // if (V1[1].IsSame(V2[0]) || V1[1].IsSame(V2[1])) return V1[1];
106 if (V1[1].IsSame(V2[0]) || V1[1].IsSame(V2[1])) return V1[1];
107 if (V1[0].IsSame(V2[0]) || V1[0].IsSame(V2[1])) return V1[0];
108 // Modified by skv - Wed Dec 24 18:08:40 2003 OCC4455 End
112 //=======================================================================
115 //=======================================================================
117 static void Store (const TopoDS_Edge& E1,
118 const TopoDS_Edge& E2,
119 TopTools_ListOfShape& LV1,
120 TopTools_ListOfShape& LV2,
121 Handle(BRepAlgo_AsDes) AsDes,
124 //-------------------------------------------------------------
125 // Test if the points of intersection correspond to existing
126 // vertices. Otherwise add edges in the descendants.
127 // Note: at this stage only vertices of intersection are in the descendants.
128 //-------------------------------------------------------------
129 const TopTools_ListOfShape& VOnE1 = AsDes->Descendant(E1);
130 const TopTools_ListOfShape& VOnE2 = AsDes->Descendant(E2);
131 TopTools_ListOfShape NewVOnE1;
132 TopTools_ListOfShape NewVOnE2;
135 TopTools_ListIteratorOfListOfShape it, itLV1, itLV2;
137 TopAbs_Orientation O1,O2;
139 Standard_Boolean OnE1,OnE2;
141 for (itLV1.Initialize(LV1),itLV2.Initialize(LV2);
143 itLV1.Next() ,itLV2.Next()) {
145 TopoDS_Vertex V = TopoDS::Vertex(itLV1.Value());
147 U1 = (BRep_Tool::Degenerated(E1))?
148 BRep_Tool::Parameter(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)), E1) :
149 BRep_Tool::Parameter(V, E1);
150 U2 = (BRep_Tool::Degenerated(E2))?
151 BRep_Tool::Parameter(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)), E2) :
152 BRep_Tool::Parameter(V, E2);
153 O1 = V.Orientation();
154 O2 = itLV2.Value().Orientation();
155 P = BRep_Tool::Pnt(V);
156 OnE1 = OnE2 = Standard_False;
158 if (!VOnE1.IsEmpty()) {
159 //-----------------------------------------------------------------
160 // Find if the point of intersection corresponds to a vertex of E1.
161 //-----------------------------------------------------------------
162 for (it.Initialize(VOnE1); it.More(); it.Next()) {
163 P1 = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
164 if (P.IsEqual(P1,Tol)) {
165 V = TopoDS::Vertex(it.Value());
167 OnE1 = Standard_True;
172 if (!VOnE2.IsEmpty()) {
174 //-----------------------------------------------------------------
175 // Find if the vertex found on E1 is not already on E2.
176 //-----------------------------------------------------------------
177 for (it.Initialize(VOnE2); it.More(); it.Next()) {
178 if (it.Value().IsSame(V)) {
179 OnE2 = Standard_True;
185 for (it.Initialize(VOnE2); it.More(); it.Next()) {
186 //-----------------------------------------------------------------
187 // Find if the point of intersection corresponds to a vertex of E2.
188 //-----------------------------------------------------------------
189 P2 = BRep_Tool::Pnt(TopoDS::Vertex(it.Value()));
190 if (P.IsEqual(P2,Tol)) {
191 V = TopoDS::Vertex(it.Value());
193 OnE2 = Standard_True;
199 if (!V1.IsSame(V2)) {
200 //---------------------------------------------------------------
201 // Two vertices are actually the same.
202 // V2 will be replaced by V1.
203 // update the parameters of vertex on edges.
204 //---------------------------------------------------------------
207 const TopTools_ListOfShape& EdgeWithV2 = AsDes->Ascendant(V2);
209 for (it.Initialize(EdgeWithV2); it.More(); it.Next()) {
210 EWE2 = TopoDS::Edge(it.Value());
211 TopoDS_Shape aLocalShape =V2.Oriented(TopAbs_INTERNAL);
212 UV2 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalShape),EWE2);
214 // BRep_Tool::Parameter(TopoDS::Vertex(V2.Oriented(TopAbs_INTERNAL)),EWE2);
215 aLocalShape = V1.Oriented(TopAbs_INTERNAL);
216 B.UpdateVertex(TopoDS::Vertex(aLocalShape),UV2,EWE2,Tol);
217 // B.UpdateVertex(TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)),
220 AsDes->Replace(V2,V1);
225 TopoDS_Shape aLocalShape = V.Oriented(TopAbs_INTERNAL);
226 B.UpdateVertex(TopoDS::Vertex(aLocalShape),U1,E1,Tol);
227 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
230 NewVOnE1.Append(V.Oriented(O1));
234 TopoDS_Shape aLocalShape = V.Oriented(TopAbs_INTERNAL);
235 B.UpdateVertex(TopoDS::Vertex(aLocalShape),U2,E2,Tol);
236 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
239 NewVOnE2.Append(V.Oriented(O2));
244 if (!OnE1 && !OnE2) {
246 char* name = new char[100];
247 sprintf(name,"VV_%d",NbNewVertices++);
253 if (!NewVOnE1.IsEmpty()) AsDes->Add(E1,NewVOnE1);
254 if (!NewVOnE2.IsEmpty()) AsDes->Add(E2,NewVOnE2);
258 //=======================================================================
259 //function : EdgeInter
261 //=======================================================================
263 static void EdgeInter(const TopoDS_Face& F,
264 const TopoDS_Edge& E1,
265 const TopoDS_Edge& E2,
266 const Handle(BRepAlgo_AsDes)& AsDes,
268 Standard_Boolean WithOri)
273 char* name = new char[100];
274 sprintf(name,"E2d_%d_%d",NbF2d,NbE2d++);
276 sprintf(name,"E2d_%d_%d",NbF2d,NbE2d++);
284 Standard_Real f[3],l[3];
285 Standard_Real MilTol2 = 1000*Tol*Tol;
286 Standard_Real TolDub = 1.e-7;
289 BRep_Tool::Range(E1, f[1], l[1]);
290 BRep_Tool::Range(E2, f[2], l[2]);
292 BRepAdaptor_Curve CE1(E1,F);
293 BRepAdaptor_Curve CE2(E2,F);
295 TopoDS_Edge EI[3]; EI[1] = E1; EI[2] = E2;
296 TopTools_ListOfShape LV1;
297 TopTools_ListOfShape LV2;
301 if (!TopExp::CommonVertex( E1, E2, CV ))
303 BRepLib::BuildCurve3d(E1);
304 BRepLib::BuildCurve3d(E2);
306 Standard_Real TolSum = BRep_Tool::Tolerance(E1) + BRep_Tool::Tolerance(E2);
307 TolSum = Max( TolSum, 1.e-5 );
309 TColgp_SequenceOfPnt ResPoints;
310 TColStd_SequenceOfReal ResParamsOnE1, ResParamsOnE2;
312 Standard_Boolean WithDegen = BRep_Tool::Degenerated(E1) || BRep_Tool::Degenerated(E2);
316 Standard_Integer ideg = (BRep_Tool::Degenerated(E1))? 1 : 2;
317 TopoDS_Iterator iter( EI[ideg] );
320 const TopoDS_Vertex& vdeg = TopoDS::Vertex(iter.Value());
321 DegPoint = BRep_Tool::Pnt(vdeg);
325 BRepAdaptor_Curve CEdeg( EI[ideg], F );
326 DegPoint = CEdeg.Value( CEdeg.FirstParameter() );
329 BRepAdaptor_Surface BAsurf(F);
330 Handle(Geom2d_Curve) pcurve1 = BRep_Tool::CurveOnSurface(E1, F, f[1], l[1]);
331 Handle(Geom2d_Curve) pcurve2 = BRep_Tool::CurveOnSurface(E2, F, f[2], l[2]);
332 Geom2dAdaptor_Curve GAC1(pcurve1, f[1], l[1]);
333 Geom2dAdaptor_Curve GAC2(pcurve2, f[2], l[2]);
334 Geom2dInt_GInter Inter2d( GAC1, GAC2, TolDub, TolDub );
335 for (i = 1; i <= Inter2d.NbPoints(); i++)
342 gp_Pnt2d P2d = Inter2d.Point(i).Value();
343 P3d = BAsurf.Value( P2d.X(), P2d.Y() );
345 ResPoints.Append( P3d );
346 ResParamsOnE1.Append( Inter2d.Point(i).ParamOnFirst() );
347 ResParamsOnE2.Append( Inter2d.Point(i).ParamOnSecond() );
350 for (i = 1; i <= ResPoints.Length(); i++)
352 Standard_Real aT1 = ResParamsOnE1(i); //ponc1.Parameter();
353 Standard_Real aT2 = ResParamsOnE2(i); //ponc2.Parameter();
354 if (Precision::IsInfinite(aT1) || Precision::IsInfinite(aT2))
357 cout << "Inter2d : Solution rejected due to infinite parameter"<<endl;
362 gp_Pnt P = ResPoints(i); //ponc1.Value();
363 TopoDS_Vertex aNewVertex = BRepLib_MakeVertex(P);
364 aNewVertex.Orientation(TopAbs_INTERNAL);
365 B.UpdateVertex( aNewVertex, aT1, E1, Tol );
366 B.UpdateVertex( aNewVertex, aT2, E2, Tol );
367 gp_Pnt P1 = CE1.Value(aT1);
368 gp_Pnt P2 = CE2.Value(aT2);
369 Standard_Real dist1, dist2, dist3;
370 dist1 = P1.Distance(P);
371 dist2 = P2.Distance(P);
372 dist3 = P1.Distance(P2);
373 dist1 = Max( dist1, dist2 );
374 dist1 = Max( dist1, dist3 );
375 B.UpdateVertex( aNewVertex, dist1 );
378 if (aT1 < f[1]-Tol || aT1 > l[1]+Tol)
380 cout << "out of limit"<<endl;
381 cout<<"aT1 = "<<aT1<<", f[1] = "<<f[1]<<", l[1] = "<<l[1]<<endl;
383 if (aT2 < f[2]-Tol || aT2 > l[2]+Tol)
385 cout << "out of limit"<<endl;
386 cout<<"aT2 = "<<aT2<<", f[2] = "<<f[2]<<", l[2] = "<<l[2]<<endl;
388 if (P1.SquareDistance(P) > MilTol2 || P2.SquareDistance(P) > MilTol2 || P1.Distance(P2) > 2.*Tol)
390 cout << "Inter2d : Solution rejected "<<endl;
391 cout<<"P = "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<endl;
392 cout<<"P1 = "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<endl;
393 cout<<"P2 = "<<P2.X()<<" "<<P2.Y()<<" "<<P2.Z()<<endl;
394 cout<<"MaxDist = "<<dist1<<endl;
397 //define the orientation of a new vertex
398 TopAbs_Orientation OO1 = TopAbs_REVERSED;
399 TopAbs_Orientation OO2 = TopAbs_REVERSED;
402 BRepAdaptor_Curve2d PCE1( E1, F );
403 BRepAdaptor_Curve2d PCE2( E2, F );
405 gp_Vec2d V1, V2, V1or, V2or;
406 PCE1.D1( aT1, P2d1, V1 );
407 PCE2.D1( aT2, P2d2, V2 );
408 V1or = V1; V2or = V2;
409 if (E1.Orientation() == TopAbs_REVERSED) V1or.Reverse();
410 if (E2.Orientation() == TopAbs_REVERSED) V2or.Reverse();
411 Standard_Real CrossProd = V2or ^ V1;
413 if (Abs(CrossProd) <= gp::Resolution())
414 cout<<endl<<"CrossProd = "<<CrossProd<<endl;
417 OO1 = TopAbs_FORWARD;
418 CrossProd = V1or ^ V2;
420 OO2 = TopAbs_FORWARD;
422 LV1.Append( aNewVertex.Oriented(OO1) );
423 LV2.Append( aNewVertex.Oriented(OO2) );
427 //----------------------------------
429 //---------------------------------
431 Standard_Real TolConf = Tol;
432 TopoDS_Vertex V1[2],V2[2];
433 TopExp::Vertices(E1,V1[0],V1[1]);
434 TopExp::Vertices(E2,V2[0],V2[1]);
437 for (j = 0; j < 2; j++) {
438 if (V1[j].IsNull()) continue;
439 for (Standard_Integer k = 0; k < 2; k++) {
440 if (V2[k].IsNull()) continue;
441 gp_Pnt P1 = BRep_Tool::Pnt(V1[j]);
442 gp_Pnt P2 = BRep_Tool::Pnt(V2[k]);
443 Standard_Real Dist = P1.Distance(P2);
444 if (Dist < TolConf) {
445 TopoDS_Vertex V = BRepLib_MakeVertex(P1);
446 U1 = (j == 0) ? f[1] : l[1];
447 U2 = (k == 0) ? f[2] : l[2];
448 TopoDS_Shape aLocalShape = V.Oriented(TopAbs_INTERNAL);
449 // Modified by skv - Thu Jan 22 18:16:01 2004 OCC4455 Begin
450 Standard_Real aTol = BRep_Tool::Tolerance(V1[j]);
452 if (!V1[j].IsSame(V2[k])) {
453 Standard_Real aTol2 = BRep_Tool::Tolerance(V2[k]);
455 aTol = Max(aTol, aTol2);
458 B.UpdateVertex(TopoDS::Vertex(aLocalShape),U1,E1,aTol);
459 B.UpdateVertex(TopoDS::Vertex(aLocalShape),U2,E2,aTol);
460 // B.UpdateVertex(TopoDS::Vertex(aLocalShape),U1,E1,Tol);
461 // B.UpdateVertex(TopoDS::Vertex(aLocalShape),U2,E2,Tol);
462 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
464 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
466 // Modified by skv - Thu Jan 22 18:16:01 2004 OCC4455 End
467 LV1.Prepend(V.Oriented(V1[j].Orientation()));
468 LV2.Prepend(V.Oriented(V2[k].Orientation()));
473 Standard_Boolean AffichPurge = Standard_False;
475 if ( !LV1.IsEmpty()) {
476 //----------------------------------
477 // Remove all vertices.
478 // There can be doubles
479 //----------------------------------
480 TopTools_ListIteratorOfListOfShape it1LV1,it1LV2,it2LV1;
482 Standard_Boolean Purge = Standard_True;
486 Purge = Standard_False;
487 for (it1LV1.Initialize(LV1),it1LV2.Initialize(LV2);
488 it1LV1.More(); it1LV1.Next(),it1LV2.Next()) {
490 it2LV1.Initialize(LV1);
492 P1 = BRep_Tool::Pnt(TopoDS::Vertex(it1LV1.Value()));
493 P2 = BRep_Tool::Pnt(TopoDS::Vertex(it2LV1.Value()));
494 // Modified by skv - Thu Jan 22 18:19:04 2004 OCC4455 Begin
495 // if (P1.IsEqual(P2,10*Tol)) {
498 aTol = Max(BRep_Tool::Tolerance(TopoDS::Vertex(it1LV1.Value())),
499 BRep_Tool::Tolerance(TopoDS::Vertex(it2LV1.Value())));
500 if (P1.IsEqual(P2,aTol)) {
501 // Modified by skv - Thu Jan 22 18:19:05 2004 OCC4455 End
504 if (AffichPurge) cout <<"Doubles removed in EdgeInter."<<endl;
505 Purge = Standard_True;
515 //---------------------------------
516 // Vertex storage in DS.
517 //---------------------------------
518 // Modified by skv - Tue Jan 13 15:14:30 2004 Begin
519 Standard_Real TolStore = BRep_Tool::Tolerance(E1) + BRep_Tool::Tolerance(E2);
521 TolStore = Max(TolStore, 10.*Tol);
523 Store (E1,E2,LV1,LV2,AsDes,TolStore);
524 // Store (E1,E2,LV1,LV2,AsDes,10.*Tol);
525 // Store (E1,E2,LV1,LV2,AsDes,Tol);
526 // Modified by skv - Tue Jan 13 15:14:30 2004 End
529 //=======================================================================
530 //function : EdgeInter
532 //=======================================================================
534 static void RefEdgeInter(const TopoDS_Face& F,
535 const TopoDS_Edge& E1,
536 const TopoDS_Edge& E2,
537 const Handle(BRepAlgo_AsDes)& AsDes,
539 Standard_Boolean WithOri,
545 char* name = new char[100];
546 sprintf(name,"E2d_%d_%d",NbF2d,NbE2d++);
548 sprintf(name,"E2d_%d_%d",NbF2d,NbE2d++);
556 Standard_Real f[3],l[3];
557 Standard_Real MilTol2 = 1000*Tol*Tol;
558 Standard_Real TolDub = 1.e-7;
561 //BRep_Tool::Range(E1, f[1], l[1]);
562 //BRep_Tool::Range(E2, f[2], l[2]);
564 BRepAdaptor_Curve CE1(E1,F);
565 BRepAdaptor_Curve CE2(E2,F);
567 TopoDS_Edge EI[3]; EI[1] = E1; EI[2] = E2;
568 TopTools_ListOfShape LV1;
569 TopTools_ListOfShape LV2;
572 BRepLib::BuildCurve3d(E1);
573 BRepLib::BuildCurve3d(E2);
575 Standard_Real TolSum = BRep_Tool::Tolerance(E1) + BRep_Tool::Tolerance(E2);
576 TolSum = Max( TolSum, 1.e-5 );
578 TColgp_SequenceOfPnt ResPoints;
579 TColStd_SequenceOfReal ResParamsOnE1, ResParamsOnE2;
581 Standard_Boolean WithDegen = BRep_Tool::Degenerated(E1) || BRep_Tool::Degenerated(E2);
585 Standard_Integer ideg = (BRep_Tool::Degenerated(E1))? 1 : 2;
586 TopoDS_Iterator iter( EI[ideg] );
589 const TopoDS_Vertex& vdeg = TopoDS::Vertex(iter.Value());
590 DegPoint = BRep_Tool::Pnt(vdeg);
594 BRepAdaptor_Curve CEdeg( EI[ideg], F );
595 DegPoint = CEdeg.Value( CEdeg.FirstParameter() );
598 BRepAdaptor_Surface BAsurf(F);
599 Handle(Geom2d_Curve) pcurve1 = BRep_Tool::CurveOnSurface(E1, F, f[1], l[1]);
600 Handle(Geom2d_Curve) pcurve2 = BRep_Tool::CurveOnSurface(E2, F, f[2], l[2]);
601 Geom2dAdaptor_Curve GAC1(pcurve1, f[1], l[1]);
602 Geom2dAdaptor_Curve GAC2(pcurve2, f[2], l[2]);
603 Geom2dInt_GInter Inter2d( GAC1, GAC2, TolDub, TolDub );
604 for (i = 1; i <= Inter2d.NbPoints(); i++)
611 gp_Pnt2d P2d = Inter2d.Point(i).Value();
612 P3d = BAsurf.Value( P2d.X(), P2d.Y() );
614 ResPoints.Append( P3d );
615 ResParamsOnE1.Append( Inter2d.Point(i).ParamOnFirst() );
616 ResParamsOnE2.Append( Inter2d.Point(i).ParamOnSecond() );
619 for (i = 1; i <= ResPoints.Length(); i++)
621 Standard_Real aT1 = ResParamsOnE1(i); //ponc1.Parameter();
622 Standard_Real aT2 = ResParamsOnE2(i); //ponc2.Parameter();
623 if (Precision::IsInfinite(aT1) || Precision::IsInfinite(aT2))
626 cout << "Inter2d : Solution rejected due to infinite parameter"<<endl;
631 gp_Pnt P = ResPoints(i); //ponc1.Value();
632 TopoDS_Vertex aNewVertex = BRepLib_MakeVertex(P);
633 aNewVertex.Orientation(TopAbs_INTERNAL);
634 B.UpdateVertex( aNewVertex, aT1, E1, Tol );
635 B.UpdateVertex( aNewVertex, aT2, E2, Tol );
636 gp_Pnt P1 = CE1.Value(aT1);
637 gp_Pnt P2 = CE2.Value(aT2);
638 Standard_Real dist1, dist2, dist3;
639 dist1 = P1.Distance(P);
640 dist2 = P2.Distance(P);
641 dist3 = P1.Distance(P2);
642 dist1 = Max( dist1, dist2 );
643 dist1 = Max( dist1, dist3 );
644 B.UpdateVertex( aNewVertex, dist1 );
647 if (aT1 < f[1]-Tol || aT1 > l[1]+Tol)
649 cout << "out of limit"<<endl;
650 cout<<"aT1 = "<<aT1<<", f[1] = "<<f[1]<<", l[1] = "<<l[1]<<endl;
652 if (aT2 < f[2]-Tol || aT2 > l[2]+Tol)
654 cout << "out of limit"<<endl;
655 cout<<"aT2 = "<<aT2<<", f[2] = "<<f[2]<<", l[2] = "<<l[2]<<endl;
657 if (P1.SquareDistance(P) > MilTol2 || P2.SquareDistance(P) > MilTol2 || P1.Distance(P2) > 2.*Tol)
659 cout << "Inter2d : Solution rejected"<<endl;
660 cout<<"P = "<<P.X()<<" "<<P.Y()<<" "<<P.Z()<<endl;
661 cout<<"P1 = "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z()<<endl;
662 cout<<"P2 = "<<P2.X()<<" "<<P2.Y()<<" "<<P2.Z()<<endl;
663 cout<<"MaxDist = "<<dist1<<endl;
666 //define the orientation of a new vertex
667 TopAbs_Orientation OO1 = TopAbs_REVERSED;
668 TopAbs_Orientation OO2 = TopAbs_REVERSED;
671 BRepAdaptor_Curve2d PCE1( E1, F );
672 BRepAdaptor_Curve2d PCE2( E2, F );
674 gp_Vec2d V1, V2, V1or, V2or;
675 PCE1.D1( aT1, P2d1, V1 );
676 PCE2.D1( aT2, P2d2, V2 );
677 V1or = V1; V2or = V2;
678 if (E1.Orientation() == TopAbs_REVERSED) V1or.Reverse();
679 if (E2.Orientation() == TopAbs_REVERSED) V2or.Reverse();
680 Standard_Real CrossProd = V2or ^ V1;
682 if (Abs(CrossProd) <= gp::Resolution())
683 cout<<endl<<"CrossProd = "<<CrossProd<<endl;
686 OO1 = TopAbs_FORWARD;
687 CrossProd = V1or ^ V2;
689 OO2 = TopAbs_FORWARD;
691 LV1.Append( aNewVertex.Oriented(OO1) );
692 LV2.Append( aNewVertex.Oriented(OO2) );
695 //----------------------------------
697 //---------------------------------
699 Standard_Real TolConf = Tol;
700 TopoDS_Vertex V1[2],V2[2];
701 TopExp::Vertices(E1,V1[0],V1[1]);
702 TopExp::Vertices(E2,V2[0],V2[1]);
705 for (j = 0; j < 2; j++) {
706 if (V1[j].IsNull()) continue;
707 for (Standard_Integer k = 0; k < 2; k++) {
708 if (V2[k].IsNull()) continue;
709 gp_Pnt P1 = BRep_Tool::Pnt(V1[j]);
710 gp_Pnt P2 = BRep_Tool::Pnt(V2[k]);
711 Standard_Real Dist = P1.Distance(P2);
712 if (Dist < TolConf) {
713 TopoDS_Vertex V = BRepLib_MakeVertex(P1);
714 U1 = (j == 0) ? f[1] : l[1];
715 U2 = (k == 0) ? f[2] : l[2];
716 TopoDS_Shape aLocalShape = V.Oriented(TopAbs_INTERNAL);
717 B.UpdateVertex(TopoDS::Vertex(aLocalShape),U1,E1,Tol);
718 B.UpdateVertex(TopoDS::Vertex(aLocalShape),U2,E2,Tol);
719 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
721 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
723 LV1.Prepend(V.Oriented(V1[j].Orientation()));
724 LV2.Prepend(V.Oriented(V2[k].Orientation()));
729 Standard_Boolean AffichPurge = Standard_False;
731 if ( !LV1.IsEmpty()) {
732 //----------------------------------
733 // Remove all vertices.
734 // there can be doubles
735 //----------------------------------
736 TopTools_ListIteratorOfListOfShape it1LV1,it1LV2,it2LV1;
738 Standard_Boolean Purge = Standard_True;
742 Purge = Standard_False;
743 for (it1LV1.Initialize(LV1),it1LV2.Initialize(LV2);
744 it1LV1.More(); it1LV1.Next(),it1LV2.Next()) {
746 it2LV1.Initialize(LV1);
748 P1 = BRep_Tool::Pnt(TopoDS::Vertex(it1LV1.Value()));
749 P2 = BRep_Tool::Pnt(TopoDS::Vertex(it2LV1.Value()));
750 if (P1.IsEqual(P2,10*Tol)) {
753 if (AffichPurge) cout <<"Doubles removed in EdgeInter."<<endl;
754 Purge = Standard_True;
764 //---------------------------------
765 // Vertex storage in SD.
766 //---------------------------------
767 ////-----------------------------------------------------
768 if(LV1.Extent() > 1) {
769 //cout << "IFV - RefEdgeInter: remove vertex" << endl;
770 Standard_Real dmin = RealLast();
772 for (it1LV1.Initialize(LV1); it1LV1.More(); it1LV1.Next()) {
773 gp_Pnt P = BRep_Tool::Pnt(TopoDS::Vertex(it1LV1.Value()));
774 Standard_Real d = P.SquareDistance(Pref);
777 Vmin = TopoDS::Vertex(it1LV1.Value());
780 for (it1LV1.Initialize(LV1),it1LV2.Initialize(LV2);
781 it1LV1.More(); it1LV1.Next(),it1LV2.Next()) {
782 if(!Vmin.IsSame(it1LV1.Value())) {
785 if(!it1LV1.More()) break;
790 ////-----------------------------------------------------
792 // Modified by skv - Tue Jan 13 15:14:30 2004 Begin
793 Standard_Real TolStore = BRep_Tool::Tolerance(E1) + BRep_Tool::Tolerance(E2);
795 TolStore = Max(TolStore, 10.*Tol);
797 Store (E1,E2,LV1,LV2,AsDes,TolStore);
798 // Store (E1,E2,LV1,LV2,AsDes,10.*Tol);
799 // Store (E1,E2,LV1,LV2,AsDes,Tol);
800 // Modified by skv - Tue Jan 13 15:14:30 2004 End
805 //======================================================================
806 //function : EvaluateMaxSegment
807 //purpose : return MaxSegment to pass in approximation
808 //======================================================================
810 static Standard_Integer evaluateMaxSegment(const Adaptor3d_CurveOnSurface& aCurveOnSurface)
812 Handle(Adaptor3d_HSurface) aSurf = aCurveOnSurface.GetSurface();
813 Handle(Adaptor2d_HCurve2d) aCurv2d = aCurveOnSurface.GetCurve();
815 Standard_Real aNbSKnots = 0, aNbC2dKnots = 0;
817 if (aSurf->GetType() == GeomAbs_BSplineSurface) {
818 Handle(Geom_BSplineSurface) aBSpline = aSurf->BSpline();
819 aNbSKnots = Max(aBSpline->NbUKnots(), aBSpline->NbVKnots());
821 if (aCurv2d->GetType() == GeomAbs_BSplineCurve) {
822 aNbC2dKnots = aCurv2d->NbKnots();
824 Standard_Integer aReturn = (Standard_Integer) ( 30 + Max(aNbSKnots, aNbC2dKnots) ) ;
829 //=======================================================================
830 //function : ExtendPCurve
832 //=======================================================================
834 static Standard_Boolean ExtendPCurve(const Handle(Geom2d_Curve)& aPCurve,
835 const Standard_Real anEf,
836 const Standard_Real anEl,
837 const Standard_Real a2Offset,
838 Handle(Geom2d_Curve)& NewPCurve)
841 if (NewPCurve->IsInstance(STANDARD_TYPE(Geom2d_TrimmedCurve)))
842 NewPCurve = (*((Handle(Geom2d_TrimmedCurve)*)&NewPCurve))->BasisCurve();
844 Standard_Real FirstPar = NewPCurve->FirstParameter();
845 Standard_Real LastPar = NewPCurve->LastParameter();
847 if (NewPCurve->IsKind(STANDARD_TYPE(Geom2d_BoundedCurve)) &&
848 (FirstPar > anEf - a2Offset || LastPar < anEl + a2Offset))
850 if (NewPCurve->IsInstance(STANDARD_TYPE(Geom2d_BezierCurve)))
852 Handle(Geom2d_BezierCurve) aBezier = *((Handle(Geom2d_BezierCurve)*)&NewPCurve);
853 if (aBezier->NbPoles() == 2)
855 TColgp_Array1OfPnt2d thePoles(1,2);
856 aBezier->Poles(thePoles);
857 gp_Vec2d aVec(thePoles(1), thePoles(2));
858 NewPCurve = new Geom2d_Line(thePoles(1), aVec);
859 return Standard_True;
862 else if (NewPCurve->IsInstance(STANDARD_TYPE(Geom2d_BSplineCurve)))
864 Handle(Geom2d_BSplineCurve) aBSpline = *((Handle(Geom2d_BSplineCurve)*)&NewPCurve);
865 if (aBSpline->NbKnots() == 2 && aBSpline->NbPoles() == 2)
867 TColgp_Array1OfPnt2d thePoles(1,2);
868 aBSpline->Poles(thePoles);
869 gp_Vec2d aVec(thePoles(1), thePoles(2));
870 NewPCurve = new Geom2d_Line(thePoles(1), aVec);
871 return Standard_True;
876 FirstPar = aPCurve->FirstParameter();
877 LastPar = aPCurve->LastParameter();
878 Handle(Geom2d_TrimmedCurve) aTrCurve =
879 new Geom2d_TrimmedCurve(aPCurve, FirstPar, LastPar);
881 // The curve is not prolonged on begin or end.
882 // Trying to prolong it adding a segment to its bound.
887 Handle(Geom2d_Line) aLin;
888 Handle(Geom2d_TrimmedCurve) aSegment;
889 Geom2dConvert_CompCurveToBSplineCurve aCompCurve(aTrCurve, Convert_RationalC1);
890 Standard_Real aTol = Precision::Confusion();
891 Standard_Real aDelta = Max(a2Offset, 1.);
893 if (FirstPar > anEf - a2Offset) {
894 aPCurve->D1(FirstPar, aPBnd, aVBnd);
895 aDBnd.SetXY(aVBnd.XY());
896 aPBeg = aPBnd.Translated(gp_Vec2d(-aDelta*aDBnd.XY()));
897 aLin = new Geom2d_Line(aPBeg, aDBnd);
898 aSegment = new Geom2d_TrimmedCurve(aLin, 0, aDelta);
900 if (!aCompCurve.Add(aSegment, aTol))
901 return Standard_False;
904 if (LastPar < anEl + a2Offset) {
905 aPCurve->D1(LastPar, aPBeg, aVBnd);
906 aDBnd.SetXY(aVBnd.XY());
907 aLin = new Geom2d_Line(aPBeg, aDBnd);
908 aSegment = new Geom2d_TrimmedCurve(aLin, 0, aDelta);
910 if (!aCompCurve.Add(aSegment, aTol))
911 return Standard_False;
914 NewPCurve = aCompCurve.BSplineCurve();
915 return Standard_True;
918 //=======================================================================
919 //function : ExtentEdge
921 //=======================================================================
923 // Modified by skv - Fri Dec 26 17:00:55 2003 OCC4455 Begin
924 //static void ExtentEdge(const TopoDS_Edge& E,TopoDS_Edge& NE)
925 static void ExtentEdge(const TopoDS_Edge& E,TopoDS_Edge& NE, const Standard_Real theOffset)
927 //BRepLib::BuildCurve3d(E);
929 TopoDS_Shape aLocalShape = E.EmptyCopied();
932 Standard_Real a2Offset = 2.*Abs(theOffset);
934 Standard_Integer i, j;
936 BRep_Tool::Range(E, anEf, anEl);
937 NE = TopoDS::Edge(aLocalShape);
938 // NE = TopoDS::Edge(E.EmptyCopied());
939 // Enough for analytic edges, for general case reconstruct the
940 // geometry of the edge recalculating the intersection of surfaces.
942 //BRepLib::BuildCurve3d(E);
944 Standard_Integer NbPCurves = 0;
945 Standard_Real FirstParOnPC = RealFirst(), LastParOnPC = RealLast();
946 Handle(Geom2d_Curve) MinPC;
947 Handle(Geom_Surface) MinSurf;
948 TopLoc_Location MinLoc;
950 BRep_ListIteratorOfListOfCurveRepresentation itr( (Handle(BRep_TEdge)::DownCast(NE.TShape()))->ChangeCurves() );
951 for (; itr.More(); itr.Next())
953 Handle( BRep_CurveRepresentation ) CurveRep = itr.Value();
954 Standard_Real FirstPar, LastPar;
955 if (CurveRep->IsCurveOnSurface())
958 Handle(Geom2d_Curve) theCurve = CurveRep->PCurve();
959 FirstPar = theCurve->FirstParameter();
960 LastPar = theCurve->LastParameter();
962 if (theCurve->IsKind(STANDARD_TYPE(Geom2d_BoundedCurve)) &&
963 (FirstPar > anEf - a2Offset || LastPar < anEl + a2Offset))
965 Handle(Geom2d_Curve) NewPCurve;
966 if (ExtendPCurve(theCurve, anEf, anEl, a2Offset, NewPCurve))
968 CurveRep->PCurve(NewPCurve);
969 FirstPar = NewPCurve->FirstParameter();
970 LastPar = NewPCurve->LastParameter();
971 if (CurveRep->IsCurveOnClosedSurface())
973 Handle(Geom2d_Curve) PCurve2 = CurveRep->PCurve2();
974 if (ExtendPCurve(PCurve2, anEf, anEl, a2Offset, NewPCurve))
975 CurveRep->PCurve2(NewPCurve);
979 else if (theCurve->IsPeriodic())
981 Standard_Real delta = (theCurve->Period() - (anEl - anEf))*0.5;
983 FirstPar = anEf - delta;
984 LastPar = anEl + delta;
986 else if (theCurve->IsClosed())
987 LastPar -= 0.05*(LastPar - FirstPar);
989 //check FirstPar and LastPar: the pcurve should be in its surface
990 theCurve = CurveRep->PCurve();
991 Handle(Geom_Surface) theSurf = CurveRep->Surface();
992 Standard_Real Umin, Umax, Vmin, Vmax;
993 theSurf->Bounds(Umin, Umax, Vmin, Vmax);
994 TColGeom2d_SequenceOfCurve BoundLines;
995 if (!Precision::IsInfinite(Vmin))
997 Handle(Geom2d_Line) aLine = new Geom2d_Line(gp_Pnt2d( 0., Vmin ),
999 BoundLines.Append(aLine);
1001 if (!Precision::IsInfinite(Umin))
1003 Handle(Geom2d_Line) aLine = new Geom2d_Line(gp_Pnt2d( Umin, 0. ),
1004 gp_Dir2d( 0., 1. ));
1005 BoundLines.Append(aLine);
1007 if (!Precision::IsInfinite(Vmax))
1009 Handle(Geom2d_Line) aLine = new Geom2d_Line(gp_Pnt2d( 0., Vmax ),
1010 gp_Dir2d( 1., 0. ));
1011 BoundLines.Append(aLine);
1013 if (!Precision::IsInfinite(Umax))
1015 Handle(Geom2d_Line) aLine = new Geom2d_Line(gp_Pnt2d( Umax, 0. ),
1016 gp_Dir2d( 0., 1. ));
1017 BoundLines.Append(aLine);
1020 TColStd_SequenceOfReal params;
1021 Geom2dInt_GInter IntCC;
1022 Geom2dAdaptor_Curve GAcurve(theCurve);
1023 for (i = 1; i <= BoundLines.Length(); i++)
1025 Geom2dAdaptor_Curve GAline( BoundLines(i) );
1026 IntCC.Perform( GAcurve, GAline, Precision::PConfusion(), Precision::PConfusion());
1029 for (j = 1; j <= IntCC.NbPoints(); j++)
1031 const IntRes2d_IntersectionPoint& ip = IntCC.Point(j);
1032 gp_Pnt2d aPoint = ip.Value();
1033 if (aPoint.X() >= Umin && aPoint.X() <= Umax &&
1034 aPoint.Y() >= Vmin && aPoint.Y() <= Vmax)
1035 params.Append( ip.ParamOnFirst() );
1037 for (j = 1; j <= IntCC.NbSegments(); j++)
1039 const IntRes2d_IntersectionSegment& is = IntCC.Segment(j);
1040 if (is.HasFirstPoint())
1042 const IntRes2d_IntersectionPoint& ip = is.FirstPoint();
1043 gp_Pnt2d aPoint = ip.Value();
1044 if (aPoint.X() >= Umin && aPoint.X() <= Umax &&
1045 aPoint.Y() >= Vmin && aPoint.Y() <= Vmax)
1046 params.Append( ip.ParamOnFirst() );
1048 if (is.HasLastPoint())
1050 const IntRes2d_IntersectionPoint& ip = is.LastPoint();
1051 gp_Pnt2d aPoint = ip.Value();
1052 if (aPoint.X() >= Umin && aPoint.X() <= Umax &&
1053 aPoint.Y() >= Vmin && aPoint.Y() <= Vmax)
1054 params.Append( ip.ParamOnFirst() );
1059 if (!params.IsEmpty())
1061 if (params.Length() == 1)
1063 gp_Pnt2d PntFirst = theCurve->Value(FirstPar);
1064 if (PntFirst.X() >= Umin && PntFirst.X() <= Umax &&
1065 PntFirst.Y() >= Vmin && PntFirst.Y() <= Vmax)
1067 if (LastPar > params(1))
1068 LastPar = params(1);
1070 else if (FirstPar < params(1))
1071 FirstPar = params(1);
1075 Standard_Real fpar = RealLast(), lpar = RealFirst();
1076 for (i = 1; i <= params.Length(); i++)
1078 if (params(i) < fpar)
1080 if (params(i) > lpar)
1083 if (FirstPar < fpar)
1089 //// end of check ////
1090 (Handle(BRep_GCurve)::DownCast(CurveRep))->SetRange( FirstPar, LastPar );
1091 //gp_Pnt2d Pfirst = theCurve->Value(FirstPar);
1092 //gp_Pnt2d Plast = theCurve->Value(LastPar);
1093 //(Handle(BRep_CurveOnSurface)::DownCast(CurveRep))->SetUVPoints( Pfirst, Plast );
1095 //update FirstParOnPC and LastParOnPC
1096 if (FirstPar > FirstParOnPC)
1098 FirstParOnPC = FirstPar;
1101 MinLoc = CurveRep->Location();
1103 if (LastPar < LastParOnPC)
1105 LastParOnPC = LastPar;
1108 MinLoc = CurveRep->Location();
1114 Handle(Geom_Curve) C3d = BRep_Tool::Curve( NE, f, l );
1117 MinLoc = E.Location() * MinLoc;
1120 Standard_Real FirstPar = C3d->FirstParameter();
1121 Standard_Real LastPar = C3d->LastParameter();
1122 if (MinPC->IsClosed())
1127 else if (C3d->IsPeriodic())
1129 Standard_Real delta = (C3d->Period() - (l - f))*0.5;
1134 else if (C3d->IsClosed())
1140 GeomAPI_ProjectPointOnCurve Projector;
1141 if (!Precision::IsInfinite(FirstParOnPC))
1143 gp_Pnt2d P2d1 = MinPC->Value(FirstParOnPC);
1144 gp_Pnt P1 = MinSurf->Value( P2d1.X(), P2d1.Y() );
1145 P1.Transform(MinLoc.Transformation());
1146 Projector.Init( P1, C3d );
1147 if (Projector.NbPoints() > 0)
1148 f = Projector.LowerDistanceParameter();
1151 cout<<"ProjectPointOnCurve not done"<<endl;
1154 if (!Precision::IsInfinite(LastParOnPC))
1156 gp_Pnt2d P2d2 = MinPC->Value(LastParOnPC);
1157 gp_Pnt P2 = MinSurf->Value( P2d2.X(), P2d2.Y() );
1158 P2.Transform(MinLoc.Transformation());
1159 Projector.Init( P2, C3d );
1160 if (Projector.NbPoints() > 0)
1161 l = Projector.LowerDistanceParameter();
1164 cout<<"ProjectPointOnCurve not done"<<endl;
1168 BB.Range( NE, f, l );
1169 if (!Precision::IsInfinite(f) && !Precision::IsInfinite(l))
1170 BRepLib::SameParameter( NE, Precision::Confusion(), Standard_True );
1172 else if (!BRep_Tool::Degenerated(E)) //no 3d curve
1174 MinSurf = Handle(Geom_Surface)::DownCast
1175 (MinSurf->Transformed(MinLoc.Transformation()));
1176 Standard_Real max_deviation = 0.;
1177 if (Precision::IsInfinite(FirstParOnPC) || Precision::IsInfinite(LastParOnPC))
1179 if (MinPC->IsInstance(STANDARD_TYPE(Geom2d_Line)))
1181 Standard_Boolean IsLine = Standard_False;
1182 if (MinSurf->IsInstance(STANDARD_TYPE(Geom_Plane)))
1183 IsLine = Standard_True;
1184 else if (MinSurf->IsInstance(STANDARD_TYPE(Geom_CylindricalSurface)) ||
1185 MinSurf->IsInstance(STANDARD_TYPE(Geom_ConicalSurface)))
1187 Handle(Geom2d_Line) theLine = *((Handle(Geom2d_Line)*)&MinPC);
1188 gp_Dir2d LineDir = theLine->Direction();
1189 if (LineDir.IsParallel( gp::DY2d(), Precision::Angular() ))
1190 IsLine = Standard_True;
1194 gp_Pnt2d P2d1 = MinPC->Value(0.), P2d2 = MinPC->Value(1.);
1195 gp_Pnt P1 = MinSurf->Value(P2d1.X(), P2d1.Y());
1196 gp_Pnt P2 = MinSurf->Value(P2d2.X(), P2d2.Y());
1197 gp_Vec aVec(P1, P2);
1198 C3d = new Geom_Line( P1, aVec );
1204 Geom2dAdaptor_Curve AC2d( MinPC, FirstParOnPC, LastParOnPC );
1205 GeomAdaptor_Surface GAsurf( MinSurf );
1206 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( AC2d );
1207 Handle(GeomAdaptor_HSurface) HSurf = new GeomAdaptor_HSurface( GAsurf );
1208 Adaptor3d_CurveOnSurface ConS( HC2d, HSurf );
1209 Standard_Real /*max_deviation,*/ average_deviation;
1210 GeomAbs_Shape Continuity = GeomAbs_C1;
1211 Standard_Integer MaxDegree = 14;
1212 Standard_Integer MaxSegment = evaluateMaxSegment(ConS);
1213 GeomLib::BuildCurve3d(Precision::Confusion(),
1214 ConS, FirstParOnPC, LastParOnPC,
1215 C3d, max_deviation, average_deviation,
1216 Continuity, MaxDegree, MaxSegment);
1218 BB.UpdateEdge( NE, C3d, max_deviation );
1219 //BB.Range( NE, FirstParOnPC, LastParOnPC );
1220 Standard_Boolean ProjectionSuccess = Standard_True;
1222 //BRepLib::SameParameter( NE, Precision::Confusion(), Standard_True );
1223 for (itr.Initialize((Handle(BRep_TEdge)::DownCast(NE.TShape()))->ChangeCurves());
1227 Handle( BRep_CurveRepresentation ) CurveRep = itr.Value();
1228 Standard_Real FirstPar, LastPar;
1229 if (CurveRep->IsCurveOnSurface())
1231 Handle(Geom2d_Curve) theCurve = CurveRep->PCurve();
1232 Handle(Geom_Surface) theSurf = CurveRep->Surface();
1233 TopLoc_Location theLoc = CurveRep->Location();
1234 if (theCurve == MinPC && theSurf == MinSurf && theLoc == MinLoc)
1236 FirstPar = (Handle(BRep_GCurve)::DownCast(CurveRep))->First();
1237 LastPar = (Handle(BRep_GCurve)::DownCast(CurveRep))->Last();
1238 if (Abs(FirstPar - FirstParOnPC) > Precision::PConfusion() ||
1239 Abs(LastPar - LastParOnPC) > Precision::PConfusion())
1241 theLoc = E.Location() * theLoc;
1242 theSurf = Handle(Geom_Surface)::DownCast
1243 (theSurf->Transformed(theLoc.Transformation()));
1245 if (theCurve->IsInstance(STANDARD_TYPE(Geom2d_Line)) &&
1246 theSurf->IsKind(STANDARD_TYPE(Geom_BoundedSurface)))
1248 gp_Dir2d theDir = (*((Handle(Geom2d_Line)*)&theCurve))->Direction();
1249 if (theDir.IsParallel(gp::DX2d(), Precision::Angular()) ||
1250 theDir.IsParallel(gp::DY2d(), Precision::Angular()))
1252 Standard_Real U1, U2, V1, V2;
1253 theSurf->Bounds(U1, U2, V1, V2);
1254 gp_Pnt2d Origin = (*((Handle(Geom2d_Line)*)&theCurve))->Location();
1255 if (Abs(Origin.X()-U1) <= Precision::Confusion() ||
1256 Abs(Origin.X()-U2) <= Precision::Confusion() ||
1257 Abs(Origin.Y()-V1) <= Precision::Confusion() ||
1258 Abs(Origin.Y()-V2) <= Precision::Confusion())
1260 BRepLib::SameParameter( NE, Precision::Confusion(), Standard_True );
1266 Handle(Geom2d_Curve) ProjPCurve =
1267 GeomProjLib::Curve2d( C3d, FirstParOnPC, LastParOnPC, theSurf );
1268 if (ProjPCurve.IsNull())
1269 ProjectionSuccess = Standard_False;
1271 CurveRep->PCurve( ProjPCurve );
1275 if (ProjectionSuccess)
1276 BB.Range( NE, FirstParOnPC, LastParOnPC );
1279 BB.Range( NE, FirstParOnPC, LastParOnPC, Standard_True );
1280 BRepLib::SameParameter( NE, Precision::Confusion(), Standard_True );
1286 Standard_Real FirstPar = C3d->FirstParameter();
1287 Standard_Real LastPar = C3d->LastParameter();
1289 if (C3d->IsKind(STANDARD_TYPE(Geom_BoundedCurve)) &&
1290 (FirstPar > anEf - a2Offset || LastPar < anEl + a2Offset))
1292 Handle(Geom_TrimmedCurve) aTrCurve =
1293 new Geom_TrimmedCurve(C3d, FirstPar, LastPar);
1295 // The curve is not prolonged on begin or end.
1296 // Trying to prolong it adding a segment to its bound.
1301 Handle(Geom_Line) aLin;
1302 Handle(Geom_TrimmedCurve) aSegment;
1303 GeomConvert_CompCurveToBSplineCurve aCompCurve(aTrCurve, Convert_RationalC1);
1304 Standard_Real aTol = Precision::Confusion();
1305 Standard_Real aDelta = Max(a2Offset, 1.);
1307 if (FirstPar > anEf - a2Offset) {
1308 C3d->D1(FirstPar, aPBnd, aVBnd);
1309 aDBnd.SetXYZ(aVBnd.XYZ());
1310 aPBeg = aPBnd.Translated(gp_Vec(-aDelta*aDBnd.XYZ()));
1311 aLin = new Geom_Line(aPBeg, aDBnd);
1312 aSegment = new Geom_TrimmedCurve(aLin, 0, aDelta);
1314 if (!aCompCurve.Add(aSegment, aTol))
1318 if (LastPar < anEl + a2Offset) {
1319 C3d->D1(LastPar, aPBeg, aVBnd);
1320 aDBnd.SetXYZ(aVBnd.XYZ());
1321 aLin = new Geom_Line(aPBeg, aDBnd);
1322 aSegment = new Geom_TrimmedCurve(aLin, 0, aDelta);
1324 if (!aCompCurve.Add(aSegment, aTol))
1328 C3d = aCompCurve.BSplineCurve();
1329 FirstPar = C3d->FirstParameter();
1330 LastPar = C3d->LastParameter();
1331 BB.UpdateEdge(NE, C3d, Precision::Confusion());
1333 else if (C3d->IsPeriodic())
1335 Standard_Real delta = (C3d->Period() - (anEl - anEf))*0.5;
1337 FirstPar = anEf - delta;
1338 LastPar = anEl + delta;
1340 else if (C3d->IsClosed())
1341 LastPar -= 0.05*(LastPar - FirstPar);
1343 BB.Range( NE, FirstPar, LastPar );
1346 // Modified by skv - Fri Dec 26 17:00:57 2003 OCC4455 End
1349 //=======================================================================
1350 //function : UpdateVertex
1352 //=======================================================================
1354 static Standard_Boolean UpdateVertex(TopoDS_Vertex V,
1357 Standard_Real TolConf)
1359 BRepAdaptor_Curve OC(OE);
1360 BRepAdaptor_Curve NC(NE);
1361 Standard_Real Of = OC.FirstParameter(); Standard_Real Ol = OC.LastParameter();
1362 Standard_Real Nf = NC.FirstParameter(); Standard_Real Nl = NC.LastParameter();
1364 Standard_Real U = 0.;
1368 Standard_Real ParTol = Precision::PConfusion();
1369 gp_Pnt P = BRep_Tool::Pnt(V);
1370 Standard_Boolean OK = Standard_False;
1372 if (P.Distance(OC.Value(Of)) < TolConf) {
1373 if (Of >= Nf + ParTol && Of <= Nl + ParTol && P.Distance(NC.Value(Of)) < TolConf) {
1378 if (P.Distance(OC.Value(Ol)) < TolConf) {
1379 if (Ol >= Nf + ParTol && Ol <= Nl + ParTol && P.Distance(NC.Value(Ol)) < TolConf) {
1386 TopoDS_Shape aLocalShape = NE.Oriented(TopAbs_FORWARD);
1387 TopoDS_Edge EE = TopoDS::Edge(aLocalShape);
1388 // TopoDS_Edge EE = TopoDS::Edge(NE.Oriented(TopAbs_FORWARD));
1389 aLocalShape = V.Oriented(TopAbs_INTERNAL);
1390 B.UpdateVertex(TopoDS::Vertex(aLocalShape),
1391 U,NE,BRep_Tool::Tolerance(NE));
1392 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
1393 // U,NE,BRep_Tool::Tolerance(NE));
1398 //=======================================================================
1399 //function : Compute
1401 //=======================================================================
1403 void BRepOffset_Inter2d::Compute (const Handle(BRepAlgo_AsDes)& AsDes,
1404 const TopoDS_Face& F,
1405 const TopTools_IndexedMapOfShape& NewEdges,
1406 const Standard_Real Tol)
1413 //Do not intersect the edges of face
1414 TopTools_MapOfShape EdgesOfFace;
1415 TopExp_Explorer Explo( F, TopAbs_EDGE );
1416 for (; Explo.More(); Explo.Next())
1417 EdgesOfFace.Add( Explo.Current() );
1419 //-----------------------------------------------------------
1420 // calculate intersections2d on faces touched by
1422 //---------------------------------------------------------
1423 TopTools_ListIteratorOfListOfShape it1LE ;
1424 TopTools_ListIteratorOfListOfShape it2LE ;
1426 //-----------------------------------------------
1427 // Intersection of edges 2*2.
1428 //-----------------------------------------------
1429 const TopTools_ListOfShape& LE = AsDes->Descendant(F);
1430 TopoDS_Vertex V1,V2;
1431 Standard_Integer j, i = 1;
1433 for ( it1LE.Initialize(LE) ; it1LE.More(); it1LE.Next()) {
1434 const TopoDS_Edge& E1 = TopoDS::Edge(it1LE.Value());
1436 it2LE.Initialize(LE);
1438 while (j < i && it2LE.More()) {
1439 const TopoDS_Edge& E2 = TopoDS::Edge(it2LE.Value());
1440 //--------------------------------------------------------------
1441 // Intersections of New edges obtained by intersection
1442 // between them and with edges of restrictions
1443 //------------------------------------------------------
1444 if ( (!EdgesOfFace.Contains(E1) || !EdgesOfFace.Contains(E2)) &&
1445 (NewEdges.Contains(E1) || NewEdges.Contains(E2)) ) {
1446 TopoDS_Shape aLocalShape = F.Oriented(TopAbs_FORWARD);
1447 EdgeInter(TopoDS::Face(aLocalShape),E1,E2,AsDes,Tol,Standard_True);
1448 // EdgeInter(TopoDS::Face(F.Oriented(TopAbs_FORWARD)),E1,E2,AsDes,Tol,Standard_True);
1457 //=======================================================================
1458 //function : ConnexIntByInt
1460 //=======================================================================
1462 // Modified by skv - Fri Dec 26 16:53:16 2003 OCC4455 Begin
1463 // Add another parameter: offset value.
1464 void BRepOffset_Inter2d::ConnexIntByInt
1465 (const TopoDS_Face& FI,
1466 BRepOffset_Offset& OFI,
1467 TopTools_DataMapOfShapeShape& MES,
1468 const TopTools_DataMapOfShapeShape& Build,
1469 const Handle(BRepAlgo_AsDes)& AsDes,
1470 const Standard_Real Offset,
1471 const Standard_Real Tol)
1472 // Modified by skv - Fri Dec 26 16:53:18 2003 OCC4455 End
1475 TopTools_DataMapOfShapeListOfShape MVE;
1476 BRepOffset_Tool::MapVertexEdges(FI,MVE);
1478 //---------------------
1479 // Extension of edges.
1480 //---------------------
1482 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape it(MVE);
1483 for ( ; it.More(); it.Next()) {
1484 const TopTools_ListOfShape& L = it.Value();
1485 Standard_Boolean YaBuild = 0;
1486 TopTools_ListIteratorOfListOfShape itL(L);
1487 for (; itL.More(); itL.Next()) {
1488 YaBuild = Build.IsBound(itL.Value());
1492 for (itL.Initialize(L); itL.More(); itL.Next()) {
1493 const TopoDS_Edge& EI = TopoDS::Edge(itL.Value());
1494 TopoDS_Shape aLocalShape = OFI.Generated(EI);
1495 const TopoDS_Edge& OE = TopoDS::Edge(aLocalShape);
1496 // const TopoDS_Edge& OE = TopoDS::Edge(OFI.Generated(EI));
1497 if (!MES.IsBound(OE) && !Build.IsBound(EI)) {
1498 // Modified by skv - Fri Dec 26 16:59:52 2003 OCC4455 Begin
1499 // ExtentEdge(OE,NE);
1500 ExtentEdge(OE,NE, Offset);
1501 // Modified by skv - Fri Dec 26 16:59:54 2003 OCC4455 End
1508 TopoDS_Face FIO = TopoDS::Face(OFI.Face());
1509 if (MES.IsBound(FIO)) FIO = TopoDS::Face(MES(FIO));
1511 TopExp_Explorer exp(FI.Oriented(TopAbs_FORWARD),TopAbs_WIRE);
1512 for (; exp.More(); exp.Next()) {
1513 const TopoDS_Wire& W = TopoDS::Wire(exp.Current());
1514 BRepTools_WireExplorer wexp;
1515 Standard_Boolean end = Standard_False ;
1516 TopoDS_Edge FirstE,CurE,NextE;
1518 TopoDS_Shape aLocalWire = W .Oriented(TopAbs_FORWARD);
1519 TopoDS_Shape aLocalFace = FI.Oriented(TopAbs_FORWARD);
1520 wexp.Init(TopoDS::Wire(aLocalWire),TopoDS::Face(aLocalFace));
1521 // wexp.Init(TopoDS::Wire(W .Oriented(TopAbs_FORWARD)),
1522 // TopoDS::Face(FI.Oriented(TopAbs_FORWARD)));
1523 CurE = FirstE = wexp.Current();
1527 NextE = wexp.Current();
1530 NextE = FirstE; end = Standard_True;
1532 if (CurE.IsSame(NextE)) continue;
1535 TopoDS_Vertex Vref = CommonVertex(CurE, NextE);
1536 gp_Pnt Pref = BRep_Tool::Pnt(Vref);
1539 TopoDS_Shape aLocalShape = OFI.Generated(CurE);
1540 TopoDS_Edge CEO = TopoDS::Edge(aLocalShape);
1541 aLocalShape = OFI.Generated(NextE);
1542 TopoDS_Edge NEO = TopoDS::Edge(aLocalShape);
1543 // TopoDS_Edge CEO = TopoDS::Edge(OFI.Generated(CurE));
1544 // TopoDS_Edge NEO = TopoDS::Edge(OFI.Generated(NextE));
1545 //------------------------------------------
1546 // Inter processing of images of CurE NextE.
1547 //------------------------------------------
1548 TopTools_ListOfShape LV1,LV2;
1549 Standard_Boolean DoInter = 1;
1550 TopoDS_Shape NE1,NE2;
1552 if (Build.IsBound(CurE) && Build.IsBound(NextE)) {
1556 else if (Build.IsBound(CurE) && MES.IsBound(NEO)) {
1560 else if (Build.IsBound(NextE) && MES.IsBound(CEO)) {
1568 //------------------------------------
1569 // NE1,NE2 can be a compound of Edges.
1570 //------------------------------------
1571 TopExp_Explorer Exp1,Exp2;
1572 for (Exp1.Init(NE1,TopAbs_EDGE) ; Exp1.More(); Exp1.Next()) {
1573 for (Exp2.Init(NE2,TopAbs_EDGE) ; Exp2.More(); Exp2.Next()) {
1574 RefEdgeInter(FIO,TopoDS::Edge(Exp1.Current()),TopoDS::Edge(Exp2.Current()),
1575 AsDes,Tol,Standard_True/*Standard_False*/, Pref);
1580 if (MES.IsBound(CEO)) {
1581 TopoDS_Vertex V = CommonVertex(CEO,NEO);
1582 UpdateVertex (V,CEO,TopoDS::Edge(MES(CEO)),Tol);
1583 AsDes->Add (MES(CEO),V);
1585 else if (MES.IsBound(NEO)) {
1586 TopoDS_Vertex V = CommonVertex(CEO,NEO);
1587 UpdateVertex (V,NEO,TopoDS::Edge(MES(NEO)),Tol);
1588 AsDes->Add (MES(NEO),V);