Point Cloud Library (PCL)  1.14.1-dev
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 #pragma once
42 
43 #include <pcl/memory.h>
44 #include <pcl/pcl_macros.h>
45 #include <pcl/sample_consensus/sac_model.h>
46 #include <pcl/sample_consensus/sac_model_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:
86 
90 
93 
94  using Ptr = shared_ptr<SampleConsensusModelNormalPlane<PointT, PointNT> >;
95  using ConstPtr = shared_ptr<const SampleConsensusModelNormalPlane<PointT, PointNT>>;
96 
97  /** \brief Constructor for base SampleConsensusModelNormalPlane.
98  * \param[in] cloud the input point cloud dataset
99  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
100  */
102  bool random = false)
103  : SampleConsensusModelPlane<PointT> (cloud, random)
105  {
106  model_name_ = "SampleConsensusModelNormalPlane";
107  sample_size_ = 3;
108  model_size_ = 4;
109  }
110 
111  /** \brief Constructor for base SampleConsensusModelNormalPlane.
112  * \param[in] cloud the input point cloud dataset
113  * \param[in] indices a vector of point indices to be used from \a cloud
114  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
115  */
117  const Indices &indices,
118  bool random = false)
119  : SampleConsensusModelPlane<PointT> (cloud, indices, random)
121  {
122  model_name_ = "SampleConsensusModelNormalPlane";
123  sample_size_ = 3;
124  model_size_ = 4;
125  }
126 
127  /** \brief Empty destructor */
128  ~SampleConsensusModelNormalPlane () override = default;
129 
130  /** \brief Select all the points which respect the given model coefficients as inliers.
131  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
132  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
133  * \param[out] inliers the resultant model inliers
134  */
135  void
136  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
137  const double threshold,
138  Indices &inliers) override;
139 
140  /** \brief Count all the points which respect the given model coefficients as inliers.
141  *
142  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
143  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
144  * \return the resultant number of inliers
145  */
146  std::size_t
147  countWithinDistance (const Eigen::VectorXf &model_coefficients,
148  const double threshold) const override;
149 
150  /** \brief Compute all distances from the cloud data to a given plane model.
151  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
152  * \param[out] distances the resultant estimated distances
153  */
154  void
155  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
156  std::vector<double> &distances) const override;
157 
158  /** \brief Return a unique id for this model (SACMODEL_NORMAL_PLANE). */
159  inline pcl::SacModel
160  getModelType () const override { return (SACMODEL_NORMAL_PLANE); }
161 
163 
164  protected:
167 
168  /** This implementation uses no SIMD instructions. It is not intended for normal use.
169  * See countWithinDistance which automatically uses the fastest implementation.
170  */
171  std::size_t
172  countWithinDistanceStandard (const Eigen::VectorXf &model_coefficients,
173  const double threshold,
174  std::size_t i = 0) const;
175 
176 #if defined (__SSE__) && defined (__SSE2__) && defined (__SSE4_1__)
177  /** This implementation uses SSE, SSE2, and SSE4.1 instructions. It is not intended for normal use.
178  * See countWithinDistance which automatically uses the fastest implementation.
179  */
180  std::size_t
181  countWithinDistanceSSE (const Eigen::VectorXf &model_coefficients,
182  const double threshold,
183  std::size_t i = 0) const;
184 #endif
185 
186 #if defined (__AVX__) && defined (__AVX2__)
187  /** This implementation uses AVX and AVX2 instructions. It is not intended for normal use.
188  * See countWithinDistance which automatically uses the fastest implementation.
189  */
190  std::size_t
191  countWithinDistanceAVX (const Eigen::VectorXf &model_coefficients,
192  const double threshold,
193  std::size_t i = 0) const;
194 #endif
195  };
196 }
197 
198 #ifdef PCL_NO_PRECOMPILE
199 #include <pcl/sample_consensus/impl/sac_model_normal_plane.hpp>
200 #endif
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
SampleConsensusModelFromNormals represents the base model class for models that require the use of su...
Definition: sac_model.h:613
typename pcl::PointCloud< PointNT >::ConstPtr PointCloudNConstPtr
Definition: sac_model.h:615
typename pcl::PointCloud< PointNT >::Ptr PointCloudNPtr
Definition: sac_model.h:616
SampleConsensusModel represents the base model class.
Definition: sac_model.h:71
shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:78
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:589
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: sac_model.h:74
std::string model_name_
The model name.
Definition: sac_model.h:551
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:592
typename PointCloud::Ptr PointCloudPtr
Definition: sac_model.h:75
shared_ptr< const SampleConsensusModel< PointT > > ConstPtr
Definition: sac_model.h:79
SampleConsensusModelNormalPlane defines a model for 3D plane segmentation using additional surface no...
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.
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.
~SampleConsensusModelNormalPlane() override=default
Empty destructor.
SampleConsensusModelNormalPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelNormalPlane.
SampleConsensusModelNormalPlane(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelNormalPlane.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given plane model.
std::size_t countWithinDistanceStandard(const Eigen::VectorXf &model_coefficients, const double threshold, std::size_t i=0) const
This implementation uses no SIMD instructions.
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_NORMAL_PLANE).
SampleConsensusModelPlane defines a model for 3D plane segmentation.
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Defines functions, macros and traits for allocating and using memory.
SacModel
Definition: model_types.h:46
@ SACMODEL_NORMAL_PLANE
Definition: model_types.h:58
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
Defines all the PCL and non-PCL macros used.
A point structure representing Euclidean xyz coordinates, and the RGB color.