0024510: Remove unused local variables
[occt.git] / src / GeometryTest / GeometryTest_CurveCommands.cxx
CommitLineData
b311480e 1// Created on: 1993-08-12
2// Created by: Bruno DUMORTIER
3// Copyright (c) 1993-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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public version 2.1 as published
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// 09/06/97 : JPI : suppression des commandes redondantes suite a la creation de GeomliteTest
18
19#include <GeometryTest.hxx>
20#include <Draw_Appli.hxx>
21#include <DrawTrSurf.hxx>
22#include <DrawTrSurf_Curve.hxx>
23#include <DrawTrSurf_Curve2d.hxx>
24#include <DrawTrSurf_BezierCurve.hxx>
25#include <DrawTrSurf_BSplineCurve.hxx>
26#include <DrawTrSurf_BezierCurve2d.hxx>
27#include <DrawTrSurf_BSplineCurve2d.hxx>
28#include <Draw_Marker3D.hxx>
29#include <Draw_Marker2D.hxx>
30#include <Draw.hxx>
31#include <Draw_Interpretor.hxx>
32#include <Draw_Color.hxx>
33#include <Draw_Display.hxx>
34
35#include <GeomAPI.hxx>
36#include <GeomAPI_IntCS.hxx>
37#include <GeomAPI_IntSS.hxx>
38
39//#include <GeomLProp.hxx>
40#include <GeomProjLib.hxx>
41#include <BSplCLib.hxx>
42
43#include <gp.hxx>
44#include <gp_Pln.hxx>
45#include <gp_Parab2d.hxx>
46#include <gp_Elips2d.hxx>
47#include <gp_Hypr2d.hxx>
48
49#include <Geom_Line.hxx>
50#include <Geom_Circle.hxx>
51#include <Geom_Ellipse.hxx>
52#include <Geom_Parabola.hxx>
53#include <Geom_Hyperbola.hxx>
54#include <Geom2d_Line.hxx>
55#include <Geom2d_Circle.hxx>
56#include <Geom2d_Ellipse.hxx>
57#include <Geom2d_Parabola.hxx>
58#include <Geom2d_Hyperbola.hxx>
59#include <Geom2d_BSplineCurve.hxx>
60#include <Geom2d_Curve.hxx>
61
62#include <GccAna_Lin2dBisec.hxx>
63#include <GccAna_Circ2dBisec.hxx>
64#include <GccAna_CircLin2dBisec.hxx>
65#include <GccAna_CircPnt2dBisec.hxx>
66#include <GccAna_LinPnt2dBisec.hxx>
67#include <GccAna_Pnt2dBisec.hxx>
68#include <GccInt_Bisec.hxx>
69#include <GccInt_IType.hxx>
70
71#include <Geom_Plane.hxx>
72#include <Geom_Curve.hxx>
73#include <Geom2d_Curve.hxx>
74#include <Geom2d_TrimmedCurve.hxx>
75#include <Geom_TrimmedCurve.hxx>
76
77#include <Law_BSpline.hxx>
78
79#include <TColgp_Array1OfPnt.hxx>
80#include <TColgp_Array1OfPnt2d.hxx>
81#include <TColStd_Array1OfReal.hxx>
82#include <TColStd_Array1OfInteger.hxx>
83
84#include <Adaptor3d_HCurve.hxx>
85#include <Adaptor3d_HSurface.hxx>
86#include <Adaptor3d_CurveOnSurface.hxx>
87
88#include <GeomAdaptor_HCurve.hxx>
89#include <GeomAdaptor_HSurface.hxx>
90#include <GeomAdaptor.hxx>
91#include <Geom2dAdaptor_HCurve.hxx>
92
93#include <GeomAbs_SurfaceType.hxx>
94#include <GeomAbs_CurveType.hxx>
95
96#include <ProjLib_CompProjectedCurve.hxx>
97#include <ProjLib_HCompProjectedCurve.hxx>
98#include <Approx_CurveOnSurface.hxx>
99#include <Precision.hxx>
100#include <Geom2dAdaptor.hxx>
101
102
103#include <Precision.hxx>
104
105#include <Geom_Surface.hxx>
106#include <Adaptor2d_HCurve2d.hxx>
107#include <stdio.h>
108#include <BSplCLib.hxx>
109#include <Geom_BSplineSurface.hxx>
110#include <Geom_BSplineCurve.hxx>
111#include <GCPnts_QuasiUniformDeflection.hxx>
112#include <GCPnts_UniformDeflection.hxx>
113#include <GCPnts_TangentialDeflection.hxx>
114#include <GeomAPI_ExtremaCurveCurve.hxx>
115#include <gce_MakeLin.hxx>
116#include <TColStd_Array1OfBoolean.hxx>
117#include <GeomAdaptor_HSurface.hxx>
118#include <Adaptor3d_TopolTool.hxx>
119#include <TColgp_Array2OfPnt.hxx>
120#include <Geom_BSplineSurface.hxx>
121#include <DrawTrSurf_BSplineSurface.hxx>
122#include <TColStd_HArray1OfReal.hxx>
123
124//epa test
125#include <BRepBuilderAPI_MakeEdge.hxx>
126#include <AIS_Shape.hxx>
127#include <TopoDS_Edge.hxx>
128#include <GeomLProp_CLProps.hxx>
129#include <GCPnts_AbscissaPoint.hxx>
130#include <GCPnts_UniformAbscissa.hxx>
131#include <DBRep.hxx>
132
133#ifdef WNT
134Standard_IMPORT Draw_Viewer dout;
135#endif
136
137//=======================================================================
138//function : polecurve2d
139//purpose :
140//=======================================================================
141
142static Standard_Integer polelaw (Draw_Interpretor& , Standard_Integer n, const char** a)
143{
144 Standard_Integer k,
145 jj,
146 qq,
147 i;
148
149
150 if (n < 3) return 1;
151 Standard_Boolean periodic = Standard_False ;
91322f44 152 Standard_Integer deg = Draw::Atoi(a[2]);
153 Standard_Integer nbk = Draw::Atoi(a[3]);
7fd59977 154
155 TColStd_Array1OfReal knots(1, nbk);
156 TColStd_Array1OfInteger mults(1, nbk);
157 k = 4;
158 Standard_Integer Sigma = 0;
159 for (i = 1; i<=nbk; i++) {
91322f44 160 knots( i) = Draw::Atof(a[k]);
7fd59977 161 k++;
91322f44 162 mults( i) = Draw::Atoi(a[k]);
7fd59977 163 Sigma += mults(i);
164 k++;
165 }
166
167 Standard_Integer np;
168 np = Sigma - deg -1;
169 TColStd_Array1OfReal flat_knots(1, Sigma) ;
170 jj = 1 ;
171 for (i = 1 ; i <= nbk ; i++) {
172 for(qq = 1 ; qq <= mults(i) ; qq++) {
173 flat_knots(jj) = knots(i) ;
174 jj ++ ;
175 }
176 }
177
178 TColgp_Array1OfPnt2d poles (1, np);
179 TColStd_Array1OfReal schoenberg_points(1,np) ;
180 BSplCLib::BuildSchoenbergPoints(deg,
181 flat_knots,
182 schoenberg_points) ;
183 for (i = 1; i <= np; i++) {
91322f44 184 poles(i).SetCoord(schoenberg_points(i),Draw::Atof(a[k]));
7fd59977 185 k++;
186 }
187
188 Handle(Geom2d_BSplineCurve) result =
189 new Geom2d_BSplineCurve(poles, knots, mults, deg, periodic);
190 DrawTrSurf::Set(a[1],result);
191
192
193 return 0;
194}
195//=======================================================================
196//function : to2d
197//purpose :
198//=======================================================================
199
200static Standard_Integer to2d (Draw_Interpretor& , Standard_Integer n, const char** a)
201{
202 if (n < 3) return 1;
203
204 // get the curve
205 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
206 if (C.IsNull())
207 return 1;
208
209 Handle(Geom_Surface) S;
210 if (n >= 4) {
211 S = DrawTrSurf::GetSurface(a[3]);
212 if (S.IsNull()) return 1;
213 }
214 else
215 S = new Geom_Plane(gp::XOY());
216
217 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
218 if (P.IsNull()) return 1;
219 Handle(Geom2d_Curve) r = GeomAPI::To2d(C,P->Pln());
220 DrawTrSurf::Set(a[1],r);
221 return 0;
222}
223
224//=======================================================================
225//function : to3d
226//purpose :
227//=======================================================================
228
229static Standard_Integer to3d (Draw_Interpretor& , Standard_Integer n, const char** a)
230{
231 if (n < 3) return 1;
232
233 Handle(Geom2d_Curve) C = DrawTrSurf::GetCurve2d(a[2]);
234 if (C.IsNull()) return 1;
235
236 Handle(Geom_Surface) S;
237 if (n >= 4) {
238 S = DrawTrSurf::GetSurface(a[3]);
239 if (S.IsNull()) return 1;
240 }
241 else
242 S = new Geom_Plane(gp::XOY());
243
244 Handle(Geom_Plane) P = Handle(Geom_Plane)::DownCast(S);
245 if (P.IsNull()) return 1;
246 Handle(Geom_Curve) r = GeomAPI::To3d(C,P->Pln());
247
248 DrawTrSurf::Set(a[1],r);
249 return 0;
250}
251
252//=======================================================================
253//function : gproject
254//purpose :
255//=======================================================================
256
257
258static Standard_Integer gproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
259{
260
261 char newname[1024];
262 char* temp = newname;
263 char newname1[10];
264 char* temp1 = newname1;
265 char name[100];
266 Standard_Integer ONE = 1;
267
268 if (n == 3)
91322f44 269 Sprintf(name,"p");
7fd59977 270 else if (n == 4) {
91322f44 271 Sprintf(name,"%s",a[1]);
7fd59977 272 ONE = 2;
273 }
274 else {
275 di << "gproject wait 2 or 3 arguments" << "\n";
276 return 1;
277 }
278
279 Handle(Geom_Curve) Cur = DrawTrSurf::GetCurve(a[ONE]);
280 Handle(Geom_Surface) Sur = DrawTrSurf::GetSurface(a[ONE+1]);
281 if (Cur.IsNull() || Sur.IsNull()) return 1;
282
283 Handle(GeomAdaptor_HCurve) hcur = new GeomAdaptor_HCurve(Cur);
284 Handle(GeomAdaptor_HSurface) hsur = new GeomAdaptor_HSurface(Sur);
285
286
287 Standard_Real myTol3d = 1.e-6;
288 GeomAbs_Shape myContinuity = GeomAbs_C2;
289 Standard_Integer myMaxDegree = 14, myMaxSeg = 16;
290
291
292 ProjLib_CompProjectedCurve Projector(hsur, hcur, myTol3d/10, myTol3d/10);
293 Handle(ProjLib_HCompProjectedCurve) HProjector = new ProjLib_HCompProjectedCurve();
294 HProjector->Set(Projector);
295
296 Standard_Integer k;
297 Standard_Real Udeb, Ufin, UIso, VIso;
298 Standard_Integer Only2d, Only3d;
299 gp_Pnt2d P2d, Pdeb, Pfin;
300 gp_Pnt P;
301 Handle(Adaptor2d_HCurve2d) HPCur;
302 Handle(Geom2d_Curve) PCur2d; // Only for isoparametric projection
303
304 for(k = 1; k <= Projector.NbCurves(); k++){
91322f44 305 Sprintf(newname,"%s_%d",name,k);
306 Sprintf(newname1,"%s2d_%d",name,k);
7fd59977 307 if(Projector.IsSinglePnt(k, P2d)){
308// cout<<"Part "<<k<<" of the projection is punctual"<<endl;
309 Projector.GetSurface()->D0(P2d.X(), P2d.Y(), P);
310 DrawTrSurf::Set(temp, P);
311 DrawTrSurf::Set(temp1, P2d);
312 di<<temp<<" is 3d projected curve"<<"\n";
313 di<<temp1<<" is pcurve"<<"\n";
314 }
315 else {
316 Only2d = Only3d = Standard_False;
317 Projector.Bounds(k, Udeb, Ufin);
318 gp_Dir2d Dir; // Only for isoparametric projection
319
320 if (Projector.IsUIso(k, UIso)) {
321// cout<<"Part "<<k<<" of the projection is U-isoparametric curve"<<endl;
322 Projector.D0(Udeb, Pdeb);
323 Projector.D0(Ufin, Pfin);
324 Udeb = Pdeb.Y();
325 Ufin = Pfin.Y();
326 if (Udeb > Ufin) {
327 Dir = gp_Dir2d(0, -1);
328 Udeb = - Udeb;
329 Ufin = - Ufin;
330 }
331 else Dir = gp_Dir2d(0, 1);
332 PCur2d = new Geom2d_TrimmedCurve(new Geom2d_Line(gp_Pnt2d(UIso, 0), Dir), Udeb, Ufin);
333 HPCur = new Geom2dAdaptor_HCurve(PCur2d);
334 Only3d = Standard_True;
335 }
336 else if(Projector.IsVIso(k, VIso)) {
337// cout<<"Part "<<k<<" of the projection is V-isoparametric curve"<<endl;
338 Projector.D0(Udeb, Pdeb);
339 Projector.D0(Ufin, Pfin);
340 Udeb = Pdeb.X();
341 Ufin = Pfin.X();
342 if (Udeb > Ufin) {
343 Dir = gp_Dir2d(-1, 0);
344 Udeb = - Udeb;
345 Ufin = - Ufin;
346 }
347 else Dir = gp_Dir2d(1, 0);
348 PCur2d = new Geom2d_TrimmedCurve(new Geom2d_Line(gp_Pnt2d(0, VIso), Dir), Udeb, Ufin);
349 HPCur = new Geom2dAdaptor_HCurve(PCur2d);
350 Only3d = Standard_True;
351 }
352 else HPCur = HProjector;
353
354 if(Projector.MaxDistance(k) <= myTol3d)
355 Only2d = Standard_True;
356
357 if(Only2d && Only3d) {
358 Handle(Geom_Curve) OutCur = new Geom_TrimmedCurve(GeomAdaptor::MakeCurve(hcur->Curve()), Ufin, Udeb);
359 DrawTrSurf::Set(temp, OutCur);
360 DrawTrSurf::Set(temp1, PCur2d);
361 di<<temp<<" is 3d projected curve"<<"\n";
362 di<<temp1<<" is pcurve"<<"\n";
363 return 0;
364 }
365 else {
366 Approx_CurveOnSurface appr(HPCur, hsur, Udeb, Ufin, myTol3d,
367 myContinuity, myMaxDegree, myMaxSeg,
368 Only3d, Only2d);
369 if(!Only3d) {
370 PCur2d = appr.Curve2d();
371 di << " Error in 2d is " << appr.MaxError2dU()
372 << "; " << appr.MaxError2dV() << "\n";
373 }
374 if(Only2d) {
375 Handle(Geom_Curve) OutCur =
376 new Geom_TrimmedCurve(GeomAdaptor::MakeCurve(hcur->Curve()),
377 Ufin, Udeb);
378 DrawTrSurf::Set(temp, OutCur);
379 }
380 else {
381 di << " Error in 3d is " << appr.MaxError3d() << "\n";
382 DrawTrSurf::Set(temp, appr.Curve3d());
383 }
384 DrawTrSurf::Set(temp1, PCur2d);
385 di<<temp<<" is 3d projected curve"<<"\n";
386 di<<temp1<<" is pcurve"<<"\n";
387 }
388 }
389 }
390return 0;
391}
392//=======================================================================
393//function : project
394//purpose :
395//=======================================================================
396
397static Standard_Integer project (Draw_Interpretor& di,
398 Standard_Integer n, const char** a)
399{
400 if ( n == 1) {
401
402 di << "project result2d c3d surf [-e p] [-v n] [-t tol]" << "\n";
403 di << " -e p : extent the surface of <p>%" << "\n";
404 di << " -v n : verify the projection at <n> points." << "\n";
405 di << " -t tol : set the tolerance for approximation" << "\n";
406 return 0;
407 }
408
409 if (n < 4) return 1;
410 Handle(Geom_Surface) GS = DrawTrSurf::GetSurface(a[3]);
411 if (GS.IsNull()) return 1;
412
413 Handle(Geom_Curve) GC = DrawTrSurf::GetCurve(a[2]);
414 if (GC.IsNull()) return 1;
415
416 Standard_Real tolerance = Precision::Confusion() ;
417
418 Standard_Real U1,U2,V1,V2;
419 GS->Bounds(U1,U2,V1,V2);
420
96a95605 421 Standard_Boolean Verif = Standard_False;
7fd59977 422 Standard_Integer NbPoints=0;
423
424 Standard_Integer index = 4;
425 while ( index+1 < n) {
426 if ( a[index][0] != '-') return 1;
427
428 if ( a[index][1] == 'e') {
91322f44 429 Standard_Real p = Draw::Atof(a[index+1]);
7fd59977 430 Standard_Real dU = p * (U2 - U1) / 100.;
431 Standard_Real dV = p * (V2 - V1) / 100.;
432 U1 -= dU; U2 += dU; V1 -= dV; V2 += dV;
7fd59977 433 }
434 else if ( a[index][1] == 'v') {
435 Verif = Standard_True;
91322f44 436 NbPoints = Draw::Atoi(a[index+1]);
7fd59977 437 }
438 else if ( a[index][1] == 't') {
91322f44 439 tolerance = Draw::Atof(a[index+1]);
7fd59977 440 }
441 index += 2;
442 }
443
444 Handle(Geom2d_Curve) G2d =
445 GeomProjLib::Curve2d(GC, GS, U1, U2, V1, V2, tolerance);
446
447 if ( G2d.IsNull() ) {
448 di << "\n" << "Projection Failed" << "\n";
449 return 1;
450 }
451 else {
452 DrawTrSurf::Set(a[1],G2d);
453 }
454 if ( Verif) { // verify the projection on n points
455 if ( NbPoints <= 0) {
456 di << " n must be positive" << "\n";
457 return 0;
458 }
459 gp_Pnt P1,P2;
460 gp_Pnt2d P2d;
461
462 Standard_Real U, dU;
463 Standard_Real Dist,DistMax = -1.;
464 U1 = GC->FirstParameter();
465 U2 = GC->LastParameter();
466 dU = ( U2 - U1) / (NbPoints + 1);
467 for ( Standard_Integer i = 0 ; i <= NbPoints +1; i++) {
468 U = U1 + i *dU;
469 P1 = GC->Value(U);
470 P2d = G2d->Value(U);
471 P2 = GS->Value(P2d.X(), P2d.Y());
472 Dist = P1.Distance(P2);
473 di << " Parameter = " << U << "\tDistance = " << Dist << "\n";
474 if ( Dist > DistMax) DistMax = Dist;
475 }
476 di << " **** Distance Maximale : " << DistMax << "\n";
477 }
478
479 return 0;
480}
481
482//=======================================================================
483//function : projonplane
484//purpose :
485//=======================================================================
486
487Standard_Integer projonplane(Draw_Interpretor& di,
488 Standard_Integer n, const char** a)
489{
490 if ( n < 4 ) return 1;
491
492 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
493 if ( S.IsNull()) return 1;
494
495 Handle(Geom_Plane) Pl = Handle(Geom_Plane)::DownCast(S);
496 if ( Pl.IsNull()) {
497 di << " The surface must be a plane" << "\n";
498 return 1;
499 }
500
501 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
502 if ( C.IsNull()) return 1;
503
504 Standard_Boolean Param = Standard_True;
91322f44 505 if ((n == 5 && Draw::Atoi(a[4]) == 0) ||
506 (n == 8 && Draw::Atoi(a[7]) == 0)) Param = Standard_False;
7fd59977 507
508 gp_Dir D;
509
510 if ( n == 8) {
91322f44 511 D = gp_Dir(Draw::Atof(a[4]),Draw::Atof(a[5]),Draw::Atof(a[6]));
7fd59977 512 }
513 else {
514 D = Pl->Pln().Position().Direction();
515 }
516
517 Handle(Geom_Curve) Res =
518 GeomProjLib::ProjectOnPlane(C,Pl,D,Param);
519
520 DrawTrSurf::Set(a[1],Res);
521 return 0;
522
523}
524
525
526//=======================================================================
527//function : bisec
528//purpose :
529//=======================================================================
530
531static void solution(const Handle(GccInt_Bisec)& Bis,
532 const char* name,
533 const Standard_Integer i)
534{
535 char solname[200];
536 if ( i == 0)
91322f44 537 Sprintf(solname,"%s",name);
7fd59977 538 else
91322f44 539 Sprintf(solname,"%s_%d",name,i);
7fd59977 540 const char* temp = solname; // pour portage WNT
541
542 switch ( Bis->ArcType()) {
543 case GccInt_Lin:
544 DrawTrSurf::Set(temp, new Geom2d_Line(Bis->Line()));
545 break;
546 case GccInt_Cir:
547 DrawTrSurf::Set(temp, new Geom2d_Circle(Bis->Circle()));
548 break;
549 case GccInt_Ell:
550 DrawTrSurf::Set(temp, new Geom2d_Ellipse(Bis->Ellipse()));
551 break;
552 case GccInt_Par:
553 DrawTrSurf::Set(temp, new Geom2d_Parabola(Bis->Parabola()));
554 break;
555 case GccInt_Hpr:
556 DrawTrSurf::Set(temp, new Geom2d_Hyperbola(Bis->Hyperbola()));
557 break;
558 case GccInt_Pnt:
559 DrawTrSurf::Set(temp, Bis->Point());
560 break;
561 }
562}
563
564static Standard_Integer bisec (Draw_Interpretor& di,
565 Standard_Integer n, const char** a)
566{
567 if (n < 4) return 1;
568
569 Handle(Geom2d_Curve) C1 = DrawTrSurf::GetCurve2d(a[2]);
570 Handle(Geom2d_Curve) C2 = DrawTrSurf::GetCurve2d(a[3]);
571 gp_Pnt2d P1,P2;
572 Standard_Boolean ip1 = DrawTrSurf::GetPoint2d(a[2],P1);
573 Standard_Boolean ip2 = DrawTrSurf::GetPoint2d(a[3],P2);
574 Standard_Integer i, Compt = 0;
575 Standard_Integer NbSol = 0;
576
577 if ( !C1.IsNull()) {
578 Handle(Standard_Type) Type1 = C1->DynamicType();
579 if ( !C2.IsNull()) {
580 Handle(Standard_Type) Type2 = C2->DynamicType();
581 if ( Type1 == STANDARD_TYPE(Geom2d_Line) &&
582 Type2 == STANDARD_TYPE(Geom2d_Line) ) {
583 GccAna_Lin2dBisec Bis(Handle(Geom2d_Line)::DownCast(C1)->Lin2d(),
584 Handle(Geom2d_Line)::DownCast(C2)->Lin2d());
585 if ( Bis.IsDone()) {
586 char solname[200];
587 NbSol = Bis.NbSolutions();
588 for ( i = 1; i <= NbSol; i++) {
91322f44 589 Sprintf(solname,"%s_%d",a[1],i);
7fd59977 590 const char* temp = solname; // pour portage WNT
591 DrawTrSurf::Set(temp,new Geom2d_Line(Bis.ThisSolution(i)));
592 }
593 }
594 else {
595 di << " Bisec has failed !!" << "\n";
596 return 1;
597 }
598 }
599 else if ( Type1 == STANDARD_TYPE(Geom2d_Line) &&
600 Type2 == STANDARD_TYPE(Geom2d_Circle) ) {
601 GccAna_CircLin2dBisec
602 Bis(Handle(Geom2d_Circle)::DownCast(C2)->Circ2d(),
603 Handle(Geom2d_Line)::DownCast(C1)->Lin2d());
604 if ( Bis.IsDone()) {
605 NbSol= Bis.NbSolutions();
606 if ( NbSol >= 2) Compt = 1;
607 for ( i = 1; i <= NbSol; i++) {
608 solution(Bis.ThisSolution(i),a[1],Compt);
609 Compt++;
610 }
611 }
612 else {
613 di << " Bisec has failed !!" << "\n";
614 return 1;
615 }
616 }
617 else if ( Type2 == STANDARD_TYPE(Geom2d_Line) &&
618 Type1 == STANDARD_TYPE(Geom2d_Circle) ) {
619 GccAna_CircLin2dBisec
620 Bis(Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),
621 Handle(Geom2d_Line)::DownCast(C2)->Lin2d());
622 if ( Bis.IsDone()) {
623// char solname[200];
624 NbSol = Bis.NbSolutions();
625 if ( NbSol >= 2) Compt = 1;
626 for ( i = 1; i <= NbSol; i++) {
627 solution(Bis.ThisSolution(i),a[1],Compt);
628 Compt++;
629 }
630 }
631 else {
632 di << " Bisec has failed !!" << "\n";
633 return 1;
634 }
635 }
636 else if ( Type2 == STANDARD_TYPE(Geom2d_Circle) &&
637 Type1 == STANDARD_TYPE(Geom2d_Circle) ) {
638 GccAna_Circ2dBisec
639 Bis(Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),
640 Handle(Geom2d_Circle)::DownCast(C2)->Circ2d());
641 if ( Bis.IsDone()) {
642// char solname[200];
643 NbSol = Bis.NbSolutions();
644 if ( NbSol >= 2) Compt = 1;
645 for ( i = 1; i <= NbSol; i++) {
646 solution(Bis.ThisSolution(i),a[1],Compt);
647 Compt++;
648 }
649 }
650 else {
651 di << " Bisec has failed !!" << "\n";
652 return 1;
653 }
654 }
655 else {
656 di << " args must be line/circle/point line/circle/point" << "\n";
657 return 1;
658 }
659 }
660 else if (ip2) {
661 if ( Type1 == STANDARD_TYPE(Geom2d_Circle)) {
662 GccAna_CircPnt2dBisec Bis
663 (Handle(Geom2d_Circle)::DownCast(C1)->Circ2d(),P2);
664 if ( Bis.IsDone()) {
665 NbSol = Bis.NbSolutions();
666 if ( NbSol >= 2) Compt = 1;
667 for ( i = 1; i <= NbSol; i++) {
668 solution(Bis.ThisSolution(i),a[1],Compt);
669 Compt++;
670 }
671 }
672 else {
673 di << " Bisec has failed !!" << "\n";
674 return 1;
675 }
676 }
677 else if ( Type1 == STANDARD_TYPE(Geom2d_Line)) {
678 GccAna_LinPnt2dBisec Bis
679 (Handle(Geom2d_Line)::DownCast(C1)->Lin2d(),P2);
680 if ( Bis.IsDone()) {
681 NbSol = 1;
682 solution(Bis.ThisSolution(),a[1],0);
683 }
684 else {
685 di << " Bisec has failed !!" << "\n";
686 return 1;
687 }
688 }
689 }
690 else {
691 di << " the second arg must be line/circle/point " << "\n";
692 }
693 }
694 else if ( ip1) {
695 if ( !C2.IsNull()) {
696 Handle(Standard_Type) Type2 = C2->DynamicType();
697 if ( Type2 == STANDARD_TYPE(Geom2d_Circle)) {
698 GccAna_CircPnt2dBisec Bis
699 (Handle(Geom2d_Circle)::DownCast(C2)->Circ2d(),P1);
700 if ( Bis.IsDone()) {
701 NbSol = Bis.NbSolutions();
702 if ( NbSol >= 2) Compt = 1;
703 for ( i = 1; i <= Bis.NbSolutions(); i++) {
704 solution(Bis.ThisSolution(i),a[1],Compt);
705 Compt++;
706 }
707 }
708 else {
709 di << " Bisec has failed !!" << "\n";
710 return 1;
711 }
712 }
713 else if ( Type2 == STANDARD_TYPE(Geom2d_Line)) {
714 GccAna_LinPnt2dBisec Bis
715 (Handle(Geom2d_Line)::DownCast(C2)->Lin2d(),P1);
716 if ( Bis.IsDone()) {
717 NbSol = 1;
718 solution(Bis.ThisSolution(),a[1],0);
719 }
720 else {
721 di << " Bisec has failed !!" << "\n";
722 return 1;
723 }
724 }
725 }
726 else if (ip2) {
727 GccAna_Pnt2dBisec Bis(P1,P2);
728 if ( Bis.HasSolution()) {
729 NbSol = 1;
730 DrawTrSurf::Set(a[1],new Geom2d_Line(Bis.ThisSolution()));
731 }
732 else {
733 di << " Bisec has failed !!" << "\n";
734 return 1;
735 }
736 }
737 else {
738 di << " the second arg must be line/circle/point " << "\n";
739 return 1;
740 }
741 }
742 else {
743 di << " args must be line/circle/point line/circle/point" << "\n";
744 return 1;
745 }
746
747 if ( NbSol >= 2) {
748 di << "There are " << NbSol << " Solutions." << "\n";
749 }
750 else {
751 di << "There is " << NbSol << " Solution." << "\n";
752 }
753
754 return 0;
755}
756
757//=======================================================================
758//function : cmovetangent
759//purpose :
760//=======================================================================
761
762static Standard_Integer movelaw (Draw_Interpretor& di, Standard_Integer n, const char** a)
763{
96a95605 764 Standard_Integer
7fd59977 765 ii,
766 condition=0,
767 error_status ;
768 Standard_Real u,
769 x,
770 tolerance,
771 tx ;
772
91322f44 773 u = Draw::Atof(a[2]);
774 x = Draw::Atof(a[3]);
7fd59977 775 tolerance = 1.0e-5 ;
7fd59977 776 if (n < 5) {
777 return 1 ;
778 }
779 Handle(Geom2d_BSplineCurve) G2 = DrawTrSurf::GetBSplineCurve2d(a[1]);
780 if (!G2.IsNull()) {
91322f44 781 tx = Draw::Atof(a[4]) ;
7fd59977 782 if (n == 6) {
91322f44 783 condition = Max(Draw::Atoi(a[5]), -1) ;
7fd59977 784 condition = Min(condition, G2->Degree()-1) ;
785 }
786 TColgp_Array1OfPnt2d curve_poles(1,G2->NbPoles()) ;
787 TColStd_Array1OfReal law_poles(1,G2->NbPoles()) ;
788 TColStd_Array1OfReal law_knots(1,G2->NbKnots()) ;
789 TColStd_Array1OfInteger law_mults(1,G2->NbKnots()) ;
790
791 G2->Knots(law_knots) ;
792 G2->Multiplicities(law_mults) ;
793 G2->Poles(curve_poles) ;
794 for (ii = 1 ; ii <= G2->NbPoles() ; ii++) {
795 law_poles(ii) = curve_poles(ii).Coord(2) ;
796 }
797
798 Law_BSpline a_law(law_poles,
799 law_knots,
800 law_mults,
801 G2->Degree(),
802 Standard_False) ;
803
804 a_law.MovePointAndTangent(u,
805 x,
806 tx,
807 tolerance,
808 condition,
809 condition,
810 error_status) ;
811
812 for (ii = 1 ; ii <= G2->NbPoles() ; ii++) {
813 curve_poles(ii).SetCoord(2,a_law.Pole(ii)) ;
814 G2->SetPole(ii,curve_poles(ii)) ;
815 }
816
817
818 if (! error_status) {
819 Draw::Repaint();
820 }
821 else {
822 di << "Not enought degree of freedom increase degree please" << "\n";
823 }
824
825
826 }
827 return 0;
828}
829
830
3492f422
PA
831//Static method computing deviation of curve and polyline
832
833static void ComputeDeviation(const Handle(Geom_Curve)& theCurve,
834 const Handle(Geom_BSplineCurve)& thePnts,
835 Standard_Real& theDmax,
836 Standard_Real& theUfMax,
837 Standard_Real& theUlMax,
838 Standard_Integer& theImax)
839{
840 theDmax = 0.;
841 theUfMax = 0.;
842 theUlMax = 0.;
843 theImax = 0;
3492f422
PA
844
845 //take knots
846 Standard_Integer nbp = thePnts->NbKnots();
847 TColStd_Array1OfReal aKnots(1, nbp);
848 thePnts->Knots(aKnots);
849
850 Standard_Integer i;
851 for(i = 1; i < nbp; ++i) {
852 Standard_Real uf = aKnots(i);
853 Standard_Real ul = aKnots(i+1);
854
855 GeomAPI_ExtremaCurveCurve ECC(theCurve, thePnts, uf, ul, uf, ul);
856
857 Standard_Integer nbe = ECC.NbExtrema();
858 if(nbe > 0) {
859 Standard_Integer k;
860 Standard_Real d = 0.;
861 for(k = 1; k <= nbe; k++) {
862 if(ECC.Distance(k) > d) d = ECC.Distance(k);
863 }
864
865 if(d > theDmax) {
866 theDmax = d;
867 theUfMax = uf;
868 theUlMax = ul;
869 theImax = i;
870 }
871 }
872 }
873}
874
875
7fd59977 876//=======================================================================
877//function : crvpoints
878//purpose :
879//=======================================================================
880
881static Standard_Integer crvpoints (Draw_Interpretor& di, Standard_Integer /*n*/, const char** a)
882{
883 Standard_Integer i, nbp;
884 Standard_Real defl;
885
886 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
91322f44 887 defl = Draw::Atof(a[3]);
7fd59977 888
889 GeomAdaptor_Curve GAC(C);
7fd59977 890 GCPnts_QuasiUniformDeflection PntGen(GAC, defl);
3492f422 891
7fd59977 892 if(!PntGen.IsDone()) {
893 di << "Points generation failed" << "\n";
894 return 1;
895 }
896
897 nbp = PntGen.NbPoints();
898 di << "Nb points : " << nbp << "\n";
899
900 TColgp_Array1OfPnt aPoles(1, nbp);
901 TColStd_Array1OfReal aKnots(1, nbp);
902 TColStd_Array1OfInteger aMults(1, nbp);
903
904 for(i = 1; i <= nbp; ++i) {
905 aPoles(i) = PntGen.Value(i);
906 aKnots(i) = PntGen.Parameter(i);
907 aMults(i) = 1;
908 }
909
910 aMults(1) = 2;
911 aMults(nbp) = 2;
912
913 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
914 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
915
916 aDrCrv->ClearPoles();
917 Draw_Color aKnColor(Draw_or);
918 aDrCrv->SetKnotsColor(aKnColor);
919 aDrCrv->SetKnotsShape(Draw_Plus);
920
921 Draw::Set(a[1], aDrCrv);
922
923 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
924 Standard_Integer imax = 0;
925
3492f422
PA
926 //check deviation
927 ComputeDeviation(C,aPnts,dmax,ufmax,ulmax,imax);
928 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << i << "\n";
7fd59977 929
3492f422
PA
930 return 0;
931}
7fd59977 932
3492f422
PA
933//=======================================================================
934//function : crvtpoints
935//purpose :
936//=======================================================================
7fd59977 937
3492f422
PA
938static Standard_Integer crvtpoints (Draw_Interpretor& di, Standard_Integer n, const char** a)
939{
940 Standard_Integer i, nbp;
941 Standard_Real defl, angle = Precision::Angular();
942
943 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
91322f44 944 defl = Draw::Atof(a[3]);
3492f422
PA
945
946 if(n > 3)
91322f44 947 angle = Draw::Atof(a[4]);
3492f422
PA
948
949 GeomAdaptor_Curve GAC(C);
950 GCPnts_TangentialDeflection PntGen(GAC, angle, defl, 2);
951
952 nbp = PntGen.NbPoints();
953 di << "Nb points : " << nbp << "\n";
954
955 TColgp_Array1OfPnt aPoles(1, nbp);
956 TColStd_Array1OfReal aKnots(1, nbp);
957 TColStd_Array1OfInteger aMults(1, nbp);
958
959 for(i = 1; i <= nbp; ++i) {
960 aPoles(i) = PntGen.Value(i);
961 aKnots(i) = PntGen.Parameter(i);
962 aMults(i) = 1;
7fd59977 963 }
3492f422
PA
964
965 aMults(1) = 2;
966 aMults(nbp) = 2;
7fd59977 967
3492f422
PA
968 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
969 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
970
971 aDrCrv->ClearPoles();
972 Draw_Color aKnColor(Draw_or);
973 aDrCrv->SetKnotsColor(aKnColor);
974 aDrCrv->SetKnotsShape(Draw_Plus);
975
976 Draw::Set(a[1], aDrCrv);
977
978 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
979 Standard_Integer imax = 0;
980
981 //check deviation
982 ComputeDeviation(C,aPnts,dmax,ufmax,ulmax,imax);
7fd59977 983 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << i << "\n";
984
985 return 0;
986}
7fd59977 987//=======================================================================
988//function : uniformAbscissa
989//purpose : epa test (TATA-06-002 (Problem with GCPnts_UniformAbscissa class)
990//=======================================================================
991static Standard_Integer uniformAbscissa (Draw_Interpretor& di, Standard_Integer n, const char** a)
992{
993 if( n != 3 )
994 return 1;
995
996 /*Handle(Geom_BSplineCurve) ellip;
997 ellip = DrawTrSurf::GetBSplineCurve(a[1]);
998 if (ellip.IsNull())
999 {
1000 di << " BSpline is NULL "<<"\n";
1001 return 1;
1002 }*/
1003
1004 Handle(Geom_Curve) ellip;
1005 ellip = DrawTrSurf::GetCurve(a[1]);
1006 if (ellip.IsNull())
1007 {
1008 di << " Curve is NULL "<<"\n";
1009 return 1;
1010 }
1011
1012 Standard_Integer nocp;
91322f44 1013 nocp = Draw::Atoi(a[2]);
7fd59977 1014 if(nocp < 2)
1015 return 1;
1016
1017
1018 //test nbPoints for Geom_Ellipse
1019
1020 try
1021 {
1022 GeomLProp_CLProps Prop(ellip,2,Precision::Intersection());
1023 Prop.SetCurve(ellip);
1024
1025 GeomAdaptor_Curve GAC(ellip);
1026 di<<"Type Of curve: "<<GAC.GetType()<<"\n";
1027 Standard_Real Tol = Precision::Confusion();
1028 Standard_Real L;
1029
1030 L = GCPnts_AbscissaPoint::Length(GAC, GAC.FirstParameter(), GAC.LastParameter(), Tol);
1031 di<<"Ellipse length = "<<L<<"\n";
1032 Standard_Real Abscissa = L/(nocp-1);
1033 di << " CUR : Abscissa " << Abscissa << "\n";
1034
1035 GCPnts_UniformAbscissa myAlgo(GAC, Abscissa, ellip->FirstParameter(), ellip->LastParameter());
1036 if ( myAlgo.IsDone() )
1037 {
1038 di << " CasCurve - nbpoints " << myAlgo.NbPoints() << "\n";
1039 for(Standard_Integer i = 1; i<= myAlgo.NbPoints(); i++ )
1040 di << i <<" points = " << myAlgo.Parameter( i ) << "\n";
1041 }
1042 }
1043
1044 catch (Standard_Failure )
1045 {
1046 di << " Standard Failure " <<"\n";
1047 }
1048 return 0;
1049}
1050
1051//=======================================================================
1052//function : EllipsUniformAbscissa
1053//purpose : epa test (TATA-06-002 (Problem with GCPnts_UniformAbscissa class)
1054//=======================================================================
1055static Standard_Integer EllipsUniformAbscissa (Draw_Interpretor& di, Standard_Integer n, const char** a)
1056{
1057 if( n != 4 )
1058 return 1;
1059
1060 Standard_Real R1;
91322f44 1061 R1 = Draw::Atof(a[1]);
7fd59977 1062 Standard_Real R2;
91322f44 1063 R2 = Draw::Atof(a[2]);
7fd59977 1064
1065 Standard_Integer nocp;
91322f44 1066 nocp = Draw::Atoi(a[3]);
7fd59977 1067 if(nocp < 2)
1068 return 1;
1069
1070 //test nbPoints for Geom_Ellipse
1071 Handle_Geom_Ellipse ellip;
1072
1073
1074 try
1075 {
1076 gp_Pnt location;
1077 location = gp_Pnt( 0.0, 0.0, 0.0);
1078 gp_Dir main_direction(0.0, 0.0, 1.0);
1079
1080 gp_Dir x_direction(1.0, 0.0, 0.0);
1081 gp_Ax2 mainaxis( location, main_direction);
1082
1083 mainaxis.SetXDirection(x_direction);
1084 ellip = new Geom_Ellipse(mainaxis,R1, R2);
1085
1086 BRepBuilderAPI_MakeEdge curve_edge(ellip);
1087 TopoDS_Edge edge_curve = curve_edge.Edge();
1088
1089 DBRep::Set("Ellipse",edge_curve);
1090 }
1091
1092 catch(Standard_Failure)
1093 {
1094 di << " Standard Failure "<<"\n";
1095 }
1096
1097 try
1098 {
1099 GeomLProp_CLProps Prop(ellip,2,Precision::Intersection());
1100 Prop.SetCurve(ellip);
1101
1102 GeomAdaptor_Curve GAC(ellip);
1103 di<<"Type Of curve: "<<GAC.GetType()<<"\n";
1104 Standard_Real Tol = Precision::Confusion();
1105 Standard_Real L;
1106
1107 L = GCPnts_AbscissaPoint::Length(GAC, GAC.FirstParameter(), GAC.LastParameter(), Tol);
1108 di<<"Ellipse length = "<<L<<"\n";
1109 Standard_Real Abscissa = L/(nocp-1);
1110 di << " CUR : Abscissa " << Abscissa << "\n";
1111
1112 GCPnts_UniformAbscissa myAlgo(GAC, Abscissa, ellip->FirstParameter(), ellip->LastParameter());
1113 if ( myAlgo.IsDone() )
1114 {
1115 di << " CasCurve - nbpoints " << myAlgo.NbPoints() << "\n";
1116 for(Standard_Integer i = 1; i<= myAlgo.NbPoints(); i++ )
1117 di << i <<" points = " << myAlgo.Parameter( i ) << "\n";
1118 }
1119 }
1120
1121 catch (Standard_Failure )
1122 {
1123 di << " Standard Failure " <<"\n";
1124 }
1125 return 0;
1126}
1127
1128//=======================================================================
1129//function : mypoints
1130//purpose :
1131//=======================================================================
1132
1133static Standard_Integer mypoints (Draw_Interpretor& di, Standard_Integer /*n*/, const char** a)
1134{
1135 Standard_Integer i, nbp;
1136 Standard_Real defl;
1137
1138 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
91322f44 1139 defl = Draw::Atof(a[3]);
7fd59977 1140 const Handle(Geom_BSplineCurve)& aBS = Handle(Geom_BSplineCurve)::DownCast(C);
1141
1142 if(aBS.IsNull()) return 1;
1143
1144 Standard_Integer ui1 = aBS->FirstUKnotIndex();
1145 Standard_Integer ui2 = aBS->LastUKnotIndex();
1146
1147 Standard_Integer nbsu = ui2-ui1+1; nbsu += (nbsu - 1) * (aBS->Degree()-1);
1148
1149 TColStd_Array1OfReal anUPars(1, nbsu);
1150 TColStd_Array1OfBoolean anUFlg(1, nbsu);
1151
1152 Standard_Integer j, k, nbi;
1153 Standard_Real t1, t2, dt;
1154
1155 //Filling of sample parameters
1156 nbi = aBS->Degree();
1157 k = 0;
1158 t1 = aBS->Knot(ui1);
1159 for(i = ui1+1; i <= ui2; ++i) {
1160 t2 = aBS->Knot(i);
1161 dt = (t2 - t1)/nbi;
1162 j = 1;
1163 do {
1164 ++k;
1165 anUPars(k) = t1;
1166 anUFlg(k) = Standard_False;
1167 t1 += dt;
1168 }
1169 while (++j <= nbi);
1170 t1 = t2;
1171 }
1172 ++k;
1173 anUPars(k) = t1;
1174
1175 Standard_Integer l;
1176 defl *= defl;
1177
1178 j = 1;
1179 anUFlg(1) = Standard_True;
1180 anUFlg(nbsu) = Standard_True;
1181 Standard_Boolean bCont = Standard_True;
1182 while (j < nbsu-1 && bCont) {
1183 t2 = anUPars(j);
1184 gp_Pnt p1 = aBS->Value(t2);
1185 for(k = j+2; k <= nbsu; ++k) {
1186 t2 = anUPars(k);
1187 gp_Pnt p2 = aBS->Value(t2);
1188 gce_MakeLin MkLin(p1, p2);
1189 const gp_Lin& lin = MkLin.Value();
1190 Standard_Boolean ok = Standard_True;
1191 for(l = j+1; l < k; ++l) {
1192 if(anUFlg(l)) continue;
1193 gp_Pnt pp = aBS->Value(anUPars(l));
1194 Standard_Real d = lin.SquareDistance(pp);
1195
1196 if(d <= defl) continue;
1197
1198 ok = Standard_False;
1199 break;
1200 }
1201
1202
1203 if(!ok) {
1204 j = k - 1;
1205 anUFlg(j) = Standard_True;
1206 break;
1207 }
1208
1209 }
1210
1211 if(k >= nbsu) bCont = Standard_False;
1212 }
1213
1214 nbp = 0;
1215 for(i = 1; i <= nbsu; ++i) {
1216 if(anUFlg(i)) nbp++;
1217 }
1218
1219 TColgp_Array1OfPnt aPoles(1, nbp);
1220 TColStd_Array1OfReal aKnots(1, nbp);
1221 TColStd_Array1OfInteger aMults(1, nbp);
1222 j = 0;
1223 for(i = 1; i <= nbsu; ++i) {
1224 if(anUFlg(i)) {
1225 ++j;
1226 aKnots(j) = anUPars(i);
1227 aMults(j) = 1;
1228 aPoles(j) = aBS->Value(aKnots(j));
1229 }
1230 }
1231
1232 aMults(1) = 2;
1233 aMults(nbp) = 2;
1234
1235 Handle(Geom_BSplineCurve) aPnts = new Geom_BSplineCurve(aPoles, aKnots, aMults, 1);
1236 Handle(DrawTrSurf_BSplineCurve) aDrCrv = new DrawTrSurf_BSplineCurve(aPnts);
1237
1238 aDrCrv->ClearPoles();
1239 Draw_Color aKnColor(Draw_or);
1240 aDrCrv->SetKnotsColor(aKnColor);
1241 aDrCrv->SetKnotsShape(Draw_Plus);
1242
1243 Draw::Set(a[1], aDrCrv);
1244
6e6cd5d9 1245 Standard_Real dmax = 0., ufmax = 0., ulmax = 0.;
7fd59977 1246 Standard_Integer imax = 0;
1247
3492f422 1248 ComputeDeviation(C,aPnts,dmax,ufmax,ulmax,imax);
7fd59977 1249 di << "Max defl: " << dmax << " " << ufmax << " " << ulmax << " " << imax << "\n";
1250
1251 return 0;
1252}
1253
1254
1255
1256//=======================================================================
1257//function : surfpoints
1258//purpose :
1259//=======================================================================
1260
1261static Standard_Integer surfpoints (Draw_Interpretor& /*di*/, Standard_Integer /*n*/, const char** a)
1262{
1263 Standard_Integer i;
1264 Standard_Real defl;
1265
1266 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[2]);
91322f44 1267 defl = Draw::Atof(a[3]);
7fd59977 1268
1269 Handle(GeomAdaptor_HSurface) AS = new GeomAdaptor_HSurface(S);
1270
1271 Handle(Adaptor3d_TopolTool) aTopTool = new Adaptor3d_TopolTool(AS);
1272
1273 aTopTool->SamplePnts(defl, 10, 10);
1274
1275 Standard_Integer nbpu = aTopTool->NbSamplesU();
1276 Standard_Integer nbpv = aTopTool->NbSamplesV();
1277 TColStd_Array1OfReal Upars(1, nbpu), Vpars(1, nbpv);
1278 aTopTool->UParameters(Upars);
1279 aTopTool->VParameters(Vpars);
1280
1281 TColgp_Array2OfPnt aPoles(1, nbpu, 1, nbpv);
1282 TColStd_Array1OfReal anUKnots(1, nbpu);
1283 TColStd_Array1OfReal aVKnots(1, nbpv);
1284 TColStd_Array1OfInteger anUMults(1, nbpu);
1285 TColStd_Array1OfInteger aVMults(1, nbpv);
1286
1287 Standard_Integer j;
1288 for(i = 1; i <= nbpu; ++i) {
1289 anUKnots(i) = Upars(i);
1290 anUMults(i) = 1;
1291 for(j = 1; j <= nbpv; ++j) {
1292 aVKnots(j) = Vpars(j);
1293 aVMults(j) = 1;
1294 aPoles(i,j) = S->Value(anUKnots(i),aVKnots(j));
1295 }
1296 }
1297
1298 anUMults(1) = 2;
1299 anUMults(nbpu) = 2;
1300 aVMults(1) = 2;
1301 aVMults(nbpv) = 2;
1302
1303 Handle(Geom_BSplineSurface) aPnts = new Geom_BSplineSurface(aPoles, anUKnots, aVKnots,
1304 anUMults, aVMults, 1, 1);
1305 Handle(DrawTrSurf_BSplineSurface) aDrSurf = new DrawTrSurf_BSplineSurface(aPnts);
1306
1307 aDrSurf->ClearPoles();
1308 Draw_Color aKnColor(Draw_or);
1309 aDrSurf->SetKnotsColor(aKnColor);
1310 aDrSurf->SetKnotsShape(Draw_Plus);
1311
1312 Draw::Set(a[1], aDrSurf);
1313
1314
1315 return 0;
1316}
1317
1318
1319
1320//=======================================================================
1321//function : intersect
1322//purpose :
1323//=======================================================================
7fd59977 1324static Standard_Integer intersection (Draw_Interpretor& di, Standard_Integer n, const char** a)
32ca7a51 1325 {
1326 if (n < 4)
c5c34473 1327 return 1;
32ca7a51 1328
c5c34473 1329 //
7fd59977 1330 Handle(Geom_Curve) GC1;
1331 Handle(Geom_Surface) GS1 = DrawTrSurf::GetSurface(a[2]);
32ca7a51 1332 if (GS1.IsNull())
1333 {
7fd59977 1334 GC1 = DrawTrSurf::GetCurve(a[2]);
1335 if (GC1.IsNull())
1336 return 1;
32ca7a51 1337 }
1338
c5c34473 1339 //
7fd59977 1340 Handle(Geom_Surface) GS2 = DrawTrSurf::GetSurface(a[3]);
32ca7a51 1341 if (GS2.IsNull())
c5c34473 1342 return 1;
32ca7a51 1343
c5c34473 1344 //
7fd59977 1345 Standard_Real tol = Precision::Confusion();
32ca7a51 1346 if (n == 5 || n == 9 || n == 13 || n == 17)
1347 tol = Draw::Atof(a[n-1]);
1348
c5c34473 1349 //
7fd59977 1350 Handle(Geom_Curve) Result;
1351 gp_Pnt Point;
32ca7a51 1352
c5c34473 1353 //
32ca7a51 1354 if (GC1.IsNull())
1355 {
c5c34473
J
1356 GeomInt_IntSS Inters;
1357 //
7fd59977 1358 // Surface Surface
32ca7a51 1359 if (n <= 5)
1360 {
7fd59977 1361 // General case
c5c34473 1362 Inters.Perform(GS1,GS2,tol,Standard_True);
32ca7a51 1363 }
1364 else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
1365 {
7fd59977 1366 Standard_Boolean useStart = Standard_True, useBnd = Standard_True;
1367 Standard_Integer ista1=0,ista2=0,ibnd1=0,ibnd2=0;
1368 Standard_Real UVsta[4];
1369 Handle(GeomAdaptor_HSurface) AS1,AS2;
32ca7a51 1370
c5c34473 1371 //
32ca7a51 1372 if (n <= 9) // user starting point
1373 {
7fd59977 1374 useBnd = Standard_False;
32ca7a51 1375 ista1 = 4;
1376 ista2 = 7;
1377 }
1378 else if (n <= 13) // user bounding
1379 {
7fd59977 1380 useStart = Standard_False;
1381 ibnd1 = 4; ibnd2 = 11;
32ca7a51 1382 }
1383 else // both user starting point and bounding
1384 {
7fd59977 1385 ista1 = 4; ista2 = 7;
1386 ibnd1 = 8; ibnd2 = 15;
32ca7a51 1387 }
1388
7fd59977 1389 if (useStart)
32ca7a51 1390 {
7fd59977 1391 for (Standard_Integer i=ista1; i <= ista2; i++)
32ca7a51 1392 {
91322f44 1393 UVsta[i-ista1] = Draw::Atof(a[i]);
32ca7a51 1394 }
1395 }
1396
1397 if (useBnd)
1398 {
7fd59977 1399 Standard_Real UVbnd[8];
1400 for (Standard_Integer i=ibnd1; i <= ibnd2; i++)
91322f44 1401 UVbnd[i-ibnd1] = Draw::Atof(a[i]);
32ca7a51 1402
7fd59977 1403 AS1 = new GeomAdaptor_HSurface(GS1,UVbnd[0],UVbnd[1],UVbnd[2],UVbnd[3]);
1404 AS2 = new GeomAdaptor_HSurface(GS2,UVbnd[4],UVbnd[5],UVbnd[6],UVbnd[7]);
32ca7a51 1405 }
1406
c5c34473 1407 //
32ca7a51 1408 if (useStart && !useBnd)
1409 {
7fd59977 1410 Inters.Perform(GS1,GS2,tol,UVsta[0],UVsta[1],UVsta[2],UVsta[3]);
32ca7a51 1411 }
1412 else if (!useStart && useBnd)
1413 {
c5c34473 1414 Inters.Perform(AS1,AS2,tol);
32ca7a51 1415 }
1416 else
1417 {
c5c34473 1418 Inters.Perform(AS1,AS2,tol,UVsta[0],UVsta[1],UVsta[2],UVsta[3]);
32ca7a51 1419 }
1420 }//else if (n == 8 || n == 9 || n == 12 || n == 13 || n == 16 || n == 17)
1421 else
1422 {
7fd59977 1423 di<<"incorrect number of arguments"<<"\n";
1424 return 1;
32ca7a51 1425 }
1426
c5c34473 1427 //
32ca7a51 1428 if (!Inters.IsDone())
1429 {
1430 di<<"No intersections found!"<<"\n";
1431
c5c34473 1432 return 1;
32ca7a51 1433 }
1434
c5c34473
J
1435 //
1436 char buf[1024];
1437 Standard_Integer i, aNbLines, aNbPoints;
32ca7a51 1438
1439 //
c5c34473 1440 aNbLines = Inters.NbLines();
32ca7a51 1441 if (aNbLines >= 2)
1442 {
1443 for (i=1; i<=aNbLines; ++i)
1444 {
1445 Sprintf(buf, "%s_%d",a[1],i);
1446 di << buf << " ";
1447 Result = Inters.Line(i);
1448 const char* temp = buf;
1449 DrawTrSurf::Set(temp,Result);
1450 }
c5c34473 1451 }
32ca7a51 1452 else if (aNbLines == 1)
1453 {
c5c34473 1454 Result = Inters.Line(1);
32ca7a51 1455 Sprintf(buf,"%s",a[1]);
1456 di << buf << " ";
c5c34473
J
1457 DrawTrSurf::Set(a[1],Result);
1458 }
32ca7a51 1459
c5c34473
J
1460 //
1461 aNbPoints=Inters.NbPoints();
32ca7a51 1462 for (i=1; i<=aNbPoints; ++i)
1463 {
c5c34473 1464 Point=Inters.Point(i);
91322f44 1465 Sprintf(buf,"%s_p_%d",a[1],i);
32ca7a51 1466 di << buf << " ";
1467 const char* temp = buf;
c5c34473 1468 DrawTrSurf::Set(temp, Point);
32ca7a51 1469 }
1470 }// if (GC1.IsNull())
1471 else
1472 {
7fd59977 1473 // Curve Surface
1474 GeomAPI_IntCS Inters(GC1,GS2);
7fd59977 1475
32ca7a51 1476 //
1477 if (!Inters.IsDone())
1478 {
1479 di<<"No intersections found!"<<"\n";
1480 return 1;
1481 }
1482
7fd59977 1483 Standard_Integer nblines = Inters.NbSegments();
1484 Standard_Integer nbpoints = Inters.NbPoints();
32ca7a51 1485
1486 char newname[1024];
1487
1488 if ( (nblines+nbpoints) >= 2)
1489 {
7fd59977 1490 Standard_Integer i;
1491 Standard_Integer Compt = 1;
32ca7a51 1492
1493 if(nblines >= 1)
1494 cout << " Lines: " << endl;
1495
1496 for (i = 1; i <= nblines; i++, Compt++)
1497 {
1498 Sprintf(newname,"%s_%d",a[1],Compt);
1499 di << newname << " ";
1500 Result = Inters.Segment(i);
1501 const char* temp = newname; // pour portage WNT
1502 DrawTrSurf::Set(temp,Result);
1503 }
1504
1505 if(nbpoints >= 1)
1506 cout << " Points: " << endl;
1507
1508 const Standard_Integer imax = nblines+nbpoints;
1509
1510 for (/*i = 1*/; i <= imax; i++, Compt++)
1511 {
1512 Sprintf(newname,"%s_%d",a[1],i);
1513 di << newname << " ";
1514 Point = Inters.Point(i);
1515 const char* temp = newname; // pour portage WNT
1516 DrawTrSurf::Set(temp,Point);
1517 }
7fd59977 1518 }
32ca7a51 1519 else if (nblines == 1)
1520 {
7fd59977 1521 Result = Inters.Segment(1);
32ca7a51 1522 Sprintf(newname,"%s",a[1]);
1523 di << newname << " ";
7fd59977 1524 DrawTrSurf::Set(a[1],Result);
32ca7a51 1525 }
1526 else if (nbpoints == 1)
1527 {
7fd59977 1528 Point = Inters.Point(1);
32ca7a51 1529 Sprintf(newname,"%s",a[1]);
1530 di << newname << " ";
7fd59977 1531 DrawTrSurf::Set(a[1],Point);
32ca7a51 1532 }
7fd59977 1533 }
7fd59977 1534
1535 dout.Flush();
1536 return 0;
32ca7a51 1537 }
7fd59977 1538
1539//=======================================================================
1540//function : CurveCommands
1541//purpose :
1542//=======================================================================
7fd59977 1543void GeometryTest::CurveCommands(Draw_Interpretor& theCommands)
1544{
1545
1546 static Standard_Boolean loaded = Standard_False;
1547 if (loaded) return;
1548 loaded = Standard_True;
1549
1550 DrawTrSurf::BasicCommands(theCommands);
1551
1552 const char* g;
1553
1554 g = "GEOMETRY curves creation";
1555
1556 theCommands.Add("law",
1557 "law name degree nbknots knot, umult value",
1558 __FILE__,
1559 polelaw,g);
1560
1561 theCommands.Add("to2d","to2d c2dname c3d [plane (XOY)]",
1562 __FILE__,
1563 to2d,g);
1564
1565 theCommands.Add("to3d","to3d c3dname c2d [plane (XOY)]",
1566 __FILE__,
1567 to3d,g);
1568
1569 theCommands.Add("gproject",
1570 "gproject : [projectname] curve surface",
1571 __FILE__,
1572 gproject,g);
1573
1574 theCommands.Add("project",
1575 "project : no args to have help",
1576 __FILE__,
1577 project,g);
1578
1579 theCommands.Add("projonplane",
1580 "projonplane r C3d Plane [dx dy dz] [0/1]",
1581 projonplane);
1582
1583 theCommands.Add("bisec",
1584 "bisec result line/circle/point line/circle/point",
1585 __FILE__,
1586 bisec, g);
1587
1588 g = "GEOMETRY Curves and Surfaces modification";
1589
1590
1591 theCommands.Add("movelaw",
1592 "movelaw name u x tx [ constraint = 0]",
1593 __FILE__,
1594 movelaw,g) ;
1595
1596
1597
1598 g = "GEOMETRY intersections";
1599
1600 theCommands.Add("intersect",
1601 "intersect result surf1/curv1 surf2 [tolerance]\n\t\t "
1602 "intersect result surf1 surf2 [u1 v1 u2 v2] [U1F U1L V1F V1L U2F U2L V2F V2L] [tolerance]",
1603 __FILE__,
1604 intersection,g);
1605
1606 theCommands.Add("crvpoints",
1607 "crvpoints result curv deflection",
1608 __FILE__,
1609 crvpoints,g);
3492f422
PA
1610
1611 theCommands.Add("crvtpoints",
1612 "crvtpoints result curv deflection angular deflection - tangential deflection points",
1613 __FILE__,
1614 crvtpoints,g);
7fd59977 1615
1616 theCommands.Add("uniformAbscissa",
1617 "uniformAbscissa Curve nbPnt",
1618 __FILE__,
1619 uniformAbscissa,g);
1620
1621 theCommands.Add("uniformAbscissaEl",
1622 "uniformAbscissaEl maxR minR nbPnt",
1623 __FILE__, EllipsUniformAbscissa,g);
1624
1625 theCommands.Add("mypoints",
1626 "mypoints result curv deflection",
1627 __FILE__,
1628 mypoints,g);
1629 theCommands.Add("surfpoints",
1630 "surfoints result surf deflection",
1631 __FILE__,
1632 surfpoints,g);
1633
1634}
1635