IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit
Angles2d.h
Go to the documentation of this file.
1 // Angles2d.h:
3 // -----------
4 //
14 
15 #ifndef __IPSDKMATH_ANGLES2D_H__
16 #define __IPSDKMATH_ANGLES2D_H__
17 
22 
23 namespace ipsdk {
24 namespace math {
25 
28 
33 template <typename TOut, typename TIn>
34 IPSDK_FORCEINLINE TOut
35 polarToXCartesian(const TIn rho, const TIn cosTheta, const TIn sinTheta)
36 {
37  return round<TOut>(rho * cosTheta);
38 }
39 template <typename TOut, typename TIn>
40 IPSDK_FORCEINLINE TOut
41 polarToYCartesian(const TIn rho, const TIn cosTheta, const TIn sinTheta)
42 {
43  return round<TOut>(rho * sinTheta);
44 }
45 template <typename TOut, typename TIn>
46 IPSDK_FORCEINLINE void
47 polarToCartesian(const TIn rho, const TIn cosTheta, const TIn sinTheta,
48  TOut& x, TOut& y)
49 {
50  x = polarToXCartesian<TOut>(rho, cosTheta, sinTheta);
51  y = polarToYCartesian<TOut>(rho, cosTheta,sinTheta);
52 }
53 template <typename TOut, typename TIn>
54 IPSDK_FORCEINLINE void
55 polarToCartesian(const TIn rho, const TIn theta,
56  TOut& x, TOut& y)
57 {
58  polarToCartesian(rho, std::cos(theta), std::sin(theta), x, y);
59 }
61 
65 template <typename TOut, typename TIn>
66 IPSDK_FORCEINLINE void
67 cartesianToPolar(const TIn x, const TIn y,
68  TOut& rho, TOut& theta)
69 {
70  rho = round<TOut>(normL2(x, y));
71  theta = std::atan2(y, x);
72 }
73 
78 template <typename T>
79 IPSDK_FORCEINLINE void
80 angleToMatrix(const T cosTheta, const T sinTheta,
81  T& rxx, T& rxy,
82  T& ryx, T& ryy)
83 {
84  rxx = cosTheta; rxy = -sinTheta;
85  ryx = sinTheta; ryy = cosTheta;
86 }
87 template <typename T>
88 IPSDK_FORCEINLINE void
89 angleToMatrix(const T theta,
90  T& rxx, T& rxy,
91  T& ryx, T& ryy)
92 {
93  angleToMatrix(std::cos(theta), std::sin(theta),
94  rxx, rxy,
95  ryx, ryy);
96 }
97 IPSDK_FORCEINLINE Matrix2d
98 angleToMatrix(const ipReal64 theta)
99 {
100  Matrix2d matRot;
101  angleToMatrix(theta,
102  matRot(0, 0), matRot(0, 1),
103  matRot(1, 0), matRot(1, 1));
104  return matRot;
105 }
107 
113 template <typename T>
114 IPSDK_FORCEINLINE void
115 matrixToAngle(const T rxx, const T rxy,
116  T& theta)
117 {
118  theta = std::atan2(-rxy, rxx);
119  if (theta == -M_PI)
120  theta = M_PI;
121 }
122 template <typename T>
123 IPSDK_FORCEINLINE void
124 matrixToAngle(const T rxx, const T rxy,
125  const T ryx, const T ryy,
126  T& theta)
127 {
128  matrixToAngle(rxx, rxy, theta);
129 }
130 IPSDK_FORCEINLINE ipReal64
131 matrixToAngle(const Matrix2d& matRot)
132 {
133  ipReal64 theta;
134  matrixToAngle(matRot(0, 0), matRot(0, 1), theta);
135 
136  return theta;
137 }
139 
145 template <typename T>
146 IPSDK_FORCEINLINE void
147 rotate2d(const T xIn, const T yIn,
148  const ipReal64 cosTheta, const ipReal64 sinTheta,
149  T& xOut, T& yOut)
150 {
151  xOut = round<T>(cosTheta * xIn - sinTheta * yIn);
152  yOut = round<T>(sinTheta * xIn + cosTheta * yIn);
153 }
154 template <typename T>
155 IPSDK_FORCEINLINE void
156 rotate2dInSitu(const ipReal64 cosTheta, const ipReal64 sinTheta,
157  T& x, T& y)
158 {
159  rotate2d(x, y,
160  cosTheta, sinTheta,
161  x, y);
162 }
163 template <typename T>
164 IPSDK_FORCEINLINE void
165 rotate2d(const T xIn, const T yIn,
166  const ipReal64 theta,
167  T& xOut, T& yOut)
168 {
169  rotate2d(xIn, yIn,
170  std::cos(theta), std::sin(theta),
171  xOut, yOut);
172 }
174 
177 
178 } // end of namespace math
179 } // end of namespace ipsdk
180 
181 #endif // __IPSDKMATH_ANGLES2D_H__
IPSDK_FORCEINLINE void rotate2d(const T xIn, const T yIn, const ipReal64 cosTheta, const ipReal64 sinTheta, T &xOut, T &yOut)
rotation of a point using a rotation angle (rotation around origin)
Definition: Angles2d.h:147
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
Predefined types for linear algebra management.
IPSDK_FORCEINLINE void cartesianToPolar(const TIn x, const TIn y, TOut &rho, TOut &theta)
cartesian to polar convertion
Definition: Angles2d.h:67
double ipReal64
Base types definition.
Definition: BaseTypes.h:57
IPSDK_FORCEINLINE TOut polarToYCartesian(const TIn rho, const TIn cosTheta, const TIn sinTheta)
polar to cartesian convertion
Definition: Angles2d.h:41
IPSDK_FORCEINLINE void polarToCartesian(const TIn rho, const TIn cosTheta, const TIn sinTheta, TOut &x, TOut &y)
polar to cartesian convertion
Definition: Angles2d.h:47
Utility functions used to handle points 2d.
IPSDK_FORCEINLINE TOut polarToXCartesian(const TIn rho, const TIn cosTheta, const TIn sinTheta)
polar to cartesian convertion
Definition: Angles2d.h:35
Utility functions for angle management.
Utility functions for ipsdk math library.
IPSDK_FORCEINLINE void matrixToAngle(const T rxx, const T rxy, T &theta)
Convertion from rotation matrix to angle.
Definition: Angles2d.h:115
boost::numeric::ublas::bounded_matrix< ipReal64, 2, 2 > Matrix2d
2d matrix (2x2) type associated to library
Definition: LinearAlgebraTypes.h:51
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
IPSDK_FORCEINLINE ipReal64 normL2(const T x, const T y)
L2 norm of a 2d vector.
Definition: Vector2d.h:32