Point Cloud Library (PCL)  1.14.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_ ()
75  {
76  filter_name_ = "ProjectInliers";
77  }
78 
79  /** \brief Empty destructor */
80  ~ProjectInliers () override = default;
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_{0};
146 
147  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
148  bool copy_all_data_{false};
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. */
178  {
179  filter_name_ = "ProjectInliers";
180  }
181 
182  /** \brief Empty destructor */
183  ~ProjectInliers () override = default;
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). */
250  int model_type_{0};
251 
252  /** \brief True if all data will be returned, false if only the projected inliers. Default: false. */
253  bool copy_all_data_{false};
254 
255  /** \brief True if all fields will be returned, false if only XYZ. Default: true. */
256  bool copy_all_fields_{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
Filter represents the base filter class.
Definition: filter.h:81
shared_ptr< Filter< PointT > > Ptr
Definition: filter.h:83
shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:84
std::string filter_name_
The filter name.
Definition: filter.h:158
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:185
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:186
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
void setCopyAllFields(bool val)
Set whether all fields should be copied, or only the XYZ.
int getModelType() const
Get the type of SAC model used.
bool getCopyAllFields() const
Get whether all fields are being copied (true), or only XYZ (false).
void setCopyAllData(bool val)
Set whether all data will be returned, or only the projected inliers.
bool getCopyAllData() const
Get whether all data is being copied (true), or only the projected inliers (false).
ModelCoefficientsConstPtr model_
A pointer to the vector of model coefficients.
void applyFilter(PCLPointCloud2 &output) override
Abstract filter method.
ModelCoefficientsConstPtr getModelCoefficients() const
Get a pointer to the model coefficients.
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
~ProjectInliers() override=default
Empty destructor.
void setModelType(int model)
The type of model to use (user given parameter).
ProjectInliers uses a model and a set of inlier indices from a PointCloud to project them into a sepa...
~ProjectInliers() override=default
Empty destructor.
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 constructor.
bool getCopyAllData()
Get whether all data is being copied (true), or only the projected inliers (false).
void applyFilter(PointCloud &output) override
Project point indices into a separate PointCloud.
void setModelCoefficients(const ModelCoefficientsConstPtr &model)
Provide a pointer to the model coefficients.
ModelCoefficientsConstPtr getModelCoefficients()
Get a pointer to the model coefficients.
void setModelType(int model)
The type of model to use (user given parameter).
SampleConsensusModel represents the base model class.
Definition: sac_model.h:71
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:78
Defines all the PCL implemented PointT point type structures.
ModelCoefficients::ConstPtr ModelCoefficientsConstPtr
#define PCL_EXPORTS
Definition: pcl_macros.h:323
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr