Matrix Class Reference

#include <Matrix.h>

List of all members.

Public Member Functions

 Matrix ()
 Matrix (const Matrix &_M)
 ~Matrix ()
Matrix multiply (Matrix M2)
double * multiply (double *x)
int multiply_internally (double *x)
int multiply_rotation_internally (double *normal_copy)
double det () const
int set_identity ()
int set_zero ()
int set_translation (double *t)
int set_translation (double tx, double ty, double tz)
int add_translation (double *t)
int add_translation (double tx, double ty, double tz)
int set_euler_angle (double *r)
int set_euler_angle (double theta_1, double theta_2, double theta_3)
int set_rotation_matrix (double *axis, double angle)
int set_rotation_matrix (double x_axis, double y_axis, double z_axis, double angle)
Matrix multiply_rotation (double *axis, double angle)
Matrix multiply_rotation (double x_axis, double y_axis, double z_axis, double angle)
int build_rotation_matrix_to_vector (const V_3D v, const V_3D w)
double value (int k_x, int k_y) const
double & value (int k_x, int k_y)
double v (int k_x, int k_y) const
double & v (int k_x, int k_y)
int set_value (double val, int k_x, int k_y)
int set_value (double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)
int set_vector_rotation (double *v, double theta)
int set_vector_rotation (double v_x, double v_y, double v_z, double theta)
int multiply_vector_rotation (double *v, double theta)
Matrix get_rotation_part ()
int set_rotation_part (Matrix R)
int set_translation_part (Matrix T)
Matrixoperator= (const Matrix &)
Matrixoperator+= (const Matrix &)
Matrixoperator/= (const double &)
double & operator[] (int k_dim)
double operator[] (int k_dim) const
double operator() (int k_1, int k_2) const
 Return matrix(k_row,k_column).
double & operator() (int k_1, int k_2)
Matrix invert () const
int get_position (double *p)
V_3D get_position ()
int scale (double *s)

Private Attributes

double M [16]

Friends

ostream & operator<< (ostream &flux, Matrix M)
Matrix operator* (const Matrix &, const Matrix &)
Matrix operator* (const Matrix &, const double &)
Matrix operator* (const double &, const Matrix &)
V_3D operator* (const Matrix &, const V_3D &)
V_3D operator* (const V_3D &, const Matrix &)
Matrix operator+ (const Matrix &, const Matrix &)
Matrix operator- (const Matrix &, const Matrix &)
int operator== (const Matrix &, const Matrix &)
int operator!= (const Matrix &, const Matrix &)


Detailed Description

Definition at line 25 of file Matrix.h.


Constructor & Destructor Documentation

Matrix::Matrix (  ) 

Definition at line 7 of file Matrix.cpp.

References set_identity().

00008 {
00009   set_identity();
00010 }

Here is the call graph for this function:

Matrix::Matrix ( const Matrix _M  ) 

Definition at line 15 of file Matrix.cpp.

References M, and set_value().

00016 {
00017   for(int k_x=0;k_x<4;k_x++)
00018     for(int k_y=0;k_y<4;k_y++)
00019       this->set_value(_M.M[k_x+4*k_y],k_x,k_y);
00020 }

Here is the call graph for this function:

Matrix::~Matrix (  ) 

Definition at line 12 of file Matrix.cpp.

00013 {
00014 }


Member Function Documentation

Matrix Matrix::multiply ( Matrix  M2  ) 

Definition at line 22 of file Matrix.cpp.

References M, and value().

Referenced by multiply_vector_rotation(), Skeleton::reccursive_bone_looking_for_position(), and set_euler_angle().

00023 {
00024 
00025   double temp_M[16];
00026 
00027   int k_x=0,k_y=0,k_m=0;
00028   double temp=0;
00029 
00030   //all index
00031   for(k_x=0;k_x<4;k_x++)
00032     for(k_y=0;k_y<4;k_y++)
00033       {
00034         //multiply
00035         for(k_m=0,temp=0;k_m<4;k_m++)
00036           {
00037             temp += M[k_m+4*k_y] * (M2.value(k_x,k_m));
00038           }
00039         temp_M[k_x+4*k_y] = temp;
00040       }
00041 
00042   //set new matrix
00043   for(int k=0;k<16;k++)
00044     M[k]=temp_M[k];
00045 
00046   return *this;
00047 }

Here is the call graph for this function:

Here is the caller graph for this function:

double * Matrix::multiply ( double *  x  ) 

Definition at line 49 of file Matrix.cpp.

References M.

