1 // Created on: 1995-06-02
2 // Created by: Xavier BENVENISTE
3 // Copyright (c) 1995-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 #ifndef _Approx_SameParameter_HeaderFile
18 #define _Approx_SameParameter_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23 #include <Adaptor3d_CurveOnSurface.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Real.hxx>
26 class Adaptor2d_HCurve2d;
27 class Adaptor3d_HCurve;
28 class Adaptor3d_HSurface;
33 //! Approximation of a PCurve on a surface to make its
34 //! parameter be the same that the parameter of a given 3d
36 class Approx_SameParameter
42 //! Warning: the C3D and C2D must have the same parametric domain.
43 Standard_EXPORT Approx_SameParameter(const Handle(Geom_Curve)& C3D,
44 const Handle(Geom2d_Curve)& C2D,
45 const Handle(Geom_Surface)& S,
46 const Standard_Real Tol);
48 //! Warning: the C3D and C2D must have the same parametric domain.
49 Standard_EXPORT Approx_SameParameter(const Handle(Adaptor3d_HCurve)& C3D,
50 const Handle(Geom2d_Curve)& C2D,
51 const Handle(Adaptor3d_HSurface)& S,
52 const Standard_Real Tol);
54 //! Warning: the C3D and C2D must have the same parametric domain.
55 Standard_EXPORT Approx_SameParameter(const Handle(Adaptor3d_HCurve)& C3D,
56 const Handle(Adaptor2d_HCurve2d)& C2D,
57 const Handle(Adaptor3d_HSurface)& S,
58 const Standard_Real Tol);
60 //!@Returns .false. if calculations failed,
61 //! .true. if calculations succeed
62 Standard_Boolean IsDone() const
67 //!@Returns tolerance (maximal distance) between 3d curve
68 //! and curve on surface, generated by 2d curve and surface.
69 Standard_Real TolReached() const
74 //! Tells whether the original data had already the same
75 //! parameter up to the tolerance : in that case nothing
77 Standard_Boolean IsSameParameter() const
79 return mySameParameter;
82 //! Returns the 2D curve that has the same parameter as
83 //! the 3D curve once evaluated on the surface up to the
84 //! specified tolerance.
85 Handle(Geom2d_Curve) Curve2d() const
92 //! Internal data structure to unify access to the most actively used data.
93 //! This structure is not intended to be class field since
94 //! a lot of memory is used in intermediate computations.
95 struct Approx_SameParameter_Data
97 Adaptor3d_CurveOnSurface myCOnS; // Curve on surface.
98 Standard_Integer myNbPnt; // Number of points.
99 Standard_Real *myPC3d; // Parameters on 3d curve.
100 Standard_Real *myPC2d; // Parameters on 2d curve.
102 // Second data arrays. Used in loop over poles.
103 Standard_Real *myNewPC3d; // Parameters on 3d curve.
104 Standard_Real *myNewPC2d; // Parameters on 2d curve.
106 // Parameters ranges.
107 Standard_Real myC3dPF; // Curve 3d Parameter First.
108 Standard_Real myC3dPL; // Curve 3d Parameter Last.
109 Standard_Real myC2dPF; // Curve 2d Parameter First.
110 Standard_Real myC2dPL; // Curve 2d Parameter Last.
112 Standard_Real myTol; // Working tolerance.
114 // Swap data arrays and update number of points.
115 void Swap(const Standard_Integer theNewNbPoints)
117 myNbPnt = theNewNbPoints;
118 Standard_Real * temp;
133 Approx_SameParameter(const Approx_SameParameter &);
134 Approx_SameParameter& operator=(const Approx_SameParameter &);
136 //! Computes the pcurve (internal use only).
137 Standard_EXPORT void Build (const Standard_Real Tol);
139 //! Computes initial point distribution.
140 Standard_Boolean BuildInitialDistribution(Approx_SameParameter_Data &theData) const;
142 //! Increases initial number of samples in case of the C0 continuity.
143 //! Return new number of points and corresponding data arrays.
144 //@return true if new number of samples is good and false otherwise.
145 Standard_Boolean IncreaseInitialNbSamples(Approx_SameParameter_Data &theData) const;
147 //! Computes tangents on boundary points.
148 //@return true if tangents are not null and false otherwise.
149 Standard_Boolean ComputeTangents(const Adaptor3d_CurveOnSurface & theCOnS,
150 Standard_Real &theFirstTangent,
151 Standard_Real &theLastTangent) const;
153 //! Method to check same parameter state
154 //! and build dependency between 2d and 3d curves.
155 //@return true if 2d and 3d curves have same parameter state and false otherwise.
156 Standard_Boolean CheckSameParameter(Approx_SameParameter_Data &theData,
157 Standard_Real &theSqDist) const;
159 //! Computes interpolated values.
160 //!@Returns .false. if computations failed;
161 Standard_Boolean Interpolate(const Approx_SameParameter_Data & theData,
162 const Standard_Real aTangFirst,
163 const Standard_Real aTangLast,
164 TColStd_Array1OfReal & thePoles,
165 TColStd_Array1OfReal & theFlatKnots) const;
167 //! Increases number of poles in poles loop.
168 //@return true if poles is changed and false otherwise.
169 Standard_Boolean IncreaseNbPoles(const TColStd_Array1OfReal & thePoles,
170 const TColStd_Array1OfReal & theFlatKnots,
171 Approx_SameParameter_Data & theData,
172 Standard_Real &theBestSqTol) const;
174 static const Standard_Integer myNbSamples = 22; // To be consistent with "checkshape".
175 static const Standard_Integer myMaxArraySize = 1000;
176 const Standard_Real myDeltaMin; // Initialization is allowed only for integral types.
178 Standard_Boolean mySameParameter;
179 Standard_Boolean myDone;
180 Standard_Real myTolReached;
181 Handle(Geom2d_Curve) myCurve2d;
182 Handle(Adaptor2d_HCurve2d) myHCurve2d;
183 Handle(Adaptor3d_HCurve) myC3d;
184 Handle(Adaptor3d_HSurface) mySurf;
187 #endif // _Approx_SameParameter_HeaderFile