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 #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
00069 pfhrgb_histogram.setZero ();
00070
00071
00072 float hist_incr = 100.0f / static_cast<float> (indices.size () * indices.size () - 1);
00073
00074
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
00080 if (i_idx == j_idx)
00081 continue;
00082
00083
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
00090 f_index_[0] = static_cast<int> (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] = static_cast<int> (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] = static_cast<int> (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
00103 f_index_[4] = static_cast<int> (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] = static_cast<int> (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] = static_cast<int> (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
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
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
00148
00149 std::vector<int> nn_indices (k_);
00150 std::vector<float> nn_dists (k_);
00151
00152
00153 for (size_t idx = 0; idx < indices_->size (); ++idx)
00154 {
00155 this->searchForNeighbors ((*indices_)[idx], search_parameter_, nn_indices, nn_dists);
00156
00157
00158 computePointPFHRGBSignature (*surface_, *normals_, nn_indices, nr_subdiv_, pfhrgb_histogram_);
00159
00160
00161 for (int d = 0; d < pfhrgb_histogram_.size (); ++d) {
00162 output.points[idx].histogram[d] = pfhrgb_histogram_[d];
00163
00164 }
00165
00166 }
00167 }
00168
00169 #define PCL_INSTANTIATE_PFHRGBEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::PFHRGBEstimation<T,NT,OutT>;
00170
00171 #endif