DGtal  1.5.beta
CDLR_naiverotation.h
1 
18 #pragma once
19 
29 #if defined(CDLR_NAIVEROTATION_RECURSES)
30 #error Recursive header files inclusion detected in RDSL.h
31 #else // defined(CDLR_NAIVEROTATION_RECURSES)
33 #define CDLR_NAIVEROTATION_RECURSES
34 
35 #if !defined CDLR_NAIVEROTATION_h
37 #define CDLR_NAIVEROTATION_h
38 
39 #include "DGtal/base/Common.h"
40 #include <DGtal/images/RigidTransformation2D.h>
41 #include "PointUtils.h"
42 #include "DigitizedReflection.h"
43 
44 namespace DGtal {
45 
46 
47  template < typename TSpace, typename TInputValue = typename TSpace::Point, typename TOutputValue = typename TSpace::Point>
49 
50  inline int X(int y, const double a, const double b, const int k) const {
51  return std::ceil((2.0*k-1)/2.0 - (a/b)*(y)); // a = sin(theta) ; b=cos(theta)
52  }
53 
54  TOutputValue reflect(const double angle, TOutputValue center, const TInputValue& p ) const{
55  double a = std::sin(angle/2.0);
56  double b = std::cos(angle/2.0);
57  TOutputValue pcentered = p;
58 
59  int k = std::floor(pcentered[0] + (a/b)*pcentered[1] + 0.5);
60 
61  TOutputValue X1 = TOutputValue(X(std::ceil(a*b*k),a,b,k),std::ceil(a*b*k));
62  TOutputValue X2 = TOutputValue(X(std::floor(a*b*k),a,b,k),std::floor(a*b*k));
63 
64  const double line2 = a*X1[0]-b*X1[1];
65  if(line2<b/2 && line2 >(-b/2)){
66  return TOutputValue(X(2*X1[1]-pcentered[1],a,b,k),2*X1[1]-pcentered[1]);
67  }else{
68  const double line3 = a*X2[0]-b*X2[1];
69  if(line3<b/2 && line3 >(-b/2)){
70  return TOutputValue(X(2*X2[1]-pcentered[1],a,b,k),2*X2[1]-pcentered[1]);
71  }
72  else{
73  return TOutputValue(X(X1[1]+X2[1]-pcentered[1],a,b,k),X1[1]+X2[1]-pcentered[1]);
74  }
75  }
76 
77 
78  }
79 
80 
81 
82 
83  CDLR_naiverotation( double ang=0., TOutputValue ptCenter=TOutputValue(0,0), double starting_angle =0. ):my_angle(ang),my_center(ptCenter),my_startingAngle(starting_angle) {
84  }
85 
87  inline double angle() const{return my_angle;};
88 
90  inline double startingAngle() const{return my_startingAngle;};
91 
93  inline void set_angle(const double new_angle){my_angle=new_angle;}
94 
96  inline void set_startingAngle(const double new_startingAngle){my_startingAngle=new_startingAngle;}
97 
98 
99 
100 
102  inline TOutputValue center() const{return my_center;};
104  inline TOutputValue& center(){return my_center;};
105 
109  TOutputValue rotate( const TInputValue& p ) const {
111  reflect(
113  }
114  TOutputValue operator()( const TInputValue& p ) const {
115  return rotate(p);
116  }
117 
118 
119 
120 
121  protected:
123  double my_angle;
125 
127  TOutputValue my_center;
128 
129 
130  };
131 
132 }
133 
134 
135 
136 #endif //CDLR_NAIVEROTATION
137 #undef CDLR_NAIVEROTATION_RECURSES
138 #endif // else defined(CDLR_NAIVEROTATION_RECURSES)
139 
DGtal is the top-level namespace which contains all DGtal functions and types.
double my_angle
The angle of rotation.
TOutputValue operator()(const TInputValue &p) const
void set_startingAngle(const double new_startingAngle)
set the starting angle not the rotation angle
int X(int y, const double a, const double b, const int k) const
TOutputValue center() const
TOutputValue reflect(const double angle, TOutputValue center, const TInputValue &p) const
void set_angle(const double new_angle)
set the angle of rotation and call the composition of reflections solver.
TOutputValue rotate(const TInputValue &p) const
CDLR_naiverotation(double ang=0., TOutputValue ptCenter=TOutputValue(0, 0), double starting_angle=0.)
TOutputValue my_center
The center of rotation.