Back to home page

EIC code displayed by LXR

 
 

    


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

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 _GeomGridEval_Curve_HeaderFile
0015 #define _GeomGridEval_Curve_HeaderFile
0016 
0017 #include <Adaptor3d_Curve.hxx>
0018 #include <GeomAbs_CurveType.hxx>
0019 #include <Geom_Curve.hxx>
0020 #include <GeomGridEval_BSplineCurve.hxx>
0021 #include <GeomGridEval_BezierCurve.hxx>
0022 #include <GeomGridEval_Circle.hxx>
0023 #include <GeomGridEval_Ellipse.hxx>
0024 #include <GeomGridEval_Hyperbola.hxx>
0025 #include <GeomGridEval_Line.hxx>
0026 #include <GeomGridEval_OffsetCurve.hxx>
0027 #include <GeomGridEval_OtherCurve.hxx>
0028 #include <GeomGridEval_Parabola.hxx>
0029 #include <gp_Pnt.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 3D 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 //! Adaptor3d_Curve 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_GridEvaluator
0050 //! - Other: Fallback using Adaptor3d_Curve::D0
0051 //!
0052 //! Usage:
0053 //! @code
0054 //!   GeomGridEval_Curve anEval(myAdaptorCurve);
0055 //!   // OR
0056 //!   GeomGridEval_Curve anEval(myGeomCurve);
0057 //!   NCollection_Array1<gp_Pnt> aGrid = anEval.EvaluateGrid(myParams);
0058 //! @endcode
0059 class GeomGridEval_Curve
0060 {
0061 public:
0062   DEFINE_STANDARD_ALLOC
0063 
0064   //! Variant type holding all possible curve evaluators.
0065   using EvaluatorVariant = std::variant<std::monostate,            // Uninitialized state
0066                                         GeomGridEval_Line,         // Line curve
0067                                         GeomGridEval_Circle,       // Circle curve
0068                                         GeomGridEval_Ellipse,      // Ellipse curve
0069                                         GeomGridEval_Hyperbola,    // Hyperbola curve
0070                                         GeomGridEval_Parabola,     // Parabola curve
0071                                         GeomGridEval_BezierCurve,  // Bezier curve
0072                                         GeomGridEval_BSplineCurve, // B-spline curve
0073                                         GeomGridEval_OffsetCurve,  // Offset curve
0074                                         GeomGridEval_OtherCurve>;  // Fallback for other types
0075 
0076   //! Construct from adaptor reference (auto-detects curve type).
0077   //! For GeomAdaptor_Curve, extracts underlying Geom_Curve for optimized evaluation.
0078   //! For other adaptors, stores reference for fallback evaluation.
0079   //! @note The curve adaptor reference must remain valid during the lifetime
0080   //!       of this evaluator when using fallback evaluation.
0081   //! @param[in] theCurve curve adaptor reference to evaluate
0082   Standard_EXPORT GeomGridEval_Curve(const Adaptor3d_Curve& theCurve);
0083 
0084   //! Construct from geometry handle (auto-detects curve type).
0085   //! @param[in] theCurve geometry to evaluate
0086   Standard_EXPORT GeomGridEval_Curve(const occ::handle<Geom_Curve>& theCurve);
0087 
0088   //! Non-copyable and non-movable.
0089   GeomGridEval_Curve(const GeomGridEval_Curve&)            = delete;
0090   GeomGridEval_Curve& operator=(const GeomGridEval_Curve&) = delete;
0091   GeomGridEval_Curve(GeomGridEval_Curve&&)                 = delete;
0092   GeomGridEval_Curve& operator=(GeomGridEval_Curve&&)      = delete;
0093 
0094   //! Evaluate grid points at all parameters.
0095   //! @param theParams array of parameter values
0096   //! @return array of 3D points (1-based indexing)
0097   Standard_EXPORT NCollection_Array1<gp_Pnt> EvaluateGrid(
0098     const NCollection_Array1<double>& theParams) const;
0099 
0100   //! Evaluate grid points with first derivative.
0101   //! @param theParams array of parameter values
0102   //! @return array of CurveD1 (1-based indexing)
0103   Standard_EXPORT NCollection_Array1<GeomGridEval::CurveD1> EvaluateGridD1(
0104     const NCollection_Array1<double>& theParams) const;
0105 
0106   //! Evaluate grid points with first and second derivatives.
0107   //! @param theParams array of parameter values
0108   //! @return array of CurveD2 (1-based indexing)
0109   Standard_EXPORT NCollection_Array1<GeomGridEval::CurveD2> EvaluateGridD2(
0110     const NCollection_Array1<double>& theParams) const;
0111 
0112   //! Evaluate grid points with first, second, and third derivatives.
0113   //! @param theParams array of parameter values
0114   //! @return array of CurveD3 (1-based indexing)
0115   Standard_EXPORT NCollection_Array1<GeomGridEval::CurveD3> EvaluateGridD3(
0116     const NCollection_Array1<double>& theParams) const;
0117 
0118   //! Evaluate Nth derivative at all grid points.
0119   //! @param theParams array of parameter values
0120   //! @param theN derivative order (N >= 1)
0121   //! @return array of derivative vectors (1-based indexing)
0122   Standard_EXPORT NCollection_Array1<gp_Vec> EvaluateGridDN(
0123     const NCollection_Array1<double>& theParams,
0124     int                               theN) const;
0125 
0126   //! Returns the detected curve type.
0127   GeomAbs_CurveType GetType() const { return myCurveType; }
0128 
0129 protected:
0130   //! Initialize from adaptor reference (auto-detects curve type).
0131   //! @param[in] theCurve curve adaptor reference to evaluate
0132   Standard_EXPORT void initialization(const Adaptor3d_Curve& theCurve);
0133 
0134   //! Initialize from geometry handle (auto-detects curve type).
0135   //! @param[in] theCurve geometry to evaluate
0136   Standard_EXPORT void initialization(const occ::handle<Geom_Curve>& theCurve);
0137 
0138 private:
0139   EvaluatorVariant  myEvaluator;
0140   GeomAbs_CurveType myCurveType;
0141 };
0142 
0143 #endif // _GeomGridEval_Curve_HeaderFile