41 #ifndef PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
42 #define PCL_FEATURES_IMPL_INTENSITY_SPIN_H_
44 #include <pcl/features/intensity_spin.h>
47 template <
typename Po
intInT,
typename Po
intOutT>
void
52 const std::vector<float> &squared_distances,
53 Eigen::MatrixXf &intensity_spin_image)
56 int nr_distance_bins =
static_cast<int> (intensity_spin_image.cols ());
57 int nr_intensity_bins =
static_cast<int> (intensity_spin_image.rows ());
60 float min_intensity = std::numeric_limits<float>::max ();
61 float max_intensity = -std::numeric_limits<float>::max ();
62 for (
int idx = 0; idx < k; ++idx)
64 min_intensity = (std::min) (min_intensity, cloud[indices[idx]].intensity);
65 max_intensity = (std::max) (max_intensity, cloud[indices[idx]].intensity);
68 float constant = 1.0f / (2.0f * sigma_ * sigma_);
70 intensity_spin_image.setZero ();
71 for (
int idx = 0; idx < k; ++idx)
74 const float eps = std::numeric_limits<float>::epsilon ();
75 float d =
static_cast<float> (nr_distance_bins) * std::sqrt (squared_distances[idx]) / (radius + eps);
76 float i =
static_cast<float> (nr_intensity_bins) *
77 (cloud[indices[idx]].intensity - min_intensity) / (max_intensity - min_intensity + eps);
82 int d_idx =
static_cast<int> (d);
83 int i_idx =
static_cast<int> (i);
84 intensity_spin_image (i_idx, d_idx) += 1;
89 int d_idx_min = (std::max)(
static_cast<int> (std::floor (d - 3*sigma)), 0);
90 int d_idx_max = (std::min)(
static_cast<int> (std::ceil (d + 3*sigma)), nr_distance_bins - 1);
91 int i_idx_min = (std::max)(
static_cast<int> (std::floor (i - 3*sigma)), 0);
92 int i_idx_max = (std::min)(
static_cast<int> (std::ceil (i + 3*sigma)), nr_intensity_bins - 1);
95 for (
int i_idx = i_idx_min; i_idx <= i_idx_max; ++i_idx)
97 for (
int d_idx = d_idx_min; d_idx <= d_idx_max; ++d_idx)
100 float w = std::exp (-powf (d -
static_cast<float> (d_idx), 2.0f) * constant - powf (i -
static_cast<float> (i_idx), 2.0f) * constant);
101 intensity_spin_image (i_idx, d_idx) += w;
109 template <
typename Po
intInT,
typename Po
intOutT>
void
113 if (search_radius_ == 0.0)
115 PCL_ERROR (
"[pcl::%s::computeFeature] The search radius must be set before computing the feature!\n",
116 getClassName ().c_str ());
123 if (nr_intensity_bins_ <= 0)
125 PCL_ERROR (
"[pcl::%s::computeFeature] The number of intensity bins must be greater than zero!\n",
126 getClassName ().c_str ());
131 if (nr_distance_bins_ <= 0)
133 PCL_ERROR (
"[pcl::%s::computeFeature] The number of distance bins must be greater than zero!\n",
134 getClassName ().c_str ());
140 Eigen::MatrixXf intensity_spin_image (nr_intensity_bins_, nr_distance_bins_);
143 std::vector<float> nn_dist_sqr (surface_->size ());
147 for (std::size_t idx = 0; idx < indices_->size (); ++idx)
151 int k = tree_->radiusSearch ((*indices_)[idx], search_radius_, nn_indices, nn_dist_sqr);
154 for (
int bin = 0; bin < nr_intensity_bins_ * nr_distance_bins_; ++bin)
155 output[idx].histogram[bin] = std::numeric_limits<float>::quiet_NaN ();
161 computeIntensitySpinImage (*surface_,
static_cast<float> (search_radius_), sigma_, k, nn_indices, nn_dist_sqr, intensity_spin_image);
165 for (Eigen::Index bin_j = 0; bin_j < intensity_spin_image.cols (); ++bin_j)
166 for (Eigen::Index bin_i = 0; bin_i < intensity_spin_image.rows (); ++bin_i)
167 output[idx].histogram[bin++] = intensity_spin_image (bin_i, bin_j);
171 #define PCL_INSTANTIATE_IntensitySpinEstimation(T,NT) template class PCL_EXPORTS pcl::IntensitySpinEstimation<T,NT>;
void computeFeature(PointCloudOut &output) override
Estimate the intensity-domain descriptors at a set of points given by <setInputCloud (),...
void computeIntensitySpinImage(const PointCloudIn &cloud, float radius, float sigma, int k, const pcl::Indices &indices, const std::vector< float > &squared_distances, Eigen::MatrixXf &intensity_spin_image)
Estimate the intensity-domain spin image descriptor for a given point based on its spatial neighborho...
bool is_dense
True if no points are invalid (e.g., have NaN or Inf values in any of their floating point fields).
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.
IndicesAllocator<> Indices
Type used for indices in PCL.