Point Cloud Library (PCL)  1.9.1-dev
covariance_sampling.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$
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/filters/filter_indices.h>
44 
45 namespace pcl
46 {
47  /** \brief Point Cloud sampling based on the 6D covariances. It selects the points such that the resulting cloud is
48  * as stable as possible for being registered (against a copy of itself) with ICP. The algorithm adds points to the
49  * resulting cloud incrementally, while trying to keep all the 6 eigenvalues of the covariance matrix as close to each
50  * other as possible.
51  * This class also comes with the \a computeConditionNumber method that returns a number which shows how stable a point
52  * cloud will be when used as input for ICP (the closer the value it is to 1.0, the better).
53  *
54  * Based on the following publication:
55  * * "Geometrically Stable Sampling for the ICP Algorithm" - N. Gelfand, L. Ikemoto, S. Rusinkiewicz, M. Levoy
56  *
57  * \author Alexandru E. Ichim, alex.e.ichim@gmail.com
58  */
59  template <typename PointT, typename PointNT>
60  class CovarianceSampling : public FilterIndices<PointT>
61  {
67 
69  typedef typename Cloud::Ptr CloudPtr;
70  typedef typename Cloud::ConstPtr CloudConstPtr;
71  typedef typename pcl::PointCloud<PointNT>::ConstPtr NormalsConstPtr;
72 
73  public:
74  typedef boost::shared_ptr< CovarianceSampling<PointT, PointNT> > Ptr;
75  typedef boost::shared_ptr< const CovarianceSampling<PointT, PointNT> > ConstPtr;
76 
77  /** \brief Empty constructor. */
79  { filter_name_ = "CovarianceSampling"; }
80 
81  /** \brief Set number of indices to be sampled.
82  * \param[in] samples the number of sample indices
83  */
84  inline void
85  setNumberOfSamples (unsigned int samples)
86  { num_samples_ = samples; }
87 
88  /** \brief Get the value of the internal \a num_samples_ parameter. */
89  inline unsigned int
91  { return (num_samples_); }
92 
93  /** \brief Set the normals computed on the input point cloud
94  * \param[in] normals the normals computed for the input cloud
95  */
96  inline void
97  setNormals (const NormalsConstPtr &normals)
98  { input_normals_ = normals; }
99 
100  /** \brief Get the normals computed on the input point cloud */
101  inline NormalsConstPtr
102  getNormals () const
103  { return (input_normals_); }
104 
105 
106 
107  /** \brief Compute the condition number of the input point cloud. The condition number is the ratio between the
108  * largest and smallest eigenvalues of the 6x6 covariance matrix of the cloud. The closer this number is to 1.0,
109  * the more stable the cloud is for ICP registration.
110  * \return the condition number
111  */
112  double
114 
115  /** \brief Compute the condition number of the input point cloud. The condition number is the ratio between the
116  * largest and smallest eigenvalues of the 6x6 covariance matrix of the cloud. The closer this number is to 1.0,
117  * the more stable the cloud is for ICP registration.
118  * \param[in] covariance_matrix user given covariance matrix. Assumed to be self adjoint/symmetric.
119  * \return the condition number
120  */
121  static double
122  computeConditionNumber (const Eigen::Matrix<double, 6, 6> &covariance_matrix);
123 
124  /** \brief Computes the covariance matrix of the input cloud.
125  * \param[out] covariance_matrix the computed covariance matrix.
126  * \return whether the computation succeeded or not
127  */
128  bool
129  computeCovarianceMatrix (Eigen::Matrix<double, 6, 6> &covariance_matrix);
130 
131  protected:
132  /** \brief Number of indices that will be returned. */
133  unsigned int num_samples_;
134 
135  /** \brief The normals computed at each point in the input cloud */
136  NormalsConstPtr input_normals_;
137 
138  std::vector<Eigen::Vector3f, Eigen::aligned_allocator<Eigen::Vector3f> > scaled_points_;
139 
140  bool
141  initCompute ();
142 
143  /** \brief Sample of point indices into a separate PointCloud
144  * \param[out] output the resultant point cloud
145  */
146  void
147  applyFilter (Cloud &output) override;
148 
149  /** \brief Sample of point indices
150  * \param[out] indices the resultant point cloud indices
151  */
152  void
153  applyFilter (std::vector<int> &indices) override;
154 
155  static bool
156  sort_dot_list_function (std::pair<int, double> a,
157  std::pair<int, double> b)
158  { return (a.second > b.second); }
159 
160  public:
161  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
162  };
163 }
164 
165 #ifdef PCL_NO_PRECOMPILE
166 #include <pcl/filters/impl/covariance_sampling.hpp>
167 #endif
unsigned int num_samples_
Number of indices that will be returned.
Point Cloud sampling based on the 6D covariances.
CovarianceSampling()
Empty constructor.
void setNormals(const NormalsConstPtr &normals)
Set the normals computed on the input point cloud.
unsigned int getNumberOfSamples() const
Get the value of the internal num_samples_ parameter.
std::vector< Eigen::Vector3f, Eigen::aligned_allocator< Eigen::Vector3f > > scaled_points_
NormalsConstPtr getNormals() const
Get the normals computed on the input point cloud.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
void setNumberOfSamples(unsigned int samples)
Set number of indices to be sampled.
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:427
FilterIndices represents the base class for filters that are about binary point removal.
NormalsConstPtr input_normals_
The normals computed at each point in the input cloud.
static bool sort_dot_list_function(std::pair< int, double > a, std::pair< int, double > b)
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:428
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void applyFilter(Cloud &output) override
Sample of point indices into a separate PointCloud.
std::string filter_name_
The filter name.
Definition: filter.h:165
bool computeCovarianceMatrix(Eigen::Matrix< double, 6, 6 > &covariance_matrix)
Computes the covariance matrix of the input cloud.
double computeConditionNumber()
Compute the condition number of the input point cloud.
boost::shared_ptr< const CovarianceSampling< PointT, PointNT > > ConstPtr
boost::shared_ptr< CovarianceSampling< PointT, PointNT > > Ptr