Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-16 09:17:03

0001 // Created on: 1993-06-03
0002 // Created by: Bruno DUMORTIER
0003 // Copyright (c) 1993-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 _Geom2dAdaptor_Curve_HeaderFile
0018 #define _Geom2dAdaptor_Curve_HeaderFile
0019 
0020 #include <Adaptor2d_Curve2d.hxx>
0021 #include <BSplCLib_Cache.hxx>
0022 #include <Geom2d_Curve.hxx>
0023 #include <GeomAbs_CurveType.hxx>
0024 #include <GeomAbs_Shape.hxx>
0025 #include <gp_Circ2d.hxx>
0026 #include <gp_Elips2d.hxx>
0027 #include <gp_Hypr2d.hxx>
0028 #include <gp_Lin2d.hxx>
0029 #include <gp_Parab2d.hxx>
0030 #include <gp_Pnt2d.hxx>
0031 #include <Precision.hxx>
0032 #include <Standard_NullObject.hxx>
0033 #include <NCollection_Array1.hxx>
0034 
0035 #include <variant>
0036 
0037 class gp_Vec2d;
0038 class Geom2d_BezierCurve;
0039 class Geom2d_BSplineCurve;
0040 
0041 namespace Geom2dEval_RepCurveDesc
0042 {
0043 class Base;
0044 }
0045 
0046 //! An interface between the services provided by any
0047 //! curve from the package Geom2d and those required
0048 //! of the curve by algorithms which use it.
0049 //!
0050 //! Polynomial coefficients of BSpline curves used for their evaluation are
0051 //! cached for better performance. Therefore these evaluations are not
0052 //! thread-safe and parallel evaluations need to be prevented.
0053 class Geom2dAdaptor_Curve : public Adaptor2d_Curve2d
0054 {
0055   DEFINE_STANDARD_RTTIEXT(Geom2dAdaptor_Curve, Adaptor2d_Curve2d)
0056 public:
0057   //! Internal structure for 2D offset curve evaluation data.
0058   struct OffsetData
0059   {
0060     occ::handle<Geom2dAdaptor_Curve>           BasisAdaptor; //!< Adaptor for basis curve
0061     double                                     Offset = 0.0; //!< Offset distance
0062     occ::handle<Geom2dEval_RepCurveDesc::Base> EvalRep;      //!< Eval representation descriptor
0063   };
0064 
0065   //! Internal structure for Bezier curve evaluation data.
0066   struct BezierData
0067   {
0068     occ::handle<Geom2d_BezierCurve>            Curve;   //!< Bezier curve to prevent downcasts
0069     mutable occ::handle<BSplCLib_Cache>        Cache;   //!< Cached data for evaluation
0070     occ::handle<Geom2dEval_RepCurveDesc::Base> EvalRep; //!< Eval representation descriptor
0071   };
0072 
0073   //! Internal structure for BSpline curve evaluation data.
0074   struct BSplineData
0075   {
0076     occ::handle<Geom2d_BSplineCurve>           Curve;   //!< BSpline curve to prevent downcasts
0077     mutable occ::handle<BSplCLib_Cache>        Cache;   //!< Cached data for evaluation
0078     occ::handle<Geom2dEval_RepCurveDesc::Base> EvalRep; //!< Eval representation descriptor
0079   };
0080 
0081   //! Variant type for 2D curve-specific evaluation data.
0082   using CurveDataVariant = std::variant<std::monostate,
0083                                         gp_Lin2d,
0084                                         gp_Circ2d,
0085                                         gp_Elips2d,
0086                                         gp_Hypr2d,
0087                                         gp_Parab2d,
0088                                         OffsetData,
0089                                         BezierData,
0090                                         BSplineData>;
0091 
0092 public:
0093   Standard_EXPORT Geom2dAdaptor_Curve();
0094 
0095   Standard_EXPORT Geom2dAdaptor_Curve(const occ::handle<Geom2d_Curve>& C);
0096 
0097   //! Standard_ConstructionError is raised if Ufirst>Ulast
0098   Standard_EXPORT Geom2dAdaptor_Curve(const occ::handle<Geom2d_Curve>& C,
0099                                       const double                     UFirst,
0100                                       const double                     ULast);
0101 
0102   //! Shallow copy of adaptor
0103   Standard_EXPORT occ::handle<Adaptor2d_Curve2d> ShallowCopy() const override;
0104 
0105   //! Reset currently loaded curve (undone Load()).
0106   Standard_EXPORT void Reset();
0107 
0108   void Load(const occ::handle<Geom2d_Curve>& theCurve)
0109   {
0110     if (theCurve.IsNull())
0111     {
0112       throw Standard_NullObject();
0113     }
0114     load(theCurve, theCurve->FirstParameter(), theCurve->LastParameter());
0115   }
0116 
0117   //! Standard_ConstructionError is raised if theUFirst > theULast + Precision::PConfusion()
0118   void Load(const occ::handle<Geom2d_Curve>& theCurve,
0119             const double                     theUFirst,
0120             const double                     theULast)
0121   {
0122     if (theCurve.IsNull())
0123     {
0124       throw Standard_NullObject();
0125     }
0126     if (theUFirst > theULast + Precision::Confusion())
0127     {
0128       throw Standard_ConstructionError();
0129     }
0130     load(theCurve, theUFirst, theULast);
0131   }
0132 
0133   //! Returns true if the adaptor has been loaded with a curve.
0134   bool IsInitialized() const { return !myCurve.IsNull(); }
0135 
0136   const occ::handle<Geom2d_Curve>& Curve() const { return myCurve; }
0137 
0138   double FirstParameter() const override { return myFirst; }
0139 
0140   double LastParameter() const override { return myLast; }
0141 
0142   Standard_EXPORT GeomAbs_Shape Continuity() const override;
0143 
0144   //! If necessary, breaks the curve in intervals of
0145   //! continuity <S>. And returns the number of
0146   //! intervals.
0147   Standard_EXPORT int NbIntervals(const GeomAbs_Shape S) const override;
0148 
0149   //! Stores in <T> the parameters bounding the intervals
0150   //! of continuity <S>.
0151   //!
0152   //! The array must provide enough room to accommodate
0153   //! for the parameters. i.e. T.Length() > NbIntervals()
0154   Standard_EXPORT void Intervals(NCollection_Array1<double>& T,
0155                                  const GeomAbs_Shape         S) const override;
0156 
0157   //! Returns a curve equivalent of <me> between
0158   //! parameters <First> and <Last>. <Tol> is used to
0159   //! test for 3d points confusion.
0160   //! If <First> >= <Last>
0161   Standard_EXPORT occ::handle<Adaptor2d_Curve2d> Trim(const double First,
0162                                                       const double Last,
0163                                                       const double Tol) const override;
0164 
0165   Standard_EXPORT bool IsClosed() const override;
0166 
0167   Standard_EXPORT bool IsPeriodic() const override;
0168 
0169   Standard_EXPORT double Period() const override;
0170 
0171   //! Computes the point of parameter U on the curve
0172   Standard_EXPORT gp_Pnt2d Value(const double U) const final;
0173 
0174   //! Computes the point of parameter U.
0175   Standard_EXPORT void D0(const double U, gp_Pnt2d& P) const final;
0176 
0177   //! Computes the point of parameter U on the curve with its
0178   //! first derivative.
0179   //! Raised if the continuity of the current interval
0180   //! is not C1.
0181   Standard_EXPORT void D1(const double U, gp_Pnt2d& P, gp_Vec2d& V) const final;
0182 
0183   //! Returns the point P of parameter U, the first and second
0184   //! derivatives V1 and V2.
0185   //! Raised if the continuity of the current interval
0186   //! is not C2.
0187   Standard_EXPORT void D2(const double U, gp_Pnt2d& P, gp_Vec2d& V1, gp_Vec2d& V2) const final;
0188 
0189   //! Returns the point P of parameter U, the first, the second
0190   //! and the third derivative.
0191   //! Raised if the continuity of the current interval
0192   //! is not C3.
0193   Standard_EXPORT void D3(const double U,
0194                           gp_Pnt2d&    P,
0195                           gp_Vec2d&    V1,
0196                           gp_Vec2d&    V2,
0197                           gp_Vec2d&    V3) const final;
0198 
0199   //! The returned vector gives the value of the derivative for the
0200   //! order of derivation N.
0201   //! Raised if the continuity of the current interval
0202   //! is not CN.
0203   //! Raised if N < 1.
0204   Standard_EXPORT gp_Vec2d DN(const double U, const int N) const final;
0205 
0206   //! returns the parametric resolution
0207   Standard_EXPORT double Resolution(const double Ruv) const override;
0208 
0209   GeomAbs_CurveType GetType() const override { return myTypeCurve; }
0210 
0211   Standard_EXPORT gp_Lin2d Line() const override;
0212 
0213   Standard_EXPORT gp_Circ2d Circle() const override;
0214 
0215   Standard_EXPORT gp_Elips2d Ellipse() const override;
0216 
0217   Standard_EXPORT gp_Hypr2d Hyperbola() const override;
0218 
0219   Standard_EXPORT gp_Parab2d Parabola() const override;
0220 
0221   Standard_EXPORT int Degree() const override;
0222 
0223   Standard_EXPORT bool IsRational() const override;
0224 
0225   Standard_EXPORT int NbPoles() const override;
0226 
0227   Standard_EXPORT int NbKnots() const override;
0228 
0229   Standard_EXPORT int NbSamples() const override;
0230 
0231   Standard_EXPORT occ::handle<Geom2d_BezierCurve> Bezier() const override;
0232 
0233   Standard_EXPORT occ::handle<Geom2d_BSplineCurve> BSpline() const override;
0234 
0235   //! Point evaluation. Raises an exception on failure.
0236   [[nodiscard]] Standard_EXPORT gp_Pnt2d EvalD0(const double theU) const final;
0237 
0238   //! D1 evaluation. Raises an exception on failure.
0239   [[nodiscard]] Standard_EXPORT Geom2d_Curve::ResD1 EvalD1(const double theU) const final;
0240 
0241   //! D2 evaluation. Raises an exception on failure.
0242   [[nodiscard]] Standard_EXPORT Geom2d_Curve::ResD2 EvalD2(const double theU) const final;
0243 
0244   //! D3 evaluation. Raises an exception on failure.
0245   [[nodiscard]] Standard_EXPORT Geom2d_Curve::ResD3 EvalD3(const double theU) const final;
0246 
0247   //! DN evaluation. Raises an exception on failure.
0248   [[nodiscard]] Standard_EXPORT gp_Vec2d EvalDN(const double theU, const int theN) const final;
0249 
0250 private:
0251   Standard_EXPORT GeomAbs_Shape LocalContinuity(const double U1, const double U2) const;
0252 
0253   Standard_EXPORT void load(const occ::handle<Geom2d_Curve>& C,
0254                             const double                     UFirst,
0255                             const double                     ULast);
0256 
0257   //! Check theU relates to start or finish point of B-spline curve and return indices of span the
0258   //! point is located
0259   bool IsBoundary(const double theU, int& theSpanStart, int& theSpanFinish) const;
0260 
0261   //! Rebuilds B-spline cache
0262   //! \param theParameter the value on the knot axis which identifies the caching span
0263   void RebuildCache(const double theParameter) const;
0264 
0265 protected:
0266   occ::handle<Geom2d_Curve> myCurve;
0267   GeomAbs_CurveType         myTypeCurve;
0268   double                    myFirst;
0269   double                    myLast;
0270   CurveDataVariant myCurveData; ///< Curve-specific evaluation data (BSpline, Bezier, offset)
0271 };
0272 
0273 #endif // _Geom2dAdaptor_Curve_HeaderFile