Biomechanical Joint Model
 Author: Anderson Maciel

hmat.h

Go to the documentation of this file.
00001 #ifndef AMAURY_HMAT_H
00002 #define AMAURY_HMAT_H
00003 
00004 #include "mat.h"
00005 
00006 
00007 namespace LinAlg{
00008 
00009   // HMAT: homgoneous matrix; internal representation is column-vector, 3x4.
00010   // conversion to/from Scenelib, Inventor is easy with defined operators.
00011   //
00012 class HMAT : public MAT
00013 {
00014 public:
00015    typedef float   MatriX[4][4]; // nicely mirrors Scenelib's geom definition
00016 
00017    // constructors
00018    HMAT(const HMAT &A);
00019    explicit HMAT(const REAL& value = REAL(0));
00020    HMAT(const MatriX mat);
00021    HMAT(const MAT &rot, const VEC &trans);
00022    
00023    static HMAT getIdentity();
00024    void setIdt() { set(0); MAT::addToDiagonal(1); };
00025 
00026    VEC getColumn(int i) const;
00027    VEC getRow(int i) const;
00028    VEC getTranslation() const;
00029    
00030    void setColumn(int i, const VEC &V);
00031    void setRow(int i, const VEC &V);
00032    void setTranslation(const VEC &trans);
00033 
00034    // make a rotation matrix that maps v0 onto v1
00035    static void makeVecRotVec(HMAT &mat, const VEC &v0, const VEC &v1);
00036 
00037    virtual VEC operator*(const VEC &V) const; // point multiplication
00038    VEC fullMult(const VEC &V) const;          // point multiplication
00039    VEC mult(const VEC &V) const;              // vector multiplication
00040    operator MatriX&();
00041 
00042    friend HMAT inverse(const HMAT &A);
00043 private:
00044    MatriX mx;
00045 };
00046 
00047 // constructors
00048 
00049 inline HMAT::HMAT(const REAL& value) : MAT(3,4,value) {}
00050 
00051 inline HMAT::HMAT(const HMAT &A) : MAT(A) {}
00052 
00053 inline HMAT::HMAT(const MatriX mat) : MAT() 
00054 {
00055    initialize(3,4);
00056    for (int i=0;i<3;i++)
00057       for (int j=0;j<4;j++)
00058          v_[i][j]=mat[j][i];  // transpose because of switch from row-vector to column-vector
00059 }
00060    
00061 inline HMAT::HMAT(const MAT &rot, const VEC &trans) : MAT() 
00062 {
00063    int i;
00064    initialize(3,4);
00065 
00066    // rotation
00067    for (i=0;i<3;i++)
00068       for (int j=0;j<3;j++)
00069          v_[i][j]=rot(i,j);
00070 
00071    // translation
00072    for (i=0; i<3; i++)
00073       v_[i][3] = trans[i];
00074 }
00075 
00076 inline HMAT 
00077 HMAT::getIdentity()
00078 {
00079    HMAT Id;
00080    Id.addToDiagonal(1);
00081    return Id;
00082 }
00083 
00084 inline VEC 
00085 HMAT::getColumn(int i) const
00086 {
00087 #ifdef BOUNDS_CHECK
00088    assert (i>=0 && i<4);
00089 #endif
00090    static VEC V(3);
00091    V[0] = v_[0][i];
00092    V[1] = v_[1][i];
00093    V[2] = v_[2][i];
00094    return V;
00095 }
00096 
00097 inline VEC HMAT::getRow(int i) const
00098 {
00099 #ifdef BOUNDS_CHECK
00100    assert (i>=0 && i<3);
00101 #endif
00102    static VEC V(3);
00103    V[0] = v_[i][0];
00104    V[1] = v_[i][1];
00105    V[2] = v_[i][2];
00106    return V;
00107 }
00108 
00109 inline VEC HMAT::getTranslation() const 
00110 { 
00111    return getColumn(3); 
00112 }
00113 
00114 inline void HMAT::setColumn(int i, const VEC &V)
00115 {
00116 #ifdef BOUNDS_CHECK
00117    assert (i>=0 && i<4);
00118    assert (V.dim() == 3 || V.dim() == 4);
00119 #endif
00120    v_[0][i] = V[0];
00121    v_[1][i] = V[1];
00122    v_[2][i] = V[2];
00123 }
00124 
00125 inline void HMAT::setRow(int i, const VEC &V)
00126 {
00127 #ifdef BOUNDS_CHECK
00128    assert (i>=0 && i<3);
00129    assert (V.dim() == 3 || V.dim() == 4);
00130 #endif
00131    v_[i][0] = V[0];
00132    v_[i][1] = V[1];
00133    v_[i][2] = V[2];   
00134 }
00135 
00136 inline void HMAT::setTranslation(const VEC &trans)
00137 {
00138    setColumn(3, trans);
00139 }
00140 
00141 
00142 inline VEC HMAT::fullMult(const VEC &V) const
00143 {
00144    return this->operator*(V);
00145 }
00146 
00147 inline VEC HMAT::mult(const VEC &V) const
00148 {
00149    assert (V.dim()==3);
00150    static VEC tmp(3);
00151    for (int i=0; i<3; i++)
00152    {
00153       REAL sum=0;
00154       for (int j=0;j<3;j++)
00155          sum += V[j] * v_[i][j];          
00156       tmp[i]=sum;
00157    }
00158    return tmp;
00159 }
00160 
00161 inline HMAT::operator HMAT::MatriX&()
00162 {   
00163    mx[0][3]=mx[1][3]=mx[2][3]=0; mx[3][3]=1;
00164    for (int i=0;i<4;i++)
00165       for (int j=0;j<3;j++)
00166          mx[i][j]=v_[j][i];  
00167    return mx;
00168 }
00169 
00170    
00171 inline HMAT inverse(const HMAT &A)
00172 {
00173    static MAT  rot(3,3);
00174 
00175    // inverse rotation part (take matrix's transpose)
00176    for (int i=0; i<3; i++)
00177       for (int j=0; j<3; j++)
00178          rot(j,i) = A.v_[i][j];
00179 
00180    // negate translation
00181    static VEC tmp(3);
00182    tmp = -A.getTranslation();
00183    // rotate translational part
00184    
00185    return HMAT(rot, rot*tmp);
00186 }
00187 
00188 }
00189 #endif

Generated on Thu Dec 1 10:13:38 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5