40 #ifndef PCL_FILTERS_VOXEL_GRID_MAP_H_
41 #define PCL_FILTERS_VOXEL_GRID_MAP_H_
43 #include <pcl/filters/boost.h>
44 #include <pcl/filters/filter.h>
59 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
77 const std::string &distance_field_name,
float min_distance,
float max_distance,
78 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
84 inline Eigen::MatrixXi
87 Eigen::MatrixXi relative_coordinates (3, 13);
91 for (
int i = -1; i < 2; i++)
93 for (
int j = -1; j < 2; j++)
95 relative_coordinates (0, idx) = i;
96 relative_coordinates (1, idx) = j;
97 relative_coordinates (2, idx) = -1;
102 for (
int i = -1; i < 2; i++)
104 relative_coordinates (0, idx) = i;
105 relative_coordinates (1, idx) = -1;
106 relative_coordinates (2, idx) = 0;
110 relative_coordinates (0, idx) = -1;
111 relative_coordinates (1, idx) = 0;
112 relative_coordinates (2, idx) = 0;
114 return (relative_coordinates);
121 inline Eigen::MatrixXi
125 Eigen::MatrixXi relative_coordinates_all( 3, 26);
126 relative_coordinates_all.block<3, 13> (0, 0) = relative_coordinates;
127 relative_coordinates_all.block<3, 13> (0, 13) = -relative_coordinates;
128 return (relative_coordinates_all);
142 template <
typename Po
intT>
void
144 const std::string &distance_field_name,
float min_distance,
float max_distance,
145 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
159 template <
typename Po
intT>
void
161 const std::vector<int> &indices,
162 const std::string &distance_field_name,
float min_distance,
float max_distance,
163 Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt,
bool limit_negative =
false);
177 template <
typename Po
intT>
189 typedef boost::shared_ptr< VoxelGrid<PointT> >
Ptr;
190 typedef boost::shared_ptr< const VoxelGrid<PointT> >
ConstPtr;
201 min_b_ (Eigen::Vector4i::Zero ()),
202 max_b_ (Eigen::Vector4i::Zero ()),
203 div_b_ (Eigen::Vector4i::Zero ()),
249 inline Eigen::Vector3f
277 inline Eigen::Vector3i
283 inline Eigen::Vector3i
289 inline Eigen::Vector3i
295 inline Eigen::Vector3i
320 inline std::vector<int>
323 Eigen::Vector4i ijk (static_cast<int> (floor (reference_point.x *
inverse_leaf_size_[0])),
326 Eigen::Array4i diff2min =
min_b_ - ijk;
327 Eigen::Array4i diff2max =
max_b_ - ijk;
328 std::vector<int> neighbors (relative_coordinates.cols());
329 for (
int ni = 0; ni < relative_coordinates.cols (); ni++)
331 Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
333 if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
344 inline std::vector<int>
352 inline Eigen::Vector3i
356 static_cast<int> (floor (y * inverse_leaf_size_[1])),
357 static_cast<int> (floor (z * inverse_leaf_size_[2]))));
366 int idx = ((Eigen::Vector4i() << ijk, 0).finished() -
min_b_).dot (
divb_mul_);
367 if (idx < 0 || idx >= static_cast<int> (
leaf_layout_.size ()))
387 inline std::string
const
508 leaf_size_ (Eigen::Vector4f::Zero ()),
509 inverse_leaf_size_ (Eigen::Array4f::Zero ()),
510 downsample_all_data_ (true),
511 save_leaf_layout_ (false),
513 min_b_ (Eigen::Vector4i::Zero ()),
514 max_b_ (Eigen::Vector4i::Zero ()),
515 div_b_ (Eigen::Vector4i::Zero ()),
516 divb_mul_ (Eigen::Vector4i::Zero ()),
517 filter_field_name_ (
""),
518 filter_limit_min_ (-FLT_MAX),
519 filter_limit_max_ (FLT_MAX),
520 filter_limit_negative_ (false)
522 filter_name_ =
"VoxelGrid";
536 leaf_size_ = leaf_size;
538 if (leaf_size_[3] == 0)
541 inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
552 leaf_size_[0] = lx; leaf_size_[1] = ly; leaf_size_[2] = lz;
554 if (leaf_size_[3] == 0)
557 inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
561 inline Eigen::Vector3f
589 inline Eigen::Vector3i
595 inline Eigen::Vector3i
601 inline Eigen::Vector3i
607 inline Eigen::Vector3i
620 return (leaf_layout_.at ((Eigen::Vector4i (static_cast<int> (floor (x * inverse_leaf_size_[0])),
621 static_cast<int> (floor (y * inverse_leaf_size_[1])),
622 static_cast<int> (floor (z * inverse_leaf_size_[2])),
624 - min_b_).dot (divb_mul_)));
635 inline std::vector<int>
638 Eigen::Vector4i ijk (static_cast<int> (floor (x * inverse_leaf_size_[0])),
639 static_cast<int> (floor (y * inverse_leaf_size_[1])),
640 static_cast<int> (floor (z * inverse_leaf_size_[2])), 0);
641 Eigen::Array4i diff2min = min_b_ - ijk;
642 Eigen::Array4i diff2max = max_b_ - ijk;
643 std::vector<int> neighbors (relative_coordinates.cols());
644 for (
int ni = 0; ni < relative_coordinates.cols (); ni++)
646 Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
648 if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
649 neighbors[ni] = leaf_layout_[((ijk + displacement - min_b_).dot (divb_mul_))];
664 inline std::vector<int>
667 Eigen::Vector4i ijk (static_cast<int> (floorf (x * inverse_leaf_size_[0])), static_cast<int> (floorf (y * inverse_leaf_size_[1])), static_cast<int> (floorf (z * inverse_leaf_size_[2])), 0);
668 std::vector<int> neighbors;
669 neighbors.reserve (relative_coordinates.size ());
670 for (std::vector<Eigen::Vector3i>::const_iterator it = relative_coordinates.begin (); it != relative_coordinates.end (); it++)
671 neighbors.push_back (leaf_layout_[(ijk + (Eigen::Vector4i() << *it, 0).finished() - min_b_).dot (divb_mul_)]);
678 inline std::vector<int>
686 inline Eigen::Vector3i
689 return (Eigen::Vector3i (static_cast<int> (floor (x * inverse_leaf_size_[0])),
690 static_cast<int> (floor (y * inverse_leaf_size_[1])),
691 static_cast<int> (floor (z * inverse_leaf_size_[2]))));
700 int idx = ((Eigen::Vector4i() << ijk, 0).finished() - min_b_).dot (divb_mul_);
701 if (idx < 0 || idx >= static_cast<int> (leaf_layout_.size ()))
707 return (leaf_layout_[idx]);
717 filter_field_name_ = field_name;
721 inline std::string
const
724 return (filter_field_name_);
734 filter_limit_min_ = limit_min;
735 filter_limit_max_ = limit_max;
745 limit_min = filter_limit_min_;
746 limit_max = filter_limit_max_;
756 filter_limit_negative_ = limit_negative;
765 limit_negative = filter_limit_negative_;
774 return (filter_limit_negative_);
800 Eigen::Vector4i
min_b_, max_b_, div_b_, divb_mul_;
822 #ifdef PCL_NO_PRECOMPILE
823 #include <pcl/filters/impl/voxel_grid.hpp>
826 #endif //#ifndef PCL_FILTERS_VOXEL_GRID_MAP_H_
PointCloud::Ptr PointCloudPtr
Eigen::Vector3i getGridCoordinates(float x, float y, float z)
Returns the corresponding (i,j,k) coordinates in the grid of point (x,y,z).
void applyFilter(PointCloud &output)
Downsample a Point Cloud using a voxelized grid approach.
Eigen::Vector3f getLeafSize()
Get the voxel grid leaf size.
bool getDownsampleAllData()
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.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
void getFilterLimitsNegative(bool &limit_negative)
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min...
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
std::vector< int > getNeighborCentroidIndices(float x, float y, float z, const Eigen::MatrixXi &relative_coordinates)
Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinate...
Eigen::Vector3i getMaxBoxCoordinates()
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.
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
Eigen::Vector3i getNrDivisions()
Get the number of divisions along all 3 axes (after filtering is performed).
boost::shared_ptr< PointCloud< PointT > > Ptr
bool getDownsampleAllData()
Get the state of the internal downsampling parameter (true if all fields need to be downsampled...
bool getFilterLimitsNegative()
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
Eigen::Vector4f leaf_size_
The size of a leaf.
boost::shared_ptr< VoxelGrid< PointT > > Ptr
pcl::traits::fieldList< PointT >::type FieldList
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier...
boost::shared_ptr< ::pcl::PCLPointCloud2 const > PCLPointCloud2ConstPtr
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
VoxelGrid()
Empty constructor.
void getFilterLimits(double &limit_min, double &limit_max)
Get the field filter limits (min/max) set by the user.
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
std::vector< int > getNeighborCentroidIndices(const PointT &reference_point, const Eigen::MatrixXi &relative_coordinates)
Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinate...
Eigen::Vector3i getNrDivisions()
Get the number of divisions along all 3 axes (after filtering is performed).
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data...
std::vector< int > getLeafLayout()
Returns the layout of the leafs for fast access to cells relative to current position.
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
bool getSaveLeafLayout()
Returns true if leaf layout information will to be saved for later access.
Eigen::Vector3i getDivisionMultiplier()
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
std::string filter_field_name_
The desired user filter field name.
std::string const getFilterFieldName()
Get the name of the field used for filtering.
bool filter_limit_negative_
Set to true if we want to return the data outside (filter_limit_min_;filter_limit_max_).
Eigen::Vector3i getDivisionMultiplier()
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
virtual ~VoxelGrid()
Destructor.
std::string const getFilterFieldName()
Get the name of the field used for filtering.
int getCentroidIndex(float x, float y, float z)
Returns the index in the resulting downsampled cloud of the specified point.
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
Eigen::Vector3i getMinBoxCoordinates()
Get the minimum coordinates of the bounding box (after filtering is performed).
Eigen::Vector3i getMinBoxCoordinates()
Get the minimum coordinates of the bounding box (after filtering is performed).
Filter represents the base filter class.
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
int getCentroidIndexAt(const Eigen::Vector3i &ijk)
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
std::vector< int > getLeafLayout()
Returns the layout of the leafs for fast access to cells relative to current position.
Eigen::Vector3i getGridCoordinates(float x, float y, float z)
Returns the corresponding (i,j,k) coordinates in the grid of point (x,y,z).
int getCentroidIndex(const PointT &p)
Returns the index in the resulting downsampled cloud of the specified point.
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.
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min...
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.
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
Eigen::Vector3i getMaxBoxCoordinates()
Get the minimum coordinates of the bounding box (after filtering is performed).
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
double filter_limit_max_
The maximum allowed filter value a point will be considered from.
bool getFilterLimitsNegative()
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
Eigen::Vector4i divb_mul_
std::vector< int > getNeighborCentroidIndices(float x, float y, float z, const std::vector< Eigen::Vector3i > &relative_coordinates)
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.
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
std::string filter_field_name_
The desired user filter field name.
VoxelGrid()
Empty constructor.
bool filter_limit_negative_
Set to true if we want to return the data outside (filter_limit_min_;filter_limit_max_).
void getFilterLimitsNegative(bool &limit_negative)
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false)...
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout.
boost::shared_ptr< const VoxelGrid< PointT > > ConstPtr
Eigen::MatrixXi getAllNeighborCellIndices()
Get the relative cell indices of all the 26 neighbors.
double filter_limit_min_
The minimum allowed filter value a point will be considered from.
double filter_limit_max_
The maximum allowed filter value a point will be considered from.
PointCloud::ConstPtr PointCloudConstPtr
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...
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.
int getCentroidIndexAt(const Eigen::Vector3i &ijk)
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
virtual ~VoxelGrid()
Destructor.
bool getSaveLeafLayout()
Returns true if leaf layout information will to be saved for later access.
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
Filter< PointT >::PointCloud PointCloud
void getFilterLimits(double &limit_min, double &limit_max)
Get the field filter limits (min/max) set by the user.
Eigen::Vector3f getLeafSize()
Get the voxel grid leaf size.