1 // Created on: 2011-06-30
2 // Created by: jgv@ROLEX
3 // Copyright (c) 2011-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <GeometryTest.hxx>
17 #include <Geom_Curve.hxx>
18 #include <Geom2d_Curve.hxx>
19 #include <Geom_Surface.hxx>
20 #include <GeomAPI_ProjectPointOnSurf.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>
31 Standard_IMPORT Draw_Viewer dout;
34 //=======================================================================
37 //=======================================================================
38 static Standard_Integer xdistcc(Draw_Interpretor& , Standard_Integer n, const char** a)
42 cout<<" Use xdistcc c1 c2 t1 t2 nbp"<<endl;
46 Standard_Integer i, aNbP, iSize;
47 Standard_Real aD, aT, aT1, aT2, dT;
49 Handle(Geom_Curve) aC1, aC2;
50 Handle(Draw_Marker3D) aMr;
51 Draw_Color aColor(Draw_rouge);
53 aC1=DrawTrSurf::GetCurve(a[1]);
56 cout<<a[1]<<" is null curve"<<endl;
60 aC2=DrawTrSurf::GetCurve(a[2]);
63 cout<<a[2]<<" is null curve"<<endl;
73 aNbP=Draw::Atoi(a[5]);
78 Standard_Real aMaxParam = 0.0;
79 Standard_Real aMaxDist = 0.0;
81 dT=(aT2 - aT1) / (aNbP - 1);
82 for(i = 0; i < aNbP; ++i)
91 aD = aP1.Distance(aP2);
99 printf(" T=%lg\tD=%lg\n", aT, aD);
101 aMr=new Draw_Marker3D(aP1, Draw_Plus, aColor, iSize);
105 cout << "Max distance = " << aMaxDist << endl;
106 cout << "Param = " << aMaxParam << endl;
111 //=======================================================================
112 //function : xdistc2dc2dss
114 //=======================================================================
115 static Standard_Integer xdistc2dc2dss(Draw_Interpretor& , Standard_Integer n, const char** a)
119 cout<<" Use xdistc2dc2dss c2d_1 c2d_2 s1 s2 t1 t2 nbp"<<endl;
123 Standard_Integer i, aNbP, iSize;
124 Standard_Real aD, aT, aT1, aT2, dT;
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);
132 aC2d1=DrawTrSurf::GetCurve2d(a[1]);
135 cout<<a[1]<<" is null 2dcurve"<<endl;
139 aC2d2=DrawTrSurf::GetCurve2d(a[2]);
142 cout<<a[2]<<" is null 2dcurve"<<endl;
146 aS1=DrawTrSurf::GetSurface(a[3]);
149 cout<<a[3]<<" is null surface"<<endl;
153 aS2=DrawTrSurf::GetSurface(a[4]);
156 cout<<a[4]<<" is null surface"<<endl;
160 aT1=Draw::Atof(a[5]);
161 aT2=Draw::Atof(a[6]);
166 aNbP=Draw::Atoi(a[7]);
171 Standard_Real aMaxParam = 0.0;
172 Standard_Real aMaxDist = 0.0;
174 dT=(aT2 - aT1) / (aNbP - 1);
175 for(i = 0; i < aNbP; ++i)
181 aC2d1->D0(aT, aP2d1);
182 aS1->D0(aP2d1.X(), aP2d1.Y(), aP1);
184 aC2d2->D0(aT, aP2d2);
185 aS2->D0(aP2d2.X(), aP2d2.Y(), aP2);
187 aD = aP1.Distance(aP2);
195 printf(" T=%lg\tD=%lg\n", aT, aD);
197 aMr=new Draw_Marker3D(aP1, Draw_Plus, aColor, iSize);
201 cout << "Max distance = " << aMaxDist << endl;
202 cout << "Param = " << aMaxParam << endl;
207 //=======================================================================
208 //function : xdistcc2ds
210 //=======================================================================
211 static Standard_Integer xdistcc2ds(Draw_Interpretor& , Standard_Integer n, const char** a)
215 cout<<" Use xdistcc2ds c c2d s t1 t2 nbp"<<endl;
219 Standard_Integer i, aNbP, iSize;
220 Standard_Real aD, aT, aT1, aT2, dT;
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);
229 aC=DrawTrSurf::GetCurve(a[1]);
232 cout<<a[1]<<" is null curve"<<endl;
236 aC2d=DrawTrSurf::GetCurve2d(a[2]);
239 cout<<a[2]<<" is null 2dcurve"<<endl;
243 aS=DrawTrSurf::GetSurface(a[3]);
246 cout<<a[3]<<" is null surface"<<endl;
250 aT1=Draw::Atof(a[4]);
251 aT2=Draw::Atof(a[5]);
256 aNbP=Draw::Atoi(a[6]);
261 Standard_Real aMaxParam = 0.0;
262 Standard_Real aMaxDist = 0.0;
264 dT=(aT2 - aT1) / (aNbP - 1);
265 for(i = 0; i < aNbP; ++i)
274 aS->D0(aP2d.X(), aP2d.Y(), aPOnS);
276 aD = aP.Distance(aPOnS);
284 printf(" T=%lg\tD=%lg\n", aT, aD);
286 aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize);
290 cout << "Max distance = " << aMaxDist << endl;
291 cout << "Param = " << aMaxParam << endl;
296 //=======================================================================
299 //=======================================================================
300 static Standard_Integer xdistcs(Draw_Interpretor& di, Standard_Integer n, const char** a)
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;
310 Standard_Boolean bRet;
311 Standard_Integer i, aNbP, iSize;
312 Standard_Real aTol, aD, aT, aT1, aT2, dT;
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);
322 aC=DrawTrSurf::GetCurve(a[1]);
324 di << "Error: " << a[1] << " is not a curve!\n";
328 aS=DrawTrSurf::GetSurface(a[2]);
330 di << "Error: " << a[2] << " is not a surface!\n";
334 aT1=Draw::Atof(a[3]);
335 aT2=Draw::Atof(a[4]);
339 aNbP=Draw::Atoi(a[5]);
341 Standard_Real anErrTol = (n > 6 ? Draw::Atof(a[6]) : RealLast());
342 Standard_Real aWarnTol = (n > 7 ? Draw::Atof(a[7]) : RealLast());
346 dT=(aT2-aT1)/(aNbP-1);
348 Standard_Real aMaxParam = 0.0;
349 Standard_Real aMaxDist = 0.0;
350 for (i=0; i<aNbP; ++i) {
357 aPPS.Init(aP, aS, aTol);
360 di << "Error: GeomAPI_ProjectPointOnSurf failed\n";
364 aD=aPPS.LowerDistance();
365 // report error or warning if distance is greater than tolerance
368 di << "Error in " << a[1] << ":";
370 else if (aD > aWarnTol)
372 di << "Attention (critical value of tolerance) :";
375 sprintf(aMsg," T=%lg\tD=%lg\n", aT, aD);
378 aMr=new Draw_Marker3D(aP, Draw_Plus, aColor, iSize);
388 di << "Max distance = " << aMaxDist << "\n" ;
389 di << "Param = " << aMaxParam << "\n" ;
394 //=======================================================================
395 //function : TestProjCommands
397 //=======================================================================
399 void GeometryTest::TestProjCommands(Draw_Interpretor& theCommands)
402 static Standard_Boolean loaded = Standard_False;
404 loaded = Standard_True;
406 DrawTrSurf::BasicCommands(theCommands);
410 g = "Testing of projection (geometric objects)";
412 theCommands.Add("xdistcs", "xdistcs curve surface t1 t2 nbpoints [tol [warn_tol]]", __FILE__, xdistcs, g);
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);