Back to home page

EIC code displayed by LXR

 
 

    


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

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 _Geom2dGridEval_Curve_HeaderFile
0015 #define _Geom2dGridEval_Curve_HeaderFile
0016 
0017 #include <Adaptor2d_Curve2d.hxx>
0018 #include <GeomAbs_CurveType.hxx>
0019 #include <Geom2d_Curve.hxx>
0020 #include <Geom2dGridEval_BSplineCurve.hxx>
0021 #include <Geom2dGridEval_BezierCurve.hxx>
0022 #include <Geom2dGridEval_Circle.hxx>
0023 #include <Geom2dGridEval_Ellipse.hxx>
0024 #include <Geom2dGridEval_Hyperbola.hxx>
0025 #include <Geom2dGridEval_Line.hxx>
0026 #include <Geom2dGridEval_OffsetCurve.hxx>
0027 #include <Geom2dGridEval_OtherCurve.hxx>
0028 #include <Geom2dGridEval_Parabola.hxx>
0029 #include <gp_Pnt2d.hxx>
0030 #include <NCollection_Array1.hxx>
0031 #include <Standard.hxx>
0032 #include <Standard_DefineAlloc.hxx>
0033 
0034 #include <variant>
0035 
0036 //! @brief Unified grid evaluator for any 2D curve.
0037 //!
0038 //! Uses std::variant for compile-time type safety and zero heap allocation
0039 //! for the evaluator itself. Automatically detects curve type from
0040 //! Adaptor2d_Curve2d and dispatches to the appropriate specialized evaluator.
0041 //!
0042 //! Supported curve types with optimized evaluation:
0043 //! - Line: Direct analytical formula
0044 //! - Circle: Trigonometric formula
0045 //! - Ellipse: Analytical formula
0046 //! - Hyperbola: Analytical formula
0047 //! - Parabola: Analytical formula
0048 //! - BezierCurve: Optimized batch evaluation via BSplCLib
0049 //! - BSplineCurve: Optimized batch evaluation via BSplCLib with span caching
0050 //! - OffsetCurve: Composite evaluation using basis curve batch evaluator
0051 //! - Other: Fallback using Adaptor2d_Curve2d::D0
0052 //!
0053 //! Usage:
0054 //! @code
0055 //!   Geom2dGridEval_Curve anEval(myAdaptorCurve2d);
0056 //!   // OR
0057 //!   Geom2dGridEval_Curve anEval(myGeom2dCurve);
0058 //!   NCollection_Array1<gp_Pnt2d> aGrid = anEval.EvaluateGrid(myParams);
0059 //! @endcode
0060 class Geom2dGridEval_Curve
0061 {
0062 public:
0063   DEFINE_STANDARD_ALLOC
0064 
0065   //! Variant type holding all possible 2D curve evaluators.
0066   using EvaluatorVariant = std::variant<std::monostate,              // Uninitialized state
0067                                         Geom2dGridEval_Line,         // Line curve
0068                                         Geom2dGridEval_Circle,       // Circle curve
0069                                         Geom2dGridEval_Ellipse,      // Ellipse curve
0070                                         Geom2dGridEval_Hyperbola,    // Hyperbola curve
0071                                         Geom2dGridEval_Parabola,     // Parabola curve
0072                                         Geom2dGridEval_BezierCurve,  // Bezier curve
0073                                         Geom2dGridEval_BSplineCurve, // B-spline curve
0074                                         Geom2dGridEval_OffsetCurve,  // Offset curve
0075                                         Geom2dGridEval_OtherCurve>;  // Fallback for other types
0076 
0077   //! Construct from 2D adaptor reference (auto-detects curve type).
0078   //! For Geom2dAdaptor_Curve, extracts underlying Geom2d_Curve for optimized evaluation.
0079   //! For other adaptors, stores reference for fallback evaluation.
0080   //! @note The curve adaptor reference must remain valid during the lifetime
0081   //!       of this evaluator when using fallback evaluation.
0082   //! @param[in] theCurve 2D curve adaptor reference to evaluate
0083   Standard_EXPORT Geom2dGridEval_Curve(const Adaptor2d_Curve2d& theCurve);
0084 
0085   //! Construct from geometry handle (auto-detects curve type).
0086   //! @param[in] theCurve 2D geometry to evaluate
0087   Standard_EXPORT Geom2dGridEval_Curve(const occ::handle<Geom2d_Curve>& theCurve);
0088 
0089   //! Non-copyable and non-movable.
0090   Geom2dGridEval_Curve(const Geom2dGridEval_Curve&)            = delete;
0091   Geom2dGridEval_Curve& operator=(const Geom2dGridEval_Curve&) = delete;
0092   Geom2dGridEval_Curve(Geom2dGridEval_Curve&&)                 = delete;
0093   Geom2dGridEval_Curve& operator=(Geom2dGridEval_Curve&&)      = delete;
0094 
0095   //! Evaluate grid points at all parameters.
0096   //! @param theParams array of parameter values
0097   //! @return array of 2D points (1-based indexing)
0098   Standard_EXPORT NCollection_Array1<gp_Pnt2d> EvaluateGrid(
0099     const NCollection_Array1<double>& theParams) const;
0100 
0101   //! Evaluate grid points with first derivative.
0102   //! @param theParams array of parameter values
0103   //! @return array of CurveD1 (1-based indexing)
0104   Standard_EXPORT NCollection_Array1<Geom2dGridEval::CurveD1> EvaluateGridD1(
0105     const NCollection_Array1<double>& theParams) const;
0106 
0107   //! Evaluate grid points with first and second derivatives.
0108   //! @param theParams array of parameter values
0109   //! @return array of CurveD2 (1-based indexing)
0110   Standard_EXPORT NCollection_Array1<Geom2dGridEval::CurveD2> EvaluateGridD2(
0111     const NCollection_Array1<double>& theParams) const;
0112 
0113   //! Evaluate grid points with first, second, and third derivatives.
0114   //! @param theParams array of parameter values
0115   //! @return array of CurveD3 (1-based indexing)
0116   Standard_EXPORT NCollection_Array1<Geom2dGridEval::CurveD3> EvaluateGridD3(
0117     const NCollection_Array1<double>& theParams) const;
0118 
0119   //! Evaluate Nth derivative at all grid points.
0120   //! @param theParams array of parameter values
0121   //! @param theN derivative order (N >= 1)
0122   //! @return array of derivative vectors (1-based indexing)
0123   Standard_EXPORT NCollection_Array1<gp_Vec2d> EvaluateGridDN(
0124     const NCollection_Array1<double>& theParams,
0125     int                               theN) const;
0126 
0127   //! Returns the detected curve type.
0128   GeomAbs_CurveType GetType() const { return myCurveType; }
0129 
0130 protected:
0131   //! Initialize from 2D adaptor reference (auto-detects curve type).
0132   //! @param[in] theCurve 2D curve adaptor reference to evaluate
0133   Standard_EXPORT void initialization(const Adaptor2d_Curve2d& theCurve);
0134 
0135   //! Initialize from geometry handle (auto-detects curve type).
0136   //! @param[in] theCurve 2D geometry to evaluate
0137   Standard_EXPORT void initialization(const occ::handle<Geom2d_Curve>& theCurve);
0138 
0139 private:
0140   EvaluatorVariant  myEvaluator;
0141   GeomAbs_CurveType myCurveType;
0142 };
0143 
0144 #endif // _Geom2dGridEval_Curve_HeaderFile