Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
mapManager.hpp
00001 /* $Id$ */
00002 
00003 #ifndef SLAM_MAP_MANAGER_HPP
00004 #define SLAM_MAP_MANAGER_HPP
00005 
00006 #include <list>
00007 
00008 #include "jmath/jblas.hpp"
00009 
00010 #include "slam/abstractMapManager.hpp"
00011 #include "slam/feature.hpp"
00012 #include "slam/slamEvents.hpp"
00013 
00014 // #define DEBUG_FREE_STATE_COLLECTOR
00015 
00016 namespace jafar {
00017   namespace slam {
00018 
00019     class SlamEkf;
00020     
00027     class FreeStateCollector {
00028         struct StateBlock {
00029           StateBlock(std::size_t index_, std::size_t size_) : index(index_), size(size_) {}
00030           std::size_t index;
00031           std::size_t size;
00032           inline bool operator <(StateBlock const& block2) const {
00033             return index < block2.index;
00034           }
00035         };
00036 #ifdef DEBUG_FREE_STATE_COLLECTOR
00037         struct HistoryItem {
00038           std::string what;
00039           int index;
00040           int countObject;
00041         };
00042         int m_countObject;
00043         std::list<HistoryItem> m_history;
00044 #endif
00045 
00046         typedef std::list<StateBlock> StateBlockCont;
00048         StateBlockCont m_freeStateBlocks;
00049         SlamEkf& m_slam;
00050       public:
00051         FreeStateCollector(SlamEkf& slam_);
00052         ~FreeStateCollector();
00056         std::size_t getFreeIndex(std::size_t sizeState);
00062         void collectIndex( std::size_t index, std::size_t sizeState);
00066         void clear();
00070         void defrag();
00071         void dump() const;
00072     };
00073 
00079     class DefaultMapManager : public AbstractMapManager {
00080   
00081     public:
00082 
00083       DefaultMapManager(SlamEkf& slam_) : AbstractMapManager(slam_) {}
00084 
00085       void clear();
00086       void setMapObjectState(AbstractMapObject& mapObj);
00087       void removeMapObject(AbstractMapObject const& mapObj);
00088 
00089     };
00090 
00096     class LocalMapManager : public AbstractMapManager, public SlamEventAdapter {
00097 
00098     protected:
00099 
00101       const std::size_t m_sizeFeatureState;
00102 
00103       const std::size_t m_sizeLocalMapMax;
00104 
00106       FreeStateCollector m_freeStateCollector;
00107 
00108      public:
00109 
00110       LocalMapManager(SlamEkf& slam_,
00111           std::size_t sizeLocalMapMax,
00112           std::size_t sizeFeatureState);
00113       ~LocalMapManager();
00114 
00115       void clear();
00116       void setMapObjectState(AbstractMapObject& mapObj);
00117       void removeMapObject(AbstractMapObject const& mapObj);
00118 
00119       virtual void endProcessObservations(unsigned int robotId_);
00120     };
00121 
00122 #ifndef SWIG
00123     namespace details {
00124 
00125       struct VoxelCoord {
00126   int x,y,z;
00127       };
00128 
00129       std::ostream& operator <<(std::ostream& s, VoxelCoord  const& v);
00130 
00131       inline bool operator <(VoxelCoord const& v1, VoxelCoord const& v2)
00132       {
00133   if (v1.x != v2.x)
00134     return v1.x < v2.x;
00135   else if (v1.y != v2.y)
00136     return v1.y < v2.y;
00137   else
00138     return v1.z < v2.z;
00139       }
00140     } // namespace details
00141 #endif // SWIG
00142 
00157     class GlobalMapManager : public AbstractMapManager, public SlamEventAdapter {
00158 
00159      protected:
00161       unsigned int m_nbObsMin;
00163       double m_minUncertainty;
00165       double m_sizeVoxel;
00166       typedef std::map<details::VoxelCoord, BaseFeature*> VoxelsType;
00167       VoxelsType m_voxels;
00168       details::VoxelCoord getVoxelCoord(BaseFeature const& f);
00170       FreeStateCollector m_freeStateCollector;
00171 
00172       int m_ndel_density;
00173       int m_ndel_obs;
00174       int m_ndel_uncertainty;
00175 
00176       class Stats
00177       {
00178        public:
00179         int m_ndel_density;
00180         int m_ndel_obs;
00181         int m_ndel_uncertainty;
00182 
00183         Stats(): m_ndel_density(0), m_ndel_obs(0), m_ndel_uncertainty(0) {}
00184       } stats;
00185 
00186 
00187      public:
00188       GlobalMapManager(SlamEkf& slam_, double sizeVoxel_, unsigned int nbObsMin, double minUncertainty);
00189       GlobalMapManager(SlamEkf& slam_);
00190       ~GlobalMapManager();
00191 
00202       void setParams(double sizeVoxel = 1.0, unsigned int nbObsMin = 5, double minUncertainty = 0.01);
00203       void clear();
00204       void setMapObjectState(AbstractMapObject& mapObj);
00205       void removeMapObject(AbstractMapObject const& mapObj);
00206       virtual void endProcessObservations(unsigned int robotId_);
00207       virtual void writeLogHeader(jafar::kernel::DataLogger& log) const ;
00208       virtual void writeLogData(jafar::kernel::DataLogger& log) const;
00209       virtual void writeLogStats(jafar::kernel::DataLogger& log) const;
00210     };
00211 
00212  }
00213 }
00214 
00215 #endif // SLAM_MAP_MANAGER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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