6059b64a8bd78a1b1993ac0d4f3ef9a736b247d7
[occt.git] / src / GeomConvert / GeomConvert_CompBezierSurfacesToBSplineSurface.hxx
1 // Created on: 1996-06-06
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1996-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_CompBezierSurfacesToBSplineSurface_HeaderFile
18 #define _GeomConvert_CompBezierSurfacesToBSplineSurface_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Integer.hxx>
25 #include <TColStd_HArray1OfInteger.hxx>
26 #include <TColStd_HArray1OfReal.hxx>
27 #include <TColgp_HArray2OfPnt.hxx>
28 #include <Standard_Boolean.hxx>
29 #include <TColGeom_Array2OfBezierSurface.hxx>
30 #include <Standard_Real.hxx>
31 #include <TColStd_Array1OfReal.hxx>
32 #include <GeomAbs_Shape.hxx>
33 class Standard_DimensionError;
34 class Standard_NotImplemented;
35 class Standard_ConstructionError;
36
37
38 //! An algorithm to convert a grid of adjacent
39 //! non-rational Bezier surfaces (with continuity CM) into a
40 //! BSpline surface (with continuity CM).
41 //! A CompBezierSurfacesToBSplineSurface object
42 //! provides a framework for:
43 //! -   defining the grid of adjacent Bezier surfaces
44 //! which is to be converted into a BSpline surface,
45 //! -   implementing the computation algorithm, and
46 //! -   consulting the results.
47 //! Warning
48 //! Do not attempt to convert rational Bezier surfaces using such an algorithm.
49 //! Input is array of Bezier patch
50 //! 1    2    3     4  -> VIndex [1, NbVPatches] -> VDirection
51 //! -----------------------
52 //! 1    |    |    |    |      |
53 //! -----------------------
54 //! 2    |    |    |    |      |
55 //! -----------------------
56 //! 3    |    |    |    |      |
57 //! -----------------------
58 //! UIndex [1, NbUPatches]  Udirection
59 //!
60 //! Warning! Patches must have compatible parametrization
61 class GeomConvert_CompBezierSurfacesToBSplineSurface 
62 {
63 public:
64
65   DEFINE_STANDARD_ALLOC
66
67   
68   //! Computes all the data needed to build a "C0"
69   //! continuous BSpline surface equivalent to the grid of
70   //! adjacent non-rational Bezier surfaces Beziers.
71   //! Each surface in the Beziers grid becomes a natural
72   //! patch, limited by knots values, on the BSpline surface
73   //! whose data is computed. Surfaces in the grid must
74   //! satisfy the following conditions:
75   //! -   Coincident bounding curves between two
76   //! consecutive surfaces in a row of the Beziers grid
77   //! must be u-isoparametric bounding curves of these two surfaces.
78   //! -   Coincident bounding curves between two
79   //! consecutive surfaces in a column of the Beziers
80   //! grid must be v-isoparametric bounding curves of these two surfaces.
81   //! The BSpline surface whose data is computed has the
82   //! following characteristics:
83   //! -   Its degree in the u (respectively v) parametric
84   //! direction is equal to that of the Bezier surface
85   //! which has the highest degree in the u
86   //! (respectively v) parametric direction in the Beziers grid.
87   //! -   It is a "Piecewise Bezier" in both u and v
88   //! parametric directions, i.e.:
89   //! -   the knots are regularly spaced in each
90   //! parametric direction (i.e. the difference between
91   //! two consecutive knots is a constant), and
92   //! -   all the multiplicities of the surface knots in a
93   //! given parametric direction are equal to
94   //! Degree, which is the degree of the BSpline
95   //! surface in this parametric direction, except for
96   //! the first and last knots for which the multiplicity is
97   //! equal to Degree + 1.
98   //! -   Coincident bounding curves between two
99   //! consecutive columns of Bezier surfaces in the
100   //! Beziers grid become u-isoparametric curves,
101   //! corresponding to knots values of the BSpline surface.
102   //! -   Coincident bounding curves between two
103   //! consecutive rows of Bezier surfaces in the Beziers
104   //! grid become v-isoparametric curves
105   //! corresponding to knots values of the BSpline surface.
106   //! Use the available consultation functions to access the
107   //! computed data. This data may be used to construct the BSpline surface.
108   //! Warning
109   //! The surfaces in the Beziers grid must be adjacent, i.e.
110   //! two consecutive Bezier surfaces in the grid (in a row
111   //! or column) must have a coincident bounding curve. In
112   //! addition, the location of the parameterization on each
113   //! of these surfaces (i.e. the relative location of u and v
114   //! isoparametric curves on the surface) is of importance
115   //! with regard to the positioning of the surfaces in the
116   //! Beziers grid. Care must be taken with respect to the
117   //! above, as these properties are not checked and an
118   //! error may occur if they are not satisfied.
119   //! Exceptions
120   //! Standard_NotImplemented if one of the Bezier
121   //! surfaces of the Beziers grid is rational.
122   Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers);
123   
124   //! Build an Ci uniform (Rational) BSpline surface
125   //! The highest Continuity Ci is imposed, like the
126   //! maximal deformation is lower than <Tolerance>.
127   //! Warning:  The Continuity C0 is imposed without any check.
128   Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers, const Standard_Real Tolerance, const Standard_Boolean RemoveKnots = Standard_True);
129   
130   //! Computes all the data needed to construct a BSpline
131   //! surface equivalent to the adjacent non-rational
132   //! Bezier surfaces Beziers grid.
133   //! Each surface in the Beziers grid becomes a natural
134   //! patch, limited by knots values, on the BSpline surface
135   //! whose data is computed. Surfaces in the grid must
136   //! satisfy the following conditions:
137   //! -   Coincident bounding curves between two
138   //! consecutive surfaces in a row of the Beziers grid
139   //! must be u-isoparametric bounding curves of these two surfaces.
140   //! -   Coincident bounding curves between two
141   //! consecutive surfaces in a column of the Beziers
142   //! grid must be v-isoparametric bounding curves of these two surfaces.
143   //! The BSpline surface whose data is computed has the
144   //! following characteristics:
145   //! -   Its degree in the u (respectively v) parametric
146   //! direction is equal to that of the Bezier surface
147   //! which has the highest degree in the u
148   //! (respectively v) parametric direction in the Beziers grid.
149   //! -   Coincident bounding curves between two
150   //! consecutive columns of Bezier surfaces in the
151   //! Beziers grid become u-isoparametric curves
152   //! corresponding to knots values of the BSpline surface.
153   //! -   Coincident bounding curves between two
154   //! consecutive rows of Bezier surfaces in the Beziers
155   //! grid become v-isoparametric curves
156   //! corresponding to knots values of the BSpline surface.
157   //! Knots values of the BSpline surface are given in the two tables:
158   //! -   UKnots for the u parametric direction (which
159   //! corresponds to the order of Bezier surface columns in the Beziers grid), and
160   //! -   VKnots for the v parametric direction (which
161   //! corresponds to the order of Bezier surface rows in the Beziers grid).
162   //! The dimensions of UKnots (respectively VKnots)
163   //! must be equal to the number of columns (respectively,
164   //! rows) of the Beziers grid, plus 1 .
165   //! UContinuity and VContinuity, which are both
166   //! defaulted to GeomAbs_C0, specify the required
167   //! continuity on the BSpline surface. If the required
168   //! degree of continuity is greater than 0 in a given
169   //! parametric direction, a deformation is applied locally
170   //! on the initial surface (as defined by the Beziers grid)
171   //! to satisfy this condition. This local deformation is not
172   //! applied however, if it is greater than Tolerance
173   //! (defaulted to 1.0 e-7). In such cases, the
174   //! continuity condition is not satisfied, and the function
175   //! IsDone will return false. A small tolerance value
176   //! prevents any modification of the surface and a large
177   //! tolerance value "smoothes" the surface.
178   //! Use the available consultation functions to access the
179   //! computed data. This data may be used to construct the BSpline surface.
180   //! Warning
181   //! The surfaces in the Beziers grid must be adjacent, i.e.
182   //! two consecutive Bezier surfaces in the grid (in a row
183   //! or column) must have a coincident bounding curve. In
184   //! addition, the location of the parameterization on each
185   //! of these surfaces (i.e. the relative location of u and v
186   //! isoparametric curves on the surface) is of importance
187   //! with regard to the positioning of the surfaces in the
188   //! Beziers grid. Care must be taken with respect to the
189   //! above, as these properties are not checked and an
190   //! error may occur if they are not satisfied.
191   //! Exceptions
192   //! Standard_DimensionMismatch:
193   //! -   if the number of knots in the UKnots table (i.e. the
194   //! length of the UKnots array) is not equal to the
195   //! number of columns of Bezier surfaces in the
196   //! Beziers grid plus 1, or
197   //! -   if the number of knots in the VKnots table (i.e. the
198   //! length of the VKnots array) is not equal to the
199   //! number of rows of Bezier surfaces in the Beziers grid, plus 1.
200   //! Standard_ConstructionError:
201   //! -   if UContinuity and VContinuity are not equal to
202   //! one of the following values: GeomAbs_C0,
203   //! GeomAbs_C1, GeomAbs_C2 and GeomAbs_C3; or
204   //! -   if the number of columns in the Beziers grid is
205   //! greater than 1, and the required degree of
206   //! continuity in the u parametric direction is greater
207   //! than that of the Bezier surface with the highest
208   //! degree in the u parametric direction (in the Beziers grid), minus 1; or
209   //! -   if the number of rows in the Beziers grid is
210   //! greater than 1, and the required degree of
211   //! continuity in the v parametric direction is greater
212   //! than that of the Bezier surface with the highest
213   //! degree in the v parametric direction (in the Beziers grid), minus 1 .
214   //! Standard_NotImplemented if one of the Bezier
215   //! surfaces in the Beziers grid is rational.
216   Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(const TColGeom_Array2OfBezierSurface& Beziers, const TColStd_Array1OfReal& UKnots, const TColStd_Array1OfReal& VKnots, const GeomAbs_Shape UContinuity = GeomAbs_C0, const GeomAbs_Shape VContinuity = GeomAbs_C0, const Standard_Real Tolerance = 1.0e-4);
217   
218   //! Returns the number of knots in the U direction
219   //! of the BSpline surface whose data is computed in this framework.
220     Standard_Integer NbUKnots() const;
221   
222   //! Returns number of poles in the U direction
223   //! of the BSpline surface whose data is computed in this framework.
224     Standard_Integer NbUPoles() const;
225   
226   //! Returns the number of knots in the V direction
227   //! of the BSpline surface whose data is computed in this framework.
228     Standard_Integer NbVKnots() const;
229   
230   //! Returns the number of poles in the V direction
231   //! of the BSpline surface whose data is computed in this framework.
232     Standard_Integer NbVPoles() const;
233   
234   //! Returns the table of poles of the BSpline surface
235   //! whose data is computed in this framework.
236     const Handle(TColgp_HArray2OfPnt)& Poles() const;
237   
238   //! Returns the knots table for the u parametric
239   //! direction of the BSpline surface whose data is computed in this framework.
240     const Handle(TColStd_HArray1OfReal)& UKnots() const;
241   
242   //! Returns the degree for the u  parametric
243   //! direction of the BSpline surface whose data is computed in this framework.
244     Standard_Integer UDegree() const;
245   
246   //! Returns the knots table for the v parametric
247   //! direction of the BSpline surface whose data is computed in this framework.
248     const Handle(TColStd_HArray1OfReal)& VKnots() const;
249   
250   //! Returns the degree for the v  parametric
251   //! direction of the BSpline surface whose data is computed in this framework.
252     Standard_Integer VDegree() const;
253   
254
255   //! Returns the multiplicities table for the u
256   //! parametric direction of the knots of the BSpline
257   //! surface whose data is computed in this framework.
258     const Handle(TColStd_HArray1OfInteger)& UMultiplicities() const;
259   
260   //! -- Returns the multiplicities table for the v
261   //! parametric direction of the knots of the BSpline
262   //! surface whose data is computed in this framework.
263     const Handle(TColStd_HArray1OfInteger)& VMultiplicities() const;
264   
265   //! Returns true if the conversion was successful.
266   //! Unless an exception was raised at the time of
267   //! construction, the conversion of the Bezier surface
268   //! grid assigned to this algorithm is always carried out.
269   //! IsDone returns false if the constraints defined at the
270   //! time of construction cannot be respected. This occurs
271   //! when there is an incompatibility between a required
272   //! degree of continuity on the BSpline surface, and the
273   //! maximum tolerance accepted for local deformations
274   //! of the surface. In such a case the computed data
275   //! does not satisfy all the initial constraints.
276   Standard_EXPORT Standard_Boolean IsDone() const;
277
278
279
280
281 protected:
282
283
284
285
286
287 private:
288
289   
290   //! It used internally by the constructors.
291   Standard_EXPORT void Perform (const TColGeom_Array2OfBezierSurface& Beziers);
292
293
294   Standard_Integer myUDegree;
295   Standard_Integer myVDegree;
296   Handle(TColStd_HArray1OfInteger) myVMults;
297   Handle(TColStd_HArray1OfInteger) myUMults;
298   Handle(TColStd_HArray1OfReal) myUKnots;
299   Handle(TColStd_HArray1OfReal) myVKnots;
300   Handle(TColgp_HArray2OfPnt) myPoles;
301   Standard_Boolean isrational;
302   Standard_Boolean myDone;
303
304
305 };
306
307
308 #include <GeomConvert_CompBezierSurfacesToBSplineSurface.lxx>
309
310
311
312
313
314 #endif // _GeomConvert_CompBezierSurfacesToBSplineSurface_HeaderFile