Point Cloud Library (PCL)  1.7.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_PARALLELLINE_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_PARALLELLINE_H_
43 
44 #include <pcl/sample_consensus/sac_model_line.h>
45 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
46 
47 namespace pcl
48 {
49  /** \brief SampleConsensusModelParallelLine defines a model for 3D line segmentation using additional angular
50  * constraints.
51  * The model coefficients are defined as:
52  * - \b point_on_line.x : the X coordinate of a point on the line
53  * - \b point_on_line.y : the Y coordinate of a point on the line
54  * - \b point_on_line.z : the Z coordinate of a point on the line
55  * - \b line_direction.x : the X coordinate of a line's direction
56  * - \b line_direction.y : the Y coordinate of a line's direction
57  * - \b line_direction.z : the Z coordinate of a line's direction
58  *
59  * \author Radu B. Rusu
60  * \ingroup sample_consensus
61  */
62  template <typename PointT>
64  {
65  public:
69 
70  typedef boost::shared_ptr<SampleConsensusModelParallelLine> Ptr;
71 
72  /** \brief Constructor for base SampleConsensusModelParallelLine.
73  * \param[in] cloud the input point cloud dataset
74  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
75  */
77  bool random = false)
78  : SampleConsensusModelLine<PointT> (cloud, random)
79  , axis_ (Eigen::Vector3f::Zero ())
80  , eps_angle_ (0.0)
81  {
82  }
83 
84  /** \brief Constructor for base SampleConsensusModelParallelLine.
85  * \param[in] cloud the input point cloud dataset
86  * \param[in] indices a vector of point indices to be used from \a cloud
87  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
88  */
90  const std::vector<int> &indices,
91  bool random = false)
92  : SampleConsensusModelLine<PointT> (cloud, indices, random)
93  , axis_ (Eigen::Vector3f::Zero ())
94  , eps_angle_ (0.0)
95  {
96  }
97 
98  /** \brief Empty destructor */
100 
101  /** \brief Set the axis along which we need to search for a plane perpendicular to.
102  * \param[in] ax the axis along which we need to search for a plane perpendicular to
103  */
104  inline void
105  setAxis (const Eigen::Vector3f &ax) { axis_ = ax; axis_.normalize (); }
106 
107  /** \brief Get the axis along which we need to search for a plane perpendicular to. */
108  inline Eigen::Vector3f
109  getAxis () { return (axis_); }
110 
111  /** \brief Set the angle epsilon (delta) threshold.
112  * \param[in] ea the maximum allowed difference between the plane normal and the given axis.
113  */
114  inline void
115  setEpsAngle (const double ea) { eps_angle_ = ea; }
116 
117  /** \brief Get the angle epsilon (delta) threshold. */
118  inline double getEpsAngle () { return (eps_angle_); }
119 
120  /** \brief Select all the points which respect the given model coefficients as inliers.
121  * \param[in] model_coefficients the coefficients of a line model that we need to compute distances to
122  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
123  * \param[out] inliers the resultant model inliers
124  */
125  void
126  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
127  const double threshold,
128  std::vector<int> &inliers);
129 
130  /** \brief Count all the points which respect the given model coefficients as inliers.
131  *
132  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
133  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
134  * \return the resultant number of inliers
135  */
136  virtual int
137  countWithinDistance (const Eigen::VectorXf &model_coefficients,
138  const double threshold);
139 
140  /** \brief Compute all squared distances from the cloud data to a given line model.
141  * \param[in] model_coefficients the coefficients of a line model that we need to compute distances to
142  * \param[out] distances the resultant estimated squared distances
143  */
144  void
145  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
146  std::vector<double> &distances);
147 
148  /** \brief Return an unique id for this model (SACMODEL_PARALLEL_LINE). */
149  inline pcl::SacModel
150  getModelType () const { return (SACMODEL_PARALLEL_LINE); }
151 
152  protected:
153  /** \brief Check whether a model is valid given the user constraints.
154  * \param[in] model_coefficients the set of model coefficients
155  */
156  bool
157  isModelValid (const Eigen::VectorXf &model_coefficients);
158 
159  protected:
160  /** \brief The axis along which we need to search for a plane perpendicular to. */
161  Eigen::Vector3f axis_;
162 
163  /** \brief The maximum allowed difference between the plane normal and the given axis. */
164  double eps_angle_;
165  };
166 }
167 
168 #ifdef PCL_NO_PRECOMPILE
169 #include <pcl/sample_consensus/impl/sac_model_parallel_line.hpp>
170 #endif
171 
172 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_PARALLELLINE_H_