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