1 // Created on: 1991-10-03
2 // Created by: JeanClaude 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 _GeomConvert_HeaderFile
18 #define _GeomConvert_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 <TColGeom_Array1OfBSplineCurve.hxx>
29 #include <TColStd_Array1OfReal.hxx>
30 #include <TColGeom_HArray1OfBSplineCurve.hxx>
31 #include <TColStd_HArray1OfInteger.hxx>
32 class Geom_BSplineCurve;
33 class Geom_BSplineSurface;
36 class GeomConvert_BSplineCurveKnotSplitting;
37 class GeomConvert_BSplineSurfaceKnotSplitting;
38 class GeomConvert_BSplineCurveToBezierCurve;
39 class GeomConvert_CompCurveToBSplineCurve;
40 class GeomConvert_BSplineSurfaceToBezierSurface;
41 class GeomConvert_CompBezierSurfacesToBSplineSurface;
42 class GeomConvert_ApproxSurface;
43 class GeomConvert_ApproxCurve;
46 //! The GeomConvert package provides some global functions as follows
47 //! - converting classical Geom curves into BSpline curves,
48 //! - segmenting BSpline curves, particularly at knots
49 //! values: this function may be used in conjunction with the
50 //! GeomConvert_BSplineCurveKnotSplitting
51 //! class to segment a BSpline curve into arcs which
52 //! comply with required continuity levels,
53 //! - converting classical Geom surfaces into BSpline surfaces, and
54 //! - segmenting BSpline surfaces, particularly at
55 //! knots values: this function may be used in conjunction with the
56 //! GeomConvert_BSplineSurfaceKnotSplitting
57 //! class to segment a BSpline surface into patches
58 //! which comply with required continuity levels.
59 //! All geometric entities used in this package are bounded.
62 //! . Generating the Bezier Points of B-spline curves and surfaces
63 //! (Wolfgang Bohm) CAGD volume 13 number 6 november 1981
64 //! . On NURBS: A Survey (Leslie Piegl) IEEE Computer Graphics and
65 //! Application January 1991
66 //! . Curve and surface construction using rational B-splines
67 //! (Leslie Piegl and Wayne Tiller) CAD Volume 19 number 9 november
69 //! . A survey of curve and surface methods in CAGD (Wolfgang BOHM)
78 //! Convert a curve from Geom by an approximation method
80 //! This method computes the arc of B-spline curve between the two
81 //! knots FromK1 and ToK2. If C is periodic the arc has the same
82 //! orientation as C if SameOrientation = Standard_True.
83 //! If C is not periodic SameOrientation is not used for the
84 //! computation and C is oriented from the knot fromK1 to the knot toK2.
85 //! We just keep the local definition of C between the knots
86 //! FromK1 and ToK2. The returned B-spline curve has its first
87 //! and last knots with a multiplicity equal to degree + 1, where
88 //! degree is the polynomial degree of C.
89 //! The indexes of the knots FromK1 and ToK2 doesn't include the
90 //! repetition of multiple knots in their definition.
91 //! Raised if FromK1 = ToK2
92 //! Raised if FromK1 or ToK2 are out of the bounds
93 //! [FirstUKnotIndex, LastUKnotIndex]
94 Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C, const Standard_Integer FromK1, const Standard_Integer ToK2, const Standard_Boolean SameOrientation = Standard_True);
97 //! This function computes the segment of B-spline curve between the
98 //! parametric values FromU1, ToU2.
99 //! If C is periodic the arc has the same orientation as C if
100 //! SameOrientation = True.
101 //! If C is not periodic SameOrientation is not used for the
102 //! computation and C is oriented fromU1 toU2.
103 //! If U1 and U2 and two parametric values we consider that
104 //! U1 = U2 if Abs (U1 - U2) <= ParametricTolerance and
105 //! ParametricTolerance must be greater or equal to Resolution
108 //! Raised if FromU1 or ToU2 are out of the parametric bounds of the
109 //! curve (The tolerance criterion is ParametricTolerance).
110 //! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance
111 //! Raised if ParametricTolerance < Resolution from gp.
112 Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C, const Standard_Real FromU1, const Standard_Real ToU2, const Standard_Real ParametricTolerance, const Standard_Boolean SameOrientation = Standard_True);
115 //! Computes the B-spline surface patche between the knots values
116 //! FromUK1, ToUK2, FromVK1, ToVK2.
117 //! If S is periodic in one direction the patche has the same
118 //! orientation as S in this direction if the flag is true in this
119 //! direction (SameUOrientation, SameVOrientation).
120 //! If S is not periodic SameUOrientation and SameVOrientation are not
121 //! used for the computation and S is oriented FromUK1 ToUK2 and
124 //! FromUK1 = ToUK2 or FromVK1 = ToVK2
125 //! FromUK1 or ToUK2 are out of the bounds
126 //! [FirstUKnotIndex, LastUKnotIndex]
127 //! FromVK1 or ToVK2 are out of the bounds
128 //! [FirstVKnotIndex, LastVKnotIndex]
129 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S, const Standard_Integer FromUK1, const Standard_Integer ToUK2, const Standard_Integer FromVK1, const Standard_Integer ToVK2, const Standard_Boolean SameUOrientation = Standard_True, const Standard_Boolean SameVOrientation = Standard_True);
132 //! This method splits a B-spline surface patche between the
133 //! knots values FromK1, ToK2 in one direction.
134 //! If USplit = True then the splitting direction is the U parametric
135 //! direction else it is the V parametric direction.
136 //! If S is periodic in the considered direction the patche has the
137 //! same orientation as S in this direction if SameOrientation is True
138 //! If S is not periodic in this direction SameOrientation is not used
139 //! for the computation and S is oriented FromK1 ToK2.
140 //! Raised if FromK1 = ToK2 or if
141 //! FromK1 or ToK2 are out of the bounds
142 //! [FirstUKnotIndex, LastUKnotIndex] in the
143 //! considered parametric direction.
144 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S, const Standard_Integer FromK1, const Standard_Integer ToK2, const Standard_Boolean USplit, const Standard_Boolean SameOrientation = Standard_True);
147 //! This method computes the B-spline surface patche between the
148 //! parametric values FromU1, ToU2, FromV1, ToV2.
149 //! If S is periodic in one direction the patche has the same
150 //! orientation as S in this direction if the flag is True in this
151 //! direction (SameUOrientation, SameVOrientation).
152 //! If S is not periodic SameUOrientation and SameVOrientation are not
153 //! used for the computation and S is oriented FromU1 ToU2 and
155 //! If U1 and U2 and two parametric values we consider that U1 = U2 if
156 //! Abs (U1 - U2) <= ParametricTolerance and ParametricTolerance must
157 //! be greater or equal to Resolution from package gp.
159 //! Raised if FromU1 or ToU2 or FromV1 or ToU2 are out of the
160 //! parametric bounds of the surface (the tolerance criterion is
161 //! ParametricTolerance).
162 //! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance or
163 //! Abs (FromV1 - ToV2) <= ParametricTolerance.
164 //! Raised if ParametricTolerance < Resolution.
165 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S, const Standard_Real FromU1, const Standard_Real ToU2, const Standard_Real FromV1, const Standard_Real ToV2, const Standard_Real ParametricTolerance, const Standard_Boolean SameUOrientation = Standard_True, const Standard_Boolean SameVOrientation = Standard_True);
168 //! This method splits the B-spline surface S in one direction
169 //! between the parametric values FromParam1, ToParam2.
170 //! If USplit = True then the Splitting direction is the U parametric
171 //! direction else it is the V parametric direction.
172 //! If S is periodic in the considered direction the patche has
173 //! the same orientation as S in this direction if SameOrientation
175 //! If S is not periodic in the considered direction SameOrientation
176 //! is not used for the computation and S is oriented FromParam1
178 //! If U1 and U2 and two parametric values we consider that U1 = U2
179 //! if Abs (U1 - U2) <= ParametricTolerance and ParametricTolerance
180 //! must be greater or equal to Resolution from package gp.
182 //! Raises if FromParam1 or ToParam2 are out of the parametric bounds
183 //! of the surface in the considered direction.
184 //! Raises if Abs (FromParam1 - ToParam2) <= ParametricTolerance.
185 Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S, const Standard_Real FromParam1, const Standard_Real ToParam2, const Standard_Boolean USplit, const Standard_Real ParametricTolerance, const Standard_Boolean SameOrientation = Standard_True);
187 //! This function converts a non infinite curve from
188 //! Geom into a B-spline curve. C must be an ellipse or a
189 //! circle or a trimmed conic or a trimmed line or a Bezier
190 //! curve or a trimmed Bezier curve or a BSpline curve or a
191 //! trimmed BSpline curve or an OffsetCurve. The returned B-spline is
192 //! not periodic except if C is a Circle or an Ellipse. If
193 //! the Parameterisation is QuasiAngular than the returned
194 //! curve is NOT periodic in case a periodic Geom_Circle or
195 //! Geom_Ellipse. For TgtThetaOver2_1 and TgtThetaOver2_2 the
196 //! method raises an exception in case of a periodic
197 //! Geom_Circle or a Geom_Ellipse ParameterisationType applies
198 //! only if the curve is a Circle or an ellipse :
199 //! TgtThetaOver2, -- TgtThetaOver2_1, -- TgtThetaOver2_2, --
200 //! TgtThetaOver2_3, -- TgtThetaOver2_4,
202 //! Purpose: this is the classical rational parameterisation
205 //! cos(theta) = ------
210 //! sin(theta) = ------
214 //! t = tan (theta/2)
216 //! with TgtThetaOver2 the routine will compute the number of spans
217 //! using the rule num_spans = [ (ULast - UFirst) / 1.2 ] + 1
218 //! with TgtThetaOver2_N, N spans will be forced: an error will
219 //! be raized if (ULast - UFirst) >= PI and N = 1,
220 //! ULast - UFirst >= 2 PI and N = 2
223 //! here t is a rational function that approximates
224 //! theta ----> tan(theta/2).
225 //! Neverthless the composing with above function yields exact
226 //! functions whose square sum up to 1
228 //! t is replaced by a polynomial function of u so as to grant
229 //! C1 contiuity across knots.
231 //! Standard_DomainError:
232 //! - if the curve C is infinite, or
233 //! - if C is a (complete) circle or ellipse, and Parameterisation is equal to
234 //! Convert_TgtThetaOver2_1 or Convert_TgtThetaOver2_2.
235 //! Standard_ConstructionError:
236 //! - if C is a (complete) circle or ellipse, and if Parameterisation is not equal to
237 //! Convert_TgtThetaOver2, Convert_RationalC1,
238 //! Convert_QuasiAngular (the curve is converted
239 //! in these three cases) or to Convert_TgtThetaOver2_1 or
240 //! Convert_TgtThetaOver2_2 (another exception is raised in these two cases).
241 //! - if C is a trimmed circle or ellipse, if Parameterisation is equal to
242 //! Convert_TgtThetaOver2_1 and if U2 - U1 > 0.9999 * Pi, where U1 and U2 are
243 //! respectively the first and the last parameters of the
244 //! trimmed curve (this method of parameterization
245 //! cannot be used to convert a half-circle or a half-ellipse, for example), or
246 //! - if C is a trimmed circle or ellipse, if
247 //! Parameterisation is equal to Convert_TgtThetaOver2_2 and U2 - U1 >
248 //! 1.9999 * Pi where U1 and U2 are
249 //! respectively the first and the last parameters of the
250 //! trimmed curve (this method of parameterization
251 //! cannot be used to convert a quasi-complete circle or ellipse).
252 Standard_EXPORT static Handle(Geom_BSplineCurve) CurveToBSplineCurve (const Handle(Geom_Curve)& C, const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
255 //! This algorithm converts a non infinite surface from Geom
256 //! into a B-spline surface.
257 //! S must be a trimmed plane or a trimmed cylinder or a trimmed cone
258 //! or a trimmed sphere or a trimmed torus or a sphere or a torus or
259 //! a Bezier surface of a trimmed Bezier surface or a trimmed swept
260 //! surface with a corresponding basis curve which can be turned into
261 //! a B-spline curve (see the method CurveToBSplineCurve).
262 //! Raises DomainError if the type of the surface is not previously defined.
263 Standard_EXPORT static Handle(Geom_BSplineSurface) SurfaceToBSplineSurface (const Handle(Geom_Surface)& S);
265 //! This Method concatenates G1 the ArrayOfCurves as far
266 //! as it is possible.
267 //! ArrayOfCurves[0..N-1]
268 //! ArrayOfToler contains the biggest tolerance of the two
269 //! points shared by two consecutives curves.
270 //! Its dimension: [0..N-2]
271 //! ClosedG1 indicates if the ArrayOfCurves is closed.
272 //! In this case ClosedG1 contains the biggest tolerance
273 //! of the two points which are at the closure.
274 //! Otherwise its value is 0.0
275 Standard_EXPORT static void ConcatG1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves, const TColStd_Array1OfReal& ArrayOfToler, Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated, const Standard_Boolean ClosedG1Flag, const Standard_Real ClosedTolerance);
277 //! This Method concatenates C1 the ArrayOfCurves as far
278 //! as it is possible.
279 //! ArrayOfCurves[0..N-1]
280 //! ArrayOfToler contains the biggest tolerance of the two
281 //! points shared by two consecutives curves.
282 //! Its dimension: [0..N-2]
283 //! ClosedG1 indicates if the ArrayOfCurves is closed.
284 //! In this case ClosedG1 contains the biggest tolerance
285 //! of the two points which are at the closure.
286 //! Otherwise its value is 0.0
287 Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves, const TColStd_Array1OfReal& ArrayOfToler, Handle(TColStd_HArray1OfInteger)& ArrayOfIndices, Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated, const Standard_Boolean ClosedG1Flag, const Standard_Real ClosedTolerance);
289 //! This Method concatenates C1 the ArrayOfCurves as far
290 //! as it is possible.
291 //! ArrayOfCurves[0..N-1]
292 //! ArrayOfToler contains the biggest tolerance of the two
293 //! points shared by two consecutives curves.
294 //! Its dimension: [0..N-2]
295 //! ClosedG1 indicates if the ArrayOfCurves is closed.
296 //! In this case ClosedG1 contains the biggest tolerance
297 //! of the two points which are at the closure.
298 //! Otherwise its value is 0.0
299 Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves, const TColStd_Array1OfReal& ArrayOfToler, Handle(TColStd_HArray1OfInteger)& ArrayOfIndices, Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated, const Standard_Boolean ClosedG1Flag, const Standard_Real ClosedTolerance, const Standard_Real AngularTolerance);
301 //! This Method reduces as far as it is possible the
302 //! multiplicities of the knots of the BSpline BS.(keeping the
303 //! geometry). It returns a new BSpline which could still be C0.
304 //! tolerance is a geometrical tolerance.
305 //! The Angular toleranceis in radians and mesures the angle of
306 //! the tangents on the left and on the right to decide if the
307 //! curve is G1 or not at a given point
308 Standard_EXPORT static void C0BSplineToC1BSplineCurve (Handle(Geom_BSplineCurve)& BS, const Standard_Real tolerance, const Standard_Real AngularTolerance = 1.0e-7);
310 //! This Method reduces as far as it is possible the
311 //! multiplicities of the knots of the BSpline BS.(keeping the geometry).
312 //! It returns an array of BSpline C1. tolerance is a geometrical tolerance.
313 Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS, Handle(TColGeom_HArray1OfBSplineCurve)& tabBS, const Standard_Real tolerance);
315 //! This Method reduces as far as it is possible the
316 //! multiplicities of the knots of the BSpline BS.(keeping the
317 //! geometry). It returns an array of BSpline C1. tolerance is a
318 //! geometrical tolerance : it allows for the maximum deformation
319 //! The Angular tolerance is in radians and mesures the angle of
320 //! the tangents on the left and on the right to decide if the curve
321 //! is C1 or not at a given point
322 Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS, Handle(TColGeom_HArray1OfBSplineCurve)& tabBS, const Standard_Real AngularTolerance, const Standard_Real tolerance);
338 friend class GeomConvert_BSplineCurveKnotSplitting;
339 friend class GeomConvert_BSplineSurfaceKnotSplitting;
340 friend class GeomConvert_BSplineCurveToBezierCurve;
341 friend class GeomConvert_CompCurveToBSplineCurve;
342 friend class GeomConvert_BSplineSurfaceToBezierSurface;
343 friend class GeomConvert_CompBezierSurfacesToBSplineSurface;
344 friend class GeomConvert_ApproxSurface;
345 friend class GeomConvert_ApproxCurve;
355 #endif // _GeomConvert_HeaderFile