1 // Created on: 1994-09-21
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272
26 #include <GeomProjLib.ixx>
28 #include <ProjLib_ProjectedCurve.hxx>
29 #include <ProjLib_CompProjectedCurve.hxx>
30 #include <ProjLib_ProjectOnPlane.hxx>
31 #include <ProjLib_ProjectOnSurface.hxx>
33 #include <Approx_CurveOnSurface.hxx>
35 #include <GeomAdaptor_Curve.hxx>
36 #include <GeomAdaptor_Surface.hxx>
37 #include <GeomAdaptor_HCurve.hxx>
38 #include <GeomAdaptor_HSurface.hxx>
40 #include <Geom_Line.hxx>
41 #include <Geom_Circle.hxx>
42 #include <Geom_Ellipse.hxx>
43 #include <Geom_Parabola.hxx>
44 #include <Geom_Hyperbola.hxx>
45 #include <Geom_BezierCurve.hxx>
46 #include <Geom_BSplineCurve.hxx>
47 #include <Geom_TrimmedCurve.hxx>
48 #include <Geom2d_Line.hxx>
49 #include <Geom2d_Circle.hxx>
50 #include <Geom2d_Ellipse.hxx>
51 #include <Geom2d_Parabola.hxx>
52 #include <Geom2d_Hyperbola.hxx>
53 #include <Geom2d_BezierCurve.hxx>
54 #include <Geom2d_BSplineCurve.hxx>
55 #include <Geom2d_TrimmedCurve.hxx>
59 #include <Precision.hxx>
60 #include <TColStd_Array1OfReal.hxx>
61 #include <TColStd_Array1OfInteger.hxx>
62 #include <TColgp_Array1OfPnt.hxx>
63 #include <TColgp_Array1OfPnt2d.hxx>
66 #include <DrawTrSurf.hxx>
69 static Standard_Boolean Affich = Standard_False;
70 static Standard_Integer NBPROJ = 1;
74 //=======================================================================
77 //=======================================================================
79 Handle(Geom2d_Curve) GeomProjLib::Curve2d(const Handle(Geom_Curve)& C,
80 const Standard_Real First,
81 const Standard_Real Last,
82 const Handle(Geom_Surface)& S,
83 const Standard_Real UDeb,
84 const Standard_Real UFin,
85 const Standard_Real VDeb,
86 const Standard_Real VFin,
87 Standard_Real& Tolerance)
93 char* name = new char[100];
94 sprintf(name,"PROJCURV_%d",NBPROJ);
95 DrawTrSurf::Set(name,C);
96 sprintf(name,"PROJSURF_%d",NBPROJ);
97 DrawTrSurf::Set(name,S);
102 Tolerance = Max(Precision::PConfusion(),Tolerance);
104 GeomAdaptor_Curve AC(C,First,Last);
105 GeomAdaptor_Surface AS(S,
111 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(AS);
112 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
114 ProjLib_ProjectedCurve Proj(HS,HC,Tolerance);
116 Handle(Geom2d_Curve) G2dC;
118 switch ( Proj.GetType()) {
121 G2dC = new Geom2d_Line(Proj.Line());
125 G2dC = new Geom2d_Circle(Proj.Circle());
128 case GeomAbs_Ellipse:
129 G2dC = new Geom2d_Ellipse(Proj.Ellipse());
132 case GeomAbs_Parabola:
133 G2dC = new Geom2d_Parabola(Proj.Parabola());
136 case GeomAbs_Hyperbola:
137 G2dC = new Geom2d_Hyperbola(Proj.Hyperbola());
140 case GeomAbs_BezierCurve:
141 G2dC = Proj.Bezier();
144 case GeomAbs_BSplineCurve:
145 G2dC = Proj.BSpline();
154 Tolerance = Proj.GetTolerance();
158 if ( C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)) ) {
159 Handle(Geom_TrimmedCurve) CTrim = Handle(Geom_TrimmedCurve)::DownCast(C);
160 Standard_Real U1 = CTrim->FirstParameter();
161 Standard_Real U2 = CTrim->LastParameter();
162 G2dC = new Geom2d_TrimmedCurve( G2dC, U1, U2);
167 static Standard_CString aprojcurv = "projcurv" ;
168 DrawTrSurf::Set(aprojcurv,G2dC);
171 Tolerance = Proj.GetTolerance();
175 //=======================================================================
178 //=======================================================================
180 Handle(Geom2d_Curve) GeomProjLib::Curve2d(const Handle(Geom_Curve)& C,
181 const Standard_Real First,
182 const Standard_Real Last,
183 const Handle(Geom_Surface)& S,
184 Standard_Real& Tolerance)
186 Standard_Real UFirst,
205 // Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272 Begin
206 // Add not implemented method.
207 //=======================================================================
210 //=======================================================================
212 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
213 const Handle(Geom_Surface)& S,
214 const Standard_Real UDeb,
215 const Standard_Real UFin,
216 const Standard_Real VDeb,
217 const Standard_Real VFin)
219 Standard_Real First = C->FirstParameter();
220 Standard_Real Last = C->LastParameter();
221 Standard_Real Tol = Precision::PConfusion();
222 return GeomProjLib::Curve2d(C,First,Last,S,UDeb,UFin,VDeb,VFin,Tol);
224 // Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272 End
226 //=======================================================================
229 //=======================================================================
231 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
232 const Handle(Geom_Surface)& S,
233 const Standard_Real UDeb,
234 const Standard_Real UFin,
235 const Standard_Real VDeb,
236 const Standard_Real VFin,
237 Standard_Real& Tolerance)
239 Standard_Real First = C->FirstParameter();
240 Standard_Real Last = C->LastParameter();
241 return GeomProjLib::Curve2d(C,First,Last,S,UDeb,UFin,VDeb,VFin,Tolerance);
245 //=======================================================================
248 //=======================================================================
250 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
251 const Handle(Geom_Surface)& S)
253 Standard_Real First = C->FirstParameter();
254 Standard_Real Last = C->LastParameter();
255 Standard_Real Tol = Precision::PConfusion();
256 return GeomProjLib::Curve2d(C,First,Last,S,Tol);
260 //=======================================================================
263 //=======================================================================
265 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
266 const Standard_Real First,
267 const Standard_Real Last,
268 const Handle(Geom_Surface)& S)
270 Standard_Real Tol = Precision::PConfusion();
271 return GeomProjLib::Curve2d(C,First,Last,S,Tol);
275 //=======================================================================
278 //=======================================================================
280 Handle(Geom_Curve) GeomProjLib::Project( const Handle(Geom_Curve)& C,
281 const Handle(Geom_Surface)& S)
283 GeomAdaptor_Curve AC(C);
284 GeomAdaptor_Surface AS(S);
286 Handle(Geom_Curve) GC;
288 if ( AS.GetType() == GeomAbs_Plane) {
289 ProjLib_ProjectOnPlane Proj( AS.Plane().Position());
290 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
291 Proj.Load(HC,Precision::PApproximation());
293 switch ( Proj.GetType()) {
295 GC = new Geom_Line(Proj.Line());
299 GC = new Geom_Circle(Proj.Circle());
302 case GeomAbs_Ellipse:
303 GC = new Geom_Ellipse(Proj.Ellipse());
306 case GeomAbs_Parabola:
307 GC = new Geom_Parabola(Proj.Parabola());
310 case GeomAbs_Hyperbola:
311 GC = new Geom_Hyperbola(Proj.Hyperbola());
314 case GeomAbs_BezierCurve:
318 case GeomAbs_BSplineCurve:
327 if ( C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
328 Handle(Geom_TrimmedCurve) CTrim = Handle(Geom_TrimmedCurve)::DownCast(C);
329 Standard_Real U1 = CTrim->FirstParameter();
330 Standard_Real U2 = CTrim->LastParameter();
331 GC = new Geom_TrimmedCurve( GC, U1, U2);
336 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(AS);
337 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
338 // Standard_Real Tol = Precision::Approximation();
339 // Standard_Real TolU = Precision::PApproximation();
340 // Standard_Real TolV = Precision::PApproximation();
341 Standard_Real Tol = 0.0001;
342 Standard_Real TolU = Pow(Tol, 2./3);
343 Standard_Real TolV = Pow(Tol, 2./3);
344 ProjLib_CompProjectedCurve Proj(HS,HC,TolU,TolV,-1.);
348 Handle(Adaptor2d_HCurve2d) HC2d = Proj.Trim(f,l,TolU);
349 Approx_CurveOnSurface Approx(HC2d, HS, f, l, Tol,
350 GeomAbs_C2,14,16,Standard_True);
352 // ici, on a toujours un type BSpline.
353 if (Approx.IsDone() && Approx.HasResult())
354 GC = Approx.Curve3d();
360 //=======================================================================
361 //function : ProjectOnPlane
363 //=======================================================================
365 Handle(Geom_Curve) GeomProjLib::ProjectOnPlane
366 (const Handle(Geom_Curve)& Curve,
367 const Handle(Geom_Plane)& Plane,
369 const Standard_Boolean KeepParametrization)
371 GeomAdaptor_Curve AC(Curve);
372 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
374 ProjLib_ProjectOnPlane Proj(Plane->Position(), Dir);
375 Proj.Load(HC,Precision::Approximation(), KeepParametrization);
377 Handle(Geom_Curve) GC;
379 switch ( Proj.GetType()) {
381 GC = new Geom_Line(Proj.Line());
385 GC = new Geom_Circle(Proj.Circle());
388 case GeomAbs_Ellipse:
389 GC = new Geom_Ellipse(Proj.Ellipse());
392 case GeomAbs_Parabola:
393 GC = new Geom_Parabola(Proj.Parabola());
396 case GeomAbs_Hyperbola:
397 GC = new Geom_Hyperbola(Proj.Hyperbola());
400 case GeomAbs_BezierCurve:
404 case GeomAbs_BSplineCurve:
412 if ( Curve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)) ) {
413 Handle(Geom_TrimmedCurve) CTrim
414 = Handle(Geom_TrimmedCurve)::DownCast(Curve);
415 GC = new Geom_TrimmedCurve( GC, Proj.FirstParameter(),
416 Proj.LastParameter());