Point Cloud Library (PCL)  1.8.1
project_inliers.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder(s) nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #ifndef PCL_FILTERS_PROJECT_INLIERS_H_
39 #define PCL_FILTERS_PROJECT_INLIERS_H_
40 
41 #include <pcl/point_types.h>
42 #include <pcl/filters/filter.h>
43 #include <pcl/ModelCoefficients.h>
44 // Sample Consensus models
45 #include <pcl/sample_consensus/model_types.h>
46 #include <pcl/sample_consensus/sac_model.h>
47 #include <pcl/sample_consensus/sac_model_circle.h>
48 #include <pcl/sample_consensus/sac_model_cylinder.h>
49 #include <pcl/sample_consensus/sac_model_cone.h>
50 #include <pcl/sample_consensus/sac_model_line.h>
51 #include <pcl/sample_consensus/sac_model_normal_plane.h>
52 #include <pcl/sample_consensus/sac_model_normal_sphere.h>
53 #include <pcl/sample_consensus/sac_model_parallel_plane.h>
54 #include <pcl/sample_consensus/sac_model_normal_parallel_plane.h>
55 #include <pcl/sample_consensus/sac_model_parallel_line.h>
56 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
57 #include <pcl/sample_consensus/sac_model_plane.h>
58 #include <pcl/sample_consensus/sac_model_sphere.h>
59 
60 namespace pcl
61 {
62  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63  /** \brief @b ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a
64  * separate PointCloud.
65  * \author Radu Bogdan Rusu
66  * \ingroup filters
67  */
68  template<typename PointT>
69  class ProjectInliers : public Filter<PointT>
70  {
75 
76  typedef typename Filter<PointT>::PointCloud PointCloud;
77  typedef typename PointCloud::Ptr PointCloudPtr;
79 
80  typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr;
81  public:
82 
83  typedef boost::shared_ptr< ProjectInliers<PointT> > Ptr;
84  typedef boost::shared_ptr< const ProjectInliers<PointT> > ConstPtr;
85 
86 
87  /** \brief Empty constructor. */
88  ProjectInliers () : model_ (), sacmodel_ (), model_type_ (), copy_all_data_ (false)
89  {
90  filter_name_ = "ProjectInliers";
91  }
92 
93  /** \brief Empty destructor */
94  virtual ~ProjectInliers () {}
95 
96  /** \brief The type of model to use (user given parameter).
97  * \param model the model type (check \a model_types.h)
98  */
99  inline void
100  setModelType (int model)
101  {
102  model_type_ = model;
103  }
104 
105  /** \brief Get the type of SAC model used. */
106  inline int
108  {
109  return (model_type_);
110  }
111 
112  /** \brief Provide a pointer to the model coefficients.
113  * \param model a pointer to the model coefficients
114  */
115  inline void
117  {
118  model_ = model;
119  }
120 
121  /** \brief Get a pointer to the model coefficients. */
124  {
125  return (model_);
126  }
127 
128  /** \brief Set whether all data will be returned, or only the projected inliers.
129  * \param val true if all data should be returned, false if only the projected inliers
130  */
131  inline void
132  setCopyAllData (bool val)
133  {
134  copy_all_data_ = val;
135  }
136 
137  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
138  inline bool
140  {
141  return (copy_all_data_);
142  }
143  protected:
144  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
145  /** \brief Project point indices into a separate PointCloud
146  * \param output the resultant point cloud message
147  */
148  void
149  applyFilter (PointCloud &output);
150 
151  private:
152  /** \brief A pointer to the vector of model coefficients. */
154 
155  /** \brief The model that needs to be segmented. */
156  SampleConsensusModelPtr sacmodel_;
157 
158  /** \brief The type of model to use (user given parameter). */
159  int model_type_;
160 
161  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
162  bool copy_all_data_;
163 
164  /** \brief Initialize the Sample Consensus model and set its parameters.
165  * \param model_type the type of SAC model that is to be used
166  */
167  virtual bool
168  initSACModel (int model_type);
169  };
170 
171  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
172  /** \brief @b ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a
173  * separate PointCloud.
174  * \note setFilterFieldName (), setFilterLimits (), and setFilterLimitNegative () are ignored.
175  * \author Radu Bogdan Rusu
176  * \ingroup filters
177  */
178  template<>
179  class PCL_EXPORTS ProjectInliers<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
180  {
183 
187 
188  typedef SampleConsensusModel<PointXYZ>::Ptr SampleConsensusModelPtr;
189 
190  public:
191  /** \brief Empty constructor. */
192  ProjectInliers () : model_type_ (), copy_all_data_ (false), copy_all_fields_ (true), model_ (), sacmodel_ ()
193  {
194  filter_name_ = "ProjectInliers";
195  }
196 
197  /** \brief Empty destructor */
198  virtual ~ProjectInliers () {}
199 
200  /** \brief The type of model to use (user given parameter).
201  * \param[in] model the model type (check \a model_types.h)
202  */
203  inline void
204  setModelType (int model)
205  {
206  model_type_ = model;
207  }
208 
209  /** \brief Get the type of SAC model used. */
210  inline int
211  getModelType () const
212  {
213  return (model_type_);
214  }
215 
216  /** \brief Provide a pointer to the model coefficients.
217  * \param[in] model a pointer to the model coefficients
218  */
219  inline void
221  {
222  model_ = model;
223  }
224 
225  /** \brief Get a pointer to the model coefficients. */
228  {
229  return (model_);
230  }
231 
232  /** \brief Set whether all fields should be copied, or only the XYZ.
233  * \param[in] val true if all fields will be returned, false if only XYZ
234  */
235  inline void
236  setCopyAllFields (bool val)
237  {
238  copy_all_fields_ = val;
239  }
240 
241  /** \brief Get whether all fields are being copied (true), or only XYZ (false). */
242  inline bool
244  {
245  return (copy_all_fields_);
246  }
247 
248  /** \brief Set whether all data will be returned, or only the projected inliers.
249  * \param[in] val true if all data should be returned, false if only the projected inliers
250  */
251  inline void
252  setCopyAllData (bool val)
253  {
254  copy_all_data_ = val;
255  }
256 
257  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
258  inline bool
259  getCopyAllData () const
260  {
261  return (copy_all_data_);
262  }
263  protected:
264  /** \brief The type of model to use (user given parameter). */
266 
267  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
269 
270  /** \brief True if all fields will be returned, false if only XYZ. Default: true. */
272 
273  /** \brief A pointer to the vector of model coefficients. */
275 
276  void
277  applyFilter (PCLPointCloud2 &output);
278 
279  private:
280  /** \brief The model that needs to be segmented. */
281  SampleConsensusModelPtr sacmodel_;
282 
283  virtual bool
284  initSACModel (int model_type);
285  };
286 }
287 
288 #ifdef PCL_NO_PRECOMPILE
289 #include <pcl/filters/impl/project_inliers.hpp>
290 #endif
291 
292 #endif //#ifndef PCL_FILTERS_PROJECT_INLIERS_H_
boost::shared_ptr< ::pcl::ModelCoefficients const > ModelCoefficientsConstPtr
bool copy_all_fields_
True if all fields will be returned, false if only XYZ.
virtual ~ProjectInliers()
Empty destructor.
PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:73
bool copy_all_data_
True if all data will be returned, false if only the projected inliers.
ModelCoefficientsConstPtr getModelCoefficients() const
Get a pointer to the model coefficients.
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
bool getCopyAllData()
Get whether all data is being copied (true), or only the projected inliers (false).
ProjectInliers()
Empty constructor.
ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a sepa...
boost::shared_ptr< ::pcl::PCLPointCloud2 const > PCLPointCloud2ConstPtr
bool getCopyAllFields() const
Get whether all fields are being copied (true), or only XYZ (false).
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
bool getCopyAllData() const
Get whether all data is being copied (true), or only the projected inliers (false).
PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:72
SampleConsensusModel represents the base model class.
Definition: sac_model.h:66
Filter represents the base filter class.
Definition: filter.h:84
Defines all the PCL implemented PointT point type structures.
void setModelType(int model)
The type of model to use (user given parameter).
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
int getModelType() const
Get the type of SAC model used.
PointCloud represents the base class in PCL for storing collections of 3D points.
int getModelType()
Get the type of SAC model used.
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
boost::shared_ptr< SampleConsensusModel > Ptr
Definition: sac_model.h:74
ModelCoefficientsConstPtr model_
A pointer to the vector of model coefficients.
int model_type_
The type of model to use (user given parameter).
virtual ~ProjectInliers()
Empty destructor.
std::string filter_name_
The filter name.
Definition: filter.h:166
boost::shared_ptr< ProjectInliers< PointT > > Ptr
boost::shared_ptr< const ProjectInliers< PointT > > ConstPtr
void setModelType(int model)
The type of model to use (user given parameter).
ModelCoefficientsConstPtr getModelCoefficients()
Get a pointer to the model coefficients.
void applyFilter(PointCloud &output)
Project point indices into a separate PointCloud.
void setCopyAllFields(bool val)
Set whether all fields should be copied, or only the XYZ.