1 // Created on: 1995-01-11
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 <GeometryTest.hxx>
24 #include <Geom2d_Curve.hxx>
26 #include <Draw_Interpretor.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <Draw_Appli.hxx>
29 #include <DrawTrSurf_Curve2d.hxx>
30 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
31 #include <Geom2dAPI_ExtremaCurveCurve.hxx>
32 #include <Geom2dAPI_PointsToBSpline.hxx>
33 #include <Geom2dAPI_InterCurveCurve.hxx>
34 #include <Geom2d_Line.hxx>
35 #include <Geom2d_TrimmedCurve.hxx>
36 #include <TColgp_Array1OfPnt2d.hxx>
38 #include <Draw_Marker2D.hxx>
39 #include <Draw_Color.hxx>
40 #include <Draw_MarkerShape.hxx>
41 #include <TColStd_Array1OfReal.hxx>
42 #include <GeomAbs_Shape.hxx>
46 Standard_IMPORT Draw_Viewer dout;
49 //=======================================================================
52 //=======================================================================
54 static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a)
58 gp_Pnt2d P(Draw::Atof(a[2]),Draw::Atof(a[3]));
62 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]);
67 Geom2dAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(),
70 for ( Standard_Integer i = 1; i <= proj.NbPoints(); i++) {
71 gp_Pnt2d P1 = proj.Point(i);
72 Handle(Geom2d_Line) L = new Geom2d_Line(P,gp_Vec2d(P,P1));
73 Handle(Geom2d_TrimmedCurve) CT =
74 new Geom2d_TrimmedCurve(L, 0., P.Distance(P1));
75 Sprintf(name,"%s%d","ext_",i);
76 char* temp = name; // portage WNT
77 DrawTrSurf::Set(temp, CT);
84 //=======================================================================
87 //=======================================================================
89 static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a)
91 // Approximation et interpolation 2d
94 // - affiche la tolerance
96 // - change la tolerance
97 // 2dappro result nbpoint
98 // - saisie interactive
99 // 2dappro result nbpoint curve
100 // - calcule des points sur la courbe
101 // 2dappro result nbpoint x1 y1 x2 y2 ..
102 // - tableau de points
103 // 2dappro result nbpoint x1 dx y1 y2 ..
104 // - tableau de points (x1,y1) (x1+dx,y2) ... avec x = t
107 static Standard_Real Tol2d = 1.e-6;
111 Tol2d = Draw::Atof(a[1]);
113 di << "Tolerance for 2d approx : "<< Tol2d << "\n";
118 Standard_Integer i, Nb = Draw::Atoi(a[2]);
120 Standard_Boolean hasPoints = Standard_True;
121 TColgp_Array1OfPnt2d Points(1, Nb);
122 TColStd_Array1OfReal YValues(1,Nb);
123 Standard_Real X0=0,DX=0;
125 Handle(Draw_Marker2D) mark;
128 // saisie interactive
129 Standard_Integer id,XX,YY,b;
130 dout.Select(id,XX,YY,b);
131 Standard_Real zoom = dout.Zoom(id);
133 Points(1) = gp_Pnt2d( ((Standard_Real)XX)/zoom,
134 ((Standard_Real)YY)/zoom );
136 mark = new Draw_Marker2D( Points(1), Draw_X, Draw_vert);
140 for (Standard_Integer i = 2; i<=Nb; i++) {
141 dout.Select(id,XX,YY,b);
142 Points(i) = gp_Pnt2d( ((Standard_Real)XX)/zoom,
143 ((Standard_Real)YY)/zoom );
144 mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert);
151 Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[3]);
155 Standard_Real U, U1, U2;
156 U1 = GC->FirstParameter();
157 U2 = GC->LastParameter();
158 Standard_Real Delta = ( U2 - U1) / (Nb-1);
159 for ( i = 1 ; i <= Nb; i++) {
160 U = U1 + (i-1) * Delta;
161 Points(i) = GC->Value(U);
166 // test points ou ordonnees
167 hasPoints = Standard_False;
168 Standard_Integer nc = n - 3;
172 for (i = 1; i <= Nb; i++) {
173 Points(i).SetCoord(Draw::Atof(a[nc]),Draw::Atof(a[nc+1]));
177 else if (nc - 2 == Nb) {
180 X0 = Draw::Atof(a[3]);
181 DX = Draw::Atof(a[4]);
182 for (i = 1; i <= Nb; i++) {
183 YValues(i) = Draw::Atof(a[nc]);
184 Points(i).SetCoord(X0+(i-1)*DX,YValues(i));
191 // display the points
192 for ( i = 1 ; i <= Nb; i++) {
193 mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert);
198 Standard_Integer Dmin = 3;
199 Standard_Integer Dmax = 8;
201 Handle(Geom2d_BSplineCurve) TheCurve;
203 TheCurve = Geom2dAPI_PointsToBSpline(Points,Dmin,Dmax,GeomAbs_C2,Tol2d);
205 TheCurve = Geom2dAPI_PointsToBSpline(YValues,X0,DX,Dmin,Dmax,GeomAbs_C2,Tol2d);
207 DrawTrSurf::Set(a[1], TheCurve);
214 //=======================================================================
217 //=======================================================================
219 static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a)
223 Handle(Geom2d_Curve) GC1, GC2;
225 Standard_Real U1f,U1l,U2f,U2l;
227 GC1 = DrawTrSurf::GetCurve2d(a[1]);
230 U1f = GC1->FirstParameter();
231 U1l = GC1->LastParameter();
233 GC2 = DrawTrSurf::GetCurve2d(a[2]);
236 U2f = GC2->FirstParameter();
237 U2l = GC2->LastParameter();
241 Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l);
242 for ( Standard_Integer i = 1; i <= Ex.NbExtrema(); i++) {
245 Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2));
246 Handle(Geom2d_TrimmedCurve) CT =
247 new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2));
248 Sprintf(name,"%s%d","ext_",i);
249 char* temp = name; // portage WNT
250 DrawTrSurf::Set(temp, CT);
258 //=======================================================================
259 //function : intersect
261 //=======================================================================
263 static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, const char** a)
268 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]);
272 Standard_Real Tol = 0.001;
273 Geom2dAPI_InterCurveCurve Intersector;
275 Handle(Geom2d_Curve) C2;
277 C2 = DrawTrSurf::GetCurve2d(a[2]);
280 Intersector.Init(C1,C2,Tol);
283 Intersector.Init(C1, Tol);
288 for ( i = 1; i <= Intersector.NbPoints(); i++) {
289 gp_Pnt2d P = Intersector.Point(i);
290 Handle(Draw_Marker2D) mark = new Draw_Marker2D( P, Draw_X, Draw_vert);
295 Handle(Geom2d_Curve) S1,S2;
296 Handle(DrawTrSurf_Curve2d) CD;
298 for ( i = 1; i <= Intersector.NbSegments(); i++) {
299 Intersector.Segment(i,S1,S2);
300 CD = new DrawTrSurf_Curve2d(S1, Draw_bleu, 30);
302 CD = new DrawTrSurf_Curve2d(S2, Draw_violet, 30);
312 void GeometryTest::API2dCommands(Draw_Interpretor& theCommands)
314 static Standard_Boolean done = Standard_False;
319 done = Standard_True;
320 g = "GEOMETRY curves and surfaces analysis";
322 theCommands.Add("2dproj", "proj curve x y",__FILE__, proj,g);
324 g = "GEOMETRY approximations";
326 theCommands.Add("2dapprox", "2dapprox result nbpoint [curve] [[x] y [x] y...]",__FILE__,
328 theCommands.Add("2dinterpole", "2dinterpole result nbpoint [curve] [[x] y [x] y ...]",__FILE__,
331 g = "GEOMETRY curves and surfaces analysis";
333 theCommands.Add("2dextrema", "extrema curve curve",__FILE__,
336 g = "GEOMETRY intersections";
338 theCommands.Add("2dintersect", "intersect curve curve",__FILE__,