00050 {
00051   double x_homogeneous[4]={x[0],x[1],x[2],1};
00052   double temp[4]={0,0,0,0};
00053   int k_x=0,k_y=0;
00054   for(k_x=0;k_x<4;k_x++)
00055     for(k_y=0;k_y<4;k_y++)
00056       temp[k_y] += M[k_x+4*k_y]*x_homogeneous[k_x];
00057   
00058 
00059   //reduce to 3D
00060   double *output = new double[3];
00061   for(int k=0;k<3;k++)
00062     output[k]=temp[k];
00063   return output;
00064 
00065 }

int Matrix::multiply_internally ( double *  x  ) 

Definition at line 67 of file Matrix.cpp.

References M.

00068 {
00069   int ok=0;
00070 
00071   double temp[4]={0,0,0,0};
00072   double x_homogeneous[4]={x[0],x[1],x[2],1};
00073   int k_x=0,k_y=0;
00074 
00075   for(k_y=0;k_y<4;k_y++)
00076     for(k_x=0;k_x<4;k_x++)
00077       temp[k_y] += M[k_x+4*k_y]*x_homogeneous[k_x];
00078   for(int k=0;k<3;k++)
00079     x[k]=temp[k];
00080 
00081   return ok;
00082 }

int Matrix::multiply_rotation_internally ( double *  normal_copy  ) 

Definition at line 453 of file Matrix.cpp.

References M.

00454 {
00455   int ok=0;
00456 
00457   double temp[4]={0,0,0,0};
00458   double n_homogeneous[4]={n[0],n[1],n[2],1};
00459   int k_x=0,k_y=0;
00460 
00461   for(k_x=0;k_x<3;k_x++)
00462     for(k_y=0;k_y<3;k_y++)
00463       temp[k_y] += M[k_x+4*k_y]*n_homogeneous[k_x];
00464   for(int k=0;k<3;k++)
00465     n[k]=temp[k];
00466 
00467   return ok;
00468 }

double Matrix::det (  )  const

Definition at line 580 of file Matrix.cpp.

References v().

Referenced by invert().

