Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
t3d.hpp
00001 /* $Id$ */
00002 
00003 #ifndef GEOM_T3D_HPP
00004 #define GEOM_T3D_HPP
00005 
00006 #include <iostream>
00007 
00008 #include "kernel/jafarMacro.hpp"
00009 #include "kernel/keyValueFile.hpp"
00010 #include "kernel/dataLog.hpp"
00011 
00012 #include "jmath/jblas.hpp"
00013 
00014 namespace jafar {
00015   namespace geom {
00016 
00022     class T3D : public jafar::kernel::KeyValueFileSaveLoad, public jafar::kernel::DataLoggable {
00023 
00024     public:
00025 
00026       enum Type {
00027   EULER,            
00028   QUATERNION,       
00029   ROTATION_VECTOR,  
00030   IDENTITY          
00031       };
00032 
00033       enum Standard {
00034         CALIFE_TO_JAFAR,
00035         JAFAR_TO_CALIFE  
00036       };
00037 
00038       virtual ~T3D();
00039 
00043       T3D& operator=(const T3D& t);
00044 
00048       void assign(T3D const& t);
00049 
00051       virtual Type type() const = 0;
00052 
00053       std::size_t size() const {return x.size();}
00054 
00055       jblas::vec const& getX() const {return x;}
00056       jblas::vec& getX() {p_isMuptodate = false; return x;}
00057 
00058       jblas::sym_mat const& getXCov() const {
00059   JFR_PRECOND(hasCov(), "T3D::getXCov: t3d covariance is undefined"); 
00060   return xCov;
00061       }
00062       
00063       jblas::sym_mat& getXCov() {
00064   JFR_PRECOND(hasCov(), "T3D::getXCov: t3d covariance is undefined"); 
00065   p_isMuptodate = false;
00066   return xCov;
00067       }
00068 
00070       jblas::vec getXStdDev();
00071       
00072       const jblas::mat44& getM() const {
00073   if (!isMuptodate())
00074     updateM();
00075   return M;
00076       }
00077 
00078       jblas::mat33 getR() const {
00079   if (!isMuptodate())
00080     updateM();
00081   return ublas::project(M, ublas::range(0,3), ublas::range(0,3) );
00082       }
00083 
00084       jblas::vec3 getT() const {
00085   if (!isMuptodate())
00086     updateM();
00087   return ublas::project(ublas::column(M,3), ublas::range(0,3) );
00088       }
00089 
00090       bool hasCov() const {return p_hasCov;}
00091       bool is2D() const {return p_is2D;}
00092       bool isMuptodate() const {return p_isMuptodate;}
00093 
00094       bool isIdentity() const {return type() == IDENTITY;}
00095 
00097       void clear();
00098       
00100       void set(const jblas::vec& x_);
00101 
00103       void set(const jblas::mat& M_);
00104 
00106       void set(const jblas::mat& R_, const jblas::vec& t_);
00107 
00109       void set(const jblas::vec& x_, const jblas::vec& xStdDev_);
00110 
00112       void set(const jblas::vec& x_, const jblas::sym_mat& xCov_);
00113 
00115       void set2D(bool is2D=true) {p_is2D = is2D;}
00116 
00122       void rearrange(const Standard& standard = JAFAR_TO_CALIFE);
00123 
00127       static void inv(T3D const& t, T3D& t_inv);
00128 
00132       static void inv(T3D const& t, T3D& t_inv, jblas::mat& J);
00133 
00137       static void compose(T3D const& t1, T3D const& t2, T3D& t3);
00138 
00141       static void composeIncr(T3D& t1, T3D const& t2);
00142 
00149       static void compose(T3D const& t1, T3D const& t2, T3D& t3, jblas::mat& J1, jblas::mat& J2 );
00150       
00153       static void convert(T3D const& t1, T3D& t2);
00154 
00155       template<class T3D_res>
00156       static T3D_res compose(T3D const& t1, T3D const& t2) {
00157   T3D_res t3;
00158   compose(t1,t2,t3);
00159   return t3;
00160       }
00161 
00162       template<class T3D_res>
00163       static T3D_res inv(T3D const& t) {
00164   T3D_res t_inv;
00165   inv(t,t_inv);
00166   return t_inv;
00167       }
00168 
00171       static T3D* create(Type type);
00172 
00175       static T3D* clone(T3D const& t);
00176     private:
00177       static void invImpl(T3D const& t, T3D& t_inv);
00178     protected:
00179 
00181       jblas::vec x;
00183       jblas::sym_mat xCov;
00185       mutable jblas::mat44 M; // M is an internal variable, so it is declared "mutable"
00186 
00187       bool p_hasCov;
00188       bool p_is2D;
00189       mutable bool p_isMuptodate; // _isMuptodate is an internal variable, so it is declared "mutable"
00190 
00191       T3D(std::size_t size, bool hasCov_);
00192       T3D(std::size_t size, const jblas::vec& x_, bool hasCov_);
00193       T3D(std::size_t size, const jblas::vec& x_, const jblas::vec& xStdDev_);
00194       T3D(std::size_t size, const jblas::vec& x_, const jblas::sym_mat& xCov_);
00195       T3D(const jblas::mat& M_);
00196       T3D(const T3D& t_);
00197 
00199       virtual void updateM() const = 0;
00200 
00202       virtual void updateX() = 0;
00203 
00204       void loadKeyValueFile(jafar::kernel::KeyValueFile const& keyValueFile);
00205       void saveKeyValueFile(jafar::kernel::KeyValueFile& keyValueFile);
00206 
00207       void writeLogHeader(jafar::kernel::DataLogger& log) const;
00208       void writeLogData(jafar::kernel::DataLogger& log) const;
00209 
00210       friend std::ostream& operator<<(std::ostream& s, const T3D& t3d); 
00211 
00212     }; // class T3D
00213 
00214 
00215     std::ostream& operator<<(std::ostream& s, const T3D::Type& type);
00216     std::istream& operator>>(std::istream& s, T3D::Type& type);
00217 
00219     std::ostream& operator<<(std::ostream& s, const T3D& t3d);
00220 
00221 
00222   } // namespace geom
00223 } // namespace jafar
00224 
00225 #endif // GEOM_T3D_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:19 for Jafar by doxygen 1.7.6.1
LAAS-CNRS