Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
NurbsBase.cpp
1 /*
2  * NurbsBase.cpp
3  *
4  * Created on: Jul 1, 2010
5  * Author: jordt
6  */
7 #include <Base/Debug/Error.hh>
8 #include "NurbsBase.hh"
9 #include "iostream"
10 #include <cmath>
11 #include <cstdlib>
12 
13 using namespace std;
14 using namespace BIAS;
15 
16 NurbsBase::NurbsBase(int knotsPerDim, int degree, int dimension){
17 
18  knotsPerDim_ = knotsPerDim;
19  degree_ = degree;
20  vector<double> kVec;
21  for(int i = 0; i < degree; i++) kVec.push_back(0.0);
22  for(int i = 0; i < knotsPerDim ; i++) kVec.push_back((double)i / (double)(knotsPerDim-1));
23  for(int i = 0; i < degree; i++) kVec.push_back(1.0);
24  for(int d = 0; d < dimension; d++) knotVector_.push_back(kVec);
25  #ifndef NURBS_BASE_THREAD_SAFE
26  evalCache_.resize(degree+1);
27  #endif //NURBS_BASE_THREAD_SAFE
28 
29  numCtrlPoints_ = knotsPerDim+degree_-1;
30 
31 }
32 
33 #ifdef NURBS_BASE_RECURSIVE_EVALUATION
34 // The classic evaluation function
35 /*
36 double NurbsBase::BaseFunc(const int &dim, const int &knot, const int &degree, const double &u) const{
37 
38  if (degree == 0){
39  if (u < knotVector_[dim][knot]) return 0.0;
40  if (u > knotVector_[dim][knot+1]) return 0.0;
41  if (u == knotVector_[dim][knot+1] && u != 1.0) return 0.0;
42  return 1.0;
43  }
44 
45  double recursiveA = 0.0;
46  if (knotVector_[dim][knot+degree] != knotVector_[dim][knot])
47  recursiveA = (u - knotVector_[dim][knot]) / (knotVector_[dim][knot+degree]-knotVector_[dim][knot]) * BaseFunc(dim,knot,degree - 1,u);
48 
49  double recursiveB = 0.0;
50  if (knotVector_[dim][knot+degree+1] != knotVector_[dim][knot+1])
51  recursiveB = (knotVector_[dim][knot+degree+1]-u) / (knotVector_[dim][knot+degree+1]-knotVector_[dim][knot+1]) * BaseFunc(dim,knot+1,degree - 1,u);
52 
53  return recursiveA + recursiveB;
54 }*/
55 #endif
56 
57 int NurbsBase::GetNumKnots() const {
58  return knotsPerDim_;
59 }
60 
61 int NurbsBase::GetDegree() const {
62  return degree_;
63 }
64 
65 int NurbsBase::GetNumCtrlPts() const {
66  return numCtrlPoints_;
67 }
68 
69 double NurbsBase::GetKnot(int dim, int index) const {
70  BIASASSERT(dim >= 0 && dim < (int)knotVector_.size())
71  BIASASSERT(index >= 0 && index <= knotsPerDim_+1)
72  return knotVector_[dim][index];
73 }
74 
75 void NurbsBase::SetKnot(int dim, int index, double value){
76  BIASASSERT(dim >= 0 && dim < (int)knotVector_.size())
77  BIASASSERT(index >= 0 && index <= knotsPerDim_+1)
78  knotVector_[dim][index] = value;
79 }
80 
81