Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Nurbs2D.hh
1 /*
2  * NurbsBase.hh
3  *
4  * Created on: Jul 13, 2010
5  * Author: jordt
6  */
7 
8 #ifndef NURBS2D_HH
9 #define NURBS2D_HH
10 
11 #include <Base/Math/Vector2.hh>
12 #include "NurbsBase.hh"
13 
14 namespace BIAS{
15 
16  /** This class implements a NURBS-function with a two dimensional
17  * parameter space (A NURBS surface). The dimension of the output
18  * values is defined by the template type of control points
19  * @author jordt
20  */
21 
22  template <class ControlPointsT>
23  class Nurbs2D : public NurbsBase {
24 
25  public:
26 
27  /// Standard Constructor
28  /// @param knotsPerDim The number of knots in the knot vector (without the dublications)
29  /// @param degree The degree of the b-splines
30  Nurbs2D(int knotsPerDim = 4, int degree = 2);
31 
32  /// Evaluate the NURBS function at a given point in the parameter space
33  /// @param nurbsParam Point in the parameter space ( [0,0] - [1,1] )
34  /// @param result The return value
35  void Eval(const BIAS::Vector2<double> &nurbsParam, ControlPointsT &result) const;
36 
37  /// Evaluate the NURBS function at a given point in the parameter space
38  /// for a certain control point vector (helpfull for optimization)
39  /// @param nurbsParam Point in the parameter space ( [0,0] - [1,1] )
40  /// @param result The return value
41  void EvalCustom(const BIAS::Vector2<double> &nurbsParam, ControlPointsT &result, const ControlPointsT** controlPoints) const;
42 
43  /// Very generic initialization function for the control points. The control points
44  /// will be distributed equally over the cube defined by the min-max values.
45  void Init(const ControlPointsT minX,const ControlPointsT maxX,
46  const ControlPointsT minY,const ControlPointsT maxY);
47 
48  protected:
49 
50  /// The array of control points
51  ControlPointsT** controlPoints_;
52 
53  /// The corresponding weights to the function points
54  double ** weights_;
55 
56  // Some inline functions:
57 
58  public:
59 
60  /// Set the value of a specific control point. No out of bounds checks are
61  /// performed in release builds
62  /// @param indexU The u index of the control point
63  /// @param indexV The v index of the control point
64  /// @param value The value that is assigned to the control point
65  inline void SetCtrlPoint(const int &indexU,const int &indexV, const ControlPointsT &value){
66  BIASASSERT(indexU >= 0);
67  BIASASSERT(indexU < numCtrlPoints_);
68  BIASASSERT(indexV >= 0);
69  BIASASSERT(indexV < numCtrlPoints_);
70  controlPoints_[indexU][indexV] = value;
71  }
72 
73  /// Get the value of a specific control point. No out of bounds checks are
74  /// performed in release builds
75  /// @param indexU The u index of the control point
76  /// @param indexV The v index of the control point
77  inline ControlPointsT GetCtrlPoint(const int &indexU,const int &indexV) const{
78  BIASASSERT(indexU >= 0);
79  BIASASSERT(indexU < numCtrlPoints_);
80  BIASASSERT(indexV >= 0);
81  BIASASSERT(indexV < numCtrlPoints_);
82  return controlPoints_[indexU][indexV];
83  }
84 
85  /// Evaluate the base function for the control point for the point nurbsParam.
86  inline void EvalBaseFunc(const int x,const int y,const BIAS::Vector2<double> &nurbsParam, double &result) const{
87  result = (BaseFunc(0,x,degree_,nurbsParam[0])*BaseFunc(1,y,degree_,nurbsParam[1]));
88  }
89 
90  /// Evaluate the base function for the control point for the point nurbsParam using
91  /// a dedicated cache for the serial evaluation
92  inline void EvalBaseFunc(const int x,const int y,const BIAS::Vector2<double> &nurbsParam, double &result, double* baseFuncCache) const{
93  result = (BaseFunc(0,x,degree_,nurbsParam[0],baseFuncCache)*BaseFunc(1,y,degree_,nurbsParam[1],baseFuncCache));
94  }
95 
96  /// for a given point in the parameter space, this functions yields for each dimension the first and
97  /// the last control point index influencing the value at this position.
98  /// @param nurbsParam The point in the parameter space to perform the test in
99  /// @param begin The first control point (indices)
100  /// @param end The last control points (indices)
101  inline void GetRelevantBaseCtrlPoints(const BIAS::Vector2<double> &nurbsParam, BIAS::Vector2<int> &begin, BIAS::Vector2<int> &end) const{
102  for (int i = 0; i < 2; i++){
103  begin[i] = 0;
104  for (int j = 0; j < numCtrlPoints_-degree_; j++)
105  if (nurbsParam[i] >= knotVector_[i][j+degree_])
106  begin[i] = j;
107  else
108  break;
109  end[i] = numCtrlPoints_-1;
110  for (int j = numCtrlPoints_-1; j >= degree_; j--)
111  if (nurbsParam[i] <= knotVector_[i][j-degree_])
112  end[i] = j;
113  }
114  };
115 
116  };
117 
118 }
119 
120 #endif // NURBS2D_HH
double ** weights_
The corresponding weights to the function points.
Definition: Nurbs2D.hh:54
void GetRelevantBaseCtrlPoints(const BIAS::Vector2< double > &nurbsParam, BIAS::Vector2< int > &begin, BIAS::Vector2< int > &end) const
for a given point in the parameter space, this functions yields for each dimension the first and the ...
Definition: Nurbs2D.hh:101
int degree_
Degree of the b-splines.
Definition: NurbsBase.hh:68
void EvalCustom(const BIAS::Vector2< double > &nurbsParam, ControlPointsT &result, const ControlPointsT **controlPoints) const
Evaluate the NURBS function at a given point in the parameter space for a certain control point vecto...
Definition: Nurbs2D.cpp:78
ControlPointsT GetCtrlPoint(const int &indexU, const int &indexV) const
Get the value of a specific control point.
Definition: Nurbs2D.hh:77
void Eval(const BIAS::Vector2< double > &nurbsParam, ControlPointsT &result) const
Evaluate the NURBS function at a given point in the parameter space.
Definition: Nurbs2D.cpp:42
double BaseFunc(const int &dim, const int &knot, const int &degree, const double &u) const
This is a serial implementation of the recursive nurbs evaluation.
Definition: NurbsBase.hh:108
ControlPointsT ** controlPoints_
The array of control points.
Definition: Nurbs2D.hh:51
This class implements a NURBS-function with a two dimensional parameter space (A NURBS surface)...
Definition: Nurbs2D.hh:23
void EvalBaseFunc(const int x, const int y, const BIAS::Vector2< double > &nurbsParam, double &result, double *baseFuncCache) const
Evaluate the base function for the control point for the point nurbsParam using a dedicated cache for...
Definition: Nurbs2D.hh:92
void SetCtrlPoint(const int &indexU, const int &indexV, const ControlPointsT &value)
Set the value of a specific control point.
Definition: Nurbs2D.hh:65
Base class for NURBS classes.
Definition: NurbsBase.hh:29
std::vector< std::vector< double > > knotVector_
The vector of knot vectors (One for each dimension)
Definition: NurbsBase.hh:62
Nurbs2D(int knotsPerDim=4, int degree=2)
Standard Constructor.
Definition: Nurbs2D.cpp:24
void Init(const ControlPointsT minX, const ControlPointsT maxX, const ControlPointsT minY, const ControlPointsT maxY)
Very generic initialization function for the control points.
Definition: Nurbs2D.cpp:111
int numCtrlPoints_
The number of control points per dimension.
Definition: NurbsBase.hh:71
void EvalBaseFunc(const int x, const int y, const BIAS::Vector2< double > &nurbsParam, double &result) const
Evaluate the base function for the control point for the point nurbsParam.
Definition: Nurbs2D.hh:86