1 // Created on: 1993-08-25
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272
25 #include <GeomAbs_SurfaceType.hxx>
26 #include <Standard_NoSuchObject.hxx>
27 #include <Standard_NotImplemented.hxx>
28 #include <ProjLib_ProjectedCurve.hxx>
29 #include <ProjLib_CompProjectedCurve.hxx>
30 #include <ProjLib_HCompProjectedCurve.hxx>
31 #include <ProjLib_ComputeApproxOnPolarSurface.hxx>
32 #include <ProjLib_ComputeApprox.hxx>
33 #include <ProjLib_Projector.hxx>
34 #include <Handle_Adaptor3d_HCurve.hxx>
35 #include <Handle_Adaptor3d_HSurface.hxx>
36 #include <Adaptor3d_HCurve.hxx>
37 #include <Adaptor3d_HSurface.hxx>
38 #include <Approx_CurveOnSurface.hxx>
39 #include <ProjLib_Plane.hxx>
40 #include <ProjLib_Cylinder.hxx>
41 #include <ProjLib_Cone.hxx>
42 #include <ProjLib_Sphere.hxx>
43 #include <ProjLib_Torus.hxx>
44 #include <Precision.hxx>
45 #include <Handle_Geom_BSplineCurve.hxx>
46 #include <Geom2d_BSplineCurve.hxx>
47 #include <Handle_Geom2d_BSplineCurve.hxx>
48 #include <Geom2d_BezierCurve.hxx>
49 #include <Handle_Geom2d_BezierCurve.hxx>
50 #include <Handle_Adaptor2d_HCurve2d.hxx>
51 #include <gp_Vec2d.hxx>
52 #include <StdFail_NotDone.hxx>
54 #include <TColgp_HArray1OfPnt2d.hxx>
55 #include <TColStd_HArray1OfReal.hxx>
56 #include <Geom2dConvert_CompCurveToBSplineCurve.hxx>
57 #include <TColStd_Array1OfReal.hxx>
58 #include <TColStd_Array1OfInteger.hxx>
59 #include <TColgp_Array1OfPnt2d.hxx>
60 #include <TColgp_HArray1OfVec2d.hxx>
61 #include <TColStd_HArray1OfBoolean.hxx>
62 #include <BSplCLib.hxx>
63 #include <GeomAbs_IsoType.hxx>
64 #include <Geom2d_Line.hxx>
65 #include <Geom2d_TrimmedCurve.hxx>
67 #include <GeomLib.hxx>
69 //=======================================================================
72 //=======================================================================
74 static Standard_Boolean IsoIsDeg (const Adaptor3d_Surface& S,
75 const Standard_Real Param,
76 const GeomAbs_IsoType IT,
77 const Standard_Real TolMin,
78 const Standard_Real TolMax)
80 Standard_Real U1=0.,U2=0.,V1=0.,V2=0.,T;
81 Standard_Boolean Along = Standard_True;
82 U1 = S.FirstUParameter();
83 U2 = S.LastUParameter();
84 V1 = S.FirstVParameter();
85 V2 = S.LastVParameter();
88 Standard_Real Step,D1NormMax;
89 if (IT == GeomAbs_IsoV)
93 for (T=U1;T<=U2;T=T+Step)
95 S.D1(T,Param,P,D1U,D1V);
96 D1NormMax=Max(D1NormMax,D1U.Magnitude());
99 if (D1NormMax >TolMax || D1NormMax < TolMin )
100 Along = Standard_False;
106 for (T=V1;T<=V2;T=T+Step)
108 S.D1(Param,T,P,D1U,D1V);
109 D1NormMax=Max(D1NormMax,D1V.Magnitude());
112 if (D1NormMax >TolMax || D1NormMax < TolMin )
113 Along = Standard_False;
120 //=======================================================================
121 //function : Interpolate
123 //=======================================================================
125 static Handle(Geom2d_BSplineCurve) Interpolate(const Handle(TColgp_HArray1OfPnt2d)& myPoints,
126 const Handle(TColStd_HArray1OfReal)& myParameters,
127 const gp_Vec2d& InitialTangent,
128 const gp_Vec2d& FinalTangent)
130 Handle(Geom2d_BSplineCurve) myCurve = NULL;
132 // This code is extraction from Geom2dAPI_Interpolate with small correction
133 // This is done to avoid of cyclic dependency if Geom2dAPI is used in ProjLib
135 Standard_Integer degree,
150 Standard_Boolean myTangentRequest = Standard_True;
152 Handle(TColgp_HArray1OfVec2d) myTangents =
153 new TColgp_HArray1OfVec2d(myPoints->Lower(),
155 Handle(TColStd_HArray1OfBoolean) myTangentFlags =
156 new TColStd_HArray1OfBoolean(myPoints->Lower(),
158 myTangentFlags->Init(Standard_False);
160 myTangentFlags->SetValue(1,Standard_True) ;
161 myTangentFlags->SetValue(myPoints->Length(),Standard_True) ;
162 myTangents->SetValue(1,InitialTangent) ;
163 myTangents->SetValue(myPoints->Length(),FinalTangent);
167 num_poles = myPoints->Length() ;
168 if (num_poles == 2 && !myTangentRequest) {
171 else if (num_poles == 3 && !myTangentRequest) {
173 num_distinct_knots = 2 ;
178 //if (myTangentRequest)
179 //for (ii = myTangentFlags->Lower() + 1 ;
180 // ii < myTangentFlags->Upper() ; ii++) {
181 //if (myTangentFlags->Value(ii)) {
188 TColStd_Array1OfReal parameters(1,num_poles) ;
189 TColStd_Array1OfReal flatknots(1,num_poles + degree + 1) ;
190 TColStd_Array1OfInteger mults(1,num_distinct_knots) ;
191 TColStd_Array1OfReal knots(1,num_distinct_knots) ;
192 TColStd_Array1OfInteger contact_order_array(1, num_poles) ;
193 TColgp_Array1OfPnt2d poles(1,num_poles) ;
195 for (ii = 1 ; ii <= degree + 1 ; ii++) {
196 flatknots.SetValue(ii,myParameters->Value(1)) ;
197 flatknots.SetValue(ii + num_poles,
198 myParameters->Value(num_points)) ;
200 for (ii = 1 ; ii <= num_poles ; ii++) {
201 contact_order_array.SetValue(ii,0) ;
203 for (ii = 2 ; ii < num_distinct_knots ; ii++) {
204 mults.SetValue(ii,1) ;
206 mults.SetValue(1,degree + 1) ;
207 mults.SetValue(num_distinct_knots ,degree + 1) ;
211 for (ii = 1 ; ii <= num_poles ; ii++) {
212 poles.SetValue(ii ,myPoints->Value(ii)) ;
215 new Geom2d_BSplineCurve(poles,
216 myParameters->Array1(),
219 //myIsDone = Standard_True ;
222 knots.SetValue(1,myParameters->Value(1)) ;
223 knots.SetValue(2,myParameters->Value(3)) ;
224 for (ii = 1 ; ii <= num_poles ; ii++) {
225 poles.SetValue(ii,myPoints->Value(ii)) ;
228 BSplCLib::Interpolate(degree,
230 myParameters->Array1(),
234 if (!inversion_problem) {
236 new Geom2d_BSplineCurve(poles,
240 //myIsDone = Standard_True ;
245 // check if the boundary conditions are set
247 //if (num_points >= 3) {
249 // cannot build the tangents with degree 3 with only 2 points
250 // if those where not given in advance
252 //BuildTangents(myPoints->Array1(),
253 //myTangents->ChangeArray1(),
254 //myTangentFlags->ChangeArray1(),
255 //myParameters->Array1()) ;
257 contact_order_array.SetValue(2,1) ;
258 parameters.SetValue(1,myParameters->Value(1)) ;
259 parameters.SetValue(2,myParameters->Value(1)) ;
260 poles.SetValue(1,myPoints->Value(1)) ;
261 for (jj = 1 ; jj <= 2 ; jj++) {
262 a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ;
265 poles.SetValue(2,a_point) ;
269 index2 = myPoints->Lower() + 1 ;
270 index3 = degree + 2 ;
271 if (myTangentRequest) {
272 for (ii = myParameters->Lower() + 1 ;
273 ii < myParameters->Upper() ; ii++) {
274 parameters.SetValue(index,myParameters->Value(ii)) ;
275 poles.SetValue(index,myPoints->Value(index2)) ;
276 flatknots.SetValue(index3,myParameters->Value(ii)) ;
279 if (myTangentFlags->Value(index1)) {
281 // set the multiplicities, the order of the contact, the
284 mults.SetValue(mult_index,mults.Value(mult_index) + 1) ;
285 contact_order_array(index) = 1 ;
286 flatknots.SetValue(index3, myParameters->Value(ii)) ;
287 parameters.SetValue(index,
288 myParameters->Value(ii)) ;
289 for (jj = 1 ; jj <= 2 ; jj++) {
290 a_point.SetCoord(jj,myTangents->Value(ii).Coord(jj)) ;
292 poles.SetValue(index,a_point) ;
304 for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) {
305 parameters.SetValue(index1,
306 myParameters->Value(ii)) ;
310 for (ii = myPoints->Lower() + 1 ; ii <= myPoints->Upper() - 1 ; ii++) {
311 poles.SetValue(index,
312 myPoints->Value(ii)) ;
318 for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) {
319 flatknots.SetValue(index,
320 myParameters->Value(ii)) ;
324 for (jj = 1 ; jj <= 2 ; jj++) {
326 myTangents->Value(num_points).Coord(jj)) ;
328 poles.SetValue(num_poles-1 ,a_point) ;
330 contact_order_array.SetValue(num_poles - 1,1) ;
331 parameters.SetValue(num_poles,
332 myParameters->Value(myParameters->Upper())) ;
333 parameters.SetValue(num_poles -1,
334 myParameters->Value(myParameters->Upper())) ;
336 poles.SetValue(num_poles,
337 myPoints->Value(num_points)) ;
339 BSplCLib::Interpolate(degree,
345 if (!inversion_problem) {
347 new Geom2d_BSplineCurve(poles,
348 myParameters->Array1(),
351 //myIsDone = Standard_True ;
361 //=======================================================================
364 //=======================================================================
366 static void TrimC3d(Handle(Adaptor3d_HCurve)& myCurve,
367 Standard_Boolean* IsTrimmed,
368 const Standard_Real dt,
370 Standard_Integer* SingularCase,
371 const Standard_Integer NumberOfSingularCase)
373 Standard_Real f = myCurve->FirstParameter();
374 Standard_Real l = myCurve->LastParameter();
376 gp_Pnt P = myCurve->Value(f);
378 if(P.Distance(Pole) < Precision::Confusion()) {
379 IsTrimmed[0] = Standard_True;
381 myCurve = myCurve->Trim(f, l, Precision::Confusion());
382 SingularCase[0] = NumberOfSingularCase;
385 P = myCurve->Value(l);
386 if(P.Distance(Pole) < Precision::Confusion()) {
387 IsTrimmed[1] = Standard_True;
389 myCurve = myCurve->Trim(f, l, Precision::Confusion());
390 SingularCase[1] = NumberOfSingularCase;
394 //=======================================================================
395 //function : ExtendC2d
397 //=======================================================================
399 static void ExtendC2d(Handle(Geom2d_BSplineCurve)& aRes,
400 const Standard_Real t,
401 const Standard_Real dt,
402 const Standard_Real u1,
403 const Standard_Real u2,
404 const Standard_Real v1,
405 const Standard_Real v2,
406 const Standard_Integer FirstOrLast,
407 const Standard_Integer NumberOfSingularCase)
409 Standard_Real theParam = (FirstOrLast == 0)? aRes->FirstParameter()
410 : aRes->LastParameter();
415 Handle(Geom2d_TrimmedCurve) aSegment;
416 Geom2dConvert_CompCurveToBSplineCurve aCompCurve(aRes, Convert_RationalC1);
417 Standard_Real aTol = Precision::Confusion();
419 aRes->D1(theParam, aPBnd, aVBnd);
420 aDBnd.SetXY(aVBnd.XY());
421 gp_Lin2d aLin(aPBnd, aDBnd); //line in direction of derivative
424 gp_Dir2d theBoundDir;
425 switch (NumberOfSingularCase)
429 thePole.SetCoord(u1, v1);
430 theBoundDir.SetCoord(0., 1.);
435 thePole.SetCoord(u2, v1);
436 theBoundDir.SetCoord(0., 1.);
441 thePole.SetCoord(u1, v1);
442 theBoundDir.SetCoord(1., 0.);
447 thePole.SetCoord(u1, v2);
448 theBoundDir.SetCoord(1., 0.);
452 gp_Lin2d BoundLin(thePole, theBoundDir); //one of the bounds of rectangle
454 Standard_Real U1x = BoundLin.Direction().X();
455 Standard_Real U1y = BoundLin.Direction().Y();
456 Standard_Real U2x = aLin.Direction().X();
457 Standard_Real U2y = aLin.Direction().Y();
458 Standard_Real Uo21x = aLin.Location().X() - BoundLin.Location().X();
459 Standard_Real Uo21y = aLin.Location().Y() - BoundLin.Location().Y();
461 Standard_Real D = U1y*U2x-U1x*U2y;
463 Standard_Real ParOnLin = (Uo21y * U1x - Uo21x * U1y)/D; //parameter of intersection point
465 Handle(Geom2d_Line) aSegLine = new Geom2d_Line(aLin);
466 aSegment = (FirstOrLast == 0)?
467 new Geom2d_TrimmedCurve(aSegLine, ParOnLin, 0.) :
468 new Geom2d_TrimmedCurve(aSegLine, 0., ParOnLin);
470 aCompCurve.Add(aSegment, aTol);
471 aRes = aCompCurve.BSplineCurve();
476 aRes->D2(t, P0, V01, V02);
478 gp_XY XYP1 = P0.XY() + V01.XY()*dt + .5*V02.XY()*dt*dt;
480 gp_Vec2d V11 = V01 + V02*dt;
482 if(XYP1.X() < u1) XYP1.SetX(u1);
483 if(XYP1.X() > u2) XYP1.SetX(u2);
484 if(XYP1.Y() < v1) XYP1.SetY(v1);
485 if(XYP1.Y() > v2) XYP1.SetY(v2);
487 Handle(TColgp_HArray1OfPnt2d) aPnts = new TColgp_HArray1OfPnt2d(1, 2);
488 Handle(TColStd_HArray1OfReal) aPars = new TColStd_HArray1OfReal(1, 2);
491 aPnts->SetValue(1, gp_Pnt2d(XYP1));
492 aPnts->SetValue(2, P0);
493 aPars->SetValue(1, t + dt);
494 aPars->SetValue(2, t);
497 aPnts->SetValue(2, gp_Pnt2d(XYP1));
498 aPnts->SetValue(1, P0);
499 aPars->SetValue(2, t + dt);
500 aPars->SetValue(1, t);
503 Handle(Geom2d_BSplineCurve) aC;
506 aC = Interpolate(aPnts, aPars, V11, V01);
509 aC = Interpolate(aPnts, aPars, V01, V11);
513 Geom2dConvert_CompCurveToBSplineCurve aConcat(aRes);
514 aConcat.Add(aC, Precision::PConfusion());
516 aRes = aConcat.BSplineCurve();
520 //=======================================================================
523 //=======================================================================
525 static void Project(ProjLib_Projector& P, Handle(Adaptor3d_HCurve)& C)
527 GeomAbs_CurveType CType = C->GetType();
530 P.Project(C->Line());
533 P.Project(C->Circle());
535 case GeomAbs_Ellipse:
536 P.Project(C->Ellipse());
538 case GeomAbs_Hyperbola:
539 P.Project(C->Hyperbola());
541 case GeomAbs_Parabola:
542 P.Project(C->Parabola());
544 case GeomAbs_BSplineCurve:
545 case GeomAbs_BezierCurve:
546 case GeomAbs_OtherCurve: // try the approximation
549 Standard_NoSuchObject::Raise(" ");
553 //=======================================================================
554 //function : ProjLib_ProjectedCurve
556 //=======================================================================
558 ProjLib_ProjectedCurve::ProjLib_ProjectedCurve()
561 myTolerance = Precision::Confusion();
565 //=======================================================================
566 //function : ProjLib_ProjectedCurve
568 //=======================================================================
570 ProjLib_ProjectedCurve::ProjLib_ProjectedCurve
571 (const Handle(Adaptor3d_HSurface)& S)
573 myTolerance = Precision::Confusion();
578 //=======================================================================
579 //function : ProjLib_ProjectedCurve
581 //=======================================================================
583 ProjLib_ProjectedCurve::ProjLib_ProjectedCurve
584 (const Handle(Adaptor3d_HSurface)& S,
585 const Handle(Adaptor3d_HCurve)& C)
587 myTolerance = Precision::Confusion();
593 //=======================================================================
594 //function : ProjLib_ProjectedCurve
596 //=======================================================================
598 ProjLib_ProjectedCurve::ProjLib_ProjectedCurve
599 (const Handle(Adaptor3d_HSurface)& S,
600 const Handle(Adaptor3d_HCurve)& C,
601 const Standard_Real Tol)
603 myTolerance = Max(Tol, Precision::Confusion());
609 //=======================================================================
612 //=======================================================================
614 void ProjLib_ProjectedCurve::Load(const Handle(Adaptor3d_HSurface)& S)
620 //=======================================================================
623 //=======================================================================
625 void ProjLib_ProjectedCurve::Load(const Handle(Adaptor3d_HCurve)& C)
627 myTolerance = Max(myTolerance, Precision::Confusion());
629 Standard_Real FirstPar = C->FirstParameter();
630 Standard_Real LastPar = C->LastParameter();
631 GeomAbs_SurfaceType SType = mySurface->GetType();
632 GeomAbs_CurveType CType = myCurve->GetType();
638 ProjLib_Plane P(mySurface->Plane());
644 case GeomAbs_Cylinder:
646 ProjLib_Cylinder P(mySurface->Cylinder());
654 ProjLib_Cone P(mySurface->Cone());
662 ProjLib_Sphere P(mySurface->Sphere());
665 // on met dans la pseudo-periode ( car Sphere n'est pas
666 // periodique en V !)
667 P.SetInBounds(myCurve->FirstParameter());
675 ProjLib_Torus P(mySurface->Torus());
681 case GeomAbs_BezierSurface:
682 case GeomAbs_BSplineSurface:
685 Standard_Boolean IsTrimmed[2] = {Standard_False, Standard_False};
686 Standard_Integer SingularCase[2];
687 Standard_Real f, l, dt;
688 const Standard_Real eps = 0.01;
689 f = myCurve->FirstParameter();
690 l = myCurve->LastParameter();
693 Standard_Real U1=0.,U2=0.,V1=0.,V2=0;
694 const Adaptor3d_Surface& S = mySurface->Surface();
695 U1 = S.FirstUParameter();
696 U2 = S.LastUParameter();
697 V1 = S.FirstVParameter();
698 V2 = S.LastVParameter();
700 if(IsoIsDeg(S, U1, GeomAbs_IsoU, 0., myTolerance) ) {
701 //Surface has pole at U = Umin
702 gp_Pnt Pole = mySurface->Value(U1, V1);
703 TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 1);
706 if(IsoIsDeg(S, U2, GeomAbs_IsoU, 0., myTolerance) ) {
707 //Surface has pole at U = Umax
708 gp_Pnt Pole = mySurface->Value(U2, V1);
709 TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 2);
712 if(IsoIsDeg(S, V1, GeomAbs_IsoV, 0., myTolerance) ) {
713 //Surface has pole at V = Vmin
714 gp_Pnt Pole = mySurface->Value(U1, V1);
715 TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 3);
718 if(IsoIsDeg(S, V2, GeomAbs_IsoV, 0., myTolerance) ) {
719 //Surface has pole at V = Vmax
720 gp_Pnt Pole = mySurface->Value(U1, V2);
721 TrimC3d(myCurve, IsTrimmed, dt, Pole, SingularCase, 4);
724 ProjLib_ComputeApproxOnPolarSurface polar(myCurve,
728 Handle(Geom2d_BSplineCurve) aRes = polar.BSpline();
730 if(IsTrimmed[0] || IsTrimmed[1]) {
732 //Add segment before start of curve
733 f = myCurve->FirstParameter();
734 ExtendC2d(aRes, f, -dt, U1, U2, V1, V2, 0, SingularCase[0]);
737 //Add segment after end of curve
738 l = myCurve->LastParameter();
739 ExtendC2d(aRes, l, dt, U1, U2, V1, V2, 1, SingularCase[1]);
741 Handle(Geom2d_Curve) NewCurve2d;
742 GeomLib::SameRange(Precision::PConfusion(), aRes,
743 aRes->FirstParameter(), aRes->LastParameter(),
746 aRes = Handle(Geom2d_BSplineCurve)::DownCast(NewCurve2d);
748 myResult.SetBSpline(aRes);
750 myResult.SetType(GeomAbs_BSplineCurve);
756 Standard_Boolean IsTrimmed[2] = {Standard_False, Standard_False};
757 Standard_Real Vsingular[2]; //for surfaces of revolution
758 Standard_Real f, l, dt;
759 const Standard_Real eps = 0.01;
761 if(mySurface->GetType() == GeomAbs_SurfaceOfRevolution) {
762 //Check possible singularity
764 gp_Pnt P = mySurface->AxeOfRevolution().Location();
765 gp_Dir N = mySurface->AxeOfRevolution().Direction();
769 f = myCurve->FirstParameter();
770 l = myCurve->LastParameter();
773 P = myCurve->Value(f);
774 if(L.Distance(P) < Precision::Confusion()) {
775 IsTrimmed[0] = Standard_True;
777 myCurve = myCurve->Trim(f, l, Precision::Confusion());
778 Vsingular[0] = ElCLib::Parameter(L, P);
779 //SingularCase[0] = 3;
782 P = myCurve->Value(l);
783 if(L.Distance(P) < Precision::Confusion()) {
784 IsTrimmed[1] = Standard_True;
786 myCurve = myCurve->Trim(f, l, Precision::Confusion());
787 Vsingular[1] = ElCLib::Parameter(L, P);
788 //SingularCase[1] = 3;
792 ProjLib_CompProjectedCurve Projector(mySurface,myCurve,
793 myTolerance,myTolerance);
794 Handle(ProjLib_HCompProjectedCurve) HProjector =
795 new ProjLib_HCompProjectedCurve();
796 HProjector->Set(Projector);
798 // Normalement, dans le cadre de ProjLib, le resultat
799 // doit etre une et une seule courbe !!!
800 // De plus, cette courbe ne doit pas etre Single point
801 Standard_Integer NbCurves = Projector.NbCurves();
802 Standard_Real Udeb,Ufin;
804 Projector.Bounds(1,Udeb,Ufin);
807 StdFail_NotDone::Raise("ProjLib CompProjectedCurve Not Done");
809 // Approximons cette courbe algorithmique.
810 Standard_Boolean Only3d = Standard_False;
811 Standard_Boolean Only2d = Standard_True;
812 GeomAbs_Shape Continuity = GeomAbs_C1;
813 Standard_Integer MaxDegree = 14;
814 Standard_Integer MaxSeg = 16;
816 Approx_CurveOnSurface appr(HProjector, mySurface, Udeb, Ufin,
818 Continuity, MaxDegree, MaxSeg,
821 Handle(Geom2d_BSplineCurve) aRes = appr.Curve2d();
823 if(IsTrimmed[0] || IsTrimmed[1]) {
824 // Treatment only for surface of revolution
825 Standard_Real u1, u2, v1, v2;
826 u1 = mySurface->FirstUParameter();
827 u2 = mySurface->LastUParameter();
828 v1 = mySurface->FirstVParameter();
829 v2 = mySurface->LastVParameter();
832 //Add segment before start of curve
833 ExtendC2d(aRes, f, -dt, u1, u2, Vsingular[0], v2, 0, 3);
836 //Add segment after end of curve
837 ExtendC2d(aRes, l, dt, u1, u2, Vsingular[1], v2, 1, 3);
839 Handle(Geom2d_Curve) NewCurve2d;
840 GeomLib::SameRange(Precision::PConfusion(), aRes,
841 aRes->FirstParameter(), aRes->LastParameter(),
844 aRes = Handle(Geom2d_BSplineCurve)::DownCast(NewCurve2d);
847 myResult.SetBSpline(aRes);
849 myResult.SetType(GeomAbs_BSplineCurve);
852 if ( !myResult.IsDone()) {
853 ProjLib_ComputeApprox Comp( myCurve, mySurface, myTolerance);
857 if ( SType == GeomAbs_Plane && CType == GeomAbs_BezierCurve) {
858 myResult.SetType(GeomAbs_BezierCurve);
859 myResult.SetBezier(Comp.Bezier()) ;
862 myResult.SetType(GeomAbs_BSplineCurve);
863 myResult.SetBSpline(Comp.BSpline()) ;
865 // set the periodicity flag
866 if ( SType == GeomAbs_Plane &&
867 CType == GeomAbs_BSplineCurve &&
868 myCurve->IsPeriodic() ) {
869 myResult.SetPeriodic();
871 myTolerance = Comp.Tolerance();
875 // On remet arbitrairement la tol atteinte a une valeur
876 // petite en attendant mieux. dub lbo 11/03/97
877 myTolerance = Min(myTolerance,Precision::Confusion());
879 // Translate the projected curve to keep the first point
880 // In the canonical boundaries of periodic surfaces.
881 if (mySurface->IsUPeriodic()) {
883 Standard_Real aT1, aT2, aU1, aU2, aUPeriod, aUr, aUm, aUmid, dUm, dUr;
884 GeomAbs_CurveType aTypeR;
885 ProjLib_Projector aResult;
887 aT1=myCurve->FirstParameter();
888 aT2=myCurve->LastParameter();
889 aU1=mySurface->FirstUParameter();
890 aU2=mySurface->LastUParameter();
891 aUPeriod=mySurface->UPeriod();
893 aTypeR=myResult.GetType();
894 if ((aU2-aU1)<(aUPeriod-myTolerance) && aTypeR == GeomAbs_Line) {
896 aResult.UFrame(aT1, aT2, aU1, aUPeriod);
898 gp_Lin2d &aLr = (gp_Lin2d &) aResult.Line();
899 aUr=aLr.Location().X();
900 gp_Lin2d &aLm = (gp_Lin2d &) myResult.Line();
901 aUm=aLm.Location().X();
911 myResult.UFrame(aT1, aT2, aU1, aUPeriod);
915 myResult.UFrame(myCurve->FirstParameter(),
916 myCurve->LastParameter(),
917 mySurface->FirstUParameter(),
918 mySurface->UPeriod());
921 // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin
922 // Correct the U isoline in periodical surface
923 // to be inside restriction boundaries.
924 if (myResult.GetType() == GeomAbs_Line) {
925 gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line();
927 Standard_Real aPeriod = mySurface->UPeriod();
928 Standard_Real aFUPar = mySurface->FirstUParameter();
929 Standard_Real aLUPar = mySurface->LastUParameter();
931 // Check if the parametric range is lower then the period.
932 if (aLUPar - aFUPar < aPeriod - myTolerance) {
933 Standard_Real aU = aLine.Location().X();
935 if (Abs(aU + aPeriod - aFUPar) < myTolerance ||
936 Abs(aU - aPeriod - aFUPar) < myTolerance) {
937 gp_Pnt2d aNewLoc(aFUPar, aLine.Location().Y());
939 aLine.SetLocation(aNewLoc);
940 } else if (Abs(aU + aPeriod - aLUPar) < myTolerance ||
941 Abs(aU - aPeriod - aLUPar) < myTolerance) {
942 gp_Pnt2d aNewLoc(aLUPar, aLine.Location().Y());
944 aLine.SetLocation(aNewLoc);
949 // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End
951 if (mySurface->IsVPeriodic()) {
952 myResult.VFrame(myCurve->FirstParameter(),
953 myCurve->LastParameter(),
954 mySurface->FirstVParameter(),
955 mySurface->VPeriod());
956 // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 Begin
957 // Correct the V isoline in a periodical surface
958 // to be inside restriction boundaries.
959 if (myResult.GetType() == GeomAbs_Line) {
960 gp_Lin2d &aLine = (gp_Lin2d &) myResult.Line();
962 Standard_Real aPeriod = mySurface->VPeriod();
963 Standard_Real aFVPar = mySurface->FirstVParameter();
964 Standard_Real aLVPar = mySurface->LastVParameter();
966 // Check if the parametric range is lower then the period.
967 if (aLVPar - aFVPar < aPeriod - myTolerance) {
968 Standard_Real aV = aLine.Location().Y();
970 if (Abs(aV + aPeriod - aFVPar) < myTolerance ||
971 Abs(aV - aPeriod - aFVPar) < myTolerance) {
972 gp_Pnt2d aNewLoc(aLine.Location().X(), aFVPar);
974 aLine.SetLocation(aNewLoc);
975 } else if (Abs(aV + aPeriod - aLVPar) < myTolerance ||
976 Abs(aV - aPeriod - aLVPar) < myTolerance) {
977 gp_Pnt2d aNewLoc(aLine.Location().X(), aLVPar);
979 aLine.SetLocation(aNewLoc);
984 // Modified by skv - Wed Aug 11 15:45:58 2004 OCC6272 End
989 //=======================================================================
990 //function : GetSurface
992 //=======================================================================
994 const Handle(Adaptor3d_HSurface)& ProjLib_ProjectedCurve::GetSurface() const
1000 //=======================================================================
1001 //function : GetCurve
1003 //=======================================================================
1005 const Handle(Adaptor3d_HCurve)& ProjLib_ProjectedCurve::GetCurve() const
1011 //=======================================================================
1012 //function : GetTolerance
1014 //=======================================================================
1016 Standard_Real ProjLib_ProjectedCurve::GetTolerance() const
1022 //=======================================================================
1023 //function : FirstParameter
1025 //=======================================================================
1027 Standard_Real ProjLib_ProjectedCurve::FirstParameter() const
1029 return myCurve->FirstParameter();
1033 //=======================================================================
1034 //function : LastParameter
1036 //=======================================================================
1038 Standard_Real ProjLib_ProjectedCurve::LastParameter() const
1040 return myCurve->LastParameter();
1044 //=======================================================================
1045 //function : Continuity
1047 //=======================================================================
1049 GeomAbs_Shape ProjLib_ProjectedCurve::Continuity() const
1051 Standard_NotImplemented::Raise("");
1056 //=======================================================================
1057 //function : NbIntervals
1059 //=======================================================================
1061 Standard_Integer ProjLib_ProjectedCurve::NbIntervals(const GeomAbs_Shape ) const
1063 Standard_NotImplemented::Raise("");
1068 //=======================================================================
1069 //function : Intervals
1071 //=======================================================================
1073 //void ProjLib_ProjectedCurve::Intervals(TColStd_Array1OfReal& T,
1074 void ProjLib_ProjectedCurve::Intervals(TColStd_Array1OfReal& ,
1075 const GeomAbs_Shape ) const
1077 Standard_NotImplemented::Raise("");
1081 //=======================================================================
1082 //function : IsClosed
1084 //=======================================================================
1086 Standard_Boolean ProjLib_ProjectedCurve::IsClosed() const
1088 Standard_NotImplemented::Raise("");
1089 return Standard_True;
1093 //=======================================================================
1094 //function : IsPeriodic
1096 //=======================================================================
1098 Standard_Boolean ProjLib_ProjectedCurve::IsPeriodic() const
1100 return myResult.IsPeriodic();
1104 //=======================================================================
1107 //=======================================================================
1109 Standard_Real ProjLib_ProjectedCurve::Period() const
1111 Standard_NotImplemented::Raise("");
1116 //=======================================================================
1119 //=======================================================================
1121 gp_Pnt2d ProjLib_ProjectedCurve::Value(const Standard_Real ) const
1123 Standard_NotImplemented::Raise("");
1124 return gp_Pnt2d(0.,0.);
1128 //=======================================================================
1131 //=======================================================================
1133 void ProjLib_ProjectedCurve::D0(const Standard_Real , gp_Pnt2d& ) const
1135 Standard_NotImplemented::Raise("");
1139 //=======================================================================
1142 //=======================================================================
1144 void ProjLib_ProjectedCurve::D1(const Standard_Real ,
1148 Standard_NotImplemented::Raise("");
1152 //=======================================================================
1155 //=======================================================================
1157 void ProjLib_ProjectedCurve::D2(const Standard_Real ,
1162 Standard_NotImplemented::Raise("");
1166 //=======================================================================
1169 //=======================================================================
1171 void ProjLib_ProjectedCurve::D3(const Standard_Real,
1177 Standard_NotImplemented::Raise("");
1181 //=======================================================================
1184 //=======================================================================
1186 gp_Vec2d ProjLib_ProjectedCurve::DN(const Standard_Real,
1187 const Standard_Integer) const
1189 Standard_NotImplemented::Raise("");
1190 return gp_Vec2d(0.,0.);
1194 //=======================================================================
1195 //function : Resolution
1197 //=======================================================================
1199 Standard_Real ProjLib_ProjectedCurve::Resolution(const Standard_Real) const
1201 Standard_NotImplemented::Raise("");
1206 //=======================================================================
1207 //function : GetType
1209 //=======================================================================
1211 GeomAbs_CurveType ProjLib_ProjectedCurve::GetType() const
1213 return myResult.GetType();
1217 //=======================================================================
1220 //=======================================================================
1222 gp_Lin2d ProjLib_ProjectedCurve::Line() const
1224 return myResult.Line();
1228 //=======================================================================
1231 //=======================================================================
1233 gp_Circ2d ProjLib_ProjectedCurve::Circle() const
1235 return myResult.Circle();
1239 //=======================================================================
1240 //function : Ellipse
1242 //=======================================================================
1244 gp_Elips2d ProjLib_ProjectedCurve::Ellipse() const
1246 return myResult.Ellipse();
1250 //=======================================================================
1251 //function : Hyperbola
1253 //=======================================================================
1255 gp_Hypr2d ProjLib_ProjectedCurve::Hyperbola() const
1257 return myResult.Hyperbola();
1261 //=======================================================================
1262 //function : Parabola
1264 //=======================================================================
1266 gp_Parab2d ProjLib_ProjectedCurve::Parabola() const
1268 return myResult.Parabola();
1273 //=======================================================================
1276 //=======================================================================
1278 Standard_Integer ProjLib_ProjectedCurve::Degree() const
1280 Standard_NoSuchObject_Raise_if
1281 ( (GetType() != GeomAbs_BSplineCurve) &&
1282 (GetType() != GeomAbs_BezierCurve),
1283 "ProjLib_ProjectedCurve:Degree");
1284 if (GetType() == GeomAbs_BSplineCurve) {
1285 return myResult.BSpline()->Degree();
1287 else if (GetType() == GeomAbs_BezierCurve) {
1288 return myResult.Bezier()->Degree();
1295 //=======================================================================
1296 //function : IsRational
1298 //=======================================================================
1300 Standard_Boolean ProjLib_ProjectedCurve::IsRational() const
1302 Standard_NoSuchObject_Raise_if
1303 ( (GetType() != GeomAbs_BSplineCurve) &&
1304 (GetType() != GeomAbs_BezierCurve),
1305 "ProjLib_ProjectedCurve:IsRational");
1306 if (GetType() == GeomAbs_BSplineCurve) {
1307 return myResult.BSpline()->IsRational();
1309 else if (GetType() == GeomAbs_BezierCurve) {
1310 return myResult.Bezier()->IsRational();
1313 return Standard_False;
1316 //=======================================================================
1317 //function : NbPoles
1319 //=======================================================================
1321 Standard_Integer ProjLib_ProjectedCurve::NbPoles() const
1323 Standard_NoSuchObject_Raise_if
1324 ( (GetType() != GeomAbs_BSplineCurve) &&
1325 (GetType() != GeomAbs_BezierCurve)
1326 ,"ProjLib_ProjectedCurve:NbPoles" );
1327 if (GetType() == GeomAbs_BSplineCurve) {
1328 return myResult.BSpline()->NbPoles();
1330 else if (GetType() == GeomAbs_BezierCurve) {
1331 return myResult.Bezier()->NbPoles();
1338 //=======================================================================
1339 //function : NbKnots
1341 //=======================================================================
1343 Standard_Integer ProjLib_ProjectedCurve::NbKnots() const
1345 Standard_NoSuchObject_Raise_if ( GetType() != GeomAbs_BSplineCurve,
1346 "ProjLib_ProjectedCurve:NbKnots");
1347 return myResult.BSpline()->NbKnots();
1350 //=======================================================================
1353 //=======================================================================
1355 Handle(Geom2d_BezierCurve) ProjLib_ProjectedCurve::Bezier() const
1357 return myResult.Bezier() ;
1360 //=======================================================================
1361 //function : BSpline
1363 //=======================================================================
1365 Handle(Geom2d_BSplineCurve) ProjLib_ProjectedCurve::BSpline() const
1367 return myResult.BSpline() ;
1369 //=======================================================================
1372 //=======================================================================
1374 Handle(Adaptor2d_HCurve2d) ProjLib_ProjectedCurve::Trim
1375 //(const Standard_Real First,
1376 // const Standard_Real Last,
1377 // const Standard_Real Tolerance) const
1378 (const Standard_Real ,
1379 const Standard_Real ,
1380 const Standard_Real ) const
1382 Standard_NotImplemented::Raise("");