Point Cloud Library (PCL)  1.14.1-dev
sac_model_parallel_line.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$
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/sample_consensus/sac_model_line.h>
44 
45 namespace pcl
46 {
47  /** \brief SampleConsensusModelParallelLine defines a model for 3D line segmentation using additional angular
48  * constraints.
49  *
50  * Checking for inliers will not only involve a "distance to model" criterion, but also an additional "maximum
51  * angular deviation" between the line's direction and a user-specified axis.
52  *
53  * The model coefficients are defined as:
54  * - \b point_on_line.x : the X coordinate of a point on the line
55  * - \b point_on_line.y : the Y coordinate of a point on the line
56  * - \b point_on_line.z : the Z coordinate of a point on the line
57  * - \b line_direction.x : the X coordinate of a line's direction
58  * - \b line_direction.y : the Y coordinate of a line's direction
59  * - \b line_direction.z : the Z coordinate of a line's direction
60  *
61  * \author Radu B. Rusu
62  * \ingroup sample_consensus
63  */
64  template <typename PointT>
66  {
67  public:
69 
73 
74  using Ptr = shared_ptr<SampleConsensusModelParallelLine<PointT> >;
75  using ConstPtr = shared_ptr<const SampleConsensusModelParallelLine<PointT>>;
76 
77  /** \brief Constructor for base SampleConsensusModelParallelLine.
78  * \param[in] cloud the input point cloud dataset
79  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
80  */
82  bool random = false)
83  : SampleConsensusModelLine<PointT> (cloud, random)
84  , axis_ (Eigen::Vector3f::Zero ())
85  , eps_angle_ (0.0)
86  {
87  model_name_ = "SampleConsensusModelParallelLine";
88  sample_size_ = 2;
89  model_size_ = 6;
90  }
91 
92  /** \brief Constructor for base SampleConsensusModelParallelLine.
93  * \param[in] cloud the input point cloud dataset
94  * \param[in] indices a vector of point indices to be used from \a cloud
95  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
96  */
98  const Indices &indices,
99  bool random = false)
100  : SampleConsensusModelLine<PointT> (cloud, indices, random)
101  , axis_ (Eigen::Vector3f::Zero ())
102  , eps_angle_ (0.0)
103  {
104  model_name_ = "SampleConsensusModelParallelLine";
105  sample_size_ = 2;
106  model_size_ = 6;
107  }
108 
109  /** \brief Empty destructor */
110  ~SampleConsensusModelParallelLine () override = default;
111 
112  /** \brief Set the axis along which we need to search for a line.
113  * \param[in] ax the axis along which we need to search for a line
114  */
115  inline void
116  setAxis (const Eigen::Vector3f &ax) { axis_ = ax; axis_.normalize (); }
117 
118  /** \brief Get the axis along which we need to search for a line. */
119  inline Eigen::Vector3f
120  getAxis () const { return (axis_); }
121 
122  /** \brief Set the angle epsilon (delta) threshold.
123  * \param[in] ea the maximum allowed difference between the line direction and the given axis (in radians).
124  */
125  inline void
126  setEpsAngle (const double ea) { eps_angle_ = ea; }
127 
128  /** \brief Get the angle epsilon (delta) threshold (in radians). */
129  inline double getEpsAngle () const { return (eps_angle_); }
130 
131  /** \brief Select all the points which respect the given model coefficients as inliers.
132  * \param[in] model_coefficients the coefficients of a line model that we need to compute distances to
133  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
134  * \param[out] inliers the resultant model inliers
135  */
136  void
137  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
138  const double threshold,
139  Indices &inliers) override;
140 
141  /** \brief Count all the points which respect the given model coefficients as inliers.
142  *
143  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
144  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
145  * \return the resultant number of inliers
146  */
147  std::size_t
148  countWithinDistance (const Eigen::VectorXf &model_coefficients,
149  const double threshold) const override;
150 
151  /** \brief Compute all squared distances from the cloud data to a given line model.
152  * \param[in] model_coefficients the coefficients of a line model that we need to compute distances to
153  * \param[out] distances the resultant estimated squared distances
154  */
155  void
156  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
157  std::vector<double> &distances) const override;
158 
159  /** \brief Return a unique id for this model (SACMODEL_PARALLEL_LINE). */
160  inline pcl::SacModel
161  getModelType () const override { return (SACMODEL_PARALLEL_LINE); }
162 
163  protected:
166 
167  /** \brief Check whether a model is valid given the user constraints.
168  * \param[in] model_coefficients the set of model coefficients
169  */
170  bool
171  isModelValid (const Eigen::VectorXf &model_coefficients) const override;
172 
173  /** \brief The axis along which we need to search for a line. */
174  Eigen::Vector3f axis_;
175 
176  /** \brief The maximum allowed difference between the line direction and the given axis. */
177  double eps_angle_;
178  };
179 }
180 
181 #ifdef PCL_NO_PRECOMPILE
182 #include <pcl/sample_consensus/impl/sac_model_parallel_line.hpp>
183 #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
SampleConsensusModelLine defines a model for 3D line segmentation.
typename SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
typename SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
typename SampleConsensusModel< PointT >::PointCloud PointCloud
SampleConsensusModelParallelLine defines a model for 3D line segmentation using additional angular co...
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_PARALLEL_LINE).
SampleConsensusModelParallelLine(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelParallelLine.
double eps_angle_
The maximum allowed difference between the line direction and the given axis.
Eigen::Vector3f axis_
The axis along which we need to search for a line.
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a line.
Eigen::Vector3f getAxis() const
Get the axis along which we need to search for a line.
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.
~SampleConsensusModelParallelLine() override=default
Empty destructor.
double getEpsAngle() const
Get the angle epsilon (delta) threshold (in radians).
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all squared distances from the cloud data to a given line 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 setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
SampleConsensusModelParallelLine(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelParallelLine.
Definition: bfgs.h:10
SacModel
Definition: model_types.h:46
@ SACMODEL_PARALLEL_LINE
Definition: model_types.h:55
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.