Point Cloud Library (PCL)
1.11.1-dev
|
42 #include <pcl/filters/filter.h>
57 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
75 const std::string &distance_field_name,
float min_distance,
float max_distance,
76 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
82 inline Eigen::MatrixXi
85 Eigen::MatrixXi relative_coordinates (3, 13);
89 for (
int i = -1; i < 2; i++)
91 for (
int j = -1; j < 2; j++)
93 relative_coordinates (0, idx) = i;
94 relative_coordinates (1, idx) = j;
95 relative_coordinates (2, idx) = -1;
100 for (
int i = -1; i < 2; i++)
102 relative_coordinates (0, idx) = i;
103 relative_coordinates (1, idx) = -1;
104 relative_coordinates (2, idx) = 0;
108 relative_coordinates (0, idx) = -1;
109 relative_coordinates (1, idx) = 0;
110 relative_coordinates (2, idx) = 0;
112 return (relative_coordinates);
119 inline Eigen::MatrixXi
123 Eigen::MatrixXi relative_coordinates_all( 3, 26);
124 relative_coordinates_all.block<3, 13> (0, 0) = relative_coordinates;
125 relative_coordinates_all.block<3, 13> (0, 13) = -relative_coordinates;
126 return (relative_coordinates_all);
140 template <
typename Po
intT>
void
142 const std::string &distance_field_name,
float min_distance,
float max_distance,
143 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
157 template <
typename Po
intT>
void
160 const std::string &distance_field_name,
float min_distance,
float max_distance,
161 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
175 template <
typename Po
intT>
190 using Ptr = shared_ptr<VoxelGrid<PointT> >;
191 using ConstPtr = shared_ptr<const VoxelGrid<PointT> >;
248 inline Eigen::Vector3f
287 inline Eigen::Vector3i
293 inline Eigen::Vector3i
299 inline Eigen::Vector3i
305 inline Eigen::Vector3i
330 inline std::vector<int>
333 Eigen::Vector4i ijk (
static_cast<int> (std::floor (reference_point.x *
inverse_leaf_size_[0])),
336 Eigen::Array4i diff2min =
min_b_ - ijk;
337 Eigen::Array4i diff2max =
max_b_ - ijk;
338 std::vector<int> neighbors (relative_coordinates.cols());
339 for (Eigen::Index ni = 0; ni < relative_coordinates.cols (); ni++)
341 Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
343 if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
354 inline std::vector<int>
362 inline Eigen::Vector3i
376 int idx = ((Eigen::Vector4i() << ijk, 0).finished() -
min_b_).dot (
divb_mul_);
377 if (idx < 0 || idx >=
static_cast<int> (
leaf_layout_.size ()))
397 inline std::string
const
487 using FieldList =
typename pcl::traits::fieldList<PointT>::type;
521 leaf_size_ (
Eigen::Vector4f::Zero ()),
522 inverse_leaf_size_ (
Eigen::Array4f::Zero ()),
523 downsample_all_data_ (true),
524 save_leaf_layout_ (false),
525 min_b_ (
Eigen::Vector4i::Zero ()),
526 max_b_ (
Eigen::Vector4i::Zero ()),
527 div_b_ (
Eigen::Vector4i::Zero ()),
528 divb_mul_ (
Eigen::Vector4i::Zero ()),
529 filter_field_name_ (
""),
530 filter_limit_min_ (-FLT_MAX),
531 filter_limit_max_ (FLT_MAX),
532 filter_limit_negative_ (false),
533 min_points_per_voxel_ (0)
535 filter_name_ =
"VoxelGrid";
549 leaf_size_ = leaf_size;
551 if (leaf_size_[3] == 0)
554 inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
565 leaf_size_[0] = lx; leaf_size_[1] = ly; leaf_size_[2] = lz;
567 if (leaf_size_[3] == 0)
570 inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
574 inline Eigen::Vector3f
613 inline Eigen::Vector3i
619 inline Eigen::Vector3i
625 inline Eigen::Vector3i
631 inline Eigen::Vector3i
644 return (leaf_layout_.at ((Eigen::Vector4i (
static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
645 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
646 static_cast<int> (std::floor (z * inverse_leaf_size_[2])),
648 - min_b_).dot (divb_mul_)));
659 inline std::vector<int>
662 Eigen::Vector4i ijk (
static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
663 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
664 static_cast<int> (std::floor (z * inverse_leaf_size_[2])), 0);
665 Eigen::Array4i diff2min = min_b_ - ijk;
666 Eigen::Array4i diff2max = max_b_ - ijk;
667 std::vector<int> neighbors (relative_coordinates.cols());
668 for (Eigen::Index ni = 0; ni < relative_coordinates.cols (); ni++)
670 Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
672 if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
673 neighbors[ni] = leaf_layout_[((ijk + displacement - min_b_).dot (divb_mul_))];
688 inline std::vector<int>
689 getNeighborCentroidIndices (
float x,
float y,
float z,
const std::vector<Eigen::Vector3i, Eigen::aligned_allocator<Eigen::Vector3i> > &relative_coordinates)
const
691 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);
692 std::vector<int> neighbors;
693 neighbors.reserve (relative_coordinates.size ());
694 for (
const auto &relative_coordinate : relative_coordinates)
695 neighbors.push_back (leaf_layout_[(ijk + (Eigen::Vector4i() << relative_coordinate, 0).finished() - min_b_).dot (divb_mul_)]);
702 inline std::vector<int>
710 inline Eigen::Vector3i
713 return (Eigen::Vector3i (
static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
714 static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
715 static_cast<int> (std::floor (z * inverse_leaf_size_[2]))));
724 int idx = ((Eigen::Vector4i() << ijk, 0).finished() - min_b_).dot (divb_mul_);
725 if (idx < 0 || idx >=
static_cast<int> (leaf_layout_.size ()))
731 return (leaf_layout_[idx]);
741 filter_field_name_ = field_name;
745 inline std::string
const
748 return (filter_field_name_);
758 filter_limit_min_ = limit_min;
759 filter_limit_max_ = limit_max;
769 limit_min = filter_limit_min_;
770 limit_max = filter_limit_max_;
780 filter_limit_negative_ = limit_negative;
789 limit_negative = filter_limit_negative_;
798 return (filter_limit_negative_);
824 Eigen::Vector4i
min_b_, max_b_, div_b_, divb_mul_;
849 #ifdef PCL_NO_PRECOMPILE
850 #include <pcl/filters/impl/voxel_grid.hpp>
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
Eigen::Vector3i getMinBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
Eigen::Vector4f leaf_size_
The size of a leaf.
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier.
std::vector< int > getLeafLayout() const
Returns the layout of the leafs for fast access to cells relative to current position.
std::vector< int > getLeafLayout() const
Returns the layout of the leafs for fast access to cells relative to current position.
int getCentroidIndexAt(const Eigen::Vector3i &ijk) const
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
Eigen::Vector3i getMaxBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
shared_ptr< Filter< pcl::PointXYZRGBL > > Ptr
bool getDownsampleAllData() const
Get the state of the internal downsampling parameter (true if all fields need to be downsampled,...
typename PointCloud::ConstPtr PointCloudConstPtr
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
void applyFilter(PointCloud &output) override
Downsample a Point Cloud using a voxelized grid approach.
typename PointCloud::Ptr PointCloudPtr
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Eigen::Vector3i getDivisionMultiplier() const
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
Eigen::MatrixXi getHalfNeighborCellIndices()
Get the relative cell indices of the "upper half" 13 neighbors.
VoxelGrid()
Empty constructor.
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
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.
double filter_limit_max_
The maximum allowed filter value a point will be considered from.
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
int getCentroidIndexAt(const Eigen::Vector3i &ijk) const
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
int getCentroidIndex(const PointT &p) const
Returns the index in the resulting downsampled cloud of the specified point.
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
Eigen::Vector3i getMinBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
bool filter_limit_negative_
Set to true if we want to return the data outside (filter_limit_min_;filter_limit_max_).
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
typename pcl::traits::fieldList< pcl::PointXYZRGBL >::type FieldList
void getFilterLimitsNegative(bool &limit_negative) const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
void getFilterLimitsNegative(bool &limit_negative) const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
A point structure representing Euclidean xyz coordinates, and the RGB color.
void setMinimumPointsNumberPerVoxel(unsigned int min_points_per_voxel)
Set the minimum number of points required for a voxel to be used.
Eigen::MatrixXi getAllNeighborCellIndices()
Get the relative cell indices of all the 26 neighbors.
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout_.
bool getSaveLeafLayout() const
Returns true if leaf layout information will to be saved for later access.
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
const std::string getFilterFieldName() const
Get the name of the field used for filtering.
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
bool getSaveLeafLayout() const
Returns true if leaf layout information will to be saved for later access.
unsigned int getMinimumPointsNumberPerVoxel() const
Return the minimum number of points required for a voxel to be used.
Eigen::Vector3f getLeafSize() const
Get the voxel grid leaf size.
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Eigen::Vector3i getNrDivisions() const
Get the number of divisions along all 3 axes (after filtering is performed).
unsigned int getMinimumPointsNumberPerVoxel() const
Return the minimum number of points required for a voxel to be used.
double filter_limit_max_
The maximum allowed filter value a point will be considered from.
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
unsigned int min_points_per_voxel_
Minimum number of points per voxel for the centroid to be computed.
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
const std::string getFilterFieldName() const
Get the name of the field used for filtering.
std::string filter_field_name_
The desired user filter field name.
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).
double filter_limit_min_
The minimum allowed filter value a point will be considered from.
Eigen::Vector3i getDivisionMultiplier() const
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier.
Eigen::Vector3i getMaxBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
shared_ptr< const Filter< pcl::PointXYZRGBL > > ConstPtr
VoxelGrid()
Empty constructor.
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Filter represents the base filter class.
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...
IndicesAllocator<> Indices
Type used for indices in PCL.
Eigen::Vector4i divb_mul_
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
std::string filter_name_
The filter name.
shared_ptr< PointCloud< PointT > > Ptr
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::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
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...
Eigen::Vector4f leaf_size_
The size of a leaf.
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout.
bool filter_limit_negative_
Set to true if we want to return the data outside (filter_limit_min_;filter_limit_max_).
shared_ptr< const PointCloud< PointT > > ConstPtr
void setMinimumPointsNumberPerVoxel(unsigned int min_points_per_voxel)
Set the minimum number of points required for a voxel to be used.
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
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 setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
std::string filter_field_name_
The desired user filter field name.
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
Eigen::Vector3i getNrDivisions() const
Get the number of divisions along all 3 axes (after filtering is performed).
bool getDownsampleAllData() const
Get the state of the internal downsampling parameter (true if all fields need to be downsampled,...
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
unsigned int min_points_per_voxel_
Minimum number of points per voxel for the centroid to be computed.
double filter_limit_min_
The minimum allowed filter value a point will be considered from.
int getCentroidIndex(float x, float y, float z) const
Returns the index in the resulting downsampled cloud of the specified point.
Eigen::Vector3f getLeafSize() const
Get the voxel grid leaf size.