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(), Tol);
1556 App.Perform(MaxSeg, MaxDeg, Continuity, Standard_True, Standard_False);
1558 if(App.HasResult()) {
1559 Handle(Geom_BSplineCurve) BSCurve = App.Curve3d();
1560 DrawTrSurf::Set(a[1], BSCurve);
1564 di << "Approximation failed !\n";
1569 //=======================================================================
1570 //function : approxcurve
1572 //=======================================================================
1573 static Standard_Integer approxcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1575 Standard_Real Tol = 1.e-7; // Tolerance (default 0.1mm)
1576 GeomAbs_Shape Continuity = GeomAbs_C1; // Continuity order : 0, 1 or 2 (default 1)
1577 Standard_Integer MaxDeg = 14; // Maximum degree
1578 Standard_Integer MaxSeg = 16; // Maximum number of segments
1580 Standard_Integer Case, shift;
1581 // Case == 1 : 3d approximation without reparametrization
1582 // Case == 2 : 2d approximation without reparametrization
1583 // Case == 3 : 3d approximation with reparametrization
1584 // Case == 4 : curve_on_surface approximation with reparametrization
1585 // Case == 5 : 2 curves_on_surfaces approximation with reparametrization
1587 Handle(Geom_Curve) curve;
1588 Handle(Geom2d_Curve) curve2d, curve2d2;
1589 Handle(Geom_Surface) surface, surface2;
1593 if (!strcmp(a[1],"-L")) {
1594 // aproximation with curvilinear abscissa reparametrization
1595 if (n > 11 || n < 4) return 1;
1597 curve = DrawTrSurf::GetCurve(a[3]);
1598 if (!curve.IsNull()) {
1603 // approx curve_on_surface
1604 if (n < 5) return 1;
1605 curve2d = DrawTrSurf::GetCurve2d(a[3]);
1606 surface = DrawTrSurf::GetSurface(a[4]);
1607 if (curve2d.IsNull() || surface.IsNull()) {
1611 curve2d2 = DrawTrSurf::GetCurve2d(a[5]);
1612 surface2 = DrawTrSurf::GetSurface(a[6]);
1613 if (curve2d2.IsNull() || surface2.IsNull()) {
1618 // approx 2 curves_on_surfaces
1630 // aproximation without reparamitrization
1631 if ( n>7 || n<3) return 1;
1633 curve = DrawTrSurf::GetCurve(a[2]);
1634 if (curve.IsNull()) {
1635 curve2d = DrawTrSurf::GetCurve2d(a[2]);
1636 if (curve2d.IsNull()) {
1645 if (n>shift) Tol = Max(Draw::Atof(a[shift]),1.e-10);
1648 if (Draw::Atoi(a[shift+1]) == 0) Continuity = GeomAbs_C0;
1649 if (Draw::Atoi(a[shift+1]) == 2) Continuity = GeomAbs_C2;
1653 MaxDeg = Draw::Atoi(a[shift+2]);
1654 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1657 if (n>shift+3) MaxSeg = Draw::Atoi(a[shift+3]);
1660 GeomConvert_ApproxCurve appr(curve, Tol, Continuity, MaxSeg, MaxDeg);
1661 if(appr.HasResult()) {
1662 //appr.Dump(std::cout);
1663 Standard_SStream aSStream;
1664 appr.Dump(aSStream);
1666 Handle(Geom_BSplineCurve) BSCurve = appr.Curve();
1667 DrawTrSurf::Set(a[1], BSCurve);
1671 else if (Case == 2) {
1672 Geom2dConvert_ApproxCurve appr(curve2d, Tol, Continuity, MaxSeg, MaxDeg);
1673 if(appr.HasResult()) {
1674 //appr.Dump(std::cout);
1675 Standard_SStream aSStream;
1676 appr.Dump(aSStream);
1678 Handle(Geom2d_BSplineCurve) BSCurve = appr.Curve();
1679 DrawTrSurf::Set(a[1], BSCurve);
1683 else if (Case == 3) {
1684 Handle(Adaptor3d_HCurve) HACur = new GeomAdaptor_HCurve(curve);
1685 Approx_CurvilinearParameter appr(HACur, Tol, Continuity, MaxDeg, MaxSeg);
1686 if(appr.HasResult()) {
1687 //appr.Dump(std::cout);
1688 Standard_SStream aSStream;
1689 appr.Dump(aSStream);
1691 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1692 DrawTrSurf::Set(a[2], BSCurve);
1695 else if (Case == 4) {
1696 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1697 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1698 Approx_CurvilinearParameter appr(HACur2d, HASur, Tol, Continuity, MaxDeg, MaxSeg);
1699 if(appr.HasResult()) {
1700 //appr.Dump(std::cout);
1701 Standard_SStream aSStream;
1702 appr.Dump(aSStream);
1704 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1705 DrawTrSurf::Set(a[2], BSCurve);
1709 else if (Case == 5) {
1710 Handle(Adaptor2d_HCurve2d) HACur2d = new Geom2dAdaptor_HCurve(curve2d);
1711 Handle(Adaptor3d_HSurface) HASur = new GeomAdaptor_HSurface(surface);
1712 Handle(Adaptor2d_HCurve2d) HACur2d2 = new Geom2dAdaptor_HCurve(curve2d2);
1713 Handle(Adaptor3d_HSurface) HASur2 = new GeomAdaptor_HSurface(surface2);
1714 Approx_CurvilinearParameter appr(HACur2d, HASur, HACur2d2, HASur2, Tol, Continuity, MaxDeg, MaxSeg);
1715 if(appr.HasResult()) {
1716 //appr.Dump(std::cout);
1717 Standard_SStream aSStream;
1718 appr.Dump(aSStream);
1720 Handle(Geom_BSplineCurve) BSCurve = appr.Curve3d();
1721 DrawTrSurf::Set(a[2], BSCurve);
1730 //=======================================================================
1731 //function : fitcurve
1733 //=======================================================================
1735 static Standard_Integer fitcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
1739 Handle(Geom_Curve) GC;
1740 GC = DrawTrSurf::GetCurve(a[2]);
1744 Standard_Integer Dmin = 3;
1745 Standard_Integer Dmax = 14;
1746 Standard_Real Tol3d = 1.e-5;
1747 Standard_Boolean inverse = Standard_True;
1761 Standard_Integer inv = atoi(a[5]);
1764 inverse = Standard_True;
1768 inverse = Standard_False;
1772 Handle(GeomAdaptor_HCurve) aGAC = new GeomAdaptor_HCurve(GC);
1774 CurveEvaluator aCE(aGAC);
1776 Approx_FitAndDivide anAppro(Dmin, Dmax, Tol3d, 0., Standard_True);
1777 anAppro.SetInvOrder(inverse);
1778 anAppro.Perform(aCE);
1780 if (!anAppro.IsAllApproximated())
1782 di << "Approximation failed \n";
1786 Standard_Integer NbCurves = anAppro.NbMultiCurves();
1788 Convert_CompBezierCurvesToBSplineCurve Conv;
1790 Standard_Real tol3d, tol2d, tolreached = 0.;
1791 for (i = 1; i <= NbCurves; i++) {
1792 anAppro.Error(i, tol3d, tol2d);
1793 tolreached = Max(tolreached, tol3d);
1794 AppParCurves_MultiCurve MC = anAppro.Value(i);
1795 TColgp_Array1OfPnt Poles(1, MC.Degree() + 1);
1797 Conv.AddCurve(Poles);
1800 Standard_Integer NbPoles = Conv.NbPoles();
1801 Standard_Integer NbKnots = Conv.NbKnots();
1803 TColgp_Array1OfPnt NewPoles(1, NbPoles);
1804 TColStd_Array1OfReal NewKnots(1, NbKnots);
1805 TColStd_Array1OfInteger NewMults(1, NbKnots);
1807 Conv.KnotsAndMults(NewKnots, NewMults);
1808 Conv.Poles(NewPoles);
1810 BSplCLib::Reparametrize(GC->FirstParameter(),
1811 GC->LastParameter(),
1813 Handle(Geom_BSplineCurve) TheCurve = new Geom_BSplineCurve(NewPoles, NewKnots, NewMults, Conv.Degree());
1815 DrawTrSurf::Set(a[1], TheCurve);
1816 di << a[1] << ": tolreached = " << tolreached << "\n";
1822 //=======================================================================
1823 //function : newbspline
1824 //purpose : reduce the multiplicity of the knots to their minimum
1825 // compared to the degree of the curve
1826 //=======================================================================
1828 static Standard_Integer splitc1(Draw_Interpretor& di,
1829 Standard_Integer n, const char** c)
1831 {Standard_Real tolerance=1.0e-5,
1832 angular_tolerance = 1.0e-4 ;
1833 Standard_Integer optiontab,i;
1837 optiontab=Draw::Atoi(c[2]);
1839 tolerance=Draw::Atof(c[3]);
1841 angular_tolerance = Draw::Atof(c[4]) ;
1843 Handle(Geom_Curve) ACurve = Handle(Geom_Curve)::DownCast(DrawTrSurf::Get(c[1])) ;
1845 Standard_Real f = ACurve->FirstParameter();
1846 Standard_Real l = ACurve->LastParameter();
1848 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1849 di << " Error: Infinite curves\n";
1853 Handle(Geom_BSplineCurve) BS = GeomConvert::CurveToBSplineCurve(ACurve);
1855 if ( BS.IsNull()) return 1;
1858 Handle(TColGeom_HArray1OfBSplineCurve) tabBS;
1859 GeomConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1863 for (i=0;i<=(tabBS->Length()-1);i++){
1864 Sprintf(name,"%s_%d",c[1],i+1);
1865 Standard_CString new_name = name ;
1866 DrawTrSurf::Set(new_name,
1868 di.AppendElement(name);
1872 GeomConvert::C0BSplineToC1BSplineCurve(BS,
1874 angular_tolerance) ;
1876 DrawTrSurf::Set(c[1],BS);
1881 //=======================================================================
1882 //function : splitc12d
1883 //purpose : reduce the multiplicity of the knots to their minimum
1884 // compared to the degree of the curve
1885 //=======================================================================
1887 static Standard_Integer splitc12d(Draw_Interpretor& di,
1888 Standard_Integer n, const char** c)
1890 {Standard_Real tolerance=1.0e-5,
1891 angular_tolerance = 1.0e-4 ;
1892 Standard_Integer optiontab,i;
1896 optiontab=Draw::Atoi(c[2]);
1898 tolerance=Draw::Atof(c[3]);
1900 angular_tolerance = Draw::Atof(c[4]) ;
1901 Handle(Geom2d_Curve) ACurve = DrawTrSurf::GetCurve2d(c[1]);
1903 Standard_Real f = ACurve->FirstParameter();
1904 Standard_Real l = ACurve->LastParameter();
1906 if ( Precision::IsInfinite(f) || Precision::IsInfinite(l)) {
1907 di << " Error: Infinite curves\n";
1911 Handle(Geom2d_BSplineCurve) BS = Geom2dConvert::CurveToBSplineCurve(ACurve);
1913 if ( BS.IsNull()) return 1;
1916 Handle(TColGeom2d_HArray1OfBSplineCurve) tabBS;
1917 Geom2dConvert::C0BSplineToArrayOfC1BSplineCurve(BS,
1921 for (i=0;i<=(tabBS->Length()-1);i++){
1922 Sprintf(name,"%s_%d",c[1],i+1);
1923 Standard_CString new_name = name ;
1924 DrawTrSurf::Set(new_name,
1926 di.AppendElement(name);
1930 Geom2dConvert::C0BSplineToC1BSplineCurve(BS,tolerance);
1931 DrawTrSurf::Set(c[1],BS);
1936 //=======================================================================
1937 //function : canceldenom
1938 //purpose : set the value of the denominator cancel its first
1939 // derivative on the boundaries of the surface if possible
1940 //=======================================================================
1942 static Standard_Integer canceldenom(Draw_Interpretor& ,
1943 Standard_Integer n, const char** c)
1945 {Standard_Integer uoption,voption;
1946 Standard_Boolean udirection=Standard_False;
1947 Standard_Boolean vdirection=Standard_False;
1949 uoption=Draw::Atoi(c[2]);
1950 voption=Draw::Atoi(c[3]);
1952 udirection=Standard_True;
1954 vdirection=Standard_True;
1955 Handle(Geom_BSplineSurface) BSurf = DrawTrSurf::GetBSplineSurface(c[1]);
1956 GeomLib::CancelDenominatorDerivative(BSurf,udirection,vdirection);
1957 DrawTrSurf::Set(c[1],BSurf);
1961 //=======================================================================
1963 //purpose : eval curve's length
1964 //=======================================================================
1966 static Standard_Integer length(Draw_Interpretor& di,
1967 Standard_Integer n, const char** a)
1970 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
1971 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[1]);
1972 Standard_Real Tol = Precision::Confusion(), L;
1973 if (n==3) Tol = Draw::Atof(a[2]);
1976 GeomAdaptor_Curve AC(GC);
1977 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1979 else if (!GC2d.IsNull()) {
1980 Geom2dAdaptor_Curve AC(GC2d);
1981 L = GCPnts_AbscissaPoint::Length(AC, Tol);
1984 di << a[1] << "is not a curve\n";
1988 di << "The length " << a[1] << " is " << L << "\n";
1994 //=======================================================================
1995 //function : CurveCommands
1997 //=======================================================================
1999 void GeomliteTest::CurveCommands(Draw_Interpretor& theCommands)
2002 static Standard_Boolean loaded = Standard_False;
2004 loaded = Standard_True;
2006 DrawTrSurf::BasicCommands(theCommands);
2012 g = "GEOMETRY curves creation";
2015 theCommands.Add("point",
2016 "point name x y [z]",
2020 theCommands.Add("line",
2021 "line name pos dir",
2025 theCommands.Add("circle",
2026 "circle name x y [z [dx dy dz]] [ux uy [uz]] radius",
2030 theCommands.Add("ellipse",
2031 "ellipse name x y [z [dx dy dz]] [ux uy [uz]] major minor",
2034 theCommands.Add("parabola",
2035 "parabola name x y [z [dx dy dz]] [ux uy [uz]] focal",
2038 theCommands.Add("hyperbola",
2039 "hyperbola name x y [z [dx dy dz]] [ux uy [uz]] major minor",
2043 theCommands.Add("beziercurve",
2044 "beziercurve name nbpole pole, [weight]",
2048 theCommands.Add("bsplinecurve",
2049 "bsplinecurve name degree nbknots knot, umult pole, weight",
2053 theCommands.Add("pbsplinecurve",
2054 "pbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
2058 theCommands.Add("2dbeziercurve",
2059 "2dbeziercurve name nbpole pole, [weight]",
2063 theCommands.Add("2dbsplinecurve",
2064 "2dbsplinecurve name degree nbknots knot, umult pole, weight",
2068 theCommands.Add("2dpbsplinecurve",
2069 "2dpbsplinecurve name degree nbknots knot, umult pole, weight (periodic)",
2073 g = "GEOMETRY Curves and Surfaces modification";
2075 theCommands.Add("reverse",
2076 "reverse name ... ",
2080 theCommands.Add("cmovep",
2081 "cmovep name index dx dy dz",
2085 theCommands.Add("cmovepoint",
2086 "cmovepoint name u dx dy [dz index1 index2]",
2090 theCommands.Add("cmovetangent",
2091 "cmovetangent name u x y [z] tx ty [tz constraint = 0]",
2095 theCommands.Add("insertknot",
2096 "insertknot name knot [mult = 1] [knot mult ...]",
2100 theCommands.Add("setknot",
2101 "setknot name index knot [mult]",
2105 theCommands.Add("remknot",
2106 "remknot name index [mult] [tol]",
2110 theCommands.Add("incdeg",
2111 "incdeg name degree",
2115 theCommands.Add("rempole",
2116 "rempole name index",
2120 theCommands.Add("insertpole",
2121 "insertpole name index x y [z] [weight]",
2125 theCommands.Add("cfindp",
2126 "cfindp name view x y index",
2130 theCommands.Add("setperiodic",
2131 "setperiodic name ...",
2135 theCommands.Add("setnotperiodic",
2136 "setnotperiodic name",
2140 theCommands.Add("segment",
2141 "segment name Ufirst Ulast [tol]",
2145 theCommands.Add("setorigin",
2146 "setorigin name knotindex",
2150 g = "GEOMETRY curves and surfaces analysis";
2152 theCommands.Add("cvalue",
2153 "cvalue curvename U X Y Z [D1X D1Y D1Z D2X D2Y D2Z]",
2157 theCommands.Add("2dcvalue",
2158 "2dcvalue curvename U X Y [D1X D1Y D2X D2Y]",
2162 theCommands.Add("coord",
2163 "coord P x y [z]: set in x y [z] the coordinates of P",
2167 theCommands.Add("minmaxcurandinf",
2168 "minmaxcurandinf curve",
2172 theCommands.Add("shcurvature",
2173 "shcurvature curvename",
2177 theCommands.Add("clcurvature",
2178 "clcurvature curvename",
2183 theCommands.Add("radiusmax",
2184 "radiusmax curvename radius",
2188 theCommands.Add("radiusratio",
2189 "radiusratio curvename ratio",
2192 theCommands.Add("localprop",
2193 "localprop curvename U",
2196 theCommands.Add("rawcont",
2197 "rawcont curve1 curve2 u1 u2",
2200 theCommands.Add("approxcurve",
2201 "approxcurve [-L] name curve1 [Surf1] [curve2d2 Surf2] [Tol [cont [maxdeg [maxseg]]]] ",
2205 theCommands.Add("approxcurveonsurf",
2206 "approxcurveonsurf name curve2d surface [Tol [cont [maxdeg [maxseg]]]] ",
2208 approxcurveonsurf,g);
2210 theCommands.Add("fitcurve", "fitcurve result curve [tol [maxdeg [inverse]]]", __FILE__, fitcurve, g);
2212 theCommands.Add("length", "length curve [Tol]",
2217 theCommands.Add("splitc1",
2218 "splitc1 bspline resultinarray(0/1) [tol] [angtol] ",
2222 theCommands.Add("splitc12d",
2223 "splitc12d bspline2d resultinarray(0/1) [tol] [angtol] ",
2226 theCommands.Add("canceldenom",
2227 "canceldenom BSpline-Surface UDirection(0/1) VDirection(0/1)",