0027873: Exception is raised in BRepFill_Filling::FindExtremitiesOfHoles()
[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//=======================================================================
6d368502 300static Standard_Integer xdistcs(Draw_Interpretor& di, Standard_Integer n, const char** a)
38f33510 301{
6d368502 302 if (n < 6) {
303 cout << "Use: xdistcs curve surface t1 t2 nbpoints [tol [warn_tol]]" << endl;
304 cout << "Measures distances from curve to surface by nbpoints probing points on a curve" << endl;
305 cout << "Error will be reported for points where distance is greater than tol" << endl;
306 cout << "Warning will be reported for points where distance is greater than warn_tol" << 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);
347 for (i=0; i<aNbP; ++i) {
348 aT=aT1+i*dT;
349 if (i==aNbP-1) {
350 aT=aT2;
351 }
352 //
353 aC->D0(aT, aP);
354 aPPS.Init(aP, aS, aTol);
355 bRet=aPPS.IsDone();
356 if (!bRet) {
586db386 357 di << "Error: GeomAPI_ProjectPointOnSurf failed\n";
38f33510
J
358 return 0;
359 }
360 //
361 aD=aPPS.LowerDistance();
6d368502 362 // report error or warning if distance is greater than tolerance
363 if (aD > anErrTol)
364 {
365 di << "Error :";
366 }
367 else if (aD > aWarnTol)
368 {
369 di << "Attention (critical value of tolerance) :";
370 }
371 char aMsg[256];
372 sprintf(aMsg," T=%lg\tD=%lg\n", aT, aD);
373 di << aMsg;
38f33510
J
374 //
375 aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize);
376 dout << aMr;
377 }
378 //
379 return 0;
380}
381
382//=======================================================================
383//function : TestProjCommands
384//purpose :
385//=======================================================================
386
387void GeometryTest::TestProjCommands(Draw_Interpretor& theCommands)
388{
389
390 static Standard_Boolean loaded = Standard_False;
391 if (loaded) return;
392 loaded = Standard_True;
393
394 DrawTrSurf::BasicCommands(theCommands);
395
396 const char* g;
397
398 g = "Testing of projection (geometric objects)";
399
6d368502 400 theCommands.Add("xdistcs", "xdistcs curve surface t1 t2 nbpoints [tol [warn_tol]]", __FILE__, xdistcs, g);
0a243bb4 401 theCommands.Add("xdistcc2ds", "xdistcc2ds c c2d s t1 t2 nbp", __FILE__, xdistcc2ds, g);
402 theCommands.Add("xdistc2dc2dss", "xdistc2dc2dss c2d_1 c2d_2 s1 s2 t1 t2 nbp", __FILE__, xdistc2dc2dss, g);
403 theCommands.Add("xdistcc", "xdistcc c1 c2 t1 t2 nbp", __FILE__, xdistcc, g);
38f33510 404}