Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-28 09:20:09

0001 // Copyright (c) 2025 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _GeomEval_TBezierCurve_HeaderFile
0015 #define _GeomEval_TBezierCurve_HeaderFile
0016 
0017 #include <Geom_BoundedCurve.hxx>
0018 #include <NCollection_Array1.hxx>
0019 #include <gp_Pnt.hxx>
0020 
0021 class gp_Trsf;
0022 class Geom_Geometry;
0023 
0024 //! 3D Trigonometric Bezier curve.
0025 //! Uses a trigonometric Bernstein-like basis over the space
0026 //! {1, sin(alpha*t), cos(alpha*t), ..., sin(n*alpha*t), cos(n*alpha*t)}.
0027 //!
0028 //! The parameter domain is [0, Pi/alpha].
0029 //! The number of control points is 2*n + 1 for order n.
0030 //!
0031 //! The alpha parameter controls the frequency of the trigonometric basis.
0032 //! A T-Bezier curve of order n with poles P_0, P_1, ..., P_{2n} is:
0033 //! @code
0034 //!   C(t) = P_0 * T_0(t) + P_1 * T_1(t) + ... + P_{2n} * T_{2n}(t)
0035 //! @endcode
0036 //! where:
0037 //! - T_0(t) = 1
0038 //! - T_{2k-1}(t) = sin(k * alpha * t), for k = 1..n
0039 //! - T_{2k}(t) = cos(k * alpha * t), for k = 1..n
0040 //!
0041 //! For rational curves, each pole is weighted:
0042 //! @code
0043 //!   C(t) = sum(w_i * P_i * T_i(t)) / sum(w_i * T_i(t))
0044 //! @endcode
0045 class GeomEval_TBezierCurve : public Geom_BoundedCurve
0046 {
0047 public:
0048   //! Constructs a non-rational T-Bezier curve from poles and alpha.
0049   //! @param[in] thePoles control points (1-based, size must be odd >= 3)
0050   //! @param[in] theAlpha frequency parameter (must be > 0)
0051   //! @throw Standard_ConstructionError if NbPoles is not odd or < 3 or theAlpha <= 0
0052   Standard_EXPORT GeomEval_TBezierCurve(const NCollection_Array1<gp_Pnt>& thePoles,
0053                                         double                            theAlpha);
0054 
0055   //! Constructs a rational T-Bezier curve.
0056   //! @param[in] thePoles control points (1-based, size must be odd >= 3)
0057   //! @param[in] theWeights weights (same size as poles, all > 0)
0058   //! @param[in] theAlpha frequency parameter (must be > 0)
0059   //! @throw Standard_ConstructionError if validation fails
0060   Standard_EXPORT GeomEval_TBezierCurve(const NCollection_Array1<gp_Pnt>& thePoles,
0061                                         const NCollection_Array1<double>& theWeights,
0062                                         double                            theAlpha);
0063 
0064   //! Returns the poles array.
0065   Standard_EXPORT const NCollection_Array1<gp_Pnt>& Poles() const;
0066 
0067   //! Returns the weights array (empty if non-rational).
0068   Standard_EXPORT const NCollection_Array1<double>& Weights() const;
0069 
0070   //! Returns the frequency parameter alpha.
0071   Standard_EXPORT double Alpha() const;
0072 
0073   //! Returns the number of poles.
0074   Standard_EXPORT int NbPoles() const;
0075 
0076   //! Returns the trigonometric order n (NbPoles = 2*n + 1).
0077   Standard_EXPORT int Order() const;
0078 
0079   //! Returns true if the curve is rational.
0080   Standard_EXPORT bool IsRational() const;
0081 
0082   // -- Geom_BoundedCurve interface --
0083 
0084   //! Returns the start point C(0).
0085   Standard_EXPORT gp_Pnt StartPoint() const final;
0086 
0087   //! Returns the end point C(Pi/alpha).
0088   Standard_EXPORT gp_Pnt EndPoint() const final;
0089 
0090   // -- Geom_Curve interface --
0091 
0092   //! Reversal is not supported for this eval curve.
0093   //! @throw Standard_NotImplemented
0094   Standard_EXPORT void Reverse() final;
0095 
0096   //! Reversal is not supported for this eval curve.
0097   //! @throw Standard_NotImplemented
0098   Standard_EXPORT double ReversedParameter(const double U) const final;
0099 
0100   //! Returns the first parameter value: 0.0.
0101   Standard_EXPORT double FirstParameter() const final;
0102 
0103   //! Returns the last parameter value: Pi/alpha.
0104   Standard_EXPORT double LastParameter() const final;
0105 
0106   //! Returns true if StartPoint and EndPoint coincide.
0107   Standard_EXPORT bool IsClosed() const final;
0108 
0109   //! Returns false. T-Bezier curves are not periodic.
0110   Standard_EXPORT bool IsPeriodic() const final;
0111 
0112   //! Returns GeomAbs_CN. T-Bezier curves are infinitely differentiable.
0113   Standard_EXPORT GeomAbs_Shape Continuity() const final;
0114 
0115   //! Returns true for all N. T-Bezier curves are infinitely differentiable.
0116   Standard_EXPORT bool IsCN(const int N) const final;
0117 
0118   //! Computes the point C(U).
0119   Standard_EXPORT gp_Pnt EvalD0(const double U) const final;
0120 
0121   //! Computes the point and first derivative at U.
0122   Standard_EXPORT Geom_Curve::ResD1 EvalD1(const double U) const final;
0123 
0124   //! Computes the point and first two derivatives at U.
0125   Standard_EXPORT Geom_Curve::ResD2 EvalD2(const double U) const final;
0126 
0127   //! Computes the point and first three derivatives at U.
0128   Standard_EXPORT Geom_Curve::ResD3 EvalD3(const double U) const final;
0129 
0130   //! Computes the N-th derivative at U.
0131   //! @param[in] U parameter value
0132   //! @param[in] N derivative order (must be >= 1)
0133   //! @return the N-th derivative vector
0134   //! @throw Standard_RangeError if N < 1
0135   Standard_EXPORT gp_Vec EvalDN(const double U, const int N) const final;
0136 
0137   //! Transformation is not supported for this eval geometry.
0138   //! @throw Standard_NotImplemented
0139   Standard_EXPORT void Transform(const gp_Trsf& T) final;
0140 
0141   //! Creates a new object which is a copy of this T-Bezier curve.
0142   Standard_EXPORT occ::handle<Geom_Geometry> Copy() const final;
0143 
0144   //! Dumps the content of me into the stream.
0145   Standard_EXPORT void DumpJson(Standard_OStream& theOStream, int theDepth = -1) const final;
0146 
0147   DEFINE_STANDARD_RTTIEXT(GeomEval_TBezierCurve, Geom_BoundedCurve)
0148 
0149 private:
0150   //! Evaluate trigonometric basis functions at parameter theT.
0151   //! Returns array of size 2*n+1:
0152   //! {T_0(t), T_1(t), ..., T_{2n}(t)}
0153   //! where T_0=1, T_{2k-1}=sin(k*alpha*t), T_{2k}=cos(k*alpha*t).
0154   void evalBasis(double theT, NCollection_Array1<double>& theBasis) const;
0155 
0156   //! Evaluate derivatives of basis functions of order theDerivOrder.
0157   //! @param[in] theT parameter value
0158   //! @param[in] theDerivOrder derivative order (1, 2, 3, ...)
0159   //! @param[out] theBasisDeriv array of derivatives of size 2*n+1
0160   void evalBasisDeriv(double                      theT,
0161                       int                         theDerivOrder,
0162                       NCollection_Array1<double>& theBasisDeriv) const;
0163 
0164   //! Evaluate point on a non-rational curve: sum(P_i * B_i(t)).
0165   gp_Pnt evalNonRationalPoint(const NCollection_Array1<double>& theBasis) const;
0166 
0167   //! Evaluate derivative vector on a non-rational curve: sum(P_i * B_i'(t)).
0168   gp_Vec evalNonRationalDeriv(const NCollection_Array1<double>& theBasisDeriv) const;
0169 
0170   NCollection_Array1<gp_Pnt> myPoles;    //!< Control points
0171   NCollection_Array1<double> myWeights;  //!< Weights (empty if non-rational)
0172   double                     myAlpha;    //!< Frequency parameter
0173   bool                       myRational; //!< True if curve is rational
0174 };
0175 
0176 #endif // _GeomEval_TBezierCurve_HeaderFile