00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 #ifndef _Affine3DTransform_hpp
00019 #define _Affine3DTransform_hpp
00020  
00032 #include<ImLib3D/CppTools.hpp>
00033 #include<ImLib3D/Vect3D.hpp>
00034 #include<ImLib3D/ImLib3DFile.hpp>
00035 #include<ImLib3D/Matrix.hpp>
00036 
00037 
00039 
00040 class Affine3DTransform : public Streamable
00041 {
00042     friend void Affine3DTransform_Test();
00043     friend Affine3DTransform operator*(const Affine3DTransform& a1,const Affine3DTransform& a2);
00044 private:
00045     Matrix matrix;
00046     Vect3Df translation;
00047 public:
00049     Matrix GetMatrix() const {return matrix;}
00050     Vect3Df Translation() const {return translation;}
00051     double operator()(int i,int j) const {return matrix(i,j);}
00052     double operator()(int i) const {return translation(i);}
00053     void Set(const Matrix &_matrix,const Vect3Df &_translation){matrix=_matrix;translation=_translation;}
00054 
00056     Vect3Df operator()(const Vect3Df &x) const
00057     {
00058         return matrix*x+translation;
00059     }
00061     void Inverse();
00062 
00063     virtual ~Affine3DTransform(){;}
00064     Affine3DTransform()
00065     {
00066         Reset();
00067     }
00068 
00069     Affine3DTransform(const Vect3Df &_translation)
00070     {
00071         Reset();
00072         SetTranslation(_translation);
00073     }
00074     Affine3DTransform(float theta,const Vect3Df &direction,
00075                       const Vect3Df ¢er=Vect3Df(0,0,0))
00076     {
00077         Reset();
00078         SetRotation(theta,direction,center);
00079     }
00081     Affine3DTransform(const string &fname);
00082     virtual void Read( ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL)      ;
00083     virtual void Write(ImLib3DFile *file,xmlpp::Element *parentNode=NULL,xmlpp::Element *node=NULL) const;
00084     void Show()
00085     {
00086         cout << "matrix:" << endl;
00087         cout << matrix << endl;
00088         cout << "translation:" << endl;
00089         cout << translation << endl;
00090     }
00092     void Analyse();
00094     void Reset()
00095     {
00096         matrix.SetToIdentity();
00097         translation=Vect3Df(0,0,0);
00098     }
00100 
00109     void SetRotationX(float theta,const Vect3Df ¢er=Vect3Df(0,0,0));
00110     void SetRotationY(float theta,const Vect3Df ¢er=Vect3Df(0,0,0));
00111     void SetRotationZ(float theta,const Vect3Df ¢er=Vect3Df(0,0,0));
00112     void SetRotation (float theta,Vect3Df direction,
00113                       const Vect3Df ¢er=Vect3Df(0,0,0));
00114     void SetTranslation(const Vect3Df &_translation){translation=_translation;}
00115     void SetScale(float sx,float sy,float sz)
00116     {
00117         Reset();
00118         matrix(0,0)=sx;
00119         matrix(1,1)=sy;
00120         matrix(2,2)=sz;
00121     }
00122     void SetScale(const Vect3Df &scale){SetScale(scale.x, scale.y, scale.z);}
00124 
00125     Affine3DTransform operator*=(const Affine3DTransform& other);
00126     
00127 };
00128 extern Affine3DTransform operator*(const Affine3DTransform& a1,const Affine3DTransform& a2);
00129 
00130 
00131 
00132 #endif //_Affine3DTransform_hpp