Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:03:32

0001 // Created on: 1995-11-02
0002 // Created by: Jacques GOUSSARD
0003 // Copyright (c) 1995-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 _GCPnts_QuasiUniformDeflection_HeaderFile
0018 #define _GCPnts_QuasiUniformDeflection_HeaderFile
0019 
0020 #include <StdFail_NotDone.hxx>
0021 #include <TColStd_SequenceOfReal.hxx>
0022 #include <TColgp_SequenceOfPnt.hxx>
0023 #include <GeomAbs_Shape.hxx>
0024 
0025 class Adaptor3d_Curve;
0026 class Adaptor2d_Curve2d;
0027 class gp_Pnt;
0028 
0029 //! This class computes a distribution of points on a curve.
0030 //! The points may respect the deflection.
0031 //! The algorithm is not based on the classical prediction (with second derivative of curve),
0032 //! but either on the evaluation of the distance between the mid point
0033 //! and the point of mid parameter of the two points,
0034 //! or the distance between the mid point and the point at parameter 0.5
0035 //! on the cubic interpolation of the two points and their tangents.
0036 //!
0037 //! Note: this algorithm is faster than a GCPnts_UniformDeflection algorithm,
0038 //! and is able to work with non-"C2" continuous curves.
0039 //! However, it generates more points in the distribution.
0040 class GCPnts_QuasiUniformDeflection 
0041 {
0042 public:
0043 
0044   DEFINE_STANDARD_ALLOC
0045 
0046   //! Constructs an empty algorithm.
0047   //! To define the problem to be solved, use the function Initialize().
0048   Standard_EXPORT GCPnts_QuasiUniformDeflection();
0049 
0050   //! Computes a QuasiUniform Deflection distribution of points on the Curve.
0051   Standard_EXPORT GCPnts_QuasiUniformDeflection (const Adaptor3d_Curve& theC,
0052                                                  const Standard_Real theDeflection,
0053                                                  const GeomAbs_Shape theContinuity = GeomAbs_C1);
0054 
0055   //! Computes a QuasiUniform Deflection distribution of points on the Curve.
0056   Standard_EXPORT GCPnts_QuasiUniformDeflection (const Adaptor2d_Curve2d& theC,
0057                                                  const Standard_Real theDeflection,
0058                                                  const GeomAbs_Shape theContinuity = GeomAbs_C1);
0059 
0060   //! Computes a QuasiUniform Deflection distribution of points on a part of the Curve.
0061   Standard_EXPORT GCPnts_QuasiUniformDeflection (const Adaptor3d_Curve& theC,
0062                                                  const Standard_Real theDeflection,
0063                                                  const Standard_Real theU1, const Standard_Real theU2,
0064                                                  const GeomAbs_Shape theContinuity = GeomAbs_C1);
0065 
0066   //! Computes a QuasiUniform Deflection distribution of points on a part of the Curve.
0067   //! This and the above algorithms compute a distribution of points:
0068   //! -   on the curve theC, or
0069   //! -   on the part of curve theC limited by the two parameter values theU1 and theU2,
0070   //! where the deflection resulting from the distributed
0071   //! points is not greater than theDeflection.
0072   //!
0073   //! The first point of the distribution is either the origin of
0074   //! curve theC or the point of parameter theU1.
0075   //! The last point of the distribution is either the end point
0076   //! of curve theC or the point of parameter theU2.
0077   //!
0078   //! Intermediate points of the distribution are built such
0079   //! that the deflection is not greater than theDeflection.
0080   //! Using the following evaluation of the deflection:
0081   //! if Pi and Pj are two consecutive points of the
0082   //! distribution, respectively of parameter ui and uj on the curve,
0083   //! the deflection is the distance between:
0084   //! -   the mid-point of Pi and Pj (the center of the chord joining these two points)
0085   //! -   and the point of mid-parameter of these two
0086   //!     points (the point of parameter [(ui+uj) / 2] on curve theC).
0087   //! theContinuity, defaulted to GeomAbs_C1, gives the degree of continuity of the curve theC.
0088   //! (Note that C is an Adaptor3d_Curve or an Adaptor2d_Curve2d object,
0089   //! and does not know the degree of continuity of the underlying curve).
0090   //! Use the function IsDone() to verify that the computation was successful,
0091   //! the function NbPoints() to obtain the number of points of the computed distribution,
0092   //! and the function Parameter() to read the parameter of each point.
0093   //!
0094   //! Warning
0095   //! -   The roles of theU1 and theU2 are inverted if theU1 > theU2.
0096   //! -   Derivative functions on the curve are called according to theContinuity.
0097   //!     An error may occur if theContinuity is greater than
0098   //!     the real degree of continuity of the curve.
0099   //!
0100   //! Warning
0101   //! theC is an adapted curve, i.e. an object which is an interface between:
0102   //! -   the services provided by either a 2D curve from
0103   //!     the package Geom2d (in the case of an Adaptor2d_Curve2d curve)
0104   //!     or a 3D curve from the package Geom (in the case of an Adaptor3d_Curve curve),
0105   //! -   and those required on the curve by the computation algorithm.
0106   Standard_EXPORT GCPnts_QuasiUniformDeflection (const Adaptor2d_Curve2d& theC,
0107                                                  const Standard_Real theDeflection,
0108                                                  const Standard_Real theU1, const Standard_Real theU2,
0109                                                  const GeomAbs_Shape theContinuity = GeomAbs_C1);
0110 
0111   //! Initialize the algorithms with 3D curve and deflection.
0112   Standard_EXPORT void Initialize (const Adaptor3d_Curve& theC,
0113                                    const Standard_Real theDeflection,
0114                                    const GeomAbs_Shape theContinuity = GeomAbs_C1);
0115 
0116   //! Initialize the algorithms with 2D curve and deflection.
0117   Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& theC,
0118                                    const Standard_Real theDeflection,
0119                                    const GeomAbs_Shape theContinuity = GeomAbs_C1);
0120 
0121   //! Initialize the algorithms with 3D curve, deflection and parameter range.
0122   Standard_EXPORT void Initialize (const Adaptor3d_Curve& theC,
0123                                    const Standard_Real theDeflection,
0124                                    const Standard_Real theU1, const Standard_Real theU2,
0125                                    const GeomAbs_Shape theContinuity = GeomAbs_C1);
0126 
0127   //! Initialize the algorithms with theC, theDeflection, theU1, theU2.
0128   //! This and the above algorithms initialize (or reinitialize)
0129   //! this algorithm and compute a distribution of points:
0130   //! -   on the curve theC, or
0131   //! -   on the part of curve theC limited by the two parameter values theU1 and theU2,
0132   //! where the deflection resulting from the distributed
0133   //! points is not greater than theDeflection.
0134   //!
0135   //! The first point of the distribution is either the origin
0136   //! of curve theC or the point of parameter theU1.
0137   //! The last point of the distribution is either the end point of
0138   //! curve theC or the point of parameter theU2.
0139   //!
0140   //! Intermediate points of the distribution are built in
0141   //! such a way that the deflection is not greater than theDeflection.
0142   //! Using the following evaluation of the deflection:
0143   //! if Pi and Pj are two consecutive points of the distribution,
0144   //! respectively of parameter ui and uj on the curve,
0145   //! the deflection is the distance between:
0146   //! -   the mid-point of Pi and Pj (the center of the chord joining these two points)
0147   //! -   and the point of mid-parameter of these two
0148   //!     points (the point of parameter [(ui+uj) / 2] on curve theC).
0149   //! theContinuity, defaulted to GeomAbs_C1, gives the degree of continuity of the curve theC.
0150   //! (Note that C is an Adaptor3d_Curve or an Adaptor2d_Curve2d object,
0151   //! and does not know the degree of continuity of the underlying curve).
0152   //! Use the function IsDone to verify that the computation was successful,
0153   //! the function NbPoints() to obtain the number of points of the computed distribution,
0154   //! and the function Parameter() to read the parameter of each point.
0155   //!
0156   //! Warning
0157   //! -   The roles of theU1 and theU2 are inverted if theU1 > theU2.
0158   //! -   Derivative functions on the curve are called according to theContinuity.
0159   //!     An error may occur if theContinuity is greater than
0160   //!     the real degree of continuity of the curve.
0161   //!
0162   //! Warning
0163   //! theC is an adapted curve, i.e. an object which is an interface between:
0164   //! -   the services provided by either a 2D curve from
0165   //!     the package Geom2d (in the case of an Adaptor2d_Curve2d curve)
0166   //!     or a 3D curve from the package Geom (in the case of an Adaptor3d_Curve curve),
0167   //!     and those required on the curve by the computation algorithm.
0168   Standard_EXPORT void Initialize (const Adaptor2d_Curve2d& theC,
0169                                    const Standard_Real theDeflection,
0170                                    const Standard_Real theU1, const Standard_Real theU2,
0171                                    const GeomAbs_Shape theContinuity = GeomAbs_C1);
0172 
0173   //! Returns true if the computation was successful.
0174   //! IsDone is a protection against:
0175   //! -   non-convergence of the algorithm
0176   //! -   querying the results before computation.
0177   Standard_Boolean IsDone () const
0178   {
0179     return myDone;
0180   }
0181 
0182   //! Returns the number of points of the distribution
0183   //! computed by this algorithm.
0184   //! Exceptions
0185   //! StdFail_NotDone if this algorithm has not been
0186   //! initialized, or if the computation was not successful.
0187   Standard_Integer NbPoints () const
0188   {
0189     StdFail_NotDone_Raise_if (!myDone, "GCPnts_QuasiUniformDeflection::NbPoints()");
0190     return myParams.Length ();
0191   }
0192   
0193   //! Returns the parameter of the point of index Index in
0194   //! the distribution computed by this algorithm.
0195   //! Warning
0196   //! Index must be greater than or equal to 1, and less
0197   //! than or equal to the number of points of the
0198   //! distribution. However, pay particular attention as this
0199   //! condition is not checked by this function.
0200   //! Exceptions
0201   //! StdFail_NotDone if this algorithm has not been
0202   //! initialized, or if the computation was not successful.
0203   Standard_Real Parameter (const Standard_Integer Index) const
0204   {
0205     StdFail_NotDone_Raise_if (!myDone, "GCPnts_QuasiUniformDeflection::Parameter()");
0206     return myParams (Index);
0207   }
0208   
0209   //! Returns the point of index Index in the distribution
0210   //! computed by this algorithm.
0211   //! Warning
0212   //! Index must be greater than or equal to 1, and less
0213   //! than or equal to the number of points of the
0214   //! distribution. However, pay particular attention as this
0215   //! condition is not checked by this function.
0216   //! Exceptions
0217   //! StdFail_NotDone if this algorithm has not been
0218   //! initialized, or if the computation was not successful.
0219   Standard_EXPORT gp_Pnt Value (const Standard_Integer Index) const;
0220   
0221   //! Returns the deflection between the curve and the
0222   //! polygon resulting from the points of the distribution
0223   //! computed by this algorithm.
0224   //! This is the value given to the algorithm at the time
0225   //! of construction (or initialization).
0226   //! Exceptions
0227   //! StdFail_NotDone if this algorithm has not been
0228   //! initialized, or if the computation was not successful.
0229   Standard_Real Deflection () const
0230   {
0231     StdFail_NotDone_Raise_if (!myDone, "GCPnts_QuasiUniformDeflection::Deflection()");
0232     return myDeflection;
0233   }
0234 
0235 private:
0236 
0237   //! Initializes algorithm.
0238   template<class TheCurve>
0239   void initialize (const TheCurve& theC,
0240                    const Standard_Real theDeflection,
0241                    const Standard_Real theU1, const Standard_Real theU2,
0242                    const GeomAbs_Shape theContinuity);
0243 
0244 private:
0245   Standard_Boolean myDone;
0246   Standard_Real myDeflection;
0247   TColStd_SequenceOfReal myParams;
0248   TColgp_SequenceOfPnt myPoints;
0249   GeomAbs_Shape myCont;
0250 };
0251 
0252 #endif // _GCPnts_QuasiUniformDeflection_HeaderFile