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 // std::cout<<"Part "<<k<<" of the projection is punctual"<<std::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 // std::cout<<"Part "<<k<<" of the projection is U-isoparametric curve"<<std::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 // std::cout<<"Part "<<k<<" of the projection is V-isoparametric curve"<<std::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 appr.Perform(myMaxSeg, myMaxDegree, myContinuity, Only3d, Only2d);
373 PCur2d = appr.Curve2d();
374 di << " Error in 2d is " << appr.MaxError2dU()
375 << "; " << appr.MaxError2dV() << "\n";
378 Handle(Geom_Curve) OutCur =
379 new Geom_TrimmedCurve(GeomAdaptor::MakeCurve(hcur->Curve()),
381 DrawTrSurf::Set(temp, OutCur);
384 di << " Error in 3d is " << appr.MaxError3d() << "\n";
385 DrawTrSurf::Set(temp, appr.Curve3d());
387 DrawTrSurf::Set(temp1, PCur2d);
388 di<<temp<<" is 3d projected curve\n";
389 di<<temp1<<" is pcurve\n";
395 //=======================================================================
398 //=======================================================================
400 static Standard_Integer project (Draw_Interpretor& di,
401 Standard_Integer n, const char** a)
405 di << "project result2d c3d surf [-e p] [-v n] [-t tol]\n";
406 di << " -e p : extent the surface of <p>%\n";
407 di << " -v n : verify the projection at <n> points.\n";
408 di << " -t tol : set the tolerance for approximation\n";
413 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3]);
414 if (GS.IsNull()) return 1;
416 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
417 if (GC.IsNull()) return 1;
419 Standard_Real tolerance = Precision::Confusion() ;
421 Standard_Real U1,U2,V1,V2;
422 GS->Bounds(U1,U2,V1,V2);
424 Standard_Boolean Verif = Standard_False;
425 Standard_Integer NbPoints=0;
427 Standard_Integer index = 4;
428 while ( index+1 < n) {
429 if ( a[index][0] != '-') return 1;
431 if ( a[index][1] == 'e') {
432 Standard_Real p = Draw::Atof(a[index+1]);
433 Standard_Real dU = p * (U2 - U1) / 100.;
434 Standard_Real dV = p * (V2 - V1) / 100.;
435 U1 -= dU; U2 += dU; V1 -= dV; V2 += dV;
437 else if ( a[index][1] == 'v') {
438 Verif = Standard_True;
439 NbPoints = Draw::Atoi(a[index+1]);
441 else if ( a[index][1] == 't') {
442 tolerance = Draw::Atof(a[index+1]);
447 Handle(Geom2d_Curve) G2d =
448 GeomProjLib::Curve2d(GC, GS, U1, U2, V1, V2, tolerance);
450 if ( G2d.IsNull() ) {
451 di << "\nProjection Failed\n";
455 DrawTrSurf::Set(a[1],G2d);
457 if ( Verif) { // verify the projection on n points
458 if ( NbPoints <= 0) {
459 di << " n must be positive\n";
466 Standard_Real Dist,DistMax = -1.;
467 U1 = GC->FirstParameter();
468 U2 = GC->LastParameter();
469 dU = ( U2 - U1) / (NbPoints + 1);
470 for ( Standard_Integer i = 0 ; i <= NbPoints +1; i++) {
474 P2 = GS->Value(P2d.X(), P2d.Y());
475 Dist = P1.Distance(P2);
476 di << " Parameter = " << U << "\tDistance = " << Dist << "\n";
477 if ( Dist > DistMax) DistMax = Dist;
479 di << " **** Distance Maximale : " << DistMax << "\n";
485 //=======================================================================
486 //function : projonplane
488 //=======================================================================
490 Standard_Integer projonplane(Draw_Interpretor& di,
491 Standard_Integer n, const char** a)
493 if ( n < 4 ) return 1;
495 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
496 if ( S.IsNull()) return 1;
498 Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(S);
500 di << " The surface must be a plane\n";
504 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
505 if ( C.IsNull()) return 1;
507 Standard_Boolean Param = Standard_True;
508 if ((n == 5 && Draw::Atoi(a[4]) == 0) ||
509 (n == 8 && Draw::Atoi(a[7]) == 0)) Param = Standard_False;
514 D = gp_Dir(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
517 D = Pl->Pln().Position().Direction();
520 Handle(Geom_Curve) Res =
521 GeomProjLib::ProjectOnPlane(C,Pl,D,Param);
523 DrawTrSurf::Set(a[1],Res);
529 //=======================================================================
532 //=======================================================================
534 static void solution(const Handle(GccInt_Bisec)& Bis,
536 const Standard_Integer i)
540 Sprintf(solname,"%s",name);
542 Sprintf(solname,"%s_%d",name,i);
543 const char* temp = solname; // pour portage WNT
545 switch ( Bis->ArcType()) {
547 DrawTrSurf::Set(temp, new Geom2d_Line(Bis->Line()));
550 DrawTrSurf::Set(temp, new Geom2d_Circle(Bis->Circle()));
553 DrawTrSurf::Set(temp, new Geom2d_Ellipse(Bis->Ellipse()));
556 DrawTrSurf::Set(temp, new Geom2d_Parabola(Bis->Parabola()));
559 DrawTrSurf::Set(temp, new Geom2d_Hyperbola(Bis->Hyperbola()));
562 DrawTrSurf::Set(temp, Bis->Point());
567 static Standard_Integer bisec (Draw_Interpretor& di,
568 Standard_Integer n, const char** a)
572 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
573 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
575 Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
576 Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
577 Standard_Integer i, Compt = 0;
578 Standard_Integer NbSol = 0;
581 Handle(Standard_Type) Type1 = C1->DynamicType();
583 Handle(Standard_Type) Type2 = C2->DynamicType();
584 if ( Type1 == STANDARD_TYPE(Geom2d_Line) &&
585 Type2 == STANDARD_TYPE(Geom2d_Line) ) {
586 GccAna_Lin2dBisec Bis(Handle(Geom2d_Line)::DownCast(C1)->Lin2d(),
587 Handle(Geom2d_Line)::DownCast(C2)->Lin2d());
590 NbSol = Bis.NbSolutions();
591 for ( i = 1; i <= NbSol; i++) {
592 Sprintf(solname,"%s_%d",a[1],i);
593 const char* temp = solname; // pour portage WNT
594 DrawTrSurf::Set(temp,new Geom2d_Line(Bis.ThisSolution(i)));
598 di << " Bisec has failed !!\n";
602 else if ( Type1 == STANDARD_TYPE(Geom2d_Line) &&
603 Type2 == STANDARD_TYPE(Geom2d_Circle) ) {
604 GccAna_CircLin2dBisec
605 Bis(Handle(Geom2d_Circle)::DownCast(C2)->Circ2d(),
606 Handle(Geom2d_Line)::DownCast(C1)->Lin2d());
608 NbSol= Bis.NbSolutions();
609 if ( NbSol >= 2) Compt = 1;
610 for ( i = 1; i <= NbSol; i++) {
611 solution(Bis.ThisSolution(i),a[1],Compt);
616 di << " Bisec has failed !!\n";
620 else if ( Type2 == STANDARD_TYPE(Geom2d_Line) &&
621 Type1 == STANDARD_TYPE(Geom2d_Circle) ) {
622 GccAna_CircLin2dBisec
623 Bis(Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),
624 Handle(Geom2d_Line)::DownCast(C2)->Lin2d());
626 // char solname[200];
627 NbSol = Bis.NbSolutions();
628 if ( NbSol >= 2) Compt = 1;
629 for ( i = 1; i <= NbSol; i++) {
630 solution(Bis.ThisSolution(i),a[1],Compt);
635 di << " Bisec has failed !!\n";
639 else if ( Type2 == STANDARD_TYPE(Geom2d_Circle) &&
640 Type1 == STANDARD_TYPE(Geom2d_Circle) ) {
642 Bis(Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),
643 Handle(Geom2d_Circle)::DownCast(C2)->Circ2d());
645 // char solname[200];
646 NbSol = Bis.NbSolutions();
647 if ( NbSol >= 2) Compt = 1;
648 for ( i = 1; i <= NbSol; i++) {
649 solution(Bis.ThisSolution(i),a[1],Compt);
654 di << " Bisec has failed !!\n";
659 di << " args must be line/circle/point line/circle/point\n";
664 if ( Type1 == STANDARD_TYPE(Geom2d_Circle)) {
665 GccAna_CircPnt2dBisec Bis
666 (Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),P2);
668 NbSol = Bis.NbSolutions();
669 if ( NbSol >= 2) Compt = 1;
670 for ( i = 1; i <= NbSol; i++) {
671 solution(Bis.ThisSolution(i),a[1],Compt);
676 di << " Bisec has failed !!\n";
680 else if ( Type1 == STANDARD_TYPE(Geom2d_Line)) {
681 GccAna_LinPnt2dBisec Bis
682 (Handle(Geom2d_Line)::DownCast(C1)->Lin2d(),P2);
685 solution(Bis.ThisSolution(),a[1],0);
688 di << " Bisec has failed !!\n";
694 di << " the second arg must be line/circle/point \n";
699 Handle(Standard_Type) Type2 = C2->DynamicType();
700 if ( Type2 == STANDARD_TYPE(Geom2d_Circle)) {
701 GccAna_CircPnt2dBisec Bis
702 (Handle(Geom2d_Circle)::DownCast(C2)->Circ2d(),P1);
704 NbSol = Bis.NbSolutions();
705 if ( NbSol >= 2) Compt = 1;
706 for ( i = 1; i <= Bis.NbSolutions(); i++) {
707 solution(Bis.ThisSolution(i),a[1],Compt);
712 di << " Bisec has failed !!\n";
716 else if ( Type2 == STANDARD_TYPE(Geom2d_Line)) {
717 GccAna_LinPnt2dBisec Bis
718 (Handle(Geom2d_Line)::DownCast(C2)->Lin2d(),P1);
721 solution(Bis.ThisSolution(),a[1],0);
724 di << " Bisec has failed !!\n";
730 GccAna_Pnt2dBisec Bis(P1,P2);
731 if ( Bis.HasSolution()) {
733 DrawTrSurf::Set(a[1],new Geom2d_Line(Bis.ThisSolution()));
736 di << " Bisec has failed !!\n";
741 di << " the second arg must be line/circle/point \n";
746 di << " args must be line/circle/point line/circle/point\n";
751 di << "There are " << NbSol << " Solutions.\n";
754 di << "There is " << NbSol << " Solution.\n";
760 //=======================================================================
761 //function : cmovetangent
763 //=======================================================================
765 static Standard_Integer movelaw (Draw_Interpretor& di, Standard_Integer n, const char** a)
776 u = Draw::Atof(a[2]);
777 x = Draw::Atof(a[3]);
782 Handle(Geom2d_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve2d(a[1]);
784 tx = Draw::Atof(a[4]) ;
786 condition = Max(Draw::Atoi(a[5]), -1) ;
787 condition = Min(condition, G2->Degree()-1) ;
789 TColgp_Array1OfPnt2d curve_poles(1,G2->NbPoles()) ;
790 TColStd_Array1OfReal law_poles(1,G2->NbPoles()) ;
791 TColStd_Array1OfReal law_knots(1,G2->NbKnots()) ;
792 TColStd_Array1OfInteger law_mults(1,G2->NbKnots()) ;
794 G2->Knots(law_knots) ;
795 G2->Multiplicities(law_mults) ;
796 G2->Poles(curve_poles) ;
797 for (ii = 1 ; ii <= G2->NbPoles() ; ii++) {
798 law_poles(ii) = curve_poles(ii).Coord(2) ;
801 Law_BSpline a_law(law_poles,
807 a_law.MovePointAndTangent(u,
815 for (ii = 1 ; ii <= G2->NbPoles() ; ii++) {
816 curve_poles(ii).SetCoord(2,a_law.Pole(ii)) ;
817 G2->SetPole(ii,curve_poles(ii)) ;
821 if (! error_status) {
825 di << "Not enought degree of freedom increase degree please\n";
834 //Static method computing deviation of curve and polyline
835 #include <math_PSO.hxx>
836 #include <math_PSOParticlesPool.hxx>
837 #include <math_MultipleVarFunction.hxx>
838 #include <math_BrentMinimum.hxx>
840 static Standard_Real CompLocalDev(const Adaptor3d_Curve& theCurve,
841 const Standard_Real u1, const Standard_Real u2);
843 static void ComputeDeviation(const Adaptor3d_Curve& theCurve,
844 const Handle(Geom_BSplineCurve)& thePnts,
845 Standard_Real& theDmax,
846 Standard_Real& theUfMax,
847 Standard_Real& theUlMax,
848 Standard_Integer& theImax)
856 Standard_Integer nbp = thePnts->NbKnots();
857 TColStd_Array1OfReal aKnots(1, nbp);
858 thePnts->Knots(aKnots);
861 for(i = 1; i < nbp; ++i)
863 Standard_Real u1 = aKnots(i), u2 = aKnots(i+1);
864 Standard_Real d = CompLocalDev(theCurve, u1, u2);
875 Standard_Real CompLocalDev(const Adaptor3d_Curve& theCurve,
876 const Standard_Real u1, const Standard_Real u2)
878 math_Vector aLowBorder(1,1);
879 math_Vector aUppBorder(1,1);
880 math_Vector aSteps(1,1);
884 aSteps(1) =(aUppBorder(1) - aLowBorder(1)) * 0.01; // Run PSO on even distribution with 100 points.
886 GCPnts_DistFunction aFunc1(theCurve, u1, u2);
888 Standard_Real aValue;
890 GCPnts_DistFunctionMV aFunc(aFunc1);
892 math_PSO aFinder(&aFunc, aLowBorder, aUppBorder, aSteps); // Choose 32 best points from 100 above.
893 aFinder.Perform(aSteps, aValue, aT);
894 Standard_Real d = 0.;
896 Standard_Real d1, d2;
897 Standard_Real x1 = Max(u1, aT(1) - aSteps(1));
898 Standard_Boolean Ok = aFunc1.Value(x1, d1);
901 return Sqrt(-aValue);
903 Standard_Real x2 = Min(u2, aT(1) + aSteps(1));
904 Ok = aFunc1.Value(x2, d2);
907 return Sqrt(-aValue);
909 if(!(d1 > aValue && d2 > aValue))
911 Standard_Real dmin = Min(d1, Min(aValue, d2));
915 math_BrentMinimum anOptLoc(Precision::PConfusion());
916 anOptLoc.Perform(aFunc1, x1, aT(1), x2);
918 if (anOptLoc.IsDone())
920 d = -anOptLoc.Minimum();
929 //=======================================================================
930 //function : crvpoints
932 //=======================================================================
934 static Standard_Integer crvpoints (Draw_Interpretor& di, Standard_Integer /*n*/, const char** a)
936 Standard_Integer i, nbp;
939 Handle(Adaptor3d_HCurve) aHCurve;
940 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
943 // try getting a wire
944 TopoDS_Wire aWire = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
947 std::cout << "cannot evaluate the argument " << a[2] << " as a curve" << std::endl;
950 BRepAdaptor_CompCurve aCompCurve(aWire);
951 aHCurve = new BRepAdaptor_HCompCurve(aCompCurve);
955 aHCurve = new GeomAdaptor_HCurve(C);
958 defl = Draw::Atof(a[3]);
960 GCPnts_QuasiUniformDeflection PntGen(aHCurve->Curve(), defl);
962 if(!PntGen.IsDone()) {
963 di << "Points generation failed\n";
967 nbp = PntGen.NbPoints();
968 di << "Nb points : " << nbp << "\n";
970 TColgp_Array1OfPnt aPoles(1, nbp);
971 TColStd_Array1OfReal aKnots(1, nbp);
972 TColStd_Array1OfInteger aMults(1, nbp);
974 for(i = 1; i <= nbp; ++i) {
975 aPoles(i) = PntGen.Value(i);
976 aKnots(i) = PntGen.Parameter(i);
983 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
984 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
986 aDrCrv->ClearPoles();
987 Draw_Color aKnColor(Draw_or);
988 aDrCrv->SetKnotsColor(aKnColor);
989 aDrCrv->SetKnotsShape(Draw_Plus);
991 Draw::Set(a[1], aDrCrv);
993 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
994 Standard_Integer imax = 0;
997 ComputeDeviation(aHCurve->Curve(), aPnts, dmax, ufmax, ulmax, imax);
998 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1003 //=======================================================================
1004 //function : crvtpoints
1006 //=======================================================================
1008 static Standard_Integer crvtpoints (Draw_Interpretor& di, Standard_Integer n, const char** a)
1010 Standard_Integer i, nbp, aMinPntsNb = 2;
1011 Standard_Real defl, angle = Precision::Angular();
1013 Handle(Adaptor3d_HCurve) aHCurve;
1014 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
1017 // try getting a wire
1018 TopoDS_Wire aWire = TopoDS::Wire(DBRep::Get(a[2], TopAbs_WIRE));
1021 std::cout << "cannot evaluate the argument " << a[2] << " as a curve" << std::endl;
1024 BRepAdaptor_CompCurve aCompCurve(aWire);
1025 aHCurve = new BRepAdaptor_HCompCurve(aCompCurve);
1029 aHCurve = new GeomAdaptor_HCurve(C);
1031 defl = Draw::Atof(a[3]);
1034 angle = Draw::Atof(a[4]);
1037 aMinPntsNb = Draw::Atoi (a[5]);
1039 GCPnts_TangentialDeflection PntGen(aHCurve->Curve(), angle, defl, aMinPntsNb);
1041 nbp = PntGen.NbPoints();
1042 di << "Nb points : " << nbp << "\n";
1044 TColgp_Array1OfPnt aPoles(1, nbp);
1045 TColStd_Array1OfReal aKnots(1, nbp);
1046 TColStd_Array1OfInteger aMults(1, nbp);
1048 for(i = 1; i <= nbp; ++i) {
1049 aPoles(i) = PntGen.Value(i);
1050 aKnots(i) = PntGen.Parameter(i);
1057 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
1058 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
1060 aDrCrv->ClearPoles();
1061 Draw_Color aKnColor(Draw_or);
1062 aDrCrv->SetKnotsColor(aKnColor);
1063 aDrCrv->SetKnotsShape(Draw_Plus);
1065 Draw::Set(a[1], aDrCrv);
1067 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
1068 Standard_Integer imax = 0;
1071 ComputeDeviation(aHCurve->Curve(), aPnts, dmax, ufmax, ulmax, imax);
1073 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1077 //=======================================================================
1078 //function : uniformAbscissa
1079 //purpose : epa test (TATA-06-002 (Problem with GCPnts_UniformAbscissa class)
1080 //=======================================================================
1081 static Standard_Integer uniformAbscissa (Draw_Interpretor& di, Standard_Integer n, const char** a)
1086 /*Handle(Geom_BSplineCurve) ellip;
1087 ellip = DrawTrSurf::GetBSplineCurve(a[1]);
1090 di << " BSpline is NULL \n";
1094 Handle(Geom_Curve) ellip;
1095 ellip = DrawTrSurf::GetCurve(a[1]);
1098 di << " Curve is NULL \n";
1102 Standard_Integer nocp;
1103 nocp = Draw::Atoi(a[2]);
1108 //test nbPoints for Geom_Ellipse
1112 GeomLProp_CLProps Prop(ellip,2,Precision::Intersection());
1113 Prop.SetCurve(ellip);
1115 GeomAdaptor_Curve GAC(ellip);
1116 di<<"Type Of curve: "<<GAC.GetType()<<"\n";
1117 Standard_Real Tol = Precision::Confusion();
1120 L = GCPnts_AbscissaPoint::Length(GAC, GAC.FirstParameter(), GAC.LastParameter(), Tol);
1121 di<<"Ellipse length = "<<L<<"\n";
1122 Standard_Real Abscissa = L/(nocp-1);
1123 di << " CUR : Abscissa " << Abscissa << "\n";
1125 GCPnts_UniformAbscissa myAlgo(GAC, Abscissa, ellip->FirstParameter(), ellip->LastParameter());
1126 if ( myAlgo.IsDone() )
1128 di << " CasCurve - nbpoints " << myAlgo.NbPoints() << "\n";
1129 for(Standard_Integer i = 1; i<= myAlgo.NbPoints(); i++ )
1130 di << i <<" points = " << myAlgo.Parameter( i ) << "\n";
1134 catch (Standard_Failure const&)
1136 di << " Standard Failure \n";
1141 //=======================================================================
1142 //function : EllipsUniformAbscissa
1143 //purpose : epa test (TATA-06-002 (Problem with GCPnts_UniformAbscissa class)
1144 //=======================================================================
1145 static Standard_Integer EllipsUniformAbscissa (Draw_Interpretor& di, Standard_Integer n, const char** a)
1151 R1 = Draw::Atof(a[1]);
1153 R2 = Draw::Atof(a[2]);
1155 Standard_Integer nocp;
1156 nocp = Draw::Atoi(a[3]);
1160 //test nbPoints for Geom_Ellipse
1161 Handle(Geom_Ellipse) ellip;
1167 location = gp_Pnt( 0.0, 0.0, 0.0);
1168 gp_Dir main_direction(0.0, 0.0, 1.0);
1170 gp_Dir x_direction(1.0, 0.0, 0.0);
1171 gp_Ax2 mainaxis( location, main_direction);
1173 mainaxis.SetXDirection(x_direction);
1174 ellip = new Geom_Ellipse(mainaxis,R1, R2);
1176 BRepBuilderAPI_MakeEdge curve_edge(ellip);
1177 TopoDS_Edge edge_curve = curve_edge.Edge();
1179 DBRep::Set("Ellipse",edge_curve);
1182 catch(Standard_Failure const&)
1184 di << " Standard Failure \n";
1189 GeomLProp_CLProps Prop(ellip,2,Precision::Intersection());
1190 Prop.SetCurve(ellip);
1192 GeomAdaptor_Curve GAC(ellip);
1193 di<<"Type Of curve: "<<GAC.GetType()<<"\n";
1194 Standard_Real Tol = Precision::Confusion();
1197 L = GCPnts_AbscissaPoint::Length(GAC, GAC.FirstParameter(), GAC.LastParameter(), Tol);
1198 di<<"Ellipse length = "<<L<<"\n";
1199 Standard_Real Abscissa = L/(nocp-1);
1200 di << " CUR : Abscissa " << Abscissa << "\n";
1202 GCPnts_UniformAbscissa myAlgo(GAC, Abscissa, ellip->FirstParameter(), ellip->LastParameter());
1203 if ( myAlgo.IsDone() )
1205 di << " CasCurve - nbpoints " << myAlgo.NbPoints() << "\n";
1206 for(Standard_Integer i = 1; i<= myAlgo.NbPoints(); i++ )
1207 di << i <<" points = " << myAlgo.Parameter( i ) << "\n";
1211 catch (Standard_Failure const&)
1213 di << " Standard Failure \n";
1218 //=======================================================================
1219 //function : discrCurve
1221 //=======================================================================
1222 static Standard_Integer discrCurve(Draw_Interpretor& di, Standard_Integer theArgNb, const char** theArgVec)
1226 di << "Invalid number of parameters.\n";
1230 Handle(Geom_Curve) aCurve = DrawTrSurf::GetCurve(theArgVec[2]);
1231 if (aCurve.IsNull())
1233 di << "Curve is NULL.\n";
1237 Standard_Integer aSrcNbPnts = 0;
1238 Standard_Boolean isUniform = Standard_False;
1239 for (Standard_Integer anArgIter = 3; anArgIter < theArgNb; ++anArgIter)
1241 TCollection_AsciiString anArg (theArgVec[anArgIter]);
1242 TCollection_AsciiString anArgCase (anArg);
1243 anArgCase.LowerCase();
1244 if (anArgCase == "nbpnts")
1246 if (++anArgIter >= theArgNb)
1248 di << "Value for argument '" << anArg << "' is absent.\n";
1252 aSrcNbPnts = Draw::Atoi (theArgVec[anArgIter]);
1254 else if (anArgCase == "uniform")
1256 if (++anArgIter >= theArgNb)
1258 di << "Value for argument '" << anArg << "' is absent.\n";
1262 isUniform = (Draw::Atoi (theArgVec[anArgIter]) == 1);
1266 di << "Invalid argument '" << anArg << "'.\n";
1273 di << "Invalid count of points.\n";
1279 di << "Invalid type of discretization.\n";
1283 GeomAdaptor_Curve aCurveAdaptor(aCurve);
1284 GCPnts_UniformAbscissa aSplitter(aCurveAdaptor, aSrcNbPnts, Precision::Confusion());
1285 if (!aSplitter.IsDone())
1287 di << "Error: Invalid result.\n";
1291 const Standard_Integer aDstNbPnts = aSplitter.NbPoints();
1295 di << "Error: Invalid result.\n";
1299 TColgp_Array1OfPnt aPoles(1, aDstNbPnts);
1300 TColStd_Array1OfReal aKnots(1, aDstNbPnts);
1301 TColStd_Array1OfInteger aMultiplicities(1, aDstNbPnts);
1303 for (Standard_Integer aPntIter = 1; aPntIter <= aDstNbPnts; ++aPntIter)
1305 aPoles.ChangeValue(aPntIter) = aCurveAdaptor.Value(aSplitter.Parameter(aPntIter));
1306 aKnots.ChangeValue(aPntIter) = (aPntIter - 1) / (aDstNbPnts - 1.0);
1307 aMultiplicities.ChangeValue(aPntIter) = 1;
1309 aMultiplicities.ChangeValue(1) = 2;
1310 aMultiplicities.ChangeValue(aDstNbPnts) = 2;
1312 Handle(Geom_BSplineCurve) aPolyline =
1313 new Geom_BSplineCurve(aPoles, aKnots, aMultiplicities, 1);
1314 DrawTrSurf::Set(theArgVec[1], aPolyline);
1319 //=======================================================================
1320 //function : mypoints
1322 //=======================================================================
1324 static Standard_Integer mypoints (Draw_Interpretor& di, Standard_Integer /*n*/, const char** a)
1326 Standard_Integer i, nbp;
1329 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
1330 defl = Draw::Atof(a[3]);
1331 Handle(Geom_BSplineCurve) aBS (Handle(Geom_BSplineCurve)::DownCast(C));
1333 if(aBS.IsNull()) return 1;
1335 Standard_Integer ui1 = aBS->FirstUKnotIndex();
1336 Standard_Integer ui2 = aBS->LastUKnotIndex();
1338 Standard_Integer nbsu = ui2-ui1+1; nbsu += (nbsu - 1) * (aBS->Degree()-1);
1340 TColStd_Array1OfReal anUPars(1, nbsu);
1341 TColStd_Array1OfBoolean anUFlg(1, nbsu);
1343 Standard_Integer j, k, nbi;
1344 Standard_Real t1, t2, dt;
1346 //Filling of sample parameters
1347 nbi = aBS->Degree();
1349 t1 = aBS->Knot(ui1);
1350 for(i = ui1+1; i <= ui2; ++i) {
1357 anUFlg(k) = Standard_False;
1370 anUFlg(1) = Standard_True;
1371 anUFlg(nbsu) = Standard_True;
1372 Standard_Boolean bCont = Standard_True;
1373 while (j < nbsu-1 && bCont) {
1375 gp_Pnt p1 = aBS->Value(t2);
1376 for(k = j+2; k <= nbsu; ++k) {
1378 gp_Pnt p2 = aBS->Value(t2);
1379 gce_MakeLin MkLin(p1, p2);
1380 const gp_Lin& lin = MkLin.Value();
1381 Standard_Boolean ok = Standard_True;
1382 for(l = j+1; l < k; ++l) {
1383 if(anUFlg(l)) continue;
1384 gp_Pnt pp = aBS->Value(anUPars(l));
1385 Standard_Real d = lin.SquareDistance(pp);
1387 if(d <= defl) continue;
1389 ok = Standard_False;
1396 anUFlg(j) = Standard_True;
1402 if(k >= nbsu) bCont = Standard_False;
1406 for(i = 1; i <= nbsu; ++i) {
1407 if(anUFlg(i)) nbp++;
1410 TColgp_Array1OfPnt aPoles(1, nbp);
1411 TColStd_Array1OfReal aKnots(1, nbp);
1412 TColStd_Array1OfInteger aMults(1, nbp);
1414 for(i = 1; i <= nbsu; ++i) {
1417 aKnots(j) = anUPars(i);
1419 aPoles(j) = aBS->Value(aKnots(j));
1426 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
1427 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
1429 aDrCrv->ClearPoles();
1430 Draw_Color aKnColor(Draw_or);
1431 aDrCrv->SetKnotsColor(aKnColor);
1432 aDrCrv->SetKnotsShape(Draw_Plus);
1434 Draw::Set(a[1], aDrCrv);
1436 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
1437 Standard_Integer imax = 0;
1439 ComputeDeviation(GeomAdaptor_Curve(C),aPnts,dmax,ufmax,ulmax,imax);
1440 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1447 //=======================================================================
1448 //function : surfpoints
1450 //=======================================================================
1452 static Standard_Integer surfpoints (Draw_Interpretor& /*di*/, Standard_Integer /*n*/, const char** a)
1457 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
1458 defl = Draw::Atof(a[3]);
1460 Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(S);
1462 Handle(Adaptor3d_TopolTool) aTopTool = new Adaptor3d_TopolTool(AS);
1464 aTopTool->SamplePnts(defl, 10, 10);
1466 Standard_Integer nbpu = aTopTool->NbSamplesU();
1467 Standard_Integer nbpv = aTopTool->NbSamplesV();
1468 TColStd_Array1OfReal Upars(1, nbpu), Vpars(1, nbpv);
1469 aTopTool->UParameters(Upars);
1470 aTopTool->VParameters(Vpars);
1472 TColgp_Array2OfPnt aPoles(1, nbpu, 1, nbpv);
1473 TColStd_Array1OfReal anUKnots(1, nbpu);
1474 TColStd_Array1OfReal aVKnots(1, nbpv);
1475 TColStd_Array1OfInteger anUMults(1, nbpu);
1476 TColStd_Array1OfInteger aVMults(1, nbpv);
1479 for(i = 1; i <= nbpu; ++i) {
1480 anUKnots(i) = Upars(i);
1482 for(j = 1; j <= nbpv; ++j) {
1483 aVKnots(j) = Vpars(j);
1485 aPoles(i,j) = S->Value(anUKnots(i),aVKnots(j));
1494 Handle(Geom_BSplineSurface) aPnts = new Geom_BSplineSurface(aPoles, anUKnots, aVKnots,
1495 anUMults, aVMults, 1, 1);
1496 Handle(DrawTrSurf_BSplineSurface) aDrSurf = new DrawTrSurf_BSplineSurface(aPnts);
1498 aDrSurf->ClearPoles();
1499 Draw_Color aKnColor(Draw_or);
1500 aDrSurf->SetKnotsColor(aKnColor);
1501 aDrSurf->SetKnotsShape(Draw_Plus);
1503 Draw::Set(a[1], aDrSurf);
1511 //=======================================================================
1512 //function : intersect
1514 //=======================================================================
1515 static Standard_Integer intersection (Draw_Interpretor& di,
1516 Standard_Integer n, const char** a)
1522 Handle(Geom_Curve) GC1;
1523 Handle(Geom_Surface) GS1 = DrawTrSurf::GetSurface(a[2]);
1526 GC1 = DrawTrSurf::GetCurve(a[2]);
1532 Handle(Geom_Surface) GS2 = DrawTrSurf::GetSurface(a[3]);
1537 Standard_Real tol = Precision::Confusion();
1538 if (n == 5 || n == 9 || n == 13 || n == 17)
1539 tol = Draw::Atof(a[n-1]);
1542 Handle(Geom_Curve) Result;
1548 GeomInt_IntSS Inters;
1554 Inters.Perform(GS1,GS2,tol,Standard_True);
1556 else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
1558 Standard_Boolean useStart = Standard_True, useBnd = Standard_True;
1559 Standard_Integer ista1=0,ista2=0,ibnd1=0,ibnd2=0;
1560 Standard_Real UVsta[4];
1561 Handle(GeomAdaptor_HSurface) AS1,AS2;
1564 if (n <= 9) // user starting point
1566 useBnd = Standard_False;
1570 else if (n <= 13) // user bounding
1572 useStart = Standard_False;
1573 ibnd1 = 4; ibnd2 = 11;
1575 else // both user starting point and bounding
1577 ista1 = 4; ista2 = 7;
1578 ibnd1 = 8; ibnd2 = 15;
1583 for (Standard_Integer i=ista1; i <= ista2; i++)
1585 UVsta[i-ista1] = Draw::Atof(a[i]);
1591 Standard_Real UVbnd[8];
1592 for (Standard_Integer i=ibnd1; i <= ibnd2; i++)
1593 UVbnd[i-ibnd1] = Draw::Atof(a[i]);
1595 AS1 = new GeomAdaptor_HSurface(GS1,UVbnd[0],UVbnd[1],UVbnd[2],UVbnd[3]);
1596 AS2 = new GeomAdaptor_HSurface(GS2,UVbnd[4],UVbnd[5],UVbnd[6],UVbnd[7]);
1600 if (useStart && !useBnd)
1602 Inters.Perform(GS1,GS2,tol,UVsta[0],UVsta[1],UVsta[2],UVsta[3]);
1604 else if (!useStart && useBnd)
1606 Inters.Perform(AS1,AS2,tol);
1610 Inters.Perform(AS1,AS2,tol,UVsta[0],UVsta[1],UVsta[2],UVsta[3]);
1612 }//else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
1615 di<<"incorrect number of arguments\n";
1620 if (!Inters.IsDone())
1622 di<<"No intersections found!\n";
1629 Standard_Integer i, aNbLines, aNbPoints;
1632 aNbLines = Inters.NbLines();
1635 for (i=1; i<=aNbLines; ++i)
1637 Sprintf(buf, "%s_%d",a[1],i);
1639 Result = Inters.Line(i);
1640 const char* temp = buf;
1641 DrawTrSurf::Set(temp,Result);
1644 else if (aNbLines == 1)
1646 Result = Inters.Line(1);
1647 Sprintf(buf,"%s",a[1]);
1649 DrawTrSurf::Set(a[1],Result);
1653 aNbPoints=Inters.NbPoints();
1654 for (i=1; i<=aNbPoints; ++i)
1656 Point=Inters.Point(i);
1657 Sprintf(buf,"%s_p_%d",a[1],i);
1659 const char* temp = buf;
1660 DrawTrSurf::Set(temp, Point);
1662 }// if (GC1.IsNull())
1666 GeomAPI_IntCS Inters(GC1,GS2);
1669 if (!Inters.IsDone())
1671 di<<"No intersections found!\n";
1675 Standard_Integer nblines = Inters.NbSegments();
1676 Standard_Integer nbpoints = Inters.NbPoints();
1680 if ( (nblines+nbpoints) >= 2)
1683 Standard_Integer Compt = 1;
1686 std::cout << " Lines: " << std::endl;
1688 for (i = 1; i <= nblines; i++, Compt++)
1690 Sprintf(newname,"%s_%d",a[1],Compt);
1691 di << newname << " ";
1692 Result = Inters.Segment(i);
1693 const char* temp = newname; // pour portage WNT
1694 DrawTrSurf::Set(temp,Result);
1698 std::cout << " Points: " << std::endl;
1700 const Standard_Integer imax = nblines+nbpoints;
1702 for (/*i = 1*/; i <= imax; i++, Compt++)
1704 Sprintf(newname,"%s_%d",a[1],i);
1705 di << newname << " ";
1706 Point = Inters.Point(i);
1707 const char* temp = newname; // pour portage WNT
1708 DrawTrSurf::Set(temp,Point);
1711 else if (nblines == 1)
1713 Result = Inters.Segment(1);
1714 Sprintf(newname,"%s",a[1]);
1715 di << newname << " ";
1716 DrawTrSurf::Set(a[1],Result);
1718 else if (nbpoints == 1)
1720 Point = Inters.Point(1);
1721 Sprintf(newname,"%s",a[1]);
1722 di << newname << " ";
1723 DrawTrSurf::Set(a[1],Point);
1731 //=======================================================================
1732 //function : GetCurveContinuity
1733 //purpose : Returns the continuity of the given curve
1734 //=======================================================================
1735 static Standard_Integer GetCurveContinuity( Draw_Interpretor& theDI,
1736 Standard_Integer theNArg,
1737 const char** theArgv)
1741 theDI << "Use: getcurvcontinuity {curve or 2dcurve} \n";
1745 char aContName[7][3] = {"C0", //0
1753 Handle(Geom2d_Curve) GC2d;
1754 Handle(Geom_Curve) GC3d = DrawTrSurf::GetCurve(theArgv[1]);
1757 GC2d = DrawTrSurf::GetCurve2d(theArgv[1]);
1760 theDI << "Argument is not a 2D or 3D curve!\n";
1765 theDI << theArgv[1] << " has " << aContName[GC2d->Continuity()] << " continuity.\n";
1770 theDI << theArgv[1] << " has " << aContName[GC3d->Continuity()] << " continuity.\n";
1776 //=======================================================================
1777 //function : CurveCommands
1779 //=======================================================================
1780 void GeometryTest::CurveCommands(Draw_Interpretor& theCommands)
1783 static Standard_Boolean loaded = Standard_False;
1785 loaded = Standard_True;
1787 DrawTrSurf::BasicCommands(theCommands);
1791 g = "GEOMETRY curves creation";
1793 theCommands.Add("law",
1794 "law name degree nbknots knot, umult value",
1798 theCommands.Add("to2d","to2d c2dname c3d [plane (XOY)]",
1802 theCommands.Add("to3d","to3d c3dname c2d [plane (XOY)]",
1806 theCommands.Add("gproject",
1807 "gproject : [projectname] curve surface",
1811 theCommands.Add("project",
1812 "project : no args to have help",
1816 theCommands.Add("projonplane",
1817 "projonplane r C3d Plane [dx dy dz] [0/1]",
1820 theCommands.Add("bisec",
1821 "bisec result line/circle/point line/circle/point",
1825 g = "GEOMETRY Curves and Surfaces modification";
1828 theCommands.Add("movelaw",
1829 "movelaw name u x tx [ constraint = 0]",
1835 g = "GEOMETRY intersections";
1837 theCommands.Add("intersect",
1838 "intersect result surf1/curv1 surf2 [tolerance]\n\t\t "
1839 "intersect result surf1 surf2 [u1 v1 u2 v2] [U1F U1L V1F V1L U2F U2L V2F V2L] [tolerance]",
1843 theCommands.Add("crvpoints",
1844 "crvpoints result <curve or wire> deflection",
1848 theCommands.Add("crvtpoints",
1849 "crvtpoints result <curve or wire> deflection angular deflection - tangential deflection points",
1853 theCommands.Add("uniformAbscissa",
1854 "uniformAbscissa Curve nbPnt",
1858 theCommands.Add("uniformAbscissaEl",
1859 "uniformAbscissaEl maxR minR nbPnt",
1860 __FILE__, EllipsUniformAbscissa,g);
1862 theCommands.Add("discrCurve",
1863 "discrCurve polyline curve params\n"
1864 "Approximates a curve by a polyline (first degree B-spline).\n"
1865 "nbPnts number - creates polylines with the number points\n"
1866 "uniform 0 | 1 - creates polyline with equal length segments",
1867 __FILE__, discrCurve, g);
1869 theCommands.Add("mypoints",
1870 "mypoints result curv deflection",
1873 theCommands.Add("surfpoints",
1874 "surfoints result surf deflection",
1878 theCommands.Add("getcurvcontinuity",
1879 "getcurvcontinuity {curve or 2dcurve}: \n\tReturns the continuity of the given curve",
1881 GetCurveContinuity,g);