Point Cloud Library (PCL)  1.8.1
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 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_PARALLEL_LINE_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_PARALLEL_LINE_H_
43 
44 #include <pcl/sample_consensus/sac_model_line.h>
45 
46 namespace pcl
47 {
48  /** \brief SampleConsensusModelParallelLine defines a model for 3D line segmentation using additional angular
49  * constraints.
50  *
51  * Checking for inliers will not only involve a "distance to model" criterion, but also an additional "maximum
52  * angular deviation" between the line's direction and a user-specified axis.
53  *
54  * The model coefficients are defined as:
55  * - \b point_on_line.x : the X coordinate of a point on the line
56  * - \b point_on_line.y : the Y coordinate of a point on the line
57  * - \b point_on_line.z : the Z coordinate of a point on the line
58  * - \b line_direction.x : the X coordinate of a line's direction
59  * - \b line_direction.y : the Y coordinate of a line's direction
60  * - \b line_direction.z : the Z coordinate of a line's direction
61  *
62  * \author Radu B. Rusu
63  * \ingroup sample_consensus
64  */
65  template <typename PointT>
67  {
68  public:
70 
74 
75  typedef boost::shared_ptr<SampleConsensusModelParallelLine> Ptr;
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 std::vector<int> &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 */
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  std::vector<int> &inliers);
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  virtual int
148  countWithinDistance (const Eigen::VectorXf &model_coefficients,
149  const double threshold);
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);
158 
159  /** \brief Return an unique id for this model (SACMODEL_PARALLEL_LINE). */
160  inline pcl::SacModel
161  getModelType () const { 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  virtual bool
171  isModelValid (const Eigen::VectorXf &model_coefficients);
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
184 
185 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_PARALLEL_LINE_H_
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
SampleConsensusModelLine defines a model for 3D line segmentation.
Eigen::Vector3f getAxis() const
Get the axis along which we need to search for a line.
SampleConsensusModelLine< PointT >::PointCloud PointCloud
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_PARALLEL_LINE).
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:575
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances)
Compute all squared distances from the cloud data to a given line model.
Definition: bfgs.h:10
virtual ~SampleConsensusModelParallelLine()
Empty destructor.
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients)
Check whether a model is valid given the user constraints.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, std::vector< int > &inliers)
Select all the points which respect the given model coefficients as inliers.
SampleConsensusModel represents the base model class.
Definition: sac_model.h:66
SampleConsensusModelParallelLine defines a model for 3D line segmentation using additional angular co...
std::string model_name_
The model name.
Definition: sac_model.h:534
SampleConsensusModelParallelLine(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelParallelLine.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
SacModel
Definition: model_types.h:48
pcl::PointCloud< PointT >::ConstPtr PointCloudConstPtr
Definition: sac_model.h:70
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold)
Count all the points which respect the given model coefficients as inliers.
SampleConsensusModelLine< PointT >::PointCloudPtr PointCloudPtr
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a line.
Eigen::Vector3f axis_
The axis along which we need to search for a line.
SampleConsensusModelLine< PointT >::PointCloudConstPtr PointCloudConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.
SampleConsensusModelParallelLine(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelParallelLine.
double eps_angle_
The maximum allowed difference between the line direction and the given axis.
double getEpsAngle() const
Get the angle epsilon (delta) threshold (in radians).
boost::shared_ptr< SampleConsensusModelParallelLine > Ptr
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:572