Point Cloud Library (PCL)  1.14.1-dev
voxel_grid.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/filters/filter.h>
43 #include <limits>
44 
45 namespace pcl
46 {
47  /** \brief Obtain the maximum and minimum points in 3D from a given point cloud.
48  * \param[in] cloud the pointer to a pcl::PCLPointCloud2 dataset
49  * \param[in] x_idx the index of the X channel
50  * \param[in] y_idx the index of the Y channel
51  * \param[in] z_idx the index of the Z channel
52  * \param[out] min_pt the minimum data point
53  * \param[out] max_pt the maximum data point
54  */
55  PCL_EXPORTS void
56  getMinMax3D (const pcl::PCLPointCloud2ConstPtr &cloud, int x_idx, int y_idx, int z_idx,
57  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
58 
59  /** \brief Obtain the maximum and minimum points in 3D from a given point cloud.
60  * \param[in] cloud the pointer to a pcl::PCLPointCloud2 dataset
61  * \param[in] indices the point cloud indices that need to be considered
62  * \param[in] x_idx the index of the X channel
63  * \param[in] y_idx the index of the Y channel
64  * \param[in] z_idx the index of the Z channel
65  * \param[out] min_pt the minimum data point
66  * \param[out] max_pt the maximum data point
67  */
68  PCL_EXPORTS void
69  getMinMax3D (const pcl::PCLPointCloud2ConstPtr &cloud, const Indices &indices, int x_idx, int y_idx, int z_idx,
70  Eigen::Vector4f &min_pt, Eigen::Vector4f &max_pt);
71 
72  /** \brief Obtain the maximum and minimum points in 3D from a given point cloud.
73  * \note Performs internal data filtering as well.
74  * \param[in] cloud the pointer to a pcl::PCLPointCloud2 dataset
75  * \param[in] x_idx the index of the X channel
76  * \param[in] y_idx the index of the Y channel
77  * \param[in] z_idx the index of the Z channel
78  * \param[in] distance_field_name the name of the dimension to filter data along to
79  * \param[in] min_distance the minimum acceptable value in \a distance_field_name data
80  * \param[in] max_distance the maximum acceptable value in \a distance_field_name data
81  * \param[out] min_pt the minimum data point
82  * \param[out] max_pt the maximum data point
83  * \param[in] limit_negative \b false if data \b inside of the [min_distance; max_distance] interval should be
84  * considered, \b true otherwise.
85  */
86  PCL_EXPORTS void
87  getMinMax3D (const pcl::PCLPointCloud2ConstPtr &cloud, int x_idx, int y_idx, int z_idx,
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);
90 
91  /** \brief Obtain the maximum and minimum points in 3D from a given point cloud.
92  * \note Performs internal data filtering as well.
93  * \param[in] cloud the pointer to a pcl::PCLPointCloud2 dataset
94  * \param[in] indices the point cloud indices that need to be considered
95  * \param[in] x_idx the index of the X channel
96  * \param[in] y_idx the index of the Y channel
97  * \param[in] z_idx the index of the Z channel
98  * \param[in] distance_field_name the name of the dimension to filter data along to
99  * \param[in] min_distance the minimum acceptable value in \a distance_field_name data
100  * \param[in] max_distance the maximum acceptable value in \a distance_field_name data
101  * \param[out] min_pt the minimum data point
102  * \param[out] max_pt the maximum data point
103  * \param[in] limit_negative \b false if data \b inside of the [min_distance; max_distance] interval should be
104  * considered, \b true otherwise.
105  */
106  PCL_EXPORTS void
107  getMinMax3D (const pcl::PCLPointCloud2ConstPtr &cloud, const Indices &indices, int x_idx, int y_idx, int z_idx,
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);
110 
111  /** \brief Get the relative cell indices of the "upper half" 13 neighbors.
112  * \note Useful in combination with getNeighborCentroidIndices() from \ref VoxelGrid
113  * \ingroup filters
114  */
115  inline Eigen::MatrixXi
117  {
118  Eigen::MatrixXi relative_coordinates (3, 13);
119  int idx = 0;
120 
121  // 0 - 8
122  for (int i = -1; i < 2; i++)
123  {
124  for (int j = -1; j < 2; j++)
125  {
126  relative_coordinates (0, idx) = i;
127  relative_coordinates (1, idx) = j;
128  relative_coordinates (2, idx) = -1;
129  idx++;
130  }
131  }
132  // 9 - 11
133  for (int i = -1; i < 2; i++)
134  {
135  relative_coordinates (0, idx) = i;
136  relative_coordinates (1, idx) = -1;
137  relative_coordinates (2, idx) = 0;
138  idx++;
139  }
140  // 12
141  relative_coordinates (0, idx) = -1;
142  relative_coordinates (1, idx) = 0;
143  relative_coordinates (2, idx) = 0;
144 
145  return (relative_coordinates);
146  }
147 
148  /** \brief Get the relative cell indices of all the 26 neighbors.
149  * \note Useful in combination with getNeighborCentroidIndices() from \ref VoxelGrid
150  * \ingroup filters
151  */
152  inline Eigen::MatrixXi
154  {
155  Eigen::MatrixXi relative_coordinates = getHalfNeighborCellIndices ();
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);
160  }
161 
162  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions
163  * in a given pointcloud, without considering points outside of a distance threshold from the laser origin
164  * \param[in] cloud the point cloud data message
165  * \param[in] distance_field_name the field name that contains the distance values
166  * \param[in] min_distance the minimum distance a point will be considered from
167  * \param[in] max_distance the maximum distance a point will be considered to
168  * \param[out] min_pt the resultant minimum bounds
169  * \param[out] max_pt the resultant maximum bounds
170  * \param[in] limit_negative if set to true, then all points outside of the interval (min_distance;max_distace) are considered
171  * \ingroup filters
172  */
173  template <typename PointT> void
174  getMinMax3D (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
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);
177 
178  /** \brief Get the minimum and maximum values on each of the 3 (x-y-z) dimensions
179  * in a given pointcloud, without considering points outside of a distance threshold from the laser origin
180  * \param[in] cloud the point cloud data message
181  * \param[in] indices the vector of indices to use
182  * \param[in] distance_field_name the field name that contains the distance values
183  * \param[in] min_distance the minimum distance a point will be considered from
184  * \param[in] max_distance the maximum distance a point will be considered to
185  * \param[out] min_pt the resultant minimum bounds
186  * \param[out] max_pt the resultant maximum bounds
187  * \param[in] limit_negative if set to true, then all points outside of the interval (min_distance;max_distace) are considered
188  * \ingroup filters
189  */
190  template <typename PointT> void
191  getMinMax3D (const typename pcl::PointCloud<PointT>::ConstPtr &cloud,
192  const Indices &indices,
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);
195 
196  /** \brief VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
197  *
198  * The VoxelGrid class creates a *3D voxel grid* (think about a voxel
199  * grid as a set of tiny 3D boxes in space) over the input point cloud data.
200  * Then, in each *voxel* (i.e., 3D box), all the points present will be
201  * approximated (i.e., *downsampled*) with their centroid. This approach is
202  * a bit slower than approximating them with the center of the voxel, but it
203  * represents the underlying surface more accurately.
204  *
205  * \author Radu B. Rusu, Bastian Steder
206  * \ingroup filters
207  */
208  template <typename PointT>
209  class VoxelGrid: public Filter<PointT>
210  {
211  protected:
216 
218  using PointCloudPtr = typename PointCloud::Ptr;
220 
221  public:
222 
223  using Ptr = shared_ptr<VoxelGrid<PointT> >;
224  using ConstPtr = shared_ptr<const VoxelGrid<PointT> >;
225 
227 
228  /** \brief Empty constructor. */
230  leaf_size_ (Eigen::Vector4f::Zero ()),
231  inverse_leaf_size_ (Eigen::Array4f::Zero ()),
232  min_b_ (Eigen::Vector4i::Zero ()),
233  max_b_ (Eigen::Vector4i::Zero ()),
234  div_b_ (Eigen::Vector4i::Zero ()),
235  divb_mul_ (Eigen::Vector4i::Zero ())
236  {
237  filter_name_ = "VoxelGrid";
238  }
239 
240  /** \brief Destructor. */
241  ~VoxelGrid () override = default;
242 
243  /** \brief Set the voxel grid leaf size.
244  * \param[in] leaf_size the voxel grid leaf size
245  */
246  inline void
247  setLeafSize (const Eigen::Vector4f &leaf_size)
248  {
249  leaf_size_ = leaf_size;
250  // Avoid division errors
251  if (leaf_size_[3] == 0)
252  leaf_size_[3] = 1;
253  // Use multiplications instead of divisions
254  inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
255  }
256 
257  /** \brief Set the voxel grid leaf size.
258  * \param[in] lx the leaf size for X
259  * \param[in] ly the leaf size for Y
260  * \param[in] lz the leaf size for Z
261  */
262  inline void
263  setLeafSize (float lx, float ly, float lz)
264  {
265  leaf_size_[0] = lx; leaf_size_[1] = ly; leaf_size_[2] = lz;
266  // Avoid division errors
267  if (leaf_size_[3] == 0)
268  leaf_size_[3] = 1;
269  // Use multiplications instead of divisions
270  inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
271  }
272 
273  /** \brief Get the voxel grid leaf size. */
274  inline Eigen::Vector3f
275  getLeafSize () const { return (leaf_size_.head<3> ()); }
276 
277  /** \brief Set to true if all fields need to be downsampled, or false if just XYZ.
278  * \param[in] downsample the new value (true/false)
279  */
280  inline void
281  setDownsampleAllData (bool downsample) { downsample_all_data_ = downsample; }
282 
283  /** \brief Get the state of the internal downsampling parameter (true if
284  * all fields need to be downsampled, false if just XYZ).
285  */
286  inline bool
288 
289  /** \brief Set the minimum number of points required for a voxel to be used.
290  * \param[in] min_points_per_voxel the minimum number of points for required for a voxel to be used
291  */
292  inline void
293  setMinimumPointsNumberPerVoxel (unsigned int min_points_per_voxel) { min_points_per_voxel_ = min_points_per_voxel; }
294 
295  /** \brief Return the minimum number of points required for a voxel to be used.
296  */
297  inline unsigned int
299 
300  /** \brief Set to true if leaf layout information needs to be saved for later access.
301  * \param[in] save_leaf_layout the new value (true/false)
302  */
303  inline void
304  setSaveLeafLayout (bool save_leaf_layout) { save_leaf_layout_ = save_leaf_layout; }
305 
306  /** \brief Returns true if leaf layout information will to be saved for later access. */
307  inline bool
308  getSaveLeafLayout () const { return (save_leaf_layout_); }
309 
310  /** \brief Get the minimum coordinates of the bounding box (after
311  * filtering is performed).
312  */
313  inline Eigen::Vector3i
314  getMinBoxCoordinates () const { return (min_b_.head<3> ()); }
315 
316  /** \brief Get the minimum coordinates of the bounding box (after
317  * filtering is performed).
318  */
319  inline Eigen::Vector3i
320  getMaxBoxCoordinates () const { return (max_b_.head<3> ()); }
321 
322  /** \brief Get the number of divisions along all 3 axes (after filtering
323  * is performed).
324  */
325  inline Eigen::Vector3i
326  getNrDivisions () const { return (div_b_.head<3> ()); }
327 
328  /** \brief Get the multipliers to be applied to the grid coordinates in
329  * order to find the centroid index (after filtering is performed).
330  */
331  inline Eigen::Vector3i
332  getDivisionMultiplier () const { return (divb_mul_.head<3> ()); }
333 
334  /** \brief Returns the index in the resulting downsampled cloud of the specified point.
335  *
336  * \note for efficiency, user must make sure that the saving of the leaf layout is enabled and filtering
337  * performed, and that the point is inside the grid, to avoid invalid access (or use
338  * getGridCoordinates+getCentroidIndexAt)
339  *
340  * \param[in] p the point to get the index at
341  */
342  inline int
343  getCentroidIndex (const PointT &p) const
344  {
345  return (leaf_layout_.at ((Eigen::Vector4i (static_cast<int> (std::floor (p.x * inverse_leaf_size_[0])),
346  static_cast<int> (std::floor (p.y * inverse_leaf_size_[1])),
347  static_cast<int> (std::floor (p.z * inverse_leaf_size_[2])), 0) - min_b_).dot (divb_mul_)));
348  }
349 
350  /** \brief Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinates,
351  * relative to the grid coordinates of the specified point (or -1 if the cell was empty/out of bounds).
352  * \param[in] reference_point the coordinates of the reference point (corresponding cell is allowed to be empty/out of bounds)
353  * \param[in] relative_coordinates matrix with the columns being the coordinates of the requested cells, relative to the reference point's cell
354  * \note for efficiency, user must make sure that the saving of the leaf layout is enabled and filtering performed
355  */
356  inline std::vector<int>
357  getNeighborCentroidIndices (const PointT &reference_point, const Eigen::MatrixXi &relative_coordinates) const
358  {
359  Eigen::Vector4i ijk (static_cast<int> (std::floor (reference_point.x * inverse_leaf_size_[0])),
360  static_cast<int> (std::floor (reference_point.y * inverse_leaf_size_[1])),
361  static_cast<int> (std::floor (reference_point.z * inverse_leaf_size_[2])), 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++)
366  {
367  Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
368  // checking if the specified cell is in the grid
369  if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
370  neighbors[ni] = leaf_layout_[((ijk + displacement - min_b_).dot (divb_mul_))]; // .at() can be omitted
371  else
372  neighbors[ni] = -1; // cell is out of bounds, consider it empty
373  }
374  return (neighbors);
375  }
376 
377  /** \brief Returns the layout of the leafs for fast access to cells relative to current position.
378  * \note position at (i-min_x) + (j-min_y)*div_x + (k-min_z)*div_x*div_y holds the index of the element at coordinates (i,j,k) in the grid (-1 if empty)
379  */
380  inline std::vector<int>
381  getLeafLayout () const { return (leaf_layout_); }
382 
383  /** \brief Returns the corresponding (i,j,k) coordinates in the grid of point (x,y,z).
384  * \param[in] x the X point coordinate to get the (i, j, k) index at
385  * \param[in] y the Y point coordinate to get the (i, j, k) index at
386  * \param[in] z the Z point coordinate to get the (i, j, k) index at
387  */
388  inline Eigen::Vector3i
389  getGridCoordinates (float x, float y, float z) const
390  {
391  return {static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
392  static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
393  static_cast<int> (std::floor (z * inverse_leaf_size_[2]))};
394  }
395 
396  /** \brief Returns the index in the downsampled cloud corresponding to a given set of coordinates.
397  * \param[in] ijk the coordinates (i,j,k) in the grid (-1 if empty)
398  */
399  inline int
400  getCentroidIndexAt (const Eigen::Vector3i &ijk) const
401  {
402  int idx = ((Eigen::Vector4i() << ijk, 0).finished() - min_b_).dot (divb_mul_);
403  if (idx < 0 || idx >= static_cast<int> (leaf_layout_.size ())) // this checks also if leaf_layout_.size () == 0 i.e. everything was computed as needed
404  {
405  //if (verbose)
406  // PCL_ERROR ("[pcl::%s::getCentroidIndexAt] Specified coordinate is outside grid bounds, or leaf layout is not saved, make sure to call setSaveLeafLayout(true) and filter(output) first!\n", getClassName ().c_str ());
407  return (-1);
408  }
409  return (leaf_layout_[idx]);
410  }
411 
412  /** \brief Provide the name of the field to be used for filtering data. In conjunction with \a setFilterLimits,
413  * points having values outside this interval will be discarded.
414  * \param[in] field_name the name of the field that contains values used for filtering
415  */
416  inline void
417  setFilterFieldName (const std::string &field_name)
418  {
419  filter_field_name_ = field_name;
420  }
421 
422  /** \brief Get the name of the field used for filtering. */
423  inline std::string const
425  {
426  return (filter_field_name_);
427  }
428 
429  /** \brief Set the field filter limits. All points having field values outside this interval will be discarded.
430  * \param[in] limit_min the minimum allowed field value
431  * \param[in] limit_max the maximum allowed field value
432  */
433  inline void
434  setFilterLimits (const double &limit_min, const double &limit_max)
435  {
436  filter_limit_min_ = limit_min;
437  filter_limit_max_ = limit_max;
438  }
439 
440  /** \brief Get the field filter limits (min/max) set by the user.
441  The default values are std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max().
442  * \param[out] limit_min the minimum allowed field value
443  * \param[out] limit_max the maximum allowed field value
444  */
445  inline void
446  getFilterLimits (double &limit_min, double &limit_max) const
447  {
448  limit_min = filter_limit_min_;
449  limit_max = filter_limit_max_;
450  }
451 
452  /** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max).
453  * Default: false.
454  * \param[in] limit_negative return data inside the interval (false) or outside (true)
455  */
456  inline void
457  setFilterLimitsNegative (const bool limit_negative)
458  {
459  filter_limit_negative_ = limit_negative;
460  }
461 
462  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
463  * \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
464  */
465  PCL_DEPRECATED(1, 16, "use bool getFilterLimitsNegative() instead")
466  inline void
467  getFilterLimitsNegative (bool &limit_negative) const
468  {
469  limit_negative = filter_limit_negative_;
470  }
471 
472  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
473  * \return true if data \b outside the interval [min; max] is to be returned, false otherwise
474  */
475  inline bool
477  {
478  return (filter_limit_negative_);
479  }
480 
481  protected:
482  /** \brief The size of a leaf. */
483  Eigen::Vector4f leaf_size_;
484 
485  /** \brief Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons. */
486  Eigen::Array4f inverse_leaf_size_;
487 
488  /** \brief Set to true if all fields need to be downsampled, or false if just XYZ. */
490 
491  /** \brief Set to true if leaf layout information needs to be saved in \a leaf_layout_. */
492  bool save_leaf_layout_{false};
493 
494  /** \brief The leaf layout information for fast access to cells relative to current position **/
495  std::vector<int> leaf_layout_;
496 
497  /** \brief The minimum and maximum bin coordinates, the number of divisions, and the division multiplier. */
498  Eigen::Vector4i min_b_, max_b_, div_b_, divb_mul_;
499 
500  /** \brief The desired user filter field name. */
501  std::string filter_field_name_;
502 
503  /** \brief The minimum allowed filter value a point will be considered from. */
504  double filter_limit_min_{std::numeric_limits<float>::lowest()};
505 
506  /** \brief The maximum allowed filter value a point will be considered from. */
507  double filter_limit_max_{std::numeric_limits<float>::max()};
508 
509  /** \brief Set to true if we want to return the data outside (\a filter_limit_min_;\a filter_limit_max_). Default: false. */
511 
512  /** \brief Minimum number of points per voxel for the centroid to be computed */
513  unsigned int min_points_per_voxel_{0};
514 
515  using FieldList = typename pcl::traits::fieldList<PointT>::type;
516 
517  /** \brief Downsample a Point Cloud using a voxelized grid approach
518  * \param[out] output the resultant point cloud message
519  */
520  void
521  applyFilter (PointCloud &output) override;
522  };
523 
524  /** \brief VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
525  *
526  * The VoxelGrid class creates a *3D voxel grid* (think about a voxel
527  * grid as a set of tiny 3D boxes in space) over the input point cloud data.
528  * Then, in each *voxel* (i.e., 3D box), all the points present will be
529  * approximated (i.e., *downsampled*) with their centroid. This approach is
530  * a bit slower than approximating them with the center of the voxel, but it
531  * represents the underlying surface more accurately.
532  *
533  * \author Radu B. Rusu, Bastian Steder, Radoslaw Cybulski
534  * \ingroup filters
535  */
536  template <>
537  class PCL_EXPORTS VoxelGrid<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
538  {
541 
545 
546  public:
547  /** \brief Empty constructor. */
549  leaf_size_ (Eigen::Vector4f::Zero ()),
550  inverse_leaf_size_ (Eigen::Array4f::Zero ()),
551 
552  min_b_ (Eigen::Vector4i::Zero ()),
553  max_b_ (Eigen::Vector4i::Zero ()),
554  div_b_ (Eigen::Vector4i::Zero ()),
555  divb_mul_ (Eigen::Vector4i::Zero ())
556  {
557  filter_name_ = "VoxelGrid";
558  }
559 
560  /** \brief Destructor. */
561  ~VoxelGrid () override = default;
562 
563  /** \brief Set the voxel grid leaf size.
564  * \param[in] leaf_size the voxel grid leaf size
565  */
566  inline void
567  setLeafSize (const Eigen::Vector4f &leaf_size)
568  {
569  leaf_size_ = leaf_size;
570  // Avoid division errors
571  if (leaf_size_[3] == 0)
572  leaf_size_[3] = 1;
573  // Use multiplications instead of divisions
574  inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
575  }
576 
577  /** \brief Set the voxel grid leaf size.
578  * \param[in] lx the leaf size for X
579  * \param[in] ly the leaf size for Y
580  * \param[in] lz the leaf size for Z
581  */
582  inline void
583  setLeafSize (float lx, float ly, float lz)
584  {
585  leaf_size_[0] = lx; leaf_size_[1] = ly; leaf_size_[2] = lz;
586  // Avoid division errors
587  if (leaf_size_[3] == 0)
588  leaf_size_[3] = 1;
589  // Use multiplications instead of divisions
590  inverse_leaf_size_ = Eigen::Array4f::Ones () / leaf_size_.array ();
591  }
592 
593  /** \brief Get the voxel grid leaf size. */
594  inline Eigen::Vector3f
595  getLeafSize () const { return (leaf_size_.head<3> ()); }
596 
597  /** \brief Set to true if all fields need to be downsampled, or false if just XYZ.
598  * \param[in] downsample the new value (true/false)
599  */
600  inline void
601  setDownsampleAllData (bool downsample) { downsample_all_data_ = downsample; }
602 
603  /** \brief Get the state of the internal downsampling parameter (true if
604  * all fields need to be downsampled, false if just XYZ).
605  */
606  inline bool
607  getDownsampleAllData () const { return (downsample_all_data_); }
608 
609  /** \brief Set the minimum number of points required for a voxel to be used.
610  * \param[in] min_points_per_voxel the minimum number of points for required for a voxel to be used
611  */
612  inline void
613  setMinimumPointsNumberPerVoxel (unsigned int min_points_per_voxel) { min_points_per_voxel_ = min_points_per_voxel; }
614 
615  /** \brief Return the minimum number of points required for a voxel to be used.
616  */
617  inline unsigned int
618  getMinimumPointsNumberPerVoxel () const { return min_points_per_voxel_; }
619 
620  /** \brief Set to true if leaf layout information needs to be saved for later access.
621  * \param[in] save_leaf_layout the new value (true/false)
622  */
623  inline void
624  setSaveLeafLayout (bool save_leaf_layout) { save_leaf_layout_ = save_leaf_layout; }
625 
626  /** \brief Returns true if leaf layout information will to be saved for later access. */
627  inline bool
628  getSaveLeafLayout () const { return (save_leaf_layout_); }
629 
630  /** \brief Get the minimum coordinates of the bounding box (after
631  * filtering is performed).
632  */
633  inline Eigen::Vector3i
634  getMinBoxCoordinates () const { return (min_b_.head<3> ()); }
635 
636  /** \brief Get the minimum coordinates of the bounding box (after
637  * filtering is performed).
638  */
639  inline Eigen::Vector3i
640  getMaxBoxCoordinates () const { return (max_b_.head<3> ()); }
641 
642  /** \brief Get the number of divisions along all 3 axes (after filtering
643  * is performed).
644  */
645  inline Eigen::Vector3i
646  getNrDivisions () const { return (div_b_.head<3> ()); }
647 
648  /** \brief Get the multipliers to be applied to the grid coordinates in
649  * order to find the centroid index (after filtering is performed).
650  */
651  inline Eigen::Vector3i
652  getDivisionMultiplier () const { return (divb_mul_.head<3> ()); }
653 
654  /** \brief Returns the index in the resulting downsampled cloud of the specified point.
655  * \note for efficiency, user must make sure that the saving of the leaf layout is enabled and filtering performed,
656  * and that the point is inside the grid, to avoid invalid access (or use getGridCoordinates+getCentroidIndexAt)
657  * \param[in] x the X point coordinate to get the index at
658  * \param[in] y the Y point coordinate to get the index at
659  * \param[in] z the Z point coordinate to get the index at
660  */
661  inline int
662  getCentroidIndex (float x, float y, float z) const
663  {
664  return (leaf_layout_.at ((Eigen::Vector4i (static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
665  static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
666  static_cast<int> (std::floor (z * inverse_leaf_size_[2])),
667  0)
668  - min_b_).dot (divb_mul_)));
669  }
670 
671  /** \brief Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinates,
672  * relative to the grid coordinates of the specified point (or -1 if the cell was empty/out of bounds).
673  * \param[in] x the X coordinate of the reference point (corresponding cell is allowed to be empty/out of bounds)
674  * \param[in] y the Y coordinate of the reference point (corresponding cell is allowed to be empty/out of bounds)
675  * \param[in] z the Z coordinate of the reference point (corresponding cell is allowed to be empty/out of bounds)
676  * \param[out] relative_coordinates matrix with the columns being the coordinates of the requested cells, relative to the reference point's cell
677  * \note for efficiency, user must make sure that the saving of the leaf layout is enabled and filtering performed
678  */
679  inline std::vector<int>
680  getNeighborCentroidIndices (float x, float y, float z, const Eigen::MatrixXi &relative_coordinates) const
681  {
682  Eigen::Vector4i ijk (static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
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++)
689  {
690  Eigen::Vector4i displacement = (Eigen::Vector4i() << relative_coordinates.col(ni), 0).finished();
691  // checking if the specified cell is in the grid
692  if ((diff2min <= displacement.array()).all() && (diff2max >= displacement.array()).all())
693  neighbors[ni] = leaf_layout_[((ijk + displacement - min_b_).dot (divb_mul_))]; // .at() can be omitted
694  else
695  neighbors[ni] = -1; // cell is out of bounds, consider it empty
696  }
697  return (neighbors);
698  }
699 
700  /** \brief Returns the indices in the resulting downsampled cloud of the points at the specified grid coordinates,
701  * relative to the grid coordinates of the specified point (or -1 if the cell was empty/out of bounds).
702  * \param[in] x the X coordinate of the reference point (corresponding cell is allowed to be empty/out of bounds)
703  * \param[in] y the Y coordinate of the reference point (corresponding cell is allowed to be empty/out of bounds)
704  * \param[in] z the Z coordinate of the reference point (corresponding cell is allowed to be empty/out of bounds)
705  * \param[out] relative_coordinates vector with the elements being the coordinates of the requested cells, relative to the reference point's cell
706  * \note for efficiency, user must make sure that the saving of the leaf layout is enabled and filtering performed
707  */
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
710  {
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)
715  neighbors.push_back (leaf_layout_[(ijk + (Eigen::Vector4i() << relative_coordinate, 0).finished() - min_b_).dot (divb_mul_)]);
716  return (neighbors);
717  }
718 
719  /** \brief Returns the layout of the leafs for fast access to cells relative to current position.
720  * \note position at (i-min_x) + (j-min_y)*div_x + (k-min_z)*div_x*div_y holds the index of the element at coordinates (i,j,k) in the grid (-1 if empty)
721  */
722  inline std::vector<int>
723  getLeafLayout () const { return (leaf_layout_); }
724 
725  /** \brief Returns the corresponding (i,j,k) coordinates in the grid of point (x,y,z).
726  * \param[in] x the X point coordinate to get the (i, j, k) index at
727  * \param[in] y the Y point coordinate to get the (i, j, k) index at
728  * \param[in] z the Z point coordinate to get the (i, j, k) index at
729  */
730  inline Eigen::Vector3i
731  getGridCoordinates (float x, float y, float z) const
732  {
733  return {static_cast<int> (std::floor (x * inverse_leaf_size_[0])),
734  static_cast<int> (std::floor (y * inverse_leaf_size_[1])),
735  static_cast<int> (std::floor (z * inverse_leaf_size_[2]))};
736  }
737 
738  /** \brief Returns the index in the downsampled cloud corresponding to a given set of coordinates.
739  * \param[in] ijk the coordinates (i,j,k) in the grid (-1 if empty)
740  */
741  inline int
742  getCentroidIndexAt (const Eigen::Vector3i &ijk) const
743  {
744  int idx = ((Eigen::Vector4i() << ijk, 0).finished() - min_b_).dot (divb_mul_);
745  if (idx < 0 || idx >= static_cast<int> (leaf_layout_.size ())) // this checks also if leaf_layout_.size () == 0 i.e. everything was computed as needed
746  {
747  //if (verbose)
748  // PCL_ERROR ("[pcl::%s::getCentroidIndexAt] Specified coordinate is outside grid bounds, or leaf layout is not saved, make sure to call setSaveLeafLayout(true) and filter(output) first!\n", getClassName ().c_str ());
749  return (-1);
750  }
751  return (leaf_layout_[idx]);
752  }
753 
754  /** \brief Provide the name of the field to be used for filtering data. In conjunction with \a setFilterLimits,
755  * points having values outside this interval will be discarded.
756  * \param[in] field_name the name of the field that contains values used for filtering
757  */
758  inline void
759  setFilterFieldName (const std::string &field_name)
760  {
761  filter_field_name_ = field_name;
762  }
763 
764  /** \brief Get the name of the field used for filtering. */
765  inline std::string const
767  {
768  return (filter_field_name_);
769  }
770 
771  /** \brief Set the field filter limits. All points having field values outside this interval will be discarded.
772  * \param[in] limit_min the minimum allowed field value
773  * \param[in] limit_max the maximum allowed field value
774  */
775  inline void
776  setFilterLimits (const double &limit_min, const double &limit_max)
777  {
778  filter_limit_min_ = limit_min;
779  filter_limit_max_ = limit_max;
780  }
781 
782  /** \brief Get the field filter limits (min/max) set by the user.
783  * The default values are std::numeric_limits<float>::lowest(), std::numeric_limits<float>::max().
784  * \param[out] limit_min the minimum allowed field value
785  * \param[out] limit_max the maximum allowed field value
786  */
787  inline void
788  getFilterLimits (double &limit_min, double &limit_max) const
789  {
790  limit_min = filter_limit_min_;
791  limit_max = filter_limit_max_;
792  }
793 
794  /** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max).
795  * Default: false.
796  * \param[in] limit_negative return data inside the interval (false) or outside (true)
797  */
798  inline void
799  setFilterLimitsNegative (const bool limit_negative)
800  {
801  filter_limit_negative_ = limit_negative;
802  }
803 
804  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
805  * \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
806  */
807  PCL_DEPRECATED(1, 16, "use bool getFilterLimitsNegative() instead")
808  inline void
809  getFilterLimitsNegative (bool &limit_negative) const
810  {
811  limit_negative = filter_limit_negative_;
812  }
813 
814  /** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
815  * \return true if data \b outside the interval [min; max] is to be returned, false otherwise
816  */
817  inline bool
819  {
820  return (filter_limit_negative_);
821  }
822 
823  protected:
824  /** \brief The size of a leaf. */
825  Eigen::Vector4f leaf_size_;
826 
827  /** \brief Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons. */
828  Eigen::Array4f inverse_leaf_size_;
829 
830  /** \brief Set to true if all fields need to be downsampled, or false if just XYZ. */
831  bool downsample_all_data_{true};
832 
833  /** \brief Set to true if leaf layout information needs to be saved in \a
834  * leaf_layout.
835  */
836  bool save_leaf_layout_{false};
837 
838  /** \brief The leaf layout information for fast access to cells relative
839  * to current position
840  */
841  std::vector<int> leaf_layout_;
842 
843  /** \brief The minimum and maximum bin coordinates, the number of
844  * divisions, and the division multiplier.
845  */
846  Eigen::Vector4i min_b_, max_b_, div_b_, divb_mul_;
847 
848  /** \brief The desired user filter field name. */
849  std::string filter_field_name_;
850 
851  /** \brief The minimum allowed filter value a point will be considered from. */
852  double filter_limit_min_{std::numeric_limits<float>::lowest()};
853 
854  /** \brief The maximum allowed filter value a point will be considered from. */
855  double filter_limit_max_{std::numeric_limits<float>::max()};
856 
857  /** \brief Set to true if we want to return the data outside (\a filter_limit_min_;\a filter_limit_max_). Default: false. */
858  bool filter_limit_negative_{false};
859 
860  /** \brief Minimum number of points per voxel for the centroid to be computed */
861  unsigned int min_points_per_voxel_{0};
862 
863  /** \brief Downsample a Point Cloud using a voxelized grid approach
864  * \param[out] output the resultant point cloud
865  */
866  void
867  applyFilter (PCLPointCloud2 &output) override;
868  };
869 
870  namespace internal
871  {
872  /** \brief Used internally in voxel grid classes.
873  */
875  {
876  unsigned int idx;
877  unsigned int cloud_point_index;
878 
880  cloud_point_index_idx (unsigned int idx_, unsigned int cloud_point_index_) : idx (idx_), cloud_point_index (cloud_point_index_) {}
881  bool operator < (const cloud_point_index_idx &p) const { return (idx < p.idx); }
882  };
883  }
884 }
885 
886 #ifdef PCL_NO_PRECOMPILE
887 #include <pcl/filters/impl/voxel_grid.hpp>
888 #endif
Filter represents the base filter class.
Definition: filter.h:81
shared_ptr< Filter< PointT > > Ptr
Definition: filter.h:83
shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:84
std::string filter_name_
The filter name.
Definition: filter.h:158
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:185
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:186
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
int getCentroidIndexAt(const Eigen::Vector3i &ijk) const
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
Definition: voxel_grid.h:742
Eigen::Vector3i getDivisionMultiplier() const
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
Definition: voxel_grid.h:652
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Definition: voxel_grid.h:818
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...
Definition: voxel_grid.h:680
std::string filter_field_name_
The desired user filter field name.
Definition: voxel_grid.h:849
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
Definition: voxel_grid.h:841
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
Definition: voxel_grid.h:601
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
Definition: voxel_grid.h:776
Eigen::Vector3f getLeafSize() const
Get the voxel grid leaf size.
Definition: voxel_grid.h:595
Eigen::Vector3i getNrDivisions() const
Get the number of divisions along all 3 axes (after filtering is performed).
Definition: voxel_grid.h:646
Eigen::Vector3i getMinBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
Definition: voxel_grid.h:634
void applyFilter(PCLPointCloud2 &output) override
Downsample a Point Cloud using a voxelized grid approach.
unsigned int getMinimumPointsNumberPerVoxel() const
Return the minimum number of points required for a voxel to be used.
Definition: voxel_grid.h:618
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
Definition: voxel_grid.h:567
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
Definition: voxel_grid.h:788
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...
Definition: voxel_grid.h:709
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).
Definition: voxel_grid.h:731
bool getDownsampleAllData() const
Get the state of the internal downsampling parameter (true if all fields need to be downsampled,...
Definition: voxel_grid.h:607
bool getSaveLeafLayout() const
Returns true if leaf layout information will to be saved for later access.
Definition: voxel_grid.h:628
std::vector< int > getLeafLayout() const
Returns the layout of the leafs for fast access to cells relative to current position.
Definition: voxel_grid.h:723
std::string const getFilterFieldName() const
Get the name of the field used for filtering.
Definition: voxel_grid.h:766
Eigen::Vector3i getMaxBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
Definition: voxel_grid.h:640
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: voxel_grid.h:759
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
Definition: voxel_grid.h:624
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
Definition: voxel_grid.h:799
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
Definition: voxel_grid.h:583
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
Definition: voxel_grid.h:828
~VoxelGrid() override=default
Destructor.
void setMinimumPointsNumberPerVoxel(unsigned int min_points_per_voxel)
Set the minimum number of points required for a voxel to be used.
Definition: voxel_grid.h:613
int getCentroidIndex(float x, float y, float z) const
Returns the index in the resulting downsampled cloud of the specified point.
Definition: voxel_grid.h:662
Eigen::Vector4f leaf_size_
The size of a leaf.
Definition: voxel_grid.h:825
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
Definition: voxel_grid.h:210
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).
Definition: voxel_grid.h:389
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: voxel_grid.h:417
void setDownsampleAllData(bool downsample)
Set to true if all fields need to be downsampled, or false if just XYZ.
Definition: voxel_grid.h:281
bool downsample_all_data_
Set to true if all fields need to be downsampled, or false if just XYZ.
Definition: voxel_grid.h:489
Eigen::Vector3i getDivisionMultiplier() const
Get the multipliers to be applied to the grid coordinates in order to find the centroid index (after ...
Definition: voxel_grid.h:332
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Definition: voxel_grid.h:476
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
Definition: voxel_grid.h:457
Eigen::Vector3i getMaxBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
Definition: voxel_grid.h:320
Eigen::Vector4i max_b_
Definition: voxel_grid.h:498
unsigned int min_points_per_voxel_
Minimum number of points per voxel for the centroid to be computed.
Definition: voxel_grid.h:513
void applyFilter(PointCloud &output) override
Downsample a Point Cloud using a voxelized grid approach.
Definition: voxel_grid.hpp:216
unsigned int getMinimumPointsNumberPerVoxel() const
Return the minimum number of points required for a voxel to be used.
Definition: voxel_grid.h:298
bool getDownsampleAllData() const
Get the state of the internal downsampling parameter (true if all fields need to be downsampled,...
Definition: voxel_grid.h:287
std::vector< int > leaf_layout_
The leaf layout information for fast access to cells relative to current position.
Definition: voxel_grid.h:495
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
Definition: voxel_grid.h:446
Eigen::Vector4i divb_mul_
Definition: voxel_grid.h:498
typename pcl::traits::fieldList< PointT >::type FieldList
Definition: voxel_grid.h:515
int getCentroidIndex(const PointT &p) const
Returns the index in the resulting downsampled cloud of the specified point.
Definition: voxel_grid.h:343
Eigen::Vector3i getNrDivisions() const
Get the number of divisions along all 3 axes (after filtering is performed).
Definition: voxel_grid.h:326
bool save_leaf_layout_
Set to true if leaf layout information needs to be saved in leaf_layout_.
Definition: voxel_grid.h:492
bool filter_limit_negative_
Set to true if we want to return the data outside (filter_limit_min_;filter_limit_max_).
Definition: voxel_grid.h:510
std::vector< int > getLeafLayout() const
Returns the layout of the leafs for fast access to cells relative to current position.
Definition: voxel_grid.h:381
int getCentroidIndexAt(const Eigen::Vector3i &ijk) const
Returns the index in the downsampled cloud corresponding to a given set of coordinates.
Definition: voxel_grid.h:400
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
Definition: voxel_grid.h:247
Eigen::Vector4i min_b_
The minimum and maximum bin coordinates, the number of divisions, and the division multiplier.
Definition: voxel_grid.h:498
void setSaveLeafLayout(bool save_leaf_layout)
Set to true if leaf layout information needs to be saved for later access.
Definition: voxel_grid.h:304
double filter_limit_max_
The maximum allowed filter value a point will be considered from.
Definition: voxel_grid.h:507
void setMinimumPointsNumberPerVoxel(unsigned int min_points_per_voxel)
Set the minimum number of points required for a voxel to be used.
Definition: voxel_grid.h:293
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...
Definition: voxel_grid.h:357
PCL_MAKE_ALIGNED_OPERATOR_NEW VoxelGrid()
Empty constructor.
Definition: voxel_grid.h:229
std::string filter_field_name_
The desired user filter field name.
Definition: voxel_grid.h:501
Eigen::Vector4f leaf_size_
The size of a leaf.
Definition: voxel_grid.h:483
double filter_limit_min_
The minimum allowed filter value a point will be considered from.
Definition: voxel_grid.h:504
Eigen::Vector3f getLeafSize() const
Get the voxel grid leaf size.
Definition: voxel_grid.h:275
void setLeafSize(float lx, float ly, float lz)
Set the voxel grid leaf size.
Definition: voxel_grid.h:263
std::string const getFilterFieldName() const
Get the name of the field used for filtering.
Definition: voxel_grid.h:424
Eigen::Vector3i getMinBoxCoordinates() const
Get the minimum coordinates of the bounding box (after filtering is performed).
Definition: voxel_grid.h:314
Eigen::Array4f inverse_leaf_size_
Internal leaf sizes stored as 1/leaf_size_ for efficiency reasons.
Definition: voxel_grid.h:486
~VoxelGrid() override=default
Destructor.
bool getSaveLeafLayout() const
Returns true if leaf layout information will to be saved for later access.
Definition: voxel_grid.h:308
Eigen::Vector4i div_b_
Definition: voxel_grid.h:498
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
Definition: voxel_grid.h:434
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.
Definition: common.hpp:295
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Eigen::MatrixXi getAllNeighborCellIndices()
Get the relative cell indices of all the 26 neighbors.
Definition: voxel_grid.h:153
Eigen::MatrixXi getHalfNeighborCellIndices()
Get the relative cell indices of the "upper half" 13 neighbors.
Definition: voxel_grid.h:116
Definition: bfgs.h:10
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
#define PCL_EXPORTS
Definition: pcl_macros.h:323
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major....
Definition: pcl_macros.h:156
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.
Used internally in voxel grid classes.
Definition: voxel_grid.h:875
bool operator<(const cloud_point_index_idx &p) const
Definition: voxel_grid.h:881
cloud_point_index_idx(unsigned int idx_, unsigned int cloud_point_index_)
Definition: voxel_grid.h:880