42 #include <pcl/filters/filter.h>
57 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
70 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
88 const std::string &distance_field_name,
float min_distance,
float max_distance,
89 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
108 const std::string &distance_field_name,
float min_distance,
float max_distance,
109 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
115 inline Eigen::MatrixXi
118 Eigen::MatrixXi relative_coordinates (3, 13);
122 for (
int i = -1; i < 2; i++)
124 for (
int j = -1; j < 2; j++)
126 relative_coordinates (0, idx) = i;
127 relative_coordinates (1, idx) = j;
128 relative_coordinates (2, idx) = -1;
133 for (
int i = -1; i < 2; i++)
135 relative_coordinates (0, idx) = i;
136 relative_coordinates (1, idx) = -1;
137 relative_coordinates (2, idx) = 0;
141 relative_coordinates (0, idx) = -1;
142 relative_coordinates (1, idx) = 0;
143 relative_coordinates (2, idx) = 0;
145 return (relative_coordinates);
152 inline Eigen::MatrixXi
156 Eigen::MatrixXi relative_coordinates_all( 3, 26);
157 relative_coordinates_all.block<3, 13> (0, 0) = relative_coordinates;
158 relative_coordinates_all.block<3, 13> (0, 13) = -relative_coordinates;
159 return (relative_coordinates_all);
173 template <
typename Po
intT>
void
175 const std::string &distance_field_name,
float min_distance,
float max_distance,
176 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
190 template <
typename Po
intT>
void
193 const std::string &distance_field_name,
float min_distance,
float max_distance,
194 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
208 template <
typename Po
intT>
223 using Ptr = shared_ptr<VoxelGrid<PointT> >;
224 using ConstPtr = shared_ptr<const VoxelGrid<PointT> >;
274 inline Eigen::Vector3f
313 inline Eigen::Vector3i
319 inline Eigen::Vector3i
325 inline Eigen::Vector3i
331 inline Eigen::Vector3i
356 inline std::vector<int>
359 Eigen::Vector4i ijk (static_cast<int> (std::floor (reference_point.x *
inverse_leaf_size_[0])),
362 Eigen::Array4i diff2min =
min_b_ - ijk;
363 Eigen::Array4i diff2max =
max_b_ - ijk;
364 std::vector<int> neighbors (relative_coordinates.cols());
365 for (Eigen::Index ni = 0; ni < relative_coordinates.cols (); ni++)
367 Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
369 if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
380 inline std::vector<int>
388 inline Eigen::Vector3i
392 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
393 static_cast<int> (std::floor (z * inverse_leaf_size_[2]))};
402 int idx = ((Eigen::Vector4i() << ijk, 0).finished() -
min_b_).dot (
divb_mul_);
403 if (idx < 0 || idx >= static_cast<int> (
leaf_layout_.size ()))
423 inline std::string
const
465 PCL_DEPRECATED(1, 16,
"use bool getFilterLimitsNegative() instead")
515 using FieldList =
typename pcl::traits::fieldList<PointT>::type;
594 inline Eigen::Vector3f
633 inline Eigen::Vector3i
639 inline Eigen::Vector3i
645 inline Eigen::Vector3i
651 inline Eigen::Vector3i
665 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
666 static_cast<int> (std::floor (z * inverse_leaf_size_[2])),
679 inline std::vector<int>
683 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
684 static_cast<int> (std::floor (z * inverse_leaf_size_[2])), 0);
685 Eigen::Array4i diff2min =
min_b_ - ijk;
686 Eigen::Array4i diff2max =
max_b_ - ijk;
687 std::vector<int> neighbors (relative_coordinates.cols());
688 for (Eigen::Index ni = 0; ni < relative_coordinates.cols (); ni++)
690 Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
692 if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
708 inline std::vector<int>
709 getNeighborCentroidIndices (
float x,
float y,
float z,
const std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > &relative_coordinates)
const
711 Eigen::Vector4i ijk (static_cast<int> (std::floor (x *
inverse_leaf_size_[0])), static_cast<int> (std::floor (y * inverse_leaf_size_[1])), static_cast<int> (std::floor (z * inverse_leaf_size_[2])), 0);
712 std::vector<int> neighbors;
713 neighbors.reserve (relative_coordinates.size ());
714 for (
const auto &relative_coordinate : relative_coordinates)
722 inline std::vector<int>
730 inline Eigen::Vector3i
734 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
735 static_cast<int> (std::floor (z * inverse_leaf_size_[2]))};
744 int idx = ((Eigen::Vector4i() << ijk, 0).finished() -
min_b_).dot (
divb_mul_);
745 if (idx < 0 || idx >= static_cast<int> (
leaf_layout_.size ()))
765 inline std::string
const
807 PCL_DEPRECATED(1, 16,
"use bool getFilterLimitsNegative() instead")
871 #ifdef PCL_NO_PRECOMPILE
872 #include <pcl/filters/impl/voxel_grid.hpp>
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
int getCentroidIndexAt(const Eigen::Vector3i &ijk) const
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
unsigned int min_points_per_voxel_
Minimum number of points per voxel for the centroid to be computed.
Eigen::Vector3i getDivisionMultiplier() const
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
shared_ptr< PointCloud< PointT > > Ptr
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min...
std::string const getFilterFieldName() const
Get the name of the field used for filtering.
Eigen::Vector3i getNrDivisions() const
Get the number of divisions along all 3 axes (after filtering is performed).
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
Eigen::Vector3i getGridCoordinates(float x, float y, float z) const
Returns the corresponding (i,j,k) coordinates in the grid of point (x,y,z).
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
unsigned int getMinimumPointsNumberPerVoxel() const
Return the minimum number of points required for a voxel to be used.
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
int getCentroidIndexAt(const Eigen::Vector3i &ijk) const
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
int getCentroidIndex(const PointT &p) const
Returns the index in the resulting downsampled cloud of the specified point.
Eigen::Vector4f leaf_size_
The size of a leaf.
Eigen::Vector3i getMinBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
bool getDownsampleAllData() const
Get the state of the internal downsampling parameter (true if all fields need to be downsampled...
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier...
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
std::string const getFilterFieldName() const
Get the name of the field used for filtering.
VoxelGrid()
Empty constructor.
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
std::vector< int > getNeighborCentroidIndices(float x, float y, float z, const std::vector< Eigen::Vector3i, Eigen::aligned_allocator< Eigen::Vector3i > > &relative_coordinates) const
Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinate...
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
typename pcl::traits::fieldList< pcl::PointXYZRGBL >::type FieldList
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
bool getDownsampleAllData() const
Get the state of the internal downsampling parameter (true if all fields need to be downsampled...
Eigen::Vector3i getNrDivisions() const
Get the number of divisions along all 3 axes (after filtering is performed).
PCL_MAKE_ALIGNED_OPERATOR_NEW VoxelGrid()
Empty constructor.
std::string filter_field_name_
The desired user filter field name.
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
std::vector< int > getNeighborCentroidIndices(float x, float y, float z, const Eigen::MatrixXi &relative_coordinates) const
Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinate...
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
unsigned int getMinimumPointsNumberPerVoxel() const
Return the minimum number of points required for a voxel to be used.
Eigen::Vector3i getDivisionMultiplier() const
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
Eigen::Vector3i getMaxBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
Eigen::Vector3i getGridCoordinates(float x, float y, float z) const
Returns the corresponding (i,j,k) coordinates in the grid of point (x,y,z).
std::vector< int > getLeafLayout() const
Returns the layout of the leafs for fast access to cells relative to current position.
Filter represents the base filter class.
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
Eigen::Vector3i getMaxBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
void setMinimumPointsNumberPerVoxel(unsigned int min_points_per_voxel)
Set the minimum number of points required for a voxel to be used.
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
shared_ptr< Filter< pcl::PointXYZRGBL > > Ptr
Eigen::Vector3f getLeafSize() const
Get the voxel grid leaf size.
bool getSaveLeafLayout() const
Returns true if leaf layout information will to be saved for later access.
void getMinMax3D(const pcl::PointCloud< PointT > &cloud, PointT &min_pt, PointT &max_pt)
Get the minimum and maximum values on each of the 3 (x-y-z) dimensions in a given pointcloud...
Eigen::MatrixXi getHalfNeighborCellIndices()
Get the relative cell indices of the "upper half" 13 neighbors.
typename PointCloud::Ptr PointCloudPtr
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min...
std::vector< int > getLeafLayout() const
Returns the layout of the leafs for fast access to cells relative to current position.
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
IndicesAllocator<> Indices
Type used for indices in PCL.
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
Eigen::Vector4i divb_mul_
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void applyFilter(PointCloud &output) override
Downsample a Point Cloud using a voxelized grid approach.
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
Eigen::Vector4f leaf_size_
The size of a leaf.
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
void setMinimumPointsNumberPerVoxel(unsigned int min_points_per_voxel)
Set the minimum number of points required for a voxel to be used.
std::string filter_field_name_
The desired user filter field name.
bool filter_limit_negative_
Set to true if we want to return the data outside (filter_limit_min_;filter_limit_max_).
int getCentroidIndex(float x, float y, float z) const
Returns the index in the resulting downsampled cloud of the specified point.
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
std::vector< int > getNeighborCentroidIndices(const PointT &reference_point, const Eigen::MatrixXi &relative_coordinates) const
Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinate...
Eigen::MatrixXi getAllNeighborCellIndices()
Get the relative cell indices of all the 26 neighbors.
bool getSaveLeafLayout() const
Returns true if leaf layout information will to be saved for later access.
Eigen::Vector3f getLeafSize() const
Get the voxel grid leaf size.
Eigen::Vector3i getMinBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
~VoxelGrid() override=default
Destructor.
double filter_limit_max_
The maximum allowed filter value a point will be considered from.
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< pcl::PointXYZRGBL > > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout_.
double filter_limit_min_
The minimum allowed filter value a point will be considered from.
PCLPointCloud2::Ptr PCLPointCloud2Ptr
typename PointCloud::ConstPtr PointCloudConstPtr
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.