Point Cloud Library (PCL)  1.3.1
centroid.h
Go to the documentation of this file.
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 #ifndef PCL_COMMON_CENTROID_H_
00037 #define PCL_COMMON_CENTROID_H_
00038 
00039 #include <pcl/point_cloud.h>
00040 #include <pcl/ros/point_traits.h>
00041 #include <pcl/PointIndices.h>
00042 
00050 namespace pcl
00051 {
00058   template <typename PointT> inline void 
00059   compute3DCentroid (const pcl::PointCloud<PointT> &cloud, Eigen::Vector4f &centroid);
00060 
00068   template <typename PointT> inline void 
00069   compute3DCentroid (const pcl::PointCloud<PointT> &cloud, 
00070                      const std::vector<int> &indices, Eigen::Vector4f &centroid);
00071 
00079   template <typename PointT> inline void 
00080   compute3DCentroid (const pcl::PointCloud<PointT> &cloud, 
00081                      const pcl::PointIndices &indices, Eigen::Vector4f &centroid);
00082 
00093   template <typename PointT> inline void 
00094   computeCovarianceMatrix (const pcl::PointCloud<PointT> &cloud, 
00095                            const Eigen::Vector4f &centroid, 
00096                            Eigen::Matrix3f &covariance_matrix);
00097 
00107   template <typename PointT> inline void 
00108   computeCovarianceMatrixNormalized (const pcl::PointCloud<PointT> &cloud, 
00109                                      const Eigen::Vector4f &centroid, 
00110                                      Eigen::Matrix3f &covariance_matrix);
00111 
00123   template <typename PointT> inline void 
00124   computeCovarianceMatrix (const pcl::PointCloud<PointT> &cloud, 
00125                            const std::vector<int> &indices, 
00126                            const Eigen::Vector4f &centroid, 
00127                            Eigen::Matrix3f &covariance_matrix);
00128 
00140   template <typename PointT> inline void 
00141   computeCovarianceMatrix (const pcl::PointCloud<PointT> &cloud, 
00142                            const pcl::PointIndices &indices, 
00143                            const Eigen::Vector4f &centroid, 
00144                            Eigen::Matrix3f &covariance_matrix);
00145 
00156   template <typename PointT> inline void 
00157   computeCovarianceMatrixNormalized (const pcl::PointCloud<PointT> &cloud, 
00158                                      const std::vector<int> &indices, 
00159                                      const Eigen::Vector4f &centroid, 
00160                                      Eigen::Matrix3f &covariance_matrix);
00161 
00171   template <typename PointT> inline void 
00172   computeCovarianceMatrixNormalized (const pcl::PointCloud<PointT> &cloud, 
00173                                      const pcl::PointIndices &indices, 
00174                                      const Eigen::Vector4f &centroid, 
00175                                      Eigen::Matrix3f &covariance_matrix);
00176 
00183   template <typename PointT> void 
00184   demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in, 
00185                     const Eigen::Vector4f &centroid, 
00186                     pcl::PointCloud<PointT> &cloud_out);
00187 
00195   template <typename PointT> void 
00196   demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in, 
00197                     const std::vector<int> &indices, 
00198                     const Eigen::Vector4f &centroid, 
00199                     pcl::PointCloud<PointT> &cloud_out);
00200 
00209   template <typename PointT> void 
00210   demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in, 
00211                     const Eigen::Vector4f &centroid, 
00212                     Eigen::MatrixXf &cloud_out);
00213 
00223   template <typename PointT> void 
00224   demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in, 
00225                     const std::vector<int> &indices, 
00226                     const Eigen::Vector4f &centroid, 
00227                     Eigen::MatrixXf &cloud_out);
00228 
00238   template <typename PointT> void 
00239   demeanPointCloud (const pcl::PointCloud<PointT> &cloud_in, 
00240                     const pcl::PointIndices& indices, 
00241                     const Eigen::Vector4f &centroid, 
00242                     Eigen::MatrixXf &cloud_out);
00243 
00245   template<typename PointT>
00246   struct NdCentroidFunctor
00247   {
00248     typedef typename traits::POD<PointT>::type Pod;
00249     
00250     NdCentroidFunctor (const PointT &p, Eigen::VectorXf &centroid)
00251       : f_idx_ (0),
00252         centroid_ (centroid),
00253         p_ (reinterpret_cast<const Pod&>(p)) { }
00254 
00255     template<typename Key> inline void operator() ()
00256     {
00257       typedef typename pcl::traits::datatype<PointT, Key>::type T;
00258       const uint8_t* raw_ptr = reinterpret_cast<const uint8_t*>(&p_) + pcl::traits::offset<PointT, Key>::value;
00259       const T* data_ptr = reinterpret_cast<const T*>(raw_ptr);
00260 
00261       // Check if the value is invalid
00262       if (!pcl_isfinite (*data_ptr))
00263       {
00264         f_idx_++;
00265         return;
00266       }
00267 
00268       centroid_[f_idx_++] += *data_ptr;
00269     }
00270 
00271     private:
00272       int f_idx_;
00273       Eigen::VectorXf &centroid_;
00274       const Pod &p_;
00275   };
00276 
00283   template <typename PointT> inline void 
00284   computeNDCentroid (const pcl::PointCloud<PointT> &cloud, Eigen::VectorXf &centroid);
00285 
00293   template <typename PointT> inline void 
00294   computeNDCentroid (const pcl::PointCloud<PointT> &cloud, 
00295                      const std::vector<int> &indices, Eigen::VectorXf &centroid);
00296 
00304   template <typename PointT> inline void 
00305   computeNDCentroid (const pcl::PointCloud<PointT> &cloud, 
00306                      const pcl::PointIndices &indices, Eigen::VectorXf &centroid);
00307 
00308 }
00310 #include "pcl/common/impl/centroid.hpp"
00311 
00312 #endif  //#ifndef PCL_COMMON_CENTROID_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines