0032743: Coding Rules - remove unused class friends of Package classes
[occt.git] / src / GeomConvert / GeomConvert.hxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _GeomConvert_HeaderFile
18 #define _GeomConvert_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
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;
34 class Geom_Curve;
35 class Geom_Surface;
36
37
38 //! The GeomConvert package provides some global functions as follows
39 //! -   converting classical Geom curves into BSpline curves,
40 //! -   segmenting BSpline curves, particularly at knots
41 //! values: this function may be used in conjunction with the
42 //! GeomConvert_BSplineCurveKnotSplitting
43 //! class to segment a BSpline curve into arcs which
44 //! comply with required continuity levels,
45 //! -   converting classical Geom surfaces into BSpline surfaces, and
46 //! -   segmenting BSpline surfaces, particularly at
47 //! knots values: this function may be used in conjunction with the
48 //! GeomConvert_BSplineSurfaceKnotSplitting
49 //! class to segment a BSpline surface into patches
50 //! which comply with required continuity levels.
51 //! All geometric entities used in this package are bounded.
52 //!
53 //! References :
54 //! . Generating the Bezier Points of B-spline curves and surfaces
55 //! (Wolfgang Bohm) CAGD volume 13 number 6 november 1981
56 //! . On NURBS: A Survey  (Leslie Piegl) IEEE Computer Graphics and
57 //! Application January 1991
58 //! . Curve and surface construction using rational B-splines
59 //! (Leslie Piegl and Wayne Tiller) CAD Volume 19 number 9 november
60 //! 1987
61 //! . A survey of curve and surface methods in CAGD (Wolfgang BOHM)
62 //! CAGD 1 1984
63 class GeomConvert 
64 {
65 public:
66
67   DEFINE_STANDARD_ALLOC
68
69   
70   //! Convert a curve from Geom by an approximation method
71   //!
72   //! This method computes the arc of B-spline curve between the two
73   //! knots FromK1 and ToK2.  If C is periodic the arc has the same
74   //! orientation as C if SameOrientation = Standard_True.
75   //! If C is not periodic  SameOrientation is not used for the
76   //! computation and C is oriented from the knot fromK1 to the knot toK2.
77   //! We just keep the local definition of C between the knots
78   //! FromK1 and ToK2.  The returned B-spline curve has its first
79   //! and last knots with a multiplicity equal to degree + 1, where
80   //! degree is the polynomial degree of C.
81   //! The indexes of the knots FromK1 and ToK2 doesn't include the
82   //! repetition of multiple knots in their definition.
83   //! Raised if FromK1 = ToK2
84   //! Raised if FromK1 or ToK2 are out of the bounds
85   //! [FirstUKnotIndex, LastUKnotIndex]
86   Standard_EXPORT static Handle(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C,
87                                                                       const Standard_Integer FromK1,
88                                                                       const Standard_Integer ToK2,
89                                                                       const Standard_Boolean SameOrientation = Standard_True);
90   
91
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
101   //! from package gp.
102   //!
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(Geom_BSplineCurve) SplitBSplineCurve (const Handle(Geom_BSplineCurve)& C,
108                                                                       const Standard_Real FromU1,
109                                                                       const Standard_Real ToU2,
110                                                                       const Standard_Real ParametricTolerance,
111                                                                       const Standard_Boolean SameOrientation = Standard_True);
112   
113
114   //! Computes the B-spline surface patche between the knots values
115   //! FromUK1, ToUK2, FromVK1, ToVK2.
116   //! If S is periodic in one direction the patche has the same
117   //! orientation as S in this direction if the flag is true in this
118   //! direction (SameUOrientation, SameVOrientation).
119   //! If S is not periodic SameUOrientation and SameVOrientation are not
120   //! used for the computation and S is oriented FromUK1 ToUK2 and
121   //! FromVK1 ToVK2.
122   //! Raised if
123   //! FromUK1 = ToUK2 or FromVK1 = ToVK2
124   //! FromUK1 or ToUK2 are out of the bounds
125   //! [FirstUKnotIndex, LastUKnotIndex]
126   //! FromVK1 or ToVK2 are out of the bounds
127   //! [FirstVKnotIndex, LastVKnotIndex]
128   Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
129                                                                           const Standard_Integer FromUK1,
130                                                                           const Standard_Integer ToUK2,
131                                                                           const Standard_Integer FromVK1,
132                                                                           const Standard_Integer ToVK2,
133                                                                           const Standard_Boolean SameUOrientation = Standard_True,
134                                                                           const Standard_Boolean SameVOrientation = Standard_True);
135   
136
137   //! This method splits a B-spline surface patche between the
138   //! knots values FromK1, ToK2 in one direction.
139   //! If USplit = True then the splitting direction is the U parametric
140   //! direction else it is the V parametric direction.
141   //! If S is periodic in the considered direction the patche has the
142   //! same orientation as S in this direction if SameOrientation is True
143   //! If S is not periodic in this direction SameOrientation is not used
144   //! for the computation and S is oriented FromK1 ToK2.
145   //! Raised if FromK1 = ToK2 or if
146   //! FromK1 or ToK2 are out of the bounds
147   //! [FirstUKnotIndex, LastUKnotIndex] in the
148   //! considered parametric direction.
149   Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
150                                                                           const Standard_Integer FromK1,
151                                                                           const Standard_Integer ToK2,
152                                                                           const Standard_Boolean USplit,
153                                                                           const Standard_Boolean SameOrientation = Standard_True);
154   
155
156   //! This method computes the B-spline surface patche between the
157   //! parametric values FromU1, ToU2, FromV1, ToV2.
158   //! If S is periodic in one direction the patche has the same
159   //! orientation as S in this direction if the flag is True in this
160   //! direction (SameUOrientation, SameVOrientation).
161   //! If S is not periodic SameUOrientation and SameVOrientation are not
162   //! used for the computation and S is oriented FromU1 ToU2 and
163   //! FromV1 ToV2.
164   //! If U1 and U2 and two parametric values we consider that U1 = U2 if
165   //! Abs (U1 - U2) <= ParametricTolerance and ParametricTolerance must
166   //! be greater or equal to Resolution from package gp.
167   //!
168   //! Raised if FromU1 or ToU2 or FromV1 or ToU2 are out of the
169   //! parametric bounds of the surface (the tolerance criterion is
170   //! ParametricTolerance).
171   //! Raised if Abs (FromU1 - ToU2) <= ParametricTolerance or
172   //! Abs (FromV1 - ToV2) <= ParametricTolerance.
173   //! Raised if ParametricTolerance < Resolution.
174   Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
175                                                                           const Standard_Real FromU1,
176                                                                           const Standard_Real ToU2,
177                                                                           const Standard_Real FromV1,
178                                                                           const Standard_Real ToV2,
179                                                                           const Standard_Real ParametricTolerance,
180                                                                           const Standard_Boolean SameUOrientation = Standard_True,
181                                                                           const Standard_Boolean SameVOrientation = Standard_True);
182   
183
184   //! This method splits the B-spline surface S in one direction
185   //! between the parametric values FromParam1, ToParam2.
186   //! If USplit = True then the Splitting direction is the U parametric
187   //! direction else it is the V parametric direction.
188   //! If S is periodic in the considered direction the patche has
189   //! the same orientation as S in this direction if SameOrientation
190   //! is true.
191   //! If S is not periodic in the considered direction SameOrientation
192   //! is not used for the computation and S is oriented FromParam1
193   //! ToParam2.
194   //! If U1 and U2 and two parametric values we consider that U1 = U2
195   //! if Abs (U1 - U2) <= ParametricTolerance and ParametricTolerance
196   //! must be greater or equal to Resolution from package gp.
197   //!
198   //! Raises if FromParam1 or ToParam2 are out of the parametric bounds
199   //! of the surface in the considered direction.
200   //! Raises if Abs (FromParam1 - ToParam2) <= ParametricTolerance.
201   Standard_EXPORT static Handle(Geom_BSplineSurface) SplitBSplineSurface (const Handle(Geom_BSplineSurface)& S,
202                                                                           const Standard_Real FromParam1,
203                                                                           const Standard_Real ToParam2,
204                                                                           const Standard_Boolean USplit,
205                                                                           const Standard_Real ParametricTolerance,
206                                                                           const Standard_Boolean SameOrientation = Standard_True);
207   
208   //! This function converts a non infinite curve from
209   //! Geom into a  B-spline curve.  C must be   an ellipse or  a
210   //! circle  or a trimmed conic  or a trimmed  line or a Bezier
211   //! curve or a trimmed  Bezier curve or a  BSpline curve or  a
212   //! trimmed  BSpline curve or  an  OffsetCurve.  The returned  B-spline is
213   //! not periodic except  if C is a Circle  or an  Ellipse.  If
214   //! the  Parameterisation is  QuasiAngular than  the returned
215   //! curve is NOT periodic  in case a  periodic Geom_Circle or
216   //! Geom_Ellipse.  For TgtThetaOver2_1 and TgtThetaOver2_2 the
217   //! method   raises  an exception  in    case  of a  periodic
218   //! Geom_Circle or a Geom_Ellipse ParameterisationType applies
219   //! only    if  the curve  is   a  Circle  or  an   ellipse :
220   //! TgtThetaOver2,  -- TgtThetaOver2_1, -- TgtThetaOver2_2, --
221   //! TgtThetaOver2_3, -- TgtThetaOver2_4,
222   //!
223   //! Purpose: this is the classical rational parameterisation
224   //! 2
225   //! 1 - t
226   //! cos(theta) = ------
227   //! 2
228   //! 1 + t
229   //!
230   //! 2t
231   //! sin(theta) = ------
232   //! 2
233   //! 1 + t
234   //!
235   //! t = tan (theta/2)
236   //!
237   //! with TgtThetaOver2  the routine will compute the number of spans
238   //! using the rule num_spans = [ (ULast - UFirst) / 1.2 ] + 1
239   //! with TgtThetaOver2_N, N  spans will be forced: an error will
240   //! be raized if (ULast - UFirst) >= PI and N = 1,
241   //! ULast - UFirst >= 2 PI and N = 2
242   //!
243   //! QuasiAngular,
244   //! here t is a rational function that approximates
245   //! theta ----> tan(theta/2).
246   //! Nevetheless the composing with above function yields exact
247   //! functions whose square sum up to 1
248   //! RationalC1 ;
249   //! t is replaced by a polynomial function of u so as to grant
250   //! C1 contiuity across knots.
251   //! Exceptions
252   //! Standard_DomainError:
253   //! -   if the curve C is infinite, or
254   //! -   if C is a (complete) circle or ellipse, and Parameterisation is equal to
255   //! Convert_TgtThetaOver2_1 or Convert_TgtThetaOver2_2.
256   //! Standard_ConstructionError:
257   //! -   if C is a (complete) circle or ellipse, and if Parameterisation is not equal to
258   //! Convert_TgtThetaOver2, Convert_RationalC1,
259   //! Convert_QuasiAngular (the curve is converted
260   //! in these three cases) or to Convert_TgtThetaOver2_1 or
261   //! Convert_TgtThetaOver2_2 (another exception is raised in these two cases).
262   //! -   if C is a trimmed circle or ellipse, if Parameterisation is equal to
263   //! Convert_TgtThetaOver2_1 and if U2 - U1 > 0.9999 * Pi, where U1 and U2 are
264   //! respectively the first and the last parameters of the
265   //! trimmed curve (this method of parameterization
266   //! cannot be used to convert a half-circle or a half-ellipse, for example), or
267   //! -   if C is a trimmed circle or ellipse, if
268   //! Parameterisation is equal to Convert_TgtThetaOver2_2 and U2 - U1 >
269   //! 1.9999 * Pi where U1 and U2 are
270   //! respectively the first and the last parameters of the
271   //! trimmed curve (this method of parameterization
272   //! cannot be used to convert a quasi-complete circle or ellipse).
273   Standard_EXPORT static Handle(Geom_BSplineCurve) CurveToBSplineCurve (const Handle(Geom_Curve)& C,
274                                                                         const Convert_ParameterisationType Parameterisation = Convert_TgtThetaOver2);
275   
276
277   //! This algorithm converts a non infinite surface from Geom
278   //! into a B-spline surface.
279   //! S must be a trimmed plane or a trimmed cylinder or a trimmed cone
280   //! or a trimmed sphere or a trimmed torus or a sphere or a torus or
281   //! a Bezier surface of a trimmed Bezier surface or a trimmed swept
282   //! surface with a corresponding basis curve which can be turned into
283   //! a B-spline curve   (see the method CurveToBSplineCurve).
284   //! Raises DomainError if the type of the surface is not previously defined.
285   Standard_EXPORT static Handle(Geom_BSplineSurface) SurfaceToBSplineSurface (const Handle(Geom_Surface)& S);
286   
287   //! This Method concatenates G1 the ArrayOfCurves as far
288   //! as it  is possible.
289   //! ArrayOfCurves[0..N-1]
290   //! ArrayOfToler contains the  biggest tolerance of the two
291   //! points shared by two consecutives curves.
292   //! Its dimension: [0..N-2]
293   //! ClosedFlag     indicates if the ArrayOfCurves is closed.
294   //! In this case ClosedTolerance contains the biggest tolerance
295   //! of the two points which are at the closure.
296   //! Otherwise its value is 0.0
297   //! ClosedFlag becomes False on the output
298   //! if it is impossible to build closed curve.
299   Standard_EXPORT static void ConcatG1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
300                                         const TColStd_Array1OfReal& ArrayOfToler,
301                                         Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
302                                         Standard_Boolean& ClosedFlag,
303                                         const Standard_Real ClosedTolerance);
304   
305   //! This Method concatenates C1 the ArrayOfCurves as far
306   //! as it is possible.
307   //! ArrayOfCurves[0..N-1]
308   //! ArrayOfToler contains the  biggest tolerance of the two
309   //! points shared by two consecutives curves.
310   //! Its dimension: [0..N-2]
311   //! ClosedFlag     indicates if the ArrayOfCurves is closed.
312   //! In this case ClosedTolerance contains the biggest tolerance
313   //! of the two points which are at the closure.
314   //! Otherwise its value is 0.0
315   //! ClosedFlag becomes False on the output
316   //! if it is impossible to build closed curve.
317   Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
318                                         const TColStd_Array1OfReal& ArrayOfToler,
319                                         Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
320                                         Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
321                                         Standard_Boolean& ClosedFlag,
322                                         const Standard_Real ClosedTolerance);
323   
324   //! This Method concatenates C1 the ArrayOfCurves as far
325   //! as it is possible.
326   //! ArrayOfCurves[0..N-1]
327   //! ArrayOfToler contains the  biggest tolerance of the two
328   //! points shared by two consecutives curves.
329   //! Its dimension: [0..N-2]
330   //! ClosedFlag     indicates if the ArrayOfCurves is closed.
331   //! In this case ClosedTolerance contains the biggest tolerance
332   //! of the two points which are at the closure.
333   //! Otherwise its value is 0.0
334   //! ClosedFlag becomes False on the output
335   //! if it is impossible to build closed curve.
336   Standard_EXPORT static void ConcatC1 (TColGeom_Array1OfBSplineCurve& ArrayOfCurves,
337                                         const TColStd_Array1OfReal& ArrayOfToler,
338                                         Handle(TColStd_HArray1OfInteger)& ArrayOfIndices,
339                                         Handle(TColGeom_HArray1OfBSplineCurve)& ArrayOfConcatenated,
340                                         Standard_Boolean& ClosedFlag,
341                                         const Standard_Real ClosedTolerance,
342                                         const Standard_Real AngularTolerance);
343   
344   //! This  Method reduces as far as   it is possible the
345   //! multiplicities of  the  knots of  the BSpline BS.(keeping  the
346   //! geometry).  It returns a new BSpline which  could still be C0.
347   //! tolerance is a  geometrical tolerance.
348   //! The  Angular toleranceis in radians  and measures  the angle of
349   //! the tangents  on  the left and on  the right  to decide if  the
350   //! curve is G1 or not at a given point
351   Standard_EXPORT static void C0BSplineToC1BSplineCurve (Handle(Geom_BSplineCurve)& BS,
352                                                          const Standard_Real tolerance,
353                                                          const Standard_Real AngularTolerance = 1.0e-7);
354   
355   //! This Method   reduces as far  as  it is possible  the
356   //! multiplicities  of  the knots  of the BSpline  BS.(keeping the geometry).
357   //! It returns an array of BSpline C1. tolerance is a geometrical tolerance.
358   Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS,
359                                                                 Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
360                                                                 const Standard_Real tolerance);
361   
362   //! This   Method reduces as far   as it is  possible the
363   //! multiplicities of  the  knots of  the  BSpline BS.(keeping the
364   //! geometry).  It returns an array of BSpline C1.  tolerance is a
365   //! geometrical tolerance : it  allows for the maximum deformation
366   //! The  Angular tolerance is in  radians and measures the angle of
367   //! the tangents on the left and on the right to decide if the curve
368   //! is C1 or not at a given point
369   Standard_EXPORT static void C0BSplineToArrayOfC1BSplineCurve (const Handle(Geom_BSplineCurve)& BS,
370                                                                 Handle(TColGeom_HArray1OfBSplineCurve)& tabBS,
371                                                                 const Standard_Real AngularTolerance,
372                                                                 const Standard_Real tolerance);
373
374 };
375
376 #endif // _GeomConvert_HeaderFile