21namespace localization {
36 float* f_buf =
reinterpret_cast<float*
>(buf);
41 unsigned int* ui_buf =
42 reinterpret_cast<unsigned int*
>(
reinterpret_cast<void*
>(f_buf));
47 f_buf =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(ui_buf));
54 for (
unsigned int i = 0; i < 3; ++i) {
55 for (
unsigned int j = 0; j < 3; ++j) {
61 for (
unsigned int i = 0; i < 3; ++i) {
62 for (
unsigned int j = 0; j < 3; ++j) {
68 unsigned char* uc_buf =
reinterpret_cast<unsigned char*
>(f_buf);
78 unsigned int buf_size)
const {
80 if (buf_size >= target_size) {
81 float* p =
reinterpret_cast<float*
>(buf);
87 reinterpret_cast<unsigned int*
>(
reinterpret_cast<void*
>(p));
92 float* ppp =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(pp));
99 for (
unsigned int i = 0; i < 3; ++i) {
100 for (
unsigned int j = 0; j < 3; ++j) {
106 for (
unsigned int i = 0; i < 3; ++i) {
107 for (
unsigned int j = 0; j < 3; ++j) {
113 unsigned char* pppp =
reinterpret_cast<unsigned char*
>(ppp);
122 static_cast<unsigned int>(
sizeof(float) * 2 +
sizeof(
unsigned int) * 2 +
123 sizeof(float) * 3 +
sizeof(
float) * 9);
125 sz +=
static_cast<unsigned int>(
sizeof(float) * 9 +
126 sizeof(
unsigned char) * 1);
161 const float resolution,
162 const Eigen::Vector3f centroid,
bool is_road) {
165 cell.
AddSample(intensity, altitude, centroid, is_road);
180 return altitude_index;
184 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
185 unsigned int size = *p;
188 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
189 for (
unsigned int i = 0; i < size; ++i) {
190 int* ppp =
reinterpret_cast<int*
>(pp);
191 int altitude_index = *ppp;
193 pp =
reinterpret_cast<unsigned char*
>(ppp);
195 unsigned int processed_size = cell.
LoadBinary(pp);
196 cells_[altitude_index] = cell;
197 pp += processed_size;
200 int* ppp =
reinterpret_cast<int*
>(pp);
206 p =
reinterpret_cast<unsigned int*
>(ppp);
209 ppp =
reinterpret_cast<int*
>(p);
210 for (
unsigned int i = 0; i < size; ++i) {
220 unsigned int buf_size)
const {
222 if (buf_size >= target_size) {
223 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
224 *p =
static_cast<unsigned int>(
cells_.size());
226 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int));
227 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
228 for (
auto it =
cells_.begin(); it !=
cells_.end(); ++it) {
229 int altitude_index = it->first;
231 int* ppp =
reinterpret_cast<int*
>(pp);
232 *ppp = altitude_index;
234 pp =
reinterpret_cast<unsigned char*
>(ppp);
235 unsigned int processed_size = cell.
CreateBinary(pp, buf_size);
236 assert(buf_size >= processed_size);
237 buf_size -= processed_size;
238 pp += processed_size;
241 int* ppp =
reinterpret_cast<int*
>(pp);
248 p =
reinterpret_cast<unsigned int*
>(ppp);
251 ppp =
reinterpret_cast<int*
>(p);
252 for (
unsigned int i = 0; i < size; ++i) {
261 unsigned int target_size =
sizeof(
unsigned int);
262 for (
auto it =
cells_.begin(); it !=
cells_.end(); ++it) {
263 target_size +=
static_cast<unsigned int>(
sizeof(int));
268 target_size +=
static_cast<unsigned int>(
sizeof(int) * 2);
269 target_size +=
static_cast<unsigned int>(
sizeof(
unsigned int));
277 const float altitude) {
278 return static_cast<int>(altitude / resolution);
282 const int altitude_index) {
283 return static_cast<float>(resolution *
284 (
static_cast<float>(altitude_index) + 0.5));
289 for (
auto it = cell_new.
cells_.begin(); it != cell_new.
cells_.end(); ++it) {
290 int altitude_index = it->first;
291 auto got = cell->
cells_.find(altitude_index);
292 if (got != cell->
cells_.end()) {
293 cell->
cells_[altitude_index].MergeCell(it->second);
322 map3d_cells_ =
nullptr;
328 Init(cells.rows_, cells.cols_);
329 for (
unsigned int y = 0; y < rows_; ++y) {
330 for (
unsigned int x = 0; x < cols_; ++x) {
353 unsigned int length = rows * cols;
354 for (
unsigned int i = 0; i < length; ++i) {
355 map3d_cells_[i].Reset();
360 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
366 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
367 for (
unsigned int y = 0; y < rows_; ++y) {
368 for (
unsigned int x = 0; x < cols_; ++x) {
370 unsigned int processed_size = cell.
LoadBinary(pp);
371 pp += processed_size;
378 unsigned int buf_size)
const {
380 if (buf_size >= target_size) {
381 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
386 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int) * 2);
387 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
388 for (
unsigned int y = 0; y < rows_; ++y) {
389 for (
unsigned int x = 0; x < cols_; ++x) {
391 unsigned int processed_size = cell.
CreateBinary(pp, buf_size);
392 assert(buf_size >= processed_size);
393 buf_size -= processed_size;
394 pp += processed_size;
402 unsigned int target_size =
403 static_cast<unsigned int>(
sizeof(
unsigned int) * 2);
404 for (
unsigned int y = 0; y < rows_; ++y) {
405 for (
unsigned int x = 0; x < cols_; ++x) {
414 for (
unsigned int y = 0; y < cells->
GetRows(); ++y) {
415 for (
unsigned int x = 0; x < cells->
GetCols(); ++x) {
424 *intensity_img = cv::Mat(cv::Size(cols_, rows_), CV_8UC1);
425 for (
unsigned int y = 0; y < rows_; ++y) {
426 for (
unsigned int x = 0; x < cols_; ++x) {
427 unsigned int id = y * cols_ + x;
428 int min_altitude_index = map3d_cells_[id].min_altitude_index_;
429 intensity_img->at<
unsigned char>(y, x) =
430 (
unsigned char)(map3d_cells_[id]
431 .cells_[min_altitude_index]
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 ndt Map cell.
void Reset()
Reset to default value.
int AddSample(const float intensity, const float altitude, const float resolution, const Eigen::Vector3f centroid, bool is_road=false)
Add an sample.
unsigned int GetBinarySize() const
Get the binary size of the object.
std::vector< int > road_cell_indices_
The indices of road surface.
static float CalAltitude(const float resolution, const int altitude_index)
Calculate altitude from altitude index.
unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.
int max_altitude_index_
The index of biggest altitude.
unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
static int CalAltitudeIndex(const float resolution, const float altitude)
Calculate altitude index from altitude.
static void Reduce(NdtMapCells *cell, const NdtMapCells &cell_new)
Combine two MapCell instances (Reduce).
std::unordered_map< int, NdtMapSingleCell > cells_
The multiple altitudes of the cell.
NdtMapCells()
The default constructor.
int min_altitude_index_
The index of smallest altitude.
The data structure of ndt Map matrix.
const NdtMapCells & GetMapCell(unsigned int row, unsigned int col) const
Get a const map cell.
unsigned int GetRows() const
Get the size of row.
NdtMapMatrix()
The default constructor.
virtual void Reset(const BaseMapConfig *config)
Reset the matrix item to default value.
virtual void GetIntensityImg(cv::Mat *intensity_img) const
get intensity image of node.
static void Reduce(NdtMapMatrix *cells, const NdtMapMatrix &cells_new)
Combine two NdtMapMatrix instances (Reduce).
virtual unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
virtual unsigned int GetBinarySize() const
Get the binary size of the object.
virtual void Init(const BaseMapConfig *config)
Initialize the matrix with the config.
unsigned int GetCols() const
Get the size of cols.
~NdtMapMatrix()
The default destructor.
virtual unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.
The data structure of a single ndt map cell.
float intensity_var_
The variance intensity value.
NdtMapSingleCell & operator=(const NdtMapSingleCell &ref)
Overloading the assign operator.
unsigned int GetBinarySize() const
Get the binary size of the object.
void AddSample(const float intensity, const float altitude, const Eigen::Vector3f centroid, bool is_road=false)
Add an sample to the single 3d map cell.
unsigned char is_icov_available_
the inverse covariance available flag.
const unsigned int minimum_points_threshold_
minimum number of points needed.
NdtMapSingleCell()
The default constructor.
Eigen::Vector3f centroid_
the centroid of the cell.
Eigen::Matrix3f centroid_icov_
the pose inverse covariance of the cell.
Eigen::Matrix3f centroid_average_cov_
the pose covariance of the cell.
unsigned int road_pt_count_
The number of samples belonging to road surface.
unsigned int CreateBinary(unsigned char *buf, unsigned int buf_size) const
Create the binary.
unsigned int LoadBinary(unsigned char *buf)
Load the map cell from a binary chunk.
unsigned int count_
The number of samples in the cell.
float intensity_
The average intensity value.
static void Reduce(NdtMapSingleCell *cell, const NdtMapSingleCell &cell_new)
Combine two NdtMapSingleCell instances (Reduce).
void MergeCell(const float intensity, const float intensity_var, const unsigned int road_pt_count, const unsigned int count, const Eigen::Vector3f ¢roid, const Eigen::Matrix3f ¢roid_cov)
Merge two cells.