20namespace localization {
29 is_ground_useful(false) {}
67 for (
unsigned int y = 0; y <
rows_; ++y) {
68 for (
unsigned int x = 0; x <
cols_; ++x) {
76 for (
unsigned int y = 0; y <
rows_; ++y) {
77 for (
unsigned int x = 0; x <
cols_; ++x) {
108 unsigned int length = rows * cols;
109 for (
unsigned int i = 0; i < length; ++i) {
116 int intensity =
static_cast<int>(cell.
intensity);
117 if (intensity > 255) {
123 return static_cast<unsigned char>(intensity);
133 var = std::sqrt(var);
135 static_cast<int>(
static_cast<const float>(
var_range_) /
136 (var *
static_cast<const float>(
var_ratio_) + 1.0));
140 if (intensity_var < 1) {
143 return static_cast<uint16_t
>(intensity_var);
148 var =
static_cast<float>((
static_cast<const float>(
var_range_) / var - 1.0) /
157 int ratio =
static_cast<int>(delta_alt + 0.5);
164 return static_cast<uint16_t
>(ratio);
176 int ratio =
static_cast<int>(delta_alt + 0.5);
177 if (ratio > 0xffff) {
183 return static_cast<uint16_t
>(ratio);
194 int count_tmp = cell.
count;
195 while (count_tmp > 0) {
202 return static_cast<unsigned char>(count_exp);
207 int count_exp = data;
208 if (count_exp == 0) {
209 cell->
count = count_exp;
211 cell->
count = 1 << (count_exp - 1);
216 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
222 float* pf =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(p));
238 unsigned char* pp =
reinterpret_cast<unsigned char*
>(pf);
240 for (
unsigned int row = 0; row <
rows_; ++row) {
241 for (
unsigned int col = 0; col <
cols_; ++col) {
248 for (
unsigned int row = 0; row <
rows_; ++row) {
249 for (
unsigned int col = 0; col <
cols_; ++col) {
257 unsigned char* pp_high = pp;
258 for (
unsigned int row = 0; row <
rows_; ++row) {
259 for (
unsigned int col = 0; col <
cols_; ++col) {
260 uint16_t var = pp_high[row *
cols_ + col];
261 var =
static_cast<uint16_t
>(var * 256 + pp_low[row *
cols_ + col]);
270 for (
unsigned int row = 0; row <
rows_; ++row) {
271 for (
unsigned int col = 0; col <
cols_; ++col) {
272 uint16_t alt = pp_high[row *
cols_ + col];
273 alt =
static_cast<uint16_t
>(alt * 256 + pp_low[row *
cols_ + col]);
275 if (cell.
count > 0) {
286 for (
unsigned int row = 0; row <
rows_; ++row) {
287 for (
unsigned int col = 0; col <
cols_; ++col) {
288 uint16_t alt = pp_high[row *
cols_ + col];
289 alt =
static_cast<uint16_t
>(alt * 256 + pp_low[row *
cols_ + col]);
307 unsigned int buf_size)
const {
309 if (buf_size >= target_size) {
310 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
315 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int) * 2);
317 float* pf =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(p));
320 for (
unsigned int y = 0; y <
rows_; ++y) {
321 for (
unsigned int x = 0; x <
cols_; ++x) {
323 if (cell.
count == 0) {
338 buf_size -=
static_cast<unsigned int>(
sizeof(float) * 2);
342 for (
unsigned int y = 0; y <
rows_; ++y) {
343 for (
unsigned int x = 0; x <
cols_; ++x) {
360 buf_size -=
static_cast<unsigned int>(
sizeof(float) * 2);
362 unsigned char* pp =
reinterpret_cast<unsigned char*
>(pf);
364 for (
unsigned int row = 0; row <
rows_; ++row) {
365 for (
unsigned int col = 0; col <
cols_; ++col) {
372 for (
unsigned int row = 0; row <
rows_; ++row) {
373 for (
unsigned int col = 0; col <
cols_; ++col) {
381 unsigned char* pp_high = pp;
382 for (
unsigned int row = 0; row <
rows_; ++row) {
383 for (
unsigned int col = 0; col <
cols_; ++col) {
385 pp_high[row *
cols_ + col] =
static_cast<unsigned char>(var / 256);
386 pp_low[row *
cols_ + col] =
static_cast<unsigned char>(var % 256);
394 for (
unsigned int row = 0; row <
rows_; ++row) {
395 for (
unsigned int col = 0; col <
cols_; ++col) {
396 uint16_t altitude = 0.0;
400 pp_high[row *
cols_ + col] =
static_cast<unsigned char>(altitude / 256);
401 pp_low[row *
cols_ + col] =
static_cast<unsigned char>(altitude % 256);
409 for (
unsigned int row = 0; row <
rows_; ++row) {
410 for (
unsigned int col = 0; col <
cols_; ++col) {
415 pp_high[row *
cols_ + col] =
static_cast<unsigned char>(altitude / 256);
416 pp_low[row *
cols_ + col] =
static_cast<unsigned char>(altitude % 256);
426 unsigned int target_size =
427 static_cast<unsigned int>(
sizeof(
unsigned int) * 2 +
sizeof(
float) * 4);
429 target_size +=
static_cast<unsigned int>(
431 (
sizeof(
unsigned char) +
sizeof(
unsigned char) +
sizeof(uint16_t) +
432 sizeof(uint16_t) +
sizeof(uint16_t)));
437 *intensity_img = cv::Mat(cv::Size(
cols_,
rows_), CV_8UC1);
439 for (
unsigned int y = 0; y <
rows_; ++y) {
440 for (
unsigned int x = 0; x <
cols_; ++x) {
441 unsigned int id = y *
cols_ + x;
442 intensity_img->at<
unsigned char>(y, x) =
The options of the reflectance map.
unsigned int map_node_size_y_
The map node size in pixels.
unsigned int map_node_size_x_
The map node size in pixels.
The data structure of the map cells in a map node.
unsigned char EncodeCount(const LossyMapCell2D &cell) const
virtual unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
unsigned int rows_
The number of rows.
LossyMapMatrix2D & operator=(const LossyMapMatrix2D &matrix)
virtual unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.
const float alt_ground_interval_
void DecodeCount(unsigned char data, LossyMapCell2D *cell) const
void DecodeAltitudeGround(uint16_t data, LossyMapCell2D *cell) const
virtual void GetIntensityImg(cv::Mat *intensity_img) const
get intensity image of node.
void DecodeVar(uint16_t data, LossyMapCell2D *cell) const
void DecodeAltitudeAvg(uint16_t data, LossyMapCell2D *cell) const
void DecodeIntensity(unsigned char data, LossyMapCell2D *cell) const
const uint16_t ground_void_flag_
uint16_t EncodeVar(const LossyMapCell2D &cell) const
const float alt_avg_interval_
uint16_t EncodeAltitudeAvg(const LossyMapCell2D &cell) const
unsigned int cols_
The number of columns.
uint16_t EncodeAltitudeGround(const LossyMapCell2D &cell) const
unsigned char EncodeIntensity(const LossyMapCell2D &cell) const
LossyMapCell2D * map_cells_
The matrix data structure.
virtual unsigned int GetBinarySize() const
Get the binary size of the object.
virtual void Init(const BaseMapConfig *config)
Initialize the map matrix.
virtual void Reset(const BaseMapConfig *config)
Reset map cells data.
void Reset()
Reset to default value.
bool is_ground_useful
is ground altitude usefu
float altitude_ground
The ground altitude of the cell.
float intensity
The average intensity value.
float altitude
The average altitude of the cell.
LossyMapCell2D()
The default constructor.
float intensity_var
The variance intensity value.
unsigned int count
The number of samples in the cell.
LossyMapCell2D & operator=(const LossyMapCell2D &ref)
Overloading the assign operator.