Point Cloud Library (PCL)  1.8.1
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:
93 
97 
100 
101  typedef boost::shared_ptr<SampleConsensusModelNormalParallelPlane> Ptr;
102 
103  /** \brief Constructor for base SampleConsensusModelNormalParallelPlane.
104  * \param[in] cloud the input point cloud dataset
105  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
106  */
108  bool random = false)
109  : SampleConsensusModelNormalPlane<PointT, PointNT> (cloud, random)
110  , axis_ (Eigen::Vector4f::Zero ())
111  , distance_from_origin_ (0)
112  , eps_angle_ (-1.0)
113  , cos_angle_ (-1.0)
114  , eps_dist_ (0.0)
115  {
116  model_name_ = "SampleConsensusModelNormalParallelPlane";
117  sample_size_ = 3;
118  model_size_ = 4;
119  }
120 
121  /** \brief Constructor for base SampleConsensusModelNormalParallelPlane.
122  * \param[in] cloud the input point cloud dataset
123  * \param[in] indices a vector of point indices to be used from \a cloud
124  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
125  */
127  const std::vector<int> &indices,
128  bool random = false)
129  : SampleConsensusModelNormalPlane<PointT, PointNT> (cloud, indices, random)
130  , axis_ (Eigen::Vector4f::Zero ())
131  , distance_from_origin_ (0)
132  , eps_angle_ (-1.0)
133  , cos_angle_ (-1.0)
134  , eps_dist_ (0.0)
135  {
136  model_name_ = "SampleConsensusModelNormalParallelPlane";
137  sample_size_ = 3;
138  model_size_ = 4;
139  }
140 
141  /** \brief Empty destructor */
143 
144  /** \brief Set the axis along which we need to search for a plane perpendicular to.
145  * \param[in] ax the axis along which we need to search for a plane perpendicular to
146  */
147  inline void
148  setAxis (const Eigen::Vector3f &ax) { axis_.head<3> () = ax; axis_.normalize ();}
149 
150  /** \brief Get the axis along which we need to search for a plane perpendicular to. */
151  inline Eigen::Vector3f
152  getAxis () { return (axis_.head<3> ()); }
153 
154  /** \brief Set the angle epsilon (delta) threshold.
155  * \param[in] ea the maximum allowed deviation from 90 degrees between the plane normal and the given axis.
156  * \note You need to specify an angle > 0 in order to activate the axis-angle constraint!
157  */
158  inline void
159  setEpsAngle (const double ea) { eps_angle_ = ea; cos_angle_ = fabs (cos (ea));}
160 
161  /** \brief Get the angle epsilon (delta) threshold. */
162  inline double
163  getEpsAngle () { return (eps_angle_); }
164 
165  /** \brief Set the distance we expect the plane to be from the origin
166  * \param[in] d distance from the template plane to the origin
167  */
168  inline void
169  setDistanceFromOrigin (const double d) { distance_from_origin_ = d; }
170 
171  /** \brief Get the distance of the plane from the origin. */
172  inline double
173  getDistanceFromOrigin () { return (distance_from_origin_); }
174 
175  /** \brief Set the distance epsilon (delta) threshold.
176  * \param[in] delta the maximum allowed deviation from the template distance from the origin
177  */
178  inline void
179  setEpsDist (const double delta) { eps_dist_ = delta; }
180 
181  /** \brief Get the distance epsilon (delta) threshold. */
182  inline double
183  getEpsDist () { return (eps_dist_); }
184 
185  /** \brief Return an unique id for this model (SACMODEL_NORMAL_PARALLEL_PLANE). */
186  inline pcl::SacModel
188 
189  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
190 
191  protected:
194 
195  /** \brief Check whether a model is valid given the user constraints.
196  * \param[in] model_coefficients the set of model coefficients
197  */
198  virtual bool
199  isModelValid (const Eigen::VectorXf &model_coefficients);
200 
201  private:
202  /** \brief The axis along which we need to search for a plane perpendicular to. */
203  Eigen::Vector4f axis_;
204 
205  /** \brief The distance from the template plane to the origin. */
206  double distance_from_origin_;
207 
208  /** \brief The maximum allowed difference between the plane normal and the given axis. */
209  double eps_angle_;
210 
211  /** \brief The cosine of the angle*/
212  double cos_angle_;
213  /** \brief The maximum allowed deviation from the template distance from the origin. */
214  double eps_dist_;
215  };
216 }
217 
218 #ifdef PCL_NO_PRECOMPILE
219 #include <pcl/sample_consensus/impl/sac_model_normal_parallel_plane.hpp>
220 #endif
221 
222 #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:594
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:575
pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:595
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.
Definition: bfgs.h:10
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.
std::string model_name_
The model name.
Definition: sac_model.h:534
pcl::PointCloud< PointT >::Ptr PointCloudPtr
Definition: sac_model.h:71
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
virtual 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:591
SampleConsensusModelNormalPlane defines a model for 3D plane segmentation using additional surface no...
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
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_NORMAL_PARALLEL_PLANE).
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...
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:572