00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00071 pfhrgb_histogram.setZero ();
00072
00073
00074 float hist_incr = 100.0f / static_cast<float> (indices.size () * indices.size () - 1);
00075
00076
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
00082 if (i_idx == j_idx)
00083 continue;
00084
00085
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
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
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
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
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
00150
00151 std::vector<int> nn_indices (k_);
00152 std::vector<float> nn_dists (k_);
00153
00154
00155 for (size_t idx = 0; idx < indices_->size (); ++idx)
00156 {
00157 this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists);
00158
00159
00160 computePointPFHRGBSignature (*surface_, *normals_, nn_indices, nr_subdiv_, pfhrgb_histogram_);
00161
00162
00163 for (int d = 0; d < pfhrgb_histogram_.size (); ++d) {
00164 output.points[idx].histogram[d] = pfhrgb_histogram_[d];
00165
00166 }
00167
00168 }
00169 }
00170
00171 #define PCL_INSTANTIATE_PFHRGBEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PFHRGBEstimation<T,NT,OutT>;
00172
00173 #endif