23 #ifndef _Matrix3x3_hh_
24 #define _Matrix3x3_hh_
25 #include "bias_config.h"
27 #include <Base/Debug/Error.hh>
29 #include <Base/Math/Vector3.hh>
37 template <
class T>
class Matrix;
42 std::ostream& operator<<(std::ostream& os, const Matrix3x3<T>& mat);
56 template <
class T=
double>
67 const T a3,
const T a4,
const T a5,
68 const T a6,
const T a7,
const T a8);
92 {
return Data_+3*row; }
96 {
return Data_+3*row; }
111 inline void SetZero();
118 inline void SetIdentity();
150 inline void Scale(
const T &scalar,
Matrix3x3<T> & destmat)
const;
169 inline void TransposeIP();
195 void GetRow(
const unsigned int row,
Vector3<T>& r)
const;
200 void GetColumn(
const unsigned int col,
Vector3<T>& r)
const;
206 void SetColumn(
const unsigned int col,
const Vector3<T>& c);
209 void SetRow(
const unsigned int row,
const Vector3<T>& r);
212 void SetAsCrossProductMatrix(
const Vector3<T> &vec);
216 void SetAsCrossProductMatrix(
const T &x,
const T &y,
const T &z);
231 {
const register T *p = this->GetData();
return p[0] + p[4] + p[8]; }
235 T GetDeterminant()
const;
239 void GetMaxMin(T& max, T&min)
const;
242 void GetAbsMaxMin(T& max, T&min)
const;
250 inline T NormL1()
const;
253 inline double NormFrobenius()
const;
256 {
return NormFrobenius(); }
264 void MakeSymmetric();
267 bool IsZero(
const T eps = std::numeric_limits<T>::epsilon())
const;
270 bool IsIdentity(
const T eps = std::numeric_limits<T>::epsilon())
const;
275 {
return !operator==(arg); }
277 bool Load(
const std::string& fname);
279 bool Save(
const std::string& fname)
const;
296 memset((
void *)Data_, 0, 9*
sizeof(T));
308 const register T *matP = this->GetData();
309 destvec[0] = argvec[0] * matP[0]
310 + argvec[1] * matP[1]
311 + argvec[2] * matP[2];
312 destvec[1] = argvec[0] * matP[3]
313 + argvec[1] * matP[4]
314 + argvec[2] * matP[5];
315 destvec[2] = argvec[0] * matP[6]
316 + argvec[1] * matP[7]
317 + argvec[2] * matP[8];
329 const register T *matP = this->GetData();
330 destvec[0] = argvec[0] * matP[0]
331 + argvec[1] * matP[3]
332 + argvec[2] * matP[6];
333 destvec[1] = argvec[0] * matP[1]
334 + argvec[1] * matP[4]
335 + argvec[2] * matP[7];
336 destvec[2] = argvec[0] * matP[2]
337 + argvec[1] * matP[5]
338 + argvec[2] * matP[8];
351 register T *destP = destmat.
GetData();
352 const register T *argP = argmat.
GetData();
353 const register T *matP = this->GetData();
355 BIASASSERT(destP!=argP);
356 BIASASSERT(destP!=matP);
358 destP[0] = matP[0] * argP[0] + matP[1] * argP[3] + matP[2] * argP[6];
359 destP[1] = matP[0] * argP[1] + matP[1] * argP[4] + matP[2] * argP[7];
360 destP[2] = matP[0] * argP[2] + matP[1] * argP[5] + matP[2] * argP[8];
362 destP[3] = matP[3] * argP[0] + matP[4] * argP[3] + matP[5] * argP[6];
363 destP[4] = matP[3] * argP[1] + matP[4] * argP[4] + matP[5] * argP[7];
364 destP[5] = matP[3] * argP[2] + matP[4] * argP[5] + matP[5] * argP[8];
366 destP[6] = matP[6] * argP[0] + matP[7] * argP[3] + matP[8] * argP[6];
367 destP[7] = matP[6] * argP[1] + matP[7] * argP[4] + matP[8] * argP[7];
368 destP[8] = matP[6] * argP[2] + matP[7] * argP[5] + matP[8] * argP[8];
376 register T *dest = destmat.
GetData();
377 const register T *src = this->GetData();
378 for (
int i=0; i<9; i++)
379 dest[i] = scalar * src[i];
391 register T *dataP = this->GetData();
412 register const T *argp = arg.
GetData();
413 this->Data_[0] = argp[0];
414 this->Data_[4] = argp[4];
415 this->Data_[8] = argp[8];
417 this->Data_[1] = argp[3];
418 this->Data_[2] = argp[6];
419 this->Data_[3] = argp[1];
421 this->Data_[5] = argp[7];
422 this->Data_[6] = argp[2];
423 this->Data_[7] = argp[5];
431 register T* d = this->GetData();
449 for (
int i=0; i<9; i++){
450 result += (double)(Data_[i]) * (double)(Data_[i]);
460 for (
int i=0; i<9; i++){
461 result += (Data_[i]>0)?(Data_[i]):(-(Data_[i]));
491 #include "Operators.hh"
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
unsigned GetNumElements() const
void TransposeIP()
tranpose this matrix "in place" example: 0 1 2 –> 0 3 6 3 4 5 –> 1 4 7 6 7 8 –> 2 5 8 ...
const T * operator[](const unsigned row) const
void TransposedMult(const Vector3< T > &argvec, Vector3< T > &destvec) const
multiplies matrix from left with transposed argvec, resulting in transposed destvec ...
T * operator[](const unsigned row)
const T * GetData() const
BIASMathBase_EXPORT Vector2< T > & operator/=(Vector2< T > &vec, const Vector2< T > &argvec)
elementwise division
T Trace() const
return the trace of the matrix
Matrix3x3< T > operator*(const T &arg, const Matrix3x3< T > &mat)
Vector2< T > & operator-=(Vector2< T > &vec, const Vector2< T > &argvec)
sub operator for two Vectors
class BIASMathBase_EXPORT Matrix
Matrix3x3< T > operator*(const Matrix3x3< T > &mat, const T &arg)
double NormFrobenius() const
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
BIASMathBase_EXPORT Vector2< T > & operator+=(Vector2< T > &vec, const Vector2< T > &argvec)
add operator for two Vectors
Vector2< T > & operator*=(Vector2< T > &vec, const T &scalar)
Multiplication operator with scalar argument.
is a 'fixed size' quadratic matrix of dim.
BIAS::Vector3< T > GetColumn(const unsigned int col) const
Matrix3x3< T > & operator*=(const Matrix3x3< T > &arg)
woelk 11/2007 (c) www.vision-n.de
class Vector3 contains a Vector of fixed dim.
class BIASMathBase_EXPORT Matrix3x3
matrix class with arbitrary size, indexing is row major.
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
bool operator!=(const Matrix3x3< T > &arg) const
void Scale(const T &scalar, Matrix3x3< T > &destmat) const
scalar-matrix multiplication
Matrix3x3< T > operator/(const Matrix3x3< T > &mat, const T &arg)
is a 'fixed size' rectangular matrix of dim.
Vector3< T > GetRow(const unsigned int row) const
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.
void SetIdentity()
set the elements of this matrix to the identity matrix (possibly overriding the inherited method) ...