0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / GeomProjLib / GeomProjLib.cxx
CommitLineData
7fd59977 1// File: GeomProjLib.cxx
2// Created: Wed Sep 21 10:38:50 1994
3// Author: Bruno DUMORTIER
4// <dub@fuegox>
5
6// Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272
7
8#include <stdio.h>
9
10#include <GeomProjLib.ixx>
11
12#include <ProjLib_ProjectedCurve.hxx>
13#include <ProjLib_CompProjectedCurve.hxx>
14#include <ProjLib_ProjectOnPlane.hxx>
15#include <ProjLib_ProjectOnSurface.hxx>
16
17#include <Approx_CurveOnSurface.hxx>
18
19#include <GeomAdaptor_Curve.hxx>
20#include <GeomAdaptor_Surface.hxx>
21#include <GeomAdaptor_HCurve.hxx>
22#include <GeomAdaptor_HSurface.hxx>
23
24#include <Geom_Line.hxx>
25#include <Geom_Circle.hxx>
26#include <Geom_Ellipse.hxx>
27#include <Geom_Parabola.hxx>
28#include <Geom_Hyperbola.hxx>
29#include <Geom_BezierCurve.hxx>
30#include <Geom_BSplineCurve.hxx>
31#include <Geom_TrimmedCurve.hxx>
32#include <Geom2d_Line.hxx>
33#include <Geom2d_Circle.hxx>
34#include <Geom2d_Ellipse.hxx>
35#include <Geom2d_Parabola.hxx>
36#include <Geom2d_Hyperbola.hxx>
37#include <Geom2d_BezierCurve.hxx>
38#include <Geom2d_BSplineCurve.hxx>
39#include <Geom2d_TrimmedCurve.hxx>
40
41#include <gp_Pln.hxx>
42
43#include <Precision.hxx>
44#include <TColStd_Array1OfReal.hxx>
45#include <TColStd_Array1OfInteger.hxx>
46#include <TColgp_Array1OfPnt.hxx>
47#include <TColgp_Array1OfPnt2d.hxx>
48
49#ifdef DRAW
50#include <DrawTrSurf.hxx>
51#endif
52#ifdef DEB
53static Standard_Boolean Affich = Standard_False;
54static Standard_Integer NBPROJ = 1;
55#endif
56
57
58//=======================================================================
59//function : Curve2d
60//purpose :
61//=======================================================================
62
63Handle(Geom2d_Curve) GeomProjLib::Curve2d(const Handle(Geom_Curve)& C,
64 const Standard_Real First,
65 const Standard_Real Last,
66 const Handle(Geom_Surface)& S,
67 const Standard_Real UDeb,
68 const Standard_Real UFin,
69 const Standard_Real VDeb,
70 const Standard_Real VFin,
71 Standard_Real& Tolerance)
72{
73#ifdef DRAW
74 if ( Affich) {
75//POP pour NT
76// char name[100];
77 char* name = new char[100];
78 sprintf(name,"PROJCURV_%d",NBPROJ);
79 DrawTrSurf::Set(name,C);
80 sprintf(name,"PROJSURF_%d",NBPROJ);
81 DrawTrSurf::Set(name,S);
82 NBPROJ++;
83 }
84#endif
85
86 Tolerance = Max(Precision::PConfusion(),Tolerance);
87
88 GeomAdaptor_Curve AC(C,First,Last);
89 GeomAdaptor_Surface AS(S,
90 UDeb,
91 UFin,
92 VDeb,
93 VFin);
94
95 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(AS);
96 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
97
98 ProjLib_ProjectedCurve Proj(HS,HC,Tolerance);
99
100 Handle(Geom2d_Curve) G2dC;
101
102 switch ( Proj.GetType()) {
103
104 case GeomAbs_Line:
105 G2dC = new Geom2d_Line(Proj.Line());
106 break;
107
108 case GeomAbs_Circle:
109 G2dC = new Geom2d_Circle(Proj.Circle());
110 break;
111
112 case GeomAbs_Ellipse:
113 G2dC = new Geom2d_Ellipse(Proj.Ellipse());
114 break;
115
116 case GeomAbs_Parabola:
117 G2dC = new Geom2d_Parabola(Proj.Parabola());
118 break;
119
120 case GeomAbs_Hyperbola:
121 G2dC = new Geom2d_Hyperbola(Proj.Hyperbola());
122 break;
123
124 case GeomAbs_BezierCurve:
125 G2dC = Proj.Bezier();
126 break;
127
128 case GeomAbs_BSplineCurve:
129 G2dC = Proj.BSpline();
130 break;
131
132 default:
133 return G2dC;
134
135 }
136
137 if(G2dC.IsNull()) {
138 Tolerance = Proj.GetTolerance();
139 return G2dC;
140 }
141
142 if ( C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)) ) {
143 Handle(Geom_TrimmedCurve) CTrim = Handle(Geom_TrimmedCurve)::DownCast(C);
144 Standard_Real U1 = CTrim->FirstParameter();
145 Standard_Real U2 = CTrim->LastParameter();
146 G2dC = new Geom2d_TrimmedCurve( G2dC, U1, U2);
147 }
148
149#ifdef DRAW
150 if ( Affich) {
151 static Standard_CString aprojcurv = "projcurv" ;
152 DrawTrSurf::Set(aprojcurv,G2dC);
153 }
154#endif
155 Tolerance = Proj.GetTolerance();
156 return G2dC;
157}
158
159//=======================================================================
160//function : Curve2d
161//purpose :
162//=======================================================================
163
164Handle(Geom2d_Curve) GeomProjLib::Curve2d(const Handle(Geom_Curve)& C,
165 const Standard_Real First,
166 const Standard_Real Last,
167 const Handle(Geom_Surface)& S,
168 Standard_Real& Tolerance)
169{
170 Standard_Real UFirst,
171 ULast,
172 VFirst,
173 VLast ;
174
175 S->Bounds(UFirst,
176 ULast,
177 VFirst,
178 VLast) ;
179 return Curve2d(C,
180 First,
181 Last,
182 S,
183 UFirst,
184 ULast,
185 VFirst,
186 VLast,
187 Tolerance) ;
188}
189// Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272 Begin
190// Add not implemented method.
191//=======================================================================
192//function : Curve2d
193//purpose :
194//=======================================================================
195
196Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
197 const Handle(Geom_Surface)& S,
198 const Standard_Real UDeb,
199 const Standard_Real UFin,
200 const Standard_Real VDeb,
201 const Standard_Real VFin)
202{
203 Standard_Real First = C->FirstParameter();
204 Standard_Real Last = C->LastParameter();
205 Standard_Real Tol = Precision::PConfusion();
206 return GeomProjLib::Curve2d(C,First,Last,S,UDeb,UFin,VDeb,VFin,Tol);
207}
208// Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272 End
209
210//=======================================================================
211//function : Curve2d
212//purpose :
213//=======================================================================
214
215Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
216 const Handle(Geom_Surface)& S,
217 const Standard_Real UDeb,
218 const Standard_Real UFin,
219 const Standard_Real VDeb,
220 const Standard_Real VFin,
221 Standard_Real& Tolerance)
222{
223 Standard_Real First = C->FirstParameter();
224 Standard_Real Last = C->LastParameter();
225 return GeomProjLib::Curve2d(C,First,Last,S,UDeb,UFin,VDeb,VFin,Tolerance);
226}
227
228
229//=======================================================================
230//function : Curve2d
231//purpose :
232//=======================================================================
233
234Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
235 const Handle(Geom_Surface)& S)
236{
237 Standard_Real First = C->FirstParameter();
238 Standard_Real Last = C->LastParameter();
239 Standard_Real Tol = Precision::PConfusion();
240 return GeomProjLib::Curve2d(C,First,Last,S,Tol);
241}
242
243
244//=======================================================================
245//function : Curve2d
246//purpose :
247//=======================================================================
248
249Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
250 const Standard_Real First,
251 const Standard_Real Last,
252 const Handle(Geom_Surface)& S)
253{
254 Standard_Real Tol = Precision::PConfusion();
255 return GeomProjLib::Curve2d(C,First,Last,S,Tol);
256}
257
258
259//=======================================================================
260//function : Project
261//purpose :
262//=======================================================================
263
264Handle(Geom_Curve) GeomProjLib::Project( const Handle(Geom_Curve)& C,
265 const Handle(Geom_Surface)& S)
266{
267 GeomAdaptor_Curve AC(C);
268 GeomAdaptor_Surface AS(S);
269
270 Handle(Geom_Curve) GC;
271
272 if ( AS.GetType() == GeomAbs_Plane) {
273 ProjLib_ProjectOnPlane Proj( AS.Plane().Position());
274 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
275 Proj.Load(HC,Precision::PApproximation());
276
277 switch ( Proj.GetType()) {
278 case GeomAbs_Line:
279 GC = new Geom_Line(Proj.Line());
280 break;
281
282 case GeomAbs_Circle:
283 GC = new Geom_Circle(Proj.Circle());
284 break;
285
286 case GeomAbs_Ellipse:
287 GC = new Geom_Ellipse(Proj.Ellipse());
288 break;
289
290 case GeomAbs_Parabola:
291 GC = new Geom_Parabola(Proj.Parabola());
292 break;
293
294 case GeomAbs_Hyperbola:
295 GC = new Geom_Hyperbola(Proj.Hyperbola());
296 break;
297
298 case GeomAbs_BezierCurve:
299 GC = Proj.Bezier();
300 break;
301
302 case GeomAbs_BSplineCurve:
303 GC = Proj.BSpline();
304 break;
305
306 default:
307 return GC;
308
309 }
310
311 if ( C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
312 Handle(Geom_TrimmedCurve) CTrim = Handle(Geom_TrimmedCurve)::DownCast(C);
313 Standard_Real U1 = CTrim->FirstParameter();
314 Standard_Real U2 = CTrim->LastParameter();
315 GC = new Geom_TrimmedCurve( GC, U1, U2);
316 }
317
318 }
319 else {
320 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(AS);
321 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
322// Standard_Real Tol = Precision::Approximation();
323// Standard_Real TolU = Precision::PApproximation();
324// Standard_Real TolV = Precision::PApproximation();
325 Standard_Real Tol = 0.0001;
326 Standard_Real TolU = Pow(Tol, 2./3);
327 Standard_Real TolV = Pow(Tol, 2./3);
328 ProjLib_CompProjectedCurve Proj(HS,HC,TolU,TolV,-1.);
329
7fd59977 330 Standard_Real f,l;
331 Proj.Bounds(1,f,l);
332 Handle(Adaptor2d_HCurve2d) HC2d = Proj.Trim(f,l,TolU);
333 Approx_CurveOnSurface Approx(HC2d, HS, f, l, Tol,
334 GeomAbs_C2,14,16,Standard_True);
335
336 // ici, on a toujours un type BSpline.
337 if (Approx.IsDone() && Approx.HasResult())
338 GC = Approx.Curve3d();
339 }
340
341 return GC;
342}
343
344//=======================================================================
345//function : ProjectOnPlane
346//purpose :
347//=======================================================================
348
349Handle(Geom_Curve) GeomProjLib::ProjectOnPlane
350(const Handle(Geom_Curve)& Curve,
351 const Handle(Geom_Plane)& Plane,
352 const gp_Dir& Dir,
353 const Standard_Boolean KeepParametrization)
354{
355 GeomAdaptor_Curve AC(Curve);
356 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
357
358 ProjLib_ProjectOnPlane Proj(Plane->Position(), Dir);
359 Proj.Load(HC,Precision::Approximation(), KeepParametrization);
360
361 Handle(Geom_Curve) GC;
362
363 switch ( Proj.GetType()) {
364 case GeomAbs_Line:
365 GC = new Geom_Line(Proj.Line());
366 break;
367
368 case GeomAbs_Circle:
369 GC = new Geom_Circle(Proj.Circle());
370 break;
371
372 case GeomAbs_Ellipse:
373 GC = new Geom_Ellipse(Proj.Ellipse());
374 break;
375
376 case GeomAbs_Parabola:
377 GC = new Geom_Parabola(Proj.Parabola());
378 break;
379
380 case GeomAbs_Hyperbola:
381 GC = new Geom_Hyperbola(Proj.Hyperbola());
382 break;
383
384 case GeomAbs_BezierCurve:
385 GC = Proj.Bezier();
386 break;
387
388 case GeomAbs_BSplineCurve:
389 GC = Proj.BSpline();
390 break;
391 default:
392 return GC;
393
394 }
395
396 if ( Curve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)) ) {
397 Handle(Geom_TrimmedCurve) CTrim
398 = Handle(Geom_TrimmedCurve)::DownCast(Curve);
399 GC = new Geom_TrimmedCurve( GC, Proj.FirstParameter(),
400 Proj.LastParameter());
401 }
402
403 return GC;
404
405}
406
407