Point Cloud Library (PCL)
1.3.1
|
00001 /* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2011, Alexandru-Eugen Ichim 00005 * Willow Garage, Inc 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of Willow Garage, Inc. nor the names of its 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00029 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00031 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00032 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00033 * POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 * $Id: pfhrgb.hpp 3023 2011-11-01 03:42:32Z svn $ 00036 */ 00037 00038 #ifndef PCL_FEATURES_IMPL_PFHRGB_H_ 00039 #define PCL_FEATURES_IMPL_PFHRGB_H_ 00040 00041 #include "pcl/features/pfhrgb.h" 00042 00044 template <typename PointInT, typename PointNT, typename PointOutT> bool 00045 pcl::PFHRGBEstimation<PointInT, PointNT, PointOutT>::computeRGBPairFeatures ( 00046 const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 00047 int p_idx, int q_idx, 00048 float &f1, float &f2, float &f3, float &f4, float &f5, float &f6, float &f7) 00049 { 00050 Eigen::Vector4i colors1 (cloud.points[p_idx].r, cloud.points[p_idx].g, cloud.points[p_idx].b, 0), 00051 colors2 (cloud.points[q_idx].r, cloud.points[q_idx].g, cloud.points[q_idx].b, 0); 00052 pcl::computeRGBPairFeatures (cloud.points[p_idx].getVector4fMap (), normals.points[p_idx].getNormalVector4fMap (), 00053 colors1, 00054 cloud.points[q_idx].getVector4fMap (), normals.points[q_idx].getNormalVector4fMap (), 00055 colors2, 00056 f1, f2, f3, f4, f5, f6, f7); 00057 return (true); 00058 } 00059 00061 template <typename PointInT, typename PointNT, typename PointOutT> void 00062 pcl::PFHRGBEstimation<PointInT, PointNT, PointOutT>::computePointPFHRGBSignature ( 00063 const pcl::PointCloud<PointInT> &cloud, const pcl::PointCloud<PointNT> &normals, 00064 const std::vector<int> &indices, int nr_split, Eigen::VectorXf &pfhrgb_histogram) 00065 { 00066 int h_index, h_p; 00067 00068 // Clear the resultant point histogram 00069 pfhrgb_histogram.setZero (); 00070 00071 // Factorization constant 00072 float hist_incr = 100.0 / (indices.size () * indices.size () - 1); 00073 00074 // Iterate over all the points in the neighborhood 00075 for (size_t i_idx = 0; i_idx < indices.size (); ++i_idx) 00076 { 00077 for (size_t j_idx = 0; j_idx < indices.size (); ++j_idx) 00078 { 00079 // Avoid unnecessary returns 00080 if (i_idx == j_idx) 00081 continue; 00082 00083 // Compute the pair NNi to NNj 00084 if (!computeRGBPairFeatures (cloud, normals, indices[i_idx], indices[j_idx], 00085 pfhrgb_tuple_[0], pfhrgb_tuple_[1], pfhrgb_tuple_[2], pfhrgb_tuple_[3], 00086 pfhrgb_tuple_[4], pfhrgb_tuple_[5], pfhrgb_tuple_[6])) 00087 continue; 00088 00089 // Normalize the f1, f2, f3, f5, f6, f7 features and push them in the histogram 00090 f_index_[0] = floor (nr_split * ((pfhrgb_tuple_[0] + M_PI) * d_pi_)); 00091 if (f_index_[0] < 0) f_index_[0] = 0; 00092 if (f_index_[0] >= nr_split) f_index_[0] = nr_split - 1; 00093 00094 f_index_[1] = floor (nr_split * ((pfhrgb_tuple_[1] + 1.0) * 0.5)); 00095 if (f_index_[1] < 0) f_index_[1] = 0; 00096 if (f_index_[1] >= nr_split) f_index_[1] = nr_split - 1; 00097 00098 f_index_[2] = floor (nr_split * ((pfhrgb_tuple_[2] + 1.0) * 0.5)); 00099 if (f_index_[2] < 0) f_index_[2] = 0; 00100 if (f_index_[2] >= nr_split) f_index_[2] = nr_split - 1; 00101 00102 // color ratios are in [-1, 1] 00103 f_index_[4] = floor (nr_split * ((pfhrgb_tuple_[4] + 1.0) * 0.5)); 00104 if (f_index_[4] < 0) f_index_[4] = 0; 00105 if (f_index_[4] >= nr_split) f_index_[4] = nr_split - 1; 00106 00107 f_index_[5] = floor (nr_split * ((pfhrgb_tuple_[5] + 1.0) * 0.5)); 00108 if (f_index_[5] < 0) f_index_[5] = 0; 00109 if (f_index_[5] >= nr_split) f_index_[5] = nr_split - 1; 00110 00111 f_index_[6] = floor (nr_split * ((pfhrgb_tuple_[6] + 1.0) * 0.5)); 00112 if (f_index_[6] < 0) f_index_[6] = 0; 00113 if (f_index_[6] >= nr_split) f_index_[6] = nr_split - 1; 00114 00115 00116 // Copy into the histogram 00117 h_index = 0; 00118 h_p = 1; 00119 for (int d = 0; d < 3; ++d) 00120 { 00121 h_index += h_p * f_index_[d]; 00122 h_p *= nr_split; 00123 } 00124 pfhrgb_histogram[h_index] += hist_incr; 00125 00126 // and the colors 00127 h_index = 125; 00128 h_p = 1; 00129 for (int d = 4; d < 7; ++d) 00130 { 00131 h_index += h_p * f_index_[d]; 00132 h_p *= nr_split; 00133 } 00134 pfhrgb_histogram[h_index] += hist_incr; 00135 } 00136 } 00137 } 00138 00140 template <typename PointInT, typename PointNT, typename PointOutT> void 00141 pcl::PFHRGBEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output) 00142 { 00144 pfhrgb_histogram_.setZero (2 * nr_subdiv_ * nr_subdiv_ * nr_subdiv_); 00145 pfhrgb_tuple_.setZero (7); 00146 00147 // Allocate enough space to hold the results 00148 // \note This resize is irrelevant for a radiusSearch (). 00149 std::vector<int> nn_indices (k_); 00150 std::vector<float> nn_dists (k_); 00151 00152 // Iterating over the entire index vector 00153 for (size_t idx = 0; idx < indices_->size (); ++idx) 00154 { 00155 this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists); 00156 00157 // Estimate the PFH signature at each patch 00158 computePointPFHRGBSignature (*surface_, *normals_, nn_indices, nr_subdiv_, pfhrgb_histogram_); 00159 00160 // Copy into the resultant cloud 00161 for (int d = 0; d < pfhrgb_histogram_.size (); ++d) { 00162 output.points[idx].histogram[d] = pfhrgb_histogram_[d]; 00163 // PCL_INFO ("%f ", pfhrgb_histogram_[d]); 00164 } 00165 // PCL_INFO ("\n"); 00166 } 00167 } 00168 00169 #define PCL_INSTANTIATE_PFHRGBEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PFHRGBEstimation<T,NT,OutT>; 00170 00171 #endif /* PCL_FEATURES_IMPL_PFHRGB_H_ */