00581 {
00582   return 
00583     v(0,0)*
00584     (
00585      +v(1,1)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00586      -v(1,2)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00587      +v(1,3)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00588      )
00589     -
00590     v(0,1)*
00591     (
00592      +v(1,0)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00593      -v(1,2)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00594      +v(1,3)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00595      )
00596     +v(0,2)*
00597     (
00598      +v(1,0)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00599      -v(1,1)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00600      +v(1,3)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00601      )
00602     -v(0,3)*
00603     (
00604      +v(1,0)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00605      -v(1,1)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00606      +v(1,2)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00607      )
00608     ;
00609     
00610 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Matrix::set_identity (  ) 

Definition at line 85 of file Matrix.cpp.

References M.

Referenced by Matrix().

00086 {
00087   for(int k_x=0;k_x<4;k_x++)
00088     for(int k_y=0;k_y<4;k_y++)
00089       {
00090         if(k_x==k_y)
00091           M[k_x+4*k_y]=1;
00092         else
00093           M[k_x+4*k_y]=0;
00094       }
00095   
00096   return 0;
00097 }

Here is the caller graph for this function:

int Matrix::set_zero (  ) 

Definition at line 99 of file Matrix.cpp.

References M.

00100 {
00101   for(int k=0;k<16;k++)
00102     M[k]=0;
00103   return 0;
00104 }

int Matrix::set_translation ( double *  t  ) 

Definition at line 107 of file Matrix.cpp.

References M.

Referenced by Skeleton::add_new_joint(), Animation_transformation::get_translation(), Point_set::rotate(), Joint::set_position(), and set_translation().

00108 {
00109   M[3]  = t[0];
00110   M[7]  = t[1];
00111   M[11] = t[2];
00112 
00113   return 0;
00114 }

Here is the caller graph for this function:

int Matrix::set_translation ( double  tx,
double  ty,
double  tz 
)

Definition at line 116 of file Matrix.cpp.

References set_translation().

00117 {
00118   double t[3]={tx,ty,tz};
00119   return set_translation(t);
00120 }

Here is the call graph for this function:

int Matrix::add_translation ( double *  t  ) 

Definition at line 371 of file Matrix.cpp.

References M.

Referenced by Joint::add_position(), and add_translation().

00372 {
00373   for(int k_dim=0;k_dim<3; M[3+4*k_dim]+=t[k_dim],k_dim++);
00374   return 0;
00375 }

Here is the caller graph for this function:

int Matrix::add_translation ( double  tx,
double  ty,
double  tz 
)

Definition at line 377 of file Matrix.cpp.

References add_translation().

00378 {
00379   double t[3]={tx,ty,tz};
00380   return add_translation(t);
00381 }

Here is the call graph for this function:

int Matrix::set_euler_angle ( double *  r  ) 

Definition at line 224 of file Matrix.cpp.

References multiply(), and set_value().

Referenced by set_euler_angle(), and Joint::set_orientation().

00225 {
00226   double cos_theta = cos(r[0]);
00227   double sin_theta = sin(r[0]);
00228 
00229   double cos_phi   = cos(r[1]);
00230   double sin_phi   = sin(r[1]);
00231 
00232   double cos_psi   = cos(r[2]);
00233   double sin_psi   = sin(r[2]);
00234 
00235 
00236   Matrix RX;
00237   RX.set_value( cos_theta,0,0);
00238   RX.set_value( cos_theta,1,1);
00239   RX.set_value( sin_theta,1,0);
00240   RX.set_value(-sin_theta,0,1);
00241 
00242   Matrix RY;
00243   RY.set_value( cos_phi,1,1);
00244   RY.set_value( cos_phi,2,2);
00245   RY.set_value( sin_phi,2,1);
00246   RY.set_value(-sin_phi,1,2);
00247 
00248   Matrix RZ;
00249   RZ.set_value( cos_psi,0,0);
00250   RZ.set_value( cos_psi,1,1);
00251   RZ.set_value( sin_psi,1,0);
00252   RZ.set_value(-sin_psi,0,1);
00253 
00254 
00255   multiply(RX);
00256   multiply(RY);
00257   multiply(RZ);
00258   
00259 
00260   return 0;
00261 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Matrix::set_euler_angle ( double  theta_1,
double  theta_2,
double  theta_3 
)

Definition at line 218 of file Matrix.cpp.

References set_euler_angle().

00219 {
00220   double theta[3]={theta_1,theta_2,theta_3};
00221   return set_euler_angle(theta);
00222 }

Here is the call graph for this function:

int Matrix::set_rotation_matrix ( double *  axis,
double  angle 
)

Definition at line 477 of file Matrix.cpp.

References M.

Referenced by multiply_rotation(), Point_set::rotate(), and set_rotation_matrix().

00478 {
00479   int k_dim=0;
00480   //normalization
00481   double norm=0.0;
00482   for(k_dim=0;k_dim<3;k_dim++)
00483     norm += axis[k_dim]*axis[k_dim];
00484   norm = powf(norm,0.5);
00485   for(k_dim=0;k_dim<3;k_dim++)
00486     axis[k_dim] /= norm;
00487 
00488   //http://fr.wikipedia.org/wiki/Rotation_vectorielle
00489 
00490   double cos_phi = cos(angle);
00491   double sin_phi = sin(angle);
00492   M[0] = cos_phi + (1-cos_phi)*axis[0]*axis[0];
00493   M[1] = (1-cos_phi)*axis[0]*axis[1]-sin_phi*axis[2];
00494   M[2] = (1-cos_phi)*axis[0]*axis[2]+sin_phi*axis[1];
00495   M[3] = 0.0;
00496   M[4] = (1-cos_phi)*axis[0]*axis[1]+sin_phi*axis[2];
00497   M[5] = cos_phi + (1-cos_phi)*axis[1]*axis[1];
00498   M[6] = (1-cos_phi)*axis[1]*axis[2]-sin_phi*axis[0];
00499   M[7] = 0.0;
00500   M[8] = (1-cos_phi)*axis[0]*axis[2]-sin_phi*axis[1];
00501   M[9] = (1-cos_phi)*axis[1]*axis[2]+sin_phi*axis[0];
00502   M[10]= cos_phi+(1-cos_phi)*axis[2]*axis[2];
00503   M[11]= 0.0;
00504 
00505 //   Matrix Id;
00506 //   Matrix vectorial;
00507 //   vectorial.set_zero();
00508 //   vectorial.set_value(-axis[2],1,0);
00509 //   vectorial.set_value( axis[1],2,0);
00510 //   vectorial.set_value( axis[2],0,1);
00511 //   vectorial.set_value(-axis[1],2,0);
00512 //   vectorial.set_value( axis[0],1,2);
00513 //   vectorial.set_value(-axis[0],2,1);
00514 
00515 //   Matrix full;
00516 //   full.set_zero();
00517 //   full.set_value(
00518 
00519   return 0;
00520 
00521 }

Here is the caller graph for this function:

int Matrix::set_rotation_matrix ( double  x_axis,
double  y_axis,
double  z_axis,
double  angle 
)

Definition at line 523 of file Matrix.cpp.

References set_rotation_matrix().

00524 {
00525   double axis[3]={x_axis,y_axis,z_axis};
00526   return set_rotation_matrix(axis,angle);
00527 }

Here is the call graph for this function:

Matrix Matrix::multiply_rotation ( double *  axis,
double  angle 
)

Definition at line 530 of file Matrix.cpp.

References set_rotation_matrix().

00531 {
00532   Matrix R;
00533   R.set_rotation_matrix(axis,angle);
00534   *this = *this*R;
00535   return *this;
00536 }

Here is the call graph for this function:

Matrix Matrix::multiply_rotation ( double  x_axis,
double  y_axis,
double  z_axis,
double  angle 
)

Definition at line 538 of file Matrix.cpp.

References set_rotation_matrix().

00539 {
00540   Matrix R;
00541   R.set_rotation_matrix(x_axis,y_axis,z_axis,angle);
00542   *this = *this*R;
00543   return *this;
00544 }

Here is the call graph for this function:

int Matrix::build_rotation_matrix_to_vector ( const V_3D  v,
const V_3D  w 
)

build rotation from vector v to the vector w (vector are automatically normalized) Get rotation matrix R such that R*v=w

Definition at line 712 of file Matrix.cpp.

References V_3D::dot(), V_3D::normalized(), and V_3D::vector_prod().

00713 {
00714   V_3D v0,v1;
00715   v0 = u.normalized();
00716   v1 = w.normalized();
00717 
00718   V_3D n = (v0.vector_prod(v1)).normalized();
00719   double cos_t=v0.dot(v1);
00720   double sin_t=powf(1.0-cos_t*cos_t,0.5);
00721 
00722   (*this)(0,0)=cos_t+n[0]*n[0]*(1-cos_t);
00723   (*this)(1,0)=n[2]*sin_t+n[0]*n[1]*(1-cos_t);
00724   (*this)(2,0)=-n[1]*sin_t+n[0]*n[2]*(1-cos_t);
00725   (*this)(3,0)=0.0;
00726 
00727   (*this)(0,1)=n[0]*n[1]*(1-cos_t)-n[2]*sin_t;
00728   (*this)(1,1)=cos_t+n[1]*n[1]*(1.0-cos_t);
00729   (*this)(2,1)=n[0]*sin_t+n[1]*n[2]*(1-cos_t);
00730   (*this)(3,1)=0.0;
00731 
00732   (*this)(0,2)=n[1]*sin_t+n[0]*n[2]*(1-cos_t);
00733   (*this)(1,2)=-n[0]*sin_t+n[1]*n[2]*(1-cos_t);
00734   (*this)(2,2)=cos_t+n[2]*n[2]*(1-cos_t);
00735   (*this)(3,2)=0.0+90;
00736                 
00737   (*this)(0,3)=0.0;
00738   (*this)(1,3)=0.0;
00739   (*this)(2,3)=0.0;
00740   (*this)(3,3)=1.0;
00741 
00742   return 0;
00743 }

Here is the call graph for this function:

double Matrix::value ( int  k_x,
int  k_y 
) const

Definition at line 130 of file Matrix.cpp.

References M.

Referenced by Joint::get_matrix(), Joint::get_position(), multiply(), operator()(), operator<<(), Skeleton::reccursive_scale(), set_rotation_part(), set_translation_part(), and Skeleton::translate().

00131 {
00132   if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00133     {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);} 
00134   return M[k_x+4*k_y];
00135 }

Here is the caller graph for this function:

double & Matrix::value ( int  k_x,
int  k_y 
)

Definition at line 137 of file Matrix.cpp.

References M.

00138 {
00139   if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00140     {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);} 
00141   return M[k_x+4*k_y];
00142 }

