22namespace localization {
24namespace pyramid_map {
49 const float* f_buf =
reinterpret_cast<const float*
>(buf);
54 const unsigned int* ui_buf =
reinterpret_cast<const unsigned int*
>(
55 reinterpret_cast<const void*
>(f_buf));
60 f_buf =
reinterpret_cast<const float*
>(
reinterpret_cast<const void*
>(ui_buf));
67 for (
unsigned int i = 0; i < 3; ++i) {
68 for (
unsigned int j = 0; j < 3; ++j) {
74 for (
unsigned int i = 0; i < 3; ++i) {
75 for (
unsigned int j = 0; j < 3; ++j) {
81 const unsigned char* uc_buf =
reinterpret_cast<const unsigned char*
>(f_buf);
91 size_t buf_size)
const {
93 if (buf_size >= target_size) {
94 float* p =
reinterpret_cast<float*
>(buf);
100 reinterpret_cast<unsigned int*
>(
reinterpret_cast<void*
>(p));
105 float* ppp =
reinterpret_cast<float*
>(
reinterpret_cast<void*
>(pp));
112 for (
unsigned int i = 0; i < 3; ++i) {
113 for (
unsigned int j = 0; j < 3; ++j) {
119 for (
unsigned int i = 0; i < 3; ++i) {
120 for (
unsigned int j = 0; j < 3; ++j) {
126 unsigned char* pppp =
reinterpret_cast<unsigned char*
>(ppp);
134 size_t sz =
sizeof(float) * 2 +
sizeof(
unsigned int) * 2 +
sizeof(float) * 3 +
137 sz +=
sizeof(float) * 9 +
sizeof(
unsigned char) * 1;
160 const Eigen::Vector3f& centroid,
167 static_cast<float>(
count_);
173 Eigen::Vector3f v3 = centroid -
centroid_;
181 const float intensity_var,
182 const unsigned int road_pt_count,
183 const unsigned int count,
184 const Eigen::Vector3f& centroid,
185 const Eigen::Matrix3f& centroid_cov) {
186 unsigned int new_count =
count_ + count;
187 float p0 =
static_cast<float>(
count_) /
static_cast<float>(new_count);
188 float p1 =
static_cast<float>(count) /
static_cast<float>(new_count);
189 float intensity_diff =
intensity_ - intensity;
193 intensity_diff * intensity_diff * p0 * p1;
210 const Eigen::Matrix3f& centroid_cov) {
216 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver;
217 eigen_solver.compute(cov);
218 Eigen::Matrix3f eigen_val = eigen_solver.eigenvalues().asDiagonal();
219 Eigen::Matrix3f centroid_evecs = eigen_solver.eigenvectors();
220 if (eigen_val(0, 0) < 0 || eigen_val(1, 1) < 0 || eigen_val(2, 2) <= 0) {
225 float min_covar_eigvalue = 0.01f * eigen_val(2, 2);
226 if (eigen_val(0, 0) < min_covar_eigvalue) {
227 eigen_val(0, 0) = min_covar_eigvalue;
228 if (eigen_val(1, 1) < min_covar_eigvalue) {
229 eigen_val(1, 1) = min_covar_eigvalue;
234 (centroid_evecs * eigen_val * centroid_evecs.inverse()).inverse();
235 if (
centroid_icov_.maxCoeff() == std::numeric_limits<float>::infinity() ||
236 centroid_icov_.minCoeff() == -std::numeric_limits<float>::infinity()) {
258 const float resolution,
259 const Eigen::Vector3f& centroid,
bool is_road) {
262 cell.
AddSample(intensity, altitude, centroid, is_road);
277 return altitude_index;
281 const unsigned int* p =
reinterpret_cast<const unsigned int*
>(buf);
282 unsigned int size = *p;
285 const unsigned char* pp =
reinterpret_cast<const unsigned char*
>(p);
286 for (
unsigned int i = 0; i < size; ++i) {
287 const int* ppp =
reinterpret_cast<const int*
>(pp);
288 int altitude_index = *ppp;
290 pp =
reinterpret_cast<const unsigned char*
>(ppp);
293 cells_[altitude_index] = cell;
294 pp += processed_size;
297 const int* ppp =
reinterpret_cast<const int*
>(pp);
303 p =
reinterpret_cast<const unsigned int*
>(ppp);
306 ppp =
reinterpret_cast<const int*
>(p);
307 for (
unsigned int i = 0; i < size; ++i) {
318 if (buf_size >= target_size) {
319 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
320 *p =
static_cast<unsigned int>(
cells_.size());
322 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int));
323 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
324 for (
auto it =
cells_.begin(); it !=
cells_.end(); ++it) {
325 int altitude_index = it->first;
327 int* ppp =
reinterpret_cast<int*
>(pp);
328 *ppp = altitude_index;
330 pp =
reinterpret_cast<unsigned char*
>(ppp);
331 size_t processed_size = cell.
CreateBinary(pp, buf_size);
332 assert(buf_size >= processed_size);
333 buf_size -= processed_size;
334 pp += processed_size;
337 int* ppp =
reinterpret_cast<int*
>(pp);
344 p =
reinterpret_cast<unsigned int*
>(ppp);
345 *p =
static_cast<unsigned int>(size);
347 ppp =
reinterpret_cast<int*
>(p);
348 for (
unsigned int i = 0; i < size; ++i) {
357 size_t target_size =
sizeof(
unsigned int);
358 for (
auto it =
cells_.begin(); it !=
cells_.end(); ++it) {
359 target_size +=
sizeof(int);
363 target_size +=
sizeof(int) * 2;
364 target_size +=
sizeof(
unsigned int);
370 const float altitude) {
371 return static_cast<int>(altitude / resolution);
375 const int altitude_index) {
376 return static_cast<float>(resolution *
377 (
static_cast<float>(altitude_index) + 0.5));
382 for (
auto it = cell_new.
cells_.begin(); it != cell_new.
cells_.end(); ++it) {
383 int altitude_index = it->first;
384 auto got = cell->
cells_.find(altitude_index);
385 if (got != cell->
cells_.end()) {
386 cell->
cells_[altitude_index].MergeCell(it->second);
415 map3d_cells_ =
nullptr;
421 Init(cells.rows_, cells.cols_);
422 for (
unsigned int y = 0; y < rows_; ++y) {
423 for (
unsigned int x = 0; x < cols_; ++x) {
444 unsigned int length = rows * cols;
445 for (
unsigned int i = 0; i < length; ++i) {
446 map3d_cells_[i].Reset();
451 const unsigned int* p =
reinterpret_cast<const unsigned int*
>(buf);
457 const unsigned char* pp =
reinterpret_cast<const unsigned char*
>(p);
458 for (
unsigned int y = 0; y < rows_; ++y) {
459 for (
unsigned int x = 0; x < cols_; ++x) {
462 pp += processed_size;
470 if (buf_size >= target_size) {
471 unsigned int* p =
reinterpret_cast<unsigned int*
>(buf);
476 buf_size -=
static_cast<unsigned int>(
sizeof(
unsigned int) * 2);
477 unsigned char* pp =
reinterpret_cast<unsigned char*
>(p);
478 for (
unsigned int y = 0; y < rows_; ++y) {
479 for (
unsigned int x = 0; x < cols_; ++x) {
481 size_t processed_size = cell.
CreateBinary(pp, buf_size);
482 assert(buf_size >= processed_size);
483 buf_size -= processed_size;
484 pp += processed_size;
492 size_t target_size =
sizeof(
unsigned int) * 2;
493 for (
unsigned int y = 0; y < rows_; ++y) {
494 for (
unsigned int x = 0; x < cols_; ++x) {
503 for (
unsigned int y = 0; y < cells->
GetRows(); ++y) {
504 for (
unsigned int x = 0; x < cells->
GetCols(); ++x) {
513 *intensity_img = cv::Mat(cv::Size(cols_, rows_), CV_8UC1);
514 for (
unsigned int y = 0; y < rows_; ++y) {
515 for (
unsigned int x = 0; x < cols_; ++x) {
516 unsigned int id = y * cols_ + x;
517 int min_altitude_index = map3d_cells_[id].min_altitude_index_;
518 intensity_img->at<
unsigned char>(y, x) =
519 (
unsigned char)(map3d_cells_[id]
520 .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.
int AddSample(const float intensity, const float altitude, const float resolution, const Eigen::Vector3f ¢roid, bool is_road=false)
Add an sample.
int min_altitude_index_
The index of smallest altitude.
void Reset()
Reset to default value.
int max_altitude_index_
The index of biggest altitude.
static int CalAltitudeIndex(const float resolution, const float altitude)
Calculate altitude index from altitude.
NdtMapCells()
The default constructor.
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.
static void Reduce(NdtMapCells *cell, const NdtMapCells &cell_new)
Combine two MapCell instances (Reduce).
size_t GetBinarySize() const
Get the binary size of the object.
size_t LoadBinary(const unsigned char *buf)
Load the map cell from a binary chunk.
std::unordered_map< int, NdtMapSingleCell > cells_
The multiple altitudes of the cell.
size_t CreateBinary(unsigned char *buf, size_t buf_size) const
Create the binary.
The data structure of ndt Map matrix.
virtual bool 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).
unsigned int GetRows() const
Get the size of row.
virtual size_t LoadBinary(const unsigned char *buf)
Load the map cell from a binary chunk.
unsigned int GetCols() const
Get the size of cols.
NdtMapMatrix()
The default constructor.
virtual void Reset()
Reset the matrix item to default value.
~NdtMapMatrix()
The default destructor.
virtual size_t GetBinarySize() const
Get the binary size of the object.
virtual size_t CreateBinary(unsigned char *buf, size_t buf_size) const
Create the binary.
virtual void Init(const BaseMapConfig &config)
Initialize the matrix with the config.
const NdtMapCells & GetMapCell(unsigned int row, unsigned int col) const
Get a const map cell.
The data structure of a single ndt map cell.
float intensity_
The average intensity value.
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.
unsigned int road_pt_count_
The number of samples belonging to road surface.
size_t LoadBinary(const unsigned char *buf)
Load the map cell from a binary chunk.
float intensity_var_
The variance intensity value.
Eigen::Vector3f centroid_
the centroid of the cell.
unsigned int count_
The number of samples in the cell.
NdtMapSingleCell & operator=(const NdtMapSingleCell &ref)
Overloading the assign operator.
void Reset()
Reset to default value.
void AddSample(const float intensity, const float altitude, const Eigen::Vector3f ¢roid, bool is_road=false)
Add an sample to the single 3d map cell.
void CentroidEigenSolver(const Eigen::Matrix3f ¢roid_cov)
static void Reduce(NdtMapSingleCell *cell, const NdtMapSingleCell &cell_new)
Combine two NdtMapSingleCell instances (Reduce).
Eigen::Matrix3f centroid_average_cov_
the pose covariance of the cell.
unsigned char is_icov_available_
the inverse covariance available flag.
Eigen::Matrix3f centroid_icov_
the pose inverse covariance of the cell.
const unsigned int minimum_points_threshold_
minimum number of points needed.
size_t CreateBinary(unsigned char *buf, size_t buf_size) const
Create the binary.
NdtMapSingleCell()
The default constructor.
size_t GetBinarySize() const
Get the binary size of the object.