Point Cloud Library (PCL)  1.14.0-dev
sac_model_stick.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id: sac_model_line.h 2326 2011-08-31 07:48:25Z rusu $
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/sample_consensus/sac_model.h>
44 #include <pcl/sample_consensus/model_types.h>
45 
46 namespace pcl
47 {
48  /** \brief SampleConsensusModelStick defines a model for 3D stick segmentation.
49  * A stick is a line with a user given minimum/maximum width.
50  * The model coefficients are defined as:
51  * - \b point_on_line.x : the X coordinate of a point on the line
52  * - \b point_on_line.y : the Y coordinate of a point on the line
53  * - \b point_on_line.z : the Z coordinate of a point on the line
54  * - \b line_direction.x : the X coordinate of a line's direction
55  * - \b line_direction.y : the Y coordinate of a line's direction
56  * - \b line_direction.z : the Z coordinate of a line's direction
57  * - \b line_width : the width of the line
58  *
59  * \warning This model is considered deprecated. The coefficients are used inconsistently in the methods, and the last coefficient (line width) is unused. We recommend to use the line or cylinder model instead.
60  * \author Radu B. Rusu
61  * \ingroup sample_consensus
62  */
63  template <typename PointT>
64 #ifdef SAC_MODEL_STICK_DONT_WARN_DEPRECATED
65  class SampleConsensusModelStick : public SampleConsensusModel<PointT>
66 #else
67  class PCL_DEPRECATED(1, 17, "Use line or cylinder model instead") SampleConsensusModelStick : public SampleConsensusModel<PointT>
68 #endif
69  {
70  public:
78 
82 
83  using Ptr = shared_ptr<SampleConsensusModelStick<PointT> >;
84  using ConstPtr = shared_ptr<const SampleConsensusModelStick<PointT>>;
85 
86  /** \brief Constructor for base SampleConsensusModelStick.
87  * \param[in] cloud the input point cloud dataset
88  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
89  */
91  bool random = false)
92  : SampleConsensusModel<PointT> (cloud, random)
93  {
94  model_name_ = "SampleConsensusModelStick";
95  sample_size_ = 2;
96  model_size_ = 7;
97  }
98 
99  /** \brief Constructor for base SampleConsensusModelStick.
100  * \param[in] cloud the input point cloud dataset
101  * \param[in] indices a vector of point indices to be used from \a cloud
102  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
103  */
105  const Indices &indices,
106  bool random = false)
107  : SampleConsensusModel<PointT> (cloud, indices, random)
108  {
109  model_name_ = "SampleConsensusModelStick";
110  sample_size_ = 2;
111  model_size_ = 7;
112  }
113 
114  /** \brief Empty destructor */
115  ~SampleConsensusModelStick () override = default;
116 
117  /** \brief Check whether the given index samples can form a valid stick model, compute the model coefficients from
118  * these samples and store them internally in model_coefficients_. The stick coefficients are represented by a
119  * point and a line direction
120  * \param[in] samples the point indices found as possible good candidates for creating a valid model
121  * \param[out] model_coefficients the resultant model coefficients
122  */
123  bool
124  computeModelCoefficients (const Indices &samples,
125  Eigen::VectorXf &model_coefficients) const override;
126 
127  /** \brief Compute all squared distances from the cloud data to a given stick model.
128  * \param[in] model_coefficients the coefficients of a stick model that we need to compute distances to
129  * \param[out] distances the resultant estimated squared distances
130  */
131  void
132  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
133  std::vector<double> &distances) const override;
134 
135  /** \brief Select all the points which respect the given model coefficients as inliers.
136  * \param[in] model_coefficients the coefficients of a stick model that we need to compute distances to
137  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
138  * \param[out] inliers the resultant model inliers
139  */
140  void
141  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
142  const double threshold,
143  Indices &inliers) override;
144 
145  /** \brief Count all the points which respect the given model coefficients as inliers.
146  *
147  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
148  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
149  * \return the resultant number of inliers
150  */
151  std::size_t
152  countWithinDistance (const Eigen::VectorXf &model_coefficients,
153  const double threshold) const override;
154 
155  /** \brief Recompute the stick coefficients using the given inlier set and return them to the user.
156  * @note: these are the coefficients of the stick model after refinement (e.g. after SVD)
157  * \param[in] inliers the data inliers found as supporting the model
158  * \param[in] model_coefficients the initial guess for the model coefficients
159  * \param[out] optimized_coefficients the resultant recomputed coefficients after optimization
160  */
161  void
162  optimizeModelCoefficients (const Indices &inliers,
163  const Eigen::VectorXf &model_coefficients,
164  Eigen::VectorXf &optimized_coefficients) const override;
165 
166  /** \brief Create a new point cloud with inliers projected onto the stick model.
167  * \param[in] inliers the data inliers that we want to project on the stick model
168  * \param[in] model_coefficients the *normalized* coefficients of a stick model
169  * \param[out] projected_points the resultant projected points
170  * \param[in] copy_data_fields set to true if we need to copy the other data fields
171  */
172  void
173  projectPoints (const Indices &inliers,
174  const Eigen::VectorXf &model_coefficients,
175  PointCloud &projected_points,
176  bool copy_data_fields = true) const override;
177 
178  /** \brief Verify whether a subset of indices verifies the given stick model coefficients.
179  * \param[in] indices the data indices that need to be tested against the plane model
180  * \param[in] model_coefficients the plane model coefficients
181  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
182  */
183  bool
184  doSamplesVerifyModel (const std::set<index_t> &indices,
185  const Eigen::VectorXf &model_coefficients,
186  const double threshold) const override;
187 
188  /** \brief Return a unique id for this model (SACMODEL_STICK). */
189  inline pcl::SacModel
190  getModelType () const override { return (SACMODEL_STICK); }
191 
192  protected:
195 
196  /** \brief Check if a sample of indices results in a good sample of points
197  * indices.
198  * \param[in] samples the resultant index samples
199  */
200  bool
201  isSampleGood (const Indices &samples) const override;
202  };
203 }
204 
205 #ifdef PCL_NO_PRECOMPILE
206 #include <pcl/sample_consensus/impl/sac_model_stick.hpp>
207 #endif
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
SampleConsensusModel represents the base model class.
Definition: sac_model.h:71
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:78
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:589
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: sac_model.h:74
std::string model_name_
The model name.
Definition: sac_model.h:551
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:592
typename PointCloud::Ptr PointCloudPtr
Definition: sac_model.h:75
shared_ptr< const SampleConsensusModel< PointT > > ConstPtr
Definition: sac_model.h:79
SampleConsensusModelStick defines a model for 3D stick segmentation.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
bool doSamplesVerifyModel(const std::set< index_t > &indices, const Eigen::VectorXf &model_coefficients, const double threshold) const override
Verify whether a subset of indices verifies the given stick model coefficients.
SampleConsensusModelStick(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelStick.
bool computeModelCoefficients(const Indices &samples, Eigen::VectorXf &model_coefficients) const override
Check whether the given index samples can form a valid stick model, compute the model coefficients fr...
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all squared distances from the cloud data to a given stick model.
~SampleConsensusModelStick() override=default
Empty destructor.
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_STICK).
bool isSampleGood(const Indices &samples) const override
Check if a sample of indices results in a good sample of points indices.
SampleConsensusModelStick(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelStick.
void projectPoints(const Indices &inliers, const Eigen::VectorXf &model_coefficients, PointCloud &projected_points, bool copy_data_fields=true) const override
Create a new point cloud with inliers projected onto the stick model.
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
void optimizeModelCoefficients(const Indices &inliers, const Eigen::VectorXf &model_coefficients, Eigen::VectorXf &optimized_coefficients) const override
Recompute the stick coefficients using the given inlier set and return them to the user.
SacModel
Definition: model_types.h:46
@ SACMODEL_STICK
Definition: model_types.h:64
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
#define PCL_DEPRECATED(Major, Minor, Message)
macro for compatibility across compilers and help remove old deprecated items for the Major....
Definition: pcl_macros.h:156
A point structure representing Euclidean xyz coordinates, and the RGB color.