double Matrix::v ( int  k_x,
int  k_y 
) const

Definition at line 143 of file Matrix.cpp.

References M.

Referenced by det(), and invert().

00144 {
00145   if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00146     {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);} 
00147   return M[k_x+4*k_y];
00148 }

Here is the caller graph for this function:

double & Matrix::v ( int  k_x,
int  k_y 
)

Definition at line 150 of file Matrix.cpp.

References M.

00151 {
00152   if(k_x<0 || k_x>=4 || k_y<0 || k_y>=4)
00153     {printf("Error (%d,%d) is not correct in v(k_x,k_y) in Matrix\n",k_x,k_y);exit(-1);} 
00154   return M[k_x+4*k_y];
00155 }

int Matrix::set_value ( double  val,
int  k_x,
int  k_y 
)

int Matrix::set_value ( double  x00,
double  x01,
double  x02,
double  x03,
double  x10,
double  x11,
double  x12,
double  x13,
double  x20,
double  x21,
double  x22,
double  x23,
double  x30,
double  x31,
double  x32,
double  x33 
)

Definition at line 208 of file Matrix.cpp.

References M.

00209 {
00210   M[0] = x00; M[4] = x10; M[8] = x20; M[12] = x30;
00211   M[1] = x01; M[5] = x11; M[9] = x21; M[13] = x31;
00212   M[2] = x02; M[6] = x12; M[10]= x22; M[14] = x32;
00213   M[3] = x03; M[7] = x13; M[11]= x23; M[15] = x33;
00214 
00215   return 0;
00216 }

