1 // Created on: 1993-08-12
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by xab, Tue Mar 11 18:31:18 1997
18 // Modified by PMN 14/04/97 : Passage a Geomlite
19 // Modified by JPI 01/08/97 : ajout de la commande approxcurve
21 #include <GeomliteTest.hxx>
22 #include <Draw_Appli.hxx>
23 #include <DrawTrSurf.hxx>
24 #include <DrawTrSurf_Curve.hxx>
25 #include <DrawTrSurf_Curve2d.hxx>
26 #include <DrawTrSurf_BezierCurve.hxx>
27 #include <DrawTrSurf_BSplineCurve.hxx>
28 #include <DrawTrSurf_BezierCurve2d.hxx>
29 #include <DrawTrSurf_BSplineCurve2d.hxx>
30 #include <Draw_Marker3D.hxx>
31 #include <Draw_Marker2D.hxx>
33 #include <Draw_Interpretor.hxx>
34 #include <Draw_Color.hxx>
35 #include <Draw_Display.hxx>
37 #include <BSplCLib.hxx>
41 #include <gp_Parab2d.hxx>
42 #include <gp_Elips2d.hxx>
43 #include <gp_Hypr2d.hxx>
45 #include <Geom_Line.hxx>
46 #include <Geom_Circle.hxx>
47 #include <Geom_Ellipse.hxx>
48 #include <Geom_Parabola.hxx>
49 #include <Geom_Hyperbola.hxx>
50 #include <Geom_BezierCurve.hxx>
51 #include <Geom_BSplineCurve.hxx>
52 #include <GeomAdaptor_Surface.hxx>
53 #include <GeomAdaptor_HSurface.hxx>
55 #include <GeomLib.hxx>
56 #include <GeomConvert.hxx>
57 #include <Geom2dConvert.hxx>
59 #include <Geom2d_Line.hxx>
60 #include <Geom2d_Circle.hxx>
61 #include <Geom2d_Ellipse.hxx>
62 #include <Geom2d_Parabola.hxx>
63 #include <Geom2d_Hyperbola.hxx>
64 #include <Geom2d_BezierCurve.hxx>
65 #include <Geom2d_BSplineCurve.hxx>
67 #include <GeomLProp.hxx>
68 #include <GeomLProp_CLProps.hxx>
69 #include <Geom2dLProp_CLProps2d.hxx>
70 #include <Geom2dLProp_CurAndInf2d.hxx>
72 #include <TColgp_Array1OfPnt.hxx>
73 #include <TColgp_Array1OfPnt2d.hxx>
74 #include <TColStd_Array1OfReal.hxx>
75 #include <TColStd_Array1OfInteger.hxx>
77 #include <GeomAbs_SurfaceType.hxx>
78 #include <GeomAbs_CurveType.hxx>
80 #include <Precision.hxx>
84 #include <TColStd_HArray1OfReal.hxx>
85 #include <TColStd_HArray2OfReal.hxx>
86 #include <TColStd_HArray1OfInteger.hxx>
87 #include <TColStd_Array1OfReal.hxx>
88 #include <TColStd_Array1OfInteger.hxx>
90 #include <TColGeom_HArray1OfBSplineCurve.hxx>
91 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
92 #include <Convert_CompPolynomialToPoles.hxx>
93 #include <CPnts_AbscissaPoint.hxx>
94 #include <GCPnts_AbscissaPoint.hxx>
97 #include <GeomAbs_Shape.hxx>
98 #include <Geom_Curve.hxx>
99 #include <GeomConvert.hxx>
100 #include <GeomConvert_ApproxCurve.hxx>
101 #include <Geom2dConvert_ApproxCurve.hxx>
102 #include <Geom2d_Curve.hxx>
104 #include <GeomAdaptor_HCurve.hxx>
105 #include <GeomAdaptor_Curve.hxx>
106 #include <Geom2dAdaptor_HCurve.hxx>
107 #include <GeomAdaptor_HCurve.hxx>
108 #include <Approx_CurvilinearParameter.hxx>
109 #include <Approx_CurveOnSurface.hxx>
110 #include <Geom_BSplineSurface.hxx>
112 #include <AppCont_Function.hxx>
113 #include <Adaptor3d_HCurve.hxx>
114 #include <GeomAdaptor_HCurve.hxx>
115 #include <Approx_FitAndDivide.hxx>
116 #include <Convert_CompBezierCurvesToBSplineCurve.hxx>
119 Standard_IMPORT Draw_Viewer dout;
122 //Class is used in fitcurve
123 class CurveEvaluator : public AppCont_Function
128 Handle(Adaptor3d_HCurve) myCurve;
130 CurveEvaluator(const Handle(Adaptor3d_HCurve)& C)
137 Standard_Real FirstParameter() const
139 return myCurve->FirstParameter();
142 Standard_Real LastParameter() const
144 return myCurve->LastParameter();
147 Standard_Boolean Value(const Standard_Real theT,
148 NCollection_Array1<gp_Pnt2d>& /*thePnt2d*/,
149 NCollection_Array1<gp_Pnt>& thePnt) const
151 thePnt(1) = myCurve->Value(theT);
152 return Standard_True;
155 Standard_Boolean D1(const Standard_Real theT,
156 NCollection_Array1<gp_Vec2d>& /*theVec2d*/,
157 NCollection_Array1<gp_Vec>& theVec) const
160 myCurve->D1(theT, aDummyPnt, theVec(1));
161 return Standard_True;
166 //=======================================================================
167 //function : anacurve
169 //=======================================================================
171 static Standard_Integer anacurve (Draw_Interpretor& , Standard_Integer n, const char** a)
175 Handle(Geom_Geometry) result;
176 Handle(Geom2d_Curve) result2d;
178 if (!strcmp(a[0],"line")) {
180 result2d = new Geom2d_Line(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
181 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5])));
183 result = new Geom_Line(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
184 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])));
189 else if (!strcmp(a[0],"circle")) {
192 new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
197 new Geom_Circle(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
202 new Geom2d_Circle(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
203 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
207 new Geom_Circle(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
208 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
212 new Geom_Circle(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
213 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
214 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
220 else if (!strcmp(a[0],"parabola")) {
223 new Geom2d_Parabola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
228 new Geom_Parabola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
233 new Geom2d_Parabola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
234 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
238 new Geom_Parabola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
239 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
243 new Geom_Parabola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
244 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
245 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
251 else if (!strcmp(a[0],"ellipse")) {
254 new Geom2d_Ellipse(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
256 Draw::Atof(a[4]),Draw::Atof(a[5]));
259 new Geom_Ellipse(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
261 Draw::Atof(a[5]),Draw::Atof(a[6]));
264 new Geom2d_Ellipse(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
265 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
266 Draw::Atof(a[6]), Draw::Atof(a[7]));
269 new Geom_Ellipse(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
270 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
271 Draw::Atof(a[8]), Draw::Atof(a[9]));
274 new Geom_Ellipse(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
275 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
276 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
277 Draw::Atof(a[11]), Draw::Atof(a[12]));
282 else if (!strcmp(a[0],"hyperbola")) {
285 new Geom2d_Hyperbola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
287 Draw::Atof(a[4]),Draw::Atof(a[5]));
290 new Geom_Hyperbola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
292 Draw::Atof(a[5]),Draw::Atof(a[6]));
295 new Geom2d_Hyperbola(gp_Ax22d(gp_Pnt2d(Draw::Atof(a[2]),Draw::Atof(a[3])),
296 gp_Dir2d(Draw::Atof(a[4]),Draw::Atof(a[5]))),
297 Draw::Atof(a[6]), Draw::Atof(a[7]));
300 new Geom_Hyperbola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
301 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7]))),
302 Draw::Atof(a[8]), Draw::Atof(a[9]));
305 new Geom_Hyperbola(gp_Ax2(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])),
306 gp_Dir(Draw::Atof(a[5]),Draw::Atof(a[6]),Draw::Atof(a[7])),
307 gp_Dir(Draw::Atof(a[8]),Draw::Atof(a[9]),Draw::Atof(a[10]))),
308 Draw::Atof(a[11]), Draw::Atof(a[12]));
313 if (!result.IsNull())
314 DrawTrSurf::Set(a[1],result);
315 else if (!result2d.IsNull())
316 DrawTrSurf::Set(a[1],result2d);
323 //=======================================================================
324 //function : polecurve
326 //=======================================================================
328 static Standard_Integer polecurve (Draw_Interpretor& , Standard_Integer n, const char** a)
330 Standard_Integer k,i;
335 if (!strcmp(a[0],"beziercurve")) {
337 Standard_Integer np = Draw::Atoi(a[2]);
338 if (np == 0) return 1;
341 if (i < 3 || i > 4) return 1;
342 Standard_Boolean hasw = i == 4;
344 TColgp_Array1OfPnt poles(1,np);
345 TColStd_Array1OfReal weights(1,np);
348 for (i = 1; i <= np; i++) {
349 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]),Draw::Atof(a[k+2]));
352 weights(i) = Draw::Atof(a[k]);
357 Handle(Geom_BezierCurve) result;
359 result = new Geom_BezierCurve(poles,weights);
361 result = new Geom_BezierCurve(poles);
363 DrawTrSurf::Set(a[1],result);
366 else if (!strcmp((*a[0] == 'p') ? a[0]+1 : a[0],"bsplinecurve")) {
367 Standard_Integer deg = Draw::Atoi(a[2]);
368 Standard_Integer nbk = Draw::Atoi(a[3]);
370 TColStd_Array1OfReal knots(1, nbk);
371 TColStd_Array1OfInteger mults(1, nbk);
373 Standard_Integer Sigma = 0;
374 for (i = 1; i<=nbk; i++) {
375 knots( i) = Draw::Atof(a[k]);
377 mults( i) = Draw::Atoi(a[k]);
382 Standard_Boolean periodic = *a[0] == 'p';
385 np = Sigma - mults(nbk);
389 TColgp_Array1OfPnt poles (1, np);
390 TColStd_Array1OfReal weights(1, np);
392 for (i = 1; i <= np; i++) {
393 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]),Draw::Atof(a[k+2]));
395 weights(i) = Draw::Atof(a[k]);
399 Handle(Geom_BSplineCurve) result =
400 new Geom_BSplineCurve(poles, weights, knots, mults, deg, periodic);
401 DrawTrSurf::Set(a[1],result);
407 //=======================================================================
408 //function : polecurve2d
410 //=======================================================================
412 static Standard_Integer polecurve2d (Draw_Interpretor& , Standard_Integer n, const char** a)
414 Standard_Integer k,i;
419 if (!strcmp(a[0],"2dbeziercurve")) {
421 Standard_Integer np = Draw::Atoi(a[2]);
422 if (np == 0) return 1;
425 if (i < 2 || i > 3) return 1;
426 Standard_Boolean hasw = i == 3;
428 TColgp_Array1OfPnt2d poles(1,np);
429 TColStd_Array1OfReal weights(1,np);
432 for (i = 1; i <= np; i++) {
433 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]));
436 weights(i) = Draw::Atof(a[k]);
441 Handle(Geom2d_BezierCurve) result;
443 result = new Geom2d_BezierCurve(poles,weights);
445 result = new Geom2d_BezierCurve(poles);
447 DrawTrSurf::Set(a[1],result);
450 else if (!strcmp((*(a[0]+2) == 'p') ? a[0]+3 : a[0]+2,"bsplinecurve")) {
451 Standard_Integer deg = Draw::Atoi(a[2]);
452 Standard_Integer nbk = Draw::Atoi(a[3]);
454 TColStd_Array1OfReal knots(1, nbk);
455 TColStd_Array1OfInteger mults(1, nbk);
457 Standard_Integer Sigma = 0;
458 for (i = 1; i<=nbk; i++) {
459 knots( i) = Draw::Atof(a[k]);
461 mults( i) = Draw::Atoi(a[k]);
466 Standard_Boolean periodic = *(a[0]+2) == 'p';
469 np = Sigma - mults(nbk);
473 TColgp_Array1OfPnt2d poles (1, np);
474 TColStd_Array1OfReal weights(1, np);
476 for (i = 1; i <= np; i++) {
477 poles(i).SetCoord(Draw::Atof(a[k]),Draw::Atof(a[k+1]));
479 weights(i) = Draw::Atof(a[k]);
483 Handle(Geom2d_BSplineCurve) result =
484 new Geom2d_BSplineCurve(poles, weights, knots, mults, deg, periodic);
485 DrawTrSurf::Set(a[1],result);
491 //=======================================================================
494 //=======================================================================
496 static Standard_Integer reverse (Draw_Interpretor& , Standard_Integer n, const char** a)
501 for (i = 1; i < n; i++) {
503 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[i]);
508 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[i]);
509 if (!GC2d.IsNull()) {
517 //=======================================================================
518 //function : cmovepole
520 //=======================================================================
522 static Standard_Integer cmovepole (Draw_Interpretor& , Standard_Integer n, const char** a)
526 Standard_Real dx = Draw::Atof(a[3]);
527 Standard_Real dy = Draw::Atof(a[4]);
529 if (n >= 6) dz = Draw::Atof(a[5]);
530 Standard_Integer Index = Draw::Atoi(a[2]);
532 Handle(Geom_BezierCurve) G1 = DrawTrSurf::GetBezierCurve(a[1]);
534 gp_Pnt P = G1->Pole(Index);
535 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
536 G1->SetPole(Index,P);
542 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
544 gp_Pnt P = G2->Pole(Index);
545 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
546 G2->SetPole(Index,P);
551 Handle(Geom2d_BezierCurve) G3 = DrawTrSurf::GetBezierCurve2d(a[1]);
553 gp_Pnt2d P = G3->Pole(Index);
554 P.SetCoord(P.X()+dx, P.Y()+dy);
555 G3->SetPole(Index,P);
561 Handle(Geom2d_BSplineCurve) G4 = DrawTrSurf::GetBSplineCurve2d(a[1]);
563 gp_Pnt2d P = G4->Pole(Index);
564 P.SetCoord(P.X()+dx, P.Y()+dy);
565 G4->SetPole(Index,P);
575 //=======================================================================
576 //function : cmovetangent
578 //=======================================================================
580 static Standard_Integer cmovetangent (Draw_Interpretor& di, Standard_Integer n, const char** a)
582 Standard_Integer dimension,
593 u = Draw::Atof(a[2]);
594 x = Draw::Atof(a[3]);
595 y = Draw::Atof(a[4]);
613 if (dimension == 3) {
614 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
616 z = Draw::Atof(a[5]) ;
617 tx = Draw::Atof(a[6]) ;
618 ty = Draw::Atof(a[7]) ;
619 tz = Draw::Atof(a[8]) ;
621 condition = Max(Draw::Atoi(a[9]), -1) ;
622 condition = Min(condition, G2->Degree()-1) ;
627 tangent.SetCoord(tx,ty,tz) ;
629 G2->MovePointAndTangent(u,
636 if (! error_status) {
640 di << "Not enought degree of freedom increase degree please\n";
647 Handle(Geom2d_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve2d(a[1]);
649 tx = Draw::Atof(a[5]) ;
650 ty = Draw::Atof(a[6]) ;
652 condition = Max(Draw::Atoi(a[7]), -1) ;
653 condition = Min(condition, G2->Degree()-1) ;
658 tangent.SetCoord(tx,ty) ;
660 G2->MovePointAndTangent(u,
667 if (! error_status) {
671 di << "Not enought degree of freedom increase degree please\n";
681 //=======================================================================
682 //function : cmovepoint
684 //=======================================================================
686 static Standard_Integer cmovepoint (Draw_Interpretor& , Standard_Integer n, const char** a)
690 Standard_Real dx = Draw::Atof(a[3]);
691 Standard_Real dy = Draw::Atof(a[4]);
693 if (n >= 6 && n != 7) dz = Draw::Atof(a[5]);
694 Standard_Real u = Draw::Atof(a[2]);
695 Standard_Integer index1 = 0;
696 Standard_Integer index2 = 0;
697 Standard_Integer fmodif, lmodif;
699 index1 = Draw::Atoi(a[5]);
700 index2 = Draw::Atoi(a[6]);
703 index1 = Draw::Atoi(a[6]);
704 index2 = Draw::Atoi(a[7]);
707 Handle(Geom_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve(a[1]);
711 index2 = G2->NbPoles()-1;
715 p.SetCoord(p.X()+dx, p.Y()+dy, p.Z()+dz);
716 G2->MovePoint(u, p, index1, index2, fmodif, lmodif);
721 Handle(Geom2d_BSplineCurve) G4 = DrawTrSurf::GetBSplineCurve2d(a[1]);
725 index2 = G4->NbPoles()-1;
729 p.SetCoord(p.X()+dx, p.Y()+dy);
730 G4->MovePoint(u, p, index1, index2, fmodif, lmodif);
737 //=======================================================================
738 //function : cinsertknot
740 //=======================================================================
742 static Standard_Integer cinsertknot (Draw_Interpretor& , Standard_Integer n, const char** a)
746 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
747 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
749 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
752 Standard_Real knot = Draw::Atof(a[2]);
753 Standard_Integer mult = 1;
754 if (n == 4) mult = Draw::Atoi(a[3]);
756 GBs->InsertKnot(knot,mult,Precision::PConfusion());
758 GBs2d->InsertKnot(knot,mult,Precision::PConfusion());
762 // multiple insertion
763 if (n % 2 != 0) return 1;
764 Standard_Integer i,nbk = (n-2) / 2;
765 TColStd_Array1OfReal knots(1,nbk);
766 TColStd_Array1OfInteger mults(1,nbk);
767 for (i = 2; i < n; i += 2) {
768 knots(i/2) = Draw::Atof(a[i]);
769 mults(i/2) = Draw::Atoi(a[i+1]);
773 GBs->InsertKnots(knots,mults,Precision::PConfusion());
775 GBs2d->InsertKnots(knots,mults,Precision::PConfusion());
783 //=======================================================================
784 //function : csetknot
786 //=======================================================================
788 static Standard_Integer csetknot (Draw_Interpretor& , Standard_Integer n, const char** a)
792 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
793 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
795 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
797 Standard_Integer index = Draw::Atoi(a[2]);
798 Standard_Real knot = Draw::Atof(a[3]);
802 GBs->SetKnot(index,knot);
804 GBs2d->SetKnot(index,knot);
807 Standard_Integer mult = Draw::Atoi(a[4]);
809 GBs->SetKnot(index,knot,mult);
811 GBs2d->SetKnot(index,knot,mult);
818 //=======================================================================
819 //function : cremknot
821 //=======================================================================
823 static Standard_Integer cremknot (Draw_Interpretor& di, Standard_Integer n, const char** a)
827 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
828 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
830 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
832 Standard_Integer index = Draw::Atoi(a[2]);
833 Standard_Integer mult = 0;
834 if (n >= 4) mult = Draw::Atoi(a[3]);
836 Standard_Real tol = RealLast();
837 if (n >= 5) tol = Draw::Atof(a[4]);
840 if (!GBs->RemoveKnot(index,mult,tol))
841 di << "Remove knots failed\n";
844 if (!GBs2d->RemoveKnot(index,mult,tol))
845 di << "Remove knots failed\n";
852 //=======================================================================
853 //function : increasedegree
855 //=======================================================================
857 static Standard_Integer increasedegree (Draw_Interpretor& , Standard_Integer n, const char** a)
861 Standard_Integer Deg = Draw::Atoi(a[2]);
863 Handle(Geom_BezierCurve) GBz = DrawTrSurf::GetBezierCurve(a[1]);
864 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
865 Handle(Geom2d_BezierCurve) GBz2d = DrawTrSurf::GetBezierCurve2d(a[1]);
866 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
870 else if (!GBs.IsNull())
871 GBs->IncreaseDegree(Deg);
872 else if (!GBz2d.IsNull())
873 GBz2d->Increase(Deg);
874 else if (!GBs2d.IsNull())
875 GBs2d->IncreaseDegree(Deg);
883 //=======================================================================
884 //function : removepole
886 //=======================================================================
888 static Standard_Integer removepole (Draw_Interpretor& di, Standard_Integer n, const char** a)
892 Standard_Integer Index = Draw::Atoi(a[2]);
894 Handle(Geom_BezierCurve) GBZ = DrawTrSurf::GetBezierCurve(a[1]);
895 Handle(Geom2d_BezierCurve) GBZ2d = DrawTrSurf::GetBezierCurve2d(a[1]);
897 GBZ->RemovePole(Index);
899 else if (!GBZ2d.IsNull()) {
900 GBZ2d->RemovePole(Index);
903 di << "rempole needs a bezier curve";
911 //=======================================================================
912 //function : insertpole
914 //=======================================================================
916 static Standard_Integer insertpole (Draw_Interpretor& di, Standard_Integer n, const char** a)
920 Standard_Integer Index = Draw::Atoi(a[2]);
922 Handle(Geom_BezierCurve) GBZ = DrawTrSurf::GetBezierCurve(a[1]);
923 Handle(Geom2d_BezierCurve) GBZ2d = DrawTrSurf::GetBezierCurve2d(a[1]);
925 gp_Pnt P (Draw::Atof(a[3]),Draw::Atof(a[4]),Draw::Atof(a[5]));
927 GBZ->InsertPoleAfter(Index,P,Draw::Atof(a[6]));
929 GBZ->InsertPoleAfter(Index,P);
931 else if (!GBZ2d.IsNull()) {
932 gp_Pnt2d P (Draw::Atof(a[3]),Draw::Atof(a[4]));
934 GBZ2d->InsertPoleAfter(Index,P,Draw::Atof(a[5]));
936 GBZ2d->InsertPoleAfter(Index,P);
939 di << "insertpole needs a bezier curve";
947 //=======================================================================
950 //=======================================================================
952 static Standard_Integer cfindp (Draw_Interpretor& , Standard_Integer n, const char** a)
956 Standard_Integer Index = 0;
957 Standard_Integer view = Draw::Atoi(a[2]);
958 Standard_Real x = Draw::Atof(a[3]);
959 Standard_Real y = Draw::Atof(a[4]);
961 Draw_Display d = dout.MakeDisplay(view);
963 Handle(Draw_Drawable3D) D = Draw::Get(a[1]);
965 Handle(DrawTrSurf_BezierCurve) DBz =
966 Handle(DrawTrSurf_BezierCurve)::DownCast(D);
968 DBz->FindPole( x, y, d, 5, Index);
970 Handle(DrawTrSurf_BSplineCurve) DBs =
971 Handle(DrawTrSurf_BSplineCurve)::DownCast(D);
973 DBs->FindPole( x, y, d, 5, Index);
975 Handle(DrawTrSurf_BezierCurve2d) DBz2d =
976 Handle(DrawTrSurf_BezierCurve2d)::DownCast(D);
978 DBz2d->FindPole( x, y, d, 5, Index);
980 Handle(DrawTrSurf_BSplineCurve2d) DBs2d =
981 Handle(DrawTrSurf_BSplineCurve2d)::DownCast(D);
983 DBs2d->FindPole( x, y, d, 5, Index);
990 Draw::Set(a[5],Index);
996 //=======================================================================
997 //function : csetperiodic
999 //=======================================================================
1001 static Standard_Integer csetperiodic (Draw_Interpretor& , Standard_Integer n, const char** a)
1003 if (n < 2) return 1;
1005 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1006 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1008 if (GBs.IsNull() && GBs2d.IsNull()) return 1;
1010 if (!strcmp(a[0],"setperiodic")) {
1014 GBs2d->SetPeriodic();
1016 else if (!strcmp(a[0],"setnotperiodic")) {
1018 GBs->SetNotPeriodic();
1020 GBs2d->SetNotPeriodic();
1027 //=======================================================================
1030 //=======================================================================
1032 static Standard_Integer value (Draw_Interpretor& ,
1033 Standard_Integer n, const char** a)
1035 if (n < 4) return 1;
1037 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
1038 if (GC.IsNull()) return 1;
1040 Standard_Real U = Draw::Atof(a[2]);
1042 Standard_Boolean DrawPoint = ( n%3 == 1);
1043 if ( DrawPoint) n--;
1047 if (n < 9) return 1;
1050 if (n < 12) return 1;
1053 Draw::Set(a[9] ,D2.X());
1054 Draw::Set(a[10],D2.Y());
1055 Draw::Set(a[11],D2.Z());
1059 Draw::Set(a[6],D1.X());
1060 Draw::Set(a[7],D1.Y());
1061 Draw::Set(a[8],D1.Z());
1067 Draw::Set(a[3],P.X());
1068 Draw::Set(a[4],P.Y());
1069 Draw::Set(a[5],P.Z());
1072 DrawTrSurf::Set(a[n],P);
1079 //=======================================================================
1080 //function : value2d
1082 //=======================================================================
1084 static Standard_Integer value2d (Draw_Interpretor& ,
1085 Standard_Integer n, const char** a)
1087 if (n < 4) return 1;
1089 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
1090 if (GC.IsNull()) return 1;
1092 Standard_Real U = Draw::Atof(a[2]);
1094 Standard_Boolean DrawPoint = ( n%2 == 0);
1095 if ( DrawPoint ) n--;
1099 if (n < 7) return 1;
1102 if (n < 9) return 1;
1105 Draw::Set(a[7] ,D2.X());
1106 Draw::Set(a[8],D2.Y());
1110 Draw::Set(a[5],D1.X());
1111 Draw::Set(a[6],D1.Y());
1117 Draw::Set(a[3],P.X());
1118 Draw::Set(a[4],P.Y());
1121 DrawTrSurf::Set(a[n], P);
1127 //=======================================================================
1128 //function : segment
1130 //=======================================================================
1132 static Standard_Integer segment (Draw_Interpretor& , Standard_Integer n, const char** a)
1134 if (n < 4) return 1;
1136 Handle(Geom_BezierCurve) GBz = DrawTrSurf::GetBezierCurve(a[1]);
1137 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1138 Handle(Geom2d_BezierCurve) GBz2d = DrawTrSurf::GetBezierCurve2d(a[1]);
1139 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1141 Standard_Real f = Draw::Atof(a[2]), l = Draw::Atof(a[3]);
1145 else if (!GBs.IsNull())
1147 else if (!GBz2d.IsNull())
1148 GBz2d->Segment(f,l);
1149 else if (!GBs2d.IsNull())
1150 GBs2d->Segment(f,l);
1159 //=======================================================================
1160 //function : setorigin
1162 //=======================================================================
1164 static Standard_Integer setorigin (Draw_Interpretor& , Standard_Integer n, const char** a)
1166 if (n < 3) return 1;
1168 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1169 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1172 GBs->SetOrigin(Draw::Atoi(a[2]));
1173 if (!GBs2d.IsNull())
1174 GBs2d->SetOrigin(Draw::Atoi(a[2]));
1183 //=======================================================================
1186 //=======================================================================
1188 static Standard_Integer point(Draw_Interpretor& , Standard_Integer n, const char** a)
1190 if (n < 4) return 1;
1192 gp_Pnt P(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
1193 DrawTrSurf::Set(a[1],P);
1196 gp_Pnt2d P(Draw::Atof(a[2]),Draw::Atof(a[3]));
1197 DrawTrSurf::Set(a[1],P);
1203 //=======================================================================
1206 //=======================================================================
1208 static Standard_Integer coord(Draw_Interpretor&,
1209 Standard_Integer n, const char** a)
1213 if ( !DrawTrSurf::GetPoint2d(a[1],P)) return 1;
1214 Draw::Set(a[2],P.X());
1215 Draw::Set(a[3],P.Y());
1219 if ( !DrawTrSurf::GetPoint(a[1],P)) return 1;
1220 Draw::Set(a[2],P.X());
1221 Draw::Set(a[3],P.Y());
1222 Draw::Set(a[4],P.Z());
1230 //=======================================================================
1233 //=======================================================================
1234 static Standard_Integer minmaxcurandinf(Draw_Interpretor& di,
1235 Standard_Integer argc, const char** argv)
1237 if (argc < 2) return 1;
1239 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(argv[1]);
1240 if (C1.IsNull()) return 1;
1243 Geom2dLProp_CurAndInf2d Sommets;
1245 Sommets.PerformCurExt (C1);
1246 if (Sommets.IsDone() && !Sommets.IsEmpty()) {
1247 for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++){
1248 Couleur = Draw_vert;
1249 if (Sommets.Type(i) == LProp_MinCur) {
1250 Couleur = Draw_orange;
1251 di << " Maximum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1254 di << " Minimum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1256 gp_Pnt2d P = C1->Value(Sommets.Parameter(i));
1257 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Couleur);
1263 Geom2dLProp_CurAndInf2d Sommets2;
1264 Sommets2.PerformInf (C1);
1266 if (Sommets2.IsDone() && !Sommets2.IsEmpty()) {
1267 for (Standard_Integer i = 1; i <= Sommets2.NbPoints(); i++){
1268 gp_Pnt2d P = C1->Value(Sommets2.Parameter(i));
1269 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Draw_bleu);
1271 di << " Inflexion at U ="<<Sommets2.Parameter(i)<<"\n";
1277 //=======================================================================
1278 //function : shcurvature
1279 //purpose : affiche le peigne de courbure
1280 //=======================================================================
1281 static Standard_Integer shcurvature(Draw_Interpretor&,
1282 Standard_Integer argc, const char** argv)
1284 if (argc < 2) return 1;
1286 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1287 ::DownCast(Draw::Get(argv[1]));
1288 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1289 ::DownCast(Draw::Get(argv[1]));
1292 if (C3d.IsNull()) return 1;
1293 C3d->ShowCurvature();
1296 C2d->ShowCurvature();
1302 //=======================================================================
1303 //function : clcurvature
1304 //purpose : efface le peigne de courbure
1305 //=======================================================================
1306 static Standard_Integer clcurvature(Draw_Interpretor&,
1307 Standard_Integer argc, const char** argv)
1309 if (argc < 2) return 1;
1310 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1311 ::DownCast(Draw::Get(argv[1]));
1312 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1313 ::DownCast(Draw::Get(argv[1]));
1316 if (C3d.IsNull()) return 1;
1317 C3d->ClearCurvature();
1320 C2d->ClearCurvature();
1326 //=======================================================================
1327 //function : radiusmax
1328 //purpose : definit le rayon de courbure maximum a afficher
1329 //=======================================================================
1330 static Standard_Integer radiusmax(Draw_Interpretor&,
1331 Standard_Integer argc, const char** argv)
1333 if (argc < 3) return 1;
1334 Standard_Real Radius = Draw::Atof(argv[2]);
1335 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1336 ::DownCast(Draw::Get(argv[1]));
1337 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1338 ::DownCast(Draw::Get(argv[1]));
1341 if (C3d.IsNull()) return 1;
1342 C3d->SetRadiusMax(Radius);
1345 C2d->SetRadiusMax(Radius);
1351 //=======================================================================
1352 //function : radiusratio
1353 //purpose : definit le ratio du rayon de courbure a afficher
1354 //=======================================================================
1355 static Standard_Integer radiusratio(Draw_Interpretor&,
1356 Standard_Integer argc, const char** argv)
1358 if (argc < 3) return 1;
1359 Standard_Real Ratio = Draw::Atof(argv[2]);
1360 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1361 ::DownCast(Draw::Get(argv[1]));
1362 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1363 ::DownCast(Draw::Get(argv[1]));
1366 if (C3d.IsNull()) return 1;
1367 C3d->SetRadiusRatio(Ratio);
1370 C2d->SetRadiusRatio(Ratio);
1376 //=======================================================================
1379 //=======================================================================
1380 static Standard_Integer localprop(Draw_Interpretor& di,
1381 Standard_Integer argc, const char** argv)
1383 if (argc < 3) return 1;
1385 Standard_Real U = Draw::Atof(argv[2]);
1387 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(argv[1]);
1388 Handle(Geom_Curve) C3d;
1392 C3d = DrawTrSurf::GetCurve(argv[1]);
1393 if (C3d.IsNull()) return 1;
1394 GeomLProp_CLProps Prop (C3d,2,Precision::Confusion());
1395 Prop.SetParameter(U);
1396 Handle(Draw_Marker3D)drp = new Draw_Marker3D(Prop.Value(),
1400 if (Prop.IsTangentDefined()) {
1401 Standard_Real K = Prop.Curvature();
1402 di <<" Curvature : "<<K<<"\n";
1404 if (Abs(K) > Precision::Confusion()) {
1405 Standard_Real R = 1/Abs(K);
1407 Prop.CentreOfCurvature(Center);
1412 gp_Dir AxC = Nor^Tang;
1413 gp_Ax2 Axe(Center,AxC,Nor);
1414 Handle(Geom_Circle) Cir3d = new Geom_Circle(Axe,R);
1415 Handle(DrawTrSurf_Curve) dr;
1416 dr = new DrawTrSurf_Curve(Cir3d);
1422 di <<"Tangent undefined.\n";
1425 Geom2dLProp_CLProps2d Prop (C2d,2,Precision::Confusion());
1426 Prop.SetParameter(U);
1427 Handle(Draw_Marker2D) drp = new Draw_Marker2D(Prop.Value(),
1431 if (Prop.IsTangentDefined()) {
1432 Standard_Real K = Prop.Curvature();
1435 di <<" Curvature : "<<K<<"\n";
1437 if (Abs(K) > Precision::Confusion()) {
1438 Standard_Real R = 1/Abs(K);
1439 Prop.CentreOfCurvature(Center);
1440 gp_Ax2d Axe(Center,gp::DX2d());
1441 Handle(Geom2d_Circle) Cir2d = new Geom2d_Circle(Axe,R);
1442 Handle(DrawTrSurf_Curve2d) dr;
1443 dr = new DrawTrSurf_Curve2d(Cir2d,Draw_rouge,30,Standard_False);
1449 di <<"Tangent undefined.\n";
1453 //=======================================================================
1454 //function : rawcont
1456 //=======================================================================
1458 static Standard_Integer rawcont(Draw_Interpretor& di, Standard_Integer n, const char** a)
1460 if (n < 5) return 1;
1462 Handle(Geom_Curve) GC1;
1463 GC1 = DrawTrSurf::GetCurve(a[1]);
1464 Handle(Geom_Curve) GC2;
1465 GC2 = DrawTrSurf::GetCurve(a[2]);
1466 Standard_Real param1 =
1468 Standard_Real param2 =
1470 if (GC1.IsNull() || GC2.IsNull())
1478 if (a_point2.SquareDistance(a_point1) < Precision::Confusion()) {
1479 GeomAbs_Shape cont =
1480 GeomLProp::Continuity(GC1,
1486 Precision::Confusion(),
1487 Precision::Angular()) ;
1490 di << " C0 Continuity \n" ;
1493 di << " G1 Continuity \n" ;
1496 di << " C1 Continuity \n" ;
1499 di << " G2 Continuity \n" ;
1502 di << " C2 Continuity \n" ;
1505 di << " C3 Continuity \n" ;
1508 di << " CN Continuity \n" ;
1515 di << " not C0 continuity \n" ;
1519 //=======================================================================
1520 //function : approxcurveonsurf
1522 //=======================================================================
1523 static Standard_Integer approxcurveonsurf(Draw_Interpretor& di, Standard_Integer n, const char** a)
1525 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1526 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1527 Standard_Integer MaxDeg = 14; // Maximum degree
1528 Standard_Integer MaxSeg = 16; /*1*/ // Maximum number of segments
1530 if ( n>8 || n<4) return 1;
1532 if (n>4) Tol = Max(Draw::Atof(a[4]),1.e-10);
1535 if (Draw::Atoi(a[5]) == 0) Continuity = GeomAbs_C0;
1536 if (Draw::Atoi(a[5]) == 2) Continuity = GeomAbs_C2;
1540 MaxDeg = Draw::Atoi(a[6]);
1541 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1544 if (n>7) MaxSeg = Draw::Atoi(a[7]);
1545 Handle(Geom2d_Curve) curve2d = DrawTrSurf::GetCurve2d(a[2]);
1546 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[3]);
1548 Handle(Geom2dAdaptor_HCurve) A2d = new (Geom2dAdaptor_HCurve)(curve2d);
1549 Handle(GeomAdaptor_HSurface) AS = new (GeomAdaptor_HSurface)(Surf);
1551 Approx_CurveOnSurface App(A2d, AS, A2d->FirstParameter(), A2d->LastParameter(),
1552 Tol, Continuity, MaxDeg, MaxSeg,
1553 Standard_True, Standard_False);
1555 if(App.HasResult()) {
1556 Handle(Geom_BSplineCurve) BSCurve = App.Curve3d();
1557 DrawTrSurf::Set(a[1], BSCurve);
1561 di << "Approximation failed !\n";
1566 //=======================================================================
1567 //function : approxcurve
1569 //=======================================================================
1570 static Standard_Integer approxcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1572 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1573 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1574 Standard_Integer MaxDeg = 14; // Maximum degree
1575 Standard_Integer MaxSeg = 16; // Maximum number of segments
1577 Standard_Integer Case, shift;
1578 // Case == 1 : 3d approximation without reparametrization
1579 // Case == 2 : 2d approximation without reparametrization
1580 // Case == 3 : 3d approximation with reparametrization
1581 // Case == 4 : curve_on_surface approximation with reparametrization
1582 // Case == 5 : 2 curves_on_surfaces approximation with reparametrization
1584 Handle(Geom_Curve) curve;
1585 Handle(Geom2d_Curve) curve2d, curve2d2;
1586 Handle(Geom_Surface) surface, surface2;
1590 if (!strcmp(a[1],"-L")) {
1591 // aproximation with curvilinear abscissa reparametrization
1592 if (n > 11 || n < 4) return 1;
1594 curve = DrawTrSurf::GetCurve(a[3]);
1595 if (!curve.IsNull()) {
1600 // approx curve_on_surface
1601 if (n < 5) return 1;
1602 curve2d = DrawTrSurf::GetCurve2d(a[3]);
1603 surface = DrawTrSurf::GetSurface(a[4]);
1604 if (curve2d.IsNull() || surface.IsNull()) {
1608 curve2d2 = DrawTrSurf::GetCurve2d(a[5]);
1609 surface2 = DrawTrSurf::GetSurface(a[6]);
1610 if (curve2d2.IsNull() || surface2.IsNull()) {
1615 // approx 2 curves_on_surfaces
1627 // aproximation without reparamitrization
1628 if ( n>7 || n<3) return 1;
1630 curve = DrawTrSurf::GetCurve(a[2]);
1631 if (curve.IsNull()) {
1632 curve2d = DrawTrSurf::GetCurve2d(a[2]);
1633 if (curve2d.IsNull()) {
1642 if (n>shift) Tol = Max(Draw::Atof(a[shift]),1.e-10);
1645 if (Draw::Atoi(a[shift+1]) == 0) Continuity = GeomAbs_C0;
1646 if (Draw::Atoi(a[shift+1]) == 2) Continuity = GeomAbs_C2;
1650 MaxDeg = Draw::Atoi(a[shift+2]);
1651 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1654 if (n>shift+3) MaxSeg = Draw::Atoi(a[shift+3]);
1657 GeomConvert_ApproxCurve appr(curve, Tol, Continuity, MaxSeg, MaxDeg);
1658 if(appr.HasResult()) {
1660 Standard_SStream aSStream;
1661 appr.Dump(aSStream);
1663 Handle(Geom_BSplineCurve) BSCurve = appr.Curve();
1664 DrawTrSurf::Set(a[1], BSCurve);
1668 else if (Case == 2) {
1669 Geom2dConvert_ApproxCurve appr(curve2d, Tol, Continuity, MaxSeg, MaxDeg);
1670 if(appr.HasResult()) {
1672 Standard_SStream aSStream;
1673 appr.Dump(aSStream);
1675 Handle(Geom2d_BSplineCurve) BSCurve = appr.Curve();
1676 DrawTrSurf::Set(a[1], BSCurve);
1680 else if (Case == 3) {
1681 Handle(Adaptor3d_HCurve) HACur = new GeomAdaptor_HCurve(curve);
1682 Approx_CurvilinearParameter appr(HACur, Tol, Continuity, MaxDeg, MaxSeg);
1683 if(appr.HasResult()) {
1685 Standard_SStream aSStream;
1686 appr.Dump(aSStream);
1688 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1689 DrawTrSurf::Set(a[2], BSCurve);
1692 else if (Case == 4) {
1693 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1694 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1695 Approx_CurvilinearParameter appr(HACur2d, HASur, Tol, Continuity, MaxDeg, MaxSeg);
1696 if(appr.HasResult()) {
1698 Standard_SStream aSStream;
1699 appr.Dump(aSStream);
1701 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1702 DrawTrSurf::Set(a[2], BSCurve);
1706 else if (Case == 5) {
1707 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1708 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1709 Handle(Adaptor2d_HCurve2d) HACur2d2 = new Geom2dAdaptor_HCurve(curve2d2);
1710 Handle(Adaptor3d_HSurface) HASur2 = new GeomAdaptor_HSurface(surface2);
1711 Approx_CurvilinearParameter appr(HACur2d, HASur, HACur2d2, HASur2, Tol, Continuity, MaxDeg, MaxSeg);
1712 if(appr.HasResult()) {
1714 Standard_SStream aSStream;
1715 appr.Dump(aSStream);
1717 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1718 DrawTrSurf::Set(a[2], BSCurve);
1727 //=======================================================================
1728 //function : fitcurve
1730 //=======================================================================
1732 static Standard_Integer fitcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1736 Handle(Geom_Curve) GC;
1737 GC = DrawTrSurf::GetCurve(a[2]);
1741 Standard_Integer Dmin = 3;
1742 Standard_Integer Dmax = 14;
1743 Standard_Real Tol3d = 1.e-5;
1744 Standard_Boolean inverse = Standard_True;
1758 Standard_Integer inv = atoi(a[5]);
1761 inverse = Standard_True;
1765 inverse = Standard_False;
1769 Handle(GeomAdaptor_HCurve) aGAC = new GeomAdaptor_HCurve(GC);
1771 CurveEvaluator aCE(aGAC);
1773 Approx_FitAndDivide anAppro(Dmin, Dmax, Tol3d, 0., Standard_True);
1774 anAppro.SetInvOrder(inverse);
1775 anAppro.Perform(aCE);
1777 if (!anAppro.IsAllApproximated())
1779 di << "Approximation failed \n";
1783 Standard_Integer NbCurves = anAppro.NbMultiCurves();
1785 Convert_CompBezierCurvesToBSplineCurve Conv;
1787 Standard_Real tol3d, tol2d, tolreached = 0.;
1788 for (i = 1; i <= NbCurves; i++) {
1789 anAppro.Error(i, tol3d, tol2d);
1790 tolreached = Max(tolreached, tol3d);
1791 AppParCurves_MultiCurve MC = anAppro.Value(i);
1792 TColgp_Array1OfPnt Poles(1, MC.Degree() + 1);
1794 Conv.AddCurve(Poles);
1797 Standard_Integer NbPoles = Conv.NbPoles();
1798 Standard_Integer NbKnots = Conv.NbKnots();
1800 TColgp_Array1OfPnt NewPoles(1, NbPoles);
1801 TColStd_Array1OfReal NewKnots(1, NbKnots);
1802 TColStd_Array1OfInteger NewMults(1, NbKnots);
1804 Conv.KnotsAndMults(NewKnots, NewMults);
1805 Conv.Poles(NewPoles);
1807 BSplCLib::Reparametrize(GC->FirstParameter(),
1808 GC->LastParameter(),
1810 Handle(Geom_BSplineCurve) TheCurve = new Geom_BSplineCurve(NewPoles, NewKnots, NewMults, Conv.Degree());
1812 DrawTrSurf::Set(a[1], TheCurve);
1813 di << a[1] << ": tolreached = " << tolreached << "\n";
1819 //=======================================================================
1820 //function : newbspline
1821 //purpose : reduce the multiplicity of the knots to their minimum
1822 // compared to the degree of the curve
1823 //=======================================================================
1825 static Standard_Integer splitc1(Draw_Interpretor& di,
1826 Standard_Integer n, const char** c)
1828 {Standard_Real tolerance=1.0e-5,
1829 angular_tolerance = 1.0e-4 ;
1830 Standard_Integer optiontab,i;
1834 optiontab=Draw::Atoi(c[2]);
1836 tolerance=Draw::Atof(c[3]);
1838 angular_tolerance = Draw::Atof(c[4]) ;
1840 Handle(Geom_Curve) ACurve = Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(c[1])) ;
1842 Standard_Real f = ACurve->FirstParameter();
1843 Standard_Real l = ACurve->LastParameter();
1845 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1846 di << " Error: Infinite curves\n";
1850 Handle(Geom_BSplineCurve) BS = GeomConvert::CurveToBSplineCurve(ACurve);
1852 if ( BS.IsNull()) return 1;
1855 Handle(TColGeom_HArray1OfBSplineCurve) tabBS;
1856 GeomConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1860 for (i=0;i<=(tabBS->Length()-1);i++){
1861 Sprintf(name,"%s_%d",c[1],i+1);
1862 Standard_CString new_name = name ;
1863 DrawTrSurf::Set(new_name,
1865 di.AppendElement(name);
1869 GeomConvert::C0BSplineToC1BSplineCurve(BS,
1871 angular_tolerance) ;
1873 DrawTrSurf::Set(c[1],BS);
1878 //=======================================================================
1879 //function : splitc12d
1880 //purpose : reduce the multiplicity of the knots to their minimum
1881 // compared to the degree of the curve
1882 //=======================================================================
1884 static Standard_Integer splitc12d(Draw_Interpretor& di,
1885 Standard_Integer n, const char** c)
1887 {Standard_Real tolerance=1.0e-5,
1888 angular_tolerance = 1.0e-4 ;
1889 Standard_Integer optiontab,i;
1893 optiontab=Draw::Atoi(c[2]);
1895 tolerance=Draw::Atof(c[3]);
1897 angular_tolerance = Draw::Atof(c[4]) ;
1898 Handle(Geom2d_Curve) ACurve = DrawTrSurf::GetCurve2d(c[1]);
1900 Standard_Real f = ACurve->FirstParameter();
1901 Standard_Real l = ACurve->LastParameter();
1903 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1904 di << " Error: Infinite curves\n";
1908 Handle(Geom2d_BSplineCurve) BS = Geom2dConvert::CurveToBSplineCurve(ACurve);
1910 if ( BS.IsNull()) return 1;
1913 Handle(TColGeom2d_HArray1OfBSplineCurve) tabBS;
1914 Geom2dConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1918 for (i=0;i<=(tabBS->Length()-1);i++){
1919 Sprintf(name,"%s_%d",c[1],i+1);
1920 Standard_CString new_name = name ;
1921 DrawTrSurf::Set(new_name,
1923 di.AppendElement(name);
1927 Geom2dConvert::C0BSplineToC1BSplineCurve(BS,tolerance);
1928 DrawTrSurf::Set(c[1],BS);
1933 //=======================================================================
1934 //function : canceldenom
1935 //purpose : set the value of the denominator cancel its first
1936 // derivative on the boundaries of the surface if possible
1937 //=======================================================================
1939 static Standard_Integer canceldenom(Draw_Interpretor& ,
1940 Standard_Integer n, const char** c)
1942 {Standard_Integer uoption,voption;
1943 Standard_Boolean udirection=Standard_False;
1944 Standard_Boolean vdirection=Standard_False;
1946 uoption=Draw::Atoi(c[2]);
1947 voption=Draw::Atoi(c[3]);
1949 udirection=Standard_True;
1951 vdirection=Standard_True;
1952 Handle(Geom_BSplineSurface) BSurf = DrawTrSurf::GetBSplineSurface(c[1]);
1953 GeomLib::CancelDenominatorDerivative(BSurf,udirection,vdirection);
1954 DrawTrSurf::Set(c[1],BSurf);
1958 //=======================================================================
1960 //purpose : eval curve's length
1961 //=======================================================================
1963 static Standard_Integer length(Draw_Interpretor& di,
1964 Standard_Integer n, const char** a)
1967 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
1968 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[1]);
1969 Standard_Real Tol = Precision::Confusion(), L;
1970 if (n==3) Tol = Draw::Atof(a[2]);
1973 GeomAdaptor_Curve AC(GC);
1974 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1976 else if (!GC2d.IsNull()) {
1977 Geom2dAdaptor_Curve AC(GC2d);
1978 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1981 di << a[1] << "is not a curve\n";
1985 di << "The length " << a[1] << " is " << L << "\n";
1991 //=======================================================================
1992 //function : CurveCommands
1994 //=======================================================================
1996 void GeomliteTest::CurveCommands(Draw_Interpretor& theCommands)
1999 static Standard_Boolean loaded = Standard_False;
2001 loaded = Standard_True;
2003 DrawTrSurf::BasicCommands(theCommands);
2009 g = "GEOMETRY curves creation";
2012 theCommands.Add("point",
2013 "point name x y [z]",
2017 theCommands.Add("line",
2018 "line name pos dir",
2022 theCommands.Add("circle",
2023 "circle name x y [z [dx dy dz]] [ux uy [uz]] radius",
2027 theCommands.Add("ellipse",
2028 "ellipse name x y [z [dx dy dz]] [ux uy [uz]] major minor",
2031 theCommands.Add("parabola",
2032 "parabola name x y [z [dx dy dz]] [ux uy [uz]] focal",
2035 theCommands.Add("hyperbola",
2036 "hyperbola name x y [z [dx dy dz]] [ux uy [uz]] major minor",
2040 theCommands.Add("beziercurve",
2041 "beziercurve name nbpole pole, [weight]",
2045 theCommands.Add("bsplinecurve",
2046 "bsplinecurve name degree nbknots knot, umult pole, weight",
2050 theCommands.Add("pbsplinecurve",
2051 "pbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
2055 theCommands.Add("2dbeziercurve",
2056 "2dbeziercurve name nbpole pole, [weight]",
2060 theCommands.Add("2dbsplinecurve",
2061 "2dbsplinecurve name degree nbknots knot, umult pole, weight",
2065 theCommands.Add("2dpbsplinecurve",
2066 "2dpbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
2070 g = "GEOMETRY Curves and Surfaces modification";
2072 theCommands.Add("reverse",
2073 "reverse name ... ",
2077 theCommands.Add("cmovep",
2078 "cmovep name index dx dy dz",
2082 theCommands.Add("cmovepoint",
2083 "cmovepoint name u dx dy [dz index1 index2]",
2087 theCommands.Add("cmovetangent",
2088 "cmovetangent name u x y [z] tx ty [tz constraint = 0]",
2092 theCommands.Add("insertknot",
2093 "insertknot name knot [mult = 1] [knot mult ...]",
2097 theCommands.Add("setknot",
2098 "setknot name index knot [mult]",
2102 theCommands.Add("remknot",
2103 "remknot name index [mult] [tol]",
2107 theCommands.Add("incdeg",
2108 "incdeg name degree",
2112 theCommands.Add("rempole",
2113 "rempole name index",
2117 theCommands.Add("insertpole",
2118 "insertpole name index x y [z] [weight]",
2122 theCommands.Add("cfindp",
2123 "cfindp name view x y index",
2127 theCommands.Add("setperiodic",
2128 "setperiodic name ...",
2132 theCommands.Add("setnotperiodic",
2133 "setnotperiodic name",
2137 theCommands.Add("segment",
2138 "segment name Ufirst Ulast",
2142 theCommands.Add("setorigin",
2143 "setorigin name knotindex",
2147 g = "GEOMETRY curves and surfaces analysis";
2149 theCommands.Add("cvalue",
2150 "cvalue curvename U X Y Z [D1X D1Y D1Z D2X D2Y D2Z]",
2154 theCommands.Add("2dcvalue",
2155 "2dcvalue curvename U X Y [D1X D1Y D2X D2Y]",
2159 theCommands.Add("coord",
2160 "coord P x y [z]: set in x y [z] the coordinates of P",
2164 theCommands.Add("minmaxcurandinf",
2165 "minmaxcurandinf curve",
2169 theCommands.Add("shcurvature",
2170 "shcurvature curvename",
2174 theCommands.Add("clcurvature",
2175 "clcurvature curvename",
2180 theCommands.Add("radiusmax",
2181 "radiusmax curvename radius",
2185 theCommands.Add("radiusratio",
2186 "radiusratio curvename ratio",
2189 theCommands.Add("localprop",
2190 "localprop curvename U",
2193 theCommands.Add("rawcont",
2194 "rawcont curve1 curve2 u1 u2",
2197 theCommands.Add("approxcurve",
2198 "approxcurve [-L] name curve1 [Surf1] [curve2d2 Surf2] [Tol [cont [maxdeg [maxseg]]]] ",
2202 theCommands.Add("approxcurveonsurf",
2203 "approxcurveonsurf name curve2d surface [Tol [cont [maxdeg [maxseg]]]] ",
2205 approxcurveonsurf,g);
2207 theCommands.Add("fitcurve", "fitcurve result curve [tol [maxdeg [inverse]]]", __FILE__, fitcurve, g);
2209 theCommands.Add("length", "length curve [Tol]",
2214 theCommands.Add("splitc1",
2215 "splitc1 bspline resultinarray(0/1) [tol] [angtol] ",
2219 theCommands.Add("splitc12d",
2220 "splitc12d bspline2d resultinarray(0/1) [tol] [angtol] ",
2223 theCommands.Add("canceldenom",
2224 "canceldenom BSpline-Surface UDirection(0/1) VDirection(0/1)",