10 #ifndef CLogOddsGridMap2D_H 11 #define CLogOddsGridMap2D_H 23 template <
typename TCELL>
29 static const int8_t CELLTYPE_MIN = -127;
32 static const int8_t CELLTYPE_MAX = 127;
33 static const int8_t P2LTABLE_SIZE = CELLTYPE_MAX;
34 static const size_t LOGODDS_LUT_ENTRIES = 1 << 8;
41 static const int16_t CELLTYPE_MAX = 32767;
42 static const int16_t P2LTABLE_SIZE = CELLTYPE_MAX;
43 static const size_t LOGODDS_LUT_ENTRIES = 1 << 16;
55 template <
typename TCELL>
74 const unsigned x,
const unsigned y,
const cell_t logodd_obs,
75 const cell_t thres,
cell_t* mapArray,
const unsigned _size_x)
77 cell_t* theCell = mapArray + (
x +
y * _size_x);
79 *theCell -= logodd_obs;
81 *theCell = traits_t::CELLTYPE_MIN;
98 *theCell -= logodd_obs;
100 *theCell = traits_t::CELLTYPE_MIN;
115 const unsigned x,
const unsigned y,
const cell_t logodd_obs,
116 const cell_t thres,
cell_t* mapArray,
const unsigned _size_x)
118 cell_t* theCell = mapArray + (
x +
y * _size_x);
119 if (*theCell < thres)
120 *theCell += logodd_obs;
122 *theCell = traits_t::CELLTYPE_MAX;
139 if (*theCell < thres)
140 *theCell += logodd_obs;
142 *theCell = traits_t::CELLTYPE_MAX;
157 template <
typename TCELL>
184 static const double LOGODD_K = 16;
185 static const double LOGODD_K_INV = 1.0 / LOGODD_K;
189 for (
int i = traits_t::CELLTYPE_MIN; i <= traits_t::CELLTYPE_MAX; i++)
191 float f = 1.0f / (1.0f + exp(-i * LOGODD_K_INV));
192 unsigned int idx = -traits_t::CELLTYPE_MIN + i;
198 p2lTable.resize(traits_t::P2LTABLE_SIZE + 1);
199 double K = 1.0 / traits_t::P2LTABLE_SIZE;
200 for (
int j = 0; j <= traits_t::P2LTABLE_SIZE; j++)
208 double logodd = log(
p) - log(1 -
p);
209 int L =
round(logodd * LOGODD_K);
210 if (L > traits_t::CELLTYPE_MAX)
211 L = traits_t::CELLTYPE_MAX;
212 else if (L < traits_t::CELLTYPE_MIN)
213 L = traits_t::CELLTYPE_MIN;
223 if (l < traits_t::CELLTYPE_MIN)
235 if (l < traits_t::CELLTYPE_MIN)
247 return p2lTable[
static_cast<unsigned int>(
p * traits_t::P2LTABLE_SIZE)];
TCELL cell_t
The type of cells.
std::vector< uint8_t > logoddsTable_255
A lookup table to compute occupancy probabilities in the range [0,255] from integer log-odds values i...
cell_t p2l(const float p)
Scales a real valued probability in [0,1] to an integer representation of: log(p)-log(1-p) in the val...
static void updateCell_fast_free(const unsigned x, const unsigned y, const cell_t logodd_obs, const cell_t thres, cell_t *mapArray, const unsigned _size_x)
Performs the Bayesian fusion of a new observation of a cell, without checking for grid limits nor upd...
detail::logoddscell_traits< TCELL > traits_t
CLogOddsGridMapLUT()
Constructor: computes all the required stuff.
std::vector< cell_t > p2lTable
A lookup table for passing from float to log-odds as cell_t.
detail::logoddscell_traits< TCELL > traits_t
std::vector< float > logoddsTable
A lookup table to compute occupancy probabilities in [0,1] from integer log-odds values in the cells...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
uint8_t l2p_255(const cell_t l)
Scales an integer representation of the log-odd into a linear scale [0,255], using p=exp(l)/(1+exp(l)...
int round(const T value)
Returns the closer integer (int) to x.
A generic provider of log-odds grid-map maintainance functions.
float l2p(const cell_t l)
Scales an integer representation of the log-odd into a real valued probability in [0...
static void updateCell_fast_free(cell_t *theCell, const cell_t logodd_obs, const cell_t thres)
Performs the Bayesian fusion of a new observation of a cell, without checking for grid limits nor upd...
One static instance of this struct should exist in any class implementing CLogOddsGridMap2D to hold t...
static void updateCell_fast_occupied(cell_t *theCell, const cell_t logodd_obs, const cell_t thres)
Performs the Bayesian fusion of a new observation of a cell, without checking for grid limits nor upd...
static void updateCell_fast_occupied(const unsigned x, const unsigned y, const cell_t logodd_obs, const cell_t thres, cell_t *mapArray, const unsigned _size_x)
Performs the Bayesian fusion of a new observation of a cell, without checking for grid limits nor upd...