int Matrix::set_vector_rotation ( double *  v,
double  theta 
)

Definition at line 384 of file Matrix.cpp.

References M.

Referenced by Animation_transformation::get_rotation(), multiply_vector_rotation(), and set_vector_rotation().

00385 {
00386   int ok=0;
00387 
00388   double cos_theta = cos(theta);
00389   double sin_theta = sin(theta);
00390   
00391   //normalize v
00392   int k_dim=0;
00393   double n=0;
00394   for(k_dim=0;k_dim<3;n+=_v[k_dim]*_v[k_dim],k_dim++);
00395   n=powf(n,0.5);
00396   for(k_dim=0;k_dim<3;_v[k_dim]/=n,k_dim++);  
00397 
00398   M[0] = cos_theta+(1-cos_theta)*_v[0]*_v[0];
00399   M[1] = (1-cos_theta)*_v[0]*_v[1]-sin_theta*_v[2];
00400   M[2] = (1-cos_theta)*_v[0]*_v[2]+sin_theta*_v[1];
00401 
00402   M[4] = (1-cos_theta)*_v[1]*_v[0]+sin_theta*_v[2];
00403   M[5] = cos_theta + (1-cos_theta)*_v[1]*_v[1];
00404   M[6] = (1-cos_theta)*_v[1]*_v[2]-sin_theta*_v[0];
00405   
00406   M[8] = (1-cos_theta)*_v[2]*_v[0]-sin_theta*_v[1];
00407   M[9] = (1-cos_theta)*_v[2]*_v[1]+sin_theta*_v[0];
00408   M[10] = cos_theta+(1-cos_theta)*_v[2]*_v[2];
00409 
00410   return ok;
00411 }

Here is the caller graph for this function:

int Matrix::set_vector_rotation ( double  v_x,
double  v_y,
double  v_z,
double  theta 
)

Definition at line 435 of file Matrix.cpp.

References set_vector_rotation().

00436 {
00437   double _v[3]={v_x,v_y,v_z};
00438   return set_vector_rotation(_v,theta);
00439 }

Here is the call graph for this function:

int Matrix::multiply_vector_rotation ( double *  v,
double  theta 
)

Definition at line 414 of file Matrix.cpp.

References multiply(), and set_vector_rotation().

Referenced by Joint::add_rotation().

00415 {
00416   int ok=0;
00417 
00418   Matrix R;
00419   R.set_vector_rotation(_v,theta);
00420   multiply(R);
00421 
00422   return ok;
00423 }

Here is the call graph for this function:

Here is the caller graph for this function:

Matrix Matrix::get_rotation_part (  ) 

Definition at line 441 of file Matrix.cpp.

References M, and set_value().

00442 {
00443   Matrix R;
00444 
00445   int k_1=0,k_2=0;
00446   for(k_1=0;k_1<3;k_1++)
00447     for(k_2=0;k_2<3;k_2++)
00448       R.set_value(M[k_1+4*k_2],k_1,k_2);
00449 
00450   return R;
00451 }

Here is the call graph for this function:

int Matrix::set_rotation_part ( Matrix  R  ) 

Definition at line 563 of file Matrix.cpp.

References M, and value().

00564 {
00565   int k1=0,k2=0;
00566   for(k1=0;k1<3;k1++)
00567     for(k2=0;k2<3;k2++)
00568       M[4*k1+k2] = R.value(k1,k2);
00569   return 0;
00570 }

Here is the call graph for this function:

int Matrix::set_translation_part ( Matrix  T  ) 

Definition at line 572 of file Matrix.cpp.

References M, and value().

00573 {
00574   int k1=0;
00575   for(k1=0;k1<3;k1++)
00576     M[4*k1+3] = T.value(k1,3);
00577   return 0;
00578 }

Here is the call graph for this function:

