1 // Created on: 1995-01-17
2 // Created by: Remi LEQUETTE
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <Geom_Curve.hxx>
24 #include <Geom_Surface.hxx>
26 #include <Draw_Interpretor.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <Draw_Appli.hxx>
29 #include <GeometryTest.hxx>
30 #include <GeomAPI_ProjectPointOnCurve.hxx>
31 #include <GeomAPI_ProjectPointOnSurf.hxx>
32 #include <GeomAPI_ExtremaCurveCurve.hxx>
33 #include <GeomAPI_ExtremaCurveSurface.hxx>
34 #include <GeomAPI_ExtremaSurfaceSurface.hxx>
35 #include <GeomAPI_PointsToBSpline.hxx>
36 #include <GeomAPI_PointsToBSplineSurface.hxx>
37 #include <Geom_Line.hxx>
38 #include <Geom_TrimmedCurve.hxx>
39 #include <Draw_Segment3D.hxx>
40 #include <Draw_Marker3D.hxx>
41 #include <Draw_Color.hxx>
42 #include <Draw_MarkerShape.hxx>
43 #include <TColgp_Array1OfPnt.hxx>
44 #include <TColgp_Array2OfPnt.hxx>
45 #include <TColStd_Array2OfReal.hxx>
46 #include <Precision.hxx>
49 Standard_IMPORT Draw_Viewer dout;
52 //=======================================================================
55 //=======================================================================
57 static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a)
61 cout << " Use proj curve/surf x y z [extrema algo: g(grad)/t(tree)]" << endl;
65 gp_Pnt P(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4]));
69 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
70 Handle(Geom_Surface) GS;
71 Extrema_ExtAlgo aProjAlgo = Extrema_ExtAlgo_Grad;
72 if (n == 6 && a[5][0] == 't')
73 aProjAlgo = Extrema_ExtAlgo_Tree;
76 GS = DrawTrSurf::GetSurface(a[1]);
79 Standard_Real U1, U2, V1, V2;
80 GS->Bounds(U1,U2,V1,V2);
82 GeomAPI_ProjectPointOnSurf proj(P,GS,U1,U2,V1,V2,aProjAlgo);
84 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
85 gp_Pnt P1 = proj.Point(i);
86 if ( P.Distance(P1) > Precision::Confusion()) {
87 Handle(Geom_Line) L = new Geom_Line(P,gp_Vec(P,P1));
88 Handle(Geom_TrimmedCurve) CT =
89 new Geom_TrimmedCurve(L, 0., P.Distance(P1));
90 Sprintf(name,"%s%d","ext_",i);
91 char* temp = name; // portage WNT
92 DrawTrSurf::Set(temp, CT);
96 Sprintf(name,"%s%d","ext_",i);
98 char* temp = name; // portage WNT
99 DrawTrSurf::Set(temp, P1);
100 proj.Parameters(i,UU,VV);
101 di << " Le point est sur la surface." << "\n";
102 di << " Ses parametres sont: UU = " << UU << "\n";
103 di << " VV = " << VV << "\n";
109 GeomAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(),
110 GC->LastParameter());
112 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
113 gp_Pnt P1 = proj.Point(i);
114 Standard_Real UU = proj.Parameter(i);
115 di << " parameter " << i << " = " << UU << "\n";
116 if ( P.Distance(P1) > Precision::Confusion()) {
117 Handle(Geom_Line) L = new Geom_Line(P,gp_Vec(P,P1));
118 Handle(Geom_TrimmedCurve) CT =
119 new Geom_TrimmedCurve(L, 0., P.Distance(P1));
120 Sprintf(name,"%s%d","ext_",i);
121 char* temp = name; // portage WNT
122 DrawTrSurf::Set(temp, CT);
126 Sprintf(name,"%s%d","ext_",i);
127 char* temp = name; // portage WNT
128 DrawTrSurf::Set(temp, P1);
130 UU = proj.Parameter(i);
131 di << " Le point est sur la courbe." << "\n";
132 di << " Son parametre est U = " << UU << "\n";
139 //=======================================================================
142 //=======================================================================
144 static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a)
148 Handle(Geom_Curve) GC;
149 Standard_Integer Nb = Draw::Atoi(a[2]);
151 TColgp_Array1OfPnt Points(1, Nb);
153 Handle(Draw_Marker3D) mark;
156 GC = DrawTrSurf::GetCurve(a[3]);
160 Standard_Real U, U1, U2;
161 U1 = GC->FirstParameter();
162 U2 = GC->LastParameter();
163 Standard_Real Delta = ( U2 - U1) / (Nb-1);
164 for ( Standard_Integer i = 1 ; i <= Nb; i++) {
165 U = U1 + (i-1) * Delta;
166 Points(i) = GC->Value(U);
167 mark = new Draw_Marker3D( Points(i), Draw_X, Draw_vert);
172 Standard_Integer id,XX,YY,b;
173 dout.Select(id,XX,YY,b);
174 Standard_Real zoom = dout.Zoom(id);
176 Points(1) = gp_Pnt( ((Standard_Real)XX)/zoom,
177 ((Standard_Real)YY)/zoom,
180 mark = new Draw_Marker3D( Points(1), Draw_X, Draw_vert);
184 for (Standard_Integer i = 2; i<=Nb; i++) {
185 dout.Select(id,XX,YY,b);
186 Points(i) = gp_Pnt( ((Standard_Real)XX)/zoom,
187 ((Standard_Real)YY)/zoom,
189 mark = new Draw_Marker3D( Points(i), Draw_X, Draw_vert);
194 Standard_Integer Dmin = 3;
195 Standard_Integer Dmax = 8;
196 Standard_Real Tol3d = 1.e-3;
198 Handle(Geom_BSplineCurve) TheCurve;
199 GeomAPI_PointsToBSpline aPointToBSpline(Points,Dmin,Dmax,GeomAbs_C2,Tol3d);
200 TheCurve = aPointToBSpline.Curve();
203 DrawTrSurf::Set(a[1], TheCurve);
211 //=======================================================================
214 //=======================================================================
216 static Standard_Integer grilapp(Draw_Interpretor& di, Standard_Integer n, const char** a)
218 if ( n < 12) return 1;
220 Standard_Integer i,j;
221 Standard_Integer Nu = Draw::Atoi(a[2]);
222 Standard_Integer Nv = Draw::Atoi(a[3]);
223 TColStd_Array2OfReal ZPoints (1, Nu, 1, Nv);
225 Standard_Real X0 = Draw::Atof(a[4]);
226 Standard_Real dX = Draw::Atof(a[5]);
227 Standard_Real Y0 = Draw::Atof(a[6]);
228 Standard_Real dY = Draw::Atof(a[7]);
230 Standard_Integer Count = 8;
231 for ( j = 1; j <= Nv; j++) {
232 for ( i = 1; i <= Nu; i++) {
233 if ( Count > n) return 1;
234 ZPoints(i,j) = Draw::Atof(a[Count]);
239 Handle(Geom_BSplineSurface) S
240 = GeomAPI_PointsToBSplineSurface(ZPoints,X0,dX,Y0,dY);
241 DrawTrSurf::Set(a[1],S);
248 //=======================================================================
251 //=======================================================================
253 static Standard_Integer surfapp(Draw_Interpretor& di, Standard_Integer n, const char** a)
255 if ( n < 5 ) return 1;
257 Standard_Integer i,j;
258 Standard_Integer Nu = Draw::Atoi(a[2]);
259 Standard_Integer Nv = Draw::Atoi(a[3]);
260 TColgp_Array2OfPnt Points (1, Nu, 1, Nv);
263 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[4]);
264 if ( Surf.IsNull()) return 1;
266 Standard_Real U, V, U1, V1, U2, V2;
267 Surf->Bounds( U1, U2, V1, V2);
268 for ( j = 1; j <= Nv; j++) {
269 V = V1 + (j-1) * (V2-V1) / (Nv-1);
270 for ( i = 1; i <= Nu; i++) {
271 U = U1 + (i-1) * (U2-U1) / (Nu-1);
272 Points(i,j) = Surf->Value(U,V);
277 Standard_Integer Count = 4;
278 for ( j = 1; j <= Nv; j++) {
279 for ( i = 1; i <= Nu; i++) {
280 if ( Count > n) return 1;
281 Points(i,j) = gp_Pnt(Draw::Atof(a[Count]),Draw::Atof(a[Count+1]),Draw::Atof(a[Count+2]));
287 Standard_Integer Count = 1;
288 for ( j = 1; j <= Nv; j++) {
289 for ( i = 1; i <= Nu; i++) {
290 Sprintf(name,"point_%d",Count++);
291 char* temp = name; // portage WNT
292 DrawTrSurf::Set(temp,Points(i,j));
296 Handle(Geom_BSplineSurface) S = GeomAPI_PointsToBSplineSurface(Points);
297 DrawTrSurf::Set(a[1],S);
304 //=======================================================================
307 //=======================================================================
309 static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
313 Handle(Geom_Curve) GC1, GC2;
314 Handle(Geom_Surface) GS1, GS2;
316 Standard_Boolean C1 = Standard_False;
317 Standard_Boolean C2 = Standard_False;
318 Standard_Boolean S1 = Standard_False;
319 Standard_Boolean S2 = Standard_False;
321 Standard_Real U1f,U1l,U2f,U2l,V1f,V1l,V2f,V2l;
323 GC1 = DrawTrSurf::GetCurve(a[1]);
325 GS1 = DrawTrSurf::GetSurface(a[1]);
329 GS1->Bounds(U1f,U1l,V1f,V1l);
333 U1f = GC1->FirstParameter();
334 U1l = GC1->LastParameter();
337 GC2 = DrawTrSurf::GetCurve(a[2]);
339 GS2 = DrawTrSurf::GetSurface(a[2]);
343 GS2->Bounds(U2f,U2l,V2f,V2l);
347 U2f = GC2->FirstParameter();
348 U2l = GC2->LastParameter();
353 GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
354 if(!Ex.Extrema().IsParallel()) {
355 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
358 if (P1.Distance(P2) < 1.e-16) {
359 di << "Extrema " << i << " is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
362 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
363 Handle(Geom_TrimmedCurve) CT =
364 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
365 Sprintf(name,"%s%d","ext_",i);
366 char* temp = name; // portage WNT
367 DrawTrSurf::Set(temp, CT);
372 di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n";
376 GeomAPI_ExtremaCurveSurface Ex(GC1,GS2,U1f,U1l,U2f,U2l,V2f,V2l);
377 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
380 if (P1.Distance(P2) < 1.e-16) continue;
381 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
382 Handle(Geom_TrimmedCurve) CT =
383 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
384 Sprintf(name,"%s%d","ext_",i);
385 char* temp = name; // portage WNT
386 DrawTrSurf::Set(temp, CT);
391 GeomAPI_ExtremaCurveSurface Ex(GC2,GS1,U2f,U2l,U1f,U1l,V1f,V1l);
392 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
395 if (P1.Distance(P2) < 1.e-16) continue;
396 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
397 Handle(Geom_TrimmedCurve) CT =
398 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
399 Sprintf(name,"%s%d","ext_",i);
400 char* temp = name; // portage WNT
401 DrawTrSurf::Set(temp, CT);
406 GeomAPI_ExtremaSurfaceSurface Ex(GS1,GS2,U1f,U1l,V1f,V1l,U2f,U2l,V2f,V2l);
407 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
410 if (P1.Distance(P2) < 1.e-16) continue;
411 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
412 Handle(Geom_TrimmedCurve) CT =
413 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
414 Sprintf(name,"%s%d","ext_",i);
415 char* temp = name; // portage WNT
416 DrawTrSurf::Set(temp, CT);
425 //=======================================================================
426 //function : totalextcc
428 //=======================================================================
430 static Standard_Integer totalextcc(Draw_Interpretor& di, Standard_Integer n, const char** a)
434 Handle(Geom_Curve) GC1, GC2;
437 Standard_Real U1f,U1l,U2f,U2l;
439 GC1 = DrawTrSurf::GetCurve(a[1]);
444 U1f = GC1->FirstParameter();
445 U1l = GC1->LastParameter();
448 GC2 = DrawTrSurf::GetCurve(a[2]);
453 U2f = GC2->FirstParameter();
454 U2l = GC2->LastParameter();
458 GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
460 if(Ex.TotalNearestPoints(P1,P2)) {
461 if (P1.Distance(P2) < 1.e-16) {
462 di << "Extrema is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
465 di << "Extrema is segment of line" << "\n";
466 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
467 Handle(Geom_TrimmedCurve) CT =
468 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
469 Sprintf(name,"%s%d","ext_",1);
470 char* temp = name; // portage WNT
471 DrawTrSurf::Set(temp, CT);
475 Standard_Real u1, u2;
476 Ex.TotalLowerDistanceParameters(u1, u2);
478 di << "Parameters on curves : " << u1 << " " << u2 << "\n";
482 di << "Curves are infinite and parallel" << "\n";
485 di << "Minimal distance : " << Ex.TotalLowerDistance() << "\n";
492 void GeometryTest::APICommands(Draw_Interpretor& theCommands)
494 static Standard_Boolean done = Standard_False;
497 done = Standard_True;
500 g = "GEOMETRY curves and surfaces analysis";
502 theCommands.Add("proj", "proj curve/surf x y z [extrema algo: g(grad)/t(tree)]",__FILE__, proj);
504 g = "GEOMETRY approximations";
506 theCommands.Add("appro", "appro result nbpoint [curve]",__FILE__, appro);
507 theCommands.Add("surfapp","surfapp result nbupoint nbvpoint x y z ....",
510 theCommands.Add("grilapp",
511 "grilapp result nbupoint nbvpoint X0 dX Y0 dY z11 z12 .. z1nu .... ",
514 g = "GEOMETRY curves and surfaces analysis";
516 theCommands.Add("extrema", "extrema curve/surface curve/surface",__FILE__,extrema);
517 theCommands.Add("totalextcc", "totalextcc curve curve",__FILE__,totalextcc);