Changeset 51:0d26d6c7f188 in rrlib_geometry


Ignore:
Timestamp:
25.06.2013 18:48:45 (6 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Adjusted knot type in tBSplineCurve and changed bezier_curve_cache to not being populated before used

Location:
curves
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • curves/tBSplineCurve.h

    r50 r51  
    9696  virtual const unsigned int NumberOfSegments() const; 
    9797 
    98   const std::vector<double> &Knots() const 
     98  const std::vector<typename tSplineCurve::tParameter> &Knots() const 
    9999  { 
    100100    return this->knots; 
     
    122122private: 
    123123  /*! B-spline knot vector (#knots = #control points + degree + 1) */ 
    124   std::vector<double> knots; 
     124  std::vector<typename tSplineCurve::tParameter> knots; 
    125125  /*! Bezier control points used to evaluate b-spline curve which is converted to a set of bezier curves  */ 
    126   std::vector<typename tShape::tPoint> bezier_control_points; 
     126  mutable std::vector<typename tShape::tPoint> bezier_control_point_cache; 
    127127 
    128128  /*! 
     
    134134   * Calculate all Bezier control points by knot insertion, this->bezier_control_points will be modified 
    135135   */ 
    136   void CalculateBezierControlPoints(); 
     136  void CalculateBezierControlPoints() const; 
    137137 
    138138  /*! 
     
    144144   * @return Control points after knot insertion 
    145145   */ 
    146   std::vector<typename tShape::tPoint> InsertKnot(int at, const std::vector<double> &knots_before_insertion, double knot, const std::vector<typename tShape::tPoint> &control_points) const; 
     146  static std::vector<typename tShape::tPoint> InsertKnot(int at, const std::vector<typename tSplineCurve::tParameter> &knots_before_insertion, typename tSplineCurve::tParameter knot, const std::vector<typename tShape::tPoint> &control_points); 
    147147 
    148148  virtual unsigned int GetSegmentForParameter(typename tSplineCurve::tParameter t) const; 
  • curves/tBSplineCurve.hpp

    r50 r51  
    6767{ 
    6868  this->CalculateKnotVector(); 
    69   this->CalculateBezierControlPoints(); 
    7069} 
    7170 
     
    7877  std::copy(knots_begin, knots_end, std::back_inserter(this->knots)); 
    7978  assert(this->knots.size() == this->ControlPoints().size() + Tdegree + 1); 
    80   this->CalculateBezierControlPoints(); 
    8179} 
    8280 
     
    8785{ 
    8886  this->CalculateKnotVector(); 
    89   this->CalculateBezierControlPoints(); 
    9087} 
    9188 
     
    9794{ 
    9895  unsigned int number_of_segments = 0; 
    99   double current_knot = this->knots[0]; 
     96  typename tSplineCurve::tParameter current_knot = this->knots[0]; 
    10097  for (size_t i = 1; i < this->knots.size(); ++i) 
    10198  { 
     
    109106}; 
    110107 
    111 //template<size_t Tdimension, typename TElement, unsigned int Tdegree> 
    112 //void tBSplineCurve<Tdimension, TElement, Tdegree>::AppendControlPoint(const typename tShape::tPoint &point) 
    113 //{ 
    114 //  tSplineCurve::AppendControlPoint(point); 
    115 //  this->CalculateKnotVector(); 
    116 //  this->CalculateBezierControlPoints(); 
    117 //} 
    118 // 
    119108//---------------------------------------------------------------------- 
    120109// tBSplineCurve SetChanged 
     
    125114  tSplineCurve::SetChanged(); 
    126115  this->CalculateKnotVector(); 
    127   this->CalculateBezierControlPoints(); 
     116  this->bezier_control_point_cache.clear(); 
    128117} 
    129118 
     
    156145 
    157146template<size_t Tdimension, typename TElement, unsigned int Tdegree> 
    158 void tBSplineCurve<Tdimension, TElement, Tdegree>::CalculateBezierControlPoints() 
    159 { 
    160   this->bezier_control_points.clear(); 
    161   std::vector<double> new_knots; 
     147void tBSplineCurve<Tdimension, TElement, Tdegree>::CalculateBezierControlPoints() const 
     148{ 
     149  this->bezier_control_point_cache.clear(); 
     150  std::vector<typename tSplineCurve::tParameter> new_knots; 
    162151  new_knots.reserve(this->knots.size() * Tdegree); 
    163152  std::copy(this->knots.begin(), this->knots.end(), std::back_inserter(new_knots)); 
    164   std::copy(this->ControlPoints().begin(), this->ControlPoints().end(), std::back_inserter(this->bezier_control_points)); 
    165  
    166   double knot = new_knots[0]; 
     153  std::copy(this->ControlPoints().begin(), this->ControlPoints().end(), std::back_inserter(this->bezier_control_point_cache)); 
     154 
     155  typename tSplineCurve::tParameter knot = new_knots[0]; 
    167156  unsigned int multiplicity = 1; 
    168157 
    169   for (std::vector<double>::iterator it = (++new_knots.begin()); it < new_knots.end(); ++it) 
     158  for (auto it = (++new_knots.begin()); it < new_knots.end(); ++it) 
    170159  { 
    171160    if (knot == *it) 
     
    179168        for (unsigned int s = multiplicity; s < Tdegree; s++) 
    180169        { 
    181           this->bezier_control_points = InsertKnot((it - new_knots.begin()) - multiplicity, new_knots, knot, this->bezier_control_points); 
     170          this->bezier_control_point_cache = InsertKnot((it - new_knots.begin()) - multiplicity, new_knots, knot, this->bezier_control_point_cache); 
    182171          new_knots.insert(it, knot); 
    183172        } 
     
    194183 
    195184template<size_t Tdimension, typename TElement, unsigned int Tdegree> 
    196 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 < 
    197     typename tShape::tPoint > &control_points) const 
     185std::vector<typename tBSplineCurve<Tdimension, TElement, Tdegree>::tShape::tPoint> tBSplineCurve<Tdimension, TElement, Tdegree>::InsertKnot(int at, const std::vector<typename tSplineCurve::tParameter> &knots_before_insertion, typename tSplineCurve::tParameter knot, const std::vector<typename tShape::tPoint> &control_points) 
    198186{ 
    199187  std::vector<typename tShape::tPoint> new_control_points; 
     
    206194  for (int i = at - Tdegree + 1; i <= at; i++) 
    207195  { 
    208     double a = (knot - knots_before_insertion[i]) / (knots_before_insertion[i + Tdegree] - knots_before_insertion[i]); 
     196    typename tSplineCurve::tParameter a = (knot - knots_before_insertion[i]) / (knots_before_insertion[i + Tdegree] - knots_before_insertion[i]); 
    209197    new_control_points.push_back((1 - a) * control_points[i - 1] + a * control_points[i]); 
    210198  } 
     
    250238std::shared_ptr<const typename tSplineCurve<Tdimension, TElement, Tdegree>::tBezierCurve> tBSplineCurve<Tdimension, TElement, Tdegree>::CreateBezierCurveForSegment(unsigned int i) const 
    251239{ 
     240  if (this->bezier_control_point_cache.empty()) 
     241  { 
     242    this->CalculateBezierControlPoints(); 
     243  } 
    252244  std::vector<typename tShape::tPoint> segment_control_points; 
    253   std::copy(this->bezier_control_points.begin() + i * Tdegree, this->bezier_control_points.begin() + i * Tdegree + Tdegree + 1, std::back_inserter(segment_control_points)); 
     245  std::copy(this->bezier_control_point_cache.begin() + i * Tdegree, this->bezier_control_point_cache.begin() + i * Tdegree + Tdegree + 1, std::back_inserter(segment_control_points)); 
    254246  return std::shared_ptr<const typename tSplineCurve::tBezierCurve>(new typename tSplineCurve::tBezierCurve(segment_control_points.begin(), segment_control_points.end())); 
    255247} 
     
    278270  size_t number_of_knots; 
    279271  stream >> number_of_knots; 
    280   double knots[number_of_knots]; 
     272  typename tSplineCurve<Tdimension, TElement, Tdegree>::tParameter knots[number_of_knots]; 
    281273  for (size_t i = 0; i < number_of_knots; ++i) 
    282274  { 
  • curves/tSplineCurve.hpp

    r49 r51  
    7272  static_assert(Tdegree > 0, "The degree of spline curves must be greater than zero"); 
    7373  assert(control_points.size() > Tdegree && "A spline curve needs at least degree + 1 control points"); 
    74   this->bezier_curve_cache.resize(this->NumberOfSegments()); 
    7574} 
    7675 
     
    8281  std::copy(begin, end, std::back_inserter(this->control_points)); 
    8382  assert(control_points.size() > Tdegree && "A spline curve needs at least degree + 1 control points"); 
    84   this->bezier_curve_cache.resize(this->NumberOfSegments()); 
    8583} 
    8684 
     
    9290  static_assert(sizeof...(rest) + 2 > Tdegree, "A spline curve needs at least degree + 1 control points"); 
    9391  util::ProcessVariadicValues<typename tShape::tPoint>([this](const typename tShape::tPoint & x) mutable { this->control_points.push_back(x); }, p1, p2, rest...); 
    94   this->bezier_curve_cache.resize(this->NumberOfSegments()); 
    9592} 
    9693 
     
    123120  this->control_points.push_back(point); 
    124121  this->SetChanged(); 
    125   this->bezier_curve_cache.emplace_back(); 
    126122}; 
    127123 
     
    135131  this->control_points.insert(this->control_points.begin() + position, point); 
    136132  this->SetChanged(); 
    137   this->bezier_curve_cache.emplace_back(); 
    138133}; 
    139134 
     
    184179{ 
    185180  assert(i < this->NumberOfSegments()); 
    186   assert(this->bezier_curve_cache.size() == this->NumberOfSegments()); 
     181  this->bezier_curve_cache.resize(this->NumberOfSegments()); 
    187182  if (!this->bezier_curve_cache[i]) 
    188183  { 
Note: See TracChangeset for help on using the changeset viewer.