1 // File: DrawTrSurf_2.cxx
2 // Created: Thu Aug 12 19:33:52 1993
3 // Author: Bruno DUMORTIER
9 #include <GeomliteTest.hxx>
10 #include <DrawTrSurf.hxx>
12 #include <Draw_Interpretor.hxx>
13 #include <Draw_Appli.hxx>
14 #include <Draw_Display.hxx>
16 #include <GeomAbs_SurfaceType.hxx>
17 #include <GeomAbs_IsoType.hxx>
18 #include <GeomAbs_Shape.hxx>
20 #include <Geom_Plane.hxx>
21 #include <Geom_CylindricalSurface.hxx>
22 #include <Geom_ConicalSurface.hxx>
23 #include <Geom_SphericalSurface.hxx>
24 #include <Geom_ToroidalSurface.hxx>
25 #include <Geom_BezierSurface.hxx>
26 #include <Geom_BSplineSurface.hxx>
27 #include <Geom_SurfaceOfLinearExtrusion.hxx>
28 #include <Geom_SurfaceOfRevolution.hxx>
29 #include <Geom_RectangularTrimmedSurface.hxx>
30 #include <Geom_OffsetSurface.hxx>
31 #include <Geom_Surface.hxx>
33 #include <Geom_TrimmedCurve.hxx>
34 #include <Geom_OffsetCurve.hxx>
35 #include <Geom_BezierCurve.hxx>
36 #include <Geom_BSplineCurve.hxx>
38 #include <Geom2d_TrimmedCurve.hxx>
39 #include <Geom2d_OffsetCurve.hxx>
41 #include <GeomAdaptor_Surface.hxx>
42 #include <GeomAdaptor_HSurface.hxx>
43 #include <GeomAdaptor_Curve.hxx>
44 #include <Geom2dAdaptor_Curve.hxx>
46 #include <TColGeom_Array2OfBezierSurface.hxx>
47 #include <TColgp_Array1OfPnt.hxx>
48 #include <TColgp_Array2OfPnt.hxx>
49 #include <TColStd_Array1OfReal.hxx>
50 #include <TColStd_Array2OfReal.hxx>
51 #include <TColStd_Array1OfInteger.hxx>
52 #include <TColStd_HArray1OfInteger.hxx>
53 #include <TColStd_HArray1OfReal.hxx>
54 #include <TColStd_HArray2OfReal.hxx>
58 #include <Precision.hxx>
59 #include <Convert_CompBezierCurvesToBSplineCurve.hxx>
60 #include <GeomConvert.hxx>
61 #include <GeomConvert_BSplineCurveToBezierCurve.hxx>
62 #include <GeomConvert_BSplineSurfaceToBezierSurface.hxx>
63 #include <GeomConvert_CompBezierSurfacesToBSplineSurface.hxx>
64 #include <Geom2dConvert.hxx>
65 #include <Geom2dConvert_BSplineCurveToBezierCurve.hxx>
66 #include <GeomLProp_SLProps.hxx>
69 #include <DrawTrSurf_BezierSurface.hxx>
70 #include <DrawTrSurf_BSplineSurface.hxx>
71 #include <GeomConvert_ApproxSurface.hxx>
72 #include <GeomLib_Tool.hxx>
73 #include <TopoDS_Shape.hxx>
79 //#define strcasecmp strcmp Already defined
80 Standard_IMPORT Draw_Viewer dout;
89 //=======================================================================
90 //function : compute min max radius of curvature on a surface
92 //=======================================================================
93 static Standard_Integer surface_radius (Draw_Interpretor& di,
97 Standard_Integer report_curvature = 0 ;
98 Standard_Real UParameter,VParameter,radius,tolerance = 1.0e-7 ;
101 if (n >= 6) report_curvature = 1 ;
103 UParameter = atof(a[2]);
104 VParameter = atof(a[3]);
105 Handle(Geom_Surface) SurfacePtr = DrawTrSurf::GetSurface(a[1]);
106 if (!SurfacePtr.IsNull()) {
107 GeomLProp_SLProps myProperties(SurfacePtr,
112 if (myProperties.IsCurvatureDefined()) {
113 radius = myProperties.MinCurvature();
115 if (report_curvature) Draw::Set(a[4],radius);
117 if (Abs(radius) > tolerance) {
118 radius = 1.0e0/ radius ;
119 di << "Min Radius of Curvature : " << radius << "\n";
122 di << "Min Radius of Curvature : infinite" << "\n";
125 radius = myProperties.MaxCurvature();
126 if (report_curvature) Draw::Set(a[5],radius);
127 if (Abs(radius) > tolerance) {
128 radius = 1.0e0/ radius;
129 di << "Max Radius of Curvature : " << radius << "\n";
132 di << "Min Radius of Curvature : infinite" << "\n";
135 di << "Curvature not defined." << "\n";
145 //=======================================================================
146 //function : anasurface
148 //=======================================================================
150 static Standard_Integer anasurface (Draw_Interpretor& ,
160 loc = gp_Ax3(gp_Pnt(0,0,0),gp_Dir(0,0,1),gp_Dir(1,0,0));
164 loc = gp_Ax3(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
165 gp_Dir(0,0,1),gp_Dir(1,0,0));
169 loc = gp_Ax3(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
170 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])));
174 loc = gp_Ax3(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4])),
175 gp_Dir(atof(a[5]),atof(a[6]),atof(a[7])),
176 gp_Dir(atof(a[8]),atof(a[9]),atof(a[10])));
182 Handle(Geom_Geometry) result;
184 if (!strcasecmp(a[0],"plane")) {
185 Handle(Geom_Plane) C = new Geom_Plane(loc);
189 if (i >= n) return 1;
190 Standard_Real par1 = atof(a[i]);
192 if (!strcasecmp(a[0],"cylinder")) {
193 Handle(Geom_CylindricalSurface) C =
194 new Geom_CylindricalSurface(loc,par1);
198 else if (!strcasecmp(a[0],"sphere")) {
199 Handle(Geom_SphericalSurface) C =
200 new Geom_SphericalSurface(loc,par1);
205 if (i+1 >= n) return 1;
206 Standard_Real par2 = atof(a[i+1]);
208 if (!strcasecmp(a[0],"cone")) {
209 par1 *= (M_PI / 180.0);
210 Handle(Geom_ConicalSurface) C =
211 new Geom_ConicalSurface(loc,par1,par2);
215 else if (!strcasecmp(a[0],"torus")) {
216 Handle(Geom_ToroidalSurface) C =
217 new Geom_ToroidalSurface(loc,par1,par2);
223 DrawTrSurf::Set(a[1],result);
228 //=======================================================================
229 //function : polesurface
231 //=======================================================================
233 static Standard_Integer polesurface (Draw_Interpretor& , Standard_Integer n, const char** a)
235 Standard_Integer k,j,i;
240 if (!strcasecmp(a[0],"beziersurf")) {
242 Standard_Integer nup = atoi(a[2]);
243 Standard_Integer nvp = atoi(a[3]);
244 if (nup * nvp == 0) return 1;
246 i = (n - 4) / (nup * nvp);
247 if (i < 3 || i > 4) return 1;
248 Standard_Boolean hasw = i == 4;
250 TColgp_Array2OfPnt poles(1,nup,1,nvp);
251 TColStd_Array2OfReal weights(1,nup,1,nvp);
254 for (j = 1; j <= nvp; j++) {
255 for (i = 1; i <= nup; i++) {
256 poles(i, j).SetCoord(atof(a[k]),atof(a[k+1]),atof(a[k+2]));
259 weights(i, j) = atof(a[k]);
265 Handle(Geom_BezierSurface) result;
267 result = new Geom_BezierSurface(poles,weights);
269 result = new Geom_BezierSurface(poles);
271 DrawTrSurf::Set(a[1],result);
275 Standard_Integer udeg = atoi(a[2]);
276 Standard_Integer nbuk = atoi(a[3]);
278 Standard_Boolean uper = (*a[0] == 'u') || (*(a[0]+1) == 'u');
279 Standard_Boolean vper = (*a[0] == 'v') || (*(a[0]+1) == 'v');
281 TColStd_Array1OfReal uk (1, nbuk);
282 TColStd_Array1OfInteger umult(1, nbuk);
284 Standard_Integer SigmaU = 0;
285 for (i = 1; i<=nbuk; i++) {
288 umult( i) = atoi(a[k]);
293 Standard_Integer vdeg = atoi(a[k]);
295 Standard_Integer nbvk = atoi(a[k]);
298 TColStd_Array1OfReal vk (1, nbvk);
299 TColStd_Array1OfInteger vmult(1, nbvk);
300 Standard_Integer SigmaV = 0;
301 for (i = 1; i<=nbvk; i++) {
304 vmult( i) = atoi(a[k]);
309 Standard_Integer nup,nvp;
311 nup = SigmaU - umult(nbuk);
313 nup = SigmaU - udeg -1;
315 nvp = SigmaV - vmult(nbvk);
317 nvp = SigmaV - vdeg -1;
318 TColgp_Array2OfPnt poles (1, nup, 1, nvp);
319 TColStd_Array2OfReal weights(1, nup, 1, nvp);
321 for (j = 1; j <= nvp; j++) {
322 for (i = 1; i <= nup; i++) {
323 poles(i, j).SetCoord(atof(a[k]),atof(a[k+1]),atof(a[k+2]));
325 weights(i, j) = atof(a[k]);
330 Handle(Geom_BSplineSurface) result =
331 new Geom_BSplineSurface(poles, weights,
337 DrawTrSurf::Set(a[1],result);
343 //=======================================================================
344 //function : algosurface
346 //=======================================================================
348 static Standard_Integer algosurface (Draw_Interpretor& , Standard_Integer n, const char** a)
352 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
353 if (GC.IsNull()) return 1;
358 if (!strcasecmp(a[0],"extsurf")) {
359 D.SetCoord(atof(a[3]),atof(a[4]),atof(a[5]));
360 Handle(Geom_SurfaceOfLinearExtrusion) result =
361 new Geom_SurfaceOfLinearExtrusion(GC,D);
363 DrawTrSurf::Set(a[1],result);
366 else if (!strcasecmp(a[0],"revsurf")) {
368 P.SetCoord(atof(a[3]),atof(a[4]),atof(a[5]));
369 D.SetCoord(atof(a[6]),atof(a[7]),atof(a[8]));
371 Handle(Geom_SurfaceOfRevolution) result =
372 new Geom_SurfaceOfRevolution(GC,gp_Ax1(P,D));
374 DrawTrSurf::Set(a[1],result);
384 //=======================================================================
385 //function : trimming
387 //=======================================================================
389 static Standard_Integer trimming (Draw_Interpretor& ,
390 Standard_Integer n, const char** a)
394 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
395 Handle(Geom2d_Curve) GC2d = DrawTrSurf::GetCurve2d(a[2]);
396 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
400 Handle(Geom_TrimmedCurve) T = Handle(Geom_TrimmedCurve)::DownCast(GC);
401 if (!T.IsNull()) GC = T->BasisCurve();
402 DrawTrSurf::Set(a[1],GC);
404 else if (!GC2d.IsNull()) {
405 Handle(Geom2d_TrimmedCurve) T = Handle(Geom2d_TrimmedCurve)::DownCast(GC2d);
406 if (!T.IsNull()) GC2d = T->BasisCurve();
407 DrawTrSurf::Set(a[1],GC2d);
409 else if (!GS.IsNull()) {
410 Handle(Geom_RectangularTrimmedSurface) T = Handle(Geom_RectangularTrimmedSurface)::DownCast(GS);
411 if (!T.IsNull()) GS = T->BasisSurface();
412 DrawTrSurf::Set(a[1],GS);
419 Standard_Real u1 = atof(a[3]);
420 Standard_Real u2 = atof(a[4]);
422 Handle(Geom_Geometry) result;
423 Handle(Geom2d_Curve) result2d;
425 if (!strcasecmp(a[0],"trim")) {
429 new Geom_RectangularTrimmedSurface(GS,u1,u2,atof(a[5]),atof(a[6]));
431 else if (!GC.IsNull()) {
432 result = new Geom_TrimmedCurve(GC, u1, u2);
434 else if (!GC2d.IsNull()) {
435 result2d = new Geom2d_TrimmedCurve(GC2d, u1, u2);
441 if (GS.IsNull()) return 1;
442 result = new Geom_RectangularTrimmedSurface(GS,u1,u2,
443 !strcasecmp(a[0],"trimu"));
446 if (!result.IsNull())
447 DrawTrSurf::Set(a[1], result);
449 DrawTrSurf::Set(a[1],result2d);
454 //=======================================================================
455 //function : converting
457 //=======================================================================
459 static Standard_Integer converting(Draw_Interpretor& , Standard_Integer n, const char ** a)
461 if ( n < 3) return 1;
463 Convert_ParameterisationType
464 Parameterisation = Convert_TgtThetaOver2 ;
465 if (strcmp(a[n-1], "qa") == 0) {
466 Parameterisation = Convert_QuasiAngular ;
468 else if (strcmp(a[n-1], "c1") == 0) {
469 Parameterisation = Convert_RationalC1 ;
471 else if (strcmp (a[n-1], "s1") == 0) {
472 Parameterisation = Convert_TgtThetaOver2_1 ;
474 else if (strcmp (a[n-1], "s2") == 0) {
475 Parameterisation = Convert_TgtThetaOver2_2;
477 else if (strcmp (a[n-1], "s3") == 0) {
478 Parameterisation = Convert_TgtThetaOver2_3 ;
480 else if (strcmp (a[n-1], "s4") == 0) {
481 Parameterisation = Convert_TgtThetaOver2_4 ;
483 else if (strcmp (a[n-1], "po") == 0) {
484 Parameterisation = Convert_Polynomial;
487 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
489 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
491 Handle(Geom2d_Curve) G2d = DrawTrSurf::GetCurve2d(a[2]);
496 G2d = Geom2dConvert::CurveToBSplineCurve(G2d,
498 DrawTrSurf::Set(a[1], G2d);
502 GS = GeomConvert::SurfaceToBSplineSurface( GS);
503 DrawTrSurf::Set(a[1], GS);
507 GC = GeomConvert::CurveToBSplineCurve( GC,
509 DrawTrSurf::Set(a[1], GC);
516 //=======================================================================
517 //function : tobezier
519 //=======================================================================
521 static Standard_Integer tobezier(Draw_Interpretor& di,
522 Standard_Integer n, const char** a)
524 if ( n < 3) return 1;
525 Standard_Integer i,j,NbU,NbV,NbArc;
526 char* name = new char[100];
528 Handle(Geom2d_BSplineCurve) C2d =
529 DrawTrSurf::GetBSplineCurve2d(a[2]);
531 Handle(Geom_BSplineCurve) C3d =
532 DrawTrSurf::GetBSplineCurve(a[2]);
534 Handle(Geom_BSplineSurface) S =
535 DrawTrSurf::GetBSplineSurface(a[2]);
536 if ( S.IsNull()) return 1;
538 Standard_Real U1, U2, V1, V2;
543 GeomConvert_BSplineSurfaceToBezierSurface
544 Conv(S, U1, U2, V1, V2, Precision::PConfusion());
545 NbU = Conv.NbUPatches();
546 NbV = Conv.NbVPatches();
547 di << NbU << " X " << NbV << " patches in the result" << "\n";
548 for (i = 1; i <= NbU; i++) {
549 for (j = 1; j <= NbV; j++) {
550 sprintf(name,"%s_%i_%i",a[1],i,j);
552 DrawTrSurf::Set(temp,Conv.Patch(i,j));
557 GeomConvert_BSplineSurfaceToBezierSurface Conv(S);
558 NbU = Conv.NbUPatches();
559 NbV = Conv.NbVPatches();
560 di << NbU << " X " << NbV << " patches in the result" << "\n";
561 for (i = 1; i <= NbU; i++) {
562 for (j = 1; j <= NbV; j++) {
563 sprintf(name,"%s_%i_%i",a[1],i,j);
565 DrawTrSurf::Set(temp,Conv.Patch(i,j));
572 Standard_Real U1, U2;
575 GeomConvert_BSplineCurveToBezierCurve Conv(C3d, U1, U2,
576 Precision::PConfusion());
577 NbArc = Conv.NbArcs();
578 di << NbArc << " arcs in the result" << "\n";
579 for (i = 1; i <= NbArc; i++) {
580 sprintf(name,"%s_%i",a[1],i);
582 DrawTrSurf::Set(temp,Conv.Arc(i));
586 GeomConvert_BSplineCurveToBezierCurve Conv(C3d);
587 NbArc = Conv.NbArcs();
588 di << NbArc << " arcs in the result" << "\n";
589 for (i = 1; i <= NbArc; i++) {
590 sprintf(name,"%s_%i",a[1],i);
592 DrawTrSurf::Set(temp,Conv.Arc(i));
599 Standard_Real U1, U2;
602 Geom2dConvert_BSplineCurveToBezierCurve Conv(C2d, U1, U2,
603 Precision::PConfusion());
604 NbArc = Conv.NbArcs();
605 di << NbArc << " arcs in the result" << "\n";
606 for (i = 1; i <= NbArc; i++) {
607 sprintf(name,"%s_%i",a[1],i);
609 DrawTrSurf::Set(temp,Conv.Arc(i));
613 Geom2dConvert_BSplineCurveToBezierCurve Conv(C2d);
614 NbArc = Conv.NbArcs();
615 di << NbArc << " arcs in the result" << "\n";
616 for (i = 1; i <= NbArc; i++) {
617 sprintf(name,"%s_%i",a[1],i);
619 DrawTrSurf::Set(temp,Conv.Arc(i));
627 //=======================================================================
630 //=======================================================================
632 static Standard_Integer convbz(Draw_Interpretor& di,
633 Standard_Integer n, const char** a)
635 if ( n < 4) return 1;
637 Standard_Integer ii, jj, kk=0, NbU, NbV;
638 Standard_Real Tol = Precision::Confusion();
641 if ( (Handle(Geom_Curve)::
642 DownCast(DrawTrSurf::Get(a[3]))).IsNull()) {
646 di << "The number of bezier surface have to be " << NbU*NbV << "\n";
649 TColGeom_Array2OfBezierSurface BZ(1, NbU, 1, NbV);
651 for (jj=1; jj<=NbV; jj++)
652 for(ii=1;ii<=NbU; ii++) {
654 Handle(Geom_BezierSurface)::DownCast(DrawTrSurf::Get(a[kk]));
655 if (BZ(ii,jj).IsNull()) {
656 di << "the Surface " << kk <<"is not a BezierSurface" << "\n";
661 if (kk<n) Tol = atof(a[kk]);
663 GeomConvert_CompBezierSurfacesToBSplineSurface Conv(BZ, Tol);
665 if (! Conv.IsDone()) {
666 di << "Convert Not Done" << "\n";
670 Handle(Geom_BSplineSurface) BSurf =
671 new Geom_BSplineSurface(Conv.Poles()->Array2(),
672 Conv.UKnots()->Array1(),
673 Conv.VKnots()->Array1(),
674 Conv.UMultiplicities()->Array1(),
675 Conv.VMultiplicities()->Array1(),
679 DrawTrSurf::Set(a[1], BSurf);
681 else { // cas de courbes
682 Convert_CompBezierCurvesToBSplineCurve Conv;
683 Handle(Geom_BezierCurve) BZ;
684 for (ii=1, kk=3; ii<=NbU; ii++,kk++) {
685 BZ = Handle(Geom_BezierCurve)::DownCast(DrawTrSurf::Get(a[kk]));
687 di << "the curve " << kk <<"is not a BezierCurve" << "\n";
690 TColgp_Array1OfPnt Poles(1, BZ->NbPoles());
692 Conv.AddCurve(Poles);
697 TColgp_Array1OfPnt Poles(1, Conv.NbPoles());
699 TColStd_Array1OfInteger Mults(1, Conv.NbKnots());
700 TColStd_Array1OfReal Knots(1, Conv.NbKnots());
701 Conv.KnotsAndMults(Knots, Mults);
702 Handle(Geom_BSplineCurve) BS =
703 new (Geom_BSplineCurve) (Poles, Knots, Mults,
705 DrawTrSurf::Set(a[1], BS);
711 //=======================================================================
712 //function : approxsurf
713 //purpose : Approximation d'une Surface par une BSpline non rationnelle
714 //=======================================================================
717 static Standard_Integer approxsurf(Draw_Interpretor& di, Standard_Integer n, const char** a)
719 // " Tolerance (par defaut 0.1mm) "
720 Standard_Real Tol = 1.e-4;
721 // " Ordres de continuites : 0, 1 ou 2 (par defaut 1)"
722 GeomAbs_Shape myUCont = GeomAbs_C1, myVCont = GeomAbs_C1;
723 // " Degre maximum des carreaux de Bezier 14 par defaut "
724 Standard_Integer degU = 14, degV = 14;
725 // " Nombre max de carreaux (par defaut 10)"
726 Standard_Integer nmax = 16;
727 // "Code de precision par defaults"
728 Standard_Integer myPrec = 1;
730 if ( n>10 || n<3) return 1;
732 if (n>3) Tol = Max(atof(a[3]),1.e-10);
737 if (atoi(a[4]) == 0) myUCont = GeomAbs_C0;
738 if (atoi(a[4]) == 2) myUCont = GeomAbs_C2;
739 if (atoi(a[5]) == 0) myVCont = GeomAbs_C0;
740 if (atoi(a[5]) == 2) myVCont = GeomAbs_C2;
746 ( degU = (atoi(a[6])));
747 ( degV = (atoi(a[7])));
748 if ((degU<1) || (degU>24)) degU = 14;
749 if ((degV<1) || (degV>24)) degV = 14;
752 if (n>8) nmax = atoi(a[8]);
753 if (n>9) myPrec = atoi(a[9]);
755 Handle(Geom_Surface) surf = DrawTrSurf::GetSurface(a[2]);
756 if (surf.IsNull()) return 1;
757 GeomConvert_ApproxSurface myApprox(surf,Tol,myUCont,myVCont,degU,degV,nmax,myPrec);
758 if ( myApprox.HasResult()) DrawTrSurf::Set(a[1], myApprox.Surface());
763 //=======================================================================
764 //function : offseting
766 //=======================================================================
768 static Standard_Integer offseting (Draw_Interpretor& ,
769 Standard_Integer n, const char** a)
773 // test the Geom2d curve
774 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
776 Handle(Geom2d_OffsetCurve) OC = new Geom2d_OffsetCurve(C2d,atof(a[3]));
777 DrawTrSurf::Set(a[1],OC);
781 Standard_Boolean yasurf = Standard_False;
783 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
784 Handle(Geom_Surface) GS;
786 GS = DrawTrSurf::GetSurface(a[2]);
789 yasurf = Standard_True;
792 Standard_Real dist = atof(a[3]);
794 Handle(Geom_Geometry) result;
797 Handle(Geom_OffsetSurface) GO = new Geom_OffsetSurface(GS,dist);
802 gp_Dir D(atof(a[4]),atof(a[5]),atof(a[6]));
803 Handle(Geom_OffsetCurve) GT = new Geom_OffsetCurve(GC, dist, D);
807 DrawTrSurf::Set(a[1], result);
811 //=======================================================================
812 //function : sreverse
814 //=======================================================================
816 static Standard_Integer sreverse (Draw_Interpretor& , Standard_Integer n, const char** a)
821 for (i = 1; i < n; i++) {
823 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[i]);
836 //=======================================================================
839 //=======================================================================
841 static Standard_Integer iso (Draw_Interpretor& , Standard_Integer n, const char** a)
845 Handle(Geom_Curve) C;
846 Standard_Real par = atof(a[3]);
847 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[2]);
853 DrawTrSurf::Set(a[1],C);
860 //=======================================================================
863 //=======================================================================
865 static Standard_Integer value (Draw_Interpretor& ,
866 Standard_Integer n, const char** a)
870 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[1]);
871 if (GS.IsNull()) return 1;
873 Standard_Real U = atof(a[2]);
874 Standard_Real V = atof(a[3]);
876 Standard_Boolean DrawPoint = ( n%3 == 2);
884 GS->D2(U,V,P,DU,DV,D2U,D2V,D2UV);
885 Draw::Set(a[13],D2U.X());
886 Draw::Set(a[14],D2U.Y());
887 Draw::Set(a[15],D2U.Z());
888 Draw::Set(a[16],D2V.X());
889 Draw::Set(a[17],D2V.Y());
890 Draw::Set(a[18],D2V.Z());
891 Draw::Set(a[19],D2UV.X());
892 Draw::Set(a[20],D2UV.Y());
893 Draw::Set(a[21],D2UV.Z());
898 Draw::Set(a[7],DU.X());
899 Draw::Set(a[8],DU.Y());
900 Draw::Set(a[9],DU.Z());
901 Draw::Set(a[10],DV.X());
902 Draw::Set(a[11],DV.Y());
903 Draw::Set(a[12],DV.Z());
909 Draw::Set(a[4],P.X());
910 Draw::Set(a[5],P.Y());
911 Draw::Set(a[6],P.Z());
914 DrawTrSurf::Set(a[n],P);
920 //=======================================================================
921 //function : movepole
923 //=======================================================================
925 static Standard_Integer movepole (Draw_Interpretor& , Standard_Integer n, const char** a)
928 Standard_Boolean BSpline = Standard_False;
930 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
931 Handle(Geom_BSplineSurface) GBs;
933 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
936 BSpline = Standard_True;
939 Standard_Real dx = atof(a[n-3]);
940 Standard_Real dy = atof(a[n-2]);
941 Standard_Real dz = atof(a[n-1]);
943 Standard_Integer nup, nvp;
945 nup = GBz->NbUPoles();
946 nvp = GBz->NbVPoles();
949 nup = GBs->NbUPoles();
950 nvp = GBs->NbVPoles();
953 Standard_Integer FirstRow=0, LastRow=0, FirstCol=0, LastCol=0;
954 // Rem : Row = indice ligne. -> variation en U.
955 // Col = indice colonne.-> variation en V.
957 if (!strcasecmp(a[0],"movep")) {
959 FirstRow = atoi(a[2]);
960 FirstCol = atoi(a[3]);
961 if ( FirstRow < 1 || FirstRow > nup ||
962 FirstCol < 1 || FirstCol > nvp ) return 1;
966 else if (!strcasecmp(a[0],"moverowp")) {
967 FirstRow = atoi(a[2]);
968 if ( FirstRow < 1 || FirstRow > nup ) return 1;
973 else if (!strcasecmp(a[0],"movecolp")) {
974 FirstCol = atoi(a[2]);
975 if ( FirstCol < 1 || FirstCol > nvp ) return 1;
983 for ( Standard_Integer i = FirstRow; i<= LastRow; i++) {
984 for ( Standard_Integer j = FirstCol; j<= LastCol; j++) {
987 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
992 P.SetCoord(P.X()+dx, P.Y()+dy, P.Z()+dz);
1004 //=======================================================================
1005 //function : movepoint
1007 //=======================================================================
1009 static Standard_Integer movepoint (Draw_Interpretor& , Standard_Integer n, const char** a)
1011 if (n < 7) return 1;
1013 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1018 Standard_Real u = atof(a[2]);
1019 Standard_Real v = atof(a[3]);
1021 Standard_Real dx = atof(a[4]);
1022 Standard_Real dy = atof(a[5]);
1023 Standard_Real dz = atof(a[6]);
1025 Standard_Integer index1u = 0;
1026 Standard_Integer index2u = 0;
1027 Standard_Integer index1v = 0;
1028 Standard_Integer index2v = 0;
1030 Standard_Integer fmodifu, lmodifu, fmodifv, lmodifv;
1032 index1u = atoi(a[7]);
1033 index2u = atoi(a[8]);
1034 index1v = atoi(a[9]);
1035 index2v = atoi(a[10]);
1039 index2u = GBs->NbUPoles()-1;
1041 index2v = GBs->NbVPoles()-1;
1046 p.SetCoord(p.X()+dx, p.Y()+dy, p.Z()+dz);
1047 GBs->MovePoint(u, v, p, index1u, index2u, index1v, index2v, fmodifu, lmodifu, fmodifv, lmodifv);
1053 //=======================================================================
1054 //function : insertknot
1056 //=======================================================================
1058 static Standard_Integer insertknot (Draw_Interpretor& , Standard_Integer n, const char** a)
1060 if (n < 3) return 1;
1062 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1064 if (GBs.IsNull()) return 1;
1066 Standard_Real knot=0;
1067 Standard_Integer mult = 0;
1068 Standard_Integer index=0;
1069 if ( !strcasecmp(a[0],"insertuknot") ||
1070 !strcasecmp(a[0],"insertvknot") ) {
1075 else if ( !strcasecmp(a[0],"remuknot") ||
1076 !strcasecmp(a[0],"remvknot") ) {
1078 if (n>=4) mult = atoi(a[3]);
1081 Standard_Real tol = RealLast();
1083 if (!strcasecmp(a[0],"insertuknot")) {
1084 GBs->InsertUKnot(knot,mult,Precision::PConfusion());
1086 else if (!strcasecmp(a[0],"insertvknot")) {
1087 GBs->InsertVKnot(knot,mult,Precision::PConfusion());
1089 else if (!strcasecmp(a[0],"remuknot")) {
1090 if (n>=5) tol = atof(a[4]);
1091 if (!GBs->RemoveUKnot(index,mult,tol))
1094 else if (!strcasecmp(a[0],"remvknot")) {
1095 if (n>=5) tol = atof(a[4]);
1096 if (!GBs->RemoveVKnot(index,mult,tol))
1104 //=======================================================================
1105 //function : incdegree
1107 //=======================================================================
1109 static Standard_Integer incdegree (Draw_Interpretor& di, Standard_Integer n, const char** a)
1111 if (n < 3) return 1;
1113 Standard_Integer NewDeg = atoi(a[2]);
1114 Standard_Boolean BSpline = Standard_False;
1116 Standard_Integer UDeg=0, VDeg=0;
1118 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1119 Handle(Geom_BSplineSurface) GBs;
1122 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1125 BSpline = Standard_True;
1128 Standard_Integer Degree=0;
1129 if ( !strcasecmp(a[0],"incudeg")) {
1132 Degree = GBs->UDegree();
1133 VDeg = GBs->VDegree();
1136 Degree = GBz->UDegree();
1137 VDeg = GBz->VDegree();
1140 else if ( !strcasecmp(a[0],"incvdeg")) {
1143 Degree = GBs->VDegree();
1144 UDeg = GBs->UDegree();
1147 Degree = GBz->VDegree();
1148 UDeg = GBz->UDegree();
1152 if (Degree > NewDeg) {
1153 di<<"The Degree must be greater than " << Degree <<"\n";
1158 GBs->IncreaseDegree(UDeg, VDeg);
1161 GBz->Increase(UDeg, VDeg);
1168 //=======================================================================
1169 //function : rempole
1171 //=======================================================================
1173 static Standard_Integer rempole (Draw_Interpretor& di, Standard_Integer n, const char** a)
1175 if (n < 3) return 1;
1177 Standard_Integer NewIndex = atoi(a[2]);
1178 Standard_Boolean BSpline = Standard_False;
1180 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1181 Handle(Geom_BSplineSurface) GBs;
1184 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1187 BSpline = Standard_True;
1190 Standard_Integer Index;
1191 if ( !strcasecmp(a[0],"remrowpole")) {
1193 Index = GBs->UDegree();
1195 Index = GBz->UDegree();
1197 else if ( !strcasecmp(a[0],"remcolpole")) {
1199 Index = GBs->VDegree();
1201 Index = GBz->VDegree();
1204 if ( !strcasecmp(a[0],"remrowpole")) {
1206 di << " Error : Cannot remove a polerow on a BSplineSurface " << "\n";
1209 GBz->RemovePoleRow(NewIndex);
1212 else if ( !strcasecmp(a[0],"remcolpole")) {
1214 di << " Error : Cannot remove a polecol on a BSplineSurface " << "\n";
1217 GBz->RemovePoleCol(NewIndex);
1225 //=======================================================================
1228 //=======================================================================
1230 static Standard_Integer sfindp (Draw_Interpretor& , Standard_Integer n, const char** a)
1232 if (n < 7) return 1;
1233 Standard_Boolean BSpline = Standard_False;
1235 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1236 Handle(Geom_BSplineSurface) GBs;
1238 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1241 BSpline = Standard_True;
1244 Standard_Integer UIndex = 0;
1245 Standard_Integer VIndex = 0;
1246 Standard_Integer view = atoi(a[2]);
1247 Standard_Real x = atof(a[3]);
1248 Standard_Real y = atof(a[4]);
1250 Draw_Display d = dout.MakeDisplay(view);
1253 Handle(DrawTrSurf_BezierSurface) DBz =
1254 new DrawTrSurf_BezierSurface(GBz);
1255 DBz->FindPole( x, y, d, 5, UIndex,VIndex);
1258 Handle(DrawTrSurf_BSplineSurface) DBs =
1259 new DrawTrSurf_BSplineSurface(GBs);
1260 DBs->FindPole( x, y, d, 5, UIndex,VIndex);
1263 Draw::Set(a[5],UIndex);
1264 Draw::Set(a[6],VIndex);
1270 //=======================================================================
1271 //function : ssetperiodic
1273 //=======================================================================
1275 static Standard_Integer ssetperiodic (Draw_Interpretor& , Standard_Integer n, const char** a)
1277 if (n < 2) return 1;
1281 if (!strcasecmp(a[0],"setuperiodic")) {
1282 for (i = 1; i < n; i++) {
1283 Handle(Geom_BSplineSurface)
1284 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1285 if (!GBs.IsNull()) {
1286 GBs->SetUPeriodic();
1291 else if (!strcasecmp(a[0],"setvperiodic")){
1292 for (i = 1; i < n; i++) {
1293 Handle(Geom_BSplineSurface)
1294 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1295 if (!GBs.IsNull()) {
1296 GBs->SetVPeriodic();
1301 else if (!strcasecmp(a[0],"setunotperiodic")){
1302 for (i = 1; i < n; i++) {
1303 Handle(Geom_BSplineSurface)
1304 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1305 if (!GBs.IsNull()) {
1306 GBs->SetUNotPeriodic();
1311 else if (!strcasecmp(a[0],"setvnotperiodic")){
1312 for (i = 1; i < n; i++) {
1313 Handle(Geom_BSplineSurface)
1314 GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1315 if (!GBs.IsNull()) {
1316 GBs->SetVNotPeriodic();
1324 //=======================================================================
1327 //=======================================================================
1329 static Standard_Integer exchuv (Draw_Interpretor& , Standard_Integer n, const char** a)
1331 if (n < 2) return 1;
1334 for (i = 1; i < n; i++) {
1336 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[i]);
1337 if (!GBs.IsNull()) {
1342 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[i]);
1343 if (!GBz.IsNull()) {
1353 //=======================================================================
1356 //=======================================================================
1358 static Standard_Integer segsur (Draw_Interpretor& , Standard_Integer n, const char** a)
1360 if (n < 6) return 1;
1362 Handle(Geom_BezierSurface) GBz = DrawTrSurf::GetBezierSurface(a[1]);
1363 Handle(Geom_BSplineSurface) GBs;
1365 GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1368 GBs->Segment(atof(a[2]),atof(a[3]),atof(a[4]),atof(a[5]));
1371 GBz->Segment(atof(a[2]),atof(a[3]),atof(a[4]),atof(a[5]));
1378 static Standard_Integer compBsplSur (Draw_Interpretor& , Standard_Integer n, const char** a)
1382 cout<<"Invalid number of parameters"<<endl;
1386 Handle(Geom_BSplineSurface) GBs1 = DrawTrSurf::GetBSplineSurface(a[1]);
1387 Handle(Geom_BSplineSurface) GBs2 = DrawTrSurf::GetBSplineSurface(a[2]);
1388 if (GBs1.IsNull() || GBs2.IsNull()) {
1389 cout<<"Invalid surface"<<endl;
1393 Standard_Real aU11,aU12,aV11,aV12;
1394 GBs1->Bounds(aU11,aU12,aV11,aV12);
1396 Standard_Real aU21,aU22,aV21,aV22;
1397 GBs2->Bounds(aU21,aU22,aV21,aV22);
1399 Standard_Real aUmin = Max(aU11,aU21);
1400 Standard_Real aUmax = Min(aU12,aU22);
1402 Standard_Real aVmin = Max(aV11,aV21);
1403 Standard_Real aVmax = Min(aV12,aV22);
1405 Standard_Integer nbP = 100;
1406 Standard_Real aStepU = (aUmax - aUmin)/nbP;
1407 Standard_Real aStepV = (aVmax - aVmin)/nbP;
1408 Standard_Integer nbErr =0;
1409 Standard_Integer i =1;
1410 for( ; i <= nbP +1; i++)
1412 Standard_Real aU = aUmin + aStepU*(i-1);
1413 Standard_Integer j =1;
1414 for( ; j <= nbP +1; j++)
1416 Standard_Real aV = aVmin + aStepV*(j-1);
1417 gp_Pnt aP1 = GBs1->Value(aU,aV);
1418 gp_Pnt aP2 = GBs2->Value(aU,aV);
1419 Standard_Real aDist = aP1.SquareDistance(aP2);
1420 if(aDist > Precision::Confusion() * Precision::Confusion())
1423 Standard_Real aD = sqrt(aDist);
1424 cout<<"Surfaces differ for U,V,Dist: "<<aU<<" "<<aV<<" "<<aD<<endl;
1434 //=======================================================================
1435 //function : setuvorigin
1437 //=======================================================================
1439 static Standard_Integer setuvorigin (Draw_Interpretor& , Standard_Integer n, const char** a)
1441 if (n < 3) return 1;
1443 Handle(Geom_BSplineSurface) GBs = DrawTrSurf::GetBSplineSurface(a[1]);
1446 if ( !strcasecmp(a[0],"setuorigin")) {
1447 GBs->SetUOrigin(atoi(a[2]));
1449 else if ( !strcasecmp(a[0],"setvorigin")) {
1450 GBs->SetVOrigin(atoi(a[2]));
1460 //=======================================================================
1461 //function : parameters
1463 //=======================================================================
1465 static Standard_Integer parameters (Draw_Interpretor& di, Standard_Integer n, const char** a)
1469 // try to find parameters on a Surface
1470 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[1]);
1471 if( S.IsNull() ) { di << "Unknown surface" << "\n"; return 1; }
1472 gp_Pnt P(atof(a[2]), atof(a[3]), atof(a[4]));
1473 Standard_Real Tol = atof(a[5]), U = 0., V = 0.;
1474 Standard_Boolean res = GeomLib_Tool::Parameters(S,P,Tol,U,V);
1479 if( !res ) { di << "Wrong point" << "\n"; return 1; }
1483 // try to find parameters on a 3d Curve
1484 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[1]);
1485 if( C.IsNull() ) { di << "Unknown curve" << "\n"; return 1; }
1486 gp_Pnt P(atof(a[2]), atof(a[3]), atof(a[4]));
1487 Standard_Real Tol = atof(a[5]), U = 0.;
1488 Standard_Boolean res = GeomLib_Tool::Parameter(C,P,Tol,U);
1492 if( !res ) { di << "Wrong point" << "\n"; return 1; }
1496 // try to find parameters on a 2d Curve
1497 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[1]);
1498 if( C.IsNull() ) { di << "Unknown curve 2d" << "\n"; return 1; }
1499 gp_Pnt2d P(atof(a[2]), atof(a[3]));
1500 Standard_Real Tol = atof(a[4]), U = 0.;
1501 Standard_Boolean res = GeomLib_Tool::Parameter(C,P,Tol,U);
1505 if( !res ) { di << "Wrong point" << "\n"; return 1; }
1509 di << "Invalid parameters!" << "\n";
1510 di << "Usage:" << "\n";
1511 di << "parameters Surf X Y Z Tol U V" << "\n";
1512 di << "parameters Curv X Y Z Tol U" << "\n";
1513 di << "parameters Curv2d X Y Tol U" << "\n";
1521 //=======================================================================
1524 //=======================================================================
1526 Standard_Integer bounds(Draw_Interpretor&, Standard_Integer n, const char** a)
1528 Standard_Real U1, U2, V1, V2;
1529 if ( n == 4) { // compute on a curve or a 2d curve
1530 Handle(Geom_Curve) C3d = DrawTrSurf::GetCurve(a[1]);
1531 if ( C3d.IsNull()) { // 2dcurve
1532 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[1]);
1533 if ( C2d.IsNull()) return 1;
1534 U1 = C2d->FirstParameter();
1535 U2 = C2d->LastParameter();
1538 U1 = C3d->FirstParameter();
1539 U2 = C3d->LastParameter();
1544 else if ( n == 6) { // compute on a Surface
1545 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[1]);
1546 if ( S.IsNull()) return 1;
1547 S->Bounds(U1,U2,V1,V2);
1558 //=======================================================================
1559 //function : SurfaceCommands
1561 //=======================================================================
1564 void GeomliteTest::SurfaceCommands(Draw_Interpretor& theCommands)
1566 static Standard_Boolean loaded = Standard_False;
1568 loaded = Standard_True;
1570 DrawTrSurf::BasicCommands(theCommands);
1573 // analytic surfaces
1574 g = "GEOMETRY surfaces creation";
1576 theCommands.Add("plane",
1577 "plane name [x y z [dx dy dz [ux uy uz]]]",
1581 theCommands.Add("cone",
1582 "cone name [x y z [dx dy dz [ux uy uz]]] semi-angle radius",
1586 theCommands.Add("cylinder",
1587 "cylinder name [x y z [dx dy dz [ux uy uz]]] radius",
1591 theCommands.Add("sphere",
1592 "sphere name [x y z [dx dy dz [ux uy uz]]] radius",
1596 theCommands.Add("torus",
1597 "torus name [x y z [dx dy dz [ux uy uz]]] major minor",
1601 theCommands.Add("beziersurf",
1602 "beziersurf name nbupoles nbvpoles pole, [weight]",
1606 theCommands.Add("bsplinesurf",
1607 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1611 theCommands.Add("upbsplinesurf",
1612 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1616 theCommands.Add("vpbsplinesurf",
1617 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1621 theCommands.Add("uvpbsplinesurf",
1622 "bsplinesurf name udegree nbuknots uknot, umult vdegree nbvknots vknot, vmult pole, weight",
1626 theCommands.Add("extsurf",
1627 "extsurf name curvename dx dy dz",
1631 theCommands.Add("revsurf",
1632 "revsurf name curvename x y z dx dy dz",
1636 theCommands.Add("offset",
1637 "offset name basename distance [dx dy dz]",
1641 theCommands.Add("trim",
1642 "trim newname name [u1 u2 [v1 v2]], no args remove trim",
1646 theCommands.Add("trimu",
1647 "trim newname name u1 u2",
1651 theCommands.Add("trimv",
1652 "trim newname name v1 v2",
1656 theCommands.Add("convert",
1657 "convert result c2d/c3d/surf [qa,c1,s1,s2,s3,s4,po]",
1661 theCommands.Add("tobezier",
1662 "tobezier result c2d/c3d/surf [ufirst, ulast / ufirst, ulast, vfirst, vlast]",
1666 theCommands.Add("convertfrombezier",
1667 "convertfrombezier result nbu [nbv] bz1 [bz2 .... bzn] [tol]",
1671 theCommands.Add("approxsurf",
1672 "approxsurf name surf [Tol [CnU CnV [degU degV [nmax]]]] ",
1676 g = "GEOMETRY Curves and Surfaces modification";
1678 theCommands.Add("ureverse",
1679 "ureverse name ... ",
1683 theCommands.Add("vreverse",
1684 "vreverse name ... ",
1688 theCommands.Add("movep",
1689 "movep name row col dx dy dz",
1693 theCommands.Add("moverowp",
1694 "moverowp name row dx dy dz",
1698 theCommands.Add("movecolp",
1699 "movecolp name col dx dy dz",
1703 theCommands.Add("movepoint",
1704 "movepoint name u v dx dy dz [index1u index2u index2v index2v",
1708 theCommands.Add("insertuknot",
1709 "insertuknot name knot mult",
1713 theCommands.Add("insertvknot",
1714 "insertvknot name knot mult",
1718 theCommands.Add("remuknot",
1719 "remuknot name index [mult] [tol]",
1723 theCommands.Add("remvknot",
1724 "remvknot name index [mult] [tol]",
1728 theCommands.Add("incudeg",
1729 "incudeg name degree",
1733 theCommands.Add("incvdeg",
1734 "incvdeg name degree",
1738 theCommands.Add("remrowpole",
1739 "remrowpole name index",
1743 theCommands.Add("remcolpole",
1744 "remcolpole name index",
1748 theCommands.Add("sfindp",
1749 "sfindp name view x y Uindex Vindex",
1753 theCommands.Add("setuperiodic",
1754 "setuperiodic name ...",
1758 theCommands.Add("setvperiodic",
1759 "setvperiodic name ...",
1763 theCommands.Add("setunotperiodic",
1764 "setunotperiodic name ...",
1768 theCommands.Add("setvnotperiodic",
1769 "setvnotperiodic name ...",
1773 theCommands.Add("exchuv",
1778 theCommands.Add("segsur",
1779 "segsur name Ufirst Ulast Vfirst Vlast",
1783 theCommands.Add("setuorigin",
1784 "setuorigin name knotindex",
1788 theCommands.Add("setvorigin",
1789 "setvorigin name knotindex",
1793 g = "GEOMETRY curves creation";
1796 theCommands.Add("uiso",
1797 "uiso curvename surfacename u",
1801 theCommands.Add("viso",
1802 "viso curvename surfacename v",
1807 g = "GEOMETRY curves and surfaces analysis";
1809 theCommands.Add("svalue",
1810 "svalue surfname U V X Y Z [DUX DUY DUZ DVX DVY DVZ [D2UX D2UY D2UZ D2VX D2VY D2VZ D2UVX D2UVY D2UVZ]]",
1814 theCommands.Add("parameters",
1815 "parameters surf/curve X Y [Z] Tol U [V] : {X Y Z} point, {U V} output parameter(s)",
1819 theCommands.Add("bounds",
1820 "bounds S/C/C2d U1 U2 [V1 V2]",
1824 theCommands.Add("surface_radius",
1825 "surface_radius surface Uvalue <Real> Vvalue <Real> returns min max radius of curvature",
1828 theCommands.Add("compBsplSur","BsplSurf1 BSplSurf2",__FILE__,compBsplSur,g);