IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Rigid2d.h
1 // Rigid2d.h:
3 // ----------
4 //
14 
15 #ifndef __IPSDKMATH_RIGID2D_H__
16 #define __IPSDKMATH_RIGID2D_H__
17 
18 // suppression warnings
19 // warning C4251: 'ipsdk::math::transform::Rigid2d::g_registrator' : struct 'ipsdk::math::transform::Registrator<ipsdk::math::transform::Rigid2d>' needs to have dll-interface to be used by clients of class 'ipsdk::math::transform::Rigid2d'
20 #pragma warning (push)
21 #pragma warning (disable : 4251)
22 
23 #include <IPSDKMath/Geometry/2d/Transform/BaseLinearGeometricTransform2d.h>
25 
26 namespace ipsdk {
27 namespace math {
28 namespace transform {
29 
32 
34 {
35 // predefined public type
36 public:
39 
40  (eTP_Theta)
41  (eTP_Tx)
42  (eTP_Ty)
43  );
44 
45  // declare geometric transformation 2d
47 
48 public:
51  Rigid2d()
52  {
53  setParams(0, 0, 0);
54  }
55  Rigid2d(const ipReal64 theta, const ipReal64 tx, const ipReal64 ty)
56  {
57  setParams(theta, tx, ty);
58  }
59  ~Rigid2d() {}
61 
62 // methods
63 public:
66  static void transform(const ipReal64 theta,
67  const ipReal64 tx, const ipReal64 ty,
68  ipReal64& x, ipReal64& y)
69  {
70  transform(std::cos(theta), std::sin(theta), tx, ty, x, y);
71  }
72  static void transform(const ipReal64 cosTheta, const ipReal64 sinTheta,
73  const ipReal64 tx, const ipReal64 ty,
74  ipReal64& x, ipReal64& y)
75  {
76  rotate2dInSitu(cosTheta, sinTheta, x, y);
77  x += tx;
78  y += ty;
79  }
81 
84  static Matrix3d getHomogenousMatrix(const ipReal64 theta,
85  const ipReal64 tx, const ipReal64 ty)
86  {
87  return getHomogenousMatrix(std::cos(theta), std::sin(theta), tx, ty);
88  }
89  static Matrix3d getHomogenousMatrix(const ipReal64 cosTheta, const ipReal64 sinTheta,
90  const ipReal64 tx, const ipReal64 ty)
91  {
92  Matrix3d transform;
93  angleToMatrix(cosTheta, sinTheta,
94  transform(0, 0), transform(0, 1),
95  transform(1, 0), transform(1, 1));
96  transform(0, 2) = tx;
97  transform(1, 2) = ty;
98  transform(2, 0) = 0; transform(2, 1) = 0; transform(2, 2) = 1;
99 
100  return transform;
101  }
103 
105  static Matrix3d getInvHomogenousMatrix(const ipReal64 theta,
106  const ipReal64 tx, const ipReal64 ty)
107  {
108  const ipReal64 cosTheta = std::cos(theta);
109  const ipReal64 sinTheta = std::sin(theta);
110  const ipReal64 invTx = -(cosTheta*tx + sinTheta*ty);
111  const ipReal64 invTy = -(-sinTheta*tx + cosTheta*ty);
112  return getHomogenousMatrix(cosTheta, -sinTheta, invTx, invTy);
113  }
114 
116  static void getInvParams(ipReal64& theta, ipReal64& tx, ipReal64& ty)
117  {
118  const ipReal64 cosTheta = std::cos(theta);
119  const ipReal64 sinTheta = std::sin(theta);
120  const ipReal64 invTx = -(cosTheta*tx + sinTheta*ty);
121  const ipReal64 invTy = -(-sinTheta*tx + cosTheta*ty);
122  theta = -theta;
123  tx = invTx;
124  ty = invTy;
125  }
126 
128  static Vector getIdentityParams();
129 
131  void setParams(const ipReal64 theta,
132  const ipReal64 tx, const ipReal64 ty)
133  {
134  _theta = theta;
135  _cosTheta = std::cos(_theta);
136  _sinTheta = std::sin(_theta);
137  _tx = tx;
138  _ty = ty;
139  }
140 
142  void setCenteredRotation(const ipReal64 theta,
143  const ipReal64 centerX, const ipReal64 centerY)
144  {
145  // store angle informations
146  _theta = theta;
147  _cosTheta = std::cos(_theta);
148  _sinTheta = std::sin(_theta);
149 
150  // we compute translation such as center point is invariant
151  // (ie C = RxC + T => T = C - RxC)
152  ipReal64 rx, ry;
153  rotate2d<ipReal64>(centerX, centerY, _cosTheta, _sinTheta, rx, ry);
154  _tx = centerX - rx;
155  _ty = centerY - ry;
156  }
157 
161  void setParams(const Vector& params);
162 
164  void setIdentity();
165 
167  void apply(ipReal64& x, ipReal64& y) const;
168 
170  Matrix3d getHomogenousMatrix() const;
171 
173  Vector getParams() const;
174 
177  ipReal64 getTheta() const;
178  ipReal64 getTx() const;
179  ipReal64 getTy() const;
181 
183  Matrix3d getInvHomogenousMatrix() const;
184 
186  Vector getInvParams() const;
187 
188 // attributes
189 protected:
191  ipReal64 _theta;
192 
195  ipReal64 _cosTheta;
196  ipReal64 _sinTheta;
198 
200  ipReal64 _tx;
203  ipReal64 _ty;
204 };
209 inline ipReal64
210 Rigid2d::getTheta() const
211 {
212  return _theta;
213 }
214 
215 inline ipReal64
216 Rigid2d::getTx() const
217 {
218  return _tx;
219 }
220 
221 inline ipReal64
222 Rigid2d::getTy() const
223 {
224  return _ty;
225 }
226 
227 inline void
229 {
231 }
232 
235 
236 } // end of namespace transform
237 } // end of namespace math
238 } // end of namespace ipsdk
239 
240 #pragma warning (pop)
241 
242 #endif // __IPSDKMATH_RIGID2D_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
IPSDK_FORCEINLINE void angleToMatrix(const T cosTheta, const T sinTheta, T &rxx, T &rxy, T &ryx, T &ryy)
Convertion from angle to rotation matrix.
Definition: Angles2d.h:80
static Matrix3d getHomogenousMatrix(const ipReal64 theta, const ipReal64 tx, const ipReal64 ty)
retrieve homogeneous matrix associated to transformation
Definition: Rigid2d.h:89
static Vector getIdentityParams()
retrieve identity parameters for transformation
void setIdentity()
set transformation parameters to identity
Definition: Rigid2d.h:233
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
Utility functions used to handle angles 2d.
IPSDKGEOMETRY_API bool apply(const BaseGeometryTransform2d &transform, BaseGeometryEntity2d &entity)
function allowing to apply in situ a given transformation on an entity
Definition: Rigid2d.h:33
ipReal64 getTx() const
retrieve parameters associated to transformation
Definition: Rigid2d.h:221
boost::numeric::ublas::vector< ipReal64 > Vector
vector type associated to library
Definition: LinearAlgebraTypes.h:36
ipReal64 getTheta() const
retrieve parameters associated to transformation
Definition: Rigid2d.h:215
#define IPSDKMATH_API
Import/Export macro for library IPSDKMath.
Definition: IPSDKMathExports.h:27
Transformation class allowing to manage 2d rigid transformations.
ipReal64 getTy() const
retrieve parameters associated to transformation
Definition: Rigid2d.h:227
boost::numeric::ublas::bounded_matrix< ipReal64, 3, 3 > Matrix3d
3d matrix (3x3) type associated to library
Definition: LinearAlgebraTypes.h:54
eTransformParams
Definition: Rigid2d.h:40
ipReal64 _ty
translation coordinate along y axis
Definition: Rigid2d.h:208
void setParams(const ipReal64 theta, const ipReal64 tx, const ipReal64 ty)
select parameters associated to transformation
Definition: Rigid2d.h:136
ipReal64 _theta
angle of rotation in radians
Definition: Rigid2d.h:196
Base class for linear geometric transformation 2d management.
Definition: BaseLinearGeometricTransform2d.h:27
#define IPSDK_ENUM(enumTypeStr, enumSeq)
macro allowing to declare an enumerate for library
Definition: EnumMacros.h:26
IPSDK_FORCEINLINE void rotate2dInSitu(const ipReal64 cosTheta, const ipReal64 sinTheta, T &x, T &y)
rotation of a point using a rotation angle (rotation around origin)
Definition: Angles2d.h:156
#define IPSDK_DECLARE_TRANSFORM2D(className)
macro allowing to declare a geometric transformation 2d
Definition: Transform2dHdrMacros.h:55
ipReal64 _tx
translation coordinate along x axis
Definition: Rigid2d.h:205