20namespace localization {
48 const float new_intensity) {
50 float fcount =
static_cast<float>(
count);
52 float value = v1 / fcount;
65 float* p =
reinterpret_cast<float*
>(buf);
75 reinterpret_cast<unsigned int*
>(
reinterpret_cast<void*
>(p));
81 unsigned int buf_size)
const {
83 if (buf_size >= target_size) {
84 float* p =
reinterpret_cast<float*
>(buf);
94 reinterpret_cast<unsigned int*
>(
reinterpret_cast<void*
>(p));
101 return static_cast<unsigned int>(
sizeof(float) * 4 +
sizeof(
unsigned int));
115 double altitude_thres) {
118 unsigned int best_layer_id =
GetLayerId(altitude);
120 if (best_layer_id == 0) {
124 cell.
AddSample(
static_cast<float>(altitude),
125 static_cast<float>(intensity));
128 std::cerr <<
"[Warning] There are no enough reserved map cell layers. "
129 "Please increase IDL_CAR_NUM_RESERVED_MAP_LAYER."
134 double layer_alt_dif = fabs(
map_cells[best_layer_id].altitude - altitude);
135 if (layer_alt_dif < altitude_thres) {
138 cell.
AddSample(
static_cast<float>(altitude),
139 static_cast<float>(intensity));
144 cell.
AddSample(
static_cast<float>(altitude),
145 static_cast<float>(intensity));
148 std::cerr <<
"[Warning] There are no enough reserved map cell layers. "
149 "Please increase IDL_CAR_NUM_RESERVED_MAP_LAYER."
159 cell.
AddSample(
static_cast<float>(altitude),
static_cast<float>(intensity));
163 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
164 unsigned int size = *p;
167 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
168 for (
unsigned int i = 0; i < size; ++i) {
170 unsigned int processed_size = cell.
LoadBinary(pp);
171 pp += processed_size;
177 unsigned int buf_size)
const {
179 if (buf_size >= target_size) {
180 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
183 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int));
184 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
187 unsigned int processed_size = cell.
CreateBinary(pp, buf_size);
188 DCHECK_GE(buf_size, processed_size);
189 buf_size -= processed_size;
190 pp += processed_size;
197 unsigned int target_size =
sizeof(
207 unsigned int best_layer_id = 0;
208 double best_layer_alt_dif = 1e10;
209 for (
unsigned int i = 1; i <
layer_num; ++i) {
211 double layer_alt_dif = fabs(cell.
altitude - altitude);
212 if (layer_alt_dif < best_layer_alt_dif) {
213 best_layer_alt_dif = layer_alt_dif;
217 return best_layer_id;
222 for (
unsigned int i = 1; i <
layer_num; ++i) {
224 values->push_back(
static_cast<unsigned char>(cell.
intensity));
230 for (
unsigned int i = 1; i <
layer_num; ++i) {
238 for (
unsigned int i = 1; i <
layer_num; ++i) {
246 for (
unsigned int i = 1; i <
layer_num; ++i) {
254 for (
unsigned int i = 1; i <
layer_num; ++i) {
256 counts->push_back(cell.
count);
278 for (
unsigned int y = 0; y <
rows_; ++y) {
279 for (
unsigned int x = 0; x <
cols_; ++x) {
309 unsigned int length = rows * cols;
310 for (
unsigned int i = 0; i < length; ++i) {
316 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
323 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
324 for (
unsigned int y = 0; y <
rows_; ++y) {
325 for (
unsigned int x = 0; x <
cols_; ++x) {
327 unsigned int processed_size = cell.
LoadBinary(pp);
328 pp += processed_size;
335 unsigned int buf_size)
const {
337 if (buf_size >= target_size) {
338 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
343 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int) * 2);
344 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
345 for (
unsigned int y = 0; y <
rows_; ++y) {
346 for (
unsigned int x = 0; x <
cols_; ++x) {
348 unsigned int processed_size = cell.
CreateBinary(pp, buf_size);
349 DCHECK_GE(buf_size, processed_size);
350 buf_size -= processed_size;
351 pp += processed_size;
360 unsigned int target_size =
361 static_cast<unsigned int>(
sizeof(
unsigned int) * 2);
362 for (
unsigned int y = 0; y <
rows_; ++y) {
363 for (
unsigned int x = 0; x <
cols_; ++x) {
372 *intensity_img = cv::Mat(cv::Size(
cols_,
rows_), CV_8UC1);
374 for (uint32_t y = 0; y <
rows_; ++y) {
375 for (uint32_t x = 0; x <
cols_; ++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.
virtual unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.
const LosslessMapCell & GetMapCell(unsigned int row, unsigned int col) const
Get a map cell.
virtual void Reset(const BaseMapConfig *config)
Reset map cells data.
virtual unsigned int GetBinarySize() const
Get the binary size of the object.
unsigned int cols_
The number of columns.
virtual void Init(const BaseMapConfig *config)
Initialize the map matrix.
virtual unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
unsigned int rows_
The number of rows.
virtual void GetIntensityImg(cv::Mat *intensity_img) const
get intensity image of node.
LosslessMapCell * map_cells_
The matrix data structure.
#define IDL_CAR_NUM_RESERVED_MAP_LAYER
The first layer (layer 0) includes all the intensities from any layers.
The multiple layers of the cell.
float GetAlt() const
Get the average altitude of the map cell.
float GetVar() const
Get the variance of the intensity of the map cell.
unsigned int GetCount() const
Get the count of the samples in the map cell.
LosslessMapCell()
The default constructor.
LosslessMapSingleCell map_cells[IDL_CAR_NUM_RESERVED_MAP_LAYER]
The multiple layers of the cell.
unsigned char GetValue() const
Get the average intensity of the map cell.
void Reset()
Reset to default value.
unsigned int GetBinarySize() const
Get the binary size of the object.
unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.
void SetValueLayer(double altitude, unsigned char intensity, double altitude_thres=10.0)
Set the value of a layer that layer_id > 0.
unsigned int layer_num
The layers of the cell.
float GetAltVar() const
Get the variance of the altitude of the map cell.
unsigned int GetLayerId(double altitude) const
Match a layer in the map cell given an altitude.
unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
void SetValue(double altitude, unsigned char intensity)
Set the value.
void GetValue(std::vector< unsigned char > *values) const
Load the map cell from a binary chunk.
float altitude_var
The variance altitude value of the cell.
float altitude
The average altitude of the cell.
unsigned int count
The number of samples in the cell.
void Reset()
Reset to default value.
unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
void AddSample(const float new_altitude, const float new_intensity)
Add a sample.
float intensity_var
The variance intensity value.
float intensity
The average intensity value.
LosslessMapSingleCell()
The default constructor.
unsigned int GetBinarySize() const
Get the binary size of the object.
LosslessMapSingleCell & operator=(const LosslessMapSingleCell &ref)
Overloading the assign operator.
unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.