Changeset 6:c83d2ac2f52f in rrlib_geometry


Ignore:
Timestamp:
23.01.2011 02:42:23 (9 years ago)
Author:
Tobias Föhst <foehst@…>
Branch:
default
Phase:
public
Convert:
svn:2168a036-5f5f-4461-96ec-bf27dc59b608/trunk@7
Message:
  • Moved curves into subdirectory
  • Added checks for valid euclidean transformation matrices
  • Added default ctors
  • Added plane class (no intersections, yet)
Files:
3 added
6 edited
9 copied

Legend:

Unmodified
Added
Removed
  • curves/tBezierCurve.cpp

    r1 r6  
    2828 */ 
    2929//---------------------------------------------------------------------- 
    30 #include "rrlib/geometry/tBezierCurve.h" 
     30#include "rrlib/geometry/curves/tBezierCurve.h" 
    3131 
    3232//---------------------------------------------------------------------- 
     
    5959//---------------------------------------------------------------------- 
    6060 
    61 //template class tBezierCurve<2, float, 2>; 
    62 //template class tBezierCurve<2, float, 3>; 
    63 // 
    64 ////template class tBezierCurve<3, float, 2>; 
    65 //template class tBezierCurve<3, float, 3>; 
    66 // 
    67 //template class tBezierCurve<2, double, 2>; 
    68 //template class tBezierCurve<2, double, 3>; 
    69 // 
    70 ////template class tBezierCurve<3, double, 2>; 
    71 //template class tBezierCurve<3, double, 3>; 
     61template class tBezierCurve<2, float, 2>; 
     62template class tBezierCurve<2, float, 3>; 
     63 
     64template class tBezierCurve<3, float, 2>; 
     65template class tBezierCurve<3, float, 3>; 
     66 
     67template class tBezierCurve<2, double, 2>; 
     68template class tBezierCurve<2, double, 3>; 
     69 
     70template class tBezierCurve<3, double, 2>; 
     71template class tBezierCurve<3, double, 3>; 
  • curves/tBezierCurve.h

    r3 r6  
    3434 */ 
    3535//---------------------------------------------------------------------- 
    36 #ifndef _rrlib_geometry_tBezierCurve_h_ 
    37 #define _rrlib_geometry_tBezierCurve_h_ 
     36#ifndef _rrlib_geometry_curves_tBezierCurve_h_ 
     37#define _rrlib_geometry_curves_tBezierCurve_h_ 
    3838 
    3939#include "rrlib/geometry/tShape.h" 
     
    9292  typedef std::pair<tBezierCurve, tBezierCurve> tSubdivision; 
    9393 
    94   tBezierCurve(const std::vector<typename tShape::tPoint> &control_points); 
     94  template <typename TIterator> 
     95  tBezierCurve(TIterator begin, TIterator end); 
     96 
     97  template <typename TSTLContainer> 
     98  explicit tBezierCurve(const TSTLContainer &control_points); 
    9599 
    96100  inline const typename tShape::tPoint &GetControlPoint(size_t i) const 
     
    127131  typename tShape::tPoint control_points[Tdegree + 1]; 
    128132 
    129   tBezierCurve(const typename tShape::tPoint * const control_points); 
    130  
    131133  virtual void UpdateBoundingBox(typename tShape::tBoundingBox &bounding_box) const; 
    132134  virtual void UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const; 
     
    147149//---------------------------------------------------------------------- 
    148150 
    149 //extern template class tBezierCurve<2, float, 2>; 
    150 //extern template class tBezierCurve<2, float, 3>; 
    151 // 
    152 //extern template class tBezierCurve<3, float, 2>; 
    153 //extern template class tBezierCurve<3, float, 3>; 
    154 // 
    155 //extern template class tBezierCurve<2, double, 2>; 
    156 //extern template class tBezierCurve<2, double, 3>; 
    157 // 
    158 //extern template class tBezierCurve<3, double, 2>; 
    159 //extern template class tBezierCurve<3, double, 3>; 
     151extern template class tBezierCurve<2, float, 2>; 
     152extern template class tBezierCurve<2, float, 3>; 
     153 
     154extern template class tBezierCurve<3, float, 2>; 
     155extern template class tBezierCurve<3, float, 3>; 
     156 
     157extern template class tBezierCurve<2, double, 2>; 
     158extern template class tBezierCurve<2, double, 3>; 
     159 
     160extern template class tBezierCurve<3, double, 2>; 
     161extern template class tBezierCurve<3, double, 3>; 
    160162 
    161163//---------------------------------------------------------------------- 
     
    166168 
    167169 
    168 #include "rrlib/geometry/tBezierCurve.hpp" 
     170#include "rrlib/geometry/curves/tBezierCurve.hpp" 
    169171 
    170172#endif 
  • curves/tBezierCurve.hpp

    r4 r6  
    7171//---------------------------------------------------------------------- 
    7272template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
    73 tBezierCurve<Tdimension, TElement, Tdegree>::tBezierCurve(const std::vector<typename tShape::tPoint> &control_points) 
     73template <typename TIterator> 
     74tBezierCurve<Tdimension, TElement, Tdegree>::tBezierCurve(TIterator begin, TIterator end) 
    7475    : tShape() 
    7576{ 
    7677  static_assert(Tdegree > 0, "The degree of Bezier curves must be greater than zero"); 
    77   assert(control_points.size() == cNUMBER_OF_CONTROL_POINTS); 
    78   for (size_t i = 0; i < cNUMBER_OF_CONTROL_POINTS; ++i) 
     78  assert(static_cast<size_t>(std::distance(begin, end)) == this->cNUMBER_OF_CONTROL_POINTS); 
     79  size_t index = 0; 
     80  for (TIterator it = begin; it != end; ++it) 
     81  { 
     82    this->control_points[index++] = *it; 
     83  } 
     84} 
     85 
     86template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
     87template <typename TSTLContainer> 
     88tBezierCurve<Tdimension, TElement, Tdegree>::tBezierCurve(const TSTLContainer &control_points) 
     89{ 
     90  static_assert(Tdegree > 0, "The degree of Bezier curves must be greater than zero"); 
     91  assert(control_points.size() == this->cNUMBER_OF_CONTROL_POINTS); 
     92  for (size_t i = 0; i < control_points.size(); ++i) 
    7993  { 
    8094    this->control_points[i] = control_points[i]; 
     
    8296} 
    8397 
    84 template <size_t Tdimension, typename TElement, unsigned int Tdegree> 
    85 tBezierCurve<Tdimension, TElement, Tdegree>::tBezierCurve(const typename tShape::tPoint * const control_points) 
    86     : tShape() 
    87 { 
    88   static_assert(Tdegree > 0, "The degree of Bezier curves must be greater than zero"); 
    89   std::memcpy(this->control_points, control_points, cNUMBER_OF_CONTROL_POINTS * sizeof(typename tShape::tPoint)); 
    90 } 
    91  
    9298//---------------------------------------------------------------------- 
    9399// tBezierCurve SetControlPoint 
     
    96102void tBezierCurve<Tdimension, TElement, Tdegree>::SetControlPoint(size_t i, const typename tShape::tPoint &point) 
    97103{ 
    98   assert(i < cNUMBER_OF_CONTROL_POINTS); 
     104  assert(i < this->cNUMBER_OF_CONTROL_POINTS); 
    99105  this->control_points[i] = point; 
    100106  this->SetChanged(); 
     
    121127const typename tBezierCurve<Tdimension, TElement, Tdegree>::tSubdivision tBezierCurve<Tdimension, TElement, Tdegree>::GetSubdivision() const 
    122128{ 
    123   typename tShape::tPoint left_half[cNUMBER_OF_CONTROL_POINTS]; 
    124   typename tShape::tPoint right_half[cNUMBER_OF_CONTROL_POINTS]; 
    125   typename tShape::tPoint temp_points[cNUMBER_OF_CONTROL_POINTS]; 
    126   std::memcpy(temp_points, this->control_points, cNUMBER_OF_CONTROL_POINTS * sizeof(typename tShape::tPoint)); 
     129  typename tShape::tPoint left_half[this->cNUMBER_OF_CONTROL_POINTS]; 
     130  typename tShape::tPoint right_half[this->cNUMBER_OF_CONTROL_POINTS]; 
     131  typename tShape::tPoint temp_points[this->cNUMBER_OF_CONTROL_POINTS]; 
     132  std::memcpy(temp_points, this->control_points, this->cNUMBER_OF_CONTROL_POINTS * sizeof(typename tShape::tPoint)); 
    127133 
    128134  left_half[0] = temp_points[0]; 
     
    141147  } 
    142148 
    143   return std::make_pair(tBezierCurve(left_half), tBezierCurve(right_half)); 
     149  return std::make_pair(tBezierCurve(left_half, left_half + this->cNUMBER_OF_CONTROL_POINTS), tBezierCurve(right_half, right_half + this->cNUMBER_OF_CONTROL_POINTS)); 
    144150} 
    145151 
     
    152158  assert((0.0 <= t) && (t <= 1.0)); 
    153159 
    154   typename tShape::tPoint temp_points[cNUMBER_OF_CONTROL_POINTS]; 
    155   std::memcpy(temp_points, this->control_points, (cNUMBER_OF_CONTROL_POINTS) * sizeof(typename tShape::tPoint)); 
     160  typename tShape::tPoint temp_points[this->cNUMBER_OF_CONTROL_POINTS]; 
     161  std::memcpy(temp_points, this->control_points, (this->cNUMBER_OF_CONTROL_POINTS) * sizeof(typename tShape::tPoint)); 
    156162 
    157163  size_t k = 0; 
     
    179185    temp[i] = Tdegree * (this->control_points[i + 1] - this->control_points[i]); 
    180186  } 
    181   return tDerivative(temp); 
     187  return tDerivative(temp, temp + Tdegree); 
    182188} 
    183189 
     
    293299tBezierCurve<Tdimension, TElement, Tdegree> &tBezierCurve<Tdimension, TElement, Tdegree>::Translate(const math::tVector<Tdimension, TElement> &translation) 
    294300{ 
    295   for (size_t i = 0; i < cNUMBER_OF_CONTROL_POINTS; ++i) 
     301  for (size_t i = 0; i < this->cNUMBER_OF_CONTROL_POINTS; ++i) 
    296302  { 
    297303    this->control_points[i] += translation; 
     
    307313tBezierCurve<Tdimension, TElement, Tdegree> &tBezierCurve<Tdimension, TElement, Tdegree>::Rotate(const math::tMatrix<Tdimension, Tdimension, TElement> &rotation) 
    308314{ 
    309   for (size_t i = 0; i < cNUMBER_OF_CONTROL_POINTS; ++i) 
     315  for (size_t i = 0; i < this->cNUMBER_OF_CONTROL_POINTS; ++i) 
    310316  { 
    311317    this->control_points[i] = rotation * this->control_points[i]; 
     
    321327tBezierCurve<Tdimension, TElement, Tdegree> &tBezierCurve<Tdimension, TElement, Tdegree>::Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation) 
    322328{ 
    323   for (size_t i = 0; i < cNUMBER_OF_CONTROL_POINTS; ++i) 
     329#ifndef NDEBUG 
     330  for (size_t i = 0; i < Tdimension; ++i) 
     331  { 
     332    assert(math::IsEqual(transformation[Tdimension][i], 0)); 
     333  } 
     334  assert(math::IsEqual(transformation[Tdimension][Tdimension], 1)); 
     335  math::tMatrix<Tdimension, Tdimension, TElement> rotation; 
     336  for (size_t row = 0; row < Tdimension; ++row) 
     337  { 
     338    for (size_t column = 0; column < Tdimension; ++column) 
     339    { 
     340      rotation[row][column] = transformation[row][column]; 
     341    } 
     342  } 
     343  assert(math::IsEqual(rotation.Determinant(), 0)); 
     344#endif 
     345 
     346  for (size_t i = 0; i < this->cNUMBER_OF_CONTROL_POINTS; ++i) 
    324347  { 
    325348    this->control_points[i] = transformation.MultiplyHomogeneously(this->control_points[i]); 
     
    335358void tBezierCurve<Tdimension, TElement, Tdegree>::UpdateBoundingBox(typename tShape::tBoundingBox &bounding_box) const 
    336359{ 
    337   for (size_t i = 0; i < cNUMBER_OF_CONTROL_POINTS; ++i) 
     360  for (size_t i = 0; i < this->cNUMBER_OF_CONTROL_POINTS; ++i) 
    338361  { 
    339362    bounding_box.Add(this->control_points[i]); 
     
    347370void tBezierCurve<Tdimension, TElement, Tdegree>::UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const 
    348371{ 
    349   for (size_t i = 0; i < cNUMBER_OF_CONTROL_POINTS; ++i) 
     372  for (size_t i = 0; i < this->cNUMBER_OF_CONTROL_POINTS; ++i) 
    350373  { 
    351374    center_of_gravity += this->control_points[i]; 
    352375  } 
    353   center_of_gravity /= cNUMBER_OF_CONTROL_POINTS; 
     376  center_of_gravity /= this->cNUMBER_OF_CONTROL_POINTS; 
    354377} 
    355378 
  • curves/tCardinalSplineCurve.h

    r5 r6  
    3434 */ 
    3535//---------------------------------------------------------------------- 
    36 #ifndef _rrlib_geometry_tCardinalSplineCurve_h_ 
    37 #define _rrlib_geometry_tCardinalSplineCurve_h_ 
     36#ifndef _rrlib_geometry_curves_tCardinalSplineCurve_h_ 
     37#define _rrlib_geometry_curves_tCardinalSplineCurve_h_ 
    3838 
    39 #include "rrlib/geometry/tSplineCurve.h" 
     39#include "rrlib/geometry/curves/tSplineCurve.h" 
    4040//---------------------------------------------------------------------- 
    4141// External includes (system with <>, local with "") 
     
    111111 
    112112 
    113 #include "rrlib/geometry/tCardinalSplineCurve.hpp" 
     113#include "rrlib/geometry/curves/tCardinalSplineCurve.hpp" 
    114114 
    115115#endif 
  • curves/tSplineCurve.h

    r5 r6  
    3434 */ 
    3535//---------------------------------------------------------------------- 
    36 #ifndef _rrlib_geometry_tSplineCurve_h_ 
    37 #define _rrlib_geometry_tSplineCurve_h_ 
     36#ifndef _rrlib_geometry_curves_tSplineCurve_h_ 
     37#define _rrlib_geometry_curves_tSplineCurve_h_ 
    3838 
    3939#include "rrlib/geometry/tShape.h" 
     
    4545// Internal includes with "" 
    4646//---------------------------------------------------------------------- 
    47 #include "rrlib/geometry/tBezierCurve.h" 
     47#include "rrlib/geometry/curves/tBezierCurve.h" 
    4848 
    4949//---------------------------------------------------------------------- 
     
    157157 
    158158 
    159 #include "rrlib/geometry/tSplineCurve.hpp" 
     159#include "rrlib/geometry/curves/tSplineCurve.hpp" 
    160160 
    161161#endif 
  • curves/tSplineCurve.hpp

    r5 r6  
    257257tSplineCurve<Tdimension, TElement, Tdegree> &tSplineCurve<Tdimension, TElement, Tdegree>::Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation) 
    258258{ 
     259#ifndef NDEBUG 
     260  for (size_t i = 0; i < Tdimension; ++i) 
     261  { 
     262    assert(math::IsEqual(transformation[Tdimension][i], 0)); 
     263  } 
     264  assert(math::IsEqual(transformation[Tdimension][Tdimension], 1)); 
     265  math::tMatrix<Tdimension, Tdimension, TElement> rotation; 
     266  for (size_t row = 0; row < Tdimension; ++row) 
     267  { 
     268    for (size_t column = 0; column < Tdimension; ++column) 
     269    { 
     270      rotation[row][column] = transformation[row][column]; 
     271    } 
     272  } 
     273  assert(math::IsEqual(rotation.Determinant(), 0)); 
     274#endif 
     275 
    259276  for (typename std::vector<typename tShape::tPoint>::iterator it = this->control_points.begin(); it != this->control_points.end(); ++it) 
    260277  { 
  • curves/tUniformBSplineCurve.h

    r5 r6  
    3434 */ 
    3535//---------------------------------------------------------------------- 
    36 #ifndef _rrlib_geometry_tUniformBSplineCurve_h_ 
    37 #define _rrlib_geometry_tUniformBSplineCurve_h_ 
     36#ifndef _rrlib_geometry_curves_tUniformBSplineCurve_h_ 
     37#define _rrlib_geometry_curves_tUniformBSplineCurve_h_ 
    3838 
    39 #include "rrlib/geometry/tSplineCurve.h" 
     39#include "rrlib/geometry/curves/tSplineCurve.h" 
    4040//---------------------------------------------------------------------- 
    4141// External includes (system with <>, local with "") 
     
    111111 
    112112 
    113 #include "rrlib/geometry/tUniformBSplineCurve.hpp" 
     113#include "rrlib/geometry/curves/tUniformBSplineCurve.hpp" 
    114114 
    115115#endif 
  • curves/tUniformBSplineCurve.hpp

    r5 r6  
    9595const typename tSplineCurve<Tdimension, TElement, 3>::tBezierCurve tUniformBSplineCurve<Tdimension, TElement>::GetBezierCurveForSegment(unsigned int i) const 
    9696{ 
    97   std::vector<typename tShape::tPoint> bezier_control_points; 
     97  typename tShape::tPoint bezier_control_points[4]; 
    9898 
    99   bezier_control_points.push_back((1.0 - this->tension) / 4.0 *(this->GetControlPoint(i) + this->GetControlPoint(i + 2)) + (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 1)); 
    100   bezier_control_points.push_back((1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 1) + (1.0 - this->tension) / 2.0 * this->GetControlPoint(i + 2)); 
    101   bezier_control_points.push_back((1.0 - this->tension) / 2.0 * this->GetControlPoint(i + 1) + (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 2)); 
    102   bezier_control_points.push_back((1.0 - this->tension) / 4.0 *(this->GetControlPoint(i + 1) + this->GetControlPoint(i + 3)) + (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 2)); 
     99  bezier_control_points[0] = (1.0 - this->tension) / 4.0 * (this->GetControlPoint(i) + this->GetControlPoint(i + 2)) + (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 1); 
     100  bezier_control_points[1] = (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 1) + (1.0 - this->tension) / 2.0 * this->GetControlPoint(i + 2); 
     101  bezier_control_points[2] = (1.0 - this->tension) / 2.0 * this->GetControlPoint(i + 1) + (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 2); 
     102  bezier_control_points[3] = (1.0 - this->tension) / 4.0 * (this->GetControlPoint(i + 1) + this->GetControlPoint(i + 3)) + (1.0 + this->tension) / 2.0 * this->GetControlPoint(i + 2); 
    103103 
    104   return typename tSplineCurve::tBezierCurve(bezier_control_points); 
     104  return typename tSplineCurve::tBezierCurve(bezier_control_points, bezier_control_points + 4); 
    105105}; 
    106106 
  • make.xml

    r4 r6  
    44  <rrlib name="geometry"> 
    55    <sources> 
    6       tBezierCurve.cpp 
    76      tBoundingBox.h 
    8       tCardinalSplineCurve.h 
    97      tLine.cpp 
    108      tLineSegment.cpp 
     9      tPlane.cpp 
    1110      tPoint.cpp 
    1211      tShape.h 
    13       tSplineCurve.h 
    14       tUniformBSplineCurve.h 
     12      curves/* 
    1513    </sources> 
    1614  </rrlib> 
  • tLine.h

    r3 r6  
    8282  typedef typename tShape::tPoint::tElement tParameter; 
    8383 
     84  tLine(); 
    8485  tLine(const typename tShape::tPoint &support, const math::tVector<Tdimension, TElement> &direction); 
    8586  tLine(const typename tShape::tPoint &support, const typename tShape::tPoint &second_support); 
  • tLine.hpp

    r1 r6  
    7070//---------------------------------------------------------------------- 
    7171template <size_t Tdimension, typename TElement> 
     72tLine<Tdimension, TElement>::tLine() 
     73{ 
     74  this->direction[0] = 1; 
     75} 
     76 
     77template <size_t Tdimension, typename TElement> 
    7278tLine<Tdimension, TElement>::tLine(const typename tShape::tPoint &support, const math::tVector<Tdimension, TElement> &direction) 
    73     : tShape(), 
    74     support(support), 
     79    : support(support), 
    7580    direction(direction.Normalized()) 
    7681{} 
     
    7883template <size_t Tdimension, typename TElement> 
    7984tLine<Tdimension, TElement>::tLine(const typename tShape::tPoint &support, const typename tShape::tPoint &second_support) 
    80     : tShape(), 
    81     support(support), 
     85    : support(support), 
    8286    direction((second_support - support).Normalized()) 
    8387{} 
     
    231235tLine<Tdimension, TElement> &tLine<Tdimension, TElement>::Transform(const math::tMatrix < Tdimension + 1, Tdimension + 1, TElement > &transformation) 
    232236{ 
     237#ifndef NDEBUG 
    233238  for (size_t i = 0; i < Tdimension; ++i) 
    234239  { 
     
    236241  } 
    237242  assert(math::IsEqual(transformation[Tdimension][Tdimension], 1)); 
     243#endif 
    238244  math::tMatrix<Tdimension, Tdimension, TElement> rotation; 
    239245  for (size_t row = 0; row < Tdimension; ++row) 
     
    265271void tLine<Tdimension, TElement>::UpdateCenterOfGravity(typename tShape::tPoint &center_of_gravity) const 
    266272{ 
    267   this->GetNearestPoint(tShape::tPoint::Zero()); 
     273  center_of_gravity = this->GetNearestPoint(tShape::tPoint::Zero()); 
    268274} 
    269275 
  • tLineSegment.h

    r1 r6  
    8484public: 
    8585 
     86  tLineSegment(); 
    8687  tLineSegment(const typename tShape::tPoint &begin, const typename tShape::tPoint &end); 
    8788 
  • tLineSegment.hpp

    r1 r6  
    6666// tLineSegment constructors 
    6767//---------------------------------------------------------------------- 
     68template <size_t Tdimension, typename TElement> 
     69tLineSegment<Tdimension, TElement>::tLineSegment() 
     70{ 
     71  this->end[0] = 1; 
     72} 
     73 
    6874template <size_t Tdimension, typename TElement> 
    6975tLineSegment<Tdimension, TElement>::tLineSegment(const typename tShape::tPoint &begin, const typename tShape::tPoint &end) 
  • test/test_geometries.cpp

    r5 r6  
    4141#include "rrlib/geometry/tShape.h" 
    4242#include "rrlib/geometry/tLine.h" 
    43 #include "rrlib/geometry/tBezierCurve.h" 
    44 #include "rrlib/geometry/tUniformBSplineCurve.h" 
    45 #include "rrlib/geometry/tCardinalSplineCurve.h" 
     43#include "rrlib/geometry/curves/tBezierCurve.h" 
     44#include "rrlib/geometry/curves/tUniformBSplineCurve.h" 
     45#include "rrlib/geometry/curves/tCardinalSplineCurve.h" 
    4646 
    4747#include "rrlib/highgui_wrapper/tWindow.h" 
Note: See TracChangeset for help on using the changeset viewer.