Point Cloud Library (PCL)  1.9.1
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 #ifndef PCL_SAMPLE_CONSENSUS_MODEL_PARALLELPLANE_H_
42 #define PCL_SAMPLE_CONSENSUS_MODEL_PARALLELPLANE_H_
43 
44 #include <pcl/sample_consensus/sac_model_plane.h>
45 #include <pcl/common/common.h>
46 
47 namespace pcl
48 {
49  /** \brief @b SampleConsensusModelParallelPlane defines a model for 3D plane segmentation using additional
50  * angular constraints. The plane must be parallel to a user-specified axis
51  * (\ref setAxis) within an user-specified angle threshold (\ref setEpsAngle).
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  typedef boost::shared_ptr<SampleConsensusModelParallelPlane> Ptr;
76 
77  /** \brief Constructor for base SampleConsensusModelParallelPlane.
78  * \param[in] cloud the input point cloud dataset
79  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
80  */
82  bool random = false)
83  : SampleConsensusModelPlane<PointT> (cloud, random)
84  , axis_ (Eigen::Vector3f::Zero ())
85  , eps_angle_ (0.0)
86  , sin_angle_ (-1.0)
87  {
88  model_name_ = "SampleConsensusModelParallelPlane";
89  sample_size_ = 3;
90  model_size_ = 4;
91  }
92 
93  /** \brief Constructor for base SampleConsensusModelParallelPlane.
94  * \param[in] cloud the input point cloud dataset
95  * \param[in] indices a vector of point indices to be used from \a cloud
96  * \param[in] random if true set the random seed to the current time, else set to 12345 (default: false)
97  */
99  const std::vector<int> &indices,
100  bool random = false)
101  : SampleConsensusModelPlane<PointT> (cloud, indices, random)
102  , axis_ (Eigen::Vector3f::Zero ())
103  , eps_angle_ (0.0)
104  , sin_angle_ (-1.0)
105  {
106  model_name_ = "SampleConsensusModelParallelPlane";
107  sample_size_ = 3;
108  model_size_ = 4;
109  }
110 
111  /** \brief Empty destructor */
113 
114  /** \brief Set the axis along which we need to search for a plane perpendicular to.
115  * \param[in] ax the axis along which we need to search for a plane perpendicular to
116  */
117  inline void
118  setAxis (const Eigen::Vector3f &ax) { axis_ = ax; }
119 
120  /** \brief Get the axis along which we need to search for a plane perpendicular to. */
121  inline Eigen::Vector3f
122  getAxis () { return (axis_); }
123 
124  /** \brief Set the angle epsilon (delta) threshold.
125  * \param[in] ea the maximum allowed difference between the plane normal and the given axis.
126  * \note You need to specify an angle > 0 in order to activate the axis-angle constraint!
127  */
128  inline void
129  setEpsAngle (const double ea) { eps_angle_ = ea; sin_angle_ = fabs (sin (ea));}
130 
131  /** \brief Get the angle epsilon (delta) threshold. */
132  inline double
133  getEpsAngle () { return (eps_angle_); }
134 
135  /** \brief Select all the points which respect the given model coefficients as inliers.
136  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
137  * \param[in] threshold a maximum admissible distance threshold for determining the inliers from the outliers
138  * \param[out] inliers the resultant model inliers
139  */
140  void
141  selectWithinDistance (const Eigen::VectorXf &model_coefficients,
142  const double threshold,
143  std::vector<int> &inliers);
144 
145  /** \brief Count all the points which respect the given model coefficients as inliers.
146  *
147  * \param[in] model_coefficients the coefficients of a model that we need to compute distances to
148  * \param[in] threshold maximum admissible distance threshold for determining the inliers from the outliers
149  * \return the resultant number of inliers
150  */
151  virtual int
152  countWithinDistance (const Eigen::VectorXf &model_coefficients,
153  const double threshold) const;
154 
155  /** \brief Compute all distances from the cloud data to a given plane model.
156  * \param[in] model_coefficients the coefficients of a plane model that we need to compute distances to
157  * \param[out] distances the resultant estimated distances
158  */
159  void
160  getDistancesToModel (const Eigen::VectorXf &model_coefficients,
161  std::vector<double> &distances) const;
162 
163  /** \brief Return an unique id for this model (SACMODEL_PARALLEL_PLANE). */
164  inline pcl::SacModel
165  getModelType () const { return (SACMODEL_PARALLEL_PLANE); }
166 
167  protected:
170 
171  /** \brief Check whether a model is valid given the user constraints.
172  * \param[in] model_coefficients the set of model coefficients
173  */
174  virtual bool
175  isModelValid (const Eigen::VectorXf &model_coefficients) const;
176 
177  /** \brief The axis along which we need to search for a plane perpendicular to. */
178  Eigen::Vector3f axis_;
179 
180  /** \brief The maximum allowed difference between the plane and the given axis. */
181  double eps_angle_;
182 
183  /** \brief The sine of the angle*/
184  double sin_angle_;
185  };
186 }
187 
188 #ifdef PCL_NO_PRECOMPILE
189 #include <pcl/sample_consensus/impl/sac_model_parallel_plane.hpp>
190 #endif
191 
192 #endif //#ifndef PCL_SAMPLE_CONSENSUS_MODEL_PARALLELPLANE_H_
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::SampleConsensusModelParallelPlane::Ptr
boost::shared_ptr< SampleConsensusModelParallelPlane > Ptr
Definition: sac_model_parallel_plane.h:75
Eigen
Definition: bfgs.h:10
common.h
pcl::SampleConsensusModelParallelPlane::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_parallel_plane.hpp:63
pcl::SampleConsensusModelParallelPlane::PointCloudPtr
SampleConsensusModelPlane< PointT >::PointCloudPtr PointCloudPtr
Definition: sac_model_parallel_plane.h:72
pcl::SampleConsensusModelPlane
SampleConsensusModelPlane defines a model for 3D plane segmentation.
Definition: sac_model_plane.h:136
pcl::SampleConsensusModelParallelPlane::getModelType
pcl::SacModel getModelType() const
Return an unique id for this model (SACMODEL_PARALLEL_PLANE).
Definition: sac_model_parallel_plane.h:165
pcl::SampleConsensusModelParallelPlane::SampleConsensusModelParallelPlane
SampleConsensusModelParallelPlane(const PointCloudConstPtr &cloud, bool random=false)
Constructor for base SampleConsensusModelParallelPlane.
Definition: sac_model_parallel_plane.h:81
pcl::SampleConsensusModelParallelPlane::~SampleConsensusModelParallelPlane
virtual ~SampleConsensusModelParallelPlane()
Empty destructor.
Definition: sac_model_parallel_plane.h:112
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::SACMODEL_PARALLEL_PLANE
@ SACMODEL_PARALLEL_PLANE
Definition: model_types.h:63
pcl::SampleConsensusModelPlane::PointCloudConstPtr
SampleConsensusModel< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition: sac_model_plane.h:147
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::SampleConsensusModel::PointCloudConstPtr
pcl::PointCloud< PointT >::ConstPtr PointCloudConstPtr
Definition: sac_model.h:70
pcl::SampleConsensusModelParallelPlane::getAxis
Eigen::Vector3f getAxis()
Get the axis along which we need to search for a plane perpendicular to.
Definition: sac_model_parallel_plane.h:122
pcl::SampleConsensusModelParallelPlane::setAxis
void setAxis(const Eigen::Vector3f &ax)
Set the axis along which we need to search for a plane perpendicular to.
Definition: sac_model_parallel_plane.h:118
pcl::SampleConsensusModelParallelPlane::SampleConsensusModelParallelPlane
SampleConsensusModelParallelPlane(const PointCloudConstPtr &cloud, const std::vector< int > &indices, bool random=false)
Constructor for base SampleConsensusModelParallelPlane.
Definition: sac_model_parallel_plane.h:98
pcl::SacModel
SacModel
Definition: model_types.h:46
pcl::SampleConsensusModelParallelPlane::axis_
Eigen::Vector3f axis_
The axis along which we need to search for a plane perpendicular to.
Definition: sac_model_parallel_plane.h:178
pcl::SampleConsensusModelParallelPlane::getDistancesToModel
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const
Compute all distances from the cloud data to a given plane model.
Definition: sac_model_parallel_plane.hpp:75
pcl::SampleConsensusModelParallelPlane::setEpsAngle
void setEpsAngle(const double ea)
Set the angle epsilon (delta) threshold.
Definition: sac_model_parallel_plane.h:129
pcl::SampleConsensusModel::model_name_
std::string model_name_
The model name.
Definition: sac_model.h:534
pcl::SampleConsensusModelParallelPlane::PointCloud
SampleConsensusModelPlane< PointT >::PointCloud PointCloud
Definition: sac_model_parallel_plane.h:71
pcl::SampleConsensusModelParallelPlane::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_parallel_plane.hpp:48
pcl::SampleConsensusModelParallelPlane::isModelValid
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients) const
Check whether a model is valid given the user constraints.
Definition: sac_model_parallel_plane.hpp:90
pcl::SampleConsensusModelParallelPlane::sin_angle_
double sin_angle_
The sine of the angle.
Definition: sac_model_parallel_plane.h:184
pcl::SampleConsensusModelParallelPlane::getEpsAngle
double getEpsAngle()
Get the angle epsilon (delta) threshold.
Definition: sac_model_parallel_plane.h:133
pcl::SampleConsensusModel
SampleConsensusModel represents the base model class.
Definition: sac_model.h:66
pcl::SampleConsensusModelParallelPlane
SampleConsensusModelParallelPlane defines a model for 3D plane segmentation using additional angular ...
Definition: sac_model_parallel_plane.h:66
pcl::SampleConsensusModelParallelPlane::eps_angle_
double eps_angle_
The maximum allowed difference between the plane and the given axis.
Definition: sac_model_parallel_plane.h:181
pcl::SampleConsensusModelParallelPlane::PointCloudConstPtr
SampleConsensusModelPlane< PointT >::PointCloudConstPtr PointCloudConstPtr
Definition: sac_model_parallel_plane.h:73
pcl::SampleConsensusModelPlane::PointCloudPtr
SampleConsensusModel< PointT >::PointCloudPtr PointCloudPtr
Definition: sac_model_plane.h:146