Point Cloud Library (PCL)
1.11.1-dev
|
40 #include <pcl/filters/voxel_grid.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> >;
220 if(min_points_per_voxel > 2)
226 PCL_WARN (
"%s: Covariance calculation requires at least 3 points, setting Min Point per Voxel to 3 ", this->
getClassName ().c_str ());
301 typename std::map<std::size_t, Leaf>::iterator leaf_iter =
leaves_.find (index);
302 if (leaf_iter !=
leaves_.end ())
326 typename std::map<std::size_t, Leaf>::iterator leaf_iter =
leaves_.find (idx);
327 if (leaf_iter !=
leaves_.end ())
352 typename std::map<std::size_t, Leaf>::iterator leaf_iter =
leaves_.find (idx);
353 if (leaf_iter !=
leaves_.end ())
371 getNeighborhoodAtPoint (
const Eigen::Matrix<int, 3, Eigen::Dynamic>& relative_coordinates,
const PointT& reference_point, std::vector<LeafConstPtr> &neighbors)
const;
412 inline const std::map<std::size_t, Leaf>&
445 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances)
const
452 PCL_WARN (
"%s: Not Searchable", this->
getClassName ().c_str ());
461 k_leaves.reserve (k);
462 for (
const auto &k_index : k_indices)
469 k_leaves.push_back(&voxel->second);
471 return k_leaves.size();
485 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances)
const
487 if (index >=
static_cast<int> (cloud.
size ()) || index < 0)
489 return (
nearestKSearch (cloud[index], k, k_leaves, k_sqr_distances));
504 std::vector<float> &k_sqr_distances,
unsigned int max_nn = 0)
const
511 PCL_WARN (
"%s: Not Searchable", this->
getClassName ().c_str ());
520 k_leaves.reserve (k);
521 for (
const auto &k_index : k_indices)
528 k_leaves.push_back(&voxel->second);
530 return k_leaves.size();
545 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances,
546 unsigned int max_nn = 0)
const
548 if (index >=
static_cast<int> (cloud.
size ()) || index < 0)
550 return (
radiusSearch (cloud[index], radius, k_leaves, k_sqr_distances, max_nn));
583 #ifdef PCL_NO_PRECOMPILE
584 #include <pcl/filters/impl/voxel_grid_covariance.hpp>
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
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.
VoxelGridCovariance()
Constructor.
shared_ptr< Filter< PointTarget > > Ptr
typename PointCloud::ConstPtr PointCloudConstPtr
typename PointCloud::Ptr PointCloudPtr
void applyFilter(PointCloud &output) override
Filter cloud and initializes voxel structure.
const Leaf * LeafConstPtr
Const pointer to VoxelGridCovariance leaf structure.
double getCovEigValueInflationRatio()
Get the minimum allowable ratio between eigenvalues to prevent singular covariance matrices.
Eigen::Matrix3d icov_
Inverse of voxel covariance matrix.
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
typename PointCloud::Ptr PointCloudPtr
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
typename pcl::traits::fieldList< PointTarget >::type FieldList
A point structure representing Euclidean xyz coordinates, and the RGB color.
LeafConstPtr getLeaf(PointT &p)
Get the voxel containing point p.
LeafConstPtr getLeaf(int index)
Get the voxel containing point p.
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout_.
int nearestKSearch(const PointT &point, unsigned int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const override
Search for k-nearest neighbors for the given query point.
PointCloudPtr voxel_centroids_
Point cloud containing centroids of voxels containing atleast minimum number of points.
Eigen::Vector3d getMean() const
Get the voxel centroid.
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.
void filter(bool searchable=false)
Initializes voxel structure.
std::vector< int > voxel_centroids_leaf_indices_
Indices of leaf structurs associated with each point in voxel_centroids_ (used for searching).
KdTreeFLANN< PointT > kdtree_
KdTree generated using voxel_centroids_ (used for searching).
Eigen::VectorXf centroid
Nd voxel centroid.
PointCloudPtr getCentroids()
Get a pointcloud containing the voxel centroids.
void getDisplayCloud(pcl::PointCloud< PointXYZ > &cell_cloud)
Get a cloud to visualize each voxels normal distribution.
Leaf * LeafPtr
Pointer to VoxelGridCovariance leaf structure.
const std::map< std::size_t, Leaf > & getLeaves()
Get the leaf structure map.
Eigen::Matrix3d getEvecs() const
Get the eigen vectors of the voxel covariance.
A searchable voxel strucure containing the mean and covariance of the data.
Eigen::Vector3d evals_
Eigen values of voxel covariance matrix.
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier.
Eigen::Vector3d getEvals() const
Get the eigen values of the voxel covariance.
Eigen::Matrix3d evecs_
Eigen vectors of voxel covariance matrix.
int getFaceNeighborsAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get the voxel at p and its facing voxels (up to 7 voxels).
Eigen::Vector3d mean_
3D voxel centroid
bool searchable_
Flag to determine if voxel structure is searchable.
Eigen::Matrix3d getCov() const
Get the voxel covariance.
shared_ptr< const Filter< PointTarget > > ConstPtr
int radiusSearch(const PointT &point, double radius, std::vector< int > &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.
double min_covar_eigvalue_mult_
Minimum allowable ratio between eigenvalues to prevent singular covariance matrices.
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.
LeafConstPtr getLeaf(Eigen::Vector3f &p)
Get the voxel containing point p.
IndicesAllocator<> Indices
Type used for indices in PCL.
Eigen::Vector4i divb_mul_
std::map< std::size_t, Leaf > leaves_
Voxel structure containing all leaf nodes (includes voxels with less than a sufficient number of poin...
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 ...
int getVoxelAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get the voxel at p.
int getMinPointPerVoxel()
Get the minimum number of points required for a cell to be used.
void filter(PointCloud &output, bool searchable=false)
Filter cloud and initializes voxel structure.
std::string filter_name_
The filter name.
shared_ptr< PointCloud< PointT > > Ptr
Eigen::Matrix3d getInverseCov() const
Get the inverse of the voxel covariance.
int getPointCount() const
Get the number of points contained by this voxel.
Eigen::Matrix3d cov_
Voxel covariance matrix.
const std::string & getClassName() const
Get a string representation of the name of this class.
int nr_points
Number of points contained by voxel.
Eigen::Vector4f leaf_size_
The size of a leaf.
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.
Simple structure to hold a centroid, covarince and the number of points in a leaf.
shared_ptr< const PointCloud< PointT > > ConstPtr
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.
int min_points_per_voxel_
Minimum points contained with in a voxel to allow it to be usable.
void setCovEigValueInflationRatio(double min_covar_eigvalue_mult)
Set the minimum allowable ratio between eigenvalues to prevent singular covariance matrices.
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr()) override
Provide a pointer to the input dataset.
int getAllNeighborsAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors) const
Get all 3x3x3 neighbor voxels of p (up to 27 voxels).