1 // Created on: 1991-10-03
2 // Created by: Jean Claude VAUTHIER
3 // Copyright (c) 1991-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 _Geom2dConvert_HeaderFile
18 #define _Geom2dConvert_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Integer.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_Real.hxx>
27 #include <Convert_ParameterisationType.hxx>
28 #include <TColGeom2d_Array1OfBSplineCurve.hxx>
29 #include <TColStd_Array1OfReal.hxx>
30 #include <TColGeom2d_HArray1OfBSplineCurve.hxx>
31 #include <TColStd_HArray1OfInteger.hxx>
32 class Geom2d_BSplineCurve;
34 class Geom2dConvert_BSplineCurveKnotSplitting;
35 class Geom2dConvert_BSplineCurveToBezierCurve;
36 class Geom2dConvert_CompCurveToBSplineCurve;
37 class Geom2dConvert_ApproxCurve;
41 //! This package provides an implementation of algorithms to do
42 //! the conversion between equivalent geometric entities from
44 //! It gives the possibility :
45 //! . to obtain the B-spline representation of bounded curves.
46 //! . to split a B-spline curve into several B-spline curves
47 //! with some constraints of continuity,
48 //! . to convert a B-spline curve into several Bezier curves
50 //! All the geometric entities used in this package are bounded.
52 //! . Generating the Bezier Points of B-spline curves and surfaces
53 //! (Wolfgang Bohm) CAGD volume 13 number 6 november 1981
54 //! . On NURBS: A Survey (Leslie Piegl) IEEE Computer Graphics and
55 //! Application January 1991
56 //! . Curve and surface construction using rational B-splines
57 //! (Leslie Piegl and Wayne Tiller) CAD Volume 19 number 9 november
59 //! . A survey of curve and surface methods in CAGD (Wolfgang BOHM)
68 //! -- Convert a curve to BSpline by Approximation
70 //! This method computes the arc of B-spline curve between the two
71 //! knots FromK1 and ToK2. If C is periodic the arc has the same
72 //! orientation as C if SameOrientation = Standard_True.
73 //! If C is not periodic SameOrientation is not used for the
74 //! computation and C is oriented from the knot fromK1 to the
76 //! We just keep the local definition of C between the knots
77 //! FromK1 and ToK2. The returned B-spline curve has its first
78 //! and last knots with a multiplicity equal to degree + 1, where
79 //! degree is the polynomial degree of C.
80 //! The indexes of the knots FromK1 and ToK2 doesn't include the
81 //! repetition of multiple knots in their definition.
83 //! Raised if FromK1 or ToK2 are out of the bounds
84 //! [FirstUKnotIndex, LastUKnotIndex]
85 //! Raised if FromK1 = ToK2
86 Standard_EXPORT static Handle(Geom2d_BSplineCurve) SplitBSplineCurve (const Handle(Geom2d_BSplineCurve)& C,
87 const Standard_Integer FromK1,
88 const Standard_Integer ToK2,
89 const Standard_Boolean SameOrientation = Standard_True);
92 //! This function computes the segment of B-spline curve between the
93 //! parametric values FromU1, ToU2.
94 //! If C is periodic the arc has the same orientation as C if
95 //! SameOrientation = True.
96 //! If C is not periodic SameOrientation is not used for the
97 //! computation and C is oriented fromU1 toU2.
98 //! If U1 and U2 and two parametric values we consider that
99 //! U1 = U2 if Abs (U1 - U2) <= ParametricTolerance and
100 //! ParametricTolerance must be greater or equal to Resolution
103 //! Raised if FromU1 or ToU2 are out of the parametric bounds of the
104 //! curve (The tolerance criterion is ParametricTolerance).
105 //! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance
106 //! Raised if ParametricTolerance < Resolution from gp.
107 Standard_EXPORT static Handle(Geom2d_BSplineCurve) SplitBSplineCurve (const Handle(Geom2d_BSplineCurve)& C,
108 const Standard_Real FromU1,
109 const Standard_Real ToU2,
110 const Standard_Real ParametricTolerance,
111 const Standard_Boolean SameOrientation = Standard_True);
113 //! This function converts a non infinite curve from
114 //! Geom into a B-spline curve. C must be an ellipse or a
115 //! circle or a trimmed conic or a trimmed line or a Bezier
116 //! curve or a trimmed Bezier curve or a BSpline curve or a
117 //! trimmed BSpline curve or an Offset curve or a trimmed
119 //! The returned B-spline is not periodic except if C is a
120 //! Circle or an Ellipse.
121 //! ParameterisationType applies only if the curve is a Circle
128 //! Purpose: this is the classical rational parameterisation
131 //! cos(theta) = ------
136 //! sin(theta) = ------
140 //! t = tan (theta/2)
142 //! with TgtThetaOver2 the routine will compute the number of spans
143 //! using the rule num_spans = [ (ULast - UFirst) / 1.2 ] + 1
144 //! with TgtThetaOver2_N, N spans will be forced: an error will
145 //! be raized if (ULast - UFirst) >= PI and N = 1,
146 //! ULast - UFirst >= 2 PI and N = 2
149 //! here t is a rational function that approximates
150 //! theta ----> tan(theta/2).
151 //! Nevetheless the composing with above function yields exact
152 //! functions whose square sum up to 1
154 //! t is replaced by a polynomial function of u so as to grant
155 //! C1 contiuity across knots.
157 //! Standard_DomainError if the curve C is infinite.
158 //! Standard_ConstructionError:
159 //! - if C is a complete circle or ellipse, and if
160 //! Parameterisation is not equal to
161 //! Convert_TgtThetaOver2 or to Convert_RationalC1, or
162 //! - if C is a trimmed circle or ellipse and if
163 //! Parameterisation is equal to
164 //! Convert_TgtThetaOver2_1 and if U2 - U1 >
165 //! 0.9999 * Pi where U1 and U2 are
166 //! respectively the first and the last parameters of the
167 //! trimmed curve (this method of parameterization
168 //! cannot be used to convert a half-circle or a
169 //! half-ellipse, for example), or
170 //! - if C is a trimmed circle or ellipse and
171 //! Parameterisation is equal to
172 //! Convert_TgtThetaOver2_2 and U2 - U1 >
173 //! 1.9999 * Pi where U1 and U2 are
174 //! respectively the first and the last parameters of the
175 //! trimmed curve (this method of parameterization
176 //! cannot be used to convert a quasi-complete circle or ellipse).
177 Standard_EXPORT static Handle(Geom2d_BSplineCurve) CurveToBSplineCurve (const Handle(Geom2d_Curve)& C,
178 const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
180 //! This Method concatenates G1 the ArrayOfCurves as far
181 //! as it is possible.
182 //! ArrayOfCurves[0..N-1]
183 //! ArrayOfToler contains the biggest tolerance of the two
184 //! points shared by two consecutives curves.
185 //! Its dimension: [0..N-2]
186 //! ClosedFlag indicates if the ArrayOfCurves is closed.
187 //! In this case ClosedTolerance contains the biggest tolerance
188 //! of the two points which are at the closure.
189 //! Otherwise its value is 0.0
190 //! ClosedFlag becomes False on the output
191 //! if it is impossible to build closed curve.
192 Standard_EXPORT static void ConcatG1 (TColGeom2d_Array1OfBSplineCurve& ArrayOfCurves,
193 const TColStd_Array1OfReal& ArrayOfToler,
194 Handle(TColGeom2d_HArray1OfBSplineCurve)& ArrayOfConcatenated,
195 Standard_Boolean& ClosedFlag,
196 const Standard_Real ClosedTolerance);
198 //! This Method concatenates C1 the ArrayOfCurves as far
199 //! as it is possible.
200 //! ArrayOfCurves[0..N-1]
201 //! ArrayOfToler contains the biggest tolerance of the two
202 //! points shared by two consecutives curves.
203 //! Its dimension: [0..N-2]
204 //! ClosedFlag indicates if the ArrayOfCurves is closed.
205 //! In this case ClosedTolerance contains the biggest tolerance
206 //! of the two points which are at the closure.
207 //! Otherwise its value is 0.0
208 //! ClosedFlag becomes False on the output
209 //! if it is impossible to build closed curve.
210 Standard_EXPORT static void ConcatC1 (TColGeom2d_Array1OfBSplineCurve& ArrayOfCurves,
211 const TColStd_Array1OfReal& ArrayOfToler,
212 Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
213 Handle(TColGeom2d_HArray1OfBSplineCurve)& ArrayOfConcatenated,
214 Standard_Boolean& ClosedFlag,
215 const Standard_Real ClosedTolerance);
217 //! This Method concatenates C1 the ArrayOfCurves as far
218 //! as it is possible.
219 //! ArrayOfCurves[0..N-1]
220 //! ArrayOfToler contains the biggest tolerance of the two
221 //! points shared by two consecutives curves.
222 //! Its dimension: [0..N-2]
223 //! ClosedFlag indicates if the ArrayOfCurves is closed.
224 //! In this case ClosedTolerance contains the biggest tolerance
225 //! of the two points which are at the closure.
226 //! Otherwise its value is 0.0
227 //! ClosedFlag becomes False on the output
228 //! if it is impossible to build closed curve.
229 Standard_EXPORT static void ConcatC1 (TColGeom2d_Array1OfBSplineCurve& ArrayOfCurves,
230 const TColStd_Array1OfReal& ArrayOfToler,
231 Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
232 Handle(TColGeom2d_HArray1OfBSplineCurve)& ArrayOfConcatenated,
233 Standard_Boolean& ClosedFlag,
234 const Standard_Real ClosedTolerance,
235 const Standard_Real AngularTolerance);
237 //! This Method reduces as far as it is possible the
238 //! multiplicities of the knots of the BSpline BS.(keeping the geometry).
239 //! It returns a new BSpline which could still be C0.
240 //! tolerance is a geometrical tolerance
241 Standard_EXPORT static void C0BSplineToC1BSplineCurve (Handle(Geom2d_BSplineCurve)& BS,
242 const Standard_Real Tolerance);
244 //! This Method reduces as far as it is possible the
245 //! multiplicities of the knots of the BSpline BS.(keeping the geometry).
246 //! It returns an array of BSpline C1.
247 //! Tolerance is a geometrical tolerance
248 Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom2d_BSplineCurve)& BS,
249 Handle(TColGeom2d_HArray1OfBSplineCurve)& tabBS,
250 const Standard_Real Tolerance);
252 //! This Method reduces as far as it is possible the
253 //! multiplicities of the knots of the BSpline BS.(keeping the geometry).
254 //! It returns an array of BSpline C1.
255 //! tolerance is a geometrical tolerance
256 Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom2d_BSplineCurve)& BS,
257 Handle(TColGeom2d_HArray1OfBSplineCurve)& tabBS,
258 const Standard_Real AngularTolerance,
259 const Standard_Real Tolerance);
275 friend class Geom2dConvert_BSplineCurveKnotSplitting;
276 friend class Geom2dConvert_BSplineCurveToBezierCurve;
277 friend class Geom2dConvert_CompCurveToBSplineCurve;
278 friend class Geom2dConvert_ApproxCurve;
288 #endif // _Geom2dConvert_HeaderFile