Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-06-30 |
2 | // Created by: jgv@ROLEX | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
38f33510 J |
15 | |
16 | #include <GeometryTest.hxx> | |
17 | #include <Geom_Curve.hxx> | |
0a243bb4 | 18 | #include <Geom2d_Curve.hxx> |
38f33510 J |
19 | #include <Geom_Surface.hxx> |
20 | #include <GeomAPI_ProjectPointOnSurf.hxx> | |
21 | ||
22 | #include <DBRep.hxx> | |
23 | #include <DBRep_DrawableShape.hxx> | |
24 | #include <Draw_Interpretor.hxx> | |
25 | #include <Draw_Appli.hxx> | |
26 | #include <DrawTrSurf.hxx> | |
27 | #include <Draw_Marker3D.hxx> | |
28 | ||
29 | #include <stdio.h> | |
57c28b61 | 30 | #ifdef _WIN32 |
38f33510 J |
31 | Standard_IMPORT Draw_Viewer dout; |
32 | #endif | |
33 | ||
0a243bb4 | 34 | //======================================================================= |
35 | //function : xdistcc | |
36 | //purpose : | |
37 | //======================================================================= | |
38 | static Standard_Integer xdistcc(Draw_Interpretor& , Standard_Integer n, const char** a) | |
39 | { | |
40 | if (n < 5) | |
41 | { | |
04232180 | 42 | std::cout<<" Use xdistcc c1 c2 t1 t2 nbp"<<std::endl; |
0a243bb4 | 43 | return 0; |
44 | } | |
45 | ||
46 | Standard_Integer i, aNbP, iSize; | |
47 | Standard_Real aD, aT, aT1, aT2, dT; | |
48 | gp_Pnt aP1, aP2; | |
49 | Handle(Geom_Curve) aC1, aC2; | |
50 | Handle(Draw_Marker3D) aMr; | |
51 | Draw_Color aColor(Draw_rouge); | |
52 | ||
53 | aC1=DrawTrSurf::GetCurve(a[1]); | |
54 | if (aC1.IsNull()) | |
55 | { | |
04232180 | 56 | std::cout<<a[1]<<" is null curve"<<std::endl; |
0a243bb4 | 57 | return 0; |
58 | } | |
59 | ||
60 | aC2=DrawTrSurf::GetCurve(a[2]); | |
61 | if (aC2.IsNull()) | |
62 | { | |
04232180 | 63 | std::cout<<a[2]<<" is null curve"<<std::endl; |
0a243bb4 | 64 | return 0; |
65 | } | |
66 | ||
67 | aT1=Draw::Atof(a[3]); | |
68 | aT2=Draw::Atof(a[4]); | |
69 | ||
70 | aNbP=10; | |
71 | if (n > 4) | |
72 | { | |
73 | aNbP=Draw::Atoi(a[5]); | |
74 | } | |
75 | ||
76 | iSize=3; | |
77 | ||
78 | Standard_Real aMaxParam = 0.0; | |
79 | Standard_Real aMaxDist = 0.0; | |
80 | ||
81 | dT=(aT2 - aT1) / (aNbP - 1); | |
82 | for(i = 0; i < aNbP; ++i) | |
83 | { | |
84 | aT=aT1 + i * dT; | |
85 | if (i == aNbP-1) | |
86 | aT=aT2; | |
87 | ||
88 | aC1->D0(aT, aP1); | |
89 | aC2->D0(aT, aP2); | |
90 | ||
91 | aD = aP1.Distance(aP2); | |
92 | ||
93 | if (aD > aMaxDist) | |
94 | { | |
95 | aMaxParam = aT; | |
96 | aMaxDist = aD; | |
97 | } | |
98 | ||
99 | printf(" T=%lg\tD=%lg\n", aT, aD); | |
100 | ||
101 | aMr=new Draw_Marker3D(aP1, Draw_Plus, aColor, iSize); | |
102 | dout << aMr; | |
103 | } | |
104 | ||
04232180 | 105 | std::cout << "Max distance = " << aMaxDist << std::endl; |
106 | std::cout << "Param = " << aMaxParam << std::endl; | |
0a243bb4 | 107 | |
108 | return 0; | |
109 | } | |
110 | ||
111 | //======================================================================= | |
112 | //function : xdistc2dc2dss | |
113 | //purpose : | |
114 | //======================================================================= | |
115 | static Standard_Integer xdistc2dc2dss(Draw_Interpretor& , Standard_Integer n, const char** a) | |
116 | { | |
117 | if (n < 7) | |
118 | { | |
04232180 | 119 | std::cout<<" Use xdistc2dc2dss c2d_1 c2d_2 s1 s2 t1 t2 nbp"<<std::endl; |
0a243bb4 | 120 | return 0; |
121 | } | |
122 | ||
123 | Standard_Integer i, aNbP, iSize; | |
124 | Standard_Real aD, aT, aT1, aT2, dT; | |
125 | gp_Pnt aP1, aP2; | |
126 | gp_Pnt2d aP2d1, aP2d2; | |
127 | Handle(Geom2d_Curve) aC2d1, aC2d2; | |
128 | Handle(Geom_Surface) aS1, aS2; | |
129 | Handle(Draw_Marker3D) aMr; | |
130 | Draw_Color aColor(Draw_rouge); | |
131 | ||
132 | aC2d1=DrawTrSurf::GetCurve2d(a[1]); | |
133 | if (aC2d1.IsNull()) | |
134 | { | |
04232180 | 135 | std::cout<<a[1]<<" is null 2dcurve"<<std::endl; |
0a243bb4 | 136 | return 0; |
137 | } | |
138 | ||
139 | aC2d2=DrawTrSurf::GetCurve2d(a[2]); | |
140 | if (aC2d2.IsNull()) | |
141 | { | |
04232180 | 142 | std::cout<<a[2]<<" is null 2dcurve"<<std::endl; |
0a243bb4 | 143 | return 0; |
144 | } | |
145 | ||
146 | aS1=DrawTrSurf::GetSurface(a[3]); | |
147 | if (aS1.IsNull()) | |
148 | { | |
04232180 | 149 | std::cout<<a[3]<<" is null surface"<<std::endl; |
0a243bb4 | 150 | return 0; |
151 | } | |
152 | ||
153 | aS2=DrawTrSurf::GetSurface(a[4]); | |
154 | if (aS2.IsNull()) | |
155 | { | |
04232180 | 156 | std::cout<<a[4]<<" is null surface"<<std::endl; |
0a243bb4 | 157 | return 0; |
158 | } | |
159 | ||
160 | aT1=Draw::Atof(a[5]); | |
161 | aT2=Draw::Atof(a[6]); | |
162 | ||
163 | aNbP=10; | |
164 | if (n > 6) | |
165 | { | |
166 | aNbP=Draw::Atoi(a[7]); | |
167 | } | |
168 | ||
169 | iSize=3; | |
170 | ||
171 | Standard_Real aMaxParam = 0.0; | |
172 | Standard_Real aMaxDist = 0.0; | |
173 | ||
174 | dT=(aT2 - aT1) / (aNbP - 1); | |
175 | for(i = 0; i < aNbP; ++i) | |
176 | { | |
177 | aT=aT1 + i * dT; | |
178 | if (i == aNbP-1) | |
179 | aT=aT2; | |
180 | ||
181 | aC2d1->D0(aT, aP2d1); | |
182 | aS1->D0(aP2d1.X(), aP2d1.Y(), aP1); | |
183 | ||
184 | aC2d2->D0(aT, aP2d2); | |
185 | aS2->D0(aP2d2.X(), aP2d2.Y(), aP2); | |
186 | ||
187 | aD = aP1.Distance(aP2); | |
188 | ||
189 | if (aD > aMaxDist) | |
190 | { | |
191 | aMaxParam = aT; | |
192 | aMaxDist = aD; | |
193 | } | |
194 | ||
195 | printf(" T=%lg\tD=%lg\n", aT, aD); | |
196 | ||
197 | aMr=new Draw_Marker3D(aP1, Draw_Plus, aColor, iSize); | |
198 | dout << aMr; | |
199 | } | |
200 | ||
04232180 | 201 | std::cout << "Max distance = " << aMaxDist << std::endl; |
202 | std::cout << "Param = " << aMaxParam << std::endl; | |
0a243bb4 | 203 | |
204 | return 0; | |
205 | } | |
206 | ||
207 | //======================================================================= | |
208 | //function : xdistcc2ds | |
209 | //purpose : | |
210 | //======================================================================= | |
211 | static Standard_Integer xdistcc2ds(Draw_Interpretor& , Standard_Integer n, const char** a) | |
212 | { | |
213 | if (n < 6) | |
214 | { | |
04232180 | 215 | std::cout<<" Use xdistcc2ds c c2d s t1 t2 nbp"<<std::endl; |
0a243bb4 | 216 | return 0; |
217 | } | |
218 | ||
219 | Standard_Integer i, aNbP, iSize; | |
220 | Standard_Real aD, aT, aT1, aT2, dT; | |
221 | gp_Pnt aP, aPOnS; | |
222 | gp_Pnt2d aP2d; | |
223 | Handle(Geom_Curve) aC; | |
224 | Handle(Geom2d_Curve) aC2d; | |
225 | Handle(Geom_Surface) aS; | |
226 | Handle(Draw_Marker3D) aMr; | |
227 | Draw_Color aColor(Draw_rouge); | |
228 | ||
229 | aC=DrawTrSurf::GetCurve(a[1]); | |
230 | if (aC.IsNull()) | |
231 | { | |
04232180 | 232 | std::cout<<a[1]<<" is null curve"<<std::endl; |
0a243bb4 | 233 | return 0; |
234 | } | |
235 | ||
236 | aC2d=DrawTrSurf::GetCurve2d(a[2]); | |
237 | if (aC2d.IsNull()) | |
238 | { | |
04232180 | 239 | std::cout<<a[2]<<" is null 2dcurve"<<std::endl; |
0a243bb4 | 240 | return 0; |
241 | } | |
242 | ||
243 | aS=DrawTrSurf::GetSurface(a[3]); | |
244 | if (aS.IsNull()) | |
245 | { | |
04232180 | 246 | std::cout<<a[3]<<" is null surface"<<std::endl; |
0a243bb4 | 247 | return 0; |
248 | } | |
249 | ||
250 | aT1=Draw::Atof(a[4]); | |
251 | aT2=Draw::Atof(a[5]); | |
252 | ||
253 | aNbP=10; | |
254 | if (n>5) | |
255 | { | |
256 | aNbP=Draw::Atoi(a[6]); | |
257 | } | |
258 | ||
259 | iSize=3; | |
260 | ||
261 | Standard_Real aMaxParam = 0.0; | |
262 | Standard_Real aMaxDist = 0.0; | |
263 | ||
264 | dT=(aT2 - aT1) / (aNbP - 1); | |
265 | for(i = 0; i < aNbP; ++i) | |
266 | { | |
267 | aT=aT1 + i * dT; | |
268 | if (i == aNbP-1) | |
269 | aT=aT2; | |
270 | ||
271 | aC->D0(aT, aP); | |
272 | ||
273 | aC2d->D0(aT, aP2d); | |
274 | aS->D0(aP2d.X(), aP2d.Y(), aPOnS); | |
275 | ||
276 | aD = aP.Distance(aPOnS); | |
277 | ||
278 | if (aD > aMaxDist) | |
279 | { | |
280 | aMaxParam = aT; | |
281 | aMaxDist = aD; | |
282 | } | |
283 | ||
284 | printf(" T=%lg\tD=%lg\n", aT, aD); | |
285 | ||
286 | aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize); | |
287 | dout << aMr; | |
288 | } | |
289 | ||
04232180 | 290 | std::cout << "Max distance = " << aMaxDist << std::endl; |
291 | std::cout << "Param = " << aMaxParam << std::endl; | |
0a243bb4 | 292 | |
293 | return 0; | |
294 | } | |
295 | ||
38f33510 J |
296 | //======================================================================= |
297 | //function : xdistcs | |
298 | //purpose : | |
299 | //======================================================================= | |
6d368502 | 300 | static Standard_Integer xdistcs(Draw_Interpretor& di, Standard_Integer n, const char** a) |
38f33510 | 301 | { |
6d368502 | 302 | if (n < 6) { |
04232180 | 303 | std::cout << "Use: xdistcs curve surface t1 t2 nbpoints [tol [warn_tol]]" << std::endl; |
304 | std::cout << "Measures distances from curve to surface by nbpoints probing points on a curve" << std::endl; | |
305 | std::cout << "Error will be reported for points where distance is greater than tol" << std::endl; | |
306 | std::cout << "Warning will be reported for points where distance is greater than warn_tol" << std::endl; | |
38f33510 J |
307 | return 0; |
308 | } | |
309 | // | |
310 | Standard_Boolean bRet; | |
311 | Standard_Integer i, aNbP, iSize; | |
312 | Standard_Real aTol, aD, aT, aT1, aT2, dT; | |
313 | gp_Pnt aP; | |
314 | Handle(Geom_Curve) aC; | |
315 | Handle(Geom_Surface) aS; | |
316 | GeomAPI_ProjectPointOnSurf aPPS; | |
317 | Handle(Draw_Marker3D) aMr; | |
318 | Draw_Color aColor(Draw_rouge); | |
319 | // | |
320 | aTol=1.e-7; | |
321 | // | |
322 | aC=DrawTrSurf::GetCurve(a[1]); | |
323 | if (aC.IsNull()) { | |
586db386 | 324 | di << "Error: " << a[1] << " is not a curve!\n"; |
38f33510 J |
325 | return 0; |
326 | } | |
327 | // | |
328 | aS=DrawTrSurf::GetSurface(a[2]); | |
329 | if (aS.IsNull()) { | |
586db386 | 330 | di << "Error: " << a[2] << " is not a surface!\n"; |
38f33510 J |
331 | return 0; |
332 | } | |
333 | // | |
91322f44 | 334 | aT1=Draw::Atof(a[3]); |
335 | aT2=Draw::Atof(a[4]); | |
38f33510 J |
336 | // |
337 | aNbP=10; | |
338 | if (n>5) { | |
91322f44 | 339 | aNbP=Draw::Atoi(a[5]); |
38f33510 | 340 | } |
6d368502 | 341 | Standard_Real anErrTol = (n > 6 ? Draw::Atof(a[6]) : RealLast()); |
342 | Standard_Real aWarnTol = (n > 7 ? Draw::Atof(a[7]) : RealLast()); | |
38f33510 J |
343 | // |
344 | iSize=3; | |
345 | // | |
346 | dT=(aT2-aT1)/(aNbP-1); | |
27ba9c60 | 347 | |
348 | Standard_Real aMaxParam = 0.0; | |
349 | Standard_Real aMaxDist = 0.0; | |
38f33510 J |
350 | for (i=0; i<aNbP; ++i) { |
351 | aT=aT1+i*dT; | |
352 | if (i==aNbP-1) { | |
353 | aT=aT2; | |
354 | } | |
355 | // | |
356 | aC->D0(aT, aP); | |
357 | aPPS.Init(aP, aS, aTol); | |
358 | bRet=aPPS.IsDone(); | |
359 | if (!bRet) { | |
586db386 | 360 | di << "Error: GeomAPI_ProjectPointOnSurf failed\n"; |
38f33510 J |
361 | return 0; |
362 | } | |
363 | // | |
364 | aD=aPPS.LowerDistance(); | |
6d368502 | 365 | // report error or warning if distance is greater than tolerance |
366 | if (aD > anErrTol) | |
367 | { | |
8dc56d0f | 368 | di << "Error in " << a[1] << ":"; |
6d368502 | 369 | } |
370 | else if (aD > aWarnTol) | |
371 | { | |
372 | di << "Attention (critical value of tolerance) :"; | |
373 | } | |
374 | char aMsg[256]; | |
375 | sprintf(aMsg," T=%lg\tD=%lg\n", aT, aD); | |
376 | di << aMsg; | |
38f33510 J |
377 | // |
378 | aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize); | |
379 | dout << aMr; | |
27ba9c60 | 380 | |
381 | if (aD > aMaxDist) | |
382 | { | |
383 | aMaxParam = aT; | |
384 | aMaxDist = aD; | |
385 | } | |
38f33510 | 386 | } |
27ba9c60 | 387 | |
388 | di << "Max distance = " << aMaxDist << "\n" ; | |
389 | di << "Param = " << aMaxParam << "\n" ; | |
38f33510 J |
390 | // |
391 | return 0; | |
392 | } | |
393 | ||
394 | //======================================================================= | |
395 | //function : TestProjCommands | |
396 | //purpose : | |
397 | //======================================================================= | |
398 | ||
399 | void GeometryTest::TestProjCommands(Draw_Interpretor& theCommands) | |
400 | { | |
401 | ||
402 | static Standard_Boolean loaded = Standard_False; | |
403 | if (loaded) return; | |
404 | loaded = Standard_True; | |
405 | ||
406 | DrawTrSurf::BasicCommands(theCommands); | |
407 | ||
408 | const char* g; | |
409 | ||
410 | g = "Testing of projection (geometric objects)"; | |
411 | ||
6d368502 | 412 | theCommands.Add("xdistcs", "xdistcs curve surface t1 t2 nbpoints [tol [warn_tol]]", __FILE__, xdistcs, g); |
0a243bb4 | 413 | theCommands.Add("xdistcc2ds", "xdistcc2ds c c2d s t1 t2 nbp", __FILE__, xdistcc2ds, g); |
414 | theCommands.Add("xdistc2dc2dss", "xdistc2dc2dss c2d_1 c2d_2 s1 s2 t1 t2 nbp", __FILE__, xdistc2dc2dss, g); | |
415 | theCommands.Add("xdistcc", "xdistcc c1 c2 t1 t2 nbp", __FILE__, xdistcc, g); | |
38f33510 | 416 | } |