Point Cloud Library (PCL)  1.9.1
sac_model_normal_sphere.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, 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: sac_model_normal_sphere.h schrandt $
38  *
39  */
40 
41 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_NORMALSPHERE_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_NORMALSPHERE_H_
43 
44 #include <pcl/sample_consensus/sac_model.h>
45 #include <pcl/sample_consensus/sac_model_sphere.h>
46 #include <pcl/sample_consensus/model_types.h>
47 #include <pcl/common/common.h>
48 
49 namespace pcl
50 {
51  /** \brief @b SampleConsensusModelNormalSphere defines a model for 3D sphere
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 sphere's normal and the inlier points normals.
56  *
57  * The model coefficients are defined as:
58  * <ul>
59  * <li><b>a</b> : the X coordinate of the plane's normal (normalized)
60  * <li><b>b</b> : the Y coordinate of the plane's normal (normalized)
61  * <li><b>c</b> : the Z coordinate of the plane's normal (normalized)
62  * <li><b>d</b> : radius of the sphere
63  * </ul>
64  *
65  * \author Stefan Schrandt
66  * \ingroup sample_consensus
67  */
68  template <typename PointT, typename PointNT>
70  {
71  public:
80 
84 
87 
88  typedef boost::shared_ptr<SampleConsensusModelNormalSphere> Ptr;
89 
90  /** \brief Constructor for base SampleConsensusModelNormalSphere.
91  * \param[in] cloud the input point cloud dataset
92  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
93  */
95  bool random = false)
96  : SampleConsensusModelSphere<PointT> (cloud, random)
98  {
99  model_name_ = "SampleConsensusModelNormalSphere";
100  sample_size_ = 4;
101  model_size_ = 4;
102  }
103 
104  /** \brief Constructor for base SampleConsensusModelNormalSphere.
105  * \param[in] cloud the input point cloud dataset
106  * \param[in] indices a vector of point indices to be used from \a cloud
107  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
108  */
110  const std::vector<int> &indices,
111  bool random = false)
112  : SampleConsensusModelSphere<PointT> (cloud, indices, random)
114  {
115  model_name_ = "SampleConsensusModelNormalSphere";
116  sample_size_ = 4;
117  model_size_ = 4;
118  }
119 
120  /** \brief Empty destructor */
122 
123  /** \brief Select all the points which respect the given model coefficients as inliers.
124  * \param[in] model_coefficients the coefficients of a sphere model that we need to compute distances to
125  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
126  * \param[out] inliers the resultant model inliers
127  */
128  void
129  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
130  const double threshold,
131  std::vector<int> &inliers);
132 
133  /** \brief Count all the points which respect the given model coefficients as inliers.
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) const;
141 
142  /** \brief Compute all distances from the cloud data to a given sphere model.
143  * \param[in] model_coefficients the coefficients of a sphere 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) const;
149 
150  /** \brief Return an unique id for this model (SACMODEL_NORMAL_SPHERE). */
151  inline pcl::SacModel
152  getModelType () const { return (SACMODEL_NORMAL_SPHERE); }
153 
154  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
155 
156  protected:
159 
160  /** \brief Check whether a model is valid given the user constraints.
161  * \param[in] model_coefficients the set of model coefficients
162  */
163  virtual bool
164  isModelValid (const Eigen::VectorXf &model_coefficients) const;
165 
166  };
167 }
168 
169 #ifdef PCL_NO_PRECOMPILE
170 #include <pcl/sample_consensus/impl/sac_model_normal_sphere.hpp>
171 #endif
172 
173 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_NORMALSPHERE_H_
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::SampleConsensusModelNormalSphere::countWithinDistance
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const
Count all the points which respect the given model coefficients as inliers.
Definition: sac_model_normal_sphere.hpp:110
common.h
pcl::SampleConsensusModel::PointCloudPtr
pcl::PointCloud< PointT >::Ptr PointCloudPtr
Definition: sac_model.h:71
pcl::SampleConsensusModelNormalSphere::selectWithinDistance
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.
Definition: sac_model_normal_sphere.hpp:48
pcl::SampleConsensusModelFromNormals
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
Definition: sac_model.h:591
pcl::SampleConsensusModelNormalSphere::~SampleConsensusModelNormalSphere
virtual ~SampleConsensusModelNormalSphere()
Empty destructor.
Definition: sac_model_normal_sphere.h:121
pcl::SampleConsensusModel::sample_size_
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:572
pcl::SampleConsensusModelNormalSphere::PointCloudNPtr
SampleConsensusModelFromNormals< PointT, PointNT >::PointCloudNPtr PointCloudNPtr
Definition: sac_model_normal_sphere.h:85
pcl::SampleConsensusModelNormalSphere::SampleConsensusModelNormalSphere
SampleConsensusModelNormalSphere(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelNormalSphere.
Definition: sac_model_normal_sphere.h:109
pcl::SampleConsensusModel::model_size_
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:575
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:53
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:619
pcl::SampleConsensusModelNormalSphere::PointCloudConstPtr
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition: sac_model_normal_sphere.h:83
pcl::SampleConsensusModel::PointCloudConstPtr
pcl::PointCloud< PointT >::ConstPtr PointCloudConstPtr
Definition: sac_model.h:70
pcl::SampleConsensusModelNormalSphere::SampleConsensusModelNormalSphere
SampleConsensusModelNormalSphere(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelNormalSphere.
Definition: sac_model_normal_sphere.h:94
pcl::SampleConsensusModelNormalSphere::isModelValid
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients) const
Check whether a model is valid given the user constraints.
Definition: sac_model_normal_sphere.hpp:210
pcl::SacModel
SacModel
Definition: model_types.h:46
pcl::SACMODEL_NORMAL_SPHERE
@ SACMODEL_NORMAL_SPHERE
Definition: model_types.h:60
pcl::SampleConsensusModel::model_name_
std::string model_name_
The model name.
Definition: sac_model.h:534
pcl::SampleConsensusModelNormalSphere::Ptr
boost::shared_ptr< SampleConsensusModelNormalSphere > Ptr
Definition: sac_model_normal_sphere.h:88
pcl::SampleConsensusModelNormalSphere::getModelType
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_NORMAL_SPHERE).
Definition: sac_model_normal_sphere.h:152
pcl::SampleConsensusModelNormalSphere::PointCloud
SampleConsensusModel< PointT >::PointCloud PointCloud
Definition: sac_model_normal_sphere.h:81
pcl::SampleConsensusModelNormalSphere
SampleConsensusModelNormalSphere defines a model for 3D sphere segmentation using additional surface ...
Definition: sac_model_normal_sphere.h:69
pcl::SampleConsensusModel
SampleConsensusModel represents the base model class.
Definition: sac_model.h:66
pcl::SampleConsensusModelNormalSphere::getDistancesToModel
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const
Compute all distances from the cloud data to a given sphere model.
Definition: sac_model_normal_sphere.hpp:160
pcl::SampleConsensusModelNormalSphere::PointCloudNConstPtr
SampleConsensusModelFromNormals< PointT, PointNT >::PointCloudNConstPtr PointCloudNConstPtr
Definition: sac_model_normal_sphere.h:86
pcl::SampleConsensusModelFromNormals::PointCloudNConstPtr
pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
Definition: sac_model.h:594
pcl::SampleConsensusModelNormalSphere::PointCloudPtr
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
Definition: sac_model_normal_sphere.h:82
pcl::SampleConsensusModelFromNormals::PointCloudNPtr
pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:595
pcl::SampleConsensusModelSphere
SampleConsensusModelSphere defines a model for 3D sphere segmentation.
Definition: sac_model_sphere.h:60