IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Homography2d.h
1 // Homography2d.h:
3 // ---------------
4 //
14 
15 #ifndef __IPSDKMATH_HOMOGRAPHY2D_H__
16 #define __IPSDKMATH_HOMOGRAPHY2D_H__
17 
18 // suppression warnings
19 // warning C4251: 'ipsdk::math::transform::Homography2d::_matA' : class 'boost::numeric::ublas::bounded_matrix<ipsdk::ipReal64,0x03,0x03,boost::numeric::ublas::row_major>' needs to have dll-interface to be used by clients of class 'ipsdk::math::transform::Homography2d'
20 #pragma warning (push)
21 #pragma warning (disable : 4251)
22 
23 #include <IPSDKMath/Geometry/2d/Transform/BaseLinearGeometricTransform2d.h>
24 
25 namespace ipsdk {
26 namespace math {
27 namespace transform {
28 
31 
33 {
34 // predefined public types
35 public:
38 
39  (eTP_Axx)
40  (eTP_Axy)
41  (eTP_Axw)
42  (eTP_Ayx)
43  (eTP_Ayy)
44  (eTP_Ayw)
45  (eTP_Awx)
46  (eTP_Awy)
47  (eTP_Aww)
48  );
49 
50  // declare geometric transformation 2d
52 
53 public:
56  Homography2d()
57  {
58  _matA(0, 0) = 1; _matA(0, 1) = 0; _matA(0, 2) = 0;
59  _matA(1, 0) = 0; _matA(1, 1) = 1; _matA(1, 2) = 0;
60  _matA(2, 0) = 0; _matA(2, 1) = 0; _matA(2, 2) = 1;
61  }
62  Homography2d(const Matrix3d& matA) :
63  _matA(matA)
64  {
65  }
66  Homography2d(const ipReal64 axx, const ipReal64 axy, const ipReal64 axw,
67  const ipReal64 ayx, const ipReal64 ayy, const ipReal64 ayw,
68  const ipReal64 awx, const ipReal64 awy, const ipReal64 aww)
69  {
70  _matA(0, 0) = axx; _matA(0, 1) = axy; _matA(0, 2) = axw;
71  _matA(1, 0) = ayx; _matA(1, 1) = ayy; _matA(1, 2) = ayw;
72  _matA(2, 0) = awx; _matA(2, 1) = awy; _matA(2, 2) = aww;
73  }
74  ~Homography2d() {}
76 
77 // methods
78 public:
82  static bool transform(const Matrix3d& matA,
83  ipReal64& x, ipReal64& y)
84  {
85  return transform(matA(0, 0), matA(0, 1), matA(0, 2),
86  matA(1, 0), matA(1, 1), matA(1, 2),
87  matA(2, 0), matA(2, 1), matA(2, 2),
88  x, y);
89  }
90  static bool transform(const ipReal64 axx, const ipReal64 axy, const ipReal64 axw,
91  const ipReal64 ayx, const ipReal64 ayy, const ipReal64 ayw,
92  const ipReal64 awx, const ipReal64 awy, const ipReal64 aww,
94  {
95  const ipReal64 xTmp = axx*x + axy*y + axw;
96  const ipReal64 yTmp = ayx*x + ayy*y + ayw;
97  const ipReal64 wTmp = awx*x + awy*y + aww;
98  if (wTmp == 0)
99  return false;
100  x = xTmp / wTmp;
101  y = yTmp / wTmp;
102 
103  return true;
104  }
106 
108  static Matrix3d getHomogenousMatrix(const ipReal64 axx, const ipReal64 axy, const ipReal64 axw,
109  const ipReal64 ayx, const ipReal64 ayy, const ipReal64 ayw,
110  const ipReal64 awx, const ipReal64 awy, const ipReal64 aww)
111  {
112  Matrix3d transform;
113  transform(0, 0) = axx; transform(0, 1) = axy; transform(0, 2) = axw;
114  transform(1, 0) = ayx; transform(1, 1) = ayy; transform(1, 2) = ayw;
115  transform(2, 0) = awx; transform(2, 1) = awy; transform(2, 2) = aww;
116 
117  return transform;
118  }
121  static bool isInvertible(const ipReal64 axx, const ipReal64 axy, const ipReal64 axw,
122  const ipReal64 ayx, const ipReal64 ayy, const ipReal64 ayw,
123  const ipReal64 awx, const ipReal64 awy, const ipReal64 aww);
124 
128  static Matrix3d getInvHomogenousMatrix(const ipReal64 axx, const ipReal64 axy, const ipReal64 axw,
129  const ipReal64 ayx, const ipReal64 ayy, const ipReal64 ayw,
130  const ipReal64 awx, const ipReal64 awy, const ipReal64 aww)
131  {
132  // invert input parameters
133  Matrix3d matA;
134  matA(0, 0) = axx; matA(0, 1) = axy; matA(0, 2) = axw;
135  matA(1, 0) = ayx; matA(1, 1) = ayy; matA(1, 2) = ayw;
136  matA(2, 0) = awx; matA(2, 1) = awy; matA(2, 2) = aww;
137  getInvParams(matA(0, 0), matA(0, 1), matA(0, 2),
138  matA(1, 0), matA(1, 1), matA(1, 2),
139  matA(2, 0), matA(2, 1), matA(2, 2));
140 
141  return matA;
142  }
143 
147  static void getInvParams(ipReal64& axx, ipReal64& axy, ipReal64& axw,
148  ipReal64& ayx, ipReal64& ayy, ipReal64& ayw,
149  ipReal64& awx, ipReal64& awy, ipReal64& aww);
150 
152  static Vector getIdentityParams();
153 
156  void setParams(const Matrix3d& matA)
157  {
158  _matA = matA;
159  }
160  void setParams(const ipReal64 axx, const ipReal64 axy, const ipReal64 axw,
161  const ipReal64 ayx, const ipReal64 ayy, const ipReal64 ayw,
162  const ipReal64 awx, const ipReal64 awy, const ipReal64 aww)
163  {
164  _matA(0, 0) = axx; _matA(0, 1) = axy; _matA(0, 2) = axw;
165  _matA(1, 0) = ayx; _matA(1, 1) = ayy; _matA(1, 2) = ayw;
166  _matA(2, 0) = awx; _matA(2, 1) = awy; _matA(2, 2) = aww;
167  }
169 
173  void setParams(const Vector& params);
174 
176  void setIdentity();
177 
179  void apply(ipReal64& x, ipReal64& y) const;
180 
182  Matrix3d getHomogenousMatrix() const;
183 
185  Vector getParams() const;
186 
188  bool isInvertible() const;
189 
193  Matrix3d getInvHomogenousMatrix() const;
194 
198  Vector getInvParams() const;
199 
200 // attributes
201 protected:
203  Matrix3d _matA;
204 };
205 
206 
209 
210 inline void
212 {
214 }
215 
218 
219 } // end of namespace transform
220 } // end of namespace math
221 } // end of namespace ipsdk
223 #pragma warning (pop)
224 
225 #endif // __IPSDKMATH_HOMOGRAPHY2D_H__
Main namespace for IPSDK library.
Definition: AlgorithmFunctionEfficiency.h:22
void setIdentity()
set transformation parameters to identity
Definition: Homography2d.h:222
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
IPSDKGEOMETRY_API bool apply(const BaseGeometryTransform2d &transform, BaseGeometryEntity2d &entity)
function allowing to apply in situ a given transformation on an entity
boost::numeric::ublas::vector< ipReal64 > Vector
vector type associated to library
Definition: LinearAlgebraTypes.h:36
static Vector getIdentityParams()
retrieve identity parameters for transformation
Transformation class allowing to manage 2d homography transformations.
Definition: Homography2d.h:32
#define IPSDKMATH_API
Import/Export macro for library IPSDKMath.
Definition: IPSDKMathExports.h:27
boost::numeric::ublas::bounded_matrix< ipReal64, 3, 3 > Matrix3d
3d matrix (3x3) type associated to library
Definition: LinearAlgebraTypes.h:54
void setParams(const Matrix3d &matA)
select parameters associated to transformation
Definition: Homography2d.h:167
eTransformParams
Definition: Homography2d.h:39
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
#define IPSDK_DECLARE_TRANSFORM2D(className)
macro allowing to declare a geometric transformation 2d
Definition: Transform2dHdrMacros.h:55