Point Cloud Library (PCL)  1.14.1-dev
sac_model_perpendicular_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/sample_consensus/sac_model_plane.h>
44 
45 namespace pcl
46 {
47  /** \brief SampleConsensusModelPerpendicularPlane defines a model for 3D plane segmentation using additional
48  * angular constraints. The plane must be perpendicular to a user-specified axis (\ref setAxis), up to a user-specified angle threshold (\ref setEpsAngle).
49  * In other words, the plane <b>normal</b> must be (nearly) <b>parallel</b> to the specified axis.
50  * The model coefficients are defined as:
51  * - \b a : the X coordinate of the plane's normal (normalized)
52  * - \b b : the Y coordinate of the plane's normal (normalized)
53  * - \b c : the Z coordinate of the plane's normal (normalized)
54  * - \b d : the fourth <a href="http://mathworld.wolfram.com/HessianNormalForm.html">Hessian component</a> of the plane's equation
55  *
56  *
57  * Code example for a plane model, perpendicular (within a 15 degrees tolerance) with the Z axis:
58  * \code
59  * SampleConsensusModelPerpendicularPlane<pcl::PointXYZ> model (cloud);
60  * model.setAxis (Eigen::Vector3f (0.0, 0.0, 1.0));
61  * model.setEpsAngle (pcl::deg2rad (15));
62  * \endcode
63  *
64  * \note Please remember that you need to specify an angle > 0 in order to activate the axis-angle constraint!
65  *
66  * \author Radu B. Rusu
67  * \ingroup sample_consensus
68  */
69  template <typename PointT>
71  {
72  public:
74 
78 
79  using Ptr = shared_ptr<SampleConsensusModelPerpendicularPlane<PointT> >;
80  using ConstPtr = shared_ptr<const SampleConsensusModelPerpendicularPlane<PointT>>;
81 
82  /** \brief Constructor for base SampleConsensusModelPerpendicularPlane.
83  * \param[in] cloud the input point cloud dataset
84  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
85  */
87  bool random = false)
88  : SampleConsensusModelPlane<PointT> (cloud, random)
89  , axis_ (Eigen::Vector3f::Zero ())
90  , eps_angle_ (0.0)
91  {
92  model_name_ = "SampleConsensusModelPerpendicularPlane";
93  sample_size_ = 3;
94  model_size_ = 4;
95  }
96 
97  /** \brief Constructor for base SampleConsensusModelPerpendicularPlane.
98  * \param[in] cloud the input point cloud dataset
99  * \param[in] indices a vector of point indices to be used from \a cloud
100  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
101  */
103  const Indices &indices,
104  bool random = false)
105  : SampleConsensusModelPlane<PointT> (cloud, indices, random)
106  , axis_ (Eigen::Vector3f::Zero ())
107  , eps_angle_ (0.0)
108  {
109  model_name_ = "SampleConsensusModelPerpendicularPlane";
110  sample_size_ = 3;
111  model_size_ = 4;
112  }
113 
114  /** \brief Empty destructor */
116 
117  /** \brief Set the axis along which we need to search for a plane perpendicular to.
118  * \param[in] ax the axis along which we need to search for a plane perpendicular to
119  */
120  inline void
121  setAxis (const Eigen::Vector3f &ax) { axis_ = ax; }
122 
123  /** \brief Get the axis along which we need to search for a plane perpendicular to. */
124  inline Eigen::Vector3f
125  getAxis () const { return (axis_); }
126 
127  /** \brief Set the angle epsilon (delta) threshold.
128  * \param[in] ea the maximum allowed difference between the plane normal and the given axis.
129  * \note You need to specify an angle > 0 in order to activate the axis-angle constraint!
130  */
131  inline void
132  setEpsAngle (const double ea) { eps_angle_ = ea; }
133 
134  /** \brief Get the angle epsilon (delta) threshold. */
135  inline double
136  getEpsAngle () const { return (eps_angle_); }
137 
138  /** \brief Select all the points which respect the given model coefficients as inliers.
139  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
140  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
141  * \param[out] inliers the resultant model inliers
142  */
143  void
144  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
145  const double threshold,
146  Indices &inliers) override;
147 
148  /** \brief Count all the points which respect the given model coefficients as inliers.
149  *
150  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
151  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
152  * \return the resultant number of inliers
153  */
154  std::size_t
155  countWithinDistance (const Eigen::VectorXf &model_coefficients,
156  const double threshold) const override;
157 
158  /** \brief Compute all distances from the cloud data to a given plane model.
159  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
160  * \param[out] distances the resultant estimated distances
161  */
162  void
163  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
164  std::vector<double> &distances) const override;
165 
166  /** \brief Return a unique id for this model (SACMODEL_PERPENDICULAR_PLANE). */
167  inline pcl::SacModel
168  getModelType () const override { return (SACMODEL_PERPENDICULAR_PLANE); }
169 
170  protected:
173 
174  /** \brief Check whether a model is valid given the user constraints.
175  * \param[in] model_coefficients the set of model coefficients
176  */
177  bool
178  isModelValid (const Eigen::VectorXf &model_coefficients) const override;
179 
180  /** \brief The axis along which we need to search for a plane perpendicular to. */
181  Eigen::Vector3f axis_;
182 
183  /** \brief The maximum allowed difference between the plane normal and the given axis. */
184  double eps_angle_;
185  };
186 }
187 
188 #ifdef PCL_NO_PRECOMPILE
189 #include <pcl/sample_consensus/impl/sac_model_perpendicular_plane.hpp>
190 #endif
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
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
SampleConsensusModelPerpendicularPlane defines a model for 3D plane segmentation using additional ang...
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.
~SampleConsensusModelPerpendicularPlane() override=default
Empty destructor.
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_PERPENDICULAR_PLANE).
Eigen::Vector3f getAxis() const
Get the axis along which we need to search for a plane perpendicular to.
double eps_angle_
The maximum allowed difference between the plane normal and the given axis.
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a plane perpendicular to.
double getEpsAngle() const
Get the angle epsilon (delta) threshold.
SampleConsensusModelPerpendicularPlane(const PointCloudConstPtr &cloud, const Indices &indices, bool random=false)
Constructor for base SampleConsensusModelPerpendicularPlane.
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
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.
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
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.
Eigen::Vector3f axis_
The axis along which we need to search for a plane perpendicular to.
SampleConsensusModelPerpendicularPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelPerpendicularPlane.
SampleConsensusModelPlane defines a model for 3D plane segmentation.
typename SampleConsensusModel< PointT >::PointCloud PointCloud
typename SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
typename SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
Definition: bfgs.h:10
SacModel
Definition: model_types.h:46
@ SACMODEL_PERPENDICULAR_PLANE
Definition: model_types.h:56
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.