DGtal  1.5.beta
QSH.h
1 
17 #pragma once
18 
28 #if defined(QSH_RECURSES)
29 #error Recursive header files inclusion detected in QSH.h
30 #else // defined(QSH_RECURSES)
32 #define QSH_RECURSES
33 
34 #if !defined QSH_h
36 #define QSH_h
37 #include <DGtal/base/Common.h>
38 #include <DGtal/images/RigidTransformation2D.h>
39 
40 namespace DGtal {
49 template < typename TSpace, typename TInputValue = typename TSpace::Point, typename TOutputValue = typename TSpace::Point>
50 struct QSH {
53  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
54  BOOST_STATIC_ASSERT(( TOutputValue::dimension == 2 ));
55  BOOST_STATIC_ASSERT(( TInputValue::dimension == 2 ));
56 
57 
58 
59 
60  inline TOutputValue hqs(const TOutputValue X, const double a, const double b, const double c) const{
61  return TOutputValue{X[0] + static_cast<int>(round((a*X[1]+c)/b)),X[1]};
62  }
63  inline TOutputValue vqs(const TOutputValue X, const double a, const double b, const double c) const{
64  return TOutputValue{X[0], X[1] + static_cast<int>((round((a*X[0]+c)/b)))};
65  }
66 
67  inline TOutputValue hqs_p(const TOutputValue X, const double ap, const double bp, const double omega) const{
68  return hqs(X, -ap, bp, 0.0);
69  }
70  inline TOutputValue vqs_p(const TOutputValue X, const double a, const double bp, const double omega) const{
71  return vqs(X,a, omega, round(omega/2.0));
72  }
73 
74  template<typename Img>
75  Img rotateImage(Img img) const;
76 
82  QSH(double ang, TOutputValue ptCenter );
83 
86  a = round(omega*std::sin(my_angle));
87  aprime = round(omega*std::sin(my_angle/2.0));
88  bprime = round(omega*std::cos(my_angle/2.0));
89  }
90 
92  inline double angle() const{return my_angle;};
93 
95  inline void set_angle(const double new_angle){my_angle=new_angle;initQSHRotation();}
96 
97 
99  inline TOutputValue center() const{return my_center;};
101  inline TOutputValue& center(){return my_center;};
102 
103 
107  TOutputValue rotate( const TInputValue& p ) const;
108  TOutputValue operator()( const TInputValue& p ) const;
109 
110  std::string tostring() const {
111  return {"QSH"};
112  }
113 
114 protected:
116  double my_angle;
118  TOutputValue my_center;
119 
120 
121 private:
123  const double omega=1<<15;
124  double a;
125  double aprime;
126  double bprime;
127 
128 
129 };
130 
131 template<typename TSpace, typename TInputValue, typename TOutputValue>
132 QSH<TSpace,TInputValue,TOutputValue>::QSH( const double ang, const TOutputValue ptCenter ):my_angle(ang),my_center(ptCenter){
133  initQSHRotation();
134 }
135 
136 
137 
138 template<typename TSpace, typename TInputValue, typename TOutputValue>
139 TOutputValue QSH<TSpace,TInputValue,TOutputValue>::rotate( const TInputValue& p ) const{
140  return this->operator()(p);
141 }
142 
143 template<typename TSpace, typename TInputValue, typename TOutputValue>
144 TOutputValue QSH<TSpace,TInputValue,TOutputValue>::operator()( const TInputValue& p ) const{
145 
146  TOutputValue pcentered = p-my_center;
147 
148  TOutputValue y1 = hqs_p(pcentered, aprime, bprime, omega);
149  TOutputValue y2 = vqs_p(y1, a, bprime, omega);
150  TOutputValue y = hqs_p(y2, aprime, bprime, omega);
151  return y+my_center;
152 }
153 
154 
155 
156 template<typename TSpace, typename TInputValue, typename TOutputValue>
157 template<typename TImage>
158 TImage QSH<TSpace,TInputValue,TOutputValue>::rotateImage( const TImage img ) const{
159  typedef typename TImage::Domain TDomain;
161  typedef std::pair < typename TSpace::Point, typename TSpace::Point > Bounds;
162 
163 
164  MyDomainTransformer domainTransformer ( *this );
165  Bounds bounds = domainTransformer ( img.domain() );
166  TDomain transformedDomain ( bounds.first, bounds.second );
167  TImage rotatedImage ( transformedDomain );
168 
169 
170 
171  for (typename TDomain::ConstIterator it = img.domain().begin(); it != img.domain().end(); ++it )
172  {
173  rotatedImage.setValue((*this)(*it),img(*it));
174  }
175 
176  return rotatedImage;
177 }
178 
179 }
180 
181 
182 #endif //QSH
183 
184 #undef QSH_RECURSES
185 #endif // else defined(QSH_RECURSES)
Aim: implements bounds of transformed domain.
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
QSH : Quasi Shears represents a bijective rotation through shears.
Definition: QSH.h:50
TOutputValue operator()(const TInputValue &p) const
Definition: QSH.h:144
double angle() const
Definition: QSH.h:92
Img rotateImage(Img img) const
TOutputValue center() const
Definition: QSH.h:99
TOutputValue hqs(const TOutputValue X, const double a, const double b, const double c) const
Definition: QSH.h:60
double my_angle
The angle of rotation.
Definition: QSH.h:116
TOutputValue rotate(const TInputValue &p) const
Definition: QSH.h:139
const double omega
shears variables
Definition: QSH.h:123
TOutputValue my_center
The center of rotation.
Definition: QSH.h:118
TOutputValue vqs_p(const TOutputValue X, const double a, const double bp, const double omega) const
Definition: QSH.h:70
std::string tostring() const
Definition: QSH.h:110
TOutputValue & center()
Definition: QSH.h:101
BOOST_STATIC_ASSERT((TSpace::dimension==2))
void initQSHRotation()
init a QSH rotation using Andres' parameters
Definition: QSH.h:85
TOutputValue hqs_p(const TOutputValue X, const double ap, const double bp, const double omega) const
Definition: QSH.h:67
QSH(double ang, TOutputValue ptCenter)
Definition: QSH.h:132
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Checking concepts.
TOutputValue vqs(const TOutputValue X, const double a, const double b, const double c) const
Definition: QSH.h:63
double bprime
Definition: QSH.h:126
double aprime
Definition: QSH.h:125
void set_angle(const double new_angle)
set rotation angle
Definition: QSH.h:95
BOOST_STATIC_ASSERT((TOutputValue::dimension==2))
double a
Definition: QSH.h:124
BOOST_STATIC_ASSERT((TInputValue::dimension==2))
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:106
HyperRectDomain< Space > Domain