Changeset 52:26851bc6daf6 in rrlib_geometry
 Timestamp:
 25.06.2013 19:28:25 (7 years ago)
 Branch:
 default
 Phase:
 public
 Location:
 curves
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

curves/tBSplineCurve.h
r51 r52 125 125 /*! Bezier control points used to evaluate bspline curve which is converted to a set of bezier curves */ 126 126 mutable std::vector<typename tShape::tPoint> bezier_control_point_cache; 127 mutable unsigned int number_of_segments; 127 128 128 129 /*! 
curves/tBSplineCurve.hpp
r51 r52 64 64 template <size_t Tdimension, typename TElement, unsigned int Tdegree> 65 65 tBSplineCurve<Tdimension, TElement, Tdegree>::tBSplineCurve() : 66 tSplineCurve() 66 tSplineCurve(), 67 number_of_segments(1) 67 68 { 68 69 this>CalculateKnotVector(); … … 72 73 template<typename TIterator, typename TKnotIterator> 73 74 tBSplineCurve<Tdimension, TElement, Tdegree>::tBSplineCurve(TIterator control_points_begin, TIterator control_points_end, TKnotIterator knots_begin, TKnotIterator knots_end) : 74 tSplineCurve(control_points_begin, control_points_end) 75 tSplineCurve(control_points_begin, control_points_end), 76 number_of_segments(1) 75 77 { 76 78 // copy knots … … 82 84 template<typename TIterator> 83 85 tBSplineCurve<Tdimension, TElement, Tdegree>::tBSplineCurve(TIterator begin, TIterator end) : 84 tSplineCurve(begin, end) 86 tSplineCurve(begin, end), 87 number_of_segments(1) 85 88 { 86 89 this>CalculateKnotVector(); … … 93 96 const unsigned int tBSplineCurve<Tdimension, TElement, Tdegree>::NumberOfSegments() const 94 97 { 95 unsigned int number_of_segments = 0; 96 typename tSplineCurve::tParameter current_knot = this>knots[0]; 97 for (size_t i = 1; i < this>knots.size(); ++i) 98 { 99 if (current_knot != this>knots[i]) 100 { 101 number_of_segments++; 102 current_knot = this>knots[i]; 103 } 104 } 105 return number_of_segments; 98 if (this>number_of_segments == static_cast<unsigned int>(1)) 99 { 100 this>number_of_segments = 0; 101 for (size_t i = 0; i < this>knots.size()  1; ++i) 102 { 103 if (this>knots[i] != this>knots[i + 1]) 104 { 105 this>number_of_segments++; 106 } 107 } 108 } 109 return this>number_of_segments; 106 110 }; 107 111 … … 115 119 this>CalculateKnotVector(); 116 120 this>bezier_control_point_cache.clear(); 121 this>number_of_segments = 1; 117 122 } 118 123 … … 211 216 { 212 217 assert((this>knots.front() <= t) && (t <= this>knots.back())); 213 auto it = std::lower_bound(this>knots.begin(), this>knots.end(), t); 214 215 return static_cast<unsigned int>(t == this>knots.front() ? 0 : std::distance(this>knots.begin(), it)  1); 218 assert(this>NumberOfSegments() > 0); 219 unsigned int segment = 0; 220 for (size_t i = 0; i < this>knots.size()  1; ++i) 221 { 222 if (this>knots[i] != this>knots[i + 1]) 223 { 224 if (this>knots[i + 1] > t) 225 { 226 return segment; 227 } 228 segment++; 229 } 230 } 231 assert(t == this>knots.back()); 232 return this>NumberOfSegments()  1; 216 233 } 217 234 … … 222 239 typename tSplineCurve<Tdimension, TElement, Tdegree>::tParameter tBSplineCurve<Tdimension, TElement, Tdegree>::GetLocalParameter(typename tSplineCurve::tParameter t) const 223 240 { 224 unsigned int start = this>GetSegmentForParameter(t); 225 unsigned int stop = start + 1; 226 while (this>knots[start] == this>knots[stop]) 227 { 228 stop++; 229 assert(stop < this>knots.size()); 230 } 231 return (t  this>knots[start]) / (this>knots[stop]  this>knots[start]); 241 assert((this>knots.front() <= t) && (t <= this>knots.back())); 242 assert(this>NumberOfSegments() > 0); 243 unsigned int segment = 0; 244 for (size_t i = 0; i < this>knots.size()  1; ++i) 245 { 246 if (this>knots[i] != this>knots[i + 1]) 247 { 248 if (this>knots[i + 1] > t) 249 { 250 return (t  this>knots[i]) / (this>knots[i + 1]  this>knots[i]); 251 } 252 segment++; 253 } 254 } 255 assert(t == this>knots.back()); 256 return 1; 232 257 } 233 258
Note: See TracChangeset
for help on using the changeset viewer.