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_VFH_H_
00039 #define PCL_FEATURES_IMPL_VFH_H_
00040
00041 #include "pcl/features/vfh.h"
00042 #include "pcl/features/pfh.h"
00043 #include <pcl/common/common.h>
00044
00046 template<typename PointInT, typename PointNT, typename PointOutT> void
00047 pcl::VFHEstimation<PointInT, PointNT, PointOutT>::computePointSPFHSignature (const Eigen::Vector4f ¢roid_p,
00048 const Eigen::Vector4f ¢roid_n,
00049 const pcl::PointCloud<PointInT> &cloud,
00050 const pcl::PointCloud<PointNT> &normals,
00051 const std::vector<int> &indices)
00052 {
00053 Eigen::Vector4f pfh_tuple;
00054
00055 hist_f1_.setZero (nr_bins_f1_);
00056 hist_f2_.setZero (nr_bins_f2_);
00057 hist_f3_.setZero (nr_bins_f3_);
00058 hist_f4_.setZero (nr_bins_f4_);
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 Eigen::Vector4f max_pt;
00070 pcl::getMaxDistance (cloud, indices, centroid_p, max_pt);
00071 double distance_normalization_factor = (centroid_p - max_pt).norm ();
00072
00073
00074 float hist_incr = 100.0 / (float)(indices.size () - 1);
00075
00076
00077 for (size_t idx = 0; idx < indices.size (); ++idx)
00078 {
00079
00080 if (!computePairFeatures (centroid_p, centroid_n, cloud.points[indices[idx]].getVector4fMap (),
00081 normals.points[indices[idx]].getNormalVector4fMap (), pfh_tuple[0], pfh_tuple[1],
00082 pfh_tuple[2], pfh_tuple[3]))
00083 continue;
00084
00085
00086 int h_index = floor (nr_bins_f1_ * ((pfh_tuple[0] + M_PI) * d_pi_));
00087 if (h_index < 0)
00088 h_index = 0;
00089 if (h_index >= nr_bins_f1_)
00090 h_index = nr_bins_f1_ - 1;
00091 hist_f1_ (h_index) += hist_incr;
00092
00093 h_index = floor (nr_bins_f2_ * ((pfh_tuple[1] + 1.0) * 0.5));
00094 if (h_index < 0)
00095 h_index = 0;
00096 if (h_index >= nr_bins_f2_)
00097 h_index = nr_bins_f2_ - 1;
00098 hist_f2_ (h_index) += hist_incr;
00099
00100 h_index = floor (nr_bins_f3_ * ((pfh_tuple[2] + 1.0) * 0.5));
00101 if (h_index < 0)
00102 h_index = 0;
00103 if (h_index >= nr_bins_f3_)
00104 h_index = nr_bins_f3_ - 1;
00105 hist_f3_ (h_index) += hist_incr;
00106
00107 h_index = floor (nr_bins_f4_ * (pfh_tuple[3] / distance_normalization_factor));
00108 if (h_index < 0)
00109 h_index = 0;
00110 if (h_index >= nr_bins_f4_)
00111 h_index = nr_bins_f4_ - 1;
00112 hist_f4_ (h_index) += hist_incr;
00113 }
00114 }
00116 template <typename PointInT, typename PointNT, typename PointOutT> void
00117 pcl::VFHEstimation<PointInT, PointNT, PointOutT>::computeFeature (PointCloudOut &output)
00118 {
00119
00120 if (!normals_)
00121 {
00122 ROS_ERROR ("[pcl::%s::computeFeature] No input dataset containing normals was given!", getClassName ().c_str ());
00123 output.width = output.height = 0;
00124 output.points.clear ();
00125 return;
00126 }
00127 if (normals_->points.size () != surface_->points.size ())
00128 {
00129 ROS_ERROR ("[pcl::%s::computeFeature] The number of points in the input dataset differs from the number of points in the dataset containing the normals!", getClassName ().c_str ());
00130 output.width = output.height = 0;
00131 output.points.clear ();
00132 return;
00133 }
00134
00135
00136 Eigen::Vector4f xyz_centroid;
00137 compute3DCentroid (*surface_, *indices_, xyz_centroid);
00138
00139
00140 Eigen::Vector4f normal_centroid = Eigen::Vector4f::Zero ();
00141 int cp = 0;
00142
00143
00144 if (normals_->is_dense)
00145 {
00146 for (size_t i = 0; i < indices_->size (); ++i)
00147 {
00148 normal_centroid += normals_->points[(*indices_)[i]].getNormalVector4fMap ();
00149 cp++;
00150 }
00151 }
00152
00153 else
00154 {
00155 for (size_t i = 0; i < indices_->size (); ++i)
00156 {
00157 if (!pcl_isfinite (normals_->points[(*indices_)[i]].normal[0]) ||
00158 !pcl_isfinite (normals_->points[(*indices_)[i]].normal[1]) ||
00159 !pcl_isfinite (normals_->points[(*indices_)[i]].normal[2]))
00160 continue;
00161 normal_centroid += normals_->points[(*indices_)[i]].getNormalVector4fMap ();
00162 cp++;
00163 }
00164 }
00165 normal_centroid /= cp;
00166
00167
00168 Eigen::Vector4f viewpoint (vpx_, vpy_, vpz_, 0);
00169 Eigen::Vector4f d_vp_p = viewpoint - xyz_centroid;
00170 d_vp_p.normalize ();
00171
00172
00173 computePointSPFHSignature (xyz_centroid, normal_centroid, *surface_, *normals_, *indices_);
00174
00175
00176 output.points.resize (1);
00177 output.width = 1;
00178 output.height = 1;
00179
00180
00181 for (int d = 0; d < hist_f1_.size (); ++d)
00182 output.points[0].histogram[d + 0] = hist_f1_[d];
00183
00184 size_t data_size = hist_f1_.size ();
00185 for (int d = 0; d < hist_f2_.size (); ++d)
00186 output.points[0].histogram[d + data_size] = hist_f2_[d];
00187
00188 data_size += hist_f2_.size ();
00189 for (int d = 0; d < hist_f3_.size (); ++d)
00190 output.points[0].histogram[d + data_size] = hist_f3_[d];
00191
00192 data_size += hist_f3_.size ();
00193 for (int d = 0; d < hist_f4_.size (); ++d)
00194 output.points[0].histogram[d + data_size] = hist_f4_[d];
00195
00196
00197 hist_vp_.setZero (nr_bins_vp_);
00198 double hist_incr = 100.0 / (double)(indices_->size ());
00199 for (size_t i = 0; i < indices_->size (); ++i)
00200 {
00201 Eigen::Vector4f normal (normals_->points[(*indices_)[i]].normal[0],
00202 normals_->points[(*indices_)[i]].normal[1],
00203 normals_->points[(*indices_)[i]].normal[2], 0);
00204
00205 double alpha = (normal.dot (d_vp_p) + 1.0) * 0.5;
00206 int fi = floor (alpha * hist_vp_.size ());
00207 if (fi < 0)
00208 fi = 0;
00209 if (fi > ((int)hist_vp_.size () - 1))
00210 fi = hist_vp_.size () - 1;
00211
00212 hist_vp_ [fi] += hist_incr;
00213 }
00214 data_size += hist_f4_.size ();
00215
00216 for (int d = 0; d < hist_vp_.size (); ++d)
00217 output.points[0].histogram[d + data_size] = hist_vp_[d];
00218 }
00219
00220 #define PCL_INSTANTIATE_VFHEstimation(T,NT,OutT) template class pcl::VFHEstimation<T,NT,OutT>;
00221
00222 #endif // PCL_FEATURES_IMPL_VFH_H_