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 // 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest
19 #include <GeometryTest.hxx>
20 #include <Draw_Appli.hxx>
21 #include <DrawTrSurf.hxx>
22 #include <DrawTrSurf_Curve.hxx>
23 #include <DrawTrSurf_Curve2d.hxx>
24 #include <DrawTrSurf_BezierCurve.hxx>
25 #include <DrawTrSurf_BSplineCurve.hxx>
26 #include <DrawTrSurf_BezierCurve2d.hxx>
27 #include <DrawTrSurf_BSplineCurve2d.hxx>
28 #include <Draw_Marker3D.hxx>
29 #include <Draw_Marker2D.hxx>
31 #include <Draw_Interpretor.hxx>
32 #include <Draw_Color.hxx>
33 #include <Draw_Display.hxx>
35 #include <GeomAPI.hxx>
36 #include <GeomAPI_IntCS.hxx>
37 #include <GeomAPI_IntSS.hxx>
39 //#include <GeomLProp.hxx>
40 #include <GeomProjLib.hxx>
41 #include <BSplCLib.hxx>
45 #include <gp_Parab2d.hxx>
46 #include <gp_Elips2d.hxx>
47 #include <gp_Hypr2d.hxx>
49 #include <Geom_Line.hxx>
50 #include <Geom_Circle.hxx>
51 #include <Geom_Ellipse.hxx>
52 #include <Geom_Parabola.hxx>
53 #include <Geom_Hyperbola.hxx>
54 #include <Geom2d_Line.hxx>
55 #include <Geom2d_Circle.hxx>
56 #include <Geom2d_Ellipse.hxx>
57 #include <Geom2d_Parabola.hxx>
58 #include <Geom2d_Hyperbola.hxx>
59 #include <Geom2d_BSplineCurve.hxx>
60 #include <Geom2d_Curve.hxx>
62 #include <GccAna_Lin2dBisec.hxx>
63 #include <GccAna_Circ2dBisec.hxx>
64 #include <GccAna_CircLin2dBisec.hxx>
65 #include <GccAna_CircPnt2dBisec.hxx>
66 #include <GccAna_LinPnt2dBisec.hxx>
67 #include <GccAna_Pnt2dBisec.hxx>
68 #include <GccInt_Bisec.hxx>
69 #include <GccInt_IType.hxx>
71 #include <Geom_Plane.hxx>
72 #include <Geom_Curve.hxx>
73 #include <Geom2d_Curve.hxx>
74 #include <Geom2d_TrimmedCurve.hxx>
75 #include <Geom_TrimmedCurve.hxx>
77 #include <Law_BSpline.hxx>
79 #include <TColgp_Array1OfPnt.hxx>
80 #include <TColgp_Array1OfPnt2d.hxx>
81 #include <TColStd_Array1OfReal.hxx>
82 #include <TColStd_Array1OfInteger.hxx>
84 #include <Adaptor3d_HCurve.hxx>
85 #include <Adaptor3d_HSurface.hxx>
86 #include <Adaptor3d_CurveOnSurface.hxx>
88 #include <GeomAdaptor_HCurve.hxx>
89 #include <GeomAdaptor_HSurface.hxx>
90 #include <GeomAdaptor.hxx>
91 #include <Geom2dAdaptor_HCurve.hxx>
93 #include <GeomAbs_SurfaceType.hxx>
94 #include <GeomAbs_CurveType.hxx>
96 #include <ProjLib_CompProjectedCurve.hxx>
97 #include <ProjLib_HCompProjectedCurve.hxx>
98 #include <Approx_CurveOnSurface.hxx>
99 #include <Precision.hxx>
100 #include <Geom2dAdaptor.hxx>
103 #include <Precision.hxx>
105 #include <Geom_Surface.hxx>
106 #include <Adaptor2d_HCurve2d.hxx>
108 #include <BSplCLib.hxx>
109 #include <Geom_BSplineSurface.hxx>
110 #include <Geom_BSplineCurve.hxx>
111 #include <GCPnts_QuasiUniformDeflection.hxx>
112 #include <GCPnts_UniformDeflection.hxx>
113 #include <GCPnts_TangentialDeflection.hxx>
114 #include <GCPnts_DistFunction.hxx>
115 #include <GeomAPI_ExtremaCurveCurve.hxx>
116 #include <gce_MakeLin.hxx>
117 #include <TColStd_Array1OfBoolean.hxx>
118 #include <GeomAdaptor_HSurface.hxx>
119 #include <Adaptor3d_TopolTool.hxx>
120 #include <TColgp_Array2OfPnt.hxx>
121 #include <Geom_BSplineSurface.hxx>
122 #include <DrawTrSurf_BSplineSurface.hxx>
123 #include <TColStd_HArray1OfReal.hxx>
126 #include <BRepBuilderAPI_MakeEdge.hxx>
127 #include <AIS_Shape.hxx>
128 #include <TopoDS.hxx>
129 #include <TopoDS_Edge.hxx>
130 #include <TopoDS_Wire.hxx>
131 #include <BRepAdaptor_HCompCurve.hxx>
132 #include <GeomLProp_CLProps.hxx>
133 #include <GCPnts_AbscissaPoint.hxx>
134 #include <GCPnts_UniformAbscissa.hxx>
138 Standard_IMPORT Draw_Viewer dout;
141 //=======================================================================
142 //function : polecurve2d
144 //=======================================================================
146 static Standard_Integer polelaw (Draw_Interpretor& , Standard_Integer n, const char** a)
155 Standard_Boolean periodic = Standard_False ;
156 Standard_Integer deg = Draw::Atoi(a[2]);
157 Standard_Integer nbk = Draw::Atoi(a[3]);
159 TColStd_Array1OfReal knots(1, nbk);
160 TColStd_Array1OfInteger mults(1, nbk);
162 Standard_Integer Sigma = 0;
163 for (i = 1; i<=nbk; i++) {
164 knots( i) = Draw::Atof(a[k]);
166 mults( i) = Draw::Atoi(a[k]);
173 TColStd_Array1OfReal flat_knots(1, Sigma) ;
175 for (i = 1 ; i <= nbk ; i++) {
176 for(qq = 1 ; qq <= mults(i) ; qq++) {
177 flat_knots(jj) = knots(i) ;
182 TColgp_Array1OfPnt2d poles (1, np);
183 TColStd_Array1OfReal schoenberg_points(1,np) ;
184 BSplCLib::BuildSchoenbergPoints(deg,
187 for (i = 1; i <= np; i++) {
188 poles(i).SetCoord(schoenberg_points(i),Draw::Atof(a[k]));
192 Handle(Geom2d_BSplineCurve) result =
193 new Geom2d_BSplineCurve(poles, knots, mults, deg, periodic);
194 DrawTrSurf::Set(a[1],result);
199 //=======================================================================
202 //=======================================================================
204 static Standard_Integer to2d (Draw_Interpretor& , Standard_Integer n, const char** a)
209 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
213 Handle(Geom_Surface) S;
215 S = DrawTrSurf::GetSurface(a[3]);
216 if (S.IsNull()) return 1;
219 S = new Geom_Plane(gp::XOY());
221 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
222 if (P.IsNull()) return 1;
223 Handle(Geom2d_Curve) r = GeomAPI::To2d(C,P->Pln());
224 DrawTrSurf::Set(a[1],r);
228 //=======================================================================
231 //=======================================================================
233 static Standard_Integer to3d (Draw_Interpretor& , Standard_Integer n, const char** a)
237 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
238 if (C.IsNull()) return 1;
240 Handle(Geom_Surface) S;
242 S = DrawTrSurf::GetSurface(a[3]);
243 if (S.IsNull()) return 1;
246 S = new Geom_Plane(gp::XOY());
248 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
249 if (P.IsNull()) return 1;
250 Handle(Geom_Curve) r = GeomAPI::To3d(C,P->Pln());
252 DrawTrSurf::Set(a[1],r);
256 //=======================================================================
257 //function : gproject
259 //=======================================================================
262 static Standard_Integer gproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
266 char* temp = newname;
268 char* temp1 = newname1;
270 Standard_Integer ONE = 1;
275 Sprintf(name,"%s",a[1]);
279 di << "gproject wait 2 or 3 arguments\n";
283 Handle(Geom_Curve) Cur = DrawTrSurf::GetCurve(a[ONE]);
284 Handle(Geom_Surface) Sur = DrawTrSurf::GetSurface(a[ONE+1]);
285 if (Cur.IsNull() || Sur.IsNull()) return 1;
287 Handle(GeomAdaptor_HCurve) hcur = new GeomAdaptor_HCurve(Cur);
288 Handle(GeomAdaptor_HSurface) hsur = new GeomAdaptor_HSurface(Sur);
291 Standard_Real myTol3d = 1.e-6;
292 GeomAbs_Shape myContinuity = GeomAbs_C2;
293 Standard_Integer myMaxDegree = 14, myMaxSeg = 16;
296 ProjLib_CompProjectedCurve Projector(hsur, hcur, myTol3d/10, myTol3d/10);
297 Handle(ProjLib_HCompProjectedCurve) HProjector = new ProjLib_HCompProjectedCurve();
298 HProjector->Set(Projector);
301 Standard_Real Udeb, Ufin, UIso, VIso;
302 Standard_Boolean Only2d, Only3d;
303 gp_Pnt2d P2d, Pdeb, Pfin;
305 Handle(Adaptor2d_HCurve2d) HPCur;
306 Handle(Geom2d_Curve) PCur2d; // Only for isoparametric projection
308 for(k = 1; k <= Projector.NbCurves(); k++){
309 Sprintf(newname,"%s_%d",name,k);
310 Sprintf(newname1,"%s2d_%d",name,k);
311 if(Projector.IsSinglePnt(k, P2d)){
312 // cout<<"Part "<<k<<" of the projection is punctual"<<endl;
313 Projector.GetSurface()->D0(P2d.X(), P2d.Y(), P);
314 DrawTrSurf::Set(temp, P);
315 DrawTrSurf::Set(temp1, P2d);
316 di<<temp<<" is 3d projected curve\n";
317 di<<temp1<<" is pcurve\n";
320 Only2d = Only3d = Standard_False;
321 Projector.Bounds(k, Udeb, Ufin);
322 gp_Dir2d Dir; // Only for isoparametric projection
324 if (Projector.IsUIso(k, UIso)) {
325 // cout<<"Part "<<k<<" of the projection is U-isoparametric curve"<<endl;
326 Projector.D0(Udeb, Pdeb);
327 Projector.D0(Ufin, Pfin);
331 Dir = gp_Dir2d(0, -1);
335 else Dir = gp_Dir2d(0, 1);
336 PCur2d = new Geom2d_TrimmedCurve(new Geom2d_Line(gp_Pnt2d(UIso, 0), Dir), Udeb, Ufin);
337 HPCur = new Geom2dAdaptor_HCurve(PCur2d);
338 Only3d = Standard_True;
340 else if(Projector.IsVIso(k, VIso)) {
341 // cout<<"Part "<<k<<" of the projection is V-isoparametric curve"<<endl;
342 Projector.D0(Udeb, Pdeb);
343 Projector.D0(Ufin, Pfin);
347 Dir = gp_Dir2d(-1, 0);
351 else Dir = gp_Dir2d(1, 0);
352 PCur2d = new Geom2d_TrimmedCurve(new Geom2d_Line(gp_Pnt2d(0, VIso), Dir), Udeb, Ufin);
353 HPCur = new Geom2dAdaptor_HCurve(PCur2d);
354 Only3d = Standard_True;
356 else HPCur = HProjector;
358 if(Projector.MaxDistance(k) <= myTol3d)
359 Only2d = Standard_True;
361 if(Only2d && Only3d) {
362 Handle(Geom_Curve) OutCur = new Geom_TrimmedCurve(GeomAdaptor::MakeCurve(hcur->Curve()), Ufin, Udeb);
363 DrawTrSurf::Set(temp, OutCur);
364 DrawTrSurf::Set(temp1, PCur2d);
365 di<<temp<<" is 3d projected curve\n";
366 di<<temp1<<" is pcurve\n";
370 Approx_CurveOnSurface appr(HPCur, hsur, Udeb, Ufin, myTol3d,
371 myContinuity, myMaxDegree, myMaxSeg,
374 PCur2d = appr.Curve2d();
375 di << " Error in 2d is " << appr.MaxError2dU()
376 << "; " << appr.MaxError2dV() << "\n";
379 Handle(Geom_Curve) OutCur =
380 new Geom_TrimmedCurve(GeomAdaptor::MakeCurve(hcur->Curve()),
382 DrawTrSurf::Set(temp, OutCur);
385 di << " Error in 3d is " << appr.MaxError3d() << "\n";
386 DrawTrSurf::Set(temp, appr.Curve3d());
388 DrawTrSurf::Set(temp1, PCur2d);
389 di<<temp<<" is 3d projected curve\n";
390 di<<temp1<<" is pcurve\n";
396 //=======================================================================
399 //=======================================================================
401 static Standard_Integer project (Draw_Interpretor& di,
402 Standard_Integer n, const char** a)
406 di << "project result2d c3d surf [-e p] [-v n] [-t tol]\n";
407 di << " -e p : extent the surface of <p>%\n";
408 di << " -v n : verify the projection at <n> points.\n";
409 di << " -t tol : set the tolerance for approximation\n";
414 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3]);
415 if (GS.IsNull()) return 1;
417 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
418 if (GC.IsNull()) return 1;
420 Standard_Real tolerance = Precision::Confusion() ;
422 Standard_Real U1,U2,V1,V2;
423 GS->Bounds(U1,U2,V1,V2);
425 Standard_Boolean Verif = Standard_False;
426 Standard_Integer NbPoints=0;
428 Standard_Integer index = 4;
429 while ( index+1 < n) {
430 if ( a[index][0] != '-') return 1;
432 if ( a[index][1] == 'e') {
433 Standard_Real p = Draw::Atof(a[index+1]);
434 Standard_Real dU = p * (U2 - U1) / 100.;
435 Standard_Real dV = p * (V2 - V1) / 100.;
436 U1 -= dU; U2 += dU; V1 -= dV; V2 += dV;
438 else if ( a[index][1] == 'v') {
439 Verif = Standard_True;
440 NbPoints = Draw::Atoi(a[index+1]);
442 else if ( a[index][1] == 't') {
443 tolerance = Draw::Atof(a[index+1]);
448 Handle(Geom2d_Curve) G2d =
449 GeomProjLib::Curve2d(GC, GS, U1, U2, V1, V2, tolerance);
451 if ( G2d.IsNull() ) {
452 di << "\nProjection Failed\n";
456 DrawTrSurf::Set(a[1],G2d);
458 if ( Verif) { // verify the projection on n points
459 if ( NbPoints <= 0) {
460 di << " n must be positive\n";
467 Standard_Real Dist,DistMax = -1.;
468 U1 = GC->FirstParameter();
469 U2 = GC->LastParameter();
470 dU = ( U2 - U1) / (NbPoints + 1);
471 for ( Standard_Integer i = 0 ; i <= NbPoints +1; i++) {
475 P2 = GS->Value(P2d.X(), P2d.Y());
476 Dist = P1.Distance(P2);
477 di << " Parameter = " << U << "\tDistance = " << Dist << "\n";
478 if ( Dist > DistMax) DistMax = Dist;
480 di << " **** Distance Maximale : " << DistMax << "\n";
486 //=======================================================================
487 //function : projonplane
489 //=======================================================================
491 Standard_Integer projonplane(Draw_Interpretor& di,
492 Standard_Integer n, const char** a)
494 if ( n < 4 ) return 1;
496 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
497 if ( S.IsNull()) return 1;
499 Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(S);
501 di << " The surface must be a plane\n";
505 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
506 if ( C.IsNull()) return 1;
508 Standard_Boolean Param = Standard_True;
509 if ((n == 5 && Draw::Atoi(a[4]) == 0) ||
510 (n == 8 && Draw::Atoi(a[7]) == 0)) Param = Standard_False;
515 D = gp_Dir(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
518 D = Pl->Pln().Position().Direction();
521 Handle(Geom_Curve) Res =
522 GeomProjLib::ProjectOnPlane(C,Pl,D,Param);
524 DrawTrSurf::Set(a[1],Res);
530 //=======================================================================
533 //=======================================================================
535 static void solution(const Handle(GccInt_Bisec)& Bis,
537 const Standard_Integer i)
541 Sprintf(solname,"%s",name);
543 Sprintf(solname,"%s_%d",name,i);
544 const char* temp = solname; // pour portage WNT
546 switch ( Bis->ArcType()) {
548 DrawTrSurf::Set(temp, new Geom2d_Line(Bis->Line()));
551 DrawTrSurf::Set(temp, new Geom2d_Circle(Bis->Circle()));
554 DrawTrSurf::Set(temp, new Geom2d_Ellipse(Bis->Ellipse()));
557 DrawTrSurf::Set(temp, new Geom2d_Parabola(Bis->Parabola()));
560 DrawTrSurf::Set(temp, new Geom2d_Hyperbola(Bis->Hyperbola()));
563 DrawTrSurf::Set(temp, Bis->Point());
568 static Standard_Integer bisec (Draw_Interpretor& di,
569 Standard_Integer n, const char** a)
573 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
574 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
576 Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
577 Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
578 Standard_Integer i, Compt = 0;
579 Standard_Integer NbSol = 0;
582 Handle(Standard_Type) Type1 = C1->DynamicType();
584 Handle(Standard_Type) Type2 = C2->DynamicType();
585 if ( Type1 == STANDARD_TYPE(Geom2d_Line) &&
586 Type2 == STANDARD_TYPE(Geom2d_Line) ) {
587 GccAna_Lin2dBisec Bis(Handle(Geom2d_Line)::DownCast(C1)->Lin2d(),
588 Handle(Geom2d_Line)::DownCast(C2)->Lin2d());
591 NbSol = Bis.NbSolutions();
592 for ( i = 1; i <= NbSol; i++) {
593 Sprintf(solname,"%s_%d",a[1],i);
594 const char* temp = solname; // pour portage WNT
595 DrawTrSurf::Set(temp,new Geom2d_Line(Bis.ThisSolution(i)));
599 di << " Bisec has failed !!\n";
603 else if ( Type1 == STANDARD_TYPE(Geom2d_Line) &&
604 Type2 == STANDARD_TYPE(Geom2d_Circle) ) {
605 GccAna_CircLin2dBisec
606 Bis(Handle(Geom2d_Circle)::DownCast(C2)->Circ2d(),
607 Handle(Geom2d_Line)::DownCast(C1)->Lin2d());
609 NbSol= Bis.NbSolutions();
610 if ( NbSol >= 2) Compt = 1;
611 for ( i = 1; i <= NbSol; i++) {
612 solution(Bis.ThisSolution(i),a[1],Compt);
617 di << " Bisec has failed !!\n";
621 else if ( Type2 == STANDARD_TYPE(Geom2d_Line) &&
622 Type1 == STANDARD_TYPE(Geom2d_Circle) ) {
623 GccAna_CircLin2dBisec
624 Bis(Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),
625 Handle(Geom2d_Line)::DownCast(C2)->Lin2d());
627 // char solname[200];
628 NbSol = Bis.NbSolutions();
629 if ( NbSol >= 2) Compt = 1;
630 for ( i = 1; i <= NbSol; i++) {
631 solution(Bis.ThisSolution(i),a[1],Compt);
636 di << " Bisec has failed !!\n";
640 else if ( Type2 == STANDARD_TYPE(Geom2d_Circle) &&
641 Type1 == STANDARD_TYPE(Geom2d_Circle) ) {
643 Bis(Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),
644 Handle(Geom2d_Circle)::DownCast(C2)->Circ2d());
646 // char solname[200];
647 NbSol = Bis.NbSolutions();
648 if ( NbSol >= 2) Compt = 1;
649 for ( i = 1; i <= NbSol; i++) {
650 solution(Bis.ThisSolution(i),a[1],Compt);
655 di << " Bisec has failed !!\n";
660 di << " args must be line/circle/point line/circle/point\n";
665 if ( Type1 == STANDARD_TYPE(Geom2d_Circle)) {
666 GccAna_CircPnt2dBisec Bis
667 (Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),P2);
669 NbSol = Bis.NbSolutions();
670 if ( NbSol >= 2) Compt = 1;
671 for ( i = 1; i <= NbSol; i++) {
672 solution(Bis.ThisSolution(i),a[1],Compt);
677 di << " Bisec has failed !!\n";
681 else if ( Type1 == STANDARD_TYPE(Geom2d_Line)) {
682 GccAna_LinPnt2dBisec Bis
683 (Handle(Geom2d_Line)::DownCast(C1)->Lin2d(),P2);
686 solution(Bis.ThisSolution(),a[1],0);
689 di << " Bisec has failed !!\n";
695 di << " the second arg must be line/circle/point \n";
700 Handle(Standard_Type) Type2 = C2->DynamicType();
701 if ( Type2 == STANDARD_TYPE(Geom2d_Circle)) {
702 GccAna_CircPnt2dBisec Bis
703 (Handle(Geom2d_Circle)::DownCast(C2)->Circ2d(),P1);
705 NbSol = Bis.NbSolutions();
706 if ( NbSol >= 2) Compt = 1;
707 for ( i = 1; i <= Bis.NbSolutions(); i++) {
708 solution(Bis.ThisSolution(i),a[1],Compt);
713 di << " Bisec has failed !!\n";
717 else if ( Type2 == STANDARD_TYPE(Geom2d_Line)) {
718 GccAna_LinPnt2dBisec Bis
719 (Handle(Geom2d_Line)::DownCast(C2)->Lin2d(),P1);
722 solution(Bis.ThisSolution(),a[1],0);
725 di << " Bisec has failed !!\n";
731 GccAna_Pnt2dBisec Bis(P1,P2);
732 if ( Bis.HasSolution()) {
734 DrawTrSurf::Set(a[1],new Geom2d_Line(Bis.ThisSolution()));
737 di << " Bisec has failed !!\n";
742 di << " the second arg must be line/circle/point \n";
747 di << " args must be line/circle/point line/circle/point\n";
752 di << "There are " << NbSol << " Solutions.\n";
755 di << "There is " << NbSol << " Solution.\n";
761 //=======================================================================
762 //function : cmovetangent
764 //=======================================================================
766 static Standard_Integer movelaw (Draw_Interpretor& di, Standard_Integer n, const char** a)
777 u = Draw::Atof(a[2]);
778 x = Draw::Atof(a[3]);
783 Handle(Geom2d_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve2d(a[1]);
785 tx = Draw::Atof(a[4]) ;
787 condition = Max(Draw::Atoi(a[5]), -1) ;
788 condition = Min(condition, G2->Degree()-1) ;
790 TColgp_Array1OfPnt2d curve_poles(1,G2->NbPoles()) ;
791 TColStd_Array1OfReal law_poles(1,G2->NbPoles()) ;
792 TColStd_Array1OfReal law_knots(1,G2->NbKnots()) ;
793 TColStd_Array1OfInteger law_mults(1,G2->NbKnots()) ;
795 G2->Knots(law_knots) ;
796 G2->Multiplicities(law_mults) ;
797 G2->Poles(curve_poles) ;
798 for (ii = 1 ; ii <= G2->NbPoles() ; ii++) {
799 law_poles(ii) = curve_poles(ii).Coord(2) ;
802 Law_BSpline a_law(law_poles,
808 a_law.MovePointAndTangent(u,
816 for (ii = 1 ; ii <= G2->NbPoles() ; ii++) {
817 curve_poles(ii).SetCoord(2,a_law.Pole(ii)) ;
818 G2->SetPole(ii,curve_poles(ii)) ;
822 if (! error_status) {
826 di << "Not enought degree of freedom increase degree please\n";
835 //Static method computing deviation of curve and polyline
836 #include <math_PSO.hxx>
837 #include <math_PSOParticlesPool.hxx>
838 #include <math_MultipleVarFunction.hxx>
839 #include <math_BrentMinimum.hxx>
841 static Standard_Real CompLocalDev(const Adaptor3d_Curve& theCurve,
842 const Standard_Real u1, const Standard_Real u2);
844 static void ComputeDeviation(const Adaptor3d_Curve& theCurve,
845 const Handle(Geom_BSplineCurve)& thePnts,
846 Standard_Real& theDmax,
847 Standard_Real& theUfMax,
848 Standard_Real& theUlMax,
849 Standard_Integer& theImax)
857 Standard_Integer nbp = thePnts->NbKnots();
858 TColStd_Array1OfReal aKnots(1, nbp);
859 thePnts->Knots(aKnots);
862 for(i = 1; i < nbp; ++i)
864 Standard_Real u1 = aKnots(i), u2 = aKnots(i+1);
865 Standard_Real d = CompLocalDev(theCurve, u1, u2);
876 Standard_Real CompLocalDev(const Adaptor3d_Curve& theCurve,
877 const Standard_Real u1, const Standard_Real u2)
879 math_Vector aLowBorder(1,1);
880 math_Vector aUppBorder(1,1);
881 math_Vector aSteps(1,1);
885 aSteps(1) =(aUppBorder(1) - aLowBorder(1)) * 0.01; // Run PSO on even distribution with 100 points.
887 GCPnts_DistFunction aFunc1(theCurve, u1, u2);
889 Standard_Real aValue;
891 GCPnts_DistFunctionMV aFunc(aFunc1);
893 math_PSO aFinder(&aFunc, aLowBorder, aUppBorder, aSteps); // Choose 32 best points from 100 above.
894 aFinder.Perform(aSteps, aValue, aT);
895 Standard_Real d = 0.;
897 Standard_Real d1, d2;
898 Standard_Real x1 = Max(u1, aT(1) - aSteps(1));
899 Standard_Boolean Ok = aFunc1.Value(x1, d1);
902 return Sqrt(-aValue);
904 Standard_Real x2 = Min(u2, aT(1) + aSteps(1));
905 Ok = aFunc1.Value(x2, d2);
908 return Sqrt(-aValue);
910 if(!(d1 > aValue && d2 > aValue))
912 Standard_Real dmin = Min(d1, Min(aValue, d2));
916 math_BrentMinimum anOptLoc(Precision::PConfusion());
917 anOptLoc.Perform(aFunc1, x1, aT(1), x2);
919 if (anOptLoc.IsDone())
921 d = -anOptLoc.Minimum();
930 //=======================================================================
931 //function : crvpoints
933 //=======================================================================
935 static Standard_Integer crvpoints (Draw_Interpretor& di, Standard_Integer /*n*/, const char** a)
937 Standard_Integer i, nbp;
940 Handle(Adaptor3d_HCurve) aHCurve;
941 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
944 // try getting a wire
945 TopoDS_Wire aWire = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
948 cout << "cannot evaluate the argument " << a[2] << " as a curve" << endl;
951 BRepAdaptor_CompCurve aCompCurve(aWire);
952 aHCurve = new BRepAdaptor_HCompCurve(aCompCurve);
956 aHCurve = new GeomAdaptor_HCurve(C);
959 defl = Draw::Atof(a[3]);
961 GCPnts_QuasiUniformDeflection PntGen(aHCurve->Curve(), defl);
963 if(!PntGen.IsDone()) {
964 di << "Points generation failed\n";
968 nbp = PntGen.NbPoints();
969 di << "Nb points : " << nbp << "\n";
971 TColgp_Array1OfPnt aPoles(1, nbp);
972 TColStd_Array1OfReal aKnots(1, nbp);
973 TColStd_Array1OfInteger aMults(1, nbp);
975 for(i = 1; i <= nbp; ++i) {
976 aPoles(i) = PntGen.Value(i);
977 aKnots(i) = PntGen.Parameter(i);
984 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
985 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
987 aDrCrv->ClearPoles();
988 Draw_Color aKnColor(Draw_or);
989 aDrCrv->SetKnotsColor(aKnColor);
990 aDrCrv->SetKnotsShape(Draw_Plus);
992 Draw::Set(a[1], aDrCrv);
994 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
995 Standard_Integer imax = 0;
998 ComputeDeviation(aHCurve->Curve(), aPnts, dmax, ufmax, ulmax, imax);
999 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1004 //=======================================================================
1005 //function : crvtpoints
1007 //=======================================================================
1009 static Standard_Integer crvtpoints (Draw_Interpretor& di, Standard_Integer n, const char** a)
1011 Standard_Integer i, nbp;
1012 Standard_Real defl, angle = Precision::Angular();
1014 Handle(Adaptor3d_HCurve) aHCurve;
1015 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
1018 // try getting a wire
1019 TopoDS_Wire aWire = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1022 cout << "cannot evaluate the argument " << a[2] << " as a curve" << endl;
1025 BRepAdaptor_CompCurve aCompCurve(aWire);
1026 aHCurve = new BRepAdaptor_HCompCurve(aCompCurve);
1030 aHCurve = new GeomAdaptor_HCurve(C);
1032 defl = Draw::Atof(a[3]);
1035 angle = Draw::Atof(a[4]);
1037 GCPnts_TangentialDeflection PntGen(aHCurve->Curve(), angle, defl, 2);
1039 nbp = PntGen.NbPoints();
1040 di << "Nb points : " << nbp << "\n";
1042 TColgp_Array1OfPnt aPoles(1, nbp);
1043 TColStd_Array1OfReal aKnots(1, nbp);
1044 TColStd_Array1OfInteger aMults(1, nbp);
1046 for(i = 1; i <= nbp; ++i) {
1047 aPoles(i) = PntGen.Value(i);
1048 aKnots(i) = PntGen.Parameter(i);
1055 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
1056 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
1058 aDrCrv->ClearPoles();
1059 Draw_Color aKnColor(Draw_or);
1060 aDrCrv->SetKnotsColor(aKnColor);
1061 aDrCrv->SetKnotsShape(Draw_Plus);
1063 Draw::Set(a[1], aDrCrv);
1065 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
1066 Standard_Integer imax = 0;
1069 ComputeDeviation(aHCurve->Curve(), aPnts, dmax, ufmax, ulmax, imax);
1071 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1075 //=======================================================================
1076 //function : uniformAbscissa
1077 //purpose : epa test (TATA-06-002 (Problem with GCPnts_UniformAbscissa class)
1078 //=======================================================================
1079 static Standard_Integer uniformAbscissa (Draw_Interpretor& di, Standard_Integer n, const char** a)
1084 /*Handle(Geom_BSplineCurve) ellip;
1085 ellip = DrawTrSurf::GetBSplineCurve(a[1]);
1088 di << " BSpline is NULL \n";
1092 Handle(Geom_Curve) ellip;
1093 ellip = DrawTrSurf::GetCurve(a[1]);
1096 di << " Curve is NULL \n";
1100 Standard_Integer nocp;
1101 nocp = Draw::Atoi(a[2]);
1106 //test nbPoints for Geom_Ellipse
1110 GeomLProp_CLProps Prop(ellip,2,Precision::Intersection());
1111 Prop.SetCurve(ellip);
1113 GeomAdaptor_Curve GAC(ellip);
1114 di<<"Type Of curve: "<<GAC.GetType()<<"\n";
1115 Standard_Real Tol = Precision::Confusion();
1118 L = GCPnts_AbscissaPoint::Length(GAC, GAC.FirstParameter(), GAC.LastParameter(), Tol);
1119 di<<"Ellipse length = "<<L<<"\n";
1120 Standard_Real Abscissa = L/(nocp-1);
1121 di << " CUR : Abscissa " << Abscissa << "\n";
1123 GCPnts_UniformAbscissa myAlgo(GAC, Abscissa, ellip->FirstParameter(), ellip->LastParameter());
1124 if ( myAlgo.IsDone() )
1126 di << " CasCurve - nbpoints " << myAlgo.NbPoints() << "\n";
1127 for(Standard_Integer i = 1; i<= myAlgo.NbPoints(); i++ )
1128 di << i <<" points = " << myAlgo.Parameter( i ) << "\n";
1132 catch (Standard_Failure const&)
1134 di << " Standard Failure \n";
1139 //=======================================================================
1140 //function : EllipsUniformAbscissa
1141 //purpose : epa test (TATA-06-002 (Problem with GCPnts_UniformAbscissa class)
1142 //=======================================================================
1143 static Standard_Integer EllipsUniformAbscissa (Draw_Interpretor& di, Standard_Integer n, const char** a)
1149 R1 = Draw::Atof(a[1]);
1151 R2 = Draw::Atof(a[2]);
1153 Standard_Integer nocp;
1154 nocp = Draw::Atoi(a[3]);
1158 //test nbPoints for Geom_Ellipse
1159 Handle(Geom_Ellipse) ellip;
1165 location = gp_Pnt( 0.0, 0.0, 0.0);
1166 gp_Dir main_direction(0.0, 0.0, 1.0);
1168 gp_Dir x_direction(1.0, 0.0, 0.0);
1169 gp_Ax2 mainaxis( location, main_direction);
1171 mainaxis.SetXDirection(x_direction);
1172 ellip = new Geom_Ellipse(mainaxis,R1, R2);
1174 BRepBuilderAPI_MakeEdge curve_edge(ellip);
1175 TopoDS_Edge edge_curve = curve_edge.Edge();
1177 DBRep::Set("Ellipse",edge_curve);
1180 catch(Standard_Failure const&)
1182 di << " Standard Failure \n";
1187 GeomLProp_CLProps Prop(ellip,2,Precision::Intersection());
1188 Prop.SetCurve(ellip);
1190 GeomAdaptor_Curve GAC(ellip);
1191 di<<"Type Of curve: "<<GAC.GetType()<<"\n";
1192 Standard_Real Tol = Precision::Confusion();
1195 L = GCPnts_AbscissaPoint::Length(GAC, GAC.FirstParameter(), GAC.LastParameter(), Tol);
1196 di<<"Ellipse length = "<<L<<"\n";
1197 Standard_Real Abscissa = L/(nocp-1);
1198 di << " CUR : Abscissa " << Abscissa << "\n";
1200 GCPnts_UniformAbscissa myAlgo(GAC, Abscissa, ellip->FirstParameter(), ellip->LastParameter());
1201 if ( myAlgo.IsDone() )
1203 di << " CasCurve - nbpoints " << myAlgo.NbPoints() << "\n";
1204 for(Standard_Integer i = 1; i<= myAlgo.NbPoints(); i++ )
1205 di << i <<" points = " << myAlgo.Parameter( i ) << "\n";
1209 catch (Standard_Failure const&)
1211 di << " Standard Failure \n";
1216 //=======================================================================
1217 //function : discrCurve
1219 //=======================================================================
1220 static Standard_Integer discrCurve(Draw_Interpretor& di, Standard_Integer theArgNb, const char** theArgVec)
1224 di << "Invalid number of parameters.\n";
1228 Handle(Geom_Curve) aCurve = DrawTrSurf::GetCurve(theArgVec[2]);
1229 if (aCurve.IsNull())
1231 di << "Curve is NULL.\n";
1235 Standard_Integer aSrcNbPnts = 0;
1236 Standard_Boolean isUniform = Standard_False;
1237 for (Standard_Integer anArgIter = 3; anArgIter < theArgNb; ++anArgIter)
1239 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1240 TCollection_AsciiString anArgCase (anArg);
1241 anArgCase.LowerCase();
1242 if (anArgCase == "nbpnts")
1244 if (++anArgIter >= theArgNb)
1246 di << "Value for argument '" << anArg << "' is absent.\n";
1250 aSrcNbPnts = Draw::Atoi (theArgVec[anArgIter]);
1252 else if (anArgCase == "uniform")
1254 if (++anArgIter >= theArgNb)
1256 di << "Value for argument '" << anArg << "' is absent.\n";
1260 isUniform = (Draw::Atoi (theArgVec[anArgIter]) == 1);
1264 di << "Invalid argument '" << anArg << "'.\n";
1271 di << "Invalid count of points.\n";
1277 di << "Invalid type of discretization.\n";
1281 GeomAdaptor_Curve aCurveAdaptor(aCurve);
1282 GCPnts_UniformAbscissa aSplitter(aCurveAdaptor, aSrcNbPnts, Precision::Confusion());
1283 if (!aSplitter.IsDone())
1285 di << "Error: Invalid result.\n";
1289 const Standard_Integer aDstNbPnts = aSplitter.NbPoints();
1293 di << "Error: Invalid result.\n";
1297 TColgp_Array1OfPnt aPoles(1, aDstNbPnts);
1298 TColStd_Array1OfReal aKnots(1, aDstNbPnts);
1299 TColStd_Array1OfInteger aMultiplicities(1, aDstNbPnts);
1301 for (Standard_Integer aPntIter = 1; aPntIter <= aDstNbPnts; ++aPntIter)
1303 aPoles.ChangeValue(aPntIter) = aCurveAdaptor.Value(aSplitter.Parameter(aPntIter));
1304 aKnots.ChangeValue(aPntIter) = (aPntIter - 1) / (aDstNbPnts - 1.0);
1305 aMultiplicities.ChangeValue(aPntIter) = 1;
1307 aMultiplicities.ChangeValue(1) = 2;
1308 aMultiplicities.ChangeValue(aDstNbPnts) = 2;
1310 Handle(Geom_BSplineCurve) aPolyline =
1311 new Geom_BSplineCurve(aPoles, aKnots, aMultiplicities, 1);
1312 DrawTrSurf::Set(theArgVec[1], aPolyline);
1317 //=======================================================================
1318 //function : mypoints
1320 //=======================================================================
1322 static Standard_Integer mypoints (Draw_Interpretor& di, Standard_Integer /*n*/, const char** a)
1324 Standard_Integer i, nbp;
1327 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
1328 defl = Draw::Atof(a[3]);
1329 Handle(Geom_BSplineCurve) aBS (Handle(Geom_BSplineCurve)::DownCast(C));
1331 if(aBS.IsNull()) return 1;
1333 Standard_Integer ui1 = aBS->FirstUKnotIndex();
1334 Standard_Integer ui2 = aBS->LastUKnotIndex();
1336 Standard_Integer nbsu = ui2-ui1+1; nbsu += (nbsu - 1) * (aBS->Degree()-1);
1338 TColStd_Array1OfReal anUPars(1, nbsu);
1339 TColStd_Array1OfBoolean anUFlg(1, nbsu);
1341 Standard_Integer j, k, nbi;
1342 Standard_Real t1, t2, dt;
1344 //Filling of sample parameters
1345 nbi = aBS->Degree();
1347 t1 = aBS->Knot(ui1);
1348 for(i = ui1+1; i <= ui2; ++i) {
1355 anUFlg(k) = Standard_False;
1368 anUFlg(1) = Standard_True;
1369 anUFlg(nbsu) = Standard_True;
1370 Standard_Boolean bCont = Standard_True;
1371 while (j < nbsu-1 && bCont) {
1373 gp_Pnt p1 = aBS->Value(t2);
1374 for(k = j+2; k <= nbsu; ++k) {
1376 gp_Pnt p2 = aBS->Value(t2);
1377 gce_MakeLin MkLin(p1, p2);
1378 const gp_Lin& lin = MkLin.Value();
1379 Standard_Boolean ok = Standard_True;
1380 for(l = j+1; l < k; ++l) {
1381 if(anUFlg(l)) continue;
1382 gp_Pnt pp = aBS->Value(anUPars(l));
1383 Standard_Real d = lin.SquareDistance(pp);
1385 if(d <= defl) continue;
1387 ok = Standard_False;
1394 anUFlg(j) = Standard_True;
1400 if(k >= nbsu) bCont = Standard_False;
1404 for(i = 1; i <= nbsu; ++i) {
1405 if(anUFlg(i)) nbp++;
1408 TColgp_Array1OfPnt aPoles(1, nbp);
1409 TColStd_Array1OfReal aKnots(1, nbp);
1410 TColStd_Array1OfInteger aMults(1, nbp);
1412 for(i = 1; i <= nbsu; ++i) {
1415 aKnots(j) = anUPars(i);
1417 aPoles(j) = aBS->Value(aKnots(j));
1424 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
1425 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
1427 aDrCrv->ClearPoles();
1428 Draw_Color aKnColor(Draw_or);
1429 aDrCrv->SetKnotsColor(aKnColor);
1430 aDrCrv->SetKnotsShape(Draw_Plus);
1432 Draw::Set(a[1], aDrCrv);
1434 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
1435 Standard_Integer imax = 0;
1437 ComputeDeviation(GeomAdaptor_Curve(C),aPnts,dmax,ufmax,ulmax,imax);
1438 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1445 //=======================================================================
1446 //function : surfpoints
1448 //=======================================================================
1450 static Standard_Integer surfpoints (Draw_Interpretor& /*di*/, Standard_Integer /*n*/, const char** a)
1455 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
1456 defl = Draw::Atof(a[3]);
1458 Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(S);
1460 Handle(Adaptor3d_TopolTool) aTopTool = new Adaptor3d_TopolTool(AS);
1462 aTopTool->SamplePnts(defl, 10, 10);
1464 Standard_Integer nbpu = aTopTool->NbSamplesU();
1465 Standard_Integer nbpv = aTopTool->NbSamplesV();
1466 TColStd_Array1OfReal Upars(1, nbpu), Vpars(1, nbpv);
1467 aTopTool->UParameters(Upars);
1468 aTopTool->VParameters(Vpars);
1470 TColgp_Array2OfPnt aPoles(1, nbpu, 1, nbpv);
1471 TColStd_Array1OfReal anUKnots(1, nbpu);
1472 TColStd_Array1OfReal aVKnots(1, nbpv);
1473 TColStd_Array1OfInteger anUMults(1, nbpu);
1474 TColStd_Array1OfInteger aVMults(1, nbpv);
1477 for(i = 1; i <= nbpu; ++i) {
1478 anUKnots(i) = Upars(i);
1480 for(j = 1; j <= nbpv; ++j) {
1481 aVKnots(j) = Vpars(j);
1483 aPoles(i,j) = S->Value(anUKnots(i),aVKnots(j));
1492 Handle(Geom_BSplineSurface) aPnts = new Geom_BSplineSurface(aPoles, anUKnots, aVKnots,
1493 anUMults, aVMults, 1, 1);
1494 Handle(DrawTrSurf_BSplineSurface) aDrSurf = new DrawTrSurf_BSplineSurface(aPnts);
1496 aDrSurf->ClearPoles();
1497 Draw_Color aKnColor(Draw_or);
1498 aDrSurf->SetKnotsColor(aKnColor);
1499 aDrSurf->SetKnotsShape(Draw_Plus);
1501 Draw::Set(a[1], aDrSurf);
1509 //=======================================================================
1510 //function : intersect
1512 //=======================================================================
1513 static Standard_Integer intersection (Draw_Interpretor& di,
1514 Standard_Integer n, const char** a)
1520 Handle(Geom_Curve) GC1;
1521 Handle(Geom_Surface) GS1 = DrawTrSurf::GetSurface(a[2]);
1524 GC1 = DrawTrSurf::GetCurve(a[2]);
1530 Handle(Geom_Surface) GS2 = DrawTrSurf::GetSurface(a[3]);
1535 Standard_Real tol = Precision::Confusion();
1536 if (n == 5 || n == 9 || n == 13 || n == 17)
1537 tol = Draw::Atof(a[n-1]);
1540 Handle(Geom_Curve) Result;
1546 GeomInt_IntSS Inters;
1552 Inters.Perform(GS1,GS2,tol,Standard_True);
1554 else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
1556 Standard_Boolean useStart = Standard_True, useBnd = Standard_True;
1557 Standard_Integer ista1=0,ista2=0,ibnd1=0,ibnd2=0;
1558 Standard_Real UVsta[4];
1559 Handle(GeomAdaptor_HSurface) AS1,AS2;
1562 if (n <= 9) // user starting point
1564 useBnd = Standard_False;
1568 else if (n <= 13) // user bounding
1570 useStart = Standard_False;
1571 ibnd1 = 4; ibnd2 = 11;
1573 else // both user starting point and bounding
1575 ista1 = 4; ista2 = 7;
1576 ibnd1 = 8; ibnd2 = 15;
1581 for (Standard_Integer i=ista1; i <= ista2; i++)
1583 UVsta[i-ista1] = Draw::Atof(a[i]);
1589 Standard_Real UVbnd[8];
1590 for (Standard_Integer i=ibnd1; i <= ibnd2; i++)
1591 UVbnd[i-ibnd1] = Draw::Atof(a[i]);
1593 AS1 = new GeomAdaptor_HSurface(GS1,UVbnd[0],UVbnd[1],UVbnd[2],UVbnd[3]);
1594 AS2 = new GeomAdaptor_HSurface(GS2,UVbnd[4],UVbnd[5],UVbnd[6],UVbnd[7]);
1598 if (useStart && !useBnd)
1600 Inters.Perform(GS1,GS2,tol,UVsta[0],UVsta[1],UVsta[2],UVsta[3]);
1602 else if (!useStart && useBnd)
1604 Inters.Perform(AS1,AS2,tol);
1608 Inters.Perform(AS1,AS2,tol,UVsta[0],UVsta[1],UVsta[2],UVsta[3]);
1610 }//else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
1613 di<<"incorrect number of arguments\n";
1618 if (!Inters.IsDone())
1620 di<<"No intersections found!\n";
1627 Standard_Integer i, aNbLines, aNbPoints;
1630 aNbLines = Inters.NbLines();
1633 for (i=1; i<=aNbLines; ++i)
1635 Sprintf(buf, "%s_%d",a[1],i);
1637 Result = Inters.Line(i);
1638 const char* temp = buf;
1639 DrawTrSurf::Set(temp,Result);
1642 else if (aNbLines == 1)
1644 Result = Inters.Line(1);
1645 Sprintf(buf,"%s",a[1]);
1647 DrawTrSurf::Set(a[1],Result);
1651 aNbPoints=Inters.NbPoints();
1652 for (i=1; i<=aNbPoints; ++i)
1654 Point=Inters.Point(i);
1655 Sprintf(buf,"%s_p_%d",a[1],i);
1657 const char* temp = buf;
1658 DrawTrSurf::Set(temp, Point);
1660 }// if (GC1.IsNull())
1664 GeomAPI_IntCS Inters(GC1,GS2);
1667 if (!Inters.IsDone())
1669 di<<"No intersections found!\n";
1673 Standard_Integer nblines = Inters.NbSegments();
1674 Standard_Integer nbpoints = Inters.NbPoints();
1678 if ( (nblines+nbpoints) >= 2)
1681 Standard_Integer Compt = 1;
1684 cout << " Lines: " << endl;
1686 for (i = 1; i <= nblines; i++, Compt++)
1688 Sprintf(newname,"%s_%d",a[1],Compt);
1689 di << newname << " ";
1690 Result = Inters.Segment(i);
1691 const char* temp = newname; // pour portage WNT
1692 DrawTrSurf::Set(temp,Result);
1696 cout << " Points: " << endl;
1698 const Standard_Integer imax = nblines+nbpoints;
1700 for (/*i = 1*/; i <= imax; i++, Compt++)
1702 Sprintf(newname,"%s_%d",a[1],i);
1703 di << newname << " ";
1704 Point = Inters.Point(i);
1705 const char* temp = newname; // pour portage WNT
1706 DrawTrSurf::Set(temp,Point);
1709 else if (nblines == 1)
1711 Result = Inters.Segment(1);
1712 Sprintf(newname,"%s",a[1]);
1713 di << newname << " ";
1714 DrawTrSurf::Set(a[1],Result);
1716 else if (nbpoints == 1)
1718 Point = Inters.Point(1);
1719 Sprintf(newname,"%s",a[1]);
1720 di << newname << " ";
1721 DrawTrSurf::Set(a[1],Point);
1729 //=======================================================================
1730 //function : GetCurveContinuity
1731 //purpose : Returns the continuity of the given curve
1732 //=======================================================================
1733 static Standard_Integer GetCurveContinuity( Draw_Interpretor& theDI,
1734 Standard_Integer theNArg,
1735 const char** theArgv)
1739 theDI << "Use: getcurvcontinuity {curve or 2dcurve} \n";
1743 char aContName[7][3] = {"C0", //0
1751 Handle(Geom2d_Curve) GC2d;
1752 Handle(Geom_Curve) GC3d = DrawTrSurf::GetCurve(theArgv[1]);
1755 GC2d = DrawTrSurf::GetCurve2d(theArgv[1]);
1758 theDI << "Argument is not a 2D or 3D curve!\n";
1763 theDI << theArgv[1] << " has " << aContName[GC2d->Continuity()] << " continuity.\n";
1768 theDI << theArgv[1] << " has " << aContName[GC3d->Continuity()] << " continuity.\n";
1774 //=======================================================================
1775 //function : CurveCommands
1777 //=======================================================================
1778 void GeometryTest::CurveCommands(Draw_Interpretor& theCommands)
1781 static Standard_Boolean loaded = Standard_False;
1783 loaded = Standard_True;
1785 DrawTrSurf::BasicCommands(theCommands);
1789 g = "GEOMETRY curves creation";
1791 theCommands.Add("law",
1792 "law name degree nbknots knot, umult value",
1796 theCommands.Add("to2d","to2d c2dname c3d [plane (XOY)]",
1800 theCommands.Add("to3d","to3d c3dname c2d [plane (XOY)]",
1804 theCommands.Add("gproject",
1805 "gproject : [projectname] curve surface",
1809 theCommands.Add("project",
1810 "project : no args to have help",
1814 theCommands.Add("projonplane",
1815 "projonplane r C3d Plane [dx dy dz] [0/1]",
1818 theCommands.Add("bisec",
1819 "bisec result line/circle/point line/circle/point",
1823 g = "GEOMETRY Curves and Surfaces modification";
1826 theCommands.Add("movelaw",
1827 "movelaw name u x tx [ constraint = 0]",
1833 g = "GEOMETRY intersections";
1835 theCommands.Add("intersect",
1836 "intersect result surf1/curv1 surf2 [tolerance]\n\t\t "
1837 "intersect result surf1 surf2 [u1 v1 u2 v2] [U1F U1L V1F V1L U2F U2L V2F V2L] [tolerance]",
1841 theCommands.Add("crvpoints",
1842 "crvpoints result <curve or wire> deflection",
1846 theCommands.Add("crvtpoints",
1847 "crvtpoints result <curve or wire> deflection angular deflection - tangential deflection points",
1851 theCommands.Add("uniformAbscissa",
1852 "uniformAbscissa Curve nbPnt",
1856 theCommands.Add("uniformAbscissaEl",
1857 "uniformAbscissaEl maxR minR nbPnt",
1858 __FILE__, EllipsUniformAbscissa,g);
1860 theCommands.Add("discrCurve",
1861 "discrCurve polyline curve params\n"
1862 "Approximates a curve by a polyline (first degree B-spline).\n"
1863 "nbPnts number - creates polylines with the number points\n"
1864 "uniform 0 | 1 - creates polyline with equal length segments",
1865 __FILE__, discrCurve, g);
1867 theCommands.Add("mypoints",
1868 "mypoints result curv deflection",
1871 theCommands.Add("surfpoints",
1872 "surfoints result surf deflection",
1876 theCommands.Add("getcurvcontinuity",
1877 "getcurvcontinuity {curve or 2dcurve}: \n\tReturns the continuity of the given curve",
1879 GetCurveContinuity,g);