Point Cloud Library (PCL)  1.11.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 #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  using PointCloud = typename Filter<PointT>::PointCloud;
76  using PointCloudPtr = typename PointCloud::Ptr;
78 
79  using SampleConsensusModelPtr = typename SampleConsensusModel<PointT>::Ptr;
80  public:
81 
82  using Ptr = shared_ptr<ProjectInliers<PointT> >;
83  using ConstPtr = shared_ptr<const ProjectInliers<PointT> >;
84 
85 
86  /** \brief Empty constructor. */
87  ProjectInliers () : 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  using SampleConsensusModelPtr = SampleConsensusModel<PointXYZ>::Ptr;
188 
189  public:
190  /** \brief Empty constructor. */
191  ProjectInliers () : model_type_ (), copy_all_data_ (false), copy_all_fields_ (true)
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
pcl
Definition: convolution.h:46
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl::ProjectInliers::setModelCoefficients
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
Definition: project_inliers.h:115
pcl::ProjectInliers< pcl::PCLPointCloud2 >::ProjectInliers
ProjectInliers()
Empty constructor.
Definition: project_inliers.h:191
pcl::PCLBase::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:77
pcl::PCLBase::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:76
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition: PCLPointCloud2.h:34
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getModelCoefficients
ModelCoefficientsConstPtr getModelCoefficients() const
Get a pointer to the model coefficients.
Definition: project_inliers.h:226
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:267
pcl::ProjectInliers::Ptr
shared_ptr< ProjectInliers< PointT > > Ptr
Definition: project_inliers.h:82
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:189
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:181
pcl::ProjectInliers::getCopyAllData
bool getCopyAllData()
Get whether all data is being copied (true), or only the projected inliers (false).
Definition: project_inliers.h:138
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getCopyAllFields
bool getCopyAllFields() const
Get whether all fields are being copied (true), or only XYZ (false).
Definition: project_inliers.h:242
pcl::ProjectInliers::ProjectInliers
ProjectInliers()
Empty constructor.
Definition: project_inliers.h:87
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:258
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:188
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:35
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setModelType
void setModelType(int model)
The type of model to use (user given parameter).
Definition: project_inliers.h:203
pcl::Filter::ConstPtr
shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:87
pcl::ProjectInliers::getModelType
int getModelType()
Get the type of SAC model used.
Definition: project_inliers.h:106
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setModelCoefficients
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
Definition: project_inliers.h:219
pcl::SampleConsensusModel::Ptr
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:78
pcl::ProjectInliers::~ProjectInliers
~ProjectInliers()
Empty destructor.
Definition: project_inliers.h:93
pcl::ProjectInliers< pcl::PCLPointCloud2 >::getModelType
int getModelType() const
Get the type of SAC model used.
Definition: project_inliers.h:210
pcl::Filter
Filter represents the base filter class.
Definition: filter.h:84
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:251
pcl::ProjectInliers::applyFilter
void applyFilter(PointCloud &output) override
Project point indices into a separate PointCloud.
Definition: project_inliers.hpp:45
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:16
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:161
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
pcl::ModelCoefficientsConstPtr
ModelCoefficients::ConstPtr ModelCoefficientsConstPtr
Definition: ModelCoefficients.h:28
pcl::ProjectInliers< pcl::PCLPointCloud2 >::model_
ModelCoefficientsConstPtr model_
A pointer to the vector of model coefficients.
Definition: project_inliers.h:273
pcl::ProjectInliers< pcl::PCLPointCloud2 >::applyFilter
void applyFilter(PCLPointCloud2 &output) override
Abstract filter method.
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:69
pcl::ProjectInliers::setCopyAllData
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
Definition: project_inliers.h:131
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:430
pcl::ProjectInliers::setModelType
void setModelType(int model)
The type of model to use (user given parameter).
Definition: project_inliers.h:99
pcl::ProjectInliers< pcl::PCLPointCloud2 >::~ProjectInliers
~ProjectInliers()
Empty destructor.
Definition: project_inliers.h:197
pcl::ProjectInliers< pcl::PCLPointCloud2 >::model_type_
int model_type_
The type of model to use (user given parameter).
Definition: project_inliers.h:264
pcl::ProjectInliers::getModelCoefficients
ModelCoefficientsConstPtr getModelCoefficients()
Get a pointer to the model coefficients.
Definition: project_inliers.h:122
pcl::SampleConsensusModel
SampleConsensusModel represents the base model class.
Definition: sac_model.h:71
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:328
pcl::ProjectInliers< pcl::PCLPointCloud2 >::setCopyAllFields
void setCopyAllFields(bool val)
Set whether all fields should be copied, or only the XYZ.
Definition: project_inliers.h:235
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:270