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_RIFT_H_
00039 #define PCL_FEATURES_IMPL_RIFT_H_
00040
00041 #include "pcl/features/rift.h"
00042
00044 template <typename PointInT, typename GradientT, typename PointOutT> void
00045 pcl::RIFTEstimation<PointInT, GradientT, PointOutT>::computeRIFT (
00046 const PointCloudIn &cloud, const PointCloudGradient &gradient,
00047 int p_idx, float radius, const std::vector<int> &indices,
00048 const std::vector<float> &sqr_distances, Eigen::MatrixXf &rift_descriptor)
00049 {
00050 if (indices.empty ())
00051 {
00052 ROS_ERROR ("[pcl::RIFTEstimation] Null indices points passed!");
00053 return;
00054 }
00055
00056
00057 int nr_distance_bins = rift_descriptor.cols ();
00058 int nr_gradient_bins = rift_descriptor.rows ();
00059
00060
00061 pcl::Vector3fMapConst p0 = cloud.points[p_idx].getVector3fMap ();
00062
00063
00064 rift_descriptor.setZero ();
00065 for (size_t idx = 0; idx < indices.size (); ++idx)
00066 {
00067
00069 pcl::Vector3fMapConst point = cloud.points[indices[idx]].getVector3fMap ();
00070 Eigen::Map<const Eigen::Vector3f> gradient_vector (& (gradient.points[indices[idx]].gradient[0]));
00071
00072 float gradient_magnitude = gradient_vector.norm ();
00073 float gradient_angle_from_center = acos (gradient_vector.dot ((point - p0).normalized ()) / gradient_magnitude);
00074 if (!pcl_isfinite (gradient_angle_from_center))
00075 {
00076 gradient_angle_from_center = 0.0;
00077 }
00078
00079
00080 const float eps = std::numeric_limits<float>::epsilon ();
00081 float d = nr_distance_bins * sqrt (sqr_distances[idx]) / (radius + eps);
00082 float g = nr_gradient_bins * gradient_angle_from_center / (M_PI + eps);
00083
00084
00085 int d_idx_min = (std::max)((int) ceil (d - 1), 0);
00086 int d_idx_max = (std::min)((int) floor (d + 1), nr_distance_bins - 1);
00087 int g_idx_min = (int) ceil (g - 1);
00088 int g_idx_max = (int) floor (g + 1);
00089
00090
00091 for (int g_idx = g_idx_min; g_idx <= g_idx_max; ++g_idx)
00092 {
00093
00094 int g_idx_wrapped = ((g_idx + nr_gradient_bins) % nr_gradient_bins);
00095
00096 for (int d_idx = d_idx_min; d_idx <= d_idx_max; ++d_idx)
00097 {
00098
00099 float w = (1 - fabs (d - d_idx)) * (1 - fabs (g - g_idx));
00100
00101 rift_descriptor (g_idx_wrapped * nr_distance_bins + d_idx) += w * gradient_magnitude;
00102 }
00103 }
00104 }
00105
00106
00107 rift_descriptor.normalize ();
00108 }
00109
00110
00112 template <typename PointInT, typename GradientT, typename PointOutT> void
00113 pcl::RIFTEstimation<PointInT, GradientT, PointOutT>::computeFeature (PointCloudOut &output)
00114 {
00115
00116 if (search_radius_ == 0.0)
00117 {
00118 ROS_ERROR ("[pcl::%s::computeFeature] The search radius must be set before computing the feature!",
00119 getClassName ().c_str ());
00120 output.width = output.height = 0;
00121 output.points.clear ();
00122 return;
00123 }
00124
00125
00126 if (nr_gradient_bins_ <= 0)
00127 {
00128 ROS_ERROR ("[pcl::%s::computeFeature] The number of gradient bins must be greater than zero!",
00129 getClassName ().c_str ());
00130 output.width = output.height = 0;
00131 output.points.clear ();
00132 return;
00133 }
00134 if (nr_distance_bins_ <= 0)
00135 {
00136 ROS_ERROR ("[pcl::%s::computeFeature] The number of distance bins must be greater than zero!",
00137 getClassName ().c_str ());
00138 output.width = output.height = 0;
00139 output.points.clear ();
00140 return;
00141 }
00142
00143
00144 if (!gradient_)
00145 {
00146 ROS_ERROR ("[pcl::%s::computeFeature] No input gradient was given!", getClassName ().c_str ());
00147 output.width = output.height = 0;
00148 output.points.clear ();
00149 return;
00150 }
00151 if (gradient_->points.size () != surface_->points.size ())
00152 {
00153 ROS_ERROR ("[pcl::%s::computeFeature] The number of points in the input dataset differs from the number of points in the gradient!", getClassName ().c_str ());
00154 output.width = output.height = 0;
00155 output.points.clear ();
00156 return;
00157 }
00158
00159 Eigen::MatrixXf rift_descriptor (nr_gradient_bins_, nr_distance_bins_);
00160 std::vector<int> nn_indices;
00161 std::vector<float> nn_dist_sqr;
00162
00163
00164 for (size_t idx = 0; idx < indices_->size (); ++idx)
00165 {
00166
00167 tree_->radiusSearch ((*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr);
00168
00169
00170 computeRIFT (*surface_, *gradient_, (*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr, rift_descriptor);
00171
00172
00173 for (int bin = 0; bin < rift_descriptor.size (); ++bin)
00174 output.points[idx].histogram[bin] = rift_descriptor (bin);
00175 }
00176 }
00177
00178 #define PCL_INSTANTIATE_RIFTEstimation(T,NT,OutT) template class pcl::RIFTEstimation<T,NT,OutT>;
00179
00180 #endif // PCL_FEATURES_IMPL_RIFT_H_
00181