58 #include "pcl/filters/boost.h" 59 #include "pcl/filters/voxel_grid.h" 60 #include "pcl/kdtree/kdtree_flann.h" 61 #include "pcl/point_types.h" 67 namespace localization {
73 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
102 template <
typename Po
intT>
105 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
125 : min_points_per_voxel_(6),
128 voxel_centroids_leaf_indices_(),
130 leaf_size_.setZero();
141 if (min_points_per_voxel > 2) {
142 min_points_per_voxel_ = min_points_per_voxel;
144 AWARN <<
"Covariance calculation requires at least 3 " 145 <<
"points, setting Min Point per Voxel to 3 ";
146 min_points_per_voxel_ = 3;
154 inline void filter(
const std::vector<Leaf> &cell_leaf,
155 bool searchable =
true) {
157 SetMap(cell_leaf, voxel_centroids_);
158 if (voxel_centroids_->size() > 0) {
159 kdtree_.setInputCloud(voxel_centroids_);
163 void SetMap(
const std::vector<Leaf> &map_leaves, PointCloudPtr output);
167 typename std::map<size_t, Leaf>::iterator leaf_iter = leaves_.find(index);
168 if (leaf_iter == leaves_.end()) {
171 LeafConstPtr ret(&(leaf_iter->second));
181 int ijk0 =
static_cast<int>((p->x - map_left_top_corner_(0)) *
182 inverse_leaf_size_[0]) -
184 int ijk1 =
static_cast<int>((p->y - map_left_top_corner_(1)) *
185 inverse_leaf_size_[1]) -
187 int ijk2 =
static_cast<int>((p->z - map_left_top_corner_(2)) *
188 inverse_leaf_size_[2]) -
192 int idx = ijk0 * divb_mul_[0] + ijk1 * divb_mul_[1] + ijk2 * divb_mul_[2];
195 typename std::map<size_t, Leaf>::iterator leaf_iter = leaves_.find(idx);
196 if (leaf_iter == leaves_.end()) {
200 LeafConstPtr ret(&(leaf_iter->second));
208 int ijk0 =
static_cast<int>((p->x() - map_left_top_corner_(0)) *
209 inverse_leaf_size_[0]) -
211 int ijk1 =
static_cast<int>((p->y() - map_left_top_corner_(1)) *
212 inverse_leaf_size_[1]) -
214 int ijk2 =
static_cast<int>((p->z() - map_left_top_corner_(2)) *
215 inverse_leaf_size_[2]) -
219 int idx = ijk0 * divb_mul_[0] + ijk1 * divb_mul_[1] + ijk2 * divb_mul_[2];
222 typename std::map<size_t, Leaf>::iterator leaf_iter = leaves_.find(idx);
223 if (leaf_iter == leaves_.end()) {
227 LeafConstPtr ret(&(leaf_iter->second));
232 inline const std::map<size_t, Leaf> &
GetLeaves() {
return leaves_; }
239 int RadiusSearch(
const PointT &point,
double radius,
240 std::vector<LeafConstPtr> *k_leaves,
241 std::vector<float> *k_sqr_distances,
242 unsigned int max_nn = 0);
244 void GetDisplayCloud(pcl::PointCloud<pcl::PointXYZ> *cell_cloud);
247 map_left_top_corner_ = left_top_corner;
255 if (leaf_size_[3] == 0) {
258 inverse_leaf_size_ = Eigen::Array4f::Ones() / leaf_size_.array();
288 #include "modules/localization/ndt/ndt_locator/ndt_voxel_grid_covariance.hpp" LeafConstPtr GetLeaf(PointT *p)
Get the voxel containing point p.
Definition: ndt_voxel_grid_covariance.h:179
Eigen::Vector4i div_b_
Definition: ndt_voxel_grid_covariance.h:119
void SetVoxelGridResolution(float lx, float ly, float lz)
Definition: ndt_voxel_grid_covariance.h:250
PointCloudPtr GetCentroids()
Get a pointcloud containing the voxel centroids.
Definition: ndt_voxel_grid_covariance.h:235
const std::map< size_t, Leaf > & GetLeaves()
Get the leaf structure map.
Definition: ndt_voxel_grid_covariance.h:232
pcl::PointCloud< PointT > PointCloud
Definition: ndt_voxel_grid_covariance.h:108
std::map< size_t, Leaf > leaves_
Voxel structure containing all leaf nodes (includes voxels with less than a sufficient number of poin...
Definition: ndt_voxel_grid_covariance.h:268
Eigen::Vector3d GetMean() const
Get the voxel centroid.
Definition: ndt_voxel_grid_covariance.h:83
Eigen::Vector4i max_b_
Definition: ndt_voxel_grid_covariance.h:117
Eigen::Vector4i divb_mul_
Definition: ndt_voxel_grid_covariance.h:120
Eigen::Vector3f Vector3f
Definition: base_map_fwd.h:29
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int GetPointCount() const
Get the number of points contained by this voxel.
Definition: ndt_voxel_grid_covariance.h:80
Eigen::Vector4i min_b_
Definition: ndt_voxel_grid_covariance.h:116
Leaf * LeafPtr
Pointer to VoxelGridCovariance leaf structure.
Definition: ndt_voxel_grid_covariance.h:96
void SetInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
Definition: ndt_voxel_grid_covariance.h:136
LeafConstPtr GetLeaf(Eigen::Vector3f *p)
Get the voxel containing point p.*.
Definition: ndt_voxel_grid_covariance.h:206
Eigen::Array4f inverse_leaf_size_
Definition: ndt_voxel_grid_covariance.h:114
Eigen::Vector4f leaf_size_
Definition: ndt_voxel_grid_covariance.h:113
PointCloudConstPtr input_
Definition: ndt_voxel_grid_covariance.h:111
Eigen::Vector3d Vector3d
Definition: frame_transform.h:27
LeafConstPtr GetLeaf(int index)
Get the voxel containing point p.
Definition: ndt_voxel_grid_covariance.h:166
Eigen::Matrix3d GetInverseCov() const
Get the inverse of the voxel covariance.
Definition: ndt_voxel_grid_covariance.h:86
pcl::PointCloud< Point >::Ptr PointCloudPtr
Definition: types.h:65
int nr_points_
Number of points contained by voxel.
Definition: ndt_voxel_grid_covariance.h:89
void SetMapLeftTopCorner(const Eigen::Vector3d &left_top_corner)
Definition: ndt_voxel_grid_covariance.h:246
const Leaf * LeafConstPtr
Const pointer to VoxelGridCovariance leaf structure.
Definition: ndt_voxel_grid_covariance.h:98
void SetMinPointPerVoxel(int min_points_per_voxel)
Set the minimum number of points required for a cell to be used (must be 3 or greater for covariance ...
Definition: ndt_voxel_grid_covariance.h:140
boost::shared_ptr< const PointCloud > PointCloudConstPtr
Definition: ndt_voxel_grid_covariance.h:110
boost::shared_ptr< PointCloud > PointCloudPtr
Definition: ndt_voxel_grid_covariance.h:109
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Leaf()
Definition: ndt_voxel_grid_covariance.h:74
int min_points_per_voxel_
Minimum points contained with in a voxel to allow it to be usable.
Definition: ndt_voxel_grid_covariance.h:264
PointCloudPtr voxel_centroids_
Point cloud containing centroids of voxels containing at least minimum number of points.
Definition: ndt_voxel_grid_covariance.h:272
VoxelGridCovariance()
Constructor.
Definition: ndt_voxel_grid_covariance.h:124
std::vector< int > voxel_centroids_leaf_indices_
Indices of leaf structurs associated with each point.
Definition: ndt_voxel_grid_covariance.h:275
A searchable voxel structure containing the mean and covariance of the data.
Definition: ndt_voxel_grid_covariance.h:103
int GetMinPointPerVoxel()
Get the minimum number of points required for a cell to be used.
Definition: ndt_voxel_grid_covariance.h:151
Eigen::Vector3d map_left_top_corner_
Left top corner.
Definition: ndt_voxel_grid_covariance.h:281
Eigen::Matrix3d icov_
Inverse of voxel covariance matrix.
Definition: ndt_voxel_grid_covariance.h:93
Simple structure to hold a centroid, covarince and the number of points in a leaf.
Definition: ndt_voxel_grid_covariance.h:72
pcl::KdTreeFLANN< PointT > kdtree_
KdTree generated using voxel_centroids_ (used for searching).
Definition: ndt_voxel_grid_covariance.h:278
#define AWARN
Definition: log.h:43
Eigen::Vector3d mean_
3D voxel centroid.
Definition: ndt_voxel_grid_covariance.h:91
Eigen::Matrix3d Matrix3d
Definition: base_map_fwd.h:33
void filter(const std::vector< Leaf > &cell_leaf, bool searchable=true)
Initializes voxel structure.
Definition: ndt_voxel_grid_covariance.h:154