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