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