Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Nurbs1D.cpp
1 /*
2  * Nurbs2D.cpp
3  *
4  * Created on: Jul 13, 2010
5  * Author: jordt
6  */
7 
8 #include <Base/Debug/Error.hh>
9 #include "Nurbs1D.hh"
10 #include <Base/Math/Vector2.hh>
11 #include <Base/Math/Vector3.hh>
12 #include <Base/Math/Vector4.hh>
13 #include <Base/Geometry/HomgPoint2D.hh>
14 #include <Base/Geometry/HomgPoint3D.hh>
15 #include <Base/Math/Operators.hh>
16 
17 #include "NurbsTemplateInit.hh"
18 
19 using namespace std;
20 using namespace BIAS;
21 
22 
23 // This function allocates and initializes the control point- and weight-arrays
24 template <class ControlPointsT>
25 Nurbs1D<ControlPointsT>::Nurbs1D(int knotsPerDim, int degree ) : NurbsBase(knotsPerDim,degree,1){
26 
27  // Allocate and initialize
28  controlPoints_ = new ControlPointsT[numCtrlPoints_];
29  weights_ = new double[numCtrlPoints_];
30 
31  for (int x = 0; x < numCtrlPoints_; x++){
33  weights_[x] = 1.0;
34  }
35 
36 
37 }
38 
39 
40 template <class ControlPointsT>
41 void Nurbs1D<ControlPointsT>::Eval(const double &nurbsParam, ControlPointsT &result) const {
42 
43  BIASASSERT(nurbsParam >= 0.0 && nurbsParam <= 1.0)
44 
45  // Initialize the return value
46  TemplateInit::Init(result);
47 
48  // Get the relevant control points
49  double weightSum = 0.0;
50  int relevantBegin;
51  int relevantEnd;
52  GetRelevantBaseCtrlPoints(nurbsParam, relevantBegin, relevantEnd);
53  double* baseFuncCache = new double[degree_+1];
54 
55  // Evaluate the relevant base functions and use them to wheight the
56  // control points
57  for (int x = relevantBegin; x <= relevantEnd; x++){
58  double weight = BaseFunc(0,x,degree_,nurbsParam,baseFuncCache)* weights_[x];
59  weightSum += weight;
60 
61  result += (weight * controlPoints_[x]);
62  }
63  if (weightSum != 0.0)
64  result = result * (1.0 / weightSum);
65 
66  delete[] baseFuncCache;
67 }
68 
69 
70 template <class ControlPointsT>
71 double Nurbs1D<ControlPointsT>::GetKnot(int index) const {
72  BIASASSERT(index >= 0 && index <= knotsPerDim_+1)
73  return knotVector_[0][index];
74 }
75 
76 template <class ControlPointsT>
77 void Nurbs1D<ControlPointsT>::SetKnot(int index, double value){
78  BIASASSERT(index >= 0 && index <= knotsPerDim_+1)
79  knotVector_[0][index] = value;
80 }
81 
82 namespace BIAS {
83 
84  // Implement NURBS1D for all common types of vectors:
85  template class Nurbs1D<double >;
86  template class Nurbs1D<Vector<double> >;
87  template class Nurbs1D<Vector2<double> >;
88  template class Nurbs1D<Vector3<double> >;
89  template class Nurbs1D<Vector4<double> >;
90  template class Nurbs1D<HomgPoint2D>;
91  template class Nurbs1D<HomgPoint3D>;
92 
93 }
94 
static void Init(double &value)
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
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
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