Point Cloud Library (PCL)  1.7.0
sac_model_normal_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_NORMALPLANE_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_NORMALPLANE_H_
43 
44 #include <pcl/sample_consensus/sac_model.h>
45 #include <pcl/sample_consensus/sac_model_plane.h>
46 #include <pcl/sample_consensus/sac_model_perpendicular_plane.h>
47 #include <pcl/sample_consensus/model_types.h>
48 
49 namespace pcl
50 {
51  /** \brief SampleConsensusModelNormalPlane defines a model for 3D plane
52  * segmentation using additional surface normal constraints. Basically this
53  * means that checking for inliers will not only involve a "distance to
54  * model" criterion, but also an additional "maximum angular deviation"
55  * between the plane's normal and the inlier points normals.
56  *
57  * The model coefficients are defined as:
58  * - \b a : the X coordinate of the plane's normal (normalized)
59  * - \b b : the Y coordinate of the plane's normal (normalized)
60  * - \b c : the Z coordinate of the plane's normal (normalized)
61  * - \b d : the fourth <a href="http://mathworld.wolfram.com/HessianNormalForm.html">Hessian component</a> of the plane's equation
62  *
63  * To set the influence of the surface normals in the inlier estimation
64  * process, set the normal weight (0.0-1.0), e.g.:
65  * \code
66  * SampleConsensusModelNormalPlane<pcl::PointXYZ, pcl::Normal> sac_model;
67  * ...
68  * sac_model.setNormalDistanceWeight (0.1);
69  * ...
70  * \endcode
71  *
72  * \author Radu B. Rusu and Jared Glover
73  * \ingroup sample_consensus
74  */
75  template <typename PointT, typename PointNT>
77  {
78  public:
85 
89 
92 
93  typedef boost::shared_ptr<SampleConsensusModelNormalPlane> Ptr;
94 
95  /** \brief Constructor for base SampleConsensusModelNormalPlane.
96  * \param[in] cloud the input point cloud dataset
97  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
98  */
100  bool random = false)
101  : SampleConsensusModelPlane<PointT> (cloud, random)
103  {
104  }
105 
106  /** \brief Constructor for base SampleConsensusModelNormalPlane.
107  * \param[in] cloud the input point cloud dataset
108  * \param[in] indices a vector of point indices to be used from \a cloud
109  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
110  */
112  const std::vector<int> &indices,
113  bool random = false)
114  : SampleConsensusModelPlane<PointT> (cloud, indices, random)
116  {
117  }
118 
119  /** \brief Empty destructor */
121 
122  /** \brief Select all the points which respect the given model coefficients as inliers.
123  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
124  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
125  * \param[out] inliers the resultant model inliers
126  */
127  void
128  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
129  const double threshold,
130  std::vector<int> &inliers);
131 
132  /** \brief Count all the points which respect the given model coefficients as inliers.
133  *
134  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
135  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
136  * \return the resultant number of inliers
137  */
138  virtual int
139  countWithinDistance (const Eigen::VectorXf &model_coefficients,
140  const double threshold);
141 
142  /** \brief Compute all distances from the cloud data to a given plane model.
143  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
144  * \param[out] distances the resultant estimated distances
145  */
146  void
147  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
148  std::vector<double> &distances);
149 
150  /** \brief Return an unique id for this model (SACMODEL_NORMAL_PLANE). */
151  inline pcl::SacModel
152  getModelType () const { return (SACMODEL_NORMAL_PLANE); }
153 
154  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
155  };
156 }
157 
158 #ifdef PCL_NO_PRECOMPILE
159 #include <pcl/sample_consensus/impl/sac_model_normal_plane.hpp>
160 #endif
161 
162 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_NORMALPLANE_H_
virtual ~SampleConsensusModelNormalPlane()
Empty destructor.
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold)
Count all the points which respect the given model coefficients as inliers.
pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
Definition: sac_model.h:559
SampleConsensusModelNormalPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelNormalPlane.
pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:560
SampleConsensusModelFromNormals< PointT, PointNT >::PointCloudNPtr PointCloudNPtr
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
SampleConsensusModelNormalPlane(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelNormalPlane.
SampleConsensusModelFromNormals< PointT, PointNT >::PointCloudNConstPtr PointCloudNConstPtr
boost::shared_ptr< SampleConsensusModelNormalPlane > Ptr
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_NORMAL_PLANE).
SampleConsensusModel represents the base model class.
Definition: sac_model.h:66
pcl::PointCloud< PointT >::Ptr PointCloudPtr
Definition: sac_model.h:71
SampleConsensusModel< PointT >::PointCloud PointCloud
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
Definition: sac_model.h:556
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
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
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.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances)
Compute all distances from the cloud data to a given plane model.
A point structure representing Euclidean xyz coordinates, and the RGB color.
SampleConsensusModelPlane defines a model for 3D plane segmentation.