29 #ifndef CLogOddsGridMap2D_H
30 #define CLogOddsGridMap2D_H
44 static const int8_t CELLTYPE_MIN = -127;
45 static const int8_t CELLTYPE_MAX = 127;
46 static const int8_t P2LTABLE_SIZE = CELLTYPE_MAX;
47 static const size_t LOGODDS_LUT_ENTRIES = 1<<8;
51 static const int16_t CELLTYPE_MIN = -32767;
52 static const int16_t CELLTYPE_MAX = 32767;
53 static const int16_t P2LTABLE_SIZE = CELLTYPE_MAX;
54 static const size_t LOGODDS_LUT_ENTRIES = 1<<16;
66 template <
typename TCELL>
70 typedef detail::logoddscell_traits<TCELL>
traits_t;
86 const unsigned _size_x)
88 cell_t *theCell = mapArray + (x+y*_size_x);
89 if (*theCell > thres )
90 *theCell -= logodd_obs;
91 else *theCell = traits_t::CELLTYPE_MIN;
106 if (*theCell > thres )
107 *theCell -= logodd_obs;
108 else *theCell = traits_t::CELLTYPE_MIN;
125 const unsigned _size_x)
127 cell_t *theCell = mapArray + (x+y*_size_x);
128 if (*theCell < thres )
129 *theCell += logodd_obs;
130 else *theCell = traits_t::CELLTYPE_MAX;
146 if (*theCell < thres )
147 *theCell += logodd_obs;
148 else *theCell = traits_t::CELLTYPE_MAX;
161 template <
typename TCELL>
165 typedef detail::logoddscell_traits<TCELL>
traits_t;
185 static const double LOGODD_K = 16;
186 static const double LOGODD_K_INV = 1.0/LOGODD_K;
190 for (
int i=traits_t::CELLTYPE_MIN;i<=traits_t::CELLTYPE_MAX;i++)
192 float f = 1.0f / (1.0f + exp( - i * LOGODD_K_INV ) );
193 unsigned int idx = -traits_t::CELLTYPE_MIN+i;
199 p2lTable.resize( traits_t::P2LTABLE_SIZE+1 );
200 double K = 1.0 / traits_t::P2LTABLE_SIZE;
201 for (
int j=0;j<=traits_t::P2LTABLE_SIZE;j++)
209 double logodd = log(p)-log(1-p);
210 int L =
round(logodd * LOGODD_K);
211 if (L>traits_t::CELLTYPE_MAX)
212 L=traits_t::CELLTYPE_MAX;
213 else if (L<traits_t::CELLTYPE_MIN)
214 L=traits_t::CELLTYPE_MIN;
225 if (l<traits_t::CELLTYPE_MIN)
234 if (l<traits_t::CELLTYPE_MIN)
243 return p2lTable[
static_cast<unsigned int>(p * traits_t::P2LTABLE_SIZE) ];