40 #include <pcl/filters/voxel_grid.h>
42 #include <pcl/point_types.h>
43 #include <pcl/kdtree/kdtree_flann.h>
54 template<
typename Po
intT>
78 using FieldList =
typename pcl::traits::fieldList<PointT>::type;
85 using Ptr = shared_ptr<VoxelGrid<PointT> >;
86 using ConstPtr = shared_ptr<const VoxelGrid<PointT> >;
216 if(min_points_per_voxel > 2)
222 PCL_WARN (
"[%s::setMinPointPerVoxel] Covariance calculation requires at least 3 points, setting Min Point per Voxel to 3\n", this->
getClassName ().c_str ());
269 PCL_WARN (
"[%s::filter] No voxels with a sufficient number of points. Grid will not be searchable. You can try reducing the min number of points required per voxel or increasing the voxel/leaf size.\n", this->
getClassName ().c_str ());
291 PCL_WARN (
"[%s::filter] No voxels with a sufficient number of points. Grid will not be searchable. You can try reducing the min number of points required per voxel or increasing the voxel/leaf size\n", this->
getClassName ().c_str ());
307 auto leaf_iter =
leaves_.find (index);
308 if (leaf_iter !=
leaves_.end ())
332 auto leaf_iter =
leaves_.find (idx);
333 if (leaf_iter !=
leaves_.end ())
351 int ijk1 =
static_cast<int> (std::floor (p[1] * inverse_leaf_size_[1]) -
min_b_[1]);
352 int ijk2 =
static_cast<int> (std::floor (p[2] * inverse_leaf_size_[2]) -
min_b_[2]);
358 auto leaf_iter =
leaves_.find (idx);
359 if (leaf_iter !=
leaves_.end ())
377 getNeighborhoodAtPoint (
const Eigen::Matrix<int, 3, Eigen::Dynamic>& relative_coordinates,
const PointT& reference_point, std::vector<LeafConstPtr> &neighbors)
const;
418 inline const std::map<std::size_t, Leaf>&
451 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances)
const
458 PCL_WARN (
"[%s::nearestKSearch] Not Searchable\n", this->
getClassName ().c_str ());
467 k_leaves.reserve (k);
468 for (
const auto &k_index : k_indices)
475 k_leaves.push_back(&voxel->second);
477 return k_leaves.size();
491 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances)
const
493 if (index >= static_cast<int> (cloud.
size ()) || index < 0)
495 return (
nearestKSearch (cloud[index], k, k_leaves, k_sqr_distances));
510 std::vector<float> &k_sqr_distances,
unsigned int max_nn = 0)
const
517 PCL_WARN (
"[%s::radiusSearch] Not Searchable\n", this->
getClassName ().c_str ());
526 k_leaves.reserve (k);
527 for (
const auto &k_index : k_indices)
534 k_leaves.push_back(&voxel->second);
536 return k_leaves.size();
551 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances,
552 unsigned int max_nn = 0)
const
554 if (index >= static_cast<int> (cloud.
size ()) || index < 0)
556 return (
radiusSearch (cloud[index], radius, k_leaves, k_sqr_distances, max_nn));
589 #ifdef PCL_NO_PRECOMPILE
590 #include <pcl/filters/impl/voxel_grid_covariance.hpp>
Eigen::Vector3d getMean() const
Get the voxel centroid.
Eigen::Vector3d getEvals() const
Get the eigen values of the voxel covariance.
LeafConstPtr getLeaf(Eigen::Vector3f &p)
Get the voxel containing point p.
shared_ptr< PointCloud< PointT > > Ptr
void filter(PointCloud &output, bool searchable=false)
Filter cloud and initializes voxel structure.
PointCloudPtr voxel_centroids_
Point cloud containing centroids of voxels containing atleast minimum number of points.
LeafConstPtr getLeaf(PointT &p)
Get the voxel containing point p.
LeafConstPtr getLeaf(int index)
Get the voxel containing point p.
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
Eigen::Vector3d mean_
3D voxel centroid
Eigen::Matrix3d getEvecs() const
Get the eigen vectors of the voxel covariance.
Eigen::Matrix3d icov_
Inverse of voxel covariance matrix.
int radiusSearch(const PointT &point, double radius, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
Search for all the nearest occupied voxels of the query point in a given radius.
double min_covar_eigvalue_mult_
Minimum allowable ratio between eigenvalues to prevent singular covariance matrices.
Eigen::Matrix3d getCov() const
Get the voxel covariance.
const std::map< std::size_t, Leaf > & getLeaves()
Get the leaf structure map.
void filter(bool searchable=false)
Initializes voxel structure.
int getMinPointPerVoxel()
Get the minimum number of points required for a cell to be used.
typename pcl::traits::fieldList< PointTarget >::type FieldList
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
Leaf * LeafPtr
Pointer to VoxelGridCovariance leaf structure.
std::vector< int > voxel_centroids_leaf_indices_
Indices of leaf structures associated with each point in voxel_centroids_ (used for searching)...
Simple structure to hold a centroid, covarince and the number of points in a leaf.
void getDisplayCloud(pcl::PointCloud< PointXYZ > &cell_cloud)
Get a cloud to visualize each voxels normal distribution.
double getCovEigValueInflationRatio()
Get the minimum allowable ratio between eigenvalues to prevent singular covariance matrices...
bool searchable_
Flag to determine if voxel structure is searchable.
int getNeighborhoodAtPoint(const Eigen::Matrix< int, 3, Eigen::Dynamic > &relative_coordinates, const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get the voxels surrounding point p designated by relative_coordinates.
Eigen::VectorXf centroid
Nd voxel centroid.
Eigen::Matrix3d getInverseCov() const
Get the inverse of the voxel covariance.
VoxelGridCovariance()
Constructor.
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
shared_ptr< Filter< PointTarget > > Ptr
int getFaceNeighborsAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get the voxel at p and its facing voxels (up to 7 voxels).
PointCloudPtr getCentroids()
Get a pointcloud containing the voxel centroids.
typename PointCloud::Ptr PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
int min_points_per_voxel_
Minimum points contained with in a voxel to allow it to be usable.
Eigen::Matrix3d evecs_
Eigen vectors of voxel covariance matrix.
void applyFilter(PointCloud &output) override
Filter cloud and initializes voxel structure.
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset.
int nearestKSearch(const PointCloud &cloud, int index, int k, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances) const
Search for the k-nearest occupied voxels for the given query point.
IndicesAllocator<> Indices
Type used for indices in PCL.
Eigen::Vector4i divb_mul_
void setCovEigValueInflationRatio(double min_covar_eigvalue_mult)
Set the minimum allowable ratio between eigenvalues to prevent singular covariance matrices...
Eigen::Vector4f leaf_size_
The size of a leaf.
int nr_points
Number of points contained by voxel.
std::map< std::size_t, Leaf > leaves_
Voxel structure containing all leaf nodes (includes voxels with less than a sufficient number of poin...
Eigen::Vector3d evals_
Eigen values of voxel covariance matrix.
int getVoxelAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get the voxel at p.
shared_ptr< const PointCloud< PointT > > ConstPtr
KdTreeFLANN< PointT > kdtree_
KdTree generated using voxel_centroids_ (used for searching).
std::string filter_name_
The filter name.
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier...
shared_ptr< const Filter< PointTarget > > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.
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 ...
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout_.
A searchable voxel structure containing the mean and covariance of the data.
const Leaf * LeafConstPtr
Const pointer to VoxelGridCovariance leaf structure.
Eigen::Matrix3d cov_
Voxel covariance matrix.
int getAllNeighborsAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get all 3x3x3 neighbor voxels of p (up to 27 voxels).
int radiusSearch(const PointT &point, double radius, Indices &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const override
Search for all the nearest neighbors of the query point in a given radius.
int nearestKSearch(const PointT &point, int k, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances) const
Search for the k-nearest occupied voxels for the given query point.
int radiusSearch(const PointCloud &cloud, int index, double radius, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
Search for all the nearest occupied voxels of the query point in a given radius.
const std::string & getClassName() const
Get a string representation of the name of this class.
typename PointCloud::ConstPtr PointCloudConstPtr
int nearestKSearch(const PointT &point, unsigned int k, Indices &k_indices, std::vector< float > &k_sqr_distances) const override
Search for k-nearest neighbors for the given query point.
int getPointCount() const
Get the number of points contained by this voxel.