Changeset 38:569a61ee1214 in rrlib_geometry
 Timestamp:
 23.04.2012 17:00:17 (8 years ago)
 Branch:
 default
 Phase:
 public
 Location:
 curves
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

curves/tBSplineCurve.h
r37 r38 69 69 // Class declaration 70 70 // 71 template < size_t Tdimension, typename TElement, unsigned int T Degree = 3 >72 class tBSplineCurve : public tSplineCurve<Tdimension, TElement, T Degree>71 template < size_t Tdimension, typename TElement, unsigned int Tdegree = 3 > 72 class tBSplineCurve : public tSplineCurve<Tdimension, TElement, Tdegree> 73 73 { 74 typedef geometry::tSplineCurve<Tdimension, TElement, T Degree> tSplineCurve;74 typedef geometry::tSplineCurve<Tdimension, TElement, Tdegree> tSplineCurve; 75 75 typedef geometry::tShape<Tdimension, TElement> tShape; 76 76 
curves/tBSplineCurve.hpp
r37 r38 62 62 // tBSplineCurve constructor 63 63 // 64 template<size_t T Dimension, typename TElement, unsigned int TDegree>64 template<size_t Tdimension, typename TElement, unsigned int Tdegree> 65 65 template<typename TIterator, typename TKnotIterator> 66 tBSplineCurve<T Dimension, TElement, TDegree>::tBSplineCurve(TIterator control_points_begin, TIterator control_points_end, TKnotIterator knots_begin, TKnotIterator knots_end) :66 tBSplineCurve<Tdimension, TElement, Tdegree>::tBSplineCurve(TIterator control_points_begin, TIterator control_points_end, TKnotIterator knots_begin, TKnotIterator knots_end) : 67 67 tSplineCurve(control_points_begin, control_points_end) 68 68 { 69 69 // copy knots 70 70 std::copy(knots_begin, knots_end, std::back_inserter(this>knots)); 71 assert(this>knots.size() == this>ControlPoints().size() + T Degree + 1);71 assert(this>knots.size() == this>ControlPoints().size() + Tdegree + 1); 72 72 this>CalculateBezierControlPoints(); 73 73 } 74 74 75 template<size_t T Dimension, typename TElement, unsigned int TDegree>75 template<size_t Tdimension, typename TElement, unsigned int Tdegree> 76 76 template<typename TIterator> 77 tBSplineCurve<T Dimension, TElement, TDegree>::tBSplineCurve(TIterator begin, TIterator end) :77 tBSplineCurve<Tdimension, TElement, Tdegree>::tBSplineCurve(TIterator begin, TIterator end) : 78 78 tSplineCurve(begin, end) 79 79 { … … 82 82 } 83 83 84 //template<size_t T Dimension, typename TElement, unsigned int TDegree>85 //void tBSplineCurve<T Dimension, TElement, TDegree>::AppendControlPoint(const typename tShape::tPoint &point)84 //template<size_t Tdimension, typename TElement, unsigned int Tdegree> 85 //void tBSplineCurve<Tdimension, TElement, Tdegree>::AppendControlPoint(const typename tShape::tPoint &point) 86 86 //{ 87 87 // tSplineCurve::AppendControlPoint(point); … … 101 101 } 102 102 103 template<size_t T Dimension, typename TElement, unsigned int TDegree>104 void tBSplineCurve<T Dimension, TElement, TDegree>::CalculateKnotVector()103 template<size_t Tdimension, typename TElement, unsigned int Tdegree> 104 void tBSplineCurve<Tdimension, TElement, Tdegree>::CalculateKnotVector() 105 105 { 106 106 this>knots.clear(); 107 assert(this>NumberOfControlPoints() > T Degree);107 assert(this>NumberOfControlPoints() > Tdegree); 108 108 // calculate knot vector 109 unsigned int length = this>NumberOfControlPoints() + T Degree + 1;109 unsigned int length = this>NumberOfControlPoints() + Tdegree + 1; 110 110 this>knots.reserve(length); 111 111 112 112 for (unsigned int i = 0; i < length; ++i) 113 113 { 114 if (i < T Degree + 1)114 if (i < Tdegree + 1) 115 115 { 116 116 this>knots.push_back(0); 117 117 } 118 else if ((T Degree + 1) <= i && i <= this>NumberOfControlPoints())118 else if ((Tdegree + 1) <= i && i <= this>NumberOfControlPoints()) 119 119 { 120 120 // inner knot vector (uniform) 121 this>knots.push_back(1.0 / (this>NumberOfControlPoints()  T Degree) * (i  TDegree));121 this>knots.push_back(1.0 / (this>NumberOfControlPoints()  Tdegree) * (i  Tdegree)); 122 122 } 123 123 else if (i > this>NumberOfControlPoints()) … … 128 128 } 129 129 130 template<size_t T Dimension, typename TElement, unsigned int TDegree>131 void tBSplineCurve<T Dimension, TElement, TDegree>::CalculateBezierControlPoints()130 template<size_t Tdimension, typename TElement, unsigned int Tdegree> 131 void tBSplineCurve<Tdimension, TElement, Tdegree>::CalculateBezierControlPoints() 132 132 { 133 133 this>bezier_control_points.clear(); 134 134 std::vector<double> new_knots; 135 new_knots.reserve(this>knots.size() * T Degree);135 new_knots.reserve(this>knots.size() * Tdegree); 136 136 std::copy(this>knots.begin(), this>knots.end(), std::back_inserter(new_knots)); 137 137 std::copy(this>ControlPoints().begin(), this>ControlPoints().end(), std::back_inserter(this>bezier_control_points)); … … 148 148 else 149 149 { 150 if (multiplicity < T Degree)150 if (multiplicity < Tdegree) 151 151 { 152 for (unsigned int s = multiplicity; s < T Degree; s++)152 for (unsigned int s = multiplicity; s < Tdegree; s++) 153 153 { 154 154 this>bezier_control_points = InsertKnot((it  new_knots.begin())  multiplicity, new_knots, knot, this>bezier_control_points); 155 155 new_knots.insert(it, knot); 156 156 } 157 it += T Degree  multiplicity;157 it += Tdegree  multiplicity; 158 158 } 159 159 if (it < new_knots.end()  1) … … 166 166 } 167 167 168 template<size_t Tdimension, typename TElement, unsigned int T Degree>169 std::vector<typename tBSplineCurve<Tdimension, TElement, T Degree>::tShape::tPoint> tBSplineCurve<Tdimension, TElement, TDegree>::InsertKnot(int at, const std::vector<double> &knots_before_insertion, double knot, const std::vector <168 template<size_t Tdimension, typename TElement, unsigned int Tdegree> 169 std::vector<typename tBSplineCurve<Tdimension, TElement, Tdegree>::tShape::tPoint> tBSplineCurve<Tdimension, TElement, Tdegree>::InsertKnot(int at, const std::vector<double> &knots_before_insertion, double knot, const std::vector < 170 170 typename tShape::tPoint > &control_points) const 171 171 { … … 173 173 new_control_points.reserve(control_points.size() + 1); 174 174 175 // copy unaffected points (index < atT Degree+1)176 std::copy(control_points.begin(), control_points.begin() + at  T Degree + 1, std::back_inserter(new_control_points));175 // copy unaffected points (index < atTdegree+1) 176 std::copy(control_points.begin(), control_points.begin() + at  Tdegree + 1, std::back_inserter(new_control_points)); 177 177 178 178 // recalculate control points affected by knot insertion 179 for (int i = at  T Degree + 1; i <= at; i++)180 { 181 double a = (knot  knots_before_insertion[i]) / (knots_before_insertion[i + T Degree]  knots_before_insertion[i]);179 for (int i = at  Tdegree + 1; i <= at; i++) 180 { 181 double a = (knot  knots_before_insertion[i]) / (knots_before_insertion[i + Tdegree]  knots_before_insertion[i]); 182 182 new_control_points.push_back((1  a) * control_points[i  1] + a * control_points[i]); 183 183 }
Note: See TracChangeset
for help on using the changeset viewer.