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