DGtal  1.0.0
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 "DGtal/base/Common.h"
46 #include "DGtal/kernel/BasicPointFunctors.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
70 template < typename TSpace, typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point,
71  typename TFunctor = VectorRounding < TInputValue, TOutputValue > >
73 {
76  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
77  BOOST_STATIC_ASSERT(( TOutputValue::dimension == 2 ));
78  BOOST_STATIC_ASSERT(( TInputValue::dimension == 2 ));
79 
80  // ----------------------- Types ------------------------------
81 public:
82  typedef typename TSpace::RealPoint RealPoint;
83  typedef typename TSpace::RealVector RealVector;
84 
85  // ----------------------- Interface --------------------------------------
86 public:
93  ForwardRigidTransformation2D ( const RealPoint & aOrigin, const double & angle, const RealVector & aTranslate )
94  :origin(aOrigin), translation(aTranslate)
95  {
96  t_sin = std::sin ( angle );
97  t_cos = std::cos ( angle );
98  }
99 
105  inline
106  TOutputValue operator()( const TInputValue & aInput ) const
107  {
108  RealPoint p;
109  p[0] = ( ( t_cos * ( aInput[0] - origin[0] ) -
110  t_sin * ( aInput[1] - origin[1] ) ) + translation[0] ) + origin[0];
111 
112  p[1] = ( ( t_sin * ( aInput[0] - origin[0] ) +
113  t_cos * ( aInput[1] - origin[1] ) ) + translation[1] ) + origin[1];
114  return functor ( p );
115  }
116 
117  // ------------------------- Protected Datas ------------------------------
118 protected:
120  double t_sin;
121  double t_cos;
123  TFunctor functor;
124 };
125 
127 // Template class BackwardRigidTransformation2D
140 template < typename TSpace, typename TInputValue = typename TSpace::RealPoint, typename TOutputValue = typename TSpace::Point,
143 {
146  BOOST_STATIC_ASSERT(( TSpace::dimension == 2 ));
147  BOOST_STATIC_ASSERT(( TOutputValue::dimension == 2 ));
148  BOOST_STATIC_ASSERT(( TInputValue::dimension == 2 ));
149 
150  // ----------------------- Types ------------------------------
151 public:
152  typedef typename TSpace::RealPoint RealPoint;
153  typedef typename TSpace::RealVector RealVector;
154 
155  // ----------------------- Interface --------------------------------------
156 public:
163  BackwardRigidTransformation2D ( const RealPoint& aOrigin, const double & angle, const RealVector & aTranslate )
164  :origin(aOrigin), translation(aTranslate)
165  {
166  t_sin = std::sin ( angle );
167  t_cos = std::cos ( angle );
168  }
169 
175  inline
176  TOutputValue operator()( const TInputValue & aInput ) const
177  {
178  RealPoint p;
179  p[0] = ( t_cos * (aInput[0] - translation[0] - origin[0] ) +
180  t_sin * ( aInput[1] - translation[1] - origin[1] ) ) + origin[0];
181 
182  p[1] = ( -t_sin * ( aInput[0] - translation[0] - origin[0] ) +
183  t_cos * ( aInput[1] - translation[1] - origin[1] ) ) + origin[1];
184  return functor ( p);
185  }
186 
187  // ------------------------- Protected Datas ------------------------------
188 protected:
190  double t_sin;
191  double t_cos;
193  TFunctor functor;
194 };
195 
197 // Template class DomainRigidTransformation2D
207 template <typename TDomain, typename TRigidTransformFunctor >
209 {
211  BOOST_STATIC_ASSERT(( TDomain::dimension == 2 ));
213 
214  // ----------------------- Types ------------------------------
215 public:
216  typedef std::pair < typename TDomain::Space::Point, typename TDomain::Space::Point > Bounds;
217 
218  // ----------------------- Interface --------------------------------------
219 public:
224  DomainRigidTransformation2D ( const TRigidTransformFunctor & aRigidFunctor ) : transform ( aRigidFunctor ) {}
225 
231  inline
232  Bounds operator()( const TDomain & aInput ) const
233  {
234  typedef typename TDomain::Point Point;
235  Point points[4];
236  points[0] = transform ( aInput.lowerBound() );
237  points[1] = transform ( aInput.upperBound() );
238  points[2] = transform ( Point ( aInput.upperBound()[0], aInput.lowerBound()[1] ) );
239  points[3] = transform ( Point ( aInput.lowerBound()[0], aInput.upperBound()[1] ) );
240 
241  Point t_min ( INT_MAX, INT_MAX ), t_max ( INT_MIN, INT_MIN );
242  for ( unsigned int i = 0; i < 4 ; i++ )
243  {
244  if ( points[i][0] < t_min[0] )
245  t_min[0] = points[i][0];
246  if ( points[i][1] < t_min[1] )
247  t_min[1] = points[i][1];
248 
249  if ( points[i][0] > t_max[0] )
250  t_max[0] = points[i][0];
251  if ( points[i][1] > t_max[1] )
252  t_max[1] = points[i][1];
253  }
254 
255  Bounds bounds;
256  bounds.first = t_min;
257  bounds.second = t_max;
258  return bounds;
259  }
260 
261  // ------------------------- Protected Datas ------------------------------
262 protected:
263  const TRigidTransformFunctor & transform;
264 };
265 
266 }// namespace DGtal::functors
267 }// namespace DGtal
268 
269 #endif // !defined RigidTransformation2D_h
270 
271 #undef RigidTransformation2D_RECURSES
272 #endif // else defined(RigidTransformation2D_RECURSES)
273 
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Checking concepts.
BackwardRigidTransformation2D(const RealPoint &aOrigin, const double &angle, const RealVector &aTranslate)
TOutputValue operator()(const TInputValue &aInput) const
Z3i::RealVector RealVector
Bounds operator()(const TDomain &aInput) const
Aim: implements bounds of transformed domain.
BOOST_CONCEPT_ASSERT((concepts::CSpace< TSpace >))
Checking concepts.
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 ...
ForwardRigidTransformation2D(const RealPoint &aOrigin, const double &angle, const RealVector &aTranslate)
Aim: Defines the concept describing a digital space, ie a cartesian product of integer lines.
Definition: CSpace.h:105
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
TOutputValue operator()(const TInputValue &aInput) const
DomainRigidTransformation2D(const TRigidTransformFunctor &aRigidFunctor)
Aim: implements backward rigid transformation of point in the 2D integer space. Warring: This version...