Point Cloud Library (PCL)  1.12.0-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/sac_model.h>
45 
46 namespace pcl
47 {
48  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
49  /** \brief @b ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a
50  * separate PointCloud.
51  * \author Radu Bogdan Rusu
52  * \ingroup filters
53  */
54  template<typename PointT>
55  class ProjectInliers : public Filter<PointT>
56  {
61 
62  using PointCloud = typename Filter<PointT>::PointCloud;
63  using PointCloudPtr = typename PointCloud::Ptr;
65 
66  using SampleConsensusModelPtr = typename SampleConsensusModel<PointT>::Ptr;
67  public:
68 
69  using Ptr = shared_ptr<ProjectInliers<PointT> >;
70  using ConstPtr = shared_ptr<const ProjectInliers<PointT> >;
71 
72 
73  /** \brief Empty constructor. */
74  ProjectInliers () : sacmodel_ (), model_type_ (), copy_all_data_ (false)
75  {
76  filter_name_ = "ProjectInliers";
77  }
78 
79  /** \brief Empty destructor */
81 
82  /** \brief The type of model to use (user given parameter).
83  * \param model the model type (check \a model_types.h)
84  */
85  inline void
86  setModelType (int model)
87  {
88  model_type_ = model;
89  }
90 
91  /** \brief Get the type of SAC model used. */
92  inline int
94  {
95  return (model_type_);
96  }
97 
98  /** \brief Provide a pointer to the model coefficients.
99  * \param model a pointer to the model coefficients
100  */
101  inline void
103  {
104  model_ = model;
105  }
106 
107  /** \brief Get a pointer to the model coefficients. */
110  {
111  return (model_);
112  }
113 
114  /** \brief Set whether all data will be returned, or only the projected inliers.
115  * \param val true if all data should be returned, false if only the projected inliers
116  */
117  inline void
118  setCopyAllData (bool val)
119  {
120  copy_all_data_ = val;
121  }
122 
123  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
124  inline bool
126  {
127  return (copy_all_data_);
128  }
129  protected:
130  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
131  /** \brief Project point indices into a separate PointCloud
132  * \param output the resultant point cloud message
133  */
134  void
135  applyFilter (PointCloud &output) override;
136 
137  private:
138  /** \brief A pointer to the vector of model coefficients. */
140 
141  /** \brief The model that needs to be segmented. */
142  SampleConsensusModelPtr sacmodel_;
143 
144  /** \brief The type of model to use (user given parameter). */
145  int model_type_;
146 
147  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
148  bool copy_all_data_;
149 
150  /** \brief Initialize the Sample Consensus model and set its parameters.
151  * \param model_type the type of SAC model that is to be used
152  */
153  virtual bool
154  initSACModel (int model_type);
155  };
156 
157  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
158  /** \brief @b ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a
159  * separate PointCloud.
160  * \author Radu Bogdan Rusu
161  * \ingroup filters
162  */
163  template<>
164  class PCL_EXPORTS ProjectInliers<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
165  {
168 
172 
173  using SampleConsensusModelPtr = SampleConsensusModel<PointXYZ>::Ptr;
174 
175  public:
176  /** \brief Empty constructor. */
177  ProjectInliers () : model_type_ (), copy_all_data_ (false), copy_all_fields_ (true)
178  {
179  filter_name_ = "ProjectInliers";
180  }
181 
182  /** \brief Empty destructor */
184 
185  /** \brief The type of model to use (user given parameter).
186  * \param[in] model the model type (check \a model_types.h)
187  */
188  inline void
189  setModelType (int model)
190  {
191  model_type_ = model;
192  }
193 
194  /** \brief Get the type of SAC model used. */
195  inline int
196  getModelType () const
197  {
198  return (model_type_);
199  }
200 
201  /** \brief Provide a pointer to the model coefficients.
202  * \param[in] model a pointer to the model coefficients
203  */
204  inline void
206  {
207  model_ = model;
208  }
209 
210  /** \brief Get a pointer to the model coefficients. */
213  {
214  return (model_);
215  }
216 
217  /** \brief Set whether all fields should be copied, or only the XYZ.
218  * \param[in] val true if all fields will be returned, false if only XYZ
219  */
220  inline void
221  setCopyAllFields (bool val)
222  {
223  copy_all_fields_ = val;
224  }
225 
226  /** \brief Get whether all fields are being copied (true), or only XYZ (false). */
227  inline bool
229  {
230  return (copy_all_fields_);
231  }
232 
233  /** \brief Set whether all data will be returned, or only the projected inliers.
234  * \param[in] val true if all data should be returned, false if only the projected inliers
235  */
236  inline void
237  setCopyAllData (bool val)
238  {
239  copy_all_data_ = val;
240  }
241 
242  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
243  inline bool
244  getCopyAllData () const
245  {
246  return (copy_all_data_);
247  }
248  protected:
249  /** \brief The type of model to use (user given parameter). */
251 
252  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
254 
255  /** \brief True if all fields will be returned, false if only XYZ. Default: true. */
257 
258  /** \brief A pointer to the vector of model coefficients. */
260 
261  void
262  applyFilter (PCLPointCloud2 &output) override;
263 
264  private:
265  /** \brief The model that needs to be segmented. */
266  SampleConsensusModelPtr sacmodel_;
267 
268  virtual bool
269  initSACModel (int model_type);
270  };
271 }
272 
273 #ifdef PCL_NO_PRECOMPILE
274 #include <pcl/filters/impl/project_inliers.hpp>
275 #endif
pcl
Definition: convolution.h:46
point_types.h
pcl::Filter::Ptr
shared_ptr< Filter< PointT > > Ptr
Definition: filter.h:83
pcl::ProjectInliers::setModelCoefficients
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
Definition: project_inliers.h:102
pcl::ProjectInliers< pcl::PCLPointCloud2 >::ProjectInliers
ProjectInliers()
Empty constructor.
Definition: project_inliers.h:177
pcl::PCLBase::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
pcl::PCLBase::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition: PCLPointCloud2.h:35
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getModelCoefficients
ModelCoefficientsConstPtr getModelCoefficients() const
Get a pointer to the model coefficients.
Definition: project_inliers.h:212
pcl::ProjectInliers< pcl::PCLPointCloud2 >::copy_all_data_
bool copy_all_data_
True if all data will be returned, false if only the projected inliers.
Definition: project_inliers.h:253
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:186
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::ProjectInliers::getCopyAllData
bool getCopyAllData()
Get whether all data is being copied (true), or only the projected inliers (false).
Definition: project_inliers.h:125
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getCopyAllFields
bool getCopyAllFields() const
Get whether all fields are being copied (true), or only XYZ (false).
Definition: project_inliers.h:228
pcl::ProjectInliers::ProjectInliers
ProjectInliers()
Empty constructor.
Definition: project_inliers.h:74
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getCopyAllData
bool getCopyAllData() const
Get whether all data is being copied (true), or only the projected inliers (false).
Definition: project_inliers.h:244
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:185
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:36
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setModelType
void setModelType(int model)
The type of model to use (user given parameter).
Definition: project_inliers.h:189
pcl::Filter::ConstPtr
shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:84
pcl::ProjectInliers::getModelType
int getModelType()
Get the type of SAC model used.
Definition: project_inliers.h:93
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setModelCoefficients
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
Definition: project_inliers.h:205
pcl::SampleConsensusModel::Ptr
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:77
pcl::ProjectInliers::~ProjectInliers
~ProjectInliers()
Empty destructor.
Definition: project_inliers.h:80
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getModelType
int getModelType() const
Get the type of SAC model used.
Definition: project_inliers.h:196
pcl::Filter
Filter represents the base filter class.
Definition: filter.h:80
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setCopyAllData
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
Definition: project_inliers.h:237
pcl::ProjectInliers::applyFilter
void applyFilter(PointCloud &output) override
Project point indices into a separate PointCloud.
Definition: project_inliers.hpp:57
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:16
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:158
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
pcl::ModelCoefficientsConstPtr
ModelCoefficients::ConstPtr ModelCoefficientsConstPtr
Definition: ModelCoefficients.h:27
pcl::ProjectInliers< pcl::PCLPointCloud2 >::model_
ModelCoefficientsConstPtr model_
A pointer to the vector of model coefficients.
Definition: project_inliers.h:259
pcl::ProjectInliers
ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a sepa...
Definition: project_inliers.h:55
pcl::ProjectInliers::setCopyAllData
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
Definition: project_inliers.h:118
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
pcl::ProjectInliers::setModelType
void setModelType(int model)
The type of model to use (user given parameter).
Definition: project_inliers.h:86
pcl::ProjectInliers< pcl::PCLPointCloud2 >::~ProjectInliers
~ProjectInliers()
Empty destructor.
Definition: project_inliers.h:183
pcl::ProjectInliers< pcl::PCLPointCloud2 >::model_type_
int model_type_
The type of model to use (user given parameter).
Definition: project_inliers.h:250
pcl::ProjectInliers::getModelCoefficients
ModelCoefficientsConstPtr getModelCoefficients()
Get a pointer to the model coefficients.
Definition: project_inliers.h:109
pcl::SampleConsensusModel
SampleConsensusModel represents the base model class.
Definition: sac_model.h:69
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:323
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setCopyAllFields
void setCopyAllFields(bool val)
Set whether all fields should be copied, or only the XYZ.
Definition: project_inliers.h:221
pcl::ProjectInliers< pcl::PCLPointCloud2 >::copy_all_fields_
bool copy_all_fields_
True if all fields will be returned, false if only XYZ.
Definition: project_inliers.h:256