pfhrgb.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) 2011, Alexandru-Eugen Ichim
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 #ifndef PCL_FEATURES_IMPL_PFHRGB_H_
00041 #define PCL_FEATURES_IMPL_PFHRGB_H_
00042 
00043 #include <pcl/features/pfhrgb.h>
00044 
00046 template <typename PointInT, typename PointNT, typename PointOutT> bool
00047 pcl::PFHRGBEstimation<PointInT, PointNT, PointOutT>::computeRGBPairFeatures (
00048     const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals,
00049     int p_idx, int q_idx,
00050     float &f1, float &f2, float &f3, float &f4, float &f5, float &f6, float &f7)
00051 {
00052   Eigen::Vector4i colors1 (cloud.points[p_idx].r, cloud.points[p_idx].g, cloud.points[p_idx].b, 0),
00053       colors2 (cloud.points[q_idx].r, cloud.points[q_idx].g, cloud.points[q_idx].b, 0);
00054   pcl::computeRGBPairFeatures (cloud.points[p_idx].getVector4fMap (), normals.points[p_idx].getNormalVector4fMap (),
00055                                colors1,
00056                                cloud.points[q_idx].getVector4fMap (), normals.points[q_idx].getNormalVector4fMap (),
00057                                colors2,
00058                                f1, f2, f3, f4, f5, f6, f7);
00059   return (true);
00060 }
00061 
00063 template <typename PointInT, typename PointNT, typename PointOutT> void
00064 pcl::PFHRGBEstimation<PointInT, PointNT, PointOutT>::computePointPFHRGBSignature (
00065     const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals,
00066     const std::vector<int> &indices, int nr_split, Eigen::VectorXf &pfhrgb_histogram)
00067 {
00068   int h_index, h_p;
00069 
00070   // Clear the resultant point histogram
00071   pfhrgb_histogram.setZero ();
00072 
00073   // Factorization constant
00074   float hist_incr = 100.0f / static_cast<float> (indices.size () * indices.size () - 1);
00075 
00076   // Iterate over all the points in the neighborhood
00077   for (size_t i_idx = 0; i_idx < indices.size (); ++i_idx)
00078   {
00079     for (size_t j_idx = 0; j_idx < indices.size (); ++j_idx)
00080     {
00081       // Avoid unnecessary returns
00082       if (i_idx == j_idx)
00083         continue;
00084 
00085       // Compute the pair NNi to NNj
00086       if (!computeRGBPairFeatures (cloud, normals, indices[i_idx], indices[j_idx],
00087                                    pfhrgb_tuple_[0], pfhrgb_tuple_[1], pfhrgb_tuple_[2], pfhrgb_tuple_[3],
00088                                    pfhrgb_tuple_[4], pfhrgb_tuple_[5], pfhrgb_tuple_[6]))
00089         continue;
00090 
00091       // Normalize the f1, f2, f3, f5, f6, f7 features and push them in the histogram
00092       f_index_[0] = static_cast<int> (floor (nr_split * ((pfhrgb_tuple_[0] + M_PI) * d_pi_)));
00093       if (f_index_[0] < 0)         f_index_[0] = 0;
00094       if (f_index_[0] >= nr_split) f_index_[0] = nr_split - 1;
00095 
00096       f_index_[1] = static_cast<int> (floor (nr_split * ((pfhrgb_tuple_[1] + 1.0) * 0.5)));
00097       if (f_index_[1] < 0)         f_index_[1] = 0;
00098       if (f_index_[1] >= nr_split) f_index_[1] = nr_split - 1;
00099 
00100       f_index_[2] = static_cast<int> (floor (nr_split * ((pfhrgb_tuple_[2] + 1.0) * 0.5)));
00101       if (f_index_[2] < 0)         f_index_[2] = 0;
00102       if (f_index_[2] >= nr_split) f_index_[2] = nr_split - 1;
00103 
00104       // color ratios are in [-1, 1]
00105       f_index_[4] = static_cast<int> (floor (nr_split * ((pfhrgb_tuple_[4] + 1.0) * 0.5)));
00106       if (f_index_[4] < 0)         f_index_[4] = 0;
00107       if (f_index_[4] >= nr_split) f_index_[4] = nr_split - 1;
00108 
00109       f_index_[5] = static_cast<int> (floor (nr_split * ((pfhrgb_tuple_[5] + 1.0) * 0.5)));
00110       if (f_index_[5] < 0)         f_index_[5] = 0;
00111       if (f_index_[5] >= nr_split) f_index_[5] = nr_split - 1;
00112 
00113       f_index_[6] = static_cast<int> (floor (nr_split * ((pfhrgb_tuple_[6] + 1.0) * 0.5)));
00114       if (f_index_[6] < 0)         f_index_[6] = 0;
00115       if (f_index_[6] >= nr_split) f_index_[6] = nr_split - 1;
00116 
00117 
00118       // Copy into the histogram
00119       h_index = 0;
00120       h_p     = 1;
00121       for (int d = 0; d < 3; ++d)
00122       {
00123         h_index += h_p * f_index_[d];
00124         h_p     *= nr_split;
00125       }
00126       pfhrgb_histogram[h_index] += hist_incr;
00127 
00128       // and the colors
00129       h_index = 125;
00130       h_p     = 1;
00131       for (int d = 4; d < 7; ++d)
00132       {
00133         h_index += h_p * f_index_[d];
00134         h_p     *= nr_split;
00135       }
00136       pfhrgb_histogram[h_index] += hist_incr;
00137     }
00138   }
00139 }
00140 
00142 template <typename PointInT, typename PointNT, typename PointOutT> void
00143 pcl::PFHRGBEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output)
00144 {
00146   pfhrgb_histogram_.setZero (2 * nr_subdiv_ * nr_subdiv_ * nr_subdiv_);
00147   pfhrgb_tuple_.setZero (7);
00148 
00149   // Allocate enough space to hold the results
00150   // \note This resize is irrelevant for a radiusSearch ().
00151   std::vector<int> nn_indices (k_);
00152   std::vector<float> nn_dists (k_);
00153 
00154   // Iterating over the entire index vector
00155   for (size_t idx = 0; idx < indices_->size (); ++idx)
00156   {
00157     this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists);
00158 
00159     // Estimate the PFH signature at each patch
00160     computePointPFHRGBSignature (*surface_, *normals_, nn_indices, nr_subdiv_, pfhrgb_histogram_);
00161 
00162     // Copy into the resultant cloud
00163     for (int d = 0; d < pfhrgb_histogram_.size (); ++d) {
00164       output.points[idx].histogram[d] = pfhrgb_histogram_[d];
00165 //      PCL_INFO ("%f ", pfhrgb_histogram_[d]);
00166     }
00167 //    PCL_INFO ("\n");
00168   }
00169 }
00170 
00171 #define PCL_INSTANTIATE_PFHRGBEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PFHRGBEstimation<T,NT,OutT>;
00172 
00173 #endif /* PCL_FEATURES_IMPL_PFHRGB_H_ */


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:28:14