Point Cloud Library (PCL)  1.14.0-dev
grid_minimum.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  * Copyright (c) 2014, RadiantBlue Technologies, Inc.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  * notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above
18  * copyright notice, this list of conditions and the following
19  * disclaimer in the documentation and/or other materials provided
20  * with the distribution.
21  * * Neither the name of the copyright holder(s) nor the names of its
22  * contributors may be used to endorse or promote products derived
23  * from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * $Id$
39  *
40  */
41 
42 #pragma once
43 
44 #include <pcl/filters/filter.h>
45 #include <pcl/filters/filter_indices.h>
46 
47 namespace pcl
48 {
49  /** \brief GridMinimum assembles a local 2D grid over a given PointCloud, and downsamples the data.
50  *
51  * The GridMinimum class creates a *2D grid* over the input point cloud
52  * data. Then, in each *cell* (i.e., 2D grid element), all the points
53  * present will be *downsampled* with the minimum z value. This grid minimum
54  * can be useful in a number of topographic processing tasks such as crudely
55  * estimating ground returns, especially under foliage.
56  *
57  * \author Bradley J Chambers
58  * \ingroup filters
59  */
60  template <typename PointT>
61  class GridMinimum: public FilterIndices<PointT>
62  {
63  protected:
68 
70 
71  public:
72  /** \brief Empty constructor. */
73  GridMinimum (const float resolution)
74  {
75  setResolution (resolution);
76  filter_name_ = "GridMinimum";
77  }
78 
79  /** \brief Destructor. */
80  ~GridMinimum () override = default;
81 
82  /** \brief Set the grid resolution.
83  * \param[in] resolution the grid resolution
84  */
85  inline void
86  setResolution (const float resolution)
87  {
88  resolution_ = resolution;
89  // Use multiplications instead of divisions
91  }
92 
93  /** \brief Get the grid resolution. */
94  inline float
95  getResolution () { return (resolution_); }
96 
97  protected:
98  /** \brief The resolution. */
99  float resolution_;
100 
101  /** \brief Internal resolution stored as 1/resolution_ for efficiency reasons. */
103 
104  /** \brief Downsample a Point Cloud using a 2D grid approach
105  * \param[out] output the resultant point cloud message
106  */
107  void
108  applyFilter (PointCloud &output) override;
109 
110  /** \brief Filtered results are indexed by an indices array.
111  * \param[out] indices The resultant indices.
112  */
113  void
114  applyFilter (Indices &indices) override
115  {
116  applyFilterIndices (indices);
117  }
118 
119  /** \brief Filtered results are indexed by an indices array.
120  * \param[out] indices The resultant indices.
121  */
122  void
123  applyFilterIndices (Indices &indices);
124 
125  };
126 }
127 
128 #ifdef PCL_NO_PRECOMPILE
129 #include <pcl/filters/impl/grid_minimum.hpp>
130 #endif
Filter represents the base filter class.
Definition: filter.h:81
std::string filter_name_
The filter name.
Definition: filter.h:158
FilterIndices represents the base class for filters that are about binary point removal.
GridMinimum assembles a local 2D grid over a given PointCloud, and downsamples the data.
Definition: grid_minimum.h:62
void setResolution(const float resolution)
Set the grid resolution.
Definition: grid_minimum.h:86
GridMinimum(const float resolution)
Empty constructor.
Definition: grid_minimum.h:73
float resolution_
The resolution.
Definition: grid_minimum.h:99
void applyFilterIndices(Indices &indices)
Filtered results are indexed by an indices array.
void applyFilter(Indices &indices) override
Filtered results are indexed by an indices array.
Definition: grid_minimum.h:114
float inverse_resolution_
Internal resolution stored as 1/resolution_ for efficiency reasons.
Definition: grid_minimum.h:102
~GridMinimum() override=default
Destructor.
void applyFilter(PointCloud &output) override
Downsample a Point Cloud using a 2D grid approach.
float getResolution()
Get the grid resolution.
Definition: grid_minimum.h:95
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133