10 #ifndef CLogOddsGridMap2D_H 11 #define CLogOddsGridMap2D_H 22 template <
typename TCELL>
28 static const int8_t CELLTYPE_MIN = -127;
31 static const int8_t CELLTYPE_MAX = 127;
32 static const int8_t P2LTABLE_SIZE = CELLTYPE_MAX;
33 static const size_t LOGODDS_LUT_ENTRIES = 1 << 8;
40 static const int16_t CELLTYPE_MAX = 32767;
41 static const int16_t P2LTABLE_SIZE = CELLTYPE_MAX;
42 static const size_t LOGODDS_LUT_ENTRIES = 1 << 16;
54 template <
typename TCELL>
73 const unsigned x,
const unsigned y,
const cell_t logodd_obs,
74 const cell_t thres,
cell_t* mapArray,
const unsigned _size_x)
76 cell_t* theCell = mapArray + (
x +
y * _size_x);
78 *theCell -= logodd_obs;
80 *theCell = traits_t::CELLTYPE_MIN;
97 *theCell -= logodd_obs;
99 *theCell = traits_t::CELLTYPE_MIN;
114 const unsigned x,
const unsigned y,
const cell_t logodd_obs,
115 const cell_t thres,
cell_t* mapArray,
const unsigned _size_x)
117 cell_t* theCell = mapArray + (
x +
y * _size_x);
118 if (*theCell < thres)
119 *theCell += logodd_obs;
121 *theCell = traits_t::CELLTYPE_MAX;
138 if (*theCell < thres)
139 *theCell += logodd_obs;
141 *theCell = traits_t::CELLTYPE_MAX;
156 template <
typename TCELL>
183 static const double LOGODD_K = 16;
184 static const double LOGODD_K_INV = 1.0 / LOGODD_K;
188 for (
int i = traits_t::CELLTYPE_MIN; i <= traits_t::CELLTYPE_MAX; i++)
190 float f = 1.0f / (1.0f + exp(-i * LOGODD_K_INV));
191 unsigned int idx = -traits_t::CELLTYPE_MIN + i;
197 p2lTable.resize(traits_t::P2LTABLE_SIZE + 1);
198 double K = 1.0 / traits_t::P2LTABLE_SIZE;
199 for (
int j = 0; j <= traits_t::P2LTABLE_SIZE; j++)
207 double logodd = log(
p) - log(1 -
p);
208 int L =
round(logodd * LOGODD_K);
209 if (L > traits_t::CELLTYPE_MAX)
210 L = traits_t::CELLTYPE_MAX;
211 else if (L < traits_t::CELLTYPE_MIN)
212 L = traits_t::CELLTYPE_MIN;
222 if (l < traits_t::CELLTYPE_MIN)
234 if (l < traits_t::CELLTYPE_MIN)
246 return p2lTable[
static_cast<unsigned int>(
p * traits_t::P2LTABLE_SIZE)];
cell_t cell_t
The type of.
int16_t 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...
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.
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)...
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...
int round(const T value)
Returns the closer integer (int) to x.