0026668: Eliminate compile warnings obtained by building occt with vc14: conversion...
[occt.git] / src / GeometryTest / GeometryTest_TestProjCommands.cxx
CommitLineData
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
31Standard_IMPORT Draw_Viewer dout;
32#endif
33
34//=======================================================================
0a243bb4 35//function : xdistcc
36//purpose :
37//=======================================================================
38static Standard_Integer xdistcc(Draw_Interpretor& , Standard_Integer n, const char** a)
39{
40 if (n < 5)
41 {
42 cout<<" Use xdistcc c1 c2 t1 t2 nbp"<<endl;
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 {
56 cout<<a[1]<<" is null curve"<<endl;
57 return 0;
58 }
59
60 aC2=DrawTrSurf::GetCurve(a[2]);
61 if (aC2.IsNull())
62 {
63 cout<<a[2]<<" is null curve"<<endl;
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
105 cout << "Max distance = " << aMaxDist << endl;
106 cout << "Param = " << aMaxParam << endl;
107
108 return 0;
109}
110
111//=======================================================================
112//function : xdistc2dc2dss
113//purpose :
114//=======================================================================
115static Standard_Integer xdistc2dc2dss(Draw_Interpretor& , Standard_Integer n, const char** a)
116{
117 if (n < 7)
118 {
119 cout<<" Use xdistc2dc2dss c2d_1 c2d_2 s1 s2 t1 t2 nbp"<<endl;
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 {
135 cout<<a[1]<<" is null 2dcurve"<<endl;
136 return 0;
137 }
138
139 aC2d2=DrawTrSurf::GetCurve2d(a[2]);
140 if (aC2d2.IsNull())
141 {
142 cout<<a[2]<<" is null 2dcurve"<<endl;
143 return 0;
144 }
145
146 aS1=DrawTrSurf::GetSurface(a[3]);
147 if (aS1.IsNull())
148 {
149 cout<<a[3]<<" is null surface"<<endl;
150 return 0;
151 }
152
153 aS2=DrawTrSurf::GetSurface(a[4]);
154 if (aS2.IsNull())
155 {
156 cout<<a[4]<<" is null surface"<<endl;
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
201 cout << "Max distance = " << aMaxDist << endl;
202 cout << "Param = " << aMaxParam << endl;
203
204 return 0;
205}
206
207//=======================================================================
208//function : xdistcc2ds
209//purpose :
210//=======================================================================
211static Standard_Integer xdistcc2ds(Draw_Interpretor& , Standard_Integer n, const char** a)
212{
213 if (n < 6)
214 {
215 cout<<" Use xdistcc2ds c c2d s t1 t2 nbp"<<endl;
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 {
232 cout<<a[1]<<" is null curve"<<endl;
233 return 0;
234 }
235
236 aC2d=DrawTrSurf::GetCurve2d(a[2]);
237 if (aC2d.IsNull())
238 {
239 cout<<a[2]<<" is null 2dcurve"<<endl;
240 return 0;
241 }
242
243 aS=DrawTrSurf::GetSurface(a[3]);
244 if (aS.IsNull())
245 {
246 cout<<a[3]<<" is null surface"<<endl;
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
290 cout << "Max distance = " << aMaxDist << endl;
291 cout << "Param = " << aMaxParam << endl;
292
293 return 0;
294}
295
296//=======================================================================
38f33510
J
297//function : xdistcs
298//purpose :
299//=======================================================================
300static Standard_Integer xdistcs(Draw_Interpretor& , Standard_Integer n, const char** a)
301{
302 if (n<5) {
303 cout<<" Use xdistcs c s t1 t2 nbp"<<endl;
304 return 0;
305 }
306 //
307 Standard_Boolean bRet;
308 Standard_Integer i, aNbP, iSize;
309 Standard_Real aTol, aD, aT, aT1, aT2, dT;
310 gp_Pnt aP;
311 Handle(Geom_Curve) aC;
312 Handle(Geom_Surface) aS;
313 GeomAPI_ProjectPointOnSurf aPPS;
314 Handle(Draw_Marker3D) aMr;
315 Draw_Color aColor(Draw_rouge);
316 //
317 aTol=1.e-7;
318 //
319 aC=DrawTrSurf::GetCurve(a[1]);
320 if (aC.IsNull()) {
321 cout<<a[1]<<" is null curve"<<endl;
322 return 0;
323 }
324 //
325 aS=DrawTrSurf::GetSurface(a[2]);
326 if (aS.IsNull()) {
327 cout<<a[2]<<" is null"<<endl;
328 return 0;
329 }
330 //
91322f44 331 aT1=Draw::Atof(a[3]);
332 aT2=Draw::Atof(a[4]);
38f33510
J
333 //
334 aNbP=10;
335 if (n>5) {
91322f44 336 aNbP=Draw::Atoi(a[5]);
38f33510
J
337 }
338 //
339 iSize=3;
340 //
341 dT=(aT2-aT1)/(aNbP-1);
342 for (i=0; i<aNbP; ++i) {
343 aT=aT1+i*dT;
344 if (i==aNbP-1) {
345 aT=aT2;
346 }
347 //
348 aC->D0(aT, aP);
349 aPPS.Init(aP, aS, aTol);
350 bRet=aPPS.IsDone();
351 if (!bRet) {
352 cout<<" GeomAPI_ProjectPointOnSurf failed"<<endl;
353 return 0;
354 }
355 //
356 aD=aPPS.LowerDistance();
357 printf(" T=%lg\tD=%lg\n", aT, aD);
358 //
359 aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize);
360 dout << aMr;
361 }
362 //
363 return 0;
364}
365
366//=======================================================================
367//function : TestProjCommands
368//purpose :
369//=======================================================================
370
371void GeometryTest::TestProjCommands(Draw_Interpretor& theCommands)
372{
373
374 static Standard_Boolean loaded = Standard_False;
375 if (loaded) return;
376 loaded = Standard_True;
377
378 DrawTrSurf::BasicCommands(theCommands);
379
380 const char* g;
381
382 g = "Testing of projection (geometric objects)";
383
384 theCommands.Add("xdistcs", "xdistcs c s t1 t2 nbp", __FILE__, xdistcs, g);
0a243bb4 385 theCommands.Add("xdistcc2ds", "xdistcc2ds c c2d s t1 t2 nbp", __FILE__, xdistcc2ds, g);
386 theCommands.Add("xdistc2dc2dss", "xdistc2dc2dss c2d_1 c2d_2 s1 s2 t1 t2 nbp", __FILE__, xdistc2dc2dss, g);
387 theCommands.Add("xdistcc", "xdistcc c1 c2 t1 t2 nbp", __FILE__, xdistcc, g);
38f33510 388}