1 // File: GeometryTest_API2dCommands.cxx
2 // Created: Wed Jan 11 10:33:13 1995
3 // Author: Remi LEQUETTE
5 // modified : pmn 11/04/97 : mis dans GeomliteTest
8 #include <GeomliteTest.hxx>
9 #include <Geom2d_Curve.hxx>
11 #include <Draw_Interpretor.hxx>
12 #include <DrawTrSurf.hxx>
13 #include <Draw_Appli.hxx>
14 #include <DrawTrSurf_Curve2d.hxx>
15 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
16 #include <Geom2dAPI_ExtremaCurveCurve.hxx>
17 #include <Geom2dAPI_PointsToBSpline.hxx>
18 #include <Geom2dAPI_InterCurveCurve.hxx>
19 #include <Geom2d_Line.hxx>
20 #include <Geom2d_TrimmedCurve.hxx>
21 #include <TColgp_Array1OfPnt2d.hxx>
23 #include <Draw_Marker2D.hxx>
24 #include <Draw_Color.hxx>
25 #include <Draw_MarkerShape.hxx>
26 #include <TColStd_Array1OfReal.hxx>
27 #include <GeomAbs_Shape.hxx>
28 #include <Precision.hxx>
32 Standard_IMPORT Draw_Viewer dout;
35 //=======================================================================
38 //=======================================================================
40 static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a)
44 gp_Pnt2d P(atof(a[2]),atof(a[3]));
48 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
53 Geom2dAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(),
56 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
57 gp_Pnt2d P1 = proj.Point(i);
58 Handle(Geom2d_Line) L = new Geom2d_Line(P,gp_Vec2d(P,P1));
59 Handle(Geom2d_TrimmedCurve) CT =
60 new Geom2d_TrimmedCurve(L, 0., P.Distance(P1));
61 sprintf(name,"%s%d","ext_",i);
62 char* temp = name; // portage WNT
63 DrawTrSurf::Set(temp, CT);
70 //=======================================================================
73 //=======================================================================
75 static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a)
77 // Approximation et interpolation 2d
80 // - affiche la tolerance
82 // - change la tolerance
83 // 2dappro result nbpoint
84 // - saisie interactive
85 // 2dappro result nbpoint curve
86 // - calcule des points sur la courbe
87 // 2dappro result nbpoint x1 y1 x2 y2 ..
88 // - tableau de points
89 // 2dappro result nbpoint x1 dx y1 y2 ..
90 // - tableau de points (x1,y1) (x1+dx,y2) ... avec x = t
93 static Standard_Real Tol2d = 1.e-6;
99 di << "Tolerance for 2d approx : "<< Tol2d << "\n";
104 Standard_Integer i, Nb = atoi(a[2]);
106 Standard_Boolean hasPoints = Standard_True;
107 TColgp_Array1OfPnt2d Points(1, Nb);
108 TColStd_Array1OfReal YValues(1,Nb);
109 Standard_Real X0=0,DX=0;
111 Handle(Draw_Marker2D) mark;
114 // saisie interactive
115 Standard_Integer id,XX,YY,b;
116 dout.Select(id,XX,YY,b);
117 Standard_Real zoom = dout.Zoom(id);
119 Points(1) = gp_Pnt2d( ((Standard_Real)XX)/zoom,
120 ((Standard_Real)YY)/zoom );
122 mark = new Draw_Marker2D( Points(1), Draw_X, Draw_vert);
126 for (i = 2; i<=Nb; i++) {
127 dout.Select(id,XX,YY,b);
128 Points(i) = gp_Pnt2d( ((Standard_Real)XX)/zoom,
129 ((Standard_Real)YY)/zoom );
130 mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert);
137 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[3]);
141 Standard_Real U, U1, U2;
142 U1 = GC->FirstParameter();
143 U2 = GC->LastParameter();
144 Standard_Real Delta = ( U2 - U1) / (Nb-1);
145 for ( i = 1 ; i <= Nb; i++) {
146 U = U1 + (i-1) * Delta;
147 Points(i) = GC->Value(U);
152 // test points ou ordonnees
153 hasPoints = Standard_False;
154 Standard_Integer nc = n - 3;
158 for (i = 1; i <= Nb; i++) {
159 Points(i).SetCoord(atof(a[nc]),atof(a[nc+1]));
163 else if (nc - 2 == Nb) {
168 for (i = 1; i <= Nb; i++) {
169 YValues(i) = atof(a[nc]);
170 Points(i).SetCoord(X0+(i-1)*DX,YValues(i));
177 // display the points
178 for ( i = 1 ; i <= Nb; i++) {
179 mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert);
184 Standard_Integer Dmin = 3;
185 Standard_Integer Dmax = 8;
187 Handle(Geom2d_BSplineCurve) TheCurve;
189 TheCurve = Geom2dAPI_PointsToBSpline(Points,Dmin,Dmax,GeomAbs_C2,Tol2d);
191 TheCurve = Geom2dAPI_PointsToBSpline(YValues,X0,DX,Dmin,Dmax,GeomAbs_C2,Tol2d);
193 DrawTrSurf::Set(a[1], TheCurve);
200 //=======================================================================
203 //=======================================================================
205 static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
209 Handle(Geom2d_Curve) GC1, GC2;
211 Standard_Real U1f,U1l,U2f,U2l;
213 GC1 = DrawTrSurf::GetCurve2d(a[1]);
216 U1f = GC1->FirstParameter();
217 U1l = GC1->LastParameter();
219 GC2 = DrawTrSurf::GetCurve2d(a[2]);
222 U2f = GC2->FirstParameter();
223 U2l = GC2->LastParameter();
227 Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
229 // modified by APV (compilation error - LINUX)
230 // for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
232 for ( i = 1; i <= Ex.NbExtrema(); i++) {
233 // modified by APV (compilation error - LINUX)
237 di << "dist " << i << ": " << Ex.Distance(i) << " \n";
238 if (Ex.Distance(i) <= Precision::PConfusion()) {
239 Handle(Draw_Marker2D) mark = new Draw_Marker2D( P1, Draw_X, Draw_vert);
244 Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2));
245 Handle(Geom2d_TrimmedCurve) CT =
246 new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2));
247 sprintf(name,"%s%d","ext_",i);
248 char* temp = name; // portage WNT
249 DrawTrSurf::Set(temp, CT);
254 di << "No decisions ";
260 //=======================================================================
261 //function : intersect
263 //=======================================================================
265 static Standard_Integer intersect(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
270 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]);
274 Standard_Real Tol = 0.001;
275 Geom2dAPI_InterCurveCurve Intersector;
277 Handle(Geom2d_Curve) C2;
279 C2 = DrawTrSurf::GetCurve2d(a[2]);
282 Intersector.Init(C1,C2,Tol);
285 Intersector.Init(C1, Tol);
290 for ( i = 1; i <= Intersector.NbPoints(); i++) {
291 gp_Pnt2d P = Intersector.Point(i);
292 Handle(Draw_Marker2D) mark = new Draw_Marker2D( P, Draw_X, Draw_vert);
297 Handle(Geom2d_Curve) S1,S2;
298 Handle(DrawTrSurf_Curve2d) CD;
300 for ( i = 1; i <= Intersector.NbSegments(); i++) {
301 Intersector.Segment(i,S1,S2);
302 CD = new DrawTrSurf_Curve2d(S1, Draw_bleu, 30);
304 CD = new DrawTrSurf_Curve2d(S2, Draw_violet, 30);
314 void GeomliteTest::API2dCommands(Draw_Interpretor& theCommands)
316 static Standard_Boolean done = Standard_False;
321 done = Standard_True;
322 g = "GEOMETRY curves and surfaces analysis";
324 theCommands.Add("2dproj", "proj curve x y",__FILE__, proj,g);
326 g = "GEOMETRY approximations";
328 theCommands.Add("2dapprox", "2dapprox result nbpoint [curve] [[x] y [x] y...]",__FILE__,
330 theCommands.Add("2dinterpole", "2dinterpole result nbpoint [curve] [[x] y [x] y ...]",__FILE__,
333 g = "GEOMETRY curves and surfaces analysis";
335 theCommands.Add("2dextrema", "extrema curve curve",__FILE__,
338 g = "GEOMETRY intersections";
340 theCommands.Add("2dintersect", "intersect curve curve",__FILE__,