32 #ifndef Matrix2_INCLUDE_ONCE 33 #define Matrix2_INCLUDE_ONCE 48 template<
typename T_Scalar>
57 e(0,0) = (T_Scalar)m.
e(0,0);
e(1,0) = (T_Scalar)m.
e(1,0);
58 e(0,1) = (T_Scalar)m.
e(0,1);
e(1,1) = (T_Scalar)m.
e(1,1);
72 explicit Matrix2(T_Scalar e00, T_Scalar e01,
73 T_Scalar e10, T_Scalar e11 )
75 e(0,0) = e00;
e(0,1) = e01;
76 e(1,0) = e10;
e(1,1) = e11;
82 e(0,1) =
e(1,1) = val;
89 for(
int i=0; i<2; ++i)
90 for(
int j=0; j<2; ++j)
91 if (
e(j,i) > other.
e(j,i))
92 err +=
e(j,i) - other.
e(j,i);
94 err += other.
e(j,i) -
e(j,i);
100 return memcmp(m.
mVec,
mVec,
sizeof(T_Scalar)*4) == 0;
110 memcpy(
mVec, m.
mVec,
sizeof(T_Scalar)*4);
117 for(
int i=0; i<2; ++i)
118 for(
int j=0; j<2; ++j)
119 t.
e(j,i) =
e(j,i) + m.
e(j,i);
125 for(
int i=0; i<2; ++i)
126 for(
int j=0; j<2; ++j)
134 for(
int i=0; i<2; ++i)
135 for(
int j=0; j<2; ++j)
136 t.
e(j,i) =
e(j,i) - m.
e(j,i);
142 for(
int i=0; i<2; ++i)
143 for(
int j=0; j<2; ++j)
156 for(
int i=0; i<2; ++i)
157 for(
int j=0; j<2; ++j)
165 for(
int i=0; i<2; ++i)
166 for(
int j=0; j<2; ++j)
167 t.
e(j,i) =
e(j,i) + d;
173 for(
int i=0; i<2; ++i)
174 for(
int j=0; j<2; ++j)
182 for(
int i=0; i<2; ++i)
183 for(
int j=0; j<2; ++j)
184 t.
e(j,i) =
e(j,i) - d;
190 for(
int i=0; i<2; ++i)
191 for(
int j=0; j<2; ++j)
199 for(
int i=0; i<2; ++i)
200 for(
int j=0; j<2; ++j)
201 t.
e(j,i) =
e(j,i) * d;
207 for(
int i=0; i<2; ++i)
208 for(
int j=0; j<2; ++j)
217 for(
int i=0; i<2; ++i)
218 for(
int j=0; j<2; ++j)
219 t.
e(j,i) =
e(j,i) * d;
226 for(
int i=0; i<2; ++i)
227 for(
int j=0; j<2; ++j)
235 return memcmp(
ptr(), i.
ptr(),
sizeof(T_Scalar)*4) == 0;
243 const T_Scalar*
ptr()
const 251 for(
int i=0; i<2; ++i)
253 for(
int j=i; j<2; ++j)
266 for(
int i=0; i<2; ++i)
267 for(
int j=0; j<2; ++j)
274 for(
int i=0; i<2; ++i)
275 for(
int j=0; j<2; ++j)
276 dest.
e(j,i) =
e(i,j);
282 for(
int i=0; i<2; ++i)
283 for(
int j=0; j<2; ++j)
308 static const T_Scalar I2d[] =
310 (T_Scalar)1, (T_Scalar)0,
311 (T_Scalar)0, (T_Scalar)1
313 memcpy(
mVec, I2d,
sizeof(T_Scalar)*4);
339 const T_Scalar& a11 =
e(0,0);
340 const T_Scalar& a12 =
e(1,0);
341 const T_Scalar& a21 =
e(0,1);
342 const T_Scalar& a22 =
e(1,1);
346 T_Scalar det = a11*a22-a12*a21;
349 dest =
Matrix2(+a22, -a12, -a21, +a11) / det;
376 out.
e(0,0) = q.
e(0,0)*p.
e(0,0) + q.
e(1,0)*p.
e(0,1);
377 out.
e(0,1) = q.
e(0,1)*p.
e(0,0) + q.
e(1,1)*p.
e(0,1);
379 out.
e(1,0) = q.
e(0,0)*p.
e(1,0) + q.
e(1,0)*p.
e(1,1);
380 out.
e(1,1) = q.
e(0,1)*p.
e(1,0) + q.
e(1,1)*p.
e(1,1);
388 return *
this =
multiply(t, *
this, m);
394 return *
this =
multiply(t, m, *
this);
398 const T_Scalar&
e(
int i,
int j)
const {
return mVec[j][i]; }
399 T_Scalar&
e(
int i,
int j) {
return mVec[j][i]; }
412 template<
typename T_Scalar>
420 template<
typename T_Scalar>
426 template<
typename T_Scalar>
433 template<
typename T_Scalar>
437 t.
x() = v.
x()*m.
e(0,0) + v.
y()*m.
e(0,1);
438 t.
y() = v.
x()*m.
e(1,0) + v.
y()*m.
e(1,1);
443 template<
typename T_Scalar>
447 t.
x() = v.
x()*m.
e(0,0) + v.
y()*m.
e(1,0);
448 t.
y() = v.
x()*m.
e(0,1) + v.
y()*m.
e(1,1);
462 #if VL_PIPELINE_PRECISION == 2 bool operator!=(const Matrix2 &m) const
T_Scalar diff(const Matrix2 &other) const
Matrix2 operator/(T_Scalar d) const
Matrix2< double > dmat2
A 2x2 matrix using double precision.
static Matrix2 & getNull(Matrix2 &out)
Matrix2(const Matrix2< T > &m)
Matrix2 & operator*=(T_Scalar d)
static Matrix2 & multiply(Matrix2 &out, const Matrix2 &p, const Matrix2 &q)
Matrix2 operator+(const Matrix2 &m) const
Matrix2 & invert(T_Scalar *determinant=NULL)
Matrix2 & operator/=(T_Scalar d)
The Matrix2 class is a template class that implements a generic 2x2 matrix, see also vl::dmat2...
Matrix2 & operator+=(T_Scalar d)
Matrix2 operator+(T_Scalar d) const
Matrix2 & operator=(const Matrix2 &m)
Matrix2 operator-(const Matrix2 &m) const
Matrix2< int > imat2
A 2x2 matrix using int precision.
Vector2< T_Scalar > mVec[2]
Visualization Library main namespace.
Matrix2 & operator-=(const Matrix2 &m)
Matrix2 & operator-=(T_Scalar d)
const T_Scalar * ptr() const
Matrix2< unsigned int > umat2
A 2x2 matrix using unsigned int precision.
Matrix2 operator*(T_Scalar d) const
Matrix2< float > fmat2
A 2x2 matrix using float precision.
Matrix2(T_Scalar e00, T_Scalar e01, T_Scalar e10, T_Scalar e11)
fmat2 mat2
Defined as: 'typedef fmat2 mat2'. See also VL_PIPELINE_PRECISION.
Matrix2 & preMultiply(const Matrix2 &m)
Matrix2 & fill(T_Scalar val)
const T_Scalar & e(int i, int j) const
bool operator==(const Matrix2 &m) const
Matrix2 getInverse(T_Scalar *determinant=NULL) const
T_Scalar & e(int i, int j)
T_Scalar getInverse(Matrix2 &dest) const
static Matrix2 getIdentity()
Matrix2 & getTransposed(Matrix2 &dest) const
The Vector2 class is a template class that implements a generic 2 components vector, see also vl::fvec2, vl::dvec2, vl::uvec2, vl::ivec2, vl::svec2, vl::usvec2, vl::bvec2, vl::ubvec2.
Matrix2 operator-() const
Matrix2 & operator*=(const Matrix2 &m)
const T_Scalar & x() const
Matrix2 operator-(T_Scalar d) const
Matrix2 & postMultiply(const Matrix2 &m)
const T_Scalar & y() const
Matrix2 & operator+=(const Matrix2 &m)
Matrix2 getTransposed() const
static Matrix2 & getIdentity(Matrix2 &out)