Point Cloud Library (PCL)  1.11.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/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  * \note setFilterFieldName (), setFilterLimits (), and setFilterLimitNegative () are ignored.
161  * \author Radu Bogdan Rusu
162  * \ingroup filters
163  */
164  template<>
165  class PCL_EXPORTS ProjectInliers<pcl::PCLPointCloud2> : public Filter<pcl::PCLPointCloud2>
166  {
169 
173 
174  using SampleConsensusModelPtr = SampleConsensusModel<PointXYZ>::Ptr;
175 
176  public:
177  /** \brief Empty constructor. */
178  ProjectInliers () : model_type_ (), copy_all_data_ (false), copy_all_fields_ (true)
179  {
180  filter_name_ = "ProjectInliers";
181  }
182 
183  /** \brief Empty destructor */
185 
186  /** \brief The type of model to use (user given parameter).
187  * \param[in] model the model type (check \a model_types.h)
188  */
189  inline void
190  setModelType (int model)
191  {
192  model_type_ = model;
193  }
194 
195  /** \brief Get the type of SAC model used. */
196  inline int
197  getModelType () const
198  {
199  return (model_type_);
200  }
201 
202  /** \brief Provide a pointer to the model coefficients.
203  * \param[in] model a pointer to the model coefficients
204  */
205  inline void
207  {
208  model_ = model;
209  }
210 
211  /** \brief Get a pointer to the model coefficients. */
214  {
215  return (model_);
216  }
217 
218  /** \brief Set whether all fields should be copied, or only the XYZ.
219  * \param[in] val true if all fields will be returned, false if only XYZ
220  */
221  inline void
222  setCopyAllFields (bool val)
223  {
224  copy_all_fields_ = val;
225  }
226 
227  /** \brief Get whether all fields are being copied (true), or only XYZ (false). */
228  inline bool
230  {
231  return (copy_all_fields_);
232  }
233 
234  /** \brief Set whether all data will be returned, or only the projected inliers.
235  * \param[in] val true if all data should be returned, false if only the projected inliers
236  */
237  inline void
238  setCopyAllData (bool val)
239  {
240  copy_all_data_ = val;
241  }
242 
243  /** \brief Get whether all data is being copied (true), or only the projected inliers (false). */
244  inline bool
245  getCopyAllData () const
246  {
247  return (copy_all_data_);
248  }
249  protected:
250  /** \brief The type of model to use (user given parameter). */
252 
253  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
255 
256  /** \brief True if all fields will be returned, false if only XYZ. Default: true. */
258 
259  /** \brief A pointer to the vector of model coefficients. */
261 
262  void
263  applyFilter (PCLPointCloud2 &output) override;
264 
265  private:
266  /** \brief The model that needs to be segmented. */
267  SampleConsensusModelPtr sacmodel_;
268 
269  virtual bool
270  initSACModel (int model_type);
271  };
272 }
273 
274 #ifdef PCL_NO_PRECOMPILE
275 #include <pcl/filters/impl/project_inliers.hpp>
276 #endif
pcl
Definition: convolution.h:46
point_types.h
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:178
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:213
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:254
pcl::ProjectInliers::Ptr
shared_ptr< ProjectInliers< PointT > > Ptr
Definition: project_inliers.h:69
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:229
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:245
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:190
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:206
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:197
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:238
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:428
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:260
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:429
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:184
pcl::ProjectInliers< pcl::PCLPointCloud2 >::model_type_
int model_type_
The type of model to use (user given parameter).
Definition: project_inliers.h:251
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:337
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setCopyAllFields
void setCopyAllFields(bool val)
Set whether all fields should be copied, or only the XYZ.
Definition: project_inliers.h:222
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:257