Changeset 47:73eab926c138 in rrlib_geometry


Ignore:
Timestamp:
21.05.2013 19:12:19 (7 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Message:

Added serialization operators for curves

Location:
curves
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • curves/tBSplineCurve.h

    r38 r47  
    7979//---------------------------------------------------------------------- 
    8080public: 
     81 
    8182  /*! 
    8283     * Construct a uniform B-spline using control points and a knot vector 
     
    9091  template <typename TIterator> 
    9192  tBSplineCurve(TIterator begin, TIterator end); 
     93 
     94  const std::vector<double> &Knots() const 
     95  { 
     96    return this->knots; 
     97  } 
     98 
     99  template <typename TIterator> 
     100  void SetKnots(TIterator begin, TIterator end) 
     101  { 
     102    this->knots.assign(begin, end); 
     103    this->CalculateBezierControlPoints(); 
     104  } 
    92105 
    93106//---------------------------------------------------------------------- 
     
    142155 
    143156//---------------------------------------------------------------------- 
     157// Operators for rrlib_serialization 
     158//---------------------------------------------------------------------- 
     159#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     160 
     161template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     162serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBSplineCurve<Tdimension, TElement, Tdegree> &spline); 
     163 
     164template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     165serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBSplineCurve<Tdimension, TElement, Tdegree> &spline); 
     166 
     167#endif 
     168 
     169//---------------------------------------------------------------------- 
    144170// End of namespace declaration 
    145171//---------------------------------------------------------------------- 
  • curves/tBSplineCurve.hpp

    r38 r47  
    228228} 
    229229 
     230//---------------------------------------------------------------------- 
     231// Operators for rrlib_serialization 
     232//---------------------------------------------------------------------- 
     233#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     234 
     235template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     236serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBSplineCurve<Tdimension, TElement, Tdegree> &spline) 
     237{ 
     238  stream << reinterpret_cast<const tSplineCurve<Tdimension, TElement, Tdegree> &>(spline); 
     239  stream << spline.Knots().size(); 
     240  for (size_t i = 0; i < spline.Knots().size(); ++i) 
     241  { 
     242    stream << spline.Knots()[i]; 
     243  } 
     244  return stream; 
     245} 
     246 
     247template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     248serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBSplineCurve<Tdimension, TElement, Tdegree> &spline) 
     249{ 
     250  stream >> reinterpret_cast<tSplineCurve<Tdimension, TElement, Tdegree> &>(spline); 
     251  size_t number_of_knots; 
     252  stream >> number_of_knots; 
     253  double knots[number_of_knots]; 
     254  for (size_t i = 0; i < number_of_knots; ++i) 
     255  { 
     256    stream >> knots[i]; 
     257  } 
     258  spline.SetKnots(knots, knots + number_of_knots); 
     259  return stream; 
     260} 
     261 
     262#endif 
    230263 
    231264//---------------------------------------------------------------------- 
  • curves/tBezierCurve.h

    r36 r47  
    4545#ifdef _LIB_RRLIB_CANVAS_PRESENT_ 
    4646#include "rrlib/canvas/tCanvas2D.h" 
     47#endif 
     48 
     49#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     50#include "rrlib/serialization/serialization.h" 
    4751#endif 
    4852 
     
    184188 
    185189//---------------------------------------------------------------------- 
     190// Operators for rrlib_serialization 
     191//---------------------------------------------------------------------- 
     192#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     193 
     194template < size_t Tdimension, typename TElement, unsigned int Tdegree = 3 > 
     195serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBezierCurve<Tdimension, TElement, Tdegree> &curve); 
     196 
     197template < size_t Tdimension, typename TElement, unsigned int Tdegree = 3 > 
     198serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBezierCurve<Tdimension, TElement, Tdegree> &curve); 
     199 
     200#endif 
     201 
     202//---------------------------------------------------------------------- 
    186203// End of namespace declaration 
    187204//---------------------------------------------------------------------- 
  • curves/tBezierCurve.hpp

    r45 r47  
    437437 
    438438//---------------------------------------------------------------------- 
     439// Operators for rrlib_serialization 
     440//---------------------------------------------------------------------- 
     441#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     442 
     443template < size_t Tdimension, typename TElement, unsigned int Tdegree> 
     444serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tBezierCurve<Tdimension, TElement, Tdegree> &curve) 
     445{ 
     446  for (size_t i = 0; i < curve.NumberOfControlPoints(); ++i) 
     447  { 
     448    stream << curve.ControlPoints()[i]; 
     449  } 
     450  return stream; 
     451} 
     452 
     453template < size_t Tdimension, typename TElement, unsigned int Tdegree> 
     454serialization::tInputStream &operator >> (serialization::tInputStream &stream, tBezierCurve<Tdimension, TElement, Tdegree> &curve) 
     455{ 
     456  for (size_t i = 0; i < curve.NumberOfControlPoints(); ++i) 
     457  { 
     458    typename tBezierCurve<Tdimension, TElement, Tdegree>::tPoint control_point; 
     459    stream >> control_point; 
     460    curve.SetControlPoint(i, control_point); 
     461  } 
     462  return stream; 
     463} 
     464 
     465#endif 
     466 
     467//---------------------------------------------------------------------- 
    439468// End of namespace declaration 
    440469//---------------------------------------------------------------------- 
  • curves/tSplineCurve.h

    r46 r47  
    4646#include "rrlib/canvas/tCanvas2D.h" 
    4747#include "rrlib/canvas/tCanvas3D.h" 
     48#endif 
     49 
     50#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     51#include "rrlib/serialization/serialization.h" 
    4852#endif 
    4953 
     
    124128  void InsertControlPoint(size_t position, const typename tShape::tPoint &point); 
    125129 
     130  template <typename TIterator> 
     131  void SetControlPoints(TIterator begin, TIterator end); 
     132 
    126133  const typename tShape::tPoint operator()(tParameter t) const; 
    127134 
     
    184191 
    185192//---------------------------------------------------------------------- 
     193// Operators for rrlib_serialization 
     194//---------------------------------------------------------------------- 
     195#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     196 
     197template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     198serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tSplineCurve<Tdimension, TElement, Tdegree> &spline); 
     199 
     200template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     201serialization::tInputStream &operator >> (serialization::tInputStream &stream, tSplineCurve<Tdimension, TElement, Tdegree> &spline); 
     202 
     203#endif 
     204 
     205//---------------------------------------------------------------------- 
    186206// End of namespace declaration 
    187207//---------------------------------------------------------------------- 
  • curves/tSplineCurve.hpp

    r45 r47  
    121121 
    122122//---------------------------------------------------------------------- 
     123// tSplineCurve SetControlPoints 
     124//---------------------------------------------------------------------- 
     125template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     126template <typename TIterator> 
     127void tSplineCurve<Tdimension, TElement, Tdegree>::SetControlPoints(TIterator begin, TIterator end) 
     128{ 
     129  this->control_points.assign(begin, end); 
     130  assert(this->control_points.size() > Tdegree && "A spline curve needs at least degree + 1 control points"); 
     131  this->SetChanged(); 
     132} 
     133 
     134//---------------------------------------------------------------------- 
    123135// tSplineCurve Evaluation: operator () 
    124136//---------------------------------------------------------------------- 
     
    376388 
    377389//---------------------------------------------------------------------- 
     390// Operators for rrlib_serialization 
     391//---------------------------------------------------------------------- 
     392#ifdef _LIB_RRLIB_SERIALIZATION_PRESENT_ 
     393 
     394template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     395serialization::tOutputStream &operator << (serialization::tOutputStream &stream, const tSplineCurve<Tdimension, TElement, Tdegree> &spline) 
     396{ 
     397  size_t number_of_control_points = spline.NumberOfControlPoints(); 
     398  stream << number_of_control_points; 
     399  for (size_t i = 0; i < number_of_control_points; ++i) 
     400  { 
     401    stream << spline.ControlPoints()[i]; 
     402  } 
     403  return stream; 
     404} 
     405 
     406template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     407serialization::tInputStream &operator >> (serialization::tInputStream &stream, tSplineCurve<Tdimension, TElement, Tdegree> &spline) 
     408{ 
     409  size_t number_of_control_points; 
     410  stream >> number_of_control_points; 
     411  tPoint<Tdimension, TElement> control_points[number_of_control_points]; 
     412  for (size_t i = 0; i < number_of_control_points; ++i) 
     413  { 
     414    stream >> control_points[i]; 
     415  } 
     416  spline.SetControlPoints(control_points, control_points + number_of_control_points); 
     417  return stream; 
     418} 
     419 
     420#endif 
     421 
     422//---------------------------------------------------------------------- 
    378423// End of namespace declaration 
    379424//---------------------------------------------------------------------- 
    380425} 
    381426} 
     427 
     428 
     429 
Note: See TracChangeset for help on using the changeset viewer.