Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Matrix3x2.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef _Matrix3x2_hh_
26 #define _Matrix3x2_hh_
27 #include "bias_config.h"
28 
29 #include <Base/Debug/Error.hh>
30 
31 #include "Matrix.hh"
32 #include "Matrix2x3.hh"
33 #include "Matrix2x2.hh"
34 #include "Vector2.hh"
35 #include "Vector3.hh"
36 
37 namespace BIAS {
38 
39 /**
40  @class Matrix3x2
41  @ingroup g_math
42  @brief is a 'fixed size'
43 **/
44 
45  template<class T=double>
46  class BIASMathBase_EXPORT Matrix3x2 : public Matrix<T>
47  {
48  public:
49  inline Matrix3x2<T>() : Matrix<T>(3, 2) {};
50 
51  explicit Matrix3x2<T>(const MatrixInitType& i) : Matrix<T>(3, 2, T(0)) {
52  switch (i) {
53  case MatrixZero:return;
54  case MatrixIdentity:{
55  this->v_[0] = this->v_[3] = T(1); return;
56  }
57  default:
58  BIASERR("undefined MatrixInitType");
59  BIASABORT;
60  }
61  }
62 
63  /** @author apetersen 2/3/2012 **/
64  Matrix3x2<T>(const Matrix3x2<T> & A) : Matrix<T>(A) {};
65 
66  /** cast constructor from TNT::Matrix */
68 
69  /** Set the matrix to | a0 a1 |
70  | a2 a3 |
71  | a4 a5 | */
73  const T a0, const T a1,
74  const T a2, const T a3,
75  const T a4, const T a5);
76 
77  virtual ~Matrix3x2<T>(){};
78 
79  /** matrix - vector multiplicate this matrix with Vector3,
80  storing the result in destvec
81  calculates:
82  destvec = (this Matrix) * argvec
83  **/
84  inline void Mult(const Vector2<T> &argvec, Vector3<T> &destvec) const;
85 
86  /** matrix - vector multiplicate this matrix with Vector2,
87  storing the result in destvec
88  calculates:
89  destvec^T = argvec^T * (this Matrix)
90  **/
91  inline void MultLeft(const Vector3<T> &argvec, Vector2<T> &destvec) const;
92 
93  /** @brief transposed argvec multipied from left, wrapper function */
94  Vector2<T> MultLeft(const Vector3<T> &argvec) const {
95  Vector2<T> ret; MultLeft(argvec, ret); return ret;
96  }
97 
98  /** matrix-matrix multiplication with Matrix2x2,
99  storing the result in destmat
100  calculates:
101  destmat = (this mat) * argmat
102  **/
103  inline void Mult(const Matrix2x2<T> & argmat, Matrix3x2<T> & destmat)const;
104 
105  /** assignment operator **/
106  Matrix3x2<T>& operator=(const Matrix3x2<T> &mat);
107 
108  /** returns transposed matrix*/
109  inline Matrix2x3<T> Transpose() const;
110 
111  /** set the elements of this matrix to the identity matrix **/
112  inline void SetIdentity();
113 
114  /** set the elements of this matrix to zero **/
115  inline void SetZero();
116 
117  /// stl conform interface
118  inline void clear() {
119  SetZero();
120  };
121 
122  /** Fixed size matrix, resize not allowed **/
123  Matrix3x2 & newsize(int rows, int cols)
124  { BIASERR("CANNOT RESIZE FIXED SIZE MATRIX!!!");
125  BIASABORT; };
126  }; // class
127 
128 
129  template <class T>
130  Matrix3x2<T>::Matrix3x2(const T a0, const T a1,
131  const T a2, const T a3,
132  const T a4, const T a5)
133  { this->v_[0] = a0; this->v_[1] = a1;
134  this->v_[2] = a2; this->v_[3] = a3;
135  this->v_[4] = a4; this->v_[5] = a5; }
136 
137  template <class T>
139  {
140  register T *vP = this->v_;
141  register const T *matP = mat.GetData();
142 
143  vP[0] = matP[0]; vP[1] = matP[1];
144  vP[2] = matP[2]; vP[3] = matP[3];
145  vP[4] = matP[4]; vP[5] = matP[5];
146 
147  return *this;
148  }
149 
150  template <class T>
152  {
153  Matrix2x3<T> res;
154 
155  register const T *dataP = this->GetData();
156  register T *resP = res.GetData();
157  resP[0] = dataP[0]; resP[1] = dataP[2]; resP[2] = dataP[4];
158  resP[3] = dataP[1]; resP[4] = dataP[3]; resP[5] = dataP[5];
159 
160  return res;
161  }
162 
163  template <class T>
164  inline void Matrix3x2<T>::Mult(const Matrix2x2<T> & argmat,
165  Matrix3x2<T> & destmat) const
166  {
167  register T *destP = destmat.GetData();
168  const register T *argP = argmat.GetData();
169  const register T *matP = this->GetData();
170 
171  destP[0] = matP[0] * argP[0] + matP[1] * argP[2];
172  destP[1] = matP[0] * argP[1] + matP[1] * argP[3];
173  destP[2] = matP[2] * argP[0] + matP[3] * argP[2];
174  destP[3] = matP[2] * argP[1] + matP[3] * argP[3];
175  destP[4] = matP[4] * argP[0] + matP[5] * argP[2];
176  destP[5] = matP[4] * argP[1] + matP[5] * argP[3];
177 
178  }
179 
180  template <class T>
181  inline void Matrix3x2<T>::Mult(const Vector2<T> &argvec,
182  Vector3<T> &destvec) const
183  {
184  const register T *matP = this->GetData();
185  destvec[0] = matP[0] * argvec[0] + matP[1] * argvec[1];
186  destvec[1] = matP[2] * argvec[0] + matP[3] * argvec[1];
187  destvec[2] = matP[4] * argvec[0] + matP[5] * argvec[1];
188  }
189 
190  template <class T>
191  inline void Matrix3x2<T>::MultLeft(const Vector3<T> &argvec,
192  Vector2<T> &destvec) const
193  {
194  const register T *matP = this->GetData();
195  destvec[0] = argvec[0] * matP[0] + argvec[1] * matP[2] + argvec[2] * matP[4];
196  destvec[1] = argvec[0] * matP[1] + argvec[1] * matP[3] + argvec[2] * matP[5];
197  }
198 
199 
200  template <class T>
202  register T* d = this->GetData(); // pointer to this matrix's data array
203  d[0] = d[3] = 1;
204  d[1] = d[2] = d[4] = d[5] = 0;
205  }
206 
207  template <class T>
208  inline void Matrix3x2<T>::SetZero() {
209  register T* d = this->GetData(); // pointer to this matrix's data array
210  d[0]=d[1]=d[2]=d[3]=d[4]=d[5] =0;
211  }
212 
213 } // end of namespace BIAS
214 
215 #include "Operators.hh"
216 
217 #endif // _Matrix3x2_hh_
MatrixInitType
can be passed to matrix constructors to init the matrix with the most often used values ...
Definition: Matrix.hh:59
is a &#39;fixed size&#39; quadratic matrix of dim.
Definition: Matrix2x2.hh:48
is a &#39;fixed size&#39;
Definition: Matrix3x2.hh:46
Matrix2x3< T > Transpose() const
returns transposed matrix
Definition: Matrix3x2.hh:151
void MultLeft(const Vector3< T > &argvec, Vector2< T > &destvec) const
matrix - vector multiplicate this matrix with Vector2, storing the result in destvec calculates: dest...
Definition: Matrix3x2.hh:191
class Vector2 contains a Vector of dim.
Definition: Vector2.hh:79
Vector2< T > MultLeft(const Vector3< T > &argvec) const
transposed argvec multipied from left, wrapper function
Definition: Matrix3x2.hh:94
void Mult(const Vector2< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Definition: Matrix3x2.hh:181
void clear()
stl conform interface
Definition: Matrix3x2.hh:118
void SetIdentity()
set the elements of this matrix to the identity matrix
Definition: Matrix3x2.hh:201
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
Definition: Matrix.hh:185
is a &#39;fixed size&#39; 2x3 matrix templated over the elemnt-type.
Definition: Matrix2x3.hh:49
class Vector3 contains a Vector of fixed dim.
Definition: Matrix.hh:53
void SetZero()
set the elements of this matrix to zero
Definition: Matrix3x2.hh:208
matrix class with arbitrary size, indexing is row major.
Matrix3x2 & newsize(int rows, int cols)
Fixed size matrix, resize not allowed.
Definition: Matrix3x2.hh:123
Matrix3x2< T > & operator=(const Matrix3x2< T > &mat)
assignment operator
Definition: Matrix3x2.hh:138