Point Cloud Library (PCL)  1.8.1-dev
extract_indices.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2012, 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 #ifndef PCL_FILTERS_EXTRACT_INDICES_H_
41 #define PCL_FILTERS_EXTRACT_INDICES_H_
42 
43 #include <pcl/filters/filter_indices.h>
44 
45 namespace pcl
46 {
47  /** \brief @b ExtractIndices extracts a set of indices from a point cloud.
48  * \details Usage example:
49  * \code
50  * pcl::ExtractIndices<PointType> eifilter (true); // Initializing with true will allow us to extract the removed indices
51  * eifilter.setInputCloud (cloud_in);
52  * eifilter.setIndices (indices_in);
53  * eifilter.filter (*cloud_out);
54  * // The resulting cloud_out contains all points of cloud_in that are indexed by indices_in
55  * indices_rem = eifilter.getRemovedIndices ();
56  * // The indices_rem array indexes all points of cloud_in that are not indexed by indices_in
57  * eifilter.setNegative (true);
58  * eifilter.filter (*indices_out);
59  * // Alternatively: the indices_out array is identical to indices_rem
60  * eifilter.setNegative (false);
61  * eifilter.setUserFilterValue (1337.0);
62  * eifilter.filterDirectly (cloud_in);
63  * // This will directly modify cloud_in instead of creating a copy of the cloud
64  * // It will overwrite all fields of the filtered points by the user value: 1337
65  * \endcode
66  * \author Radu Bogdan Rusu
67  * \ingroup filters
68  */
69  template<typename PointT>
70  class ExtractIndices : public FilterIndices<PointT>
71  {
72  protected:
74  typedef typename PointCloud::Ptr PointCloudPtr;
77 
78  public:
79 
80  typedef boost::shared_ptr< ExtractIndices<PointT> > Ptr;
81  typedef boost::shared_ptr< const ExtractIndices<PointT> > ConstPtr;
82 
83  /** \brief Constructor.
84  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
85  */
86  ExtractIndices (bool extract_removed_indices = false) :
87  FilterIndices<PointT>::FilterIndices (extract_removed_indices)
88  {
89  use_indices_ = true;
90  filter_name_ = "ExtractIndices";
91  }
92 
93  /** \brief Apply the filter and store the results directly in the input cloud.
94  * \details This method will save the time and memory copy of an output cloud but can not alter the original size of the input cloud:
95  * It operates as though setKeepOrganized() is true and will overwrite the filtered points instead of remove them.
96  * All fields of filtered points are replaced with the value set by setUserFilterValue() (default = NaN).
97  * This method also automatically alters the input cloud set via setInputCloud().
98  * It does not alter the value of the internal keep organized boolean as set by setKeepOrganized().
99  * \param cloud The point cloud used for input and output.
100  */
101  void
102  filterDirectly (PointCloudPtr &cloud);
103 
104  protected:
115 
116  /** \brief Filtered results are stored in a separate point cloud.
117  * \param[out] output The resultant point cloud.
118  */
119  void
120  applyFilter (PointCloud &output);
121 
122  /** \brief Filtered results are indexed by an indices array.
123  * \param[out] indices The resultant indices.
124  */
125  void
126  applyFilter (std::vector<int> &indices)
127  {
128  applyFilterIndices (indices);
129  }
130 
131  /** \brief Filtered results are indexed by an indices array.
132  * \param[out] indices The resultant indices.
133  */
134  void
135  applyFilterIndices (std::vector<int> &indices);
136  };
137 
138  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139  /** \brief @b ExtractIndices extracts a set of indices from a point cloud.
140  * <br>
141  * Usage examples:
142  * \code
143  * pcl::ExtractIndices<PointType> filter;
144  * filter.setInputCloud (cloud_in);
145  * filter.setIndices (indices_in);
146  * // Extract the points in cloud_in referenced by indices_in as a separate point cloud:
147  * filter.filter (*cloud_out);
148  * // Retrieve indices to all points in cloud_in except those referenced by indices_in:
149  * filter.setNegative (true);
150  * filter.filter (*indices_out);
151  * // The resulting cloud_out is identical to cloud_in, but all points referenced by indices_in are made NaN:
152  * filter.setNegative (true);
153  * filter.setKeepOrganized (true);
154  * filter.filter (*cloud_out);
155  * \endcode
156  * \note Does not inherently remove NaNs from results, hence the \a extract_removed_indices_ system is not used.
157  * \author Radu Bogdan Rusu
158  * \ingroup filters
159  */
160  template<>
161  class PCL_EXPORTS ExtractIndices<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
162  {
163  public:
167 
168  /** \brief Empty constructor. */
170  {
171  use_indices_ = true;
172  filter_name_ = "ExtractIndices";
173  }
174 
175  protected:
184 
185  /** \brief Extract point indices into a separate PointCloud
186  * \param[out] output the resultant point cloud
187  */
188  void
189  applyFilter (PCLPointCloud2 &output);
190 
191  /** \brief Extract point indices
192  * \param indices the resultant indices
193  */
194  void
195  applyFilter (std::vector<int> &indices);
196  };
197 }
198 
199 #ifdef PCL_NO_PRECOMPILE
200 #include <pcl/filters/impl/extract_indices.hpp>
201 #endif
202 
203 #endif // PCL_FILTERS_EXTRACT_INDICES_H_
204 
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
bool use_indices_
Set to true if point indices are used.
Definition: pcl_base.h:156
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
void applyFilter(PointCloud &output)
Filtered results are stored in a separate point cloud.
FilterIndices represents the base class for filters that are about binary point removal.
Filter represents the base filter class.
Definition: filter.h:84
FilterIndices< PointT >::PointCloud PointCloud
PCL base class.
Definition: pcl_base.h:68
PointCloud::Ptr PointCloudPtr
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
void applyFilterIndices(std::vector< int > &indices)
Filtered results are indexed by an indices array.
ExtractIndices(bool extract_removed_indices=false)
Constructor.
boost::shared_ptr< const ExtractIndices< PointT > > ConstPtr
pcl::traits::fieldList< PointT >::type FieldList
std::string filter_name_
The filter name.
Definition: filter.h:166
A point structure representing Euclidean xyz coordinates, and the RGB color.
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
void applyFilter(std::vector< int > &indices)
Filtered results are indexed by an indices array.
ExtractIndices extracts a set of indices from a point cloud.
boost::shared_ptr< ExtractIndices< PointT > > Ptr
PointCloud::ConstPtr PointCloudConstPtr
void filterDirectly(PointCloudPtr &cloud)
Apply the filter and store the results directly in the input cloud.