Point Cloud Library (PCL)  1.11.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 #pragma once
42 
43 #include <pcl/sample_consensus/sac_model.h>
44 #include <pcl/sample_consensus/sac_model_sphere.h>
45 #include <pcl/sample_consensus/model_types.h>
46 #include <pcl/common/common.h>
47 #include <pcl/memory.h>
48 #include <pcl/pcl_macros.h>
49 
50 namespace pcl
51 {
52  /** \brief @b SampleConsensusModelNormalSphere defines a model for 3D sphere
53  * segmentation using additional surface normal constraints. Basically this
54  * means that checking for inliers will not only involve a "distance to
55  * model" criterion, but also an additional "maximum angular deviation"
56  * between the sphere's normal and the inlier points normals.
57  *
58  * The model coefficients are defined as:
59  * <ul>
60  * <li><b>center.x</b> : the X coordinate of the sphere's center
61  * <li><b>center.y</b> : the Y coordinate of the sphere's center
62  * <li><b>center.z</b> : the Z coordinate of the sphere's center
63  * <li><b>radius</b> : radius of the sphere
64  * </ul>
65  *
66  * \author Stefan Schrandt
67  * \ingroup sample_consensus
68  */
69  template <typename PointT, typename PointNT>
71  {
72  public:
81 
85 
88 
89  using Ptr = shared_ptr<SampleConsensusModelNormalSphere<PointT, PointNT> >;
90  using ConstPtr = shared_ptr<const SampleConsensusModelNormalSphere<PointT, PointNT>>;
91 
92  /** \brief Constructor for base SampleConsensusModelNormalSphere.
93  * \param[in] cloud the input point cloud dataset
94  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
95  */
97  bool random = false)
98  : SampleConsensusModelSphere<PointT> (cloud, random)
100  {
101  model_name_ = "SampleConsensusModelNormalSphere";
102  sample_size_ = 4;
103  model_size_ = 4;
104  }
105 
106  /** \brief Constructor for base SampleConsensusModelNormalSphere.
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 Indices &indices,
113  bool random = false)
114  : SampleConsensusModelSphere<PointT> (cloud, indices, random)
116  {
117  model_name_ = "SampleConsensusModelNormalSphere";
118  sample_size_ = 4;
119  model_size_ = 4;
120  }
121 
122  /** \brief Empty destructor */
124 
125  /** \brief Select all the points which respect the given model coefficients as inliers.
126  * \param[in] model_coefficients the coefficients of a sphere model that we need to compute distances to
127  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
128  * \param[out] inliers the resultant model inliers
129  */
130  void
131  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
132  const double threshold,
133  Indices &inliers) override;
134 
135  /** \brief Count all the points which respect the given model coefficients as inliers.
136  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
137  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
138  * \return the resultant number of inliers
139  */
140  std::size_t
141  countWithinDistance (const Eigen::VectorXf &model_coefficients,
142  const double threshold) const override;
143 
144  /** \brief Compute all distances from the cloud data to a given sphere model.
145  * \param[in] model_coefficients the coefficients of a sphere model that we need to compute distances to
146  * \param[out] distances the resultant estimated distances
147  */
148  void
149  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
150  std::vector<double> &distances) const override;
151 
152  /** \brief Return a unique id for this model (SACMODEL_NORMAL_SPHERE). */
153  inline pcl::SacModel
154  getModelType () const override { return (SACMODEL_NORMAL_SPHERE); }
155 
157 
158  protected:
162  };
163 }
164 
165 #ifdef PCL_NO_PRECOMPILE
166 #include <pcl/sample_consensus/impl/sac_model_normal_sphere.hpp>
167 #endif
Defines functions, macros and traits for allocating and using memory.
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:569
SampleConsensusModelNormalSphere defines a model for 3D sphere segmentation using additional surface ...
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
typename PointCloud::Ptr PointCloudPtr
Definition: sac_model.h:75
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
SampleConsensusModelNormalSphere(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelNormalSphere.
Define standard C methods and C++ classes that are common to all methods.
typename pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
Definition: sac_model.h:588
SampleConsensusModel represents the base model class.
Definition: sac_model.h:70
std::string model_name_
The model name.
Definition: sac_model.h:528
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_NORMAL_SPHERE).
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: sac_model.h:74
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
Definition: sac_model.h:585
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:141
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: distances.h:55
SacModel
Definition: model_types.h:45
shared_ptr< const SampleConsensusModel< PointT > > ConstPtr
Definition: sac_model.h:79
SampleConsensusModelNormalSphere(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelNormalSphere.
A point structure representing Euclidean xyz coordinates, and the RGB color.
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:78
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given sphere model.
typename pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:589
SampleConsensusModelSphere defines a model for 3D sphere segmentation.
Defines all the PCL and non-PCL macros used.
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:566