41 #ifndef PCL_FEATURES_IMPL_CRH_H_
42 #define PCL_FEATURES_IMPL_CRH_H_
44 #include <pcl/features/crh.h>
45 #include <pcl/common/fft/kiss_fftr.h>
46 #include <pcl/common/transforms.h>
49 template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
56 PCL_ERROR (
"[pcl::%s::computeFeature] No input dataset containing normals was given!\n", getClassName ().c_str ());
57 output.width = output.height = 0;
62 if (normals_->size () != surface_->size ())
64 PCL_ERROR (
"[pcl::%s::computeFeature] The number of points in the input dataset differs from the number of points in the dataset containing the normals!\n", getClassName ().c_str ());
65 output.width = output.height = 0;
70 Eigen::Vector3f plane_normal;
71 plane_normal[0] = -centroid_[0];
72 plane_normal[1] = -centroid_[1];
73 plane_normal[2] = -centroid_[2];
74 Eigen::Vector3f z_vector = Eigen::Vector3f::UnitZ ();
75 plane_normal.normalize ();
76 Eigen::Vector3f axis = plane_normal.cross (z_vector);
77 double rotation = -asin (axis.norm ());
81 int bin_angle = 360 / nbins;
83 Eigen::Affine3f transformPC (Eigen::AngleAxisf (
static_cast<float> (rotation), axis));
86 grid.
resize (indices_->size ());
88 for (std::size_t i = 0; i < indices_->size (); i++)
90 grid[i].getVector4fMap () = (*surface_)[(*indices_)[i]].getVector4fMap ();
91 grid[i].getNormalVector4fMap () = (*normals_)[(*indices_)[i]].getNormalVector4fMap ();
98 std::vector<kiss_fft_scalar> spatial_data(nbins);
101 for (
const auto &point : grid.
points)
103 int bin =
static_cast<int> ((((std::atan2 (point.normal_y, point.normal_x) +
M_PI) * 180 /
M_PI) / bin_angle)) % nbins;
104 float w = std::sqrt (point.normal_y * point.normal_y + point.normal_x * point.normal_x);
106 spatial_data[bin] += w;
109 for (
auto& data: spatial_data)
112 std::vector<kiss_fft_cpx> freq_data(nbins / 2 + 1);
113 kiss_fftr_cfg mycfg = kiss_fftr_alloc (nbins, 0,
nullptr,
nullptr);
114 kiss_fftr (mycfg, spatial_data.data (), freq_data.data ());
116 for (
auto& data: freq_data)
118 data.r /= freq_data[0].r;
119 data.i /= freq_data[0].r;
123 output.width = output.height = 1;
125 output[0].histogram[0] = freq_data[0].r;
127 for (
int i = 1; i < (nbins / 2); i++, k += 2)
129 output[0].histogram[k] = freq_data[i].r;
130 output[0].histogram[k + 1] = freq_data[i].i;
133 output[0].histogram[nbins - 1] = freq_data[nbins / 2].r;
136 #define PCL_INSTANTIATE_CRHEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::CRHEstimation<T,NT,OutT>;
CRHEstimation estimates the Camera Roll Histogram (CRH) descriptor for a given point cloud dataset co...
void resize(std::size_t count)
Resizes the container to contain count elements.
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
void transformPointCloudWithNormals(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const Eigen::Matrix< Scalar, 4, 4 > &transform, bool copy_all_fields)
Transform a point cloud and rotate its normals using an Eigen transform.