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 || n > 5) 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]);
1143 Standard_Real aTolerance = Precision::PConfusion();
1145 aTolerance = Draw::Atof(a[4]);
1149 else if (!GBs.IsNull())
1150 GBs->Segment(f, l, aTolerance);
1151 else if (!GBz2d.IsNull())
1152 GBz2d->Segment(f,l);
1153 else if (!GBs2d.IsNull())
1154 GBs2d->Segment(f, l, aTolerance);
1163 //=======================================================================
1164 //function : setorigin
1166 //=======================================================================
1168 static Standard_Integer setorigin (Draw_Interpretor& , Standard_Integer n, const char** a)
1170 if (n < 3) return 1;
1172 Handle(Geom_BSplineCurve) GBs = DrawTrSurf::GetBSplineCurve(a[1]);
1173 Handle(Geom2d_BSplineCurve) GBs2d = DrawTrSurf::GetBSplineCurve2d(a[1]);
1176 GBs->SetOrigin(Draw::Atoi(a[2]));
1177 if (!GBs2d.IsNull())
1178 GBs2d->SetOrigin(Draw::Atoi(a[2]));
1187 //=======================================================================
1190 //=======================================================================
1192 static Standard_Integer point(Draw_Interpretor& , Standard_Integer n, const char** a)
1194 if (n < 4) return 1;
1196 gp_Pnt P(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
1197 DrawTrSurf::Set(a[1],P);
1200 gp_Pnt2d P(Draw::Atof(a[2]),Draw::Atof(a[3]));
1201 DrawTrSurf::Set(a[1],P);
1207 //=======================================================================
1210 //=======================================================================
1212 static Standard_Integer coord(Draw_Interpretor&,
1213 Standard_Integer n, const char** a)
1217 if ( !DrawTrSurf::GetPoint2d(a[1],P)) return 1;
1218 Draw::Set(a[2],P.X());
1219 Draw::Set(a[3],P.Y());
1223 if ( !DrawTrSurf::GetPoint(a[1],P)) return 1;
1224 Draw::Set(a[2],P.X());
1225 Draw::Set(a[3],P.Y());
1226 Draw::Set(a[4],P.Z());
1234 //=======================================================================
1237 //=======================================================================
1238 static Standard_Integer minmaxcurandinf(Draw_Interpretor& di,
1239 Standard_Integer argc, const char** argv)
1241 if (argc < 2) return 1;
1243 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(argv[1]);
1244 if (C1.IsNull()) return 1;
1247 Geom2dLProp_CurAndInf2d Sommets;
1249 Sommets.PerformCurExt (C1);
1250 if (Sommets.IsDone() && !Sommets.IsEmpty()) {
1251 for (Standard_Integer i = 1; i <= Sommets.NbPoints(); i++){
1252 Couleur = Draw_vert;
1253 if (Sommets.Type(i) == LProp_MinCur) {
1254 Couleur = Draw_orange;
1255 di << " Maximum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1258 di << " Minimum of curvature at U ="<<Sommets.Parameter(i)<<"\n";
1260 gp_Pnt2d P = C1->Value(Sommets.Parameter(i));
1261 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Couleur);
1267 Geom2dLProp_CurAndInf2d Sommets2;
1268 Sommets2.PerformInf (C1);
1270 if (Sommets2.IsDone() && !Sommets2.IsEmpty()) {
1271 for (Standard_Integer i = 1; i <= Sommets2.NbPoints(); i++){
1272 gp_Pnt2d P = C1->Value(Sommets2.Parameter(i));
1273 Handle(Draw_Marker2D) dr = new Draw_Marker2D(P,Draw_Plus,Draw_bleu);
1275 di << " Inflexion at U ="<<Sommets2.Parameter(i)<<"\n";
1281 //=======================================================================
1282 //function : shcurvature
1283 //purpose : affiche le peigne de courbure
1284 //=======================================================================
1285 static Standard_Integer shcurvature(Draw_Interpretor&,
1286 Standard_Integer argc, const char** argv)
1288 if (argc < 2) return 1;
1290 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1291 ::DownCast(Draw::Get(argv[1]));
1292 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1293 ::DownCast(Draw::Get(argv[1]));
1296 if (C3d.IsNull()) return 1;
1297 C3d->ShowCurvature();
1300 C2d->ShowCurvature();
1306 //=======================================================================
1307 //function : clcurvature
1308 //purpose : efface le peigne de courbure
1309 //=======================================================================
1310 static Standard_Integer clcurvature(Draw_Interpretor&,
1311 Standard_Integer argc, const char** argv)
1313 if (argc < 2) return 1;
1314 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1315 ::DownCast(Draw::Get(argv[1]));
1316 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1317 ::DownCast(Draw::Get(argv[1]));
1320 if (C3d.IsNull()) return 1;
1321 C3d->ClearCurvature();
1324 C2d->ClearCurvature();
1330 //=======================================================================
1331 //function : radiusmax
1332 //purpose : definit le rayon de courbure maximum a afficher
1333 //=======================================================================
1334 static Standard_Integer radiusmax(Draw_Interpretor&,
1335 Standard_Integer argc, const char** argv)
1337 if (argc < 3) return 1;
1338 Standard_Real Radius = Draw::Atof(argv[2]);
1339 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1340 ::DownCast(Draw::Get(argv[1]));
1341 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1342 ::DownCast(Draw::Get(argv[1]));
1345 if (C3d.IsNull()) return 1;
1346 C3d->SetRadiusMax(Radius);
1349 C2d->SetRadiusMax(Radius);
1355 //=======================================================================
1356 //function : radiusratio
1357 //purpose : definit le ratio du rayon de courbure a afficher
1358 //=======================================================================
1359 static Standard_Integer radiusratio(Draw_Interpretor&,
1360 Standard_Integer argc, const char** argv)
1362 if (argc < 3) return 1;
1363 Standard_Real Ratio = Draw::Atof(argv[2]);
1364 Handle(DrawTrSurf_Curve2d) C2d = Handle(DrawTrSurf_Curve2d)
1365 ::DownCast(Draw::Get(argv[1]));
1366 Handle(DrawTrSurf_Curve) C3d = Handle(DrawTrSurf_Curve)
1367 ::DownCast(Draw::Get(argv[1]));
1370 if (C3d.IsNull()) return 1;
1371 C3d->SetRadiusRatio(Ratio);
1374 C2d->SetRadiusRatio(Ratio);
1380 //=======================================================================
1383 //=======================================================================
1384 static Standard_Integer localprop(Draw_Interpretor& di,
1385 Standard_Integer argc, const char** argv)
1387 if (argc < 3) return 1;
1389 Standard_Real U = Draw::Atof(argv[2]);
1391 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(argv[1]);
1392 Handle(Geom_Curve) C3d;
1396 C3d = DrawTrSurf::GetCurve(argv[1]);
1397 if (C3d.IsNull()) return 1;
1398 GeomLProp_CLProps Prop (C3d,2,Precision::Confusion());
1399 Prop.SetParameter(U);
1400 Handle(Draw_Marker3D)drp = new Draw_Marker3D(Prop.Value(),
1404 if (Prop.IsTangentDefined()) {
1405 Standard_Real K = Prop.Curvature();
1406 di <<" Curvature : "<<K<<"\n";
1408 if (Abs(K) > Precision::Confusion()) {
1409 Standard_Real R = 1/Abs(K);
1411 Prop.CentreOfCurvature(Center);
1416 gp_Dir AxC = Nor^Tang;
1417 gp_Ax2 Axe(Center,AxC,Nor);
1418 Handle(Geom_Circle) Cir3d = new Geom_Circle(Axe,R);
1419 Handle(DrawTrSurf_Curve) dr;
1420 dr = new DrawTrSurf_Curve(Cir3d);
1426 di <<"Tangent undefined.\n";
1429 Geom2dLProp_CLProps2d Prop (C2d,2,Precision::Confusion());
1430 Prop.SetParameter(U);
1431 Handle(Draw_Marker2D) drp = new Draw_Marker2D(Prop.Value(),
1435 if (Prop.IsTangentDefined()) {
1436 Standard_Real K = Prop.Curvature();
1439 di <<" Curvature : "<<K<<"\n";
1441 if (Abs(K) > Precision::Confusion()) {
1442 Standard_Real R = 1/Abs(K);
1443 Prop.CentreOfCurvature(Center);
1444 gp_Ax2d Axe(Center,gp::DX2d());
1445 Handle(Geom2d_Circle) Cir2d = new Geom2d_Circle(Axe,R);
1446 Handle(DrawTrSurf_Curve2d) dr;
1447 dr = new DrawTrSurf_Curve2d(Cir2d,Draw_rouge,30,Standard_False);
1453 di <<"Tangent undefined.\n";
1457 //=======================================================================
1458 //function : rawcont
1460 //=======================================================================
1462 static Standard_Integer rawcont(Draw_Interpretor& di, Standard_Integer n, const char** a)
1464 if (n < 5) return 1;
1466 Handle(Geom_Curve) GC1;
1467 GC1 = DrawTrSurf::GetCurve(a[1]);
1468 Handle(Geom_Curve) GC2;
1469 GC2 = DrawTrSurf::GetCurve(a[2]);
1470 Standard_Real param1 =
1472 Standard_Real param2 =
1474 if (GC1.IsNull() || GC2.IsNull())
1482 if (a_point2.SquareDistance(a_point1) < Precision::Confusion()) {
1483 GeomAbs_Shape cont =
1484 GeomLProp::Continuity(GC1,
1490 Precision::Confusion(),
1491 Precision::Angular()) ;
1494 di << " C0 Continuity \n" ;
1497 di << " G1 Continuity \n" ;
1500 di << " C1 Continuity \n" ;
1503 di << " G2 Continuity \n" ;
1506 di << " C2 Continuity \n" ;
1509 di << " C3 Continuity \n" ;
1512 di << " CN Continuity \n" ;
1519 di << " not C0 continuity \n" ;
1523 //=======================================================================
1524 //function : approxcurveonsurf
1526 //=======================================================================
1527 static Standard_Integer approxcurveonsurf(Draw_Interpretor& di, Standard_Integer n, const char** a)
1529 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1530 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1531 Standard_Integer MaxDeg = 14; // Maximum degree
1532 Standard_Integer MaxSeg = 16; /*1*/ // Maximum number of segments
1534 if ( n>8 || n<4) return 1;
1536 if (n>4) Tol = Max(Draw::Atof(a[4]),1.e-10);
1539 if (Draw::Atoi(a[5]) == 0) Continuity = GeomAbs_C0;
1540 if (Draw::Atoi(a[5]) == 2) Continuity = GeomAbs_C2;
1544 MaxDeg = Draw::Atoi(a[6]);
1545 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1548 if (n>7) MaxSeg = Draw::Atoi(a[7]);
1549 Handle(Geom2d_Curve) curve2d = DrawTrSurf::GetCurve2d(a[2]);
1550 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[3]);
1552 Handle(Geom2dAdaptor_HCurve) A2d = new (Geom2dAdaptor_HCurve)(curve2d);
1553 Handle(GeomAdaptor_HSurface) AS = new (GeomAdaptor_HSurface)(Surf);
1555 Approx_CurveOnSurface App(A2d, AS, A2d->FirstParameter(), A2d->LastParameter(),
1556 Tol, Continuity, MaxDeg, MaxSeg,
1557 Standard_True, Standard_False);
1559 if(App.HasResult()) {
1560 Handle(Geom_BSplineCurve) BSCurve = App.Curve3d();
1561 DrawTrSurf::Set(a[1], BSCurve);
1565 di << "Approximation failed !\n";
1570 //=======================================================================
1571 //function : approxcurve
1573 //=======================================================================
1574 static Standard_Integer approxcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1576 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1577 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1578 Standard_Integer MaxDeg = 14; // Maximum degree
1579 Standard_Integer MaxSeg = 16; // Maximum number of segments
1581 Standard_Integer Case, shift;
1582 // Case == 1 : 3d approximation without reparametrization
1583 // Case == 2 : 2d approximation without reparametrization
1584 // Case == 3 : 3d approximation with reparametrization
1585 // Case == 4 : curve_on_surface approximation with reparametrization
1586 // Case == 5 : 2 curves_on_surfaces approximation with reparametrization
1588 Handle(Geom_Curve) curve;
1589 Handle(Geom2d_Curve) curve2d, curve2d2;
1590 Handle(Geom_Surface) surface, surface2;
1594 if (!strcmp(a[1],"-L")) {
1595 // aproximation with curvilinear abscissa reparametrization
1596 if (n > 11 || n < 4) return 1;
1598 curve = DrawTrSurf::GetCurve(a[3]);
1599 if (!curve.IsNull()) {
1604 // approx curve_on_surface
1605 if (n < 5) return 1;
1606 curve2d = DrawTrSurf::GetCurve2d(a[3]);
1607 surface = DrawTrSurf::GetSurface(a[4]);
1608 if (curve2d.IsNull() || surface.IsNull()) {
1612 curve2d2 = DrawTrSurf::GetCurve2d(a[5]);
1613 surface2 = DrawTrSurf::GetSurface(a[6]);
1614 if (curve2d2.IsNull() || surface2.IsNull()) {
1619 // approx 2 curves_on_surfaces
1631 // aproximation without reparamitrization
1632 if ( n>7 || n<3) return 1;
1634 curve = DrawTrSurf::GetCurve(a[2]);
1635 if (curve.IsNull()) {
1636 curve2d = DrawTrSurf::GetCurve2d(a[2]);
1637 if (curve2d.IsNull()) {
1646 if (n>shift) Tol = Max(Draw::Atof(a[shift]),1.e-10);
1649 if (Draw::Atoi(a[shift+1]) == 0) Continuity = GeomAbs_C0;
1650 if (Draw::Atoi(a[shift+1]) == 2) Continuity = GeomAbs_C2;
1654 MaxDeg = Draw::Atoi(a[shift+2]);
1655 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1658 if (n>shift+3) MaxSeg = Draw::Atoi(a[shift+3]);
1661 GeomConvert_ApproxCurve appr(curve, Tol, Continuity, MaxSeg, MaxDeg);
1662 if(appr.HasResult()) {
1664 Standard_SStream aSStream;
1665 appr.Dump(aSStream);
1667 Handle(Geom_BSplineCurve) BSCurve = appr.Curve();
1668 DrawTrSurf::Set(a[1], BSCurve);
1672 else if (Case == 2) {
1673 Geom2dConvert_ApproxCurve appr(curve2d, Tol, Continuity, MaxSeg, MaxDeg);
1674 if(appr.HasResult()) {
1676 Standard_SStream aSStream;
1677 appr.Dump(aSStream);
1679 Handle(Geom2d_BSplineCurve) BSCurve = appr.Curve();
1680 DrawTrSurf::Set(a[1], BSCurve);
1684 else if (Case == 3) {
1685 Handle(Adaptor3d_HCurve) HACur = new GeomAdaptor_HCurve(curve);
1686 Approx_CurvilinearParameter appr(HACur, Tol, Continuity, MaxDeg, MaxSeg);
1687 if(appr.HasResult()) {
1689 Standard_SStream aSStream;
1690 appr.Dump(aSStream);
1692 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1693 DrawTrSurf::Set(a[2], BSCurve);
1696 else if (Case == 4) {
1697 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1698 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1699 Approx_CurvilinearParameter appr(HACur2d, HASur, Tol, Continuity, MaxDeg, MaxSeg);
1700 if(appr.HasResult()) {
1702 Standard_SStream aSStream;
1703 appr.Dump(aSStream);
1705 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1706 DrawTrSurf::Set(a[2], BSCurve);
1710 else if (Case == 5) {
1711 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1712 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1713 Handle(Adaptor2d_HCurve2d) HACur2d2 = new Geom2dAdaptor_HCurve(curve2d2);
1714 Handle(Adaptor3d_HSurface) HASur2 = new GeomAdaptor_HSurface(surface2);
1715 Approx_CurvilinearParameter appr(HACur2d, HASur, HACur2d2, HASur2, Tol, Continuity, MaxDeg, MaxSeg);
1716 if(appr.HasResult()) {
1718 Standard_SStream aSStream;
1719 appr.Dump(aSStream);
1721 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1722 DrawTrSurf::Set(a[2], BSCurve);
1731 //=======================================================================
1732 //function : fitcurve
1734 //=======================================================================
1736 static Standard_Integer fitcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1740 Handle(Geom_Curve) GC;
1741 GC = DrawTrSurf::GetCurve(a[2]);
1745 Standard_Integer Dmin = 3;
1746 Standard_Integer Dmax = 14;
1747 Standard_Real Tol3d = 1.e-5;
1748 Standard_Boolean inverse = Standard_True;
1762 Standard_Integer inv = atoi(a[5]);
1765 inverse = Standard_True;
1769 inverse = Standard_False;
1773 Handle(GeomAdaptor_HCurve) aGAC = new GeomAdaptor_HCurve(GC);
1775 CurveEvaluator aCE(aGAC);
1777 Approx_FitAndDivide anAppro(Dmin, Dmax, Tol3d, 0., Standard_True);
1778 anAppro.SetInvOrder(inverse);
1779 anAppro.Perform(aCE);
1781 if (!anAppro.IsAllApproximated())
1783 di << "Approximation failed \n";
1787 Standard_Integer NbCurves = anAppro.NbMultiCurves();
1789 Convert_CompBezierCurvesToBSplineCurve Conv;
1791 Standard_Real tol3d, tol2d, tolreached = 0.;
1792 for (i = 1; i <= NbCurves; i++) {
1793 anAppro.Error(i, tol3d, tol2d);
1794 tolreached = Max(tolreached, tol3d);
1795 AppParCurves_MultiCurve MC = anAppro.Value(i);
1796 TColgp_Array1OfPnt Poles(1, MC.Degree() + 1);
1798 Conv.AddCurve(Poles);
1801 Standard_Integer NbPoles = Conv.NbPoles();
1802 Standard_Integer NbKnots = Conv.NbKnots();
1804 TColgp_Array1OfPnt NewPoles(1, NbPoles);
1805 TColStd_Array1OfReal NewKnots(1, NbKnots);
1806 TColStd_Array1OfInteger NewMults(1, NbKnots);
1808 Conv.KnotsAndMults(NewKnots, NewMults);
1809 Conv.Poles(NewPoles);
1811 BSplCLib::Reparametrize(GC->FirstParameter(),
1812 GC->LastParameter(),
1814 Handle(Geom_BSplineCurve) TheCurve = new Geom_BSplineCurve(NewPoles, NewKnots, NewMults, Conv.Degree());
1816 DrawTrSurf::Set(a[1], TheCurve);
1817 di << a[1] << ": tolreached = " << tolreached << "\n";
1823 //=======================================================================
1824 //function : newbspline
1825 //purpose : reduce the multiplicity of the knots to their minimum
1826 // compared to the degree of the curve
1827 //=======================================================================
1829 static Standard_Integer splitc1(Draw_Interpretor& di,
1830 Standard_Integer n, const char** c)
1832 {Standard_Real tolerance=1.0e-5,
1833 angular_tolerance = 1.0e-4 ;
1834 Standard_Integer optiontab,i;
1838 optiontab=Draw::Atoi(c[2]);
1840 tolerance=Draw::Atof(c[3]);
1842 angular_tolerance = Draw::Atof(c[4]) ;
1844 Handle(Geom_Curve) ACurve = Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(c[1])) ;
1846 Standard_Real f = ACurve->FirstParameter();
1847 Standard_Real l = ACurve->LastParameter();
1849 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1850 di << " Error: Infinite curves\n";
1854 Handle(Geom_BSplineCurve) BS = GeomConvert::CurveToBSplineCurve(ACurve);
1856 if ( BS.IsNull()) return 1;
1859 Handle(TColGeom_HArray1OfBSplineCurve) tabBS;
1860 GeomConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1864 for (i=0;i<=(tabBS->Length()-1);i++){
1865 Sprintf(name,"%s_%d",c[1],i+1);
1866 Standard_CString new_name = name ;
1867 DrawTrSurf::Set(new_name,
1869 di.AppendElement(name);
1873 GeomConvert::C0BSplineToC1BSplineCurve(BS,
1875 angular_tolerance) ;
1877 DrawTrSurf::Set(c[1],BS);
1882 //=======================================================================
1883 //function : splitc12d
1884 //purpose : reduce the multiplicity of the knots to their minimum
1885 // compared to the degree of the curve
1886 //=======================================================================
1888 static Standard_Integer splitc12d(Draw_Interpretor& di,
1889 Standard_Integer n, const char** c)
1891 {Standard_Real tolerance=1.0e-5,
1892 angular_tolerance = 1.0e-4 ;
1893 Standard_Integer optiontab,i;
1897 optiontab=Draw::Atoi(c[2]);
1899 tolerance=Draw::Atof(c[3]);
1901 angular_tolerance = Draw::Atof(c[4]) ;
1902 Handle(Geom2d_Curve) ACurve = DrawTrSurf::GetCurve2d(c[1]);
1904 Standard_Real f = ACurve->FirstParameter();
1905 Standard_Real l = ACurve->LastParameter();
1907 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1908 di << " Error: Infinite curves\n";
1912 Handle(Geom2d_BSplineCurve) BS = Geom2dConvert::CurveToBSplineCurve(ACurve);
1914 if ( BS.IsNull()) return 1;
1917 Handle(TColGeom2d_HArray1OfBSplineCurve) tabBS;
1918 Geom2dConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1922 for (i=0;i<=(tabBS->Length()-1);i++){
1923 Sprintf(name,"%s_%d",c[1],i+1);
1924 Standard_CString new_name = name ;
1925 DrawTrSurf::Set(new_name,
1927 di.AppendElement(name);
1931 Geom2dConvert::C0BSplineToC1BSplineCurve(BS,tolerance);
1932 DrawTrSurf::Set(c[1],BS);
1937 //=======================================================================
1938 //function : canceldenom
1939 //purpose : set the value of the denominator cancel its first
1940 // derivative on the boundaries of the surface if possible
1941 //=======================================================================
1943 static Standard_Integer canceldenom(Draw_Interpretor& ,
1944 Standard_Integer n, const char** c)
1946 {Standard_Integer uoption,voption;
1947 Standard_Boolean udirection=Standard_False;
1948 Standard_Boolean vdirection=Standard_False;
1950 uoption=Draw::Atoi(c[2]);
1951 voption=Draw::Atoi(c[3]);
1953 udirection=Standard_True;
1955 vdirection=Standard_True;
1956 Handle(Geom_BSplineSurface) BSurf = DrawTrSurf::GetBSplineSurface(c[1]);
1957 GeomLib::CancelDenominatorDerivative(BSurf,udirection,vdirection);
1958 DrawTrSurf::Set(c[1],BSurf);
1962 //=======================================================================
1964 //purpose : eval curve's length
1965 //=======================================================================
1967 static Standard_Integer length(Draw_Interpretor& di,
1968 Standard_Integer n, const char** a)
1971 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
1972 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[1]);
1973 Standard_Real Tol = Precision::Confusion(), L;
1974 if (n==3) Tol = Draw::Atof(a[2]);
1977 GeomAdaptor_Curve AC(GC);
1978 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1980 else if (!GC2d.IsNull()) {
1981 Geom2dAdaptor_Curve AC(GC2d);
1982 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1985 di << a[1] << "is not a curve\n";
1989 di << "The length " << a[1] << " is " << L << "\n";
1995 //=======================================================================
1996 //function : CurveCommands
1998 //=======================================================================
2000 void GeomliteTest::CurveCommands(Draw_Interpretor& theCommands)
2003 static Standard_Boolean loaded = Standard_False;
2005 loaded = Standard_True;
2007 DrawTrSurf::BasicCommands(theCommands);
2013 g = "GEOMETRY curves creation";
2016 theCommands.Add("point",
2017 "point name x y [z]",
2021 theCommands.Add("line",
2022 "line name pos dir",
2026 theCommands.Add("circle",
2027 "circle name x y [z [dx dy dz]] [ux uy [uz]] radius",
2031 theCommands.Add("ellipse",
2032 "ellipse name x y [z [dx dy dz]] [ux uy [uz]] major minor",
2035 theCommands.Add("parabola",
2036 "parabola name x y [z [dx dy dz]] [ux uy [uz]] focal",
2039 theCommands.Add("hyperbola",
2040 "hyperbola name x y [z [dx dy dz]] [ux uy [uz]] major minor",
2044 theCommands.Add("beziercurve",
2045 "beziercurve name nbpole pole, [weight]",
2049 theCommands.Add("bsplinecurve",
2050 "bsplinecurve name degree nbknots knot, umult pole, weight",
2054 theCommands.Add("pbsplinecurve",
2055 "pbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
2059 theCommands.Add("2dbeziercurve",
2060 "2dbeziercurve name nbpole pole, [weight]",
2064 theCommands.Add("2dbsplinecurve",
2065 "2dbsplinecurve name degree nbknots knot, umult pole, weight",
2069 theCommands.Add("2dpbsplinecurve",
2070 "2dpbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
2074 g = "GEOMETRY Curves and Surfaces modification";
2076 theCommands.Add("reverse",
2077 "reverse name ... ",
2081 theCommands.Add("cmovep",
2082 "cmovep name index dx dy dz",
2086 theCommands.Add("cmovepoint",
2087 "cmovepoint name u dx dy [dz index1 index2]",
2091 theCommands.Add("cmovetangent",
2092 "cmovetangent name u x y [z] tx ty [tz constraint = 0]",
2096 theCommands.Add("insertknot",
2097 "insertknot name knot [mult = 1] [knot mult ...]",
2101 theCommands.Add("setknot",
2102 "setknot name index knot [mult]",
2106 theCommands.Add("remknot",
2107 "remknot name index [mult] [tol]",
2111 theCommands.Add("incdeg",
2112 "incdeg name degree",
2116 theCommands.Add("rempole",
2117 "rempole name index",
2121 theCommands.Add("insertpole",
2122 "insertpole name index x y [z] [weight]",
2126 theCommands.Add("cfindp",
2127 "cfindp name view x y index",
2131 theCommands.Add("setperiodic",
2132 "setperiodic name ...",
2136 theCommands.Add("setnotperiodic",
2137 "setnotperiodic name",
2141 theCommands.Add("segment",
2142 "segment name Ufirst Ulast [tol]",
2146 theCommands.Add("setorigin",
2147 "setorigin name knotindex",
2151 g = "GEOMETRY curves and surfaces analysis";
2153 theCommands.Add("cvalue",
2154 "cvalue curvename U X Y Z [D1X D1Y D1Z D2X D2Y D2Z]",
2158 theCommands.Add("2dcvalue",
2159 "2dcvalue curvename U X Y [D1X D1Y D2X D2Y]",
2163 theCommands.Add("coord",
2164 "coord P x y [z]: set in x y [z] the coordinates of P",
2168 theCommands.Add("minmaxcurandinf",
2169 "minmaxcurandinf curve",
2173 theCommands.Add("shcurvature",
2174 "shcurvature curvename",
2178 theCommands.Add("clcurvature",
2179 "clcurvature curvename",
2184 theCommands.Add("radiusmax",
2185 "radiusmax curvename radius",
2189 theCommands.Add("radiusratio",
2190 "radiusratio curvename ratio",
2193 theCommands.Add("localprop",
2194 "localprop curvename U",
2197 theCommands.Add("rawcont",
2198 "rawcont curve1 curve2 u1 u2",
2201 theCommands.Add("approxcurve",
2202 "approxcurve [-L] name curve1 [Surf1] [curve2d2 Surf2] [Tol [cont [maxdeg [maxseg]]]] ",
2206 theCommands.Add("approxcurveonsurf",
2207 "approxcurveonsurf name curve2d surface [Tol [cont [maxdeg [maxseg]]]] ",
2209 approxcurveonsurf,g);
2211 theCommands.Add("fitcurve", "fitcurve result curve [tol [maxdeg [inverse]]]", __FILE__, fitcurve, g);
2213 theCommands.Add("length", "length curve [Tol]",
2218 theCommands.Add("splitc1",
2219 "splitc1 bspline resultinarray(0/1) [tol] [angtol] ",
2223 theCommands.Add("splitc12d",
2224 "splitc12d bspline2d resultinarray(0/1) [tol] [angtol] ",
2227 theCommands.Add("canceldenom",
2228 "canceldenom BSpline-Surface UDirection(0/1) VDirection(0/1)",