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