DGtal  0.9.4.1
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>
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:
115  double t_sin;
116  double t_cos;
118 };
119
121 // Template class BackwardRigidTransformation2D
131 template <typename TSpace>
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:
179  double t_sin;
180  double t_cos;
182 };
183
185 // Template class DomainRigidTransformation2D
195 template <typename TDomain, typename TRigidTransformFunctor >
197 {
199  BOOST_STATIC_ASSERT(( TDomain::dimension == 2 ));
201
202  // ----------------------- Types ------------------------------
203 public:
204  typedef std::pair < typename TDomain::Space::Point, typename TDomain::Space::Point > Bounds;
205
206  // ----------------------- Interface --------------------------------------
207 public:
212  DomainRigidTransformation2D ( const TRigidTransformFunctor & aRigidFunctor ) : transform ( aRigidFunctor ) {}
213
219  inline
220  Bounds operator()( const TDomain & aInput ) const
221  {
222  typedef typename TDomain::Point Point;
223  Point points[4];
224  points[0] = transform ( aInput.lowerBound() );
225  points[1] = transform ( aInput.upperBound() );
226  points[2] = transform ( Point ( aInput.upperBound()[0], aInput.lowerBound()[1] ) );
227  points[3] = transform ( Point ( aInput.lowerBound()[0], aInput.upperBound()[1] ) );
228
229  Point t_min ( INT_MAX, INT_MAX ), t_max ( INT_MIN, INT_MIN );
230  for ( unsigned int i = 0; i < 4 ; i++ )
231  {
232  if ( points[i][0] < t_min[0] )
233  t_min[0] = points[i][0];
234  if ( points[i][1] < t_min[1] )
235  t_min[1] = points[i][1];
236
237  if ( points[i][0] > t_max[0] )
238  t_max[0] = points[i][0];
239  if ( points[i][1] > t_max[1] )
240  t_max[1] = points[i][1];
241  }
242
243  Bounds bounds;
244  bounds.first = t_min;
245  bounds.second = t_max;
246  return bounds;
247  }
248
249  // ------------------------- Protected Datas ------------------------------
250 protected:
251  const TRigidTransformFunctor & transform;
252 };
253
254 }// namespace DGtal::functors
255 }// namespace DGtal
256
257 #endif // !defined RigidTransformation2D_h
258
259 #undef RigidTransformation2D_RECURSES
260 #endif // else defined(RigidTransformation2D_RECURSES)
261
Bounds operator()(const TDomain &aInput) const
Aim: implements bounds of transformed domain.
BOOST_STATIC_ASSERT((TDomain::dimension==2))
Checking concepts.
PointVector< 3, double > RealPoint
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)
BOOST_CONCEPT_ASSERT((concepts::CDomain< TDomain >))
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
ForwardRigidTransformation2D(const RealPoint &aOrigin, const double &angle, const RealVector &aTranslate)
DomainRigidTransformation2D(const TRigidTransformFunctor &aRigidFunctor)
Aim: implements backward rigid transformation of point in the 2D integer space. Warring: This version...