41 #ifndef PCL_FEATURES_IMPL_RIFT_H_
42 #define PCL_FEATURES_IMPL_RIFT_H_
44 #include <pcl/features/rift.h>
47 template <
typename Po
intInT,
typename GradientT,
typename Po
intOutT>
void
51 const std::vector<float> &sqr_distances, Eigen::MatrixXf &rift_descriptor)
55 PCL_ERROR (
"[pcl::RIFTEstimation] Null indices points passed!\n");
60 int nr_distance_bins =
static_cast<int> (rift_descriptor.rows ());
61 int nr_gradient_bins =
static_cast<int> (rift_descriptor.cols ());
67 rift_descriptor.setZero ();
68 for (std::size_t idx = 0; idx < indices.size (); ++idx)
72 Eigen::Map<const Eigen::Vector3f> gradient_vector (& (gradient[indices[idx]].gradient[0]));
74 float gradient_magnitude = gradient_vector.norm ();
75 float gradient_angle_from_center = std::acos (gradient_vector.dot ((point - p0).normalized ()) / gradient_magnitude);
76 if (!std::isfinite (gradient_angle_from_center))
77 gradient_angle_from_center = 0.0;
80 const float eps = std::numeric_limits<float>::epsilon ();
81 float d =
static_cast<float> (nr_distance_bins) * std::sqrt (sqr_distances[idx]) / (radius + eps);
82 float g =
static_cast<float> (nr_gradient_bins) * gradient_angle_from_center / (
static_cast<float> (
M_PI) + eps);
85 int d_idx_min = (std::max)(
static_cast<int> (std::ceil (d - 1)), 0);
86 int d_idx_max = (std::min)(
static_cast<int> (std::floor (d + 1)), nr_distance_bins - 1);
87 int g_idx_min =
static_cast<int> (std::ceil (g - 1));
88 int g_idx_max =
static_cast<int> (std::floor (g + 1));
91 for (
int g_idx = g_idx_min; g_idx <= g_idx_max; ++g_idx)
94 int g_idx_wrapped = ((g_idx + nr_gradient_bins) % nr_gradient_bins);
96 for (
int d_idx = d_idx_min; d_idx <= d_idx_max; ++d_idx)
99 float w = (1.0f - std::abs (d -
static_cast<float> (d_idx))) * (1.0f - std::abs (g -
static_cast<float> (g_idx)));
101 rift_descriptor (d_idx, g_idx_wrapped) += w * gradient_magnitude;
107 rift_descriptor.normalize ();
112 template <
typename Po
intInT,
typename GradientT,
typename Po
intOutT>
void
116 if (search_radius_ == 0.0)
118 PCL_ERROR (
"[pcl::%s::computeFeature] The search radius must be set before computing the feature!\n",
119 getClassName ().c_str ());
126 if (nr_gradient_bins_ <= 0)
128 PCL_ERROR (
"[pcl::%s::computeFeature] The number of gradient bins must be greater than zero!\n",
129 getClassName ().c_str ());
134 if (nr_distance_bins_ <= 0)
136 PCL_ERROR (
"[pcl::%s::computeFeature] The number of distance bins must be greater than zero!\n",
137 getClassName ().c_str ());
146 PCL_ERROR (
"[pcl::%s::computeFeature] No input gradient was given!\n", getClassName ().c_str ());
151 if (gradient_->size () != surface_->size ())
153 PCL_ERROR (
"[pcl::%s::computeFeature] ", getClassName ().c_str ());
154 PCL_ERROR (
"The number of points in the input dataset differs from the number of points in the gradient!\n");
160 Eigen::MatrixXf rift_descriptor (nr_distance_bins_, nr_gradient_bins_);
162 std::vector<float> nn_dist_sqr;
165 for (std::size_t idx = 0; idx < indices_->size (); ++idx)
168 tree_->radiusSearch ((*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr);
171 computeRIFT (*surface_, *gradient_, (*indices_)[idx],
static_cast<float> (search_radius_), nn_indices, nn_dist_sqr, rift_descriptor);
174 std::copy (rift_descriptor.data (), rift_descriptor.data () + rift_descriptor.size (), output[idx].histogram);
178 #define PCL_INSTANTIATE_RIFTEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::RIFTEstimation<T,NT,OutT>;
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
void clear()
Removes all points in a cloud and sets the width and height to 0.
void computeFeature(PointCloudOut &output) override
Estimate the Rotation Invariant Feature Transform (RIFT) descriptors at a set of points given by <set...
void computeRIFT(const PointCloudIn &cloud, const PointCloudGradient &gradient, int p_idx, float radius, const pcl::Indices &indices, const std::vector< float > &squared_distances, Eigen::MatrixXf &rift_descriptor)
Estimate the Rotation Invariant Feature Transform (RIFT) descriptor for a given point based on its sp...
const Eigen::Map< const Eigen::Vector3f > Vector3fMapConst
IndicesAllocator<> Indices
Type used for indices in PCL.