Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
bundleData.hpp
00001 #ifndef BUNDLE_BUNDLEDATA_HPP
00002 #define BUNDLE_BUNDLEDATA_HPP
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 #include <vector>
00007 
00008 #include "bundle/bundleDimension.hpp"
00009 #include "bundle/bundleParameters.hpp"
00010 
00011 #include "kernel/jafarMacro.hpp"
00012 
00013 #include "jmath/ublasExtra.hpp"
00014 
00015 namespace jafar {
00016   
00017   namespace bundle {
00018     
00019     /*
00020      *
00021      *   CLASS OBSERVATION
00022      *
00023      */
00024 
00032     class observation {
00033 
00034     public :
00035       
00037       enum obsType {POINT_2D, POINT_3D, CPDV_EULER, CPDV_QUATERNION};                                   
00038       
00040       obsType type;
00041     
00043       int id;
00044       
00046       int idFeature;
00047 
00049       int idView; 
00050       
00051     private :
00052 
00054       jblas::vec x;
00055 
00057       jblas::vec residual;
00058       
00060       jblas::mat covX;
00061             
00062     public :
00063 
00064       //
00065       // Constructors and desctructor
00066       //
00067       //==============================
00068 
00072       observation (obsType type_=POINT_2D) : 
00073   type(type_),
00074   id(),
00075   idFeature(),
00076   idView(),
00077   x(obsSize(type_)),
00078   residual(obsSize(type_)),
00079   covX(obsSize(type_),obsSize(type_))
00080       {
00081   int cpt;
00082 
00083   for (cpt=0;cpt<obsSize(type_);cpt++)
00084     residual[cpt] = x[cpt] = 0.0;
00085       };
00086       
00090       observation (observation const& O_) :
00091   type(O_.type),
00092   id(O_.id),
00093   idFeature(O_.idFeature),
00094   idView(O_.idView),
00095   x(O_.x),
00096   residual(O_.residual),
00097   covX(O_.covX)
00098       {};
00099 
00100       //
00101       // Read info from file
00102       //
00103       //=====================
00107       bool readFromFile (std::ifstream& infile, double sigma=0.0) 
00108       {
00109   if (!(infile.is_open()))
00110     {
00111      // std::cout << "erreur lors de la lecture du fichier" << std::endl;
00112       return false;
00113     }
00114   else if (type == POINT_2D)
00115     return readFromFile2D (infile,sigma);
00116   else if (type == POINT_3D)
00117     return readFromFileSTRMOT (infile);
00118   else if (type== CPDV_EULER)
00119     return readFromFileSTRMOT (infile);
00120   else if (type== CPDV_QUATERNION)
00121     return readFromFileSTRMOT (infile);
00122   
00123   return false;
00124       };
00125 
00126       
00127 
00128       //
00129       // Get & Set functions
00130       //
00131       //=====================
00132       
00136       void getCovMatrix (jblas::mat &covX_) const;
00137 
00141       void setValue (jblas::vec &x_, jblas::mat &covX_,  int id_,  int idFeature_, int idView_);
00142       void setValue (observation const& o_);
00143 
00148       void setResidual (jblas::vec prediction_);              
00149 
00153       void getObs (jblas::vec &x_) const;
00154 
00158       unsigned int size () const
00159       {
00160   return(x.size());
00161       };
00162 
00163       //
00164       // Residual function
00165       //
00166       //===================
00170       double residualL2Norm ();
00171       
00175       double residualWL2Norm ();
00176 
00177 
00181       void getResidual (jblas::vec &R_) const ;
00182 
00186       void getResidual (jblas::vec_range &VR_) const;
00187 
00188     private :
00189       // Return size of vector x for the given obsType 
00190       static  int obsSize (obsType type_) 
00191       {
00192   switch (type_)
00193     {
00194     case POINT_2D :
00195       return (2);
00196     case POINT_3D :
00197       return (3);
00198     case CPDV_EULER :
00199       return (6);
00200     case CPDV_QUATERNION :
00201       return (7);
00202     default : 
00203       JFR_RUN_TIME("Undefined observation size for type: " << type_);
00204     }
00205       };  
00206       
00207       bool readFromFile2D (std::ifstream& infile, double sigma);
00208   
00209       bool readFromFileSTRMOT (std::ifstream& infile);
00210 
00211             
00212     }; // class observation
00213     
00214 
00215 
00216 
00217 
00218     /*
00219      *
00220      *   CLASS OBSERVATIONSCONTAINER
00221      *
00222      */
00223 
00230     class observationsContainer  {
00231 
00232      
00233     public :      
00234       
00236       bundleDimension pbDim;
00237 
00239       jblas::bool_mat sparseSB1;
00240       
00242       jblas::bool_mat sparseSB2;
00243 
00245       std::vector<observation*> obs2D;
00246 
00248       std::vector<observation*> obs3D;
00249 
00251       std::vector<observation*> obsCPDV;
00252       
00253 
00254       //
00255       // Constructors and Desctructors
00256       //
00257       //===============================
00258       
00259 
00263       observationsContainer (bundleDimension const& bDim_) :
00264   pbDim(bDim_),
00265   sparseSB1(pbDim.nbObs2d,pbDim.nbCam),
00266   sparseSB2(pbDim.nbObs2d,pbDim.nbObj3d),
00267   obs2D(pbDim.nbObs2d),
00268   obs3D(pbDim.nbObs3d),
00269   obsCPDV(pbDim.nbObsMvt)
00270       {
00271   unsigned int cpt, cpt1, cpt2;
00272 
00273   // Alloc observation de type observation::POINT_2D
00274   for (cpt=0;cpt<pbDim.nbObs2d;cpt++)
00275     obs2D[cpt] = new observation(observation::POINT_2D);
00276 
00277   // Alloc observation de type observation::POINT_3D
00278   if (pbDim.nbObs3d)
00279     for (cpt=0;cpt<pbDim.nbObs3d;cpt++)
00280       obs3D[cpt] = new observation(observation::POINT_3D);
00281 
00282   // Alloc observation de type observation::CPDV_EULER
00283   if (pbDim.nbObsMvt)
00284     for (cpt=0;cpt<pbDim.nbObsMvt;cpt++)
00285       obsCPDV[cpt] = new observation(observation::CPDV_EULER);
00286     
00287   // Initialisation des matrices sparseSB1 et sparseSB2
00288   for ( cpt1=0 ; cpt1<sparseSB1.size1() ; cpt1++)
00289     for ( cpt2=0 ; cpt2<sparseSB1.size2() ; cpt2++)
00290       sparseSB1(cpt1,cpt2) = false;
00291 
00292   for ( cpt1=0 ; cpt1<sparseSB2.size1() ; cpt1++)
00293     for ( cpt2=0 ; cpt2<sparseSB2.size2() ; cpt2++)
00294       sparseSB2(cpt1,cpt2) = false;      
00295   
00296       }
00297 
00301       observationsContainer (observationsContainer const& ODB_) :
00302   pbDim(ODB_.pbDim),
00303   sparseSB1(ODB_.sparseSB1),
00304   sparseSB2(ODB_.sparseSB2),
00305   obs2D(ODB_.obs2D.size()),
00306   obs3D(ODB_.obs3D.size()),
00307   obsCPDV(ODB_.obsCPDV.size())
00308       {
00309   unsigned int cpt, L;
00310   
00311   // Alloc observation de type observation::POINT_2D
00312   for (cpt=0;cpt<ODB_.obs2D.size();cpt++)
00313     {
00314       obs2D[cpt] = new observation(observation::POINT_2D);
00315       *(obs2D[cpt]) = *(ODB_.obs2D[cpt]);
00316     }
00317 
00318   // Alloc observation de type observation::POINT_3D
00319   if ((L=ODB_.obs3D.size())>0)
00320     for (cpt=0;cpt<L;cpt++)
00321       {
00322         obs3D[cpt] = new observation(observation::POINT_3D);
00323         *(obs3D[cpt]) = *(ODB_.obs3D[cpt]);
00324       }
00325   
00326   // Alloc observation de type observation::CPDV_EULER
00327   if ((L=ODB_.obsCPDV.size())>0)
00328     for (cpt=0;cpt<L;cpt++)
00329       {
00330         obsCPDV[cpt] = new observation(observation::CPDV_EULER);
00331         *(obsCPDV[cpt]) = *(ODB_.obsCPDV[cpt]);
00332       } 
00333       }
00334 
00337       ~observationsContainer ()
00338       {
00339   unsigned int cpt, L;
00340   
00341   if ((L=obsCPDV.size())>0)
00342     for (cpt=0;cpt<L;cpt++)
00343       delete obsCPDV[cpt];
00344 
00345   if ((L=obs3D.size())>0)
00346     for (cpt=0;cpt<L;cpt++)
00347       delete obs3D[cpt];
00348   
00349   if ((L=obs2D.size())>0)
00350     for (cpt=0;cpt<L;cpt++)
00351       delete obs2D[cpt];
00352   
00353       }
00354       
00355       // 
00356       // File Reader
00357       //
00358       //=============
00363       void initFromFile (const bundleParameters &bP);
00364 
00365       //
00366       // Norm Tools
00367       //
00368       //============
00372       double residualWL2Norm ();
00373       
00377       double residualL2Norm ();
00378       
00379 
00380     }; // class observationDataBase
00381 
00382     // Print observation
00383     
00384     std::ostream& operator <<(std::ostream& s, jafar::bundle::observation const& o_);    
00385 
00386 
00387   } // namespace bundle
00388 
00389 } // namespace jafar
00390 
00391 
00392 
00393 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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