38 #ifndef PCL_VOXEL_GRID_COVARIANCE_H_
39 #define PCL_VOXEL_GRID_COVARIANCE_H_
41 #include <pcl/filters/boost.h>
42 #include <pcl/filters/voxel_grid.h>
44 #include <pcl/point_types.h>
45 #include <pcl/kdtree/kdtree_flann.h>
56 template<
typename Po
intT>
87 typedef boost::shared_ptr< VoxelGrid<PointT> >
Ptr;
88 typedef boost::shared_ptr< const VoxelGrid<PointT> >
ConstPtr;
100 mean_ (Eigen::Vector3d::Zero ()),
102 cov_ (Eigen::Matrix3d::Identity ()),
103 icov_ (Eigen::Matrix3d::Zero ()),
104 evecs_ (Eigen::Matrix3d::Identity ()),
105 evals_ (Eigen::Vector3d::Zero ())
224 if(min_points_per_voxel > 2)
230 PCL_WARN (
"%s: Covariance calculation requires at least 3 points, setting Min Point per Voxel to 3 ", this->
getClassName ().c_str ());
305 typename std::map<size_t, Leaf>::iterator leaf_iter =
leaves_.find (index);
306 if (leaf_iter !=
leaves_.end ())
331 typename std::map<size_t, Leaf>::iterator leaf_iter =
leaves_.find (idx);
332 if (leaf_iter !=
leaves_.end ())
351 int ijk1 =
static_cast<int> (floor (p[1] * inverse_leaf_size_[1]) -
min_b_[1]);
352 int ijk2 =
static_cast<int> (floor (p[2] * inverse_leaf_size_[2]) -
min_b_[2]);
358 typename std::map<size_t, Leaf>::iterator leaf_iter =
leaves_.find (idx);
359 if (leaf_iter !=
leaves_.end ())
382 inline const std::map<size_t, Leaf>&
415 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances)
422 PCL_WARN (
"%s: Not Searchable", this->
getClassName ().c_str ());
427 std::vector<int> k_indices;
431 k_leaves.reserve (k);
432 for (std::vector<int>::iterator iter = k_indices.begin (); iter != k_indices.end (); iter++)
449 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances)
451 if (index >= static_cast<int> (cloud.
points.size ()) || index < 0)
467 std::vector<float> &k_sqr_distances,
unsigned int max_nn = 0)
474 PCL_WARN (
"%s: Not Searchable", this->
getClassName ().c_str ());
479 std::vector<int> k_indices;
483 k_leaves.reserve (k);
484 for (std::vector<int>::iterator iter = k_indices.begin (); iter != k_indices.end (); iter++)
502 std::vector<LeafConstPtr> &k_leaves, std::vector<float> &k_sqr_distances,
503 unsigned int max_nn = 0)
505 if (index >= static_cast<int> (cloud.
points.size ()) || index < 0)
507 return (
radiusSearch (cloud.
points[index], radius, k_leaves, k_sqr_distances, max_nn));
540 #ifdef PCL_NO_PRECOMPILE
541 #include <pcl/filters/impl/voxel_grid_covariance.hpp>
544 #endif //#ifndef PCL_VOXEL_GRID_COVARIANCE_H_
void setInputCloud(const PointCloudConstPtr &cloud, const IndicesConstPtr &indices=IndicesConstPtr())
Provide a pointer to the input dataset.
int min_points_per_voxel_
Minimum points contained with in a voxel to allow it to be useable.
Eigen::Matrix3d icov_
Inverse of voxel covariance matrix.
int radiusSearch(const PointT &point, double radius, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances, unsigned int max_nn=0) const
Search for all the nearest neighbors of the query point in a given radius.
boost::shared_ptr< VoxelGrid< PointT > > Ptr
Eigen::Matrix3d getCov() const
Get the voxel covariance.
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 ...
void applyFilter(PointCloud &output)
Filter cloud and initializes voxel structure.
PointCloud::ConstPtr PointCloudConstPtr
const std::map< size_t, Leaf > & getLeaves()
Get the leaf structure map.
PointCloud::Ptr PointCloudPtr
bool searchable_
Flag to determine if voxel structure is searchable.
void setCovEigValueInflationRatio(double min_covar_eigvalue_mult)
Set the minimum allowable ratio between eigenvalues to prevent singular covariance matrices...
LeafConstPtr getLeaf(int index)
Get the voxel containing point p.
std::string filter_name_
The filter name.
Eigen::VectorXf centroid
Nd voxel centroid.
boost::shared_ptr< const VoxelGrid< PointT > > ConstPtr
A searchable voxel strucure containing the mean and covariance of the data.
Eigen::Matrix3d getEvecs() const
Get the eigen vectors of the voxel covariance.
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout_.
Eigen::Matrix3d evecs_
Eigen vectors of voxel covariance matrix.
Eigen::Vector3d getMean() const
Get the voxel centroid.
Eigen::Vector3d getEvals() const
Get the eigen values of the voxel covariance.
int nearestKSearch(const PointT &point, int k, std::vector< int > &k_indices, std::vector< float > &k_sqr_distances) const
Search for k-nearest neighbors for the given query point.
int radiusSearch(const PointT &point, double radius, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances, unsigned int max_nn=0)
Search for all the nearest occupied voxels of the query point in a given radius.
Filter< PointT >::PointCloud PointCloud
Eigen::Vector3d mean_
3D voxel centroid
Eigen::Matrix3d cov_
Voxel covariance matrix.
PointCloud::Ptr PointCloudPtr
int nr_points
Number of points contained by voxel.
double getCovEigValueInflationRatio()
Get the minimum allowable ratio between eigenvalues to prevent singular covariance matrices...
Eigen::Vector4i divb_mul_
LeafConstPtr getLeaf(Eigen::Vector3f &p)
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::Matrix3d getInverseCov() const
Get the inverse of the voxel covariance.
int nearestKSearch(const PointT &point, int k, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances)
Search for the k-nearest occupied voxels for the given query point.
boost::shared_ptr< PointCloud< PointT > > Ptr
void filter(PointCloud &output, bool searchable=false)
Filter cloud and initializes voxel structure.
KdTreeFLANN< PointT > kdtree_
KdTree generated using voxel_centroids_ (used for searching).
LeafConstPtr getLeaf(PointT &p)
Get the voxel containing point p.
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)
Search for all the nearest occupied voxels of the query point in a given radius.
const Leaf * LeafConstPtr
Const pointer to VoxelGridCovariance leaf structure.
void filter(bool searchable=false)
Initializes voxel structure.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
std::map< size_t, Leaf > leaves_
Voxel structure containing all leaf nodes (includes voxels with less than a sufficient number of poin...
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
double min_covar_eigvalue_mult_
Minimum allowable ratio between eigenvalues to prevent singular covariance matrices.
Eigen::Vector3d evals_
Eigen values of voxel covariance matrix.
int getNeighborhoodAtPoint(const PointT &reference_point, std::vector< LeafConstPtr > &neighbors)
Get the voxels surrounding point p, not including the voxel contating point p.
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
Simple structure to hold a centroid, covarince and the number of points in a leaf.
Eigen::Vector4f leaf_size_
The size of a leaf.
VoxelGridCovariance()
Constructor.
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
void getDisplayCloud(pcl::PointCloud< PointXYZ > &cell_cloud)
Get a cloud to visualize each voxels normal distribution.
int nearestKSearch(const PointCloud &cloud, int index, int k, std::vector< LeafConstPtr > &k_leaves, std::vector< float > &k_sqr_distances)
Search for the k-nearest occupied voxels for the given query point.
pcl::traits::fieldList< PointT >::type FieldList
std::vector< int > voxel_centroids_leaf_indices_
Indices of leaf structurs associated with each point in voxel_centroids_ (used for searching)...
PointCloudPtr voxel_centroids_
Point cloud containing centroids of voxels containing atleast minimum number of points.
Leaf * LeafPtr
Pointer to VoxelGridCovariance leaf structure.
PointCloudPtr getCentroids()
Get a pointcloud containing the voxel centroids.
A point structure representing Euclidean xyz coordinates, and the RGB color.
int getMinPointPerVoxel()
Get the minimum number of points required for a cell to be used.
int getPointCount() const
Get the number of points contained by this voxel.
const std::string & getClassName() const
Get a string representation of the name of this class.
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier...