25 #ifndef __Operators_hh__
26 #define __Operators_hh__
28 #include <Base/Math/Matrix.hh>
31 #include <Base/Debug/Error.hh>
32 #include <Base/Math/tnt/cmat.h>
37 template<
class T>
class BIASMathBase_EXPORT
Matrix;
38 template<
class T>
class BIASMathBase_EXPORT
Vector;
39 template<
class T>
class BIASMathBase_EXPORT
Matrix2x2;
40 template<
class T>
class BIASMathBase_EXPORT
Vector2;
41 template<
class T>
class BIASMathBase_EXPORT
Matrix2x3;
42 template<
class T>
class BIASMathBase_EXPORT
Matrix3x2;
43 template<
class T>
class BIASMathBase_EXPORT
Matrix3x3;
44 template<
class T>
class BIASMathBase_EXPORT
Vector3;
45 template<
class T>
class BIASMathBase_EXPORT
Matrix4x4;
46 template<
class T>
class BIASMathBase_EXPORT
Vector4;
47 template<
class T>
class BIASMathBase_EXPORT
Matrix3x4;
67 {
return Vector4<T>( -v[0],-v[1],-v[2],-v[3] ); }
97 vec.
Add(scalar, result);
107 vec.
Add(scalar, result);
118 vec.
Sub(scalar, result);
129 vec.
Sub(scalar, result);
161 BIASASSERT(scalar !=(T)0);
163 vec.
Divide(scalar, result);
192 vec.
Add(scalar, result);
202 return vec.
Sub(scalar);
224 vec.
Divide(scalar, result);
258 BIASERR(
"Division by Zero!");
274 v.
Add(scalar, result);
285 v.
Sub(scalar, result);
315 inline bool operator<= (const Vector2<T>& a,
const Vector2<T>& b)
316 {
return a[0]<=b[0] && a[1]<=b[1]; }
321 inline bool operator< (const Vector2<T>& a,
const Vector2<T>& b)
322 {
return a[0]<b[0] && a[1]<b[1]; }
343 vec.
Add(argvec, destvec);
354 vec.
Sub(argvec, destvec);
362 return vec[0]*argvec[0]+vec[1]*argvec[1];
380 inline bool operator<= (const Vector3<T>& a,
const Vector3<T>& b)
381 {
return a[0]<=b[0] && a[1]<=b[1] && a[2]<=b[2]; }
386 inline bool operator< (const Vector3<T>& a,
const Vector3<T>& b)
387 {
return a[0]<b[0] && a[1]<b[1] && a[2]<b[2]; }
411 vec.
Add(scalar, result);
422 vec.
Add(argvec, destvec);
434 if (argvec.
size()!=3) {
435 BIASERR(
"operator+: argument does not havesize 3");
438 destvec[0]=vec[0]+argvec[0];
439 destvec[1]=vec[1]+argvec[1];
440 destvec[2]=vec[2]+argvec[2];
451 vec.
Sub(argvec, destvec);
470 inline bool operator<= (const Vector4<T>& a,
const Vector4<T>& b)
471 {
return a[0]<=b[0] && a[1]<=b[1] && a[2]<=b[2] && a[3]<=b[3]; }
476 inline bool operator< (const Vector4<T>& a,
const Vector4<T>& b)
477 {
return a[0]<b[0] && a[1]<b[1] && a[2]<b[2] && a[3]<b[3]; }
509 v.
Sub(argvec, destvec);
520 v.
Add(argvec, destvec);
562 for (
size_t i=0; i<6; i++) resP[i] = scalar*matP[i];
573 for (
size_t i=0; i<6; i++) resP[i] = scalar*matP[i];
585 for (
size_t i=0; i<6; i++) resP[i] = scalar*matP[i];
596 for (
size_t i=0; i<6; i++) resP[i] = scalar*matP[i];
624 { mat.
DivideIP(scalar);
return mat; }
642 mat.
Mult(argvec, destvec);
655 mat.
Mult(argvec, destvec);
666 for (
register int i=0; i<mat.
num_rows(); i++)
667 res[i]=mat[i][0]*vec[0]+mat[i][1]*vec[1];
677 res[0]=mat[0][0]*vec[0]+mat[0][1]*vec[1];
678 res[1]=mat[1][0]*vec[0]+mat[1][1]*vec[1];
688 res[0]= mat[0][0]*vec[0] + mat[0][1]*vec[1] + mat[0][2]*vec[2];
689 res[1]= mat[1][0]*vec[0] + mat[1][1]*vec[1] + mat[1][2]*vec[2];
699 res[0]= mat[0][0]*vec[0] + mat[0][1]*vec[1];
700 res[1]= mat[1][0]*vec[0] + mat[1][1]*vec[1];
701 res[2]= mat[2][0]*vec[0] + mat[2][1]*vec[1];
715 for (y=0; y<(int)result.Size(); y++)
717 result[y]+=mat[y][i]*vec[i];
727 mat.
Mult(argvec, destvec);
741 for (y=0; y<result.size(); y++)
743 result[y]+=mat[y][i]*vec[i];
754 template <
class T>
inline void
759 const int res_x = lc+rc-1, res_y = lr+rr-1;
762 for (
int y=0; y<res_y; y++){
763 const int miny = (y<rr)?(0):(y-rr+1);
764 const int maxy = (y<lr)?(y+1):(lr);
766 for (
int x=0; x<res_x; x++){
767 const int minx = (x<rc)?(0):(x-rc+1);
768 const int maxx = (x<lc)?(x+1):(lc);
771 for (
int r=miny; r<maxy; r++){
772 for (
int c=minx; c<maxx; c++){
773 BIASASSERT(r>=0 && r<lr);
774 BIASASSERT(c>=0 && c<lc);
775 BIASASSERT(y-r>=0 && y-r<rr);
776 BIASASSERT(x-c>=0 && x-c<rc);
777 sum += left[r][c] * right[y-r][x-c];
791 register T *destP = destmat.
GetData();
792 const register T *argP = argMat.
GetData();
793 const register T *matP = mat.
GetData();
796 matP[0] * argP[0] + matP[1] * argP[2];
798 matP[0] * argP[1] + matP[1] * argP[3];
801 matP[2] * argP[0] + matP[3] * argP[2];
803 matP[2] * argP[1] + matP[3] * argP[3];
814 register T *destP = destmat.
GetData();
815 const register T *argP = argmat.
GetData();
816 const register T *matP = mat.
GetData();
818 destP[0] = matP[0] * argP[0] + matP[1] * argP[3] + matP[2] * argP[6];
819 destP[1] = matP[0] * argP[1] + matP[1] * argP[4] + matP[2] * argP[7];
820 destP[2] = matP[0] * argP[2] + matP[1] * argP[5] + matP[2] * argP[8];
821 destP[3] = matP[3] * argP[0] + matP[4] * argP[3] + matP[5] * argP[6];
822 destP[4] = matP[3] * argP[1] + matP[4] * argP[4] + matP[5] * argP[7];
823 destP[5] = matP[3] * argP[2] + matP[4] * argP[5] + matP[5] * argP[8];
835 register T *destP = destmat.
GetData();
836 const register T *argP = argmat.
GetData();
837 const register T *matP = mat.
GetData();
839 destP[0] = matP[0] * argP[0] + matP[1] * argP[2];
840 destP[1] = matP[0] * argP[1] + matP[1] * argP[3];
841 destP[2] = matP[0] * argP[2] + matP[1] * argP[4];
842 destP[3] = matP[2] * argP[0] + matP[3] * argP[2];
843 destP[4] = matP[2] * argP[1] + matP[3] * argP[3];
844 destP[5] = matP[2] * argP[2] + matP[3] * argP[4];
857 argL.
Mult(argR, resMat);
892 mat.
Mult(argMat, resMat);
911 #endif // __Operators_hh__
T ScalarProduct(const Vector< T > &argvec) const
scalar product (inner product) of two vectors returning a scalr
Vector4< T > operator-(const Vector4< T > &v)
Matrix< T > operator+(const Matrix< T > &mat, const T &scalar)
void Add(const T &scalar, Vector2< T > &dest) const
Addition with a scalar, storing results in destionation vector.
Vector2< T > operator+(const Vector2< T > &vec, const Vector2< T > &argvec)
void Sub(const T &scalar, Vector4< T > &dest) const
Substraction with a scalar, storing results in destionation vector.
Vector< T > operator*(const Matrix< T > &mat, const Vector2< T > &vec)
Matrix2x3< T > operator*(const Matrix2x3< T > &mat, const T &scalar)
void Multiply(const T &scalar, Vector4< T > &dest) const
Multiplication with a scalar, storing results in destionation vector.
void Add(const T &scalar, Vector4< T > &dest) const
Addition with a scalar, storing results in destionation vector.
T operator*(const Vector4< T > &v, const Vector4< T > &argvec)
Matrix2x3< T > operator*(const Matrix2x3< T > &mat, const Matrix3x3< T > &argmat)
Matrix3x3< T > operator-(const Matrix3x3< T > &left, const Matrix3x3< T > &right)
Subscript num_cols() const
class for column vectors with arbitrary size
is a 'fixed size' quadratic matrix of dim.
is a 'fixed size'
void Add(const T &scalar, Vector3< T > &dest) const
Addition with a scalar, storing results in destionation vector.
void Sub(const T &scalar, Vector2< T > &dest) const
Substraction with a scalar, storing results in destionation vector.
Matrix< T > operator*(const T &scalar, const Matrix< T > &mat)
Vector4< T > operator/(const Vector4< T > &v, const T &scalar)
Matrix3x4< T > operator*(const Matrix3x3< T > &mat, const Matrix3x4< T > &arg)
Vector2< T > operator-(const Vector2< T > &v)
Vector3< T > operator*(const Vector3< T > &vec, const T &scalar)
void ScalarProduct(const Vector3< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
Vector4< T > operator-(const Vector4< T > &v, const T &scalar)
Matrix3x3< T > operator*(const Matrix3x3< T > &argL, const Matrix3x3< T > &argR)
T operator*(const Vector2< T > &vec, const Vector2< T > &argvec)
Vector3< T > operator*(const Matrix3x4< T > &mat, const Vector4< T > &argvec)
Vector2< T > operator/(const Vector2< T > &vec, const T &scalar)
Matrix< T > & newsize(Subscript M, Subscript N)
Matrix< T > operator*(const Matrix3x3< T > &argLeft, const Matrix< T > &argMat)
void Multiply(const T &scalar, Vector3< T > &dest) const
Multiplication with a scalar, storing results in destination vector.
Matrix< T > operator+(const T &scalar, const Matrix< T > &mat)
Vector3< T > operator-(const Vector3< T > &v)
void Multiply(const T &scalar, Vector2< T > &dest) const
Multiplication with a scalar, storing results in destionation vector.
Vector3< T > operator*(const T &scalar, const Vector3< T > &vec)
Vector3< T > operator+(const Vector3< T > &vec, const Vector< T > &argvec)
Vector2< T > operator*(const Matrix2x2< T > &mat, const Vector2< T > &vec)
Matrix4x4< T > operator*(const Matrix4x4< T > &mat, const Matrix4x4< T > &argMat)
class Vector2 contains a Vector of dim.
class Vector4 contains a Vector of dim.
Vector3< T > operator+(const Vector3< T > &vec, const T &scalar)
Matrix< T > matmult(const Matrix< T > &A, const Matrix< T > &B)
Vector< T > operator*(const T &scalar, const Vector< T > &v)
void Mult(const Vector3< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector3, storing the result in destvec calculates: dest...
Matrix2x3< T > operator*(const T &scalar, const Matrix2x3< T > &mat)
void Mult(const Vector4< T > &argvec, Vector4< T > &destvec) const
matrix - vector multiplicate this matrix with Vector4, storing the result in destvec, calculates: destvec = (this Matrix) * argvec
Vector2< T > operator-(const Vector2< T > &vec, const Vector2< T > &argvec)
void Mult(const T &scalar, Vector3< T > &dest) const
Vector4< T > operator*(const Matrix4x4< T > &mat, const Vector4< T > &argvec)
DualQuaternion< T > operator+(const DualQuaternion< T > &l, const DualQuaternion< T > &r)
void Divide(const T &scalar, Vector4< T > &dest) const
Division with a scalar, storing results in destionation vector.
bool operator>(const BIAS::Polynom &p1, const BIAS::Polynom &p2)
Vector3< T > operator-(const Vector3< T > &vec, const T &scalar)
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
is a 'fixed size' 2x3 matrix templated over the elemnt-type.
is a 'fixed size' quadratic matrix of dim.
Matrix< T > & operator/=(Matrix< T > &mat, const T &scalar)
void DivideIP(const T &scalar)
in place division function
T operator*(const Vector3< T > &vec, const Vector3< T > &arg)
Vector< T > operator*(const BIAS::Matrix< T > &mat, const Vector4< T > &vec)
void Set(const T &scalar)
class Vector3 contains a Vector of fixed dim.
Matrix3x2< T > operator*(const Matrix3x2< T > &mat, const Matrix2x2< T > &argmat)
void Divide(const T &scalar, Vector2< T > &dest) const
Division with a scalar, storing results in destination vector.
void ScalarProduct(const Vector4< T > &argvec, T &result) const
scalar product (=inner product) of two vectors, storing the result in result
Vector3< T > operator/(const Vector3< T > &vec, const T &scalar)
void Sub(const T &scalar, Vector3< T > &dest) const
Substraction with a scalar, storing results in destination vector.
matrix class with arbitrary size, indexing is row major.
Matrix< T > operator*(const Matrix< T > &mat, const T &scalar)
Vector3< T > operator-(const Vector3< T > &vec, const Vector3< T > &argvec)
void Mult(const Vector4< T > &argvec, Vector3< T > &destvec) const
matrix - vector multiplicate this matrix with Vector4, storing the result in destvec calculates: dest...
void Multiply(const T &scalar, Vector< T > &res) const
multiply components with scalar storing result in res
Vector< T > operator*(const Vector< T > &v, const T &scalar)
Vector4< T > operator*(const Vector4< T > &v, const T &scalar)
Vector4< T > operator-(const Vector4< T > &v, const Vector4< T > &argvec)
Vector4< T > operator*(const T &scalar, const Vector4< T > &v)
Vector3< T > operator-(const T &scalar, const Vector3< T > &vec)
void Multiply(const T &scalar, Matrix< T > &dest) const
multiplication function, storing data destination matrix
void Sub(const T &scalar, Matrix< T > &dest) const
substraction function, storing data destination matrix
Matrix< T > operator-(const T &scalar, const Matrix< T > &mat)
Vector2< T > operator-(const T &scalar, const Vector2< T > &vec)
void Divide(const T &scalar, Vector3< T > &dest) const
Division with a scalar, storing results in destination vector.
Vector2< T > operator-(const Vector2< T > &vec, const T &scalar)
void Add(const T &scalar, Matrix< T > &dest) const
addition function, storing data destination matrix
Vector2< T > operator*(const Matrix2x3< T > &mat, const Vector3< T > &vec)
T operator*(const Vector< T > &v, const Vector< T > &argvec)
Vector3< T > operator*(const Matrix3x2< T > &mat, const Vector2< T > &vec)
Subscript num_rows() const
Vector4< T > operator+(const Vector4< T > &v, const T &scalar)
Vector2< T > operator*(const T &scalar, const Vector2< T > &vec)
Matrix2x2< T > operator*(const Matrix2x2< T > &mat, const Matrix2x2< T > &argMat)
void Divide(const T &scalar, Matrix< T > &dest) const
division function, storing data destination matrix
is a 'fixed size' rectangular matrix of dim.
is a 'fixed size' quadratic matrix of dim.
Matrix3x2< T > operator*(const T &scalar, const Matrix3x2< T > &mat)
Vector3< T > operator*(const Matrix3x3< T > &mat, const Vector3< T > &argvec)
Vector2< T > operator*(const Vector2< T > &vec, const T &scalar)
void Conv(const Matrix< T > &left, const Matrix< T > &right, Matrix< T > &res)
zero padded convolution of two matrices
Matrix< T > operator-(const Matrix< T > &mat, const T &scalar)
Vector3< T > operator+(const Vector3< T > &vec, const Vector3< T > &argvec)
Matrix< T > operator/(const Matrix< T > &mat, const T &scalar)
Matrix3x3< T > operator+(const Matrix3x3< T > &left, const Matrix3x3< T > &right)
Vector3< T > operator+(const T &scalar, const Vector3< T > &vec)
Vector4< T > operator+(const Vector4< T > &v, const Vector4< T > &argvec)
Vector< T > operator*(const BIAS::Matrix< T > &mat, const Vector3< T > &vec)
Matrix3x2< T > operator*(const Matrix3x2< T > &mat, const T &scalar)