Point Cloud Library (PCL)  1.7.2
sac_model_normal_parallel_plane.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_NORMALPARALLELPLANE_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_NORMALPARALLELPLANE_H_
43 
44 #include <pcl/sample_consensus/sac_model_normal_plane.h>
45 #include <pcl/sample_consensus/model_types.h>
46 
47 namespace pcl
48 {
49  /** \brief SampleConsensusModelNormalParallelPlane defines a model for 3D
50  * plane segmentation using additional surface normal constraints. Basically
51  * this means that checking for inliers will not only involve a "distance to
52  * model" criterion, but also an additional "maximum angular deviation"
53  * between the plane's normal and the inlier points normals. In addition,
54  * the plane normal must lie parallel to an user-specified axis.
55  *
56  * The model coefficients are defined as:
57  * - \b a : the X coordinate of the plane's normal (normalized)
58  * - \b b : the Y coordinate of the plane's normal (normalized)
59  * - \b c : the Z coordinate of the plane's normal (normalized)
60  * - \b d : the fourth <a href="http://mathworld.wolfram.com/HessianNormalForm.html">Hessian component</a> of the plane's equation
61  *
62  * To set the influence of the surface normals in the inlier estimation
63  * process, set the normal weight (0.0-1.0), e.g.:
64  * \code
65  * SampleConsensusModelNormalPlane<pcl::PointXYZ, pcl::Normal> sac_model;
66  * ...
67  * sac_model.setNormalDistanceWeight (0.1);
68  * ...
69  * \endcode
70  *
71  * In addition, the user can specify more constraints, such as:
72  *
73  * - an axis along which we need to search for a plane perpendicular to (\ref setAxis);
74  * - an angle \a tolerance threshold between the plane's normal and the above given axis (\ref setEpsAngle);
75  * - a distance we expect the plane to be from the origin (\ref setDistanceFromOrigin);
76  * - a distance \a tolerance as the maximum allowed deviation from the above given distance from the origin (\ref setEpsDist).
77  *
78  * \note Please remember that you need to specify an angle > 0 in order to activate the axis-angle constraint!
79  *
80  * \author Radu B. Rusu and Jared Glover and Nico Blodow
81  * \ingroup sample_consensus
82  */
83  template <typename PointT, typename PointNT>
85  {
86  public:
92 
96 
99 
100  typedef boost::shared_ptr<SampleConsensusModelNormalParallelPlane> Ptr;
101 
102  /** \brief Constructor for base SampleConsensusModelNormalParallelPlane.
103  * \param[in] cloud the input point cloud dataset
104  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
105  */
107  bool random = false)
108  : SampleConsensusModelNormalPlane<PointT, PointNT> (cloud, random)
109  , axis_ (Eigen::Vector4f::Zero ())
110  , distance_from_origin_ (0)
111  , eps_angle_ (-1.0)
112  , cos_angle_ (-1.0)
113  , eps_dist_ (0.0)
114  {
115  }
116 
117  /** \brief Constructor for base SampleConsensusModelNormalParallelPlane.
118  * \param[in] cloud the input point cloud dataset
119  * \param[in] indices a vector of point indices to be used from \a cloud
120  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
121  */
123  const std::vector<int> &indices,
124  bool random = false)
125  : SampleConsensusModelNormalPlane<PointT, PointNT> (cloud, indices, random)
126  , axis_ (Eigen::Vector4f::Zero ())
127  , distance_from_origin_ (0)
128  , eps_angle_ (-1.0)
129  , cos_angle_ (-1.0)
130  , eps_dist_ (0.0)
131  {
132  }
133 
134  /** \brief Empty destructor */
136 
137  /** \brief Set the axis along which we need to search for a plane perpendicular to.
138  * \param[in] ax the axis along which we need to search for a plane perpendicular to
139  */
140  inline void
141  setAxis (const Eigen::Vector3f &ax) { axis_.head<3> () = ax; axis_.normalize ();}
142 
143  /** \brief Get the axis along which we need to search for a plane perpendicular to. */
144  inline Eigen::Vector3f
145  getAxis () { return (axis_.head<3> ()); }
146 
147  /** \brief Set the angle epsilon (delta) threshold.
148  * \param[in] ea the maximum allowed deviation from 90 degrees between the plane normal and the given axis.
149  * \note You need to specify an angle > 0 in order to activate the axis-angle constraint!
150  */
151  inline void
152  setEpsAngle (const double ea) { eps_angle_ = ea; cos_angle_ = fabs (cos (ea));}
153 
154  /** \brief Get the angle epsilon (delta) threshold. */
155  inline double
156  getEpsAngle () { return (eps_angle_); }
157 
158  /** \brief Set the distance we expect the plane to be from the origin
159  * \param[in] d distance from the template plane to the origin
160  */
161  inline void
162  setDistanceFromOrigin (const double d) { distance_from_origin_ = d; }
163 
164  /** \brief Get the distance of the plane from the origin. */
165  inline double
166  getDistanceFromOrigin () { return (distance_from_origin_); }
167 
168  /** \brief Set the distance epsilon (delta) threshold.
169  * \param[in] delta the maximum allowed deviation from the template distance from the origin
170  */
171  inline void
172  setEpsDist (const double delta) { eps_dist_ = delta; }
173 
174  /** \brief Get the distance epsilon (delta) threshold. */
175  inline double
176  getEpsDist () { return (eps_dist_); }
177 
178  /** \brief Return an unique id for this model (SACMODEL_NORMAL_PARALLEL_PLANE). */
179  inline pcl::SacModel
181 
182  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
183 
184  protected:
185  /** \brief Check whether a model is valid given the user constraints.
186  * \param[in] model_coefficients the set of model coefficients
187  */
188  bool
189  isModelValid (const Eigen::VectorXf &model_coefficients);
190 
191  private:
192  /** \brief The axis along which we need to search for a plane perpendicular to. */
193  Eigen::Vector4f axis_;
194 
195  /** \brief The distance from the template plane to the origin. */
196  double distance_from_origin_;
197 
198  /** \brief The maximum allowed difference between the plane normal and the given axis. */
199  double eps_angle_;
200 
201  /** \brief The cosine of the angle*/
202  double cos_angle_;
203  /** \brief The maximum allowed deviation from the template distance from the origin. */
204  double eps_dist_;
205  };
206 }
207 
208 #ifdef PCL_NO_PRECOMPILE
209 #include <pcl/sample_consensus/impl/sac_model_normal_parallel_plane.hpp>
210 #endif
211 
212 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_NORMALPARALLELPLANE_H_
SampleConsensusModel< PointT >::PointCloud PointCloud
double getEpsAngle()
Get the angle epsilon (delta) threshold.
double getEpsDist()
Get the distance epsilon (delta) threshold.
SampleConsensusModelFromNormals< PointT, PointNT >::PointCloudNConstPtr PointCloudNConstPtr
pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
Definition: sac_model.h:560
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_NORMAL_PARALLEL_PLANE).
pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:561
Eigen::Vector3f getAxis()
Get the axis along which we need to search for a plane perpendicular to.
double getDistanceFromOrigin()
Get the distance of the plane from the origin.
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
SampleConsensusModelFromNormals< PointT, PointNT >::PointCloudNPtr PointCloudNPtr
boost::shared_ptr< SampleConsensusModelNormalParallelPlane > Ptr
SampleConsensusModel represents the base model class.
Definition: sac_model.h:66
void setDistanceFromOrigin(const double d)
Set the distance we expect the plane to be from the origin.
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a plane perpendicular to.
pcl::PointCloud< PointT >::Ptr PointCloudPtr
Definition: sac_model.h:71
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
bool isModelValid(const Eigen::VectorXf &model_coefficients)
Check whether a model is valid given the user constraints.
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
Definition: sac_model.h:557
SampleConsensusModelNormalPlane defines a model for 3D plane segmentation using additional surface no...
SacModel
Definition: model_types.h:48
pcl::PointCloud< PointT >::ConstPtr PointCloudConstPtr
Definition: sac_model.h:70
SampleConsensusModelNormalParallelPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelNormalParallelPlane.
SampleConsensusModelNormalParallelPlane(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelNormalParallelPlane.
A point structure representing Euclidean xyz coordinates, and the RGB color.
void setEpsDist(const double delta)
Set the distance epsilon (delta) threshold.
SampleConsensusModelNormalParallelPlane defines a model for 3D plane segmentation using additional su...