00001 00012 #ifndef __TINY_GRID_CELLS_H 00013 #define __TINY_GRID_CELLS_H 00014 00015 #include "../core/maps/grid_map.h" 00016 00017 //------------------------------------------------------------------------------ 00018 // Base cell 00019 00026 class BaseTinyCell : public GridCell { 00027 public: 00031 BaseTinyCell(): _prob(0.5) {} 00035 double value() const override { return _prob; } 00041 void set_value(const Occupancy &value, double quality) override { 00042 _prob = (1.0 - quality) * _prob + quality * value.prob_occ; 00043 } 00044 private: 00045 double _prob; 00046 }; 00047 00054 class TinyBaseCellFactory : public GridCellFactory { 00055 public: 00059 std::shared_ptr<GridCell> create_cell() override { 00060 return std::shared_ptr<GridCell>(new BaseTinyCell()); 00061 } 00062 }; 00063 00064 //------------------------------------------------------------------------------ 00065 // Modified cell 00066 00073 class AvgTinyCell : public GridCell { 00074 public: 00078 AvgTinyCell(): _cnt(0), _n(0) {} 00082 double value() const override { return _n == 0 ? -1 : _cnt / _n; } 00089 void set_value (const Occupancy &value, double quality) override { 00090 _n += 1; 00091 _cnt += 0.5 + (value.prob_occ - 0.5) * quality; 00092 } 00093 private: 00094 double _cnt, _n; 00095 }; 00096 00104 class TinyAvgCellFactory : public GridCellFactory { 00105 public: 00109 std::shared_ptr<GridCell> create_cell() override { 00110 return std::shared_ptr<GridCell>(new AvgTinyCell()); 00111 } 00112 }; 00113 00114 #endif