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_HeaderFile
0015 #define _GeomGridEval_HeaderFile
0016 
0017 #include <Geom_Curve.hxx>
0018 #include <Geom_Surface.hxx>
0019 #include <gp_Pnt2d.hxx>
0020 #include <NCollection_Array1.hxx>
0021 #include <NCollection_Array2.hxx>
0022 
0023 //! @brief Namespace containing type aliases and template helpers for grid evaluators.
0024 //!
0025 //! Provides type aliases to common evaluation result structures defined in Geom_Curve and
0026 //! Geom_Surface and template helpers for iterating over parameter grids.
0027 namespace GeomGridEval
0028 {
0029 
0030 using CurveD1 = Geom_Curve::ResD1;
0031 using CurveD2 = Geom_Curve::ResD2;
0032 using CurveD3 = Geom_Curve::ResD3;
0033 using SurfD1  = Geom_Surface::ResD1;
0034 using SurfD2  = Geom_Surface::ResD2;
0035 using SurfD3  = Geom_Surface::ResD3;
0036 
0037 //=================================================================================================
0038 // Template helpers for parametric surface evaluation.
0039 // These provide the iteration pattern, while the actual computation is delegated to a functor.
0040 //=================================================================================================
0041 
0042 //! Evaluate grid points using a point evaluator functor.
0043 //! @tparam Evaluator functor type with operator()(double theU, double theV) -> gp_Pnt
0044 //! @param theUParams array of U parameter values
0045 //! @param theVParams array of V parameter values
0046 //! @param theEval evaluator functor
0047 //! @return 2D array of evaluated points (1-based indexing)
0048 template <typename Evaluator>
0049 NCollection_Array2<gp_Pnt> EvaluateGridHelper(const NCollection_Array1<double>& theUParams,
0050                                               const NCollection_Array1<double>& theVParams,
0051                                               Evaluator                         theEval)
0052 {
0053   const int aNbU = theUParams.Length();
0054   const int aNbV = theVParams.Length();
0055   if (aNbU == 0 || aNbV == 0)
0056   {
0057     return NCollection_Array2<gp_Pnt>();
0058   }
0059 
0060   NCollection_Array2<gp_Pnt> aResult(1, aNbU, 1, aNbV);
0061   for (int iU = 1; iU <= aNbU; ++iU)
0062   {
0063     const double aU = theUParams.Value(theUParams.Lower() + iU - 1);
0064     for (int iV = 1; iV <= aNbV; ++iV)
0065     {
0066       const double aV = theVParams.Value(theVParams.Lower() + iV - 1);
0067       aResult.SetValue(iU, iV, theEval(aU, aV));
0068     }
0069   }
0070   return aResult;
0071 }
0072 
0073 //! Evaluate grid points with D1 using an evaluator functor.
0074 //! @tparam Evaluator functor type with operator()(double theU, double theV) -> SurfD1
0075 template <typename Evaluator>
0076 NCollection_Array2<SurfD1> EvaluateGridD1Helper(const NCollection_Array1<double>& theUParams,
0077                                                 const NCollection_Array1<double>& theVParams,
0078                                                 Evaluator                         theEval)
0079 {
0080   const int aNbU = theUParams.Length();
0081   const int aNbV = theVParams.Length();
0082   if (aNbU == 0 || aNbV == 0)
0083   {
0084     return NCollection_Array2<SurfD1>();
0085   }
0086 
0087   NCollection_Array2<SurfD1> aResult(1, aNbU, 1, aNbV);
0088   for (int iU = 1; iU <= aNbU; ++iU)
0089   {
0090     const double aU = theUParams.Value(theUParams.Lower() + iU - 1);
0091     for (int iV = 1; iV <= aNbV; ++iV)
0092     {
0093       const double aV             = theVParams.Value(theVParams.Lower() + iV - 1);
0094       aResult.ChangeValue(iU, iV) = theEval(aU, aV);
0095     }
0096   }
0097   return aResult;
0098 }
0099 
0100 //! Evaluate grid points with D2 using an evaluator functor.
0101 //! @tparam Evaluator functor type with operator()(double theU, double theV) -> SurfD2
0102 template <typename Evaluator>
0103 NCollection_Array2<SurfD2> EvaluateGridD2Helper(const NCollection_Array1<double>& theUParams,
0104                                                 const NCollection_Array1<double>& theVParams,
0105                                                 Evaluator                         theEval)
0106 {
0107   const int aNbU = theUParams.Length();
0108   const int aNbV = theVParams.Length();
0109   if (aNbU == 0 || aNbV == 0)
0110   {
0111     return NCollection_Array2<SurfD2>();
0112   }
0113 
0114   NCollection_Array2<SurfD2> aResult(1, aNbU, 1, aNbV);
0115   for (int iU = 1; iU <= aNbU; ++iU)
0116   {
0117     const double aU = theUParams.Value(theUParams.Lower() + iU - 1);
0118     for (int iV = 1; iV <= aNbV; ++iV)
0119     {
0120       const double aV             = theVParams.Value(theVParams.Lower() + iV - 1);
0121       aResult.ChangeValue(iU, iV) = theEval(aU, aV);
0122     }
0123   }
0124   return aResult;
0125 }
0126 
0127 //! Evaluate grid points with D3 using an evaluator functor.
0128 //! @tparam Evaluator functor type with operator()(double theU, double theV) -> SurfD3
0129 template <typename Evaluator>
0130 NCollection_Array2<SurfD3> EvaluateGridD3Helper(const NCollection_Array1<double>& theUParams,
0131                                                 const NCollection_Array1<double>& theVParams,
0132                                                 Evaluator                         theEval)
0133 {
0134   const int aNbU = theUParams.Length();
0135   const int aNbV = theVParams.Length();
0136   if (aNbU == 0 || aNbV == 0)
0137   {
0138     return NCollection_Array2<SurfD3>();
0139   }
0140 
0141   NCollection_Array2<SurfD3> aResult(1, aNbU, 1, aNbV);
0142   for (int iU = 1; iU <= aNbU; ++iU)
0143   {
0144     const double aU = theUParams.Value(theUParams.Lower() + iU - 1);
0145     for (int iV = 1; iV <= aNbV; ++iV)
0146     {
0147       const double aV             = theVParams.Value(theVParams.Lower() + iV - 1);
0148       aResult.ChangeValue(iU, iV) = theEval(aU, aV);
0149     }
0150   }
0151   return aResult;
0152 }
0153 
0154 //! Evaluate grid DN using an evaluator functor.
0155 //! @tparam Evaluator functor type with operator()(double theU, double theV) -> gp_Vec
0156 template <typename Evaluator>
0157 NCollection_Array2<gp_Vec> EvaluateGridDNHelper(const NCollection_Array1<double>& theUParams,
0158                                                 const NCollection_Array1<double>& theVParams,
0159                                                 Evaluator                         theEval)
0160 {
0161   const int aNbU = theUParams.Length();
0162   const int aNbV = theVParams.Length();
0163   if (aNbU == 0 || aNbV == 0)
0164   {
0165     return NCollection_Array2<gp_Vec>();
0166   }
0167 
0168   NCollection_Array2<gp_Vec> aResult(1, aNbU, 1, aNbV);
0169   for (int iU = 1; iU <= aNbU; ++iU)
0170   {
0171     const double aU = theUParams.Value(theUParams.Lower() + iU - 1);
0172     for (int iV = 1; iV <= aNbV; ++iV)
0173     {
0174       const double aV = theVParams.Value(theVParams.Lower() + iV - 1);
0175       aResult.SetValue(iU, iV, theEval(aU, aV));
0176     }
0177   }
0178   return aResult;
0179 }
0180 
0181 } // namespace GeomGridEval
0182 
0183 #endif // _GeomGridEval_HeaderFile