Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:20:21

0001 // Created on: 1996-06-06
0002 // Created by: Philippe MANGIN
0003 // Copyright (c) 1996-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _GeomConvert_CompBezierSurfacesToBSplineSurface_HeaderFile
0018 #define _GeomConvert_CompBezierSurfacesToBSplineSurface_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Integer.hxx>
0025 #include <NCollection_Array1.hxx>
0026 #include <NCollection_HArray1.hxx>
0027 #include <gp_Pnt.hxx>
0028 #include <NCollection_Array2.hxx>
0029 #include <NCollection_HArray2.hxx>
0030 #include <Geom_BezierSurface.hxx>
0031 #include <GeomAbs_Shape.hxx>
0032 
0033 //! An algorithm to convert a grid of adjacent
0034 //! non-rational Bezier surfaces (with continuity CM) into a
0035 //! BSpline surface (with continuity CM).
0036 //! A CompBezierSurfacesToBSplineSurface object
0037 //! provides a framework for:
0038 //! -   defining the grid of adjacent Bezier surfaces
0039 //! which is to be converted into a BSpline surface,
0040 //! -   implementing the computation algorithm, and
0041 //! -   consulting the results.
0042 //! Warning
0043 //! Do not attempt to convert rational Bezier surfaces using such an algorithm.
0044 //! Input is array of Bezier patch
0045 //! 1    2    3     4  -> VIndex [1, NbVPatches] -> VDirection
0046 //! -----------------------
0047 //! 1    |    |    |    |      |
0048 //! -----------------------
0049 //! 2    |    |    |    |      |
0050 //! -----------------------
0051 //! 3    |    |    |    |      |
0052 //! -----------------------
0053 //! UIndex [1, NbUPatches] Udirection
0054 //!
0055 //! Warning! Patches must have compatible parametrization
0056 class GeomConvert_CompBezierSurfacesToBSplineSurface
0057 {
0058 public:
0059   DEFINE_STANDARD_ALLOC
0060 
0061   //! Computes all the data needed to build a "C0"
0062   //! continuous BSpline surface equivalent to the grid of
0063   //! adjacent non-rational Bezier surfaces Beziers.
0064   //! Each surface in the Beziers grid becomes a natural
0065   //! patch, limited by knots values, on the BSpline surface
0066   //! whose data is computed. Surfaces in the grid must
0067   //! satisfy the following conditions:
0068   //! -   Coincident bounding curves between two
0069   //! consecutive surfaces in a row of the Beziers grid
0070   //! must be u-isoparametric bounding curves of these two surfaces.
0071   //! -   Coincident bounding curves between two
0072   //! consecutive surfaces in a column of the Beziers
0073   //! grid must be v-isoparametric bounding curves of these two surfaces.
0074   //! The BSpline surface whose data is computed has the
0075   //! following characteristics:
0076   //! -   Its degree in the u (respectively v) parametric
0077   //! direction is equal to that of the Bezier surface
0078   //! which has the highest degree in the u
0079   //! (respectively v) parametric direction in the Beziers grid.
0080   //! -   It is a "Piecewise Bezier" in both u and v
0081   //! parametric directions, i.e.:
0082   //! -   the knots are regularly spaced in each
0083   //! parametric direction (i.e. the difference between
0084   //! two consecutive knots is a constant), and
0085   //! -   all the multiplicities of the surface knots in a
0086   //! given parametric direction are equal to
0087   //! Degree, which is the degree of the BSpline
0088   //! surface in this parametric direction, except for
0089   //! the first and last knots for which the multiplicity is
0090   //! equal to Degree + 1.
0091   //! -   Coincident bounding curves between two
0092   //! consecutive columns of Bezier surfaces in the
0093   //! Beziers grid become u-isoparametric curves,
0094   //! corresponding to knots values of the BSpline surface.
0095   //! -   Coincident bounding curves between two
0096   //! consecutive rows of Bezier surfaces in the Beziers
0097   //! grid become v-isoparametric curves
0098   //! corresponding to knots values of the BSpline surface.
0099   //! Use the available consultation functions to access the
0100   //! computed data. This data may be used to construct the BSpline surface.
0101   //! Warning
0102   //! The surfaces in the Beziers grid must be adjacent, i.e.
0103   //! two consecutive Bezier surfaces in the grid (in a row
0104   //! or column) must have a coincident bounding curve. In
0105   //! addition, the location of the parameterization on each
0106   //! of these surfaces (i.e. the relative location of u and v
0107   //! isoparametric curves on the surface) is of importance
0108   //! with regard to the positioning of the surfaces in the
0109   //! Beziers grid. Care must be taken with respect to the
0110   //! above, as these properties are not checked and an
0111   //! error may occur if they are not satisfied.
0112   //! Exceptions
0113   //! Standard_NotImplemented if one of the Bezier
0114   //! surfaces of the Beziers grid is rational.
0115   Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(
0116     const NCollection_Array2<occ::handle<Geom_BezierSurface>>& Beziers);
0117 
0118   //! Build an Ci uniform (Rational) BSpline surface
0119   //! The highest Continuity Ci is imposed, like the
0120   //! maximal deformation is lower than <Tolerance>.
0121   //! Warning: The Continuity C0 is imposed without any check.
0122   Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(
0123     const NCollection_Array2<occ::handle<Geom_BezierSurface>>& Beziers,
0124     const double                                               Tolerance,
0125     const bool                                                 RemoveKnots = true);
0126 
0127   //! Computes all the data needed to construct a BSpline
0128   //! surface equivalent to the adjacent non-rational
0129   //! Bezier surfaces Beziers grid.
0130   //! Each surface in the Beziers grid becomes a natural
0131   //! patch, limited by knots values, on the BSpline surface
0132   //! whose data is computed. Surfaces in the grid must
0133   //! satisfy the following conditions:
0134   //! -   Coincident bounding curves between two
0135   //! consecutive surfaces in a row of the Beziers grid
0136   //! must be u-isoparametric bounding curves of these two surfaces.
0137   //! -   Coincident bounding curves between two
0138   //! consecutive surfaces in a column of the Beziers
0139   //! grid must be v-isoparametric bounding curves of these two surfaces.
0140   //! The BSpline surface whose data is computed has the
0141   //! following characteristics:
0142   //! -   Its degree in the u (respectively v) parametric
0143   //! direction is equal to that of the Bezier surface
0144   //! which has the highest degree in the u
0145   //! (respectively v) parametric direction in the Beziers grid.
0146   //! -   Coincident bounding curves between two
0147   //! consecutive columns of Bezier surfaces in the
0148   //! Beziers grid become u-isoparametric curves
0149   //! corresponding to knots values of the BSpline surface.
0150   //! -   Coincident bounding curves between two
0151   //! consecutive rows of Bezier surfaces in the Beziers
0152   //! grid become v-isoparametric curves
0153   //! corresponding to knots values of the BSpline surface.
0154   //! Knots values of the BSpline surface are given in the two tables:
0155   //! -   UKnots for the u parametric direction (which
0156   //! corresponds to the order of Bezier surface columns in the Beziers grid), and
0157   //! -   VKnots for the v parametric direction (which
0158   //! corresponds to the order of Bezier surface rows in the Beziers grid).
0159   //! The dimensions of UKnots (respectively VKnots)
0160   //! must be equal to the number of columns (respectively,
0161   //! rows) of the Beziers grid, plus 1 .
0162   //! UContinuity and VContinuity, which are both
0163   //! defaulted to GeomAbs_C0, specify the required
0164   //! continuity on the BSpline surface. If the required
0165   //! degree of continuity is greater than 0 in a given
0166   //! parametric direction, a deformation is applied locally
0167   //! on the initial surface (as defined by the Beziers grid)
0168   //! to satisfy this condition. This local deformation is not
0169   //! applied however, if it is greater than Tolerance
0170   //! (defaulted to 1.0 e-7). In such cases, the
0171   //! continuity condition is not satisfied, and the function
0172   //! IsDone will return false. A small tolerance value
0173   //! prevents any modification of the surface and a large
0174   //! tolerance value "smoothes" the surface.
0175   //! Use the available consultation functions to access the
0176   //! computed data. This data may be used to construct the BSpline surface.
0177   //! Warning
0178   //! The surfaces in the Beziers grid must be adjacent, i.e.
0179   //! two consecutive Bezier surfaces in the grid (in a row
0180   //! or column) must have a coincident bounding curve. In
0181   //! addition, the location of the parameterization on each
0182   //! of these surfaces (i.e. the relative location of u and v
0183   //! isoparametric curves on the surface) is of importance
0184   //! with regard to the positioning of the surfaces in the
0185   //! Beziers grid. Care must be taken with respect to the
0186   //! above, as these properties are not checked and an
0187   //! error may occur if they are not satisfied.
0188   //! Exceptions
0189   //! Standard_DimensionMismatch:
0190   //! -   if the number of knots in the UKnots table (i.e. the
0191   //! length of the UKnots array) is not equal to the
0192   //! number of columns of Bezier surfaces in the
0193   //! Beziers grid plus 1, or
0194   //! -   if the number of knots in the VKnots table (i.e. the
0195   //! length of the VKnots array) is not equal to the
0196   //! number of rows of Bezier surfaces in the Beziers grid, plus 1.
0197   //! Standard_ConstructionError:
0198   //! -   if UContinuity and VContinuity are not equal to
0199   //! one of the following values: GeomAbs_C0,
0200   //! GeomAbs_C1, GeomAbs_C2 and GeomAbs_C3; or
0201   //! -   if the number of columns in the Beziers grid is
0202   //! greater than 1, and the required degree of
0203   //! continuity in the u parametric direction is greater
0204   //! than that of the Bezier surface with the highest
0205   //! degree in the u parametric direction (in the Beziers grid), minus 1; or
0206   //! -   if the number of rows in the Beziers grid is
0207   //! greater than 1, and the required degree of
0208   //! continuity in the v parametric direction is greater
0209   //! than that of the Bezier surface with the highest
0210   //! degree in the v parametric direction (in the Beziers grid), minus 1 .
0211   //! Standard_NotImplemented if one of the Bezier
0212   //! surfaces in the Beziers grid is rational.
0213   Standard_EXPORT GeomConvert_CompBezierSurfacesToBSplineSurface(
0214     const NCollection_Array2<occ::handle<Geom_BezierSurface>>& Beziers,
0215     const NCollection_Array1<double>&                          UKnots,
0216     const NCollection_Array1<double>&                          VKnots,
0217     const GeomAbs_Shape                                        UContinuity = GeomAbs_C0,
0218     const GeomAbs_Shape                                        VContinuity = GeomAbs_C0,
0219     const double                                               Tolerance   = 1.0e-4);
0220 
0221   //! Returns the number of knots in the U direction
0222   //! of the BSpline surface whose data is computed in this framework.
0223   int NbUKnots() const;
0224 
0225   //! Returns number of poles in the U direction
0226   //! of the BSpline surface whose data is computed in this framework.
0227   int NbUPoles() const;
0228 
0229   //! Returns the number of knots in the V direction
0230   //! of the BSpline surface whose data is computed in this framework.
0231   int NbVKnots() const;
0232 
0233   //! Returns the number of poles in the V direction
0234   //! of the BSpline surface whose data is computed in this framework.
0235   int NbVPoles() const;
0236 
0237   //! Returns the table of poles of the BSpline surface
0238   //! whose data is computed in this framework.
0239   const occ::handle<NCollection_HArray2<gp_Pnt>>& Poles() const;
0240 
0241   //! Returns the knots table for the u parametric
0242   //! direction of the BSpline surface whose data is computed in this framework.
0243   const occ::handle<NCollection_HArray1<double>>& UKnots() const;
0244 
0245   //! Returns the degree for the u parametric
0246   //! direction of the BSpline surface whose data is computed in this framework.
0247   int UDegree() const;
0248 
0249   //! Returns the knots table for the v parametric
0250   //! direction of the BSpline surface whose data is computed in this framework.
0251   const occ::handle<NCollection_HArray1<double>>& VKnots() const;
0252 
0253   //! Returns the degree for the v parametric
0254   //! direction of the BSpline surface whose data is computed in this framework.
0255   int VDegree() const;
0256 
0257   //! Returns the multiplicities table for the u
0258   //! parametric direction of the knots of the BSpline
0259   //! surface whose data is computed in this framework.
0260   const occ::handle<NCollection_HArray1<int>>& UMultiplicities() const;
0261 
0262   //! -- Returns the multiplicities table for the v
0263   //! parametric direction of the knots of the BSpline
0264   //! surface whose data is computed in this framework.
0265   const occ::handle<NCollection_HArray1<int>>& VMultiplicities() const;
0266 
0267   //! Returns true if the conversion was successful.
0268   //! Unless an exception was raised at the time of
0269   //! construction, the conversion of the Bezier surface
0270   //! grid assigned to this algorithm is always carried out.
0271   //! IsDone returns false if the constraints defined at the
0272   //! time of construction cannot be respected. This occurs
0273   //! when there is an incompatibility between a required
0274   //! degree of continuity on the BSpline surface, and the
0275   //! maximum tolerance accepted for local deformations
0276   //! of the surface. In such a case the computed data
0277   //! does not satisfy all the initial constraints.
0278   Standard_EXPORT bool IsDone() const;
0279 
0280 private:
0281   //! It used internally by the constructors.
0282   Standard_EXPORT void Perform(const NCollection_Array2<occ::handle<Geom_BezierSurface>>& Beziers);
0283 
0284   int                                      myUDegree;
0285   int                                      myVDegree;
0286   occ::handle<NCollection_HArray1<int>>    myVMults;
0287   occ::handle<NCollection_HArray1<int>>    myUMults;
0288   occ::handle<NCollection_HArray1<double>> myUKnots;
0289   occ::handle<NCollection_HArray1<double>> myVKnots;
0290   occ::handle<NCollection_HArray2<gp_Pnt>> myPoles;
0291   bool                                     isrational;
0292   bool                                     myDone;
0293 };
0294 
0295 #include <GeomConvert_CompBezierSurfacesToBSplineSurface.lxx>
0296 
0297 #endif // _GeomConvert_CompBezierSurfacesToBSplineSurface_HeaderFile