DGtal  0.9.2
RigidTransformation2D.h
1
17 #pragma once
18
29 #if defined(RigidTransformation2D_RECURSES)
30 #error Recursive header files inclusion detected in RigidTransformation2D.h
31 #else // defined(RigidTransformation2D_RECURSES)
32
33 #define RigidTransformation2D_RECURSES
34
35 #if !defined RigidTransformation2D_h
36
37 #define RigidTransformation2D_h
38
40 // Inclusions
41 #include <iostream>
42 #include <cmath>
43 #include <climits>
44 #include <utility>
45 #include <functional>
46 #include "DGtal/base/Common.h"
47 #include <DGtal/helpers/StdDefs.h>
48 #include <DGtal/kernel/domains/CDomain.h>
49 #include <DGtal/kernel/CSpace.h>
51
52 namespace DGtal
53 {
54 namespace functors
55 {
57 // Template class ForwardRigidTransformation2D
67 template <typename TSpace>
68 class ForwardRigidTransformation2D : std::unary_function <typename TSpace::Point, typename TSpace::Point>
69 {
72  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
73
74  // ----------------------- Types ------------------------------
75 public:
76  typedef typename TSpace::Point Point;
77  typedef typename TSpace::RealPoint RealPoint;
78  typedef typename TSpace::RealVector RealVector;
79
80  // ----------------------- Interface --------------------------------------
81 public:
88  ForwardRigidTransformation2D ( const RealPoint & aOrigin, const double & angle, const RealVector & aTranslate )
89  :origin(aOrigin), translation(aTranslate)
90  {
91  t_sin = std::sin ( angle );
92  t_cos = std::cos ( angle );
93  }
94
100  inline
101  Point operator()( const Point& aInput ) const
102  {
103  Point p;
104  p[0] = std::floor ( ( ( t_cos * ( aInput[0] - origin[0] ) -
105  t_sin * ( aInput[1] - origin[1] ) ) + translation[0] ) + origin[0] + 0.5 );
106
107  p[1] = std::floor ( ( ( t_sin * ( aInput[0] - origin[0] ) +
108  t_cos * ( aInput[1] - origin[1] ) ) + translation[1] ) + origin[1] + 0.5 );
109  return p;
110  }
111
112  // ------------------------- Protected Datas ------------------------------
113 protected:
114  RealPoint origin;
115  double t_sin;
116  double t_cos;
117  RealVector translation;
118 };
119
121 // Template class BackwardRigidTransformation2D
131 template <typename TSpace>
132 class BackwardRigidTransformation2D : std::unary_function <typename TSpace::Point, typename TSpace::Point>
133 {
136  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
137
138  // ----------------------- Types ------------------------------
139 public:
140  typedef typename TSpace::Point Point;
141  typedef typename TSpace::RealPoint RealPoint;
142  typedef typename TSpace::RealVector RealVector;
143
144  // ----------------------- Interface --------------------------------------
145 public:
152  BackwardRigidTransformation2D ( const RealPoint& aOrigin, const double & angle, const RealVector & aTranslate )
153  :origin(aOrigin), translation(aTranslate)
154  {
155  t_sin = std::sin ( angle );
156  t_cos = std::cos ( angle );
157  }
158
164  inline
165  Point operator()( const Point& aInput ) const
166  {
167  Point p;
168  p[0] = std::floor ( ( t_cos * (aInput[0] - translation[0] - origin[0] ) +
169  t_sin * ( aInput[1] - translation[1] - origin[1] ) ) + origin[0] + 0.5 );
170
171  p[1] = std::floor ( ( -t_sin * ( aInput[0] - translation[0] - origin[0] ) +
172  t_cos * ( aInput[1] - translation[1] - origin[1] ) ) + origin[1] + 0.5 );
173  return p;
174  }
175
176  // ------------------------- Protected Datas ------------------------------
177 protected:
178  RealPoint origin;
179  double t_sin;
180  double t_cos;
181  RealVector translation;
182 };
183
185 // Template class DomainRigidTransformation2D
195 template <typename TDomain, typename TRigidTransformFunctor >
197  std::unary_function < std::pair < typename TDomain::Point, typename TDomain::Point >, TDomain>
198 {
200  BOOST_STATIC_ASSERT(( TDomain::dimension == 2 ));
202
203  // ----------------------- Types ------------------------------
204 public:
205  typedef std::pair < typename TDomain::Space::Point, typename TDomain::Space::Point > Bounds;
206
207  // ----------------------- Interface --------------------------------------
208 public:
213  DomainRigidTransformation2D ( const TRigidTransformFunctor & aRigidFunctor ) : transform ( aRigidFunctor ) {}
214
220  inline
221  Bounds operator()( const TDomain & aInput ) const
222  {
223  typedef typename TDomain::Point Point;
224  Point points[4];
225  points[0] = transform ( aInput.lowerBound() );
226  points[1] = transform ( aInput.upperBound() );
227  points[2] = transform ( Point ( aInput.upperBound()[0], aInput.lowerBound()[1] ) );
228  points[3] = transform ( Point ( aInput.lowerBound()[0], aInput.upperBound()[1] ) );
229
230  Point t_min ( INT_MAX, INT_MAX ), t_max ( INT_MIN, INT_MIN );
231  for ( unsigned int i = 0; i < 4 ; i++ )
232  {
233  if ( points[i][0] < t_min[0] )
234  t_min[0] = points[i][0];
235  if ( points[i][1] < t_min[1] )
236  t_min[1] = points[i][1];
237
238  if ( points[i][0] > t_max[0] )
239  t_max[0] = points[i][0];
240  if ( points[i][1] > t_max[1] )
241  t_max[1] = points[i][1];
242  }
243
244  Bounds bounds;
245  bounds.first = t_min;
246  bounds.second = t_max;
247  return bounds;
248  }
249
250  // ------------------------- Protected Datas ------------------------------
251 protected:
252  const TRigidTransformFunctor & transform;
253 };
254
255 }// namespace DGtal::functors
256 }// namespace DGtal
257
258 #endif // !defined RigidTransformation2D_h
259
260 #undef RigidTransformation2D_RECURSES
261 #endif // else defined(RigidTransformation2D_RECURSES)
262
Aim: implements bounds of transformed domain.
BOOST_STATIC_ASSERT((TDomain::dimension==2))
Checking concepts.
Aim: This concept represents a digital domain, i.e. a non mutable subset of points of the given digit...
Definition: CDomain.h:129
std::pair< typename TDomain::Space::Point, typename TDomain::Space::Point > Bounds
Aim: implements forward rigid transformation of point in the 2D integer space. Warring: This version ...
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Checking concepts.
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines...
Definition: CSpace.h:105
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Checking concepts.
BackwardRigidTransformation2D(const RealPoint &aOrigin, const double &angle, const RealVector &aTranslate)
Point operator()(const Point &aInput) const
BOOST_CONCEPT_ASSERT((concepts::CDomain< TDomain >))
DGtal is the top-level namespace which contains all DGtal functions and types.
ForwardRigidTransformation2D(const RealPoint &aOrigin, const double &angle, const RealVector &aTranslate)
Bounds operator()(const TDomain &aInput) const
DomainRigidTransformation2D(const TRigidTransformFunctor &aRigidFunctor)
Aim: implements backward rigid transformation of point in the 2D integer space. Warring: This version...