Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2010, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage, Inc. nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 */ 00035 00036 00037 #ifndef PCL_PCA_HPP 00038 #define PCL_PCA_HPP 00039 00040 #include <pcl/point_cloud.h> 00041 00042 namespace pcl 00043 { 00055 template <typename PointT> 00056 class PCA 00057 { 00058 public: 00059 00061 enum FLAG 00062 { 00064 increase, 00066 preserve 00067 }; 00068 00069 00073 PCA (bool basis_only = false) : compute_done_ (false), basis_only_ (basis_only) 00074 {} 00075 00080 PCA(const pcl::PointCloud<PointT>& X, bool basis_only = false) : 00081 compute_done_ (false), basis_only_ (basis_only) 00082 { 00083 compute (X); 00084 } 00085 00089 PCA (PCA const & pca_) 00090 { 00091 mean_ = pca_.mean; 00092 eigenvalues_ = pca_.eigenvalues; 00093 eigenvectors_ = pca_.eigenvectors; 00094 coefficients_ = pca_.coefficients; 00095 } 00096 00100 inline PCA& operator= (PCA const & pca) 00101 { 00102 mean_ = pca.mean; 00103 eigenvalues_ = pca.eigenvalues; 00104 eigenvectors_ = pca.eigenvectors; 00105 coefficients_ = pca.coefficients; 00106 return (*this); 00107 } 00108 00110 inline Eigen::Vector4f& 00111 getMean () 00112 { 00113 if (!compute_done_) 00114 PCL_ERROR ("[pcl::PCA::getMean] no results available\n"); 00115 return (mean_); 00116 } 00117 00119 inline Eigen::MatrixXf& 00120 getEigenVectors () 00121 { 00122 if (!compute_done_) 00123 PCL_ERROR ("[pcl::PCA::getEigenVectors] no results available\n"); 00124 return (eigenvectors_); 00125 } 00126 00128 inline Eigen::VectorXf& 00129 getEigenValues () 00130 { 00131 if (!compute_done_) 00132 PCL_ERROR ("[pcl::PCA::getEigenValues] no results available\n"); 00133 return (eigenvalues_); 00134 } 00135 00137 inline Eigen::MatrixXf& 00138 getCoefficients () 00139 { 00140 if (!compute_done_) 00141 PCL_ERROR ("[pcl::PCA::getEigenValues] no results available\n"); 00142 return (coefficients_); 00143 } 00144 00148 inline void 00149 compute (const pcl::PointCloud<PointT>& cloud); 00150 00151 00156 inline void 00157 update (const PointT& input, FLAG flag = preserve); 00158 00163 inline void 00164 project (const PointT& input, PointT& projection) const; 00165 00170 inline void 00171 reconstruct (const PointT& projection, PointT& input) const; 00172 00173 private: 00174 bool compute_done_; 00175 bool basis_only_; 00176 Eigen::MatrixXf eigenvectors_, coefficients_; 00177 Eigen::Vector4f mean_; 00178 Eigen::VectorXf eigenvalues_; 00179 }; // class PCA 00180 } // namespace pcl 00181 00182 #include "pcl/common/impl/pca.hpp" 00183 00184 #endif // PCL_PCA_HPP 00185