Matrix & Matrix::operator= ( const Matrix _M  ) 

Definition at line 184 of file Matrix.cpp.

References M, and set_value().

00185 {
00186   for(int k_x=0;k_x<4;k_x++)
00187     for(int k_y=0;k_y<4;k_y++)
00188       this->set_value(_M.M[k_x+4*k_y],k_x,k_y);
00189 
00190   return *this;
00191 }

Here is the call graph for this function:

Matrix & Matrix::operator+= ( const Matrix _M  ) 

Definition at line 193 of file Matrix.cpp.

References M, and set_value().

00194 {
00195   for(int k_x=0;k_x<4;k_x++)
00196     for(int k_y=0;k_y<4;k_y++)
00197       this->set_value(M[k_x+4*k_y]+_M.M[k_x+4*k_y],k_x,k_y);
00198 
00199   return *this;
00200 }

Here is the call graph for this function:

Matrix & Matrix::operator/= ( const double &  alpha  ) 

Definition at line 172 of file Matrix.cpp.

References M, and set_value().

00173 {
00174   for(int k_x=0;k_x<4;k_x++)
00175     for(int k_y=0;k_y<4;k_y++)
00176       this->set_value(M[k_x+4*k_y]/alpha,k_x,k_y);
00177 
00178   return *this;
00179 }

Here is the call graph for this function:

double & Matrix::operator[] ( int  k_dim  ) 

Definition at line 157 of file Matrix.cpp.

References M.

00158 {
00159   if(k_dim<0 || k_dim>9)
00160     {printf("Error k_dim too large [%d] in operator [] in matrix\n",k_dim);exit(-1);}
00161   return M[k_dim];
00162 }

double Matrix::operator[] ( int  k_dim  )  const

Definition at line 163 of file Matrix.cpp.

References M.

00164 {
00165   if(k_dim<0 || k_dim>=4)
00166     {printf("Error k_dim too large [%d] in operator [] in matrix\n",k_dim);exit(-1);}
00167   return M[k_dim];
00168 }

double Matrix::operator() ( int  k_1,
int  k_2 
) const

Return matrix(k_row,k_column).

Definition at line 745 of file Matrix.cpp.

References value().

00746 {return value(k_2,k_1);}

Here is the call graph for this function:

double & Matrix::operator() ( int  k_1,
int  k_2 
)

Definition at line 748 of file Matrix.cpp.

References value().

00749 {return value(k_2,k_1);}

Here is the call graph for this function:

Matrix Matrix::invert (  )  const

Definition at line 612 of file Matrix.cpp.

References det(), set_value(), and v().

Referenced by Skeleton::add_new_joint(), Skeleton::change_father(), Skeleton::deform_reccursive_joint(), and Skeleton::recursive_bind_pose_fixing().

