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 gp_Pnt P(atof(a[2]),atof(a[3]),atof(a[4]));
65 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[1]);
66 Handle(Geom_Surface) GS;
69 GS = DrawTrSurf::GetSurface(a[1]);
72 Standard_Real U1, U2, V1, V2;
73 GS->Bounds(U1,U2,V1,V2);
75 GeomAPI_ProjectPointOnSurf proj(P,GS,U1,U2,V1,V2);
77 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
78 gp_Pnt P1 = proj.Point(i);
79 if ( P.Distance(P1) > Precision::Confusion()) {
80 Handle(Geom_Line) L = new Geom_Line(P,gp_Vec(P,P1));
81 Handle(Geom_TrimmedCurve) CT =
82 new Geom_TrimmedCurve(L, 0., P.Distance(P1));
83 sprintf(name,"%s%d","ext_",i);
84 char* temp = name; // portage WNT
85 DrawTrSurf::Set(temp, CT);
89 sprintf(name,"%s%d","ext_",i);
91 char* temp = name; // portage WNT
92 DrawTrSurf::Set(temp, P1);
93 proj.Parameters(i,UU,VV);
94 di << " Le point est sur la surface." << "\n";
95 di << " Ses parametres sont: UU = " << UU << "\n";
96 di << " VV = " << VV << "\n";
102 GeomAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(),
103 GC->LastParameter());
105 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
106 gp_Pnt P1 = proj.Point(i);
107 Standard_Real UU = proj.Parameter(i);
108 di << " parameter " << i << " = " << UU << "\n";
109 if ( P.Distance(P1) > Precision::Confusion()) {
110 Handle(Geom_Line) L = new Geom_Line(P,gp_Vec(P,P1));
111 Handle(Geom_TrimmedCurve) CT =
112 new Geom_TrimmedCurve(L, 0., P.Distance(P1));
113 sprintf(name,"%s%d","ext_",i);
114 char* temp = name; // portage WNT
115 DrawTrSurf::Set(temp, CT);
119 sprintf(name,"%s%d","ext_",i);
120 char* temp = name; // portage WNT
121 DrawTrSurf::Set(temp, P1);
123 UU = proj.Parameter(i);
124 di << " Le point est sur la courbe." << "\n";
125 di << " Son parametre est U = " << UU << "\n";
132 //=======================================================================
135 //=======================================================================
137 static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a)
141 Handle(Geom_Curve) GC;
142 Standard_Integer Nb = atoi(a[2]);
144 TColgp_Array1OfPnt Points(1, Nb);
146 Handle(Draw_Marker3D) mark;
149 GC = DrawTrSurf::GetCurve(a[3]);
153 Standard_Real U, U1, U2;
154 U1 = GC->FirstParameter();
155 U2 = GC->LastParameter();
156 Standard_Real Delta = ( U2 - U1) / (Nb-1);
157 for ( Standard_Integer i = 1 ; i <= Nb; i++) {
158 U = U1 + (i-1) * Delta;
159 Points(i) = GC->Value(U);
160 mark = new Draw_Marker3D( Points(i), Draw_X, Draw_vert);
165 Standard_Integer id,XX,YY,b;
166 dout.Select(id,XX,YY,b);
167 Standard_Real zoom = dout.Zoom(id);
169 Points(1) = gp_Pnt( ((Standard_Real)XX)/zoom,
170 ((Standard_Real)YY)/zoom,
173 mark = new Draw_Marker3D( Points(1), Draw_X, Draw_vert);
177 for (Standard_Integer i = 2; i<=Nb; i++) {
178 dout.Select(id,XX,YY,b);
179 Points(i) = gp_Pnt( ((Standard_Real)XX)/zoom,
180 ((Standard_Real)YY)/zoom,
182 mark = new Draw_Marker3D( Points(i), Draw_X, Draw_vert);
187 Standard_Integer Dmin = 3;
188 Standard_Integer Dmax = 8;
189 Standard_Real Tol3d = 1.e-3;
191 Handle(Geom_BSplineCurve) TheCurve;
192 GeomAPI_PointsToBSpline aPointToBSpline(Points,Dmin,Dmax,GeomAbs_C2,Tol3d);
193 TheCurve = aPointToBSpline.Curve();
196 DrawTrSurf::Set(a[1], TheCurve);
204 //=======================================================================
207 //=======================================================================
209 static Standard_Integer grilapp(Draw_Interpretor& di, Standard_Integer n, const char** a)
211 if ( n < 12) return 1;
213 Standard_Integer i,j;
214 Standard_Integer Nu = atoi(a[2]);
215 Standard_Integer Nv = atoi(a[3]);
216 TColStd_Array2OfReal ZPoints (1, Nu, 1, Nv);
218 Standard_Real X0 = atof(a[4]);
219 Standard_Real dX = atof(a[5]);
220 Standard_Real Y0 = atof(a[6]);
221 Standard_Real dY = atof(a[7]);
223 Standard_Integer Count = 8;
224 for ( j = 1; j <= Nv; j++) {
225 for ( i = 1; i <= Nu; i++) {
226 if ( Count > n) return 1;
227 ZPoints(i,j) = atof(a[Count]);
232 Handle(Geom_BSplineSurface) S
233 = GeomAPI_PointsToBSplineSurface(ZPoints,X0,dX,Y0,dY);
234 DrawTrSurf::Set(a[1],S);
241 //=======================================================================
244 //=======================================================================
246 static Standard_Integer surfapp(Draw_Interpretor& di, Standard_Integer n, const char** a)
248 if ( n < 5 ) return 1;
250 Standard_Integer i,j;
251 Standard_Integer Nu = atoi(a[2]);
252 Standard_Integer Nv = atoi(a[3]);
253 TColgp_Array2OfPnt Points (1, Nu, 1, Nv);
256 Handle(Geom_Surface) Surf = DrawTrSurf::GetSurface(a[4]);
257 if ( Surf.IsNull()) return 1;
259 Standard_Real U, V, U1, V1, U2, V2;
260 Surf->Bounds( U1, U2, V1, V2);
261 for ( j = 1; j <= Nv; j++) {
262 V = V1 + (j-1) * (V2-V1) / (Nv-1);
263 for ( i = 1; i <= Nu; i++) {
264 U = U1 + (i-1) * (U2-U1) / (Nu-1);
265 Points(i,j) = Surf->Value(U,V);
270 Standard_Integer Count = 4;
271 for ( j = 1; j <= Nv; j++) {
272 for ( i = 1; i <= Nu; i++) {
273 if ( Count > n) return 1;
274 Points(i,j) = gp_Pnt(atof(a[Count]),atof(a[Count+1]),atof(a[Count+2]));
280 Standard_Integer Count = 1;
281 for ( j = 1; j <= Nv; j++) {
282 for ( i = 1; i <= Nu; i++) {
283 sprintf(name,"point_%d",Count++);
284 char* temp = name; // portage WNT
285 DrawTrSurf::Set(temp,Points(i,j));
289 Handle(Geom_BSplineSurface) S = GeomAPI_PointsToBSplineSurface(Points);
290 DrawTrSurf::Set(a[1],S);
297 //=======================================================================
300 //=======================================================================
302 static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
306 Handle(Geom_Curve) GC1, GC2;
307 Handle(Geom_Surface) GS1, GS2;
309 Standard_Boolean C1 = Standard_False;
310 Standard_Boolean C2 = Standard_False;
311 Standard_Boolean S1 = Standard_False;
312 Standard_Boolean S2 = Standard_False;
314 Standard_Real U1f,U1l,U2f,U2l,V1f,V1l,V2f,V2l;
316 GC1 = DrawTrSurf::GetCurve(a[1]);
318 GS1 = DrawTrSurf::GetSurface(a[1]);
322 GS1->Bounds(U1f,U1l,V1f,V1l);
326 U1f = GC1->FirstParameter();
327 U1l = GC1->LastParameter();
330 GC2 = DrawTrSurf::GetCurve(a[2]);
332 GS2 = DrawTrSurf::GetSurface(a[2]);
336 GS2->Bounds(U2f,U2l,V2f,V2l);
340 U2f = GC2->FirstParameter();
341 U2l = GC2->LastParameter();
346 GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
347 if(!Ex.Extrema().IsParallel()) {
348 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
351 if (P1.Distance(P2) < 1.e-16) {
352 di << "Extrema " << i << " is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
355 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
356 Handle(Geom_TrimmedCurve) CT =
357 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
358 sprintf(name,"%s%d","ext_",i);
359 char* temp = name; // portage WNT
360 DrawTrSurf::Set(temp, CT);
365 di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n";
369 GeomAPI_ExtremaCurveSurface Ex(GC1,GS2,U1f,U1l,U2f,U2l,V2f,V2l);
370 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
373 if (P1.Distance(P2) < 1.e-16) continue;
374 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
375 Handle(Geom_TrimmedCurve) CT =
376 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
377 sprintf(name,"%s%d","ext_",i);
378 char* temp = name; // portage WNT
379 DrawTrSurf::Set(temp, CT);
384 GeomAPI_ExtremaCurveSurface Ex(GC2,GS1,U2f,U2l,U1f,U1l,V1f,V1l);
385 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
388 if (P1.Distance(P2) < 1.e-16) continue;
389 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
390 Handle(Geom_TrimmedCurve) CT =
391 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
392 sprintf(name,"%s%d","ext_",i);
393 char* temp = name; // portage WNT
394 DrawTrSurf::Set(temp, CT);
399 GeomAPI_ExtremaSurfaceSurface Ex(GS1,GS2,U1f,U1l,V1f,V1l,U2f,U2l,V2f,V2l);
400 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
403 if (P1.Distance(P2) < 1.e-16) continue;
404 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
405 Handle(Geom_TrimmedCurve) CT =
406 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
407 sprintf(name,"%s%d","ext_",i);
408 char* temp = name; // portage WNT
409 DrawTrSurf::Set(temp, CT);
418 //=======================================================================
419 //function : totalextcc
421 //=======================================================================
423 static Standard_Integer totalextcc(Draw_Interpretor& di, Standard_Integer n, const char** a)
427 Handle(Geom_Curve) GC1, GC2;
430 Standard_Real U1f,U1l,U2f,U2l;
432 GC1 = DrawTrSurf::GetCurve(a[1]);
437 U1f = GC1->FirstParameter();
438 U1l = GC1->LastParameter();
441 GC2 = DrawTrSurf::GetCurve(a[2]);
446 U2f = GC2->FirstParameter();
447 U2l = GC2->LastParameter();
451 GeomAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
453 if(Ex.TotalNearestPoints(P1,P2)) {
454 if (P1.Distance(P2) < 1.e-16) {
455 di << "Extrema is point : " << P1.X() << " " << P1.Y() << " " << P1.Z() << "\n";
458 di << "Extrema is segment of line" << "\n";
459 Handle(Geom_Line) L = new Geom_Line(P1,gp_Vec(P1,P2));
460 Handle(Geom_TrimmedCurve) CT =
461 new Geom_TrimmedCurve(L, 0., P1.Distance(P2));
462 sprintf(name,"%s%d","ext_",1);
463 char* temp = name; // portage WNT
464 DrawTrSurf::Set(temp, CT);
468 Standard_Real u1, u2;
469 Ex.TotalLowerDistanceParameters(u1, u2);
471 di << "Parameters on curves : " << u1 << " " << u2 << "\n";
475 di << "Curves are infinite and parallel" << "\n";
478 di << "Minimal distance : " << Ex.TotalLowerDistance() << "\n";
485 void GeometryTest::APICommands(Draw_Interpretor& theCommands)
487 static Standard_Boolean done = Standard_False;
490 done = Standard_True;
493 g = "GEOMETRY curves and surfaces analysis";
495 theCommands.Add("proj", "proj curve/surf x y z",__FILE__, proj);
497 g = "GEOMETRY approximations";
499 theCommands.Add("appro", "appro result nbpoint [curve]",__FILE__, appro);
500 theCommands.Add("surfapp","surfapp result nbupoint nbvpoint x y z ....",
503 theCommands.Add("grilapp",
504 "grilapp result nbupoint nbvpoint X0 dX Y0 dY z11 z12 .. z1nu .... ",
507 g = "GEOMETRY curves and surfaces analysis";
509 theCommands.Add("extrema", "extrema curve/surface curve/surface",__FILE__,extrema);
510 theCommands.Add("totalextcc", "totalextcc curve curve",__FILE__,totalextcc);