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