00613 {
00614   Matrix A;
00615   double d=det();
00616 
00617   A.set_value(+v(1,1)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00618               -v(1,2)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00619               +v(1,3)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00620               ,0,0);
00621 
00622   A.set_value(-v(0,1)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00623               +v(0,2)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00624               -v(0,3)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00625               ,0,1);
00626 
00627   A.set_value(+v(0,1)*(v(1,2)*v(3,3)-v(1,3)*v(3,2))
00628               -v(0,2)*(v(1,1)*v(3,3)-v(1,3)*v(3,1))
00629               +v(0,3)*(v(1,1)*v(3,2)-v(1,2)*v(3,1))
00630               ,0,2);
00631 
00632   A.set_value(-v(0,1)*(v(1,2)*v(2,3)-v(1,3)*v(2,2))
00633               +v(0,2)*(v(1,1)*v(2,3)-v(1,3)*v(2,1))
00634               -v(0,3)*(v(1,1)*v(2,2)-v(1,2)*v(2,1))
00635               ,0,3);
00636 
00637 
00638   
00639   A.set_value(-v(1,0)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00640               +v(1,2)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00641               -v(1,3)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00642               ,1,0);
00643 
00644   A.set_value(+v(0,0)*(v(2,2)*v(3,3)-v(2,3)*v(3,2))
00645               -v(0,2)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00646               +v(0,3)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00647               ,1,1);
00648 
00649   A.set_value(-v(0,0)*(v(1,2)*v(3,3)-v(1,3)*v(3,2))
00650               +v(0,2)*(v(1,0)*v(3,3)-v(1,3)*v(3,0))
00651               -v(0,3)*(v(1,0)*v(3,2)-v(1,2)*v(3,0))
00652               ,1,2);
00653 
00654   A.set_value(+v(0,0)*(v(1,2)*v(2,3)-v(1,3)*v(2,2))
00655               -v(0,2)*(v(1,0)*v(2,3)-v(1,3)*v(2,0))
00656               +v(0,3)*(v(1,0)*v(2,2)-v(1,2)*v(2,0))
00657               ,1,3);
00658 
00659 
00660 
00661 
00662   A.set_value(+v(1,0)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00663               -v(1,1)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00664               +v(1,3)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00665               ,2,0);
00666 
00667   A.set_value(-v(0,0)*(v(2,1)*v(3,3)-v(2,3)*v(3,1))
00668               +v(0,1)*(v(2,0)*v(3,3)-v(2,3)*v(3,0))
00669               -v(0,3)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00670               ,2,1);
00671 
00672   A.set_value(+v(0,0)*(v(1,1)*v(3,3)-v(1,3)*v(3,1))
00673               -v(0,1)*(v(1,0)*v(3,3)-v(1,3)*v(3,0))
00674               +v(0,3)*(v(1,0)*v(3,1)-v(1,1)*v(3,0))
00675               ,2,2);
00676 
00677   A.set_value(-v(0,0)*(v(1,1)*v(2,3)-v(1,3)*v(2,1))
00678               +v(0,1)*(v(1,0)*v(2,3)-v(1,3)*v(2,0))
00679               -v(0,3)*(v(1,0)*v(2,1)-v(1,1)*v(2,0))
00680               ,2,3);
00681 
00682 
00683 
00684 
00685 
00686   A.set_value(-v(1,0)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00687               +v(1,1)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00688               -v(1,2)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00689               ,3,0);
00690 
00691   A.set_value(+v(0,0)*(v(2,1)*v(3,2)-v(2,2)*v(3,1))
00692               -v(0,1)*(v(2,0)*v(3,2)-v(2,2)*v(3,0))
00693               +v(0,2)*(v(2,0)*v(3,1)-v(2,1)*v(3,0))
00694               ,3,1);
00695 
00696   A.set_value(-v(0,0)*(v(1,1)*v(3,2)-v(1,2)*v(3,1))
00697               +v(0,1)*(v(1,0)*v(3,2)-v(1,2)*v(3,0))
00698               -v(0,2)*(v(1,0)*v(3,1)-v(1,1)*v(3,0))
00699               ,3,2);
00700 
00701   A.set_value(+v(0,0)*(v(1,1)*v(2,2)-v(1,2)*v(2,1))
00702               -v(0,1)*(v(1,0)*v(2,2)-v(1,2)*v(2,0))
00703               +v(0,2)*(v(1,0)*v(2,1)-v(1,1)*v(2,0))
00704               ,3,3);
00705 
00706   A/=d;
00707 
00708   return A;
00709 }

Here is the call graph for this function:

Here is the caller graph for this function:

int Matrix::get_position ( double *  p  ) 

Definition at line 263 of file Matrix.cpp.

References M.

Referenced by Skeleton::find_closest_joint(), Joint::get_min_distance_to_bone(), and Skeleton::get_world_position_of_bone().

00264 {
00265   p[0]=M[3];
00266   p[1]=M[7];
00267   p[2]=M[11];
00268 
00269   return 0;
00270 }

Here is the caller graph for this function:

V_3D Matrix::get_position (  ) 

Definition at line 470 of file Matrix.cpp.

References M, and V_3D::set().

00471 {
00472   V_3D position;
00473   position.set(M[3+4*0],M[3+4*1],M[3+4*2]);
00474   return position;
00475 }

Here is the call graph for this function:

int Matrix::scale ( double *  s  ) 

Definition at line 425 of file Matrix.cpp.

References M.

Referenced by Joint::scale().

00426 {
00427   int k=0,k_dim=0;
00428   for(k=0;k<4;k++)
00429     for(k_dim=0;k_dim<3;k_dim++)
00430       M[k+4*k_dim] *= s[k_dim];
00431   return 0;
00432 }

Here is the caller graph for this function:


Friends And Related Function Documentation

ostream& operator<< ( ostream &  flux,
Matrix  M 
) [friend]

Definition at line 122 of file Matrix.cpp.

00123 {
00124   for(int k=0;k<4;k++)
00125     flux<<"("<<M.value(0,k)<<","<<M.value(1,k)<<","<<M.value(2,k)<<","<<M.value(3,k)<<")\n";
00126   return flux;
00127 }

Matrix operator* ( const Matrix M1,
const Matrix M2 
) [friend]

Definition at line 272 of file Matrix.cpp.

00273 {
00274   double temp_M[16];
00275 
00276   int k_x=0,k_y=0,k_m=0;
00277   double temp=0;
00278 
00279   //all index
00280   for(k_x=0;k_x<4;k_x++)
00281     for(k_y=0;k_y<4;k_y++)
00282       {
00283         //multiply
00284         for(k_m=0,temp=0;k_m<4;k_m++)
00285           {
00286             temp += M1.M[k_m+4*k_y] * (M2.M[k_x+4*k_m]);
00287           }
00288         temp_M[k_x+4*k_y] = temp;
00289       }
00290 
00291   Matrix Z;
00292   //set new matrix
00293   for(int k=0;k<16;k++)
00294     Z.set_value(temp_M[k],k,0);
00295 
00296   return Z;
00297 }

Matrix operator* ( const Matrix M1,
const double &  alpha 
) [friend]

Definition at line 299 of file Matrix.cpp.

00300 {
00301   Matrix Z;
00302   int k_x=0,k_y=0;
00303   for(k_x=0;k_x<4;k_x++)
00304     for(k_y=0;k_y<4;k_y++)
00305       Z.set_value(alpha*M1.M[k_x+4*k_y],k_x,k_y);
00306   return Z;
00307 }

Matrix operator* ( const double &  alpha,
const Matrix M1 
) [friend]

Definition at line 310 of file Matrix.cpp.

00311 {
00312   Matrix Z;
00313   int k_x=0,k_y=0;
00314   for(k_x=0;k_x<4;k_x++)
00315     for(k_y=0;k_y<4;k_y++)
00316       Z.set_value(alpha*M1.M[k_x+4*k_y],k_x,k_y);
00317   return Z;
00318 }

V_3D operator* ( const Matrix _M,
const V_3D _V 
) [friend]

Definition at line 320 of file Matrix.cpp.

00321 {
00322   V_3D result;
00323   V_3D copy = _V;
00324   int k_x=0;
00325   for(k_x=0;k_x<3;k_x++)
00326     result.set(k_x,_M.M[0+4*k_x]*copy.get(0)+_M.M[1+4*k_x]*copy.get(1)+_M.M[2+4*k_x]*copy.get(2)+_M.M[3+4*k_x]);
00327   
00328   return result;
00329 }

V_3D operator* ( const V_3D _V,
const Matrix _M 
) [friend]

Definition at line 332 of file Matrix.cpp.

00333 {
00334   V_3D result;
00335   int k_y=0;
00336   for(k_y=0;k_y<3;k_y++)
00337     result.set(k_y,_V[0]*_M.M[k_y+4*0]+_V[1]*_M.M[k_y+4*1]+_V[2]*_M.M[k_y+4*2]);
00338 
00339   return result;
00340 }

Matrix operator+ ( const Matrix M1,
const Matrix M2 
) [friend]

Definition at line 342 of file Matrix.cpp.

00343 {
00344   Matrix Z;
00345   
00346   int k_x=0,k_y=0;
00347   for(k_x=0;k_x<4;k_x++)
00348     for(k_y=0;k_y<4;k_y++)
00349       {
00350         Z.set_value(M1.M[k_x+4*k_y]+M2.M[k_x+4*k_y],k_x,k_y);
00351       }
00352 
00353   return Z;
00354 }

Matrix operator- ( const Matrix M1,
const Matrix M2 
) [friend]

Definition at line 357 of file Matrix.cpp.

00358 {
00359   Matrix Z;
00360   
00361   int k_x=0,k_y=0;
00362   for(k_x=0;k_x<4;k_x++)
00363     for(k_y=0;k_y<4;k_y++)
00364       {
00365         Z.set_value(M1.M[k_x+4*k_y]-M2.M[k_x+4*k_y],k_x,k_y);
00366       }
00367 
00368   return Z;
00369 }

int operator== ( const Matrix M1,
const Matrix M2 
) [friend]

Definition at line 547 of file Matrix.cpp.

00548 {
00549   double epsilon=0.000001;
00550   int k=0;
00551   for(k=0;k<16;k++)
00552     if(fabs(M1.M[k]-M2.M[k])>epsilon)
00553       return 0;
00554   return 1;
00555 }

int operator!= ( const Matrix M1,
const Matrix M2 
) [friend]

Definition at line 557 of file Matrix.cpp.

00558 {
00559   return 1-(M1==M2);
00560 }


Member Data Documentation

double Matrix::M[16] [private]


The documentation for this class was generated from the following files:

Generated on Mon Mar 30 16:57:01 2009 by  doxygen 1.5.6