Point Cloud Library (PCL)  1.9.1-dev
sac_model_parallel_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 #include <pcl/common/common.h>
45 
46 namespace pcl
47 {
48  /** \brief @b SampleConsensusModelParallelPlane defines a model for 3D plane segmentation using additional
49  * angular constraints. The plane must be parallel to a user-specified axis
50  * (\ref setAxis) within a user-specified angle threshold (\ref setEpsAngle).
51  * In other words, the plane <b>normal</b> must be (nearly) <b>perpendicular</b> to the specified axis.
52  *
53  * Code example for a plane model, parallel (within a 15 degrees tolerance) with the Z axis:
54  * \code
55  * SampleConsensusModelParallelPlane<pcl::PointXYZ> model (cloud);
56  * model.setAxis (Eigen::Vector3f (0.0, 0.0, 1.0));
57  * model.setEpsAngle (pcl::deg2rad (15));
58  * \endcode
59  *
60  * \note Please remember that you need to specify an angle > 0 in order to activate the axis-angle constraint!
61  *
62  * \author Radu B. Rusu, Nico Blodow
63  * \ingroup sample_consensus
64  */
65  template <typename PointT>
67  {
68  public:
70 
74 
75  using Ptr = boost::shared_ptr<SampleConsensusModelParallelPlane<PointT> >;
76  using ConstPtr = boost::shared_ptr<const SampleConsensusModelParallelPlane<PointT>>;
77 
78  /** \brief Constructor for base SampleConsensusModelParallelPlane.
79  * \param[in] cloud the input point cloud dataset
80  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
81  */
83  bool random = false)
84  : SampleConsensusModelPlane<PointT> (cloud, random)
85  , axis_ (Eigen::Vector3f::Zero ())
86  , eps_angle_ (0.0)
87  , sin_angle_ (-1.0)
88  {
89  model_name_ = "SampleConsensusModelParallelPlane";
90  sample_size_ = 3;
91  model_size_ = 4;
92  }
93 
94  /** \brief Constructor for base SampleConsensusModelParallelPlane.
95  * \param[in] cloud the input point cloud dataset
96  * \param[in] indices a vector of point indices to be used from \a cloud
97  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
98  */
100  const std::vector<int> &indices,
101  bool random = false)
102  : SampleConsensusModelPlane<PointT> (cloud, indices, random)
103  , axis_ (Eigen::Vector3f::Zero ())
104  , eps_angle_ (0.0)
105  , sin_angle_ (-1.0)
106  {
107  model_name_ = "SampleConsensusModelParallelPlane";
108  sample_size_ = 3;
109  model_size_ = 4;
110  }
111 
112  /** \brief Empty destructor */
114 
115  /** \brief Set the axis along which we need to search for a plane perpendicular to.
116  * \param[in] ax the axis along which we need to search for a plane perpendicular to
117  */
118  inline void
119  setAxis (const Eigen::Vector3f &ax) { axis_ = ax; }
120 
121  /** \brief Get the axis along which we need to search for a plane perpendicular to. */
122  inline Eigen::Vector3f
123  getAxis () const { return (axis_); }
124 
125  /** \brief Set the angle epsilon (delta) threshold.
126  * \param[in] ea the maximum allowed difference between the plane normal and the given axis.
127  * \note You need to specify an angle > 0 in order to activate the axis-angle constraint!
128  */
129  inline void
130  setEpsAngle (const double ea) { eps_angle_ = ea; sin_angle_ = std::abs (sin (ea));}
131 
132  /** \brief Get the angle epsilon (delta) threshold. */
133  inline double
134  getEpsAngle () const { return (eps_angle_); }
135 
136  /** \brief Select all the points which respect the given model coefficients as inliers.
137  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
138  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
139  * \param[out] inliers the resultant model inliers
140  */
141  void
142  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
143  const double threshold,
144  std::vector<int> &inliers) override;
145 
146  /** \brief Count all the points which respect the given model coefficients as inliers.
147  *
148  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
149  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
150  * \return the resultant number of inliers
151  */
152  std::size_t
153  countWithinDistance (const Eigen::VectorXf &model_coefficients,
154  const double threshold) const override;
155 
156  /** \brief Compute all distances from the cloud data to a given plane model.
157  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
158  * \param[out] distances the resultant estimated distances
159  */
160  void
161  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
162  std::vector<double> &distances) const override;
163 
164  /** \brief Return a unique id for this model (SACMODEL_PARALLEL_PLANE). */
165  inline pcl::SacModel
166  getModelType () const override { return (SACMODEL_PARALLEL_PLANE); }
167 
168  protected:
171 
172  /** \brief Check whether a model is valid given the user constraints.
173  * \param[in] model_coefficients the set of model coefficients
174  */
175  bool
176  isModelValid (const Eigen::VectorXf &model_coefficients) const override;
177 
178  /** \brief The axis along which we need to search for a plane perpendicular to. */
179  Eigen::Vector3f axis_;
180 
181  /** \brief The maximum allowed difference between the plane and the given axis. */
182  double eps_angle_;
183 
184  /** \brief The sine of the angle*/
185  double sin_angle_;
186  };
187 }
188 
189 #ifdef PCL_NO_PRECOMPILE
190 #include <pcl/sample_consensus/impl/sac_model_parallel_plane.hpp>
191 #endif
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.
SampleConsensusModelParallelPlane defines a model for 3D plane segmentation using additional angular ...
boost::shared_ptr< SampleConsensusModel< PointT > > Ptr
Definition: sac_model.h:76
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
unsigned int model_size_
The number of coefficients in the model.
Definition: sac_model.h:564
Eigen::Vector3f axis_
The axis along which we need to search for a plane perpendicular to.
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
Eigen::Vector3f getAxis() const
Get the axis along which we need to search for a plane perpendicular to.
typename PointCloud::Ptr PointCloudPtr
Definition: sac_model.h:73
Definition: bfgs.h:9
bool isModelValid(const Eigen::VectorXf &model_coefficients) const override
Check whether a model is valid given the user constraints.
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a plane perpendicular to.
Define standard C methods and C++ classes that are common to all methods.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, std::vector< int > &inliers) override
Select all the points which respect the given model coefficients as inliers.
SampleConsensusModel represents the base model class.
Definition: sac_model.h:68
boost::shared_ptr< const SampleConsensusModel< PointT > > ConstPtr
Definition: sac_model.h:77
std::string model_name_
The model name.
Definition: sac_model.h:523
typename SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
double eps_angle_
The maximum allowed difference between the plane and the given axis.
pcl::SacModel getModelType() const override
Return a unique id for this model (SACMODEL_PARALLEL_PLANE).
SampleConsensusModelParallelPlane(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelParallelPlane.
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: sac_model.h:72
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.
PointCloud represents the base class in PCL for storing collections of 3D points. ...
SacModel
Definition: model_types.h:45
double getEpsAngle() const
Get the angle epsilon (delta) threshold.
typename SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
typename SampleConsensusModel< PointT >::PointCloud PointCloud
SampleConsensusModelParallelPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelParallelPlane.
A point structure representing Euclidean xyz coordinates, and the RGB color.
SampleConsensusModelPlane defines a model for 3D plane segmentation.
unsigned int sample_size_
The size of a sample from which the model is computed.
Definition: sac_model.h:561