b311480e |
1 | // Created on: 1995-01-11 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // modified : pmn 11/04/97 : mis dans GeomliteTest |
18 | |
19 | |
20 | #include <GeomliteTest.hxx> |
543a9964 |
21 | #include <Geom2d_BSplineCurve.hxx> |
7fd59977 |
22 | #include <Draw_Interpretor.hxx> |
23 | #include <DrawTrSurf.hxx> |
24 | #include <Draw_Appli.hxx> |
25 | #include <DrawTrSurf_Curve2d.hxx> |
26 | #include <Geom2dAPI_ProjectPointOnCurve.hxx> |
27 | #include <Geom2dAPI_ExtremaCurveCurve.hxx> |
64a44752 |
28 | #include <Geom2dAPI_Interpolate.hxx> |
7fd59977 |
29 | #include <Geom2dAPI_PointsToBSpline.hxx> |
30 | #include <Geom2dAPI_InterCurveCurve.hxx> |
31 | #include <Geom2d_Line.hxx> |
32 | #include <Geom2d_TrimmedCurve.hxx> |
323e88ad |
33 | #include <GeomLib_Tool.hxx> |
7fd59977 |
34 | #include <TColgp_Array1OfPnt2d.hxx> |
7fd59977 |
35 | #include <Draw_Marker2D.hxx> |
36 | #include <Draw_Color.hxx> |
37 | #include <Draw_MarkerShape.hxx> |
38 | #include <TColStd_Array1OfReal.hxx> |
39 | #include <GeomAbs_Shape.hxx> |
40 | #include <Precision.hxx> |
3f16d970 |
41 | #include <Geom2d_Circle.hxx> |
42 | #include <IntAna2d_AnaIntersection.hxx> |
43 | #include <IntAna2d_IntPoint.hxx> |
18d8e3e7 |
44 | #include <IntAna2d_Conic.hxx> |
1d19db8d |
45 | #include <IntRes2d_IntersectionPoint.hxx> |
c22b52d6 |
46 | #include <Geom2dAdaptor_Curve.hxx> |
d99f0355 |
47 | #include <Message.hxx> |
4f7ad5fb |
48 | #include <NCollection_Shared.hxx> |
7fd59977 |
49 | |
d99f0355 |
50 | #include <memory> |
7fd59977 |
51 | #include <stdio.h> |
57c28b61 |
52 | #ifdef _WIN32 |
7fd59977 |
53 | Standard_IMPORT Draw_Viewer dout; |
54 | #endif |
55 | |
56 | //======================================================================= |
57 | //function : proj |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | static Standard_Integer proj (Draw_Interpretor& di, Standard_Integer n, const char** a) |
62 | { |
4f7ad5fb |
63 | if (n != 4) |
64 | { |
65 | di << "Syntax error: wrong number of arguments"; |
66 | return 1; |
67 | } |
7fd59977 |
68 | |
69 | Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[1]); |
7fd59977 |
70 | if (GC.IsNull()) |
4f7ad5fb |
71 | { |
72 | di << "Syntax error: '" << a[1] << "' is NULL"; |
7fd59977 |
73 | return 1; |
4f7ad5fb |
74 | } |
7fd59977 |
75 | |
4f7ad5fb |
76 | const gp_Pnt2d P (Draw::Atof (a[2]), Draw::Atof (a[3])); |
77 | Geom2dAPI_ProjectPointOnCurve proj(P,GC,GC->FirstParameter(), GC->LastParameter()); |
23e8067c |
78 | for (Standard_Integer i = 1; i <= proj.NbPoints(); i++) |
79 | { |
80 | gp_Pnt2d aP1 = proj.Point(i); |
81 | const Standard_Real aDist = P.Distance(aP1); |
4f7ad5fb |
82 | const TCollection_AsciiString aName = TCollection_AsciiString ("ext_") + i; |
23e8067c |
83 | if (aDist > Precision::PConfusion()) |
84 | { |
85 | Handle(Geom2d_Line) L = new Geom2d_Line(P, gp_Dir2d(aP1.XY() - P.XY())); |
86 | Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., aDist); |
4f7ad5fb |
87 | DrawTrSurf::Set (aName.ToCString(), CT); |
23e8067c |
88 | } |
89 | else |
90 | { |
4f7ad5fb |
91 | DrawTrSurf::Set (aName.ToCString(), aP1); |
23e8067c |
92 | } |
93 | |
4f7ad5fb |
94 | di << aName << " "; |
7fd59977 |
95 | } |
96 | |
97 | return 0; |
98 | } |
99 | |
100 | //======================================================================= |
101 | //function : appro |
102 | //purpose : |
103 | //======================================================================= |
104 | |
105 | static Standard_Integer appro(Draw_Interpretor& di, Standard_Integer n, const char** a) |
106 | { |
107 | // Approximation et interpolation 2d |
108 | |
109 | // 2dappro |
110 | // - affiche la tolerance |
111 | // 2dappro tol |
112 | // - change la tolerance |
113 | // 2dappro result nbpoint |
114 | // - saisie interactive |
115 | // 2dappro result nbpoint curve |
116 | // - calcule des points sur la courbe |
117 | // 2dappro result nbpoint x1 y1 x2 y2 .. |
118 | // - tableau de points |
119 | // 2dappro result nbpoint x1 dx y1 y2 .. |
120 | // - tableau de points (x1,y1) (x1+dx,y2) ... avec x = t |
121 | |
7fd59977 |
122 | static Standard_Real Tol2d = 1.e-6; |
4f7ad5fb |
123 | if (n < 3) |
124 | { |
125 | if (n == 2) |
126 | { |
91322f44 |
127 | Tol2d = Draw::Atof(a[1]); |
4f7ad5fb |
128 | } |
323e88ad |
129 | |
7fd59977 |
130 | di << "Tolerance for 2d approx : "<< Tol2d << "\n"; |
131 | return 0; |
132 | } |
133 | |
91322f44 |
134 | Standard_Integer i, Nb = Draw::Atoi(a[2]); |
7fd59977 |
135 | |
136 | Standard_Boolean hasPoints = Standard_True; |
137 | TColgp_Array1OfPnt2d Points(1, Nb); |
138 | TColStd_Array1OfReal YValues(1,Nb); |
139 | Standard_Real X0=0,DX=0; |
140 | |
141 | Handle(Draw_Marker2D) mark; |
142 | |
143 | if (n == 3) { |
144 | // saisie interactive |
145 | Standard_Integer id,XX,YY,b; |
146 | dout.Select(id,XX,YY,b); |
147 | Standard_Real zoom = dout.Zoom(id); |
148 | |
149 | Points(1) = gp_Pnt2d( ((Standard_Real)XX)/zoom, |
150 | ((Standard_Real)YY)/zoom ); |
151 | |
152 | mark = new Draw_Marker2D( Points(1), Draw_X, Draw_vert); |
153 | |
154 | dout << mark; |
155 | |
156 | for (i = 2; i<=Nb; i++) { |
157 | dout.Select(id,XX,YY,b); |
158 | Points(i) = gp_Pnt2d( ((Standard_Real)XX)/zoom, |
159 | ((Standard_Real)YY)/zoom ); |
160 | mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert); |
161 | dout << mark; |
162 | } |
163 | } |
164 | else { |
165 | if ( n == 4) { |
166 | // points sur courbe |
167 | Handle(Geom2d_Curve) GC = DrawTrSurf::GetCurve2d(a[3]); |
168 | if ( GC.IsNull()) |
169 | return 1; |
170 | |
171 | Standard_Real U, U1, U2; |
172 | U1 = GC->FirstParameter(); |
173 | U2 = GC->LastParameter(); |
174 | Standard_Real Delta = ( U2 - U1) / (Nb-1); |
175 | for ( i = 1 ; i <= Nb; i++) { |
176 | U = U1 + (i-1) * Delta; |
177 | Points(i) = GC->Value(U); |
178 | } |
179 | } |
180 | |
181 | else { |
182 | // test points ou ordonnees |
7fd59977 |
183 | Standard_Integer nc = n - 3; |
184 | if (nc == 2 * Nb) { |
185 | // points |
186 | nc = 3; |
187 | for (i = 1; i <= Nb; i++) { |
91322f44 |
188 | Points(i).SetCoord(Draw::Atof(a[nc]),Draw::Atof(a[nc+1])); |
7fd59977 |
189 | nc += 2; |
190 | } |
191 | } |
192 | else if (nc - 2 == Nb) { |
193 | // YValues |
64a44752 |
194 | hasPoints = Standard_False; |
7fd59977 |
195 | nc = 5; |
91322f44 |
196 | X0 = Draw::Atof(a[3]); |
197 | DX = Draw::Atof(a[4]); |
7fd59977 |
198 | for (i = 1; i <= Nb; i++) { |
91322f44 |
199 | YValues(i) = Draw::Atof(a[nc]); |
7fd59977 |
200 | Points(i).SetCoord(X0+(i-1)*DX,YValues(i)); |
201 | nc++; |
202 | } |
203 | } |
204 | else |
205 | return 1; |
206 | } |
207 | // display the points |
208 | for ( i = 1 ; i <= Nb; i++) { |
209 | mark = new Draw_Marker2D( Points(i), Draw_X, Draw_vert); |
210 | dout << mark; |
211 | } |
212 | } |
213 | dout.Flush(); |
214 | Standard_Integer Dmin = 3; |
215 | Standard_Integer Dmax = 8; |
216 | |
217 | Handle(Geom2d_BSplineCurve) TheCurve; |
218 | if (hasPoints) |
64a44752 |
219 | { |
220 | if (!strcmp (a[0], "2dinterpole")) |
221 | { |
222 | Geom2dAPI_Interpolate anInterpol (new TColgp_HArray1OfPnt2d(Points), Standard_False, Tol2d); |
223 | anInterpol.Perform(); |
224 | if (!anInterpol.IsDone()) |
225 | { |
226 | di << "not done"; |
227 | return 1; |
228 | } |
229 | TheCurve = anInterpol.Curve(); |
230 | } |
323e88ad |
231 | else |
64a44752 |
232 | { |
233 | Geom2dAPI_PointsToBSpline anApprox (Points, Dmin, Dmax, GeomAbs_C2, Tol2d); |
234 | if (!anApprox.IsDone()) |
235 | { |
236 | di << "not done"; |
237 | return 1; |
238 | } |
239 | TheCurve = anApprox.Curve(); |
240 | } |
241 | } |
7fd59977 |
242 | else |
64a44752 |
243 | { |
244 | if (!strcmp (a[0], "2dinterpole")) |
245 | { |
246 | di << "incorrect usage"; |
247 | return 1; |
248 | } |
249 | Geom2dAPI_PointsToBSpline anApprox (YValues, X0, DX, Dmin, Dmax, GeomAbs_C2, Tol2d); |
250 | if (!anApprox.IsDone()) |
251 | { |
252 | di << "not done"; |
253 | return 1; |
254 | } |
255 | TheCurve = anApprox.Curve(); |
256 | } |
7fd59977 |
257 | |
258 | DrawTrSurf::Set(a[1], TheCurve); |
259 | di << a[1]; |
7fd59977 |
260 | return 0; |
7fd59977 |
261 | } |
262 | |
263 | //======================================================================= |
264 | //function : extrema |
265 | //purpose : |
266 | //======================================================================= |
267 | |
268 | static Standard_Integer extrema(Draw_Interpretor& di, Standard_Integer n, const char** a) |
269 | { |
4f7ad5fb |
270 | if (n != 3) |
271 | { |
272 | di << "Syntax error: wrong number of arguments"; |
7fd59977 |
273 | return 1; |
4f7ad5fb |
274 | } |
7fd59977 |
275 | |
4f7ad5fb |
276 | Handle(Geom2d_Curve) GC1 = DrawTrSurf::GetCurve2d (a[1]); |
277 | Handle(Geom2d_Curve) GC2 = DrawTrSurf::GetCurve2d (a[2]); |
323e88ad |
278 | if ( GC1.IsNull()) |
4f7ad5fb |
279 | { |
280 | di << "Syntax error: '" << a[1] << "' is NULL"; |
7fd59977 |
281 | return 1; |
4f7ad5fb |
282 | } |
323e88ad |
283 | if ( GC2.IsNull()) |
4f7ad5fb |
284 | { |
285 | di << "Syntax error: '" << a[2] << "' is NULL"; |
286 | return 1; |
287 | } |
7fd59977 |
288 | |
4f7ad5fb |
289 | const Standard_Real U1f = GC1->FirstParameter(); |
290 | const Standard_Real U1l = GC1->LastParameter(); |
291 | const Standard_Real U2f = GC2->FirstParameter(); |
292 | const Standard_Real U2l = GC2->LastParameter(); |
7fd59977 |
293 | |
294 | Geom2dAPI_ExtremaCurveCurve Ex(GC1,GC2,U1f,U1l,U2f,U2l); |
92a206a3 |
295 | Standard_Boolean isInfinitySolutions = Ex.Extrema().IsParallel(); |
32ca7a51 |
296 | const Standard_Integer aNExtr = Ex.NbExtrema(); |
7fd59977 |
297 | |
92a206a3 |
298 | if (aNExtr == 0 || isInfinitySolutions) |
299 | { |
300 | // Infinity solutions flag may be set with 0 number of |
301 | // solutions in analytic extrema Curve/Curve. |
302 | if (isInfinitySolutions) |
303 | di << "Infinite number of extremas, distance = " << Ex.LowerDistance() << "\n"; |
304 | else |
305 | di << "No solutions!\n"; |
306 | } |
307 | |
308 | for (Standard_Integer i = 1; i <= aNExtr; i++) |
309 | { |
7fd59977 |
310 | gp_Pnt2d P1,P2; |
311 | Ex.Points(i,P1,P2); |
e8746a26 |
312 | di << "dist " << i << ": " << Ex.Distance(i) << " "; |
4f7ad5fb |
313 | const TCollection_AsciiString aName = TCollection_AsciiString("ext_") + i; |
92a206a3 |
314 | if (Ex.Distance(i) <= Precision::PConfusion()) |
315 | { |
7fd59977 |
316 | Handle(Draw_Marker2D) mark = new Draw_Marker2D( P1, Draw_X, Draw_vert); |
317 | dout << mark; |
318 | dout.Flush(); |
4f7ad5fb |
319 | const char* temp = aName.ToCString(); |
e8746a26 |
320 | DrawTrSurf::Set(temp, P1); |
7fd59977 |
321 | } |
92a206a3 |
322 | else |
323 | { |
7fd59977 |
324 | Handle(Geom2d_Line) L = new Geom2d_Line(P1,gp_Vec2d(P1,P2)); |
e8746a26 |
325 | Handle(Geom2d_TrimmedCurve) CT = new Geom2d_TrimmedCurve(L, 0., P1.Distance(P2)); |
4f7ad5fb |
326 | const char* temp = aName.ToCString(); |
7fd59977 |
327 | DrawTrSurf::Set(temp, CT); |
7fd59977 |
328 | } |
4f7ad5fb |
329 | di << aName << "\n"; |
7fd59977 |
330 | } |
7fd59977 |
331 | |
332 | return 0; |
333 | } |
334 | |
7fd59977 |
335 | //======================================================================= |
336 | //function : intersect |
337 | //purpose : |
338 | //======================================================================= |
305cc3f8 |
339 | static Standard_Integer intersect(Draw_Interpretor& di, Standard_Integer n, const char** a) |
7fd59977 |
340 | { |
4f7ad5fb |
341 | Handle(Geom2d_Curve) C1, C2; |
4bc805bf |
342 | Standard_Real Tol = 0.001; |
343 | Standard_Boolean bPrintState = Standard_False; |
305cc3f8 |
344 | |
4bc805bf |
345 | // Retrieve other parameters if any |
4f7ad5fb |
346 | for (Standard_Integer i = 1; i < n; ++i) |
305cc3f8 |
347 | { |
4bc805bf |
348 | if (!strcmp(a[i], "-tol")) |
349 | { |
350 | Tol = Draw::Atof(a[++i]); |
351 | } |
352 | else if (!strcmp(a[i], "-state")) |
353 | { |
354 | bPrintState = Standard_True; |
355 | } |
4f7ad5fb |
356 | else if (C1.IsNull()) |
357 | { |
358 | C1 = DrawTrSurf::GetCurve2d (a[i]); |
359 | if (C1.IsNull()) |
360 | { |
361 | di << "Syntax error: curve '" << a[i] << "' is null"; |
362 | return 1; |
363 | } |
364 | } |
365 | else if (C2.IsNull()) |
4bc805bf |
366 | { |
367 | C2 = DrawTrSurf::GetCurve2d(a[i]); |
368 | if (C2.IsNull()) |
369 | { |
4f7ad5fb |
370 | di << "Syntax error: curve '" << a[i] << "' is null"; |
4bc805bf |
371 | return 1; |
372 | } |
373 | } |
4f7ad5fb |
374 | else |
375 | { |
376 | di << "Syntax error at '" << a[i] << "'"; |
377 | return 1; |
323e88ad |
378 | } |
4f7ad5fb |
379 | } |
380 | if (C1.IsNull()) |
381 | { |
382 | di << "Syntax error: wrong number of arguments"; |
383 | return 1; |
7fd59977 |
384 | } |
4bc805bf |
385 | |
386 | Geom2dAPI_InterCurveCurve Intersector; |
4bc805bf |
387 | if (!C2.IsNull()) |
4f7ad5fb |
388 | { |
4bc805bf |
389 | // Curves intersection |
390 | Intersector.Init(C1, C2, Tol); |
4f7ad5fb |
391 | } |
4bc805bf |
392 | else |
4f7ad5fb |
393 | { |
4bc805bf |
394 | // Self-intersection of the curve |
7fd59977 |
395 | Intersector.Init(C1, Tol); |
4f7ad5fb |
396 | } |
4bc805bf |
397 | |
398 | const Geom2dInt_GInter& anIntTool = Intersector.Intersector(); |
399 | if (!anIntTool.IsDone()) |
400 | { |
401 | di << "Intersection failed\n"; |
402 | return 0; |
7fd59977 |
403 | } |
404 | |
4bc805bf |
405 | if (anIntTool.IsEmpty()) |
4f7ad5fb |
406 | { |
4bc805bf |
407 | return 0; |
4f7ad5fb |
408 | } |
7fd59977 |
409 | |
4bc805bf |
410 | Standard_Integer aNbPoints = Intersector.NbPoints(); |
411 | for (Standard_Integer i = 1; i <= aNbPoints; i++) |
412 | { |
413 | // API simplified result |
7fd59977 |
414 | gp_Pnt2d P = Intersector.Point(i); |
4bc805bf |
415 | di << "Intersection point " << i << " : " << P.X() << " " << P.Y() << "\n"; |
416 | // Intersection extended results from intersection tool |
417 | const IntRes2d_IntersectionPoint& aPInt = anIntTool.Point(i); |
418 | di << "parameter on the fist: " << aPInt.ParamOnFirst(); |
419 | di << " parameter on the second: " << aPInt.ParamOnSecond() << "\n"; |
420 | if (bPrintState) |
421 | { |
422 | di << "Intersection type: " << |
423 | (aPInt.TransitionOfFirst().IsTangent() ? "TOUCH" : "INTERSECTION") << "\n"; |
424 | } |
425 | Handle(Draw_Marker2D) mark = new Draw_Marker2D(P, Draw_X, Draw_vert); |
7fd59977 |
426 | dout << mark; |
427 | } |
428 | dout.Flush(); |
429 | |
4bc805bf |
430 | Handle(Geom2d_Curve) S1, S2; |
7fd59977 |
431 | Handle(DrawTrSurf_Curve2d) CD; |
4bc805bf |
432 | Standard_Integer aNbSegments = Intersector.NbSegments(); |
433 | for (Standard_Integer i = 1; i <= aNbSegments; i++) |
434 | { |
4e14c88f |
435 | di << "Segment #" << i << " found.\n"; |
305cc3f8 |
436 | Intersector.Segment(i,S1,S2); |
437 | CD = new DrawTrSurf_Curve2d(S1, Draw_bleu, 30); |
438 | dout << CD; |
439 | CD = new DrawTrSurf_Curve2d(S2, Draw_violet, 30); |
440 | dout << CD; |
7fd59977 |
441 | } |
323e88ad |
442 | |
4f7ad5fb |
443 | dout.Flush(); |
7fd59977 |
444 | return 0; |
445 | } |
446 | |
3f16d970 |
447 | //======================================================================= |
18d8e3e7 |
448 | //function : intersect_ana |
3f16d970 |
449 | //purpose : |
450 | //======================================================================= |
451 | |
452 | static Standard_Integer intersect_ana(Draw_Interpretor& di, Standard_Integer n, const char** a) |
453 | { |
4f7ad5fb |
454 | if (n != 3) |
3f16d970 |
455 | { |
4f7ad5fb |
456 | di << "Syntax error: wrong number of arguments"; |
3f16d970 |
457 | return 1; |
458 | } |
18d8e3e7 |
459 | |
3f16d970 |
460 | Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]); |
3f16d970 |
461 | Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[2]); |
3f16d970 |
462 | Handle(Geom2d_Circle) aCir1 = Handle(Geom2d_Circle)::DownCast(C1); |
463 | Handle(Geom2d_Circle) aCir2 = Handle(Geom2d_Circle)::DownCast(C2); |
4f7ad5fb |
464 | if (aCir1.IsNull() || aCir2.IsNull()) |
465 | { |
466 | di << "Syntax error: '" << a[aCir1.IsNull() ? 1 : 2] << "' is not a circle"; |
467 | return 1; |
468 | } |
3f16d970 |
469 | |
470 | IntAna2d_AnaIntersection Intersector(aCir1->Circ2d(), aCir2->Circ2d()); |
4f7ad5fb |
471 | for (Standard_Integer i = 1; i <= Intersector.NbPoints(); i++) |
472 | { |
18d8e3e7 |
473 | gp_Pnt2d P = Intersector.Point(i).Value(); |
474 | di << "Intersection point " << i << " : " << P.X() << " " << P.Y() << "\n"; |
475 | di << "parameter on the fist: " << Intersector.Point(i).ParamOnFirst(); |
476 | di << " parameter on the second: " << Intersector.Point(i).ParamOnSecond() << "\n"; |
477 | Handle(Draw_Marker2D) mark = new Draw_Marker2D(P, Draw_X, Draw_vert); |
478 | dout << mark; |
479 | } |
480 | dout.Flush(); |
18d8e3e7 |
481 | return 0; |
482 | } |
483 | |
484 | //======================================================================= |
485 | //function : intconcon |
486 | //purpose : |
487 | //======================================================================= |
488 | |
489 | static Standard_Integer intconcon(Draw_Interpretor& di, Standard_Integer n, const char** a) |
490 | { |
4f7ad5fb |
491 | if (n != 3) |
18d8e3e7 |
492 | { |
4f7ad5fb |
493 | di << "Syntax error: wrong number of arguments"; |
18d8e3e7 |
494 | return 1; |
495 | } |
496 | |
497 | Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[1]); |
498 | if (C1.IsNull()) |
499 | { |
4f7ad5fb |
500 | di << "Syntax error: '" << a[1] << "' is Null"; |
18d8e3e7 |
501 | return 1; |
502 | } |
503 | |
504 | Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[2]); |
505 | if (C2.IsNull()) |
506 | { |
4f7ad5fb |
507 | di << "Syntax error: '" << a[2] << "' is Null"; |
18d8e3e7 |
508 | return 1; |
509 | } |
510 | |
511 | Geom2dAdaptor_Curve AC1(C1), AC2(C2); |
512 | GeomAbs_CurveType T1 = AC1.GetType(), T2 = AC2.GetType(); |
4f7ad5fb |
513 | Handle(NCollection_Shared<IntAna2d_Conic>) pCon; |
18d8e3e7 |
514 | switch (T2) |
515 | { |
4f7ad5fb |
516 | case GeomAbs_Line: |
517 | { |
323e88ad |
518 | pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Line())); |
4f7ad5fb |
519 | break; |
520 | } |
521 | case GeomAbs_Circle: |
522 | { |
323e88ad |
523 | pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Circle())); |
4f7ad5fb |
524 | break; |
525 | } |
526 | case GeomAbs_Ellipse: |
527 | { |
323e88ad |
528 | pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Ellipse())); |
4f7ad5fb |
529 | break; |
530 | } |
531 | case GeomAbs_Hyperbola: |
532 | { |
323e88ad |
533 | pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Hyperbola())); |
4f7ad5fb |
534 | break; |
535 | } |
536 | case GeomAbs_Parabola: |
537 | { |
323e88ad |
538 | pCon.reset (new NCollection_Shared<IntAna2d_Conic>(AC2.Parabola())); |
4f7ad5fb |
539 | break; |
540 | } |
541 | default: |
323e88ad |
542 | { |
543 | di << "Syntax error: '" << a[2] << "' is not conic"; |
4f7ad5fb |
544 | return 1; |
545 | } |
18d8e3e7 |
546 | } |
547 | |
548 | IntAna2d_AnaIntersection Intersector; |
549 | switch (T1) |
550 | { |
323e88ad |
551 | case GeomAbs_Line: |
552 | Intersector.Perform(AC1.Line(), *pCon); |
553 | break; |
554 | case GeomAbs_Circle: |
555 | Intersector.Perform(AC1.Circle(), *pCon); |
556 | break; |
557 | case GeomAbs_Ellipse: |
558 | Intersector.Perform(AC1.Ellipse(), *pCon); |
559 | break; |
560 | case GeomAbs_Hyperbola: |
561 | Intersector.Perform(AC1.Hyperbola(), *pCon); |
562 | break; |
563 | case GeomAbs_Parabola: |
564 | Intersector.Perform(AC1.Parabola(), *pCon); |
565 | break; |
566 | default: |
4f7ad5fb |
567 | di << "Syntax error: '" << a[1] << "' is not conic"; |
323e88ad |
568 | return 1; |
18d8e3e7 |
569 | } |
570 | |
4f7ad5fb |
571 | for (Standard_Integer i = 1; i <= Intersector.NbPoints(); i++) |
572 | { |
3f16d970 |
573 | gp_Pnt2d P = Intersector.Point(i).Value(); |
574 | di<<"Intersection point "<<i<<" : "<<P.X()<<" "<<P.Y()<<"\n"; |
18d8e3e7 |
575 | di << "parameter on the fist: " << Intersector.Point(i).ParamOnFirst(); |
576 | if (!Intersector.Point(i).SecondIsImplicit()) |
577 | { |
578 | di << " parameter on the second: " << Intersector.Point(i).ParamOnSecond() << "\n"; |
579 | } |
580 | else |
581 | { |
582 | di << "\n"; |
583 | } |
3f16d970 |
584 | Handle(Draw_Marker2D) mark = new Draw_Marker2D( P, Draw_X, Draw_vert); |
585 | dout << mark; |
586 | } |
587 | dout.Flush(); |
3f16d970 |
588 | return 0; |
589 | } |
590 | |
323e88ad |
591 | //======================================================================= |
592 | //function : deviation |
593 | //purpose : |
594 | //======================================================================= |
595 | static Standard_Integer deviation(Draw_Interpretor& theDI, Standard_Integer theNArg, const char** theArgv) |
596 | { |
597 | if (theNArg < 3) |
598 | { |
599 | theDI << "Syntax error: wrong number of arguments"; |
600 | return 1; |
601 | } |
602 | |
603 | const Handle(Geom2d_Curve) aC = DrawTrSurf::GetCurve2d(theArgv[2]); |
604 | |
605 | if (aC.IsNull()) |
606 | { |
607 | theDI << "Error: " << theArgv[2] << " is not a 2D-curve.\n"; |
608 | return 1; |
609 | } |
610 | |
611 | Geom2dAdaptor_Curve anAC(aC); |
612 | |
613 | Standard_Integer aNbInterv = 2; |
614 | Standard_Real aU0 = RealLast(); |
615 | Standard_Integer aNbApprox = 10; |
616 | Standard_Integer aNbExact = 100; |
617 | Standard_Boolean anIsApproxOnly = Standard_False; |
618 | |
619 | |
620 | for (Standard_Integer aCurrArg = 3; aCurrArg < theNArg; aCurrArg++) |
621 | { |
622 | TCollection_AsciiString anArg(theArgv[aCurrArg]); |
623 | anArg.LowerCase(); |
624 | if (anArg == "-i") |
625 | { |
626 | aU0 = Draw::Atof(theArgv[++aCurrArg]); |
627 | } |
628 | else if (anArg == "-d") |
629 | { |
630 | aNbInterv = Draw::Atoi(theArgv[++aCurrArg]); |
631 | } |
632 | else if (anArg == "-napprox") |
633 | { |
634 | aNbApprox = Draw::Atoi(theArgv[++aCurrArg]); |
635 | } |
636 | else if (anArg == "-nexact") |
637 | { |
638 | aNbExact = Draw::Atoi(theArgv[++aCurrArg]); |
639 | } |
640 | else if (anArg == "-approxonly") |
641 | { |
642 | anIsApproxOnly = Standard_True; |
643 | ++aCurrArg; |
644 | } |
645 | else |
646 | { |
647 | theDI << "Error: Wrong option " << theArgv[aCurrArg] << "\n"; |
648 | return 1; |
649 | } |
650 | } |
651 | |
652 | const Standard_Real aU1 = anAC.FirstParameter(); |
653 | const Standard_Real aU2 = anAC.LastParameter(); |
654 | |
655 | Standard_Real aRetCurvParam = aU0; |
656 | gp_Pnt2d aPtOnCurv; |
657 | gp_Vec2d aRetVec; |
658 | gp_Lin2d aLinSegm; |
659 | |
660 | Standard_Real aDefl = RealLast(); |
661 | |
662 | if (aU0 == RealLast() || anIsApproxOnly) |
663 | { |
664 | aDefl = GeomLib_Tool::ComputeDeviation(anAC, aU1, aU2, |
665 | aNbInterv, aNbApprox, &aU0); |
666 | |
667 | if (aDefl < 0.0) |
668 | { |
669 | theDI << "Error: Cannot compute deviation on interval.\n"; |
670 | return 0; |
671 | } |
672 | } |
673 | if (!anIsApproxOnly) |
674 | { |
675 | aDefl = GeomLib_Tool::ComputeDeviation(anAC, aU1, aU2, aU0, aNbExact, |
676 | &aRetCurvParam, &aPtOnCurv, |
677 | &aRetVec, &aLinSegm); |
678 | } |
679 | if (aDefl < 0.0) |
680 | { |
681 | theDI << "Error: Cannot compute a deviation!\n"; |
682 | return 0; |
683 | } |
684 | theDI << "Computed value is: " << aDefl << "\n"; |
685 | TCollection_AsciiString anArgString = theArgv[1]; |
686 | TCollection_AsciiString aPntString = anArgString + "_pnt"; |
687 | DrawTrSurf::Set(aPntString.ToCString(), aPtOnCurv); |
688 | theDI << "From point " << aPntString << " (with parameter " << aRetCurvParam << ") to "; |
689 | |
690 | Handle(Geom2d_Curve) aLine = new Geom2d_Line(aLinSegm); |
691 | TCollection_AsciiString aLinString = anArgString + "_lin"; |
692 | DrawTrSurf::Set(aLinString.ToCString(), aLine); |
693 | theDI << "the line " << aLinString << ".\n"; |
694 | |
695 | aLine = new Geom2d_Line(aPtOnCurv, aRetVec); |
696 | aLine = new Geom2d_TrimmedCurve(aLine, 0.0, aDefl); |
697 | TCollection_AsciiString aNormString = anArgString + "_norm"; |
698 | DrawTrSurf::Set(aNormString.ToCString(), aLine); |
699 | theDI << "The deflection is measured along the line " << aNormString << ".\n"; |
700 | |
701 | return 0; |
702 | } |
703 | |
7fd59977 |
704 | void GeomliteTest::API2dCommands(Draw_Interpretor& theCommands) |
705 | { |
706 | static Standard_Boolean done = Standard_False; |
707 | if (done) return; |
708 | |
709 | const char *g; |
710 | |
711 | done = Standard_True; |
712 | g = "GEOMETRY curves and surfaces analysis"; |
713 | |
714 | theCommands.Add("2dproj", "proj curve x y",__FILE__, proj,g); |
715 | |
716 | g = "GEOMETRY approximations"; |
717 | |
718 | theCommands.Add("2dapprox", "2dapprox result nbpoint [curve] [[x] y [x] y...]",__FILE__, |
719 | appro,g); |
720 | theCommands.Add("2dinterpole", "2dinterpole result nbpoint [curve] [[x] y [x] y ...]",__FILE__, |
721 | appro,g); |
722 | |
723 | g = "GEOMETRY curves and surfaces analysis"; |
724 | |
725 | theCommands.Add("2dextrema", "extrema curve curve",__FILE__, |
726 | extrema,g); |
727 | |
728 | g = "GEOMETRY intersections"; |
729 | |
4bc805bf |
730 | theCommands.Add("2dintersect", "2dintersect curve1 [curve2] [-tol tol] [-state]\n" |
731 | "Intersects the given 2d curve(s)." |
732 | "If only one curve is given, it will be checked on self-intersection.\n" |
733 | "Options:\n" |
734 | " -tol - allows changing the intersection tolerance (default value is 1.e-3);\n" |
735 | " -state - allows printing the intersection state for each point.", |
736 | __FILE__, intersect, g); |
3f16d970 |
737 | |
323e88ad |
738 | theCommands.Add("2dintanalytical", "2dintanalytical circle1 circle2" |
739 | "Intersect circle1 and circle2 using IntAna2d_AnaIntersection.", |
740 | __FILE__, intersect_ana, g); |
741 | theCommands.Add("intconcon", "intconcon curve1 curve2" |
742 | "Intersect conic curve1 and conic curve2 using IntAna2d_AnaIntersection", |
743 | __FILE__, intconcon, g); |
744 | |
745 | theCommands.Add("2ddeviation", "2ddeviation result curve [-i U0] [-d N] [-Napprox N] [-Nexact N] [-approxOnly]\n" |
746 | "-i - sets an initial parameter for computation by iterative method;\n" |
747 | "-d - sets number of sub-intervals for searching. Default value is 2.\n" |
748 | "-Napprox - sets number of iteration for approx deviation computing,\n" |
749 | " defauilt value is 10" |
750 | "-Nexact - sets number of iteration for exact deviation computing,\n" |
751 | " defauilt value is 100" |
752 | "-approxOnly - to find deviation with approx method only,\n" |
753 | " the exact method is used if this parameter is not specified", |
754 | __FILE__, deviation, g); |
755 | |
7fd59977 |
756 | } |