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);
77 explicit Matrix2(T_Scalar e00, T_Scalar e01,
78 T_Scalar e10, T_Scalar e11 )
80 e(0,0) = e00;
e(0,1) = e01;
81 e(1,0) = e10;
e(1,1) = e11;
87 e(0,1) =
e(1,1) = val;
94 for(
int i=0; i<2; ++i)
95 for(
int j=0; j<2; ++j)
96 if (
e(j,i) > other.
e(j,i))
97 err +=
e(j,i) - other.
e(j,i);
99 err += other.
e(j,i) -
e(j,i);
105 return memcmp(m.
mVec,
mVec,
sizeof(T_Scalar)*4) == 0;
115 memcpy(
mVec, m.
mVec,
sizeof(T_Scalar)*4);
122 for(
int i=0; i<2; ++i)
123 for(
int j=0; j<2; ++j)
124 t.
e(j,i) =
e(j,i) + m.
e(j,i);
130 for(
int i=0; i<2; ++i)
131 for(
int j=0; j<2; ++j)
139 for(
int i=0; i<2; ++i)
140 for(
int j=0; j<2; ++j)
141 t.
e(j,i) =
e(j,i) - m.
e(j,i);
147 for(
int i=0; i<2; ++i)
148 for(
int j=0; j<2; ++j)
161 for(
int i=0; i<2; ++i)
162 for(
int j=0; j<2; ++j)
170 for(
int i=0; i<2; ++i)
171 for(
int j=0; j<2; ++j)
172 t.
e(j,i) =
e(j,i) + d;
178 for(
int i=0; i<2; ++i)
179 for(
int j=0; j<2; ++j)
187 for(
int i=0; i<2; ++i)
188 for(
int j=0; j<2; ++j)
189 t.
e(j,i) =
e(j,i) - d;
195 for(
int i=0; i<2; ++i)
196 for(
int j=0; j<2; ++j)
204 for(
int i=0; i<2; ++i)
205 for(
int j=0; j<2; ++j)
206 t.
e(j,i) =
e(j,i) * d;
212 for(
int i=0; i<2; ++i)
213 for(
int j=0; j<2; ++j)
222 for(
int i=0; i<2; ++i)
223 for(
int j=0; j<2; ++j)
224 t.
e(j,i) =
e(j,i) * d;
231 for(
int i=0; i<2; ++i)
232 for(
int j=0; j<2; ++j)
240 return memcmp(
ptr(), i.
ptr(),
sizeof(T_Scalar)*4) == 0;
248 const T_Scalar*
ptr()
const 256 for(
int i=0; i<2; ++i)
258 for(
int j=i; j<2; ++j)
271 for(
int i=0; i<2; ++i)
272 for(
int j=0; j<2; ++j)
279 for(
int i=0; i<2; ++i)
280 for(
int j=0; j<2; ++j)
281 dest.
e(j,i) =
e(i,j);
287 for(
int i=0; i<2; ++i)
288 for(
int j=0; j<2; ++j)
313 static const T_Scalar I2d[] =
315 (T_Scalar)1, (T_Scalar)0,
316 (T_Scalar)0, (T_Scalar)1
318 memcpy(
mVec, I2d,
sizeof(T_Scalar)*4);
344 const T_Scalar& a11 =
e(0,0);
345 const T_Scalar& a12 =
e(1,0);
346 const T_Scalar& a21 =
e(0,1);
347 const T_Scalar& a22 =
e(1,1);
351 T_Scalar det = a11*a22-a12*a21;
354 dest =
Matrix2(+a22, -a12, -a21, +a11) / det;
381 out.
e(0,0) = q.
e(0,0)*p.
e(0,0) + q.
e(1,0)*p.
e(0,1);
382 out.
e(0,1) = q.
e(0,1)*p.
e(0,0) + q.
e(1,1)*p.
e(0,1);
384 out.
e(1,0) = q.
e(0,0)*p.
e(1,0) + q.
e(1,0)*p.
e(1,1);
385 out.
e(1,1) = q.
e(0,1)*p.
e(1,0) + q.
e(1,1)*p.
e(1,1);
393 return *
this =
multiply(t, *
this, m);
399 return *
this =
multiply(t, m, *
this);
403 const T_Scalar&
e(
int i,
int j)
const {
return mVec[j][i]; }
404 T_Scalar&
e(
int i,
int j) {
return mVec[j][i]; }
417 template<
typename T_Scalar>
425 template<
typename T_Scalar>
431 template<
typename T_Scalar>
438 template<
typename T_Scalar>
442 t.
x() = v.
x()*m.
e(0,0) + v.
y()*m.
e(0,1);
443 t.
y() = v.
x()*m.
e(1,0) + v.
y()*m.
e(1,1);
448 template<
typename T_Scalar>
452 t.
x() = v.
x()*m.
e(0,0) + v.
y()*m.
e(1,0);
453 t.
y() = v.
x()*m.
e(0,1) + v.
y()*m.
e(1,1);
467 #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(const Matrix2 &other)
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)