1 // Created on: 1994-09-21
2 // Created by: Bruno DUMORTIER
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272
19 #include <Approx_CurveOnSurface.hxx>
20 #include <Geom2d_BezierCurve.hxx>
21 #include <Geom2d_BSplineCurve.hxx>
22 #include <Geom2d_Circle.hxx>
23 #include <Geom2d_Curve.hxx>
24 #include <Geom2d_Ellipse.hxx>
25 #include <Geom2d_Hyperbola.hxx>
26 #include <Geom2d_Line.hxx>
27 #include <Geom2d_Parabola.hxx>
28 #include <Geom2d_TrimmedCurve.hxx>
29 #include <Geom_BezierCurve.hxx>
30 #include <Geom_BSplineCurve.hxx>
31 #include <Geom_Circle.hxx>
32 #include <Geom_Curve.hxx>
33 #include <Geom_Ellipse.hxx>
34 #include <Geom_Hyperbola.hxx>
35 #include <Geom_Line.hxx>
36 #include <Geom_Parabola.hxx>
37 #include <Geom_Plane.hxx>
38 #include <Geom_Surface.hxx>
39 #include <Geom_TrimmedCurve.hxx>
40 #include <GeomAdaptor_Curve.hxx>
41 #include <GeomAdaptor_HCurve.hxx>
42 #include <GeomAdaptor_HSurface.hxx>
43 #include <GeomAdaptor_Surface.hxx>
44 #include <GeomProjLib.hxx>
47 #include <Precision.hxx>
48 #include <ProjLib_CompProjectedCurve.hxx>
49 #include <ProjLib_ProjectedCurve.hxx>
50 #include <ProjLib_ProjectOnPlane.hxx>
51 #include <ProjLib_ProjectOnSurface.hxx>
52 #include <TColgp_Array1OfPnt.hxx>
53 #include <TColgp_Array1OfPnt2d.hxx>
54 #include <TColStd_Array1OfInteger.hxx>
55 #include <TColStd_Array1OfReal.hxx>
59 #include <DrawTrSurf.hxx>
60 static Standard_Boolean Affich = Standard_False;
61 static Standard_Integer NBPROJ = 1;
65 //=======================================================================
68 //=======================================================================
70 Handle(Geom2d_Curve) GeomProjLib::Curve2d(const Handle(Geom_Curve)& C,
71 const Standard_Real First,
72 const Standard_Real Last,
73 const Handle(Geom_Surface)& S,
74 const Standard_Real UDeb,
75 const Standard_Real UFin,
76 const Standard_Real VDeb,
77 const Standard_Real VFin,
78 Standard_Real& Tolerance)
83 Sprintf(name,"PROJCURV_%d",NBPROJ);
84 DrawTrSurf::Set(name,C);
85 Sprintf(name,"PROJSURF_%d",NBPROJ);
86 DrawTrSurf::Set(name,S);
91 Tolerance = Max(Precision::PConfusion(),Tolerance);
93 GeomAdaptor_Curve AC(C,First,Last);
94 GeomAdaptor_Surface AS(S,
100 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(AS);
101 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
103 ProjLib_ProjectedCurve Proj(HS,HC,Tolerance);
105 Handle(Geom2d_Curve) G2dC;
107 switch ( Proj.GetType()) {
110 G2dC = new Geom2d_Line(Proj.Line());
114 G2dC = new Geom2d_Circle(Proj.Circle());
117 case GeomAbs_Ellipse:
118 G2dC = new Geom2d_Ellipse(Proj.Ellipse());
121 case GeomAbs_Parabola:
122 G2dC = new Geom2d_Parabola(Proj.Parabola());
125 case GeomAbs_Hyperbola:
126 G2dC = new Geom2d_Hyperbola(Proj.Hyperbola());
129 case GeomAbs_BezierCurve:
130 G2dC = Proj.Bezier();
133 case GeomAbs_BSplineCurve:
134 G2dC = Proj.BSpline();
143 Tolerance = Proj.GetTolerance();
147 if ( C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)) ) {
148 Handle(Geom_TrimmedCurve) CTrim = Handle(Geom_TrimmedCurve)::DownCast(C);
149 Standard_Real U1 = CTrim->FirstParameter();
150 Standard_Real U2 = CTrim->LastParameter();
151 if (!G2dC->IsPeriodic())
153 U1 = Max(U1, G2dC->FirstParameter());
154 U2 = Min(U2, G2dC->LastParameter());
156 G2dC = new Geom2d_TrimmedCurve( G2dC, U1, U2);
161 static Standard_CString aprojcurv = "projcurv" ;
162 DrawTrSurf::Set(aprojcurv,G2dC);
165 Tolerance = Proj.GetTolerance();
169 //=======================================================================
172 //=======================================================================
174 Handle(Geom2d_Curve) GeomProjLib::Curve2d(const Handle(Geom_Curve)& C,
175 const Standard_Real First,
176 const Standard_Real Last,
177 const Handle(Geom_Surface)& S,
178 Standard_Real& Tolerance)
180 Standard_Real UFirst,
199 // Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272 Begin
200 // Add not implemented method.
201 //=======================================================================
204 //=======================================================================
206 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
207 const Handle(Geom_Surface)& S,
208 const Standard_Real UDeb,
209 const Standard_Real UFin,
210 const Standard_Real VDeb,
211 const Standard_Real VFin)
213 Standard_Real First = C->FirstParameter();
214 Standard_Real Last = C->LastParameter();
215 Standard_Real Tol = Precision::PConfusion();
216 return GeomProjLib::Curve2d(C,First,Last,S,UDeb,UFin,VDeb,VFin,Tol);
218 // Modified by skv - Wed Aug 11 17:26:03 2004 OCC6272 End
220 //=======================================================================
223 //=======================================================================
225 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
226 const Handle(Geom_Surface)& S,
227 const Standard_Real UDeb,
228 const Standard_Real UFin,
229 const Standard_Real VDeb,
230 const Standard_Real VFin,
231 Standard_Real& Tolerance)
233 Standard_Real First = C->FirstParameter();
234 Standard_Real Last = C->LastParameter();
235 return GeomProjLib::Curve2d(C,First,Last,S,UDeb,UFin,VDeb,VFin,Tolerance);
239 //=======================================================================
242 //=======================================================================
244 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
245 const Handle(Geom_Surface)& S)
247 Standard_Real First = C->FirstParameter();
248 Standard_Real Last = C->LastParameter();
249 Standard_Real Tol = Precision::PConfusion();
250 return GeomProjLib::Curve2d(C,First,Last,S,Tol);
254 //=======================================================================
257 //=======================================================================
259 Handle(Geom2d_Curve) GeomProjLib::Curve2d( const Handle(Geom_Curve)& C,
260 const Standard_Real First,
261 const Standard_Real Last,
262 const Handle(Geom_Surface)& S)
264 Standard_Real Tol = Precision::PConfusion();
265 return GeomProjLib::Curve2d(C,First,Last,S,Tol);
269 //=======================================================================
272 //=======================================================================
274 Handle(Geom_Curve) GeomProjLib::Project( const Handle(Geom_Curve)& C,
275 const Handle(Geom_Surface)& S)
277 GeomAdaptor_Curve AC(C);
278 GeomAdaptor_Surface AS(S);
280 Handle(Geom_Curve) GC;
282 if ( AS.GetType() == GeomAbs_Plane) {
283 ProjLib_ProjectOnPlane Proj( AS.Plane().Position());
284 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
285 Proj.Load(HC,Precision::PApproximation());
287 switch ( Proj.GetType()) {
289 GC = new Geom_Line(Proj.Line());
293 GC = new Geom_Circle(Proj.Circle());
296 case GeomAbs_Ellipse:
297 GC = new Geom_Ellipse(Proj.Ellipse());
300 case GeomAbs_Parabola:
301 GC = new Geom_Parabola(Proj.Parabola());
304 case GeomAbs_Hyperbola:
305 GC = new Geom_Hyperbola(Proj.Hyperbola());
308 case GeomAbs_BezierCurve:
312 case GeomAbs_BSplineCurve:
321 if ( C->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
322 Handle(Geom_TrimmedCurve) CTrim = Handle(Geom_TrimmedCurve)::DownCast(C);
323 Standard_Real U1 = CTrim->FirstParameter();
324 Standard_Real U2 = CTrim->LastParameter();
325 GC = new Geom_TrimmedCurve( GC, U1, U2);
330 Handle(GeomAdaptor_HSurface) HS = new GeomAdaptor_HSurface(AS);
331 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
332 // Standard_Real Tol = Precision::Approximation();
333 // Standard_Real TolU = Precision::PApproximation();
334 // Standard_Real TolV = Precision::PApproximation();
335 Standard_Real Tol = 0.0001;
336 Standard_Real TolU = Pow(Tol, 2./3);
337 Standard_Real TolV = Pow(Tol, 2./3);
338 ProjLib_CompProjectedCurve Proj(HS,HC,TolU,TolV,-1.);
342 Handle(Adaptor2d_HCurve2d) HC2d = Proj.Trim(f,l,TolU);
343 Approx_CurveOnSurface Approx(HC2d, HS, f, l, Tol,
344 GeomAbs_C2,14,16,Standard_True);
346 // ici, on a toujours un type BSpline.
347 if (Approx.IsDone() && Approx.HasResult())
348 GC = Approx.Curve3d();
354 //=======================================================================
355 //function : ProjectOnPlane
357 //=======================================================================
359 Handle(Geom_Curve) GeomProjLib::ProjectOnPlane
360 (const Handle(Geom_Curve)& Curve,
361 const Handle(Geom_Plane)& Plane,
363 const Standard_Boolean KeepParametrization)
365 GeomAdaptor_Curve AC(Curve);
366 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve(AC);
368 ProjLib_ProjectOnPlane Proj(Plane->Position(), Dir);
369 Proj.Load(HC,Precision::Approximation(), KeepParametrization);
371 Handle(Geom_Curve) GC;
373 switch ( Proj.GetType()) {
375 GC = new Geom_Line(Proj.Line());
379 GC = new Geom_Circle(Proj.Circle());
382 case GeomAbs_Ellipse:
383 GC = new Geom_Ellipse(Proj.Ellipse());
386 case GeomAbs_Parabola:
387 GC = new Geom_Parabola(Proj.Parabola());
390 case GeomAbs_Hyperbola:
391 GC = new Geom_Hyperbola(Proj.Hyperbola());
394 case GeomAbs_BezierCurve:
398 case GeomAbs_BSplineCurve:
406 if ( Curve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve)) ) {
407 Handle(Geom_TrimmedCurve) CTrim
408 = Handle(Geom_TrimmedCurve)::DownCast(Curve);
409 GC = new Geom_TrimmedCurve( GC, Proj.FirstParameter(),
410 Proj.LastParameter());