21#include <unordered_map>
24#include "Eigen/Eigenvalues"
30namespace localization {
48 unsigned int CreateBinary(
unsigned char* buf,
unsigned int buf_size)
const;
58 inline void AddSample(
const float intensity,
const float altitude,
59 const Eigen::Vector3f centroid,
bool is_road =
false);
62 inline void MergeCell(
const float intensity,
const float intensity_var,
63 const unsigned int road_pt_count,
64 const unsigned int count,
65 const Eigen::Vector3f& centroid,
66 const Eigen::Matrix3f& centroid_cov);
72 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
104 int AddSample(
const float intensity,
const float altitude,
105 const float resolution,
const Eigen::Vector3f centroid,
106 bool is_road =
false);
116 unsigned int CreateBinary(
unsigned char* buf,
unsigned int buf_size)
const;
124 static float CalAltitude(
const float resolution,
const int altitude_index);
131 std::unordered_map<int, NdtMapSingleCell>
cells_;
156 void Init(
unsigned int rows,
unsigned int cols);
158 void Reset(
unsigned int rows,
unsigned int cols);
162 virtual unsigned int LoadBinary(
unsigned char* buf);
168 unsigned int buf_size)
const;
176 unsigned int col)
const {
179 return map3d_cells_[row * cols_ + col];
185 return map3d_cells_[row * cols_ + col];
188 unsigned int GetRows()
const {
return rows_; }
190 unsigned int GetCols()
const {
return cols_; }
201 std::unique_ptr<NdtMapCells[]> map3d_cells_;
216 const float altitude,
217 const Eigen::Vector3f centroid,
224 static_cast<float>(
count_);
230 Eigen::Vector3f v3 = centroid -
centroid_;
238 const float intensity_var,
239 const unsigned int road_pt_count,
240 const unsigned int count,
241 const Eigen::Vector3f& centroid,
242 const Eigen::Matrix3f& centroid_cov) {
243 unsigned int new_count =
count_ + count;
244 float p0 =
static_cast<float>(
count_) /
static_cast<float>(new_count);
245 float p1 =
static_cast<float>(count) /
static_cast<float>(new_count);
246 float intensity_diff =
intensity_ - intensity;
250 intensity_diff * intensity_diff * p0 * p1;
267 const Eigen::Matrix3f& centroid_cov) {
273 Eigen::SelfAdjointEigenSolver<Eigen::Matrix3f> eigen_solver;
274 eigen_solver.compute(cov);
275 Eigen::Matrix3f eigen_val = eigen_solver.eigenvalues().asDiagonal();
276 Eigen::Matrix3f centroid_evecs = eigen_solver.eigenvectors();
277 if (eigen_val(0, 0) < 0 || eigen_val(1, 1) < 0 || eigen_val(2, 2) <= 0) {
282 float min_covar_eigvalue = 0.01f * eigen_val(2, 2);
283 if (eigen_val(0, 0) < min_covar_eigvalue) {
284 eigen_val(0, 0) = min_covar_eigvalue;
285 if (eigen_val(1, 1) < min_covar_eigvalue) {
286 eigen_val(1, 1) = min_covar_eigvalue;
291 (centroid_evecs * eigen_val * centroid_evecs.inverse()).inverse();
292 if (
centroid_icov_.maxCoeff() == std::numeric_limits<float>::infinity() ||
293 centroid_icov_.minCoeff() == -std::numeric_limits<float>::infinity()) {
The options of the reflectance map.
The data structure of the map cells in a map node.
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.
NdtMapCells & GetMapCell(unsigned int row, unsigned int col)
Get a map cell.
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.
void Reset()
Reset to default value.
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.
void CentroidEigenSolver(const Eigen::Matrix3f ¢roid_cov)
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.