Point Cloud Library (PCL)  1.9.1-dev
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 #pragma once
39 
40 #include <pcl/point_types.h>
41 #include <pcl/filters/filter.h>
42 #include <pcl/ModelCoefficients.h>
43 // Sample Consensus models
44 #include <pcl/sample_consensus/model_types.h>
45 #include <pcl/sample_consensus/sac_model.h>
46 #include <pcl/sample_consensus/sac_model_circle.h>
47 #include <pcl/sample_consensus/sac_model_cylinder.h>
48 #include <pcl/sample_consensus/sac_model_cone.h>
49 #include <pcl/sample_consensus/sac_model_line.h>
50 #include <pcl/sample_consensus/sac_model_normal_plane.h>
51 #include <pcl/sample_consensus/sac_model_normal_sphere.h>
52 #include <pcl/sample_consensus/sac_model_parallel_plane.h>
53 #include <pcl/sample_consensus/sac_model_normal_parallel_plane.h>
54 #include <pcl/sample_consensus/sac_model_parallel_line.h>
55 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
56 #include <pcl/sample_consensus/sac_model_plane.h>
57 #include <pcl/sample_consensus/sac_model_sphere.h>
58 
59 namespace pcl
60 {
61  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62  /** \brief @b ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a
63  * separate PointCloud.
64  * \author Radu Bogdan Rusu
65  * \ingroup filters
66  */
67  template<typename PointT>
68  class ProjectInliers : public Filter<PointT>
69  {
74 
75  typedef typename Filter<PointT>::PointCloud PointCloud;
76  typedef typename PointCloud::Ptr PointCloudPtr;
78 
79  typedef typename SampleConsensusModel<PointT>::Ptr SampleConsensusModelPtr;
80  public:
81 
82  typedef boost::shared_ptr< ProjectInliers<PointT> > Ptr;
83  typedef boost::shared_ptr< const ProjectInliers<PointT> > ConstPtr;
84 
85 
86  /** \brief Empty constructor. */
87  ProjectInliers () : model_ (), sacmodel_ (), model_type_ (), copy_all_data_ (false)
88  {
89  filter_name_ = "ProjectInliers";
90  }
91 
92  /** \brief Empty destructor */
94 
95  /** \brief The type of model to use (user given parameter).
96  * \param model the model type (check \a model_types.h)
97  */
98  inline void
99  setModelType (int model)
100  {
101  model_type_ = model;
102  }
103 
104  /** \brief Get the type of SAC model used. */
105  inline int
107  {
108  return (model_type_);
109  }
110 
111  /** \brief Provide a pointer to the model coefficients.
112  * \param model a pointer to the model coefficients
113  */
114  inline void
116  {
117  model_ = model;
118  }
119 
120  /** \brief Get a pointer to the model coefficients. */
123  {
124  return (model_);
125  }
126 
127  /** \brief Set whether all data will be returned, or only the projected inliers.
128  * \param val true if all data should be returned, false if only the projected inliers
129  */
130  inline void
131  setCopyAllData (bool val)
132  {
133  copy_all_data_ = val;
134  }
135 
136  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
137  inline bool
139  {
140  return (copy_all_data_);
141  }
142  protected:
143  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
144  /** \brief Project point indices into a separate PointCloud
145  * \param output the resultant point cloud message
146  */
147  void
148  applyFilter (PointCloud &output) override;
149 
150  private:
151  /** \brief A pointer to the vector of model coefficients. */
153 
154  /** \brief The model that needs to be segmented. */
155  SampleConsensusModelPtr sacmodel_;
156 
157  /** \brief The type of model to use (user given parameter). */
158  int model_type_;
159 
160  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
161  bool copy_all_data_;
162 
163  /** \brief Initialize the Sample Consensus model and set its parameters.
164  * \param model_type the type of SAC model that is to be used
165  */
166  virtual bool
167  initSACModel (int model_type);
168  };
169 
170  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
171  /** \brief @b ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a
172  * separate PointCloud.
173  * \note setFilterFieldName (), setFilterLimits (), and setFilterLimitNegative () are ignored.
174  * \author Radu Bogdan Rusu
175  * \ingroup filters
176  */
177  template<>
178  class PCL_EXPORTS ProjectInliers<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
179  {
182 
186 
187  typedef SampleConsensusModel<PointXYZ>::Ptr SampleConsensusModelPtr;
188 
189  public:
190  /** \brief Empty constructor. */
191  ProjectInliers () : model_type_ (), copy_all_data_ (false), copy_all_fields_ (true), model_ (), sacmodel_ ()
192  {
193  filter_name_ = "ProjectInliers";
194  }
195 
196  /** \brief Empty destructor */
198 
199  /** \brief The type of model to use (user given parameter).
200  * \param[in] model the model type (check \a model_types.h)
201  */
202  inline void
203  setModelType (int model)
204  {
205  model_type_ = model;
206  }
207 
208  /** \brief Get the type of SAC model used. */
209  inline int
210  getModelType () const
211  {
212  return (model_type_);
213  }
214 
215  /** \brief Provide a pointer to the model coefficients.
216  * \param[in] model a pointer to the model coefficients
217  */
218  inline void
220  {
221  model_ = model;
222  }
223 
224  /** \brief Get a pointer to the model coefficients. */
227  {
228  return (model_);
229  }
230 
231  /** \brief Set whether all fields should be copied, or only the XYZ.
232  * \param[in] val true if all fields will be returned, false if only XYZ
233  */
234  inline void
235  setCopyAllFields (bool val)
236  {
237  copy_all_fields_ = val;
238  }
239 
240  /** \brief Get whether all fields are being copied (true), or only XYZ (false). */
241  inline bool
243  {
244  return (copy_all_fields_);
245  }
246 
247  /** \brief Set whether all data will be returned, or only the projected inliers.
248  * \param[in] val true if all data should be returned, false if only the projected inliers
249  */
250  inline void
251  setCopyAllData (bool val)
252  {
253  copy_all_data_ = val;
254  }
255 
256  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
257  inline bool
258  getCopyAllData () const
259  {
260  return (copy_all_data_);
261  }
262  protected:
263  /** \brief The type of model to use (user given parameter). */
265 
266  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
268 
269  /** \brief True if all fields will be returned, false if only XYZ. Default: true. */
271 
272  /** \brief A pointer to the vector of model coefficients. */
274 
275  void
276  applyFilter (PCLPointCloud2 &output) override;
277 
278  private:
279  /** \brief The model that needs to be segmented. */
280  SampleConsensusModelPtr sacmodel_;
281 
282  virtual bool
283  initSACModel (int model_type);
284  };
285 }
286 
287 #ifdef PCL_NO_PRECOMPILE
288 #include <pcl/filters/impl/project_inliers.hpp>
289 #endif
boost::shared_ptr< ::pcl::ModelCoefficients const > ModelCoefficientsConstPtr
bool copy_all_fields_
True if all fields will be returned, false if only XYZ.
bool getCopyAllFields() const
Get whether all fields are being copied (true), or only XYZ (false).
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.
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
bool getCopyAllData() const
Get whether all data is being copied (true), or only the projected inliers (false).
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
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
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:427
PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:72
SampleConsensusModel represents the base model class.
Definition: sac_model.h:65
Filter represents the base filter class.
Definition: filter.h:83
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:428
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
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.
~ProjectInliers()
Empty destructor.
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
int getModelType() const
Get the type of SAC model used.
boost::shared_ptr< SampleConsensusModel > Ptr
Definition: sac_model.h:73
ModelCoefficientsConstPtr model_
A pointer to the vector of model coefficients.
void applyFilter(PointCloud &output) override
Project point indices into a separate PointCloud.
int model_type_
The type of model to use (user given parameter).
std::string filter_name_
The filter name.
Definition: filter.h:165
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 setCopyAllFields(bool val)
Set whether all fields should be copied, or only the XYZ.
ModelCoefficientsConstPtr getModelCoefficients() const
Get a pointer to the model coefficients.