Hugin trunk 0.1
Loading...
Searching...
No Matches
Matrix3.h
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
24#ifndef _HUGIN_MATH_MATRIX3_H_
25#define _HUGIN_MATH_MATRIX3_H_
26
27#include <hugin_shared.h>
28#include <math.h>
29#include <hugin_math/Vector3.h>
30
31
38{
39public:
41 double m[3][3];
42
44
45public:
47 Matrix3();
48
50 Matrix3(const Matrix3& ot);
51
53 void SetIdentity();
54
56 void SetRotation( double Yaw, double Pitch, double Roll );
57
58#if 0
62 void SetRotationPT( double Yaw, double Pitch, double Roll );
63#endif
64
65
66 // [Ippei note]: Why the hell is this a method of general Matrix3 class?
67 // Should be subclassed or externally provided
68 // eg. static Matrix3 RotationMatrixPanoCommand::makeRotationMatrixPT(double yaw, double pitch, double roll)
69
73 void SetRotationPT( double yaw, double pitch, double roll );
74
76 void GetRotationPT( double & Yaw, double & Pitch, double & Roll );
77
78
80 void SetRotationX( double a );
81
82 void SetRotationY( double a );
83
84 void SetRotationZ( double a );
85
87 Matrix3& operator= (const Matrix3& ot);
88
90 Matrix3 operator*(const Matrix3& ot) const;
91
93 void operator/=(double s);
94
96 void operator*=(double s);
97
99 void operator*=(Matrix3 ot);
100
102 inline bool operator==(Matrix3& ot) const
103 {
104 for(int i=0; i<3; i++)
105 for(int j=0; j<3; j++)
106 if(m[i][j] != ot.m[i][j])
107 return false;
108 return true;
109 }
110
112 inline bool operator!=(Matrix3& ot) const
113 {
114 return !(*this == ot);
115 }
116
119 {
121 Result.m[0][0] = m[0][0];
122 Result.m[0][1] = m[1][0];
123 Result.m[0][2] = m[2][0];
124 Result.m[1][0] = m[0][1];
125 Result.m[1][1] = m[1][1];
126 Result.m[1][2] = m[2][1];
127 Result.m[2][0] = m[0][2];
128 Result.m[2][1] = m[1][2];
129 Result.m[2][2] = m[2][2];
130 return Result;
131 }
132
134 inline double Determinant() const
135 {
136 double result = m[0][0] * ( m[1][1] * m[2][2] - m[2][1] * m[1][2] );
137 result -= m[1][0] * ( m[0][1] * m[2][2] - m[2][1] * m[0][2] );
138 result += m[2][0] * ( m[0][1] * m[1][2] - m[1][1] * m[0][2] );
139 return result;
140 }
141
143 inline Vector3 TransformVector(const Vector3 &V) const
144 {
146 Result.x = V.x * m[0][0] + V.y * m[1][0] + V.z * m[2][0];
147 Result.y = V.x * m[0][1] + V.y * m[1][1] + V.z * m[2][1];
148 Result.z = V.x * m[0][2] + V.y * m[1][2] + V.z * m[2][2];
149 return Result;
150 }
151
153 Matrix3 Inverse() const;
154
156 void Print(std::ostream & o) const;
157
158};
159
162{
163 // is debugged and optimized
165 if (u.Norm()<0.01) {
166 Matrix3 r;
167 r.SetIdentity();
168 return r;
169 }
170 double cs, ss, ux2, uy2, uz2, uxy, uxz, uyz;
171
172 cs = cos(Angle);
173 ss = sin(Angle);
174 ux2 = u.x*u.x;
175 uy2 = u.y*u.y;
176 uz2 = u.z*u.z;
177 uxy = u.x*u.y;
178 uxz = u.x*u.z;
179 uyz = u.y*u.z;
180 Matrix3 m;
181 m.m[0][0] = ux2 + cs*(1-ux2);
182 m.m[1][0] = uxy*(1-cs) - u.z*ss;
183 m.m[2][0] = uxz*(1-cs) + u.y*ss;
184 m.m[0][1] = uxy*(1-cs) + u.z*ss;
185 m.m[1][1] = uy2 + cs*(1-uy2);
186 m.m[2][1] = uyz*(1-cs)-u.x*ss;
187 m.m[0][2] = uxz*(1-cs)-u.y*ss;
188 m.m[1][2] = uyz*(1-cs)+u.x*ss;
189 m.m[2][2] = uz2 + cs*(1-uz2);
190 return m;
191 /*
192 return Matrix3( ux2 + cs*(1-ux2),
193 uxy*(1-cs) - u.z*ss,
194 uxz*(1-cs) + u.y*ss,
195 uxy*(1-cs) + u.z*ss,
196 uy2 + cs*(1-uy2),
197 uyz*(1-cs)-u.x*ss,
198 uxz*(1-cs)-u.y*ss,
199 uyz*(1-cs)+u.x*ss,
200 uz2 + cs*(1-uz2) );
201 */
202}
203
205{
206 return GetRotationAroundU(da, da.Norm());
207}
208
209/*// return the rotation matrix around X
210Matrix3 GetRotationX(double Ang)
211{
212 double a = cos(Ang);
213 double b = sin(Ang);
214 return Matrix3(
215 1.0, 0.0, 0.0,
216 0.0, a, b,
217 0.0, -b, a );
218}
219
220//return the rotation matrix around Y
221Matrix3 GetRotationY(double Ang)
222{
223 double a = cos(Ang);
224 double b = -sin(Ang);
225 return Matrix3(
226 a, 0.0, b,
227 0.0, 1.0, 0.0,
228 -b, 0.0, a );
229}
230
231//return the rotation matrix around Z
232Matrix3 GetRotationZ(double Ang)
233{
234 double a = cos(Ang);
235 double b = sin(Ang);
236 return Matrix3(
237 a, b, 0.0,
238 -b, a, 0.0,
239 0.0, 0.0, 1.0);
240}
241*/
242
243inline std::ostream & operator<<(std::ostream & s, const Matrix3 & m)
244{
245 m.Print(s);
246 return s;
247}
248
249#endif // _H
std::ostream & operator<<(std::ostream &s, const Matrix3 &m)
Definition Matrix3.h:243
Matrix3 GetRotationAroundU(const Vector3 &U, double Angle)
return the rotation matrix around vector U : checked
Definition Matrix3.h:161
general : Matrix3 is a class for handling 3x3 Matrix manipulation.
Definition Matrix3.h:38
void SetIdentity()
Set the identity matrix.
Definition Matrix3.cpp:49
bool operator!=(Matrix3 &ot) const
comparison
Definition Matrix3.h:112
Matrix3 Transpose()
retrieves transpose
Definition Matrix3.h:118
double Determinant() const
get the determinant
Definition Matrix3.h:134
double m[3][3]
we define the Matrix3 as 3 colums of 3 rows
Definition Matrix3.h:41
Vector3 TransformVector(const Vector3 &V) const
transforms a vector
Definition Matrix3.h:143
static Matrix3 Identity
Definition Matrix3.h:43
bool operator==(Matrix3 &ot) const
comparison
Definition Matrix3.h:102
void Print(std::ostream &o) const
Definition Matrix3.cpp:280
general : Vector3 is a class for handling 3D Vectors manipulation.
Definition Vector3.h:44
double x
x,y,z coordinates, 0 at the initialisation
Definition Vector3.h:47
Vector3 GetNormalized() const
return a normalized vector
Definition Vector3.cpp:95
vigra::Diff2D operator*(const vigra::Diff2D &d, double scale)
Definition hugin_math.h:261
#define IMPEX
double Yaw
double Roll
double Pitch
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41