moment_invariants.hpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  * $Id$
00038  *
00039  */
00040 
00041 #ifndef PCL_FEATURES_IMPL_MOMENT_INVARIANTS_H_
00042 #define PCL_FEATURES_IMPL_MOMENT_INVARIANTS_H_
00043 
00044 #include <pcl/features/moment_invariants.h>
00045 #include <pcl/common/centroid.h>
00046 
00048 template <typename PointInT, typename PointOutT> void
00049 pcl::MomentInvariantsEstimation<PointInT, PointOutT>::computePointMomentInvariants (
00050       const pcl::PointCloud<PointInT> &cloud, const std::vector<int> &indices,
00051       float &j1, float &j2, float &j3)
00052 {
00053   // Estimate the XYZ centroid
00054   compute3DCentroid (cloud, indices, xyz_centroid_);
00055 
00056   // Initalize the centralized moments
00057   float mu200 = 0, mu020 = 0, mu002 = 0, mu110 = 0, mu101 = 0, mu011  = 0;
00058 
00059   // Iterate over the nearest neighbors set
00060   for (size_t nn_idx = 0; nn_idx < indices.size (); ++nn_idx)
00061   {
00062     // Demean the points
00063     temp_pt_[0] = cloud.points[indices[nn_idx]].x - xyz_centroid_[0];
00064     temp_pt_[1] = cloud.points[indices[nn_idx]].y - xyz_centroid_[1];
00065     temp_pt_[2] = cloud.points[indices[nn_idx]].z - xyz_centroid_[2];
00066 
00067     mu200 += temp_pt_[0] * temp_pt_[0];
00068     mu020 += temp_pt_[1] * temp_pt_[1];
00069     mu002 += temp_pt_[2] * temp_pt_[2];
00070     mu110 += temp_pt_[0] * temp_pt_[1];
00071     mu101 += temp_pt_[0] * temp_pt_[2];
00072     mu011 += temp_pt_[1] * temp_pt_[2];
00073   }
00074 
00075   // Save the moment invariants
00076   j1 = mu200             + mu020               + mu002;
00077   j2 = mu200*mu020       + mu200*mu002         + mu020*mu002       - mu110*mu110       - mu101*mu101       - mu011*mu011;
00078   j3 = mu200*mu020*mu002 + 2*mu110*mu101*mu011 - mu002*mu110*mu110 - mu020*mu101*mu101 - mu200*mu011*mu011;
00079 }
00080 
00082 template <typename PointInT, typename PointOutT> void
00083 pcl::MomentInvariantsEstimation<PointInT, PointOutT>::computePointMomentInvariants (
00084       const pcl::PointCloud<PointInT> &cloud, float &j1, float &j2, float &j3)
00085 {
00086   // Estimate the XYZ centroid
00087   compute3DCentroid (cloud, xyz_centroid_);
00088 
00089   // Initalize the centralized moments
00090   float mu200 = 0, mu020 = 0, mu002 = 0, mu110 = 0, mu101 = 0, mu011  = 0;
00091 
00092   // Iterate over the nearest neighbors set
00093   for (size_t nn_idx = 0; nn_idx < cloud.points.size (); ++nn_idx )
00094   {
00095     // Demean the points
00096     temp_pt_[0] = cloud.points[nn_idx].x - xyz_centroid_[0];
00097     temp_pt_[1] = cloud.points[nn_idx].y - xyz_centroid_[1];
00098     temp_pt_[2] = cloud.points[nn_idx].z - xyz_centroid_[2];
00099 
00100     mu200 += temp_pt_[0] * temp_pt_[0];
00101     mu020 += temp_pt_[1] * temp_pt_[1];
00102     mu002 += temp_pt_[2] * temp_pt_[2];
00103     mu110 += temp_pt_[0] * temp_pt_[1];
00104     mu101 += temp_pt_[0] * temp_pt_[2];
00105     mu011 += temp_pt_[1] * temp_pt_[2];
00106   }
00107 
00108   // Save the moment invariants
00109   j1 = mu200             + mu020               + mu002;
00110   j2 = mu200*mu020       + mu200*mu002         + mu020*mu002       - mu110*mu110       - mu101*mu101       - mu011*mu011;
00111   j3 = mu200*mu020*mu002 + 2*mu110*mu101*mu011 - mu002*mu110*mu110 - mu020*mu101*mu101 - mu200*mu011*mu011;
00112 }
00113 
00115 template <typename PointInT, typename PointOutT> void
00116 pcl::MomentInvariantsEstimation<PointInT, PointOutT>::computeFeature (PointCloudOut &output)
00117 {
00118   // Allocate enough space to hold the results
00119   // \note This resize is irrelevant for a radiusSearch ().
00120   std::vector<int> nn_indices (k_);
00121   std::vector<float> nn_dists (k_);
00122 
00123   output.is_dense = true;
00124   // Save a few cycles by not checking every point for NaN/Inf values if the cloud is set to dense
00125   if (input_->is_dense)
00126   {
00127     // Iterating over the entire index vector
00128     for (size_t idx = 0; idx < indices_->size (); ++idx)
00129     {
00130       if (this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00131       {
00132         output.points[idx].j1 = output.points[idx].j2 = output.points[idx].j3 = std::numeric_limits<float>::quiet_NaN ();
00133         output.is_dense = false;
00134         continue;
00135       }
00136      
00137       computePointMomentInvariants (*surface_, nn_indices,
00138                                     output.points[idx].j1, output.points[idx].j2, output.points[idx].j3);
00139     }
00140   }
00141   else
00142   {
00143     // Iterating over the entire index vector
00144     for (size_t idx = 0; idx < indices_->size (); ++idx)
00145     {
00146       if (!isFinite ((*input_)[(*indices_)[idx]]) ||
00147           this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists) == 0)
00148       {
00149         output.points[idx].j1 = output.points[idx].j2 = output.points[idx].j3 = std::numeric_limits<float>::quiet_NaN ();
00150         output.is_dense = false;
00151         continue;
00152       }
00153 
00154       computePointMomentInvariants (*surface_, nn_indices,
00155                                     output.points[idx].j1, output.points[idx].j2, output.points[idx].j3);
00156     }
00157   }
00158 }
00159 
00160 #define PCL_INSTANTIATE_MomentInvariantsEstimation(T,NT) template class PCL_EXPORTS pcl::MomentInvariantsEstimation<T,NT>;
00161 
00162 #endif    // PCL_FEATURES_IMPL_MOMENT_INVARIANTS_H_ 
00163 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:25:40