Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pca.h
Go to the documentation of this file.
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  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: pca.h 5066 2012-03-14 06:42:21Z rusu $
37  */
38 
39 #ifndef PCL_PCA_H
40 #define PCL_PCA_H
41 
42 #include <pcl/pcl_base.h>
43 #include <pcl/pcl_macros.h>
44 
45 namespace pcl
46 {
59  template <typename PointT>
60  class PCA : public pcl::PCLBase <PointT>
61  {
62  public:
64  typedef typename Base::PointCloud PointCloud;
69 
70  using Base::input_;
71  using Base::indices_;
72  using Base::initCompute;
73  using Base::setInputCloud;
74 
76  enum FLAG
77  {
82  };
83 
87  PCA (bool basis_only = false)
88  : Base ()
89  , compute_done_ (false)
90  , basis_only_ (basis_only)
91  , eigenvectors_ ()
92  , coefficients_ ()
93  , mean_ ()
94  , eigenvalues_ ()
95  {}
96 
101  PCL_DEPRECATED (PCA (const pcl::PointCloud<PointT>& X, bool basis_only = false),
102  "Use PCA (bool basis_only); setInputCloud (X.makeShared ()); instead");
103 
107  PCA (PCA const & pca)
108  : Base (pca)
109  , compute_done_ (pca.compute_done_)
110  , basis_only_ (pca.basis_only_)
111  , eigenvectors_ (pca.eigenvectors_)
112  , coefficients_ (pca.coefficients_)
113  , mean_ (pca.mean_)
114  , eigenvalues_ (pca.eigenvalues_)
115  {}
116 
120  inline PCA&
121  operator= (PCA const & pca)
122  {
123  eigenvectors_ = pca.eigenvectors;
124  coefficients_ = pca.coefficients;
125  eigenvalues_ = pca.eigenvalues;
126  mean_ = pca.mean;
127  return (*this);
128  }
129 
133  inline void
135  {
136  Base::setInputCloud (cloud);
137  compute_done_ = false;
138  }
139 
143  inline Eigen::Vector4f&
145  {
146  if (!compute_done_)
147  initCompute ();
148  if (!compute_done_)
150  "[pcl::PCA::getMean] PCA initCompute failed");
151  return (mean_);
152  }
153 
157  inline Eigen::Matrix3f&
159  {
160  if (!compute_done_)
161  initCompute ();
162  if (!compute_done_)
164  "[pcl::PCA::getEigenVectors] PCA initCompute failed");
165  return (eigenvectors_);
166  }
167 
171  inline Eigen::Vector3f&
173  {
174  if (!compute_done_)
175  initCompute ();
176  if (!compute_done_)
178  "[pcl::PCA::getEigenVectors] PCA getEigenValues failed");
179  return (eigenvalues_);
180  }
181 
185  inline Eigen::MatrixXf&
187  {
188  if (!compute_done_)
189  initCompute ();
190  if (!compute_done_)
192  "[pcl::PCA::getEigenVectors] PCA getCoefficients failed");
193  return (coefficients_);
194  }
195 
201  inline void
202  update (const PointT& input, FLAG flag = preserve);
203 
209  inline void
210  project (const PointT& input, PointT& projection);
211 
217  inline void
218  project (const PointCloud& input, PointCloud& projection);
219 
225  inline void
226  reconstruct (const PointT& projection, PointT& input);
227 
233  inline void
234  reconstruct (const PointCloud& projection, PointCloud& input);
235 
236  private:
237  inline bool
238  initCompute ();
239 
240  bool compute_done_;
241  bool basis_only_;
242  Eigen::Matrix3f eigenvectors_;
243  Eigen::MatrixXf coefficients_;
244  Eigen::Vector4f mean_;
245  Eigen::Vector3f eigenvalues_;
246  }; // class PCA
247 } // namespace pcl
248 
249 #include <pcl/common/impl/pca.hpp>
250 
251 #endif // PCL_PCA_H
252