1 // File: GeometryTest_APICommands.cxx
2 // Created: Tue Jan 17 18:06:26 1995
3 // Author: Remi LEQUETTE
7 #include <Geom_Curve.hxx>
8 #include <Geom_Surface.hxx>
10 #include <Draw_Interpretor.hxx>
11 #include <DrawTrSurf.hxx>
12 #include <Draw_Appli.hxx>
13 #include <GeometryTest.hxx>
14 #include <GeomAPI_ProjectPointOnCurve.hxx>
15 #include <GeomAPI_ProjectPointOnSurf.hxx>
16 #include <GeomAPI_ExtremaCurveCurve.hxx>
17 #include <GeomAPI_ExtremaCurveSurface.hxx>
18 #include <GeomAPI_ExtremaSurfaceSurface.hxx>
19 #include <GeomAPI_PointsToBSpline.hxx>
20 #include <GeomAPI_PointsToBSplineSurface.hxx>
21 #include <Geom_Line.hxx>
22 #include <Geom_TrimmedCurve.hxx>
23 #include <Draw_Segment3D.hxx>
24 #include <Draw_Marker3D.hxx>
25 #include <Draw_Color.hxx>
26 #include <Draw_MarkerShape.hxx>
27 #include <TColgp_Array1OfPnt.hxx>
28 #include <TColgp_Array2OfPnt.hxx>
29 #include <TColStd_Array2OfReal.hxx>
30 #include <Precision.hxx>
33 Standard_IMPORT Draw_Viewer dout;
36 //=======================================================================
39 //=======================================================================
41 static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a)
45 gp_Pnt P(atof(a[2]),atof(a[3]),atof(a[4]));
49 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
50 Handle(Geom_Surface) GS;
53 GS = DrawTrSurf::GetSurface(a[1]);
56 Standard_Real U1, U2, V1, V2;
57 GS->Bounds(U1,U2,V1,V2);
59 GeomAPI_ProjectPointOnSurf proj(P,GS,U1,U2,V1,V2);
61 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
62 gp_Pnt P1 = proj.Point(i);
63 if ( P.Distance(P1) > Precision::Confusion()) {
64 Handle(Geom_Line) L = new Geom_Line(P,gp_Vec(P,P1));
65 Handle(Geom_TrimmedCurve) CT =
66 new Geom_TrimmedCurve(L, 0., P.Distance(P1));
67 sprintf(name,"%s%d","ext_",i);
68 char* temp = name; // portage WNT
69 DrawTrSurf::Set(temp, CT);
73 sprintf(name,"%s%d","ext_",i);
75 char* temp = name; // portage WNT
76 DrawTrSurf::Set(temp, P1);
77 proj.Parameters(i,UU,VV);
78 di << " Le point est sur la surface." << "\n";
79 di << " Ses parametres sont: UU = " << UU << "\n";
80 di << " VV = " << VV << "\n";
86 GeomAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(),
89 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
90 gp_Pnt P1 = proj.Point(i);
91 Standard_Real UU = proj.Parameter(i);
92 di << " parameter " << i << " = " << UU << "\n";
93 if ( P.Distance(P1) > Precision::Confusion()) {
94 Handle(Geom_Line) L = new Geom_Line(P,gp_Vec(P,P1));
95 Handle(Geom_TrimmedCurve) CT =
96 new Geom_TrimmedCurve(L, 0., P.Distance(P1));
97 sprintf(name,"%s%d","ext_",i);
98 char* temp = name; // portage WNT
99 DrawTrSurf::Set(temp, CT);
103 sprintf(name,"%s%d","ext_",i);
104 char* temp = name; // portage WNT
105 DrawTrSurf::Set(temp, P1);
107 UU = proj.Parameter(i);
108 di << " Le point est sur la courbe." << "\n";
109 di << " Son parametre est U = " << UU << "\n";
116 //=======================================================================
119 //=======================================================================
121 static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a)
125 Handle(Geom_Curve) GC;
126 Standard_Integer Nb = atoi(a[2]);
128 TColgp_Array1OfPnt Points(1, Nb);
130 Handle(Draw_Marker3D) mark;
133 GC = DrawTrSurf::GetCurve(a[3]);
137 Standard_Real U, U1, U2;
138 U1 = GC->FirstParameter();
139 U2 = GC->LastParameter();
140 Standard_Real Delta = ( U2 - U1) / (Nb-1);
141 for ( Standard_Integer i = 1 ; i <= Nb; i++) {
142 U = U1 + (i-1) * Delta;
143 Points(i) = GC->Value(U);
144 mark = new Draw_Marker3D( Points(i), Draw_X, Draw_vert);
149 Standard_Integer id,XX,YY,b;
150 dout.Select(id,XX,YY,b);
151 Standard_Real zoom = dout.Zoom(id);
153 Points(1) = gp_Pnt( ((Standard_Real)XX)/zoom,
154 ((Standard_Real)YY)/zoom,
157 mark = new Draw_Marker3D( Points(1), Draw_X, Draw_vert);
161 for (Standard_Integer i = 2; i<=Nb; i++) {
162 dout.Select(id,XX,YY,b);
163 Points(i) = gp_Pnt( ((Standard_Real)XX)/zoom,
164 ((Standard_Real)YY)/zoom,
166 mark = new Draw_Marker3D( Points(i), Draw_X, Draw_vert);
171 Standard_Integer Dmin = 3;
172 Standard_Integer Dmax = 8;
173 Standard_Real Tol3d = 1.e-3;
175 Handle(Geom_BSplineCurve) TheCurve;
176 GeomAPI_PointsToBSpline aPointToBSpline(Points,Dmin,Dmax,GeomAbs_C2,Tol3d);
177 TheCurve = aPointToBSpline.Curve();
180 DrawTrSurf::Set(a[1], TheCurve);
188 //=======================================================================
191 //=======================================================================
193 static Standard_Integer grilapp(Draw_Interpretor& di, Standard_Integer n, const char** a)
195 if ( n < 12) return 1;
197 Standard_Integer i,j;
198 Standard_Integer Nu = atoi(a[2]);
199 Standard_Integer Nv = atoi(a[3]);
200 TColStd_Array2OfReal ZPoints (1, Nu, 1, Nv);
202 Standard_Real X0 = atof(a[4]);
203 Standard_Real dX = atof(a[5]);
204 Standard_Real Y0 = atof(a[6]);
205 Standard_Real dY = atof(a[7]);
207 Standard_Integer Count = 8;
208 for ( j = 1; j <= Nv; j++) {
209 for ( i = 1; i <= Nu; i++) {
210 if ( Count > n) return 1;
211 ZPoints(i,j) = atof(a[Count]);
216 Handle(Geom_BSplineSurface) S
217 = GeomAPI_PointsToBSplineSurface(ZPoints,X0,dX,Y0,dY);
218 DrawTrSurf::Set(a[1],S);
225 //=======================================================================
228 //=======================================================================
230 static Standard_Integer surfapp(Draw_Interpretor& di, Standard_Integer n, const char** a)
232 if ( n < 5 ) return 1;
234 Standard_Integer i,j;
235 Standard_Integer Nu = atoi(a[2]);
236 Standard_Integer Nv = atoi(a[3]);
237 TColgp_Array2OfPnt Points (1, Nu, 1, Nv);
240 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[4]);
241 if ( Surf.IsNull()) return 1;
243 Standard_Real U, V, U1, V1, U2, V2;
244 Surf->Bounds( U1, U2, V1, V2);
245 for ( j = 1; j <= Nv; j++) {
246 V = V1 + (j-1) * (V2-V1) / (Nv-1);
247 for ( i = 1; i <= Nu; i++) {
248 U = U1 + (i-1) * (U2-U1) / (Nu-1);
249 Points(i,j) = Surf->Value(U,V);
254 Standard_Integer Count = 4;
255 for ( j = 1; j <= Nv; j++) {
256 for ( i = 1; i <= Nu; i++) {
257 if ( Count > n) return 1;
258 Points(i,j) = gp_Pnt(atof(a[Count]),atof(a[Count+1]),atof(a[Count+2]));
264 Standard_Integer Count = 1;
265 for ( j = 1; j <= Nv; j++) {
266 for ( i = 1; i <= Nu; i++) {
267 sprintf(name,"point_%d",Count++);
268 char* temp = name; // portage WNT
269 DrawTrSurf::Set(temp,Points(i,j));
273 Handle(Geom_BSplineSurface) S = GeomAPI_PointsToBSplineSurface(Points);
274 DrawTrSurf::Set(a[1],S);
281 //=======================================================================
284 //=======================================================================
286 static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
290 Handle(Geom_Curve) GC1, GC2;
291 Handle(Geom_Surface) GS1, GS2;
293 Standard_Boolean C1 = Standard_False;
294 Standard_Boolean C2 = Standard_False;
295 Standard_Boolean S1 = Standard_False;
296 Standard_Boolean S2 = Standard_False;
298 Standard_Real U1f,U1l,U2f,U2l,V1f,V1l,V2f,V2l;
300 GC1 = DrawTrSurf::GetCurve(a[1]);
302 GS1 = DrawTrSurf::GetSurface(a[1]);
306 GS1->Bounds(U1f,U1l,V1f,V1l);
310 U1f = GC1->FirstParameter();
311 U1l = GC1->LastParameter();
314 GC2 = DrawTrSurf::GetCurve(a[2]);
316 GS2 = DrawTrSurf::GetSurface(a[2]);
320 GS2->Bounds(U2f,U2l,V2f,V2l);
324 U2f = GC2->FirstParameter();
325 U2l = GC2->LastParameter();
330 GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
331 if(!Ex.Extrema().IsParallel()) {
332 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
335 if (P1.Distance(P2) < 1.e-16) {
336 di << "Extrema " << i << " is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
339 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
340 Handle(Geom_TrimmedCurve) CT =
341 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
342 sprintf(name,"%s%d","ext_",i);
343 char* temp = name; // portage WNT
344 DrawTrSurf::Set(temp, CT);
349 di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n";
353 GeomAPI_ExtremaCurveSurface Ex(GC1,GS2,U1f,U1l,U2f,U2l,V2f,V2l);
354 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
357 if (P1.Distance(P2) < 1.e-16) continue;
358 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
359 Handle(Geom_TrimmedCurve) CT =
360 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
361 sprintf(name,"%s%d","ext_",i);
362 char* temp = name; // portage WNT
363 DrawTrSurf::Set(temp, CT);
368 GeomAPI_ExtremaCurveSurface Ex(GC2,GS1,U2f,U2l,U1f,U1l,V1f,V1l);
369 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
372 if (P1.Distance(P2) < 1.e-16) continue;
373 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
374 Handle(Geom_TrimmedCurve) CT =
375 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
376 sprintf(name,"%s%d","ext_",i);
377 char* temp = name; // portage WNT
378 DrawTrSurf::Set(temp, CT);
383 GeomAPI_ExtremaSurfaceSurface Ex(GS1,GS2,U1f,U1l,V1f,V1l,U2f,U2l,V2f,V2l);
384 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
387 if (P1.Distance(P2) < 1.e-16) continue;
388 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
389 Handle(Geom_TrimmedCurve) CT =
390 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
391 sprintf(name,"%s%d","ext_",i);
392 char* temp = name; // portage WNT
393 DrawTrSurf::Set(temp, CT);
402 //=======================================================================
403 //function : totalextcc
405 //=======================================================================
407 static Standard_Integer totalextcc(Draw_Interpretor& di, Standard_Integer n, const char** a)
411 Handle(Geom_Curve) GC1, GC2;
414 Standard_Real U1f,U1l,U2f,U2l;
416 GC1 = DrawTrSurf::GetCurve(a[1]);
421 U1f = GC1->FirstParameter();
422 U1l = GC1->LastParameter();
425 GC2 = DrawTrSurf::GetCurve(a[2]);
430 U2f = GC2->FirstParameter();
431 U2l = GC2->LastParameter();
435 GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
437 if(Ex.TotalNearestPoints(P1,P2)) {
438 if (P1.Distance(P2) < 1.e-16) {
439 di << "Extrema is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
442 di << "Extrema is segment of line" << "\n";
443 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
444 Handle(Geom_TrimmedCurve) CT =
445 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
446 sprintf(name,"%s%d","ext_",1);
447 char* temp = name; // portage WNT
448 DrawTrSurf::Set(temp, CT);
452 Standard_Real u1, u2;
453 Ex.TotalLowerDistanceParameters(u1, u2);
455 di << "Parameters on curves : " << u1 << " " << u2 << "\n";
459 di << "Curves are infinite and parallel" << "\n";
462 di << "Minimal distance : " << Ex.TotalLowerDistance() << "\n";
469 void GeometryTest::APICommands(Draw_Interpretor& theCommands)
471 static Standard_Boolean done = Standard_False;
474 done = Standard_True;
477 g = "GEOMETRY curves and surfaces analysis";
479 theCommands.Add("proj", "proj curve/surf x y z",__FILE__, proj);
481 g = "GEOMETRY approximations";
483 theCommands.Add("appro", "appro result nbpoint [curve]",__FILE__, appro);
484 theCommands.Add("surfapp","surfapp result nbupoint nbvpoint x y z ....",
487 theCommands.Add("grilapp",
488 "grilapp result nbupoint nbvpoint X0 dX Y0 dY z11 z12 .. z1nu .... ",
491 g = "GEOMETRY curves and surfaces analysis";
493 theCommands.Add("extrema", "extrema curve/surface curve/surface",__FILE__,extrema);
494 theCommands.Add("totalextcc", "totalextcc curve curve",__FILE__,totalextcc);