41#ifndef PCL_FEATURES_IMPL_GFPFH_H_
42#define PCL_FEATURES_IMPL_GFPFH_H_
44#include <pcl/features/gfpfh.h>
45#include <pcl/octree/octree_search.h>
52template<
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
57 output.width = output.height = 0;
62 output.header =
input_->header;
68 output.width = output.height = 1;
69 output.is_dense =
input_->is_dense;
79template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
84 octree.addPointsFromInputCloud ();
87 octree.getOccupiedVoxelCenters (occupied_cells);
91 std::vector< std::vector<int> > line_histograms;
92 for (std::size_t i = 0; i < occupied_cells.size (); ++i)
94 Eigen::Vector3f origin = occupied_cells[i].getVector3fMap ();
96 for (std::size_t j = i+1; j < occupied_cells.size (); ++j)
99 Eigen::Vector3f end = occupied_cells[j].getVector3fMap ();
100 octree.getApproxIntersectedVoxelCentersBySegment (origin, end, intersected_cells, 0.5f);
103 std::vector<int> histogram;
104 for (std::size_t k = 0; k < intersected_cells.size (); ++k)
107 octree.voxelSearch (intersected_cells[k], indices);
109 if (!indices.empty ())
113 histogram.push_back (label);
116 line_histograms.push_back(histogram);
120 std::vector< std::vector<int> > transition_histograms;
126 std::vector<float> gfpfh_histogram;
133 std::copy (gfpfh_histogram.cbegin (), gfpfh_histogram.cend (), output[0].histogram);
137template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
139 std::vector< std::vector<int> >& transition_histograms)
141 transition_histograms.resize (label_histograms.size ());
143 for (std::size_t i = 0; i < label_histograms.size (); ++i)
148 for (
auto &transition : transitions)
153 for (std::size_t k = 1; k < label_histograms[i].size (); ++k)
155 std::uint32_t first_class = label_histograms[i][k-1];
156 std::uint32_t second_class = label_histograms[i][k];
158 if (second_class < first_class)
159 std::swap (first_class, second_class);
161 transitions[first_class][second_class] += 1;
165 std::size_t flat_index = 0;
166 for (std::size_t m = 0; m < transitions.size (); ++m)
167 for (std::size_t n = m; n < transitions[m].size (); ++n)
169 transition_histograms[i][flat_index] = transitions[m][n];
173 assert (flat_index == transition_histograms[i].size ());
178template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
182 distances.resize (transition_histograms.size ());
184 std::vector<float> mean_histogram;
187 for (std::size_t i = 0; i < transition_histograms.size (); ++i)
195template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
197 std::vector<float>& histogram)
199 std::vector<float>::const_iterator min_it, max_it;
200 std::tie (min_it, max_it) = std::minmax_element (
distances.cbegin (),
distances.cend ());
204 const float min_value = *min_it;
205 const float max_value = *max_it;
209 const float range = max_value - min_value;
215 const auto raw_bin =
descriptorSize () * (distance - min_value) / range;
216 const auto bin = std::min<binSizeT> (max_bin,
static_cast<binSizeT
> (std::floor (raw_bin)));
222template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
void
224 std::vector<float>& mean_histogram)
226 assert (histograms.size () > 0);
228 mean_histogram.resize (histograms[0].size (), 0);
229 for (
const auto &histogram : histograms)
230 for (std::size_t j = 0; j < histogram.size (); ++j)
231 mean_histogram[j] +=
static_cast<float> (histogram[j]);
233 for (
float &i : mean_histogram)
234 i /=
static_cast<float> (histograms.size ());
238template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT>
float
240 const std::vector<float>& mean_histogram)
242 assert (histogram.size () == mean_histogram.size ());
245 for (std::size_t i = 0; i < histogram.size (); ++i)
246 norm += std::min (
static_cast<float> (histogram[i]), mean_histogram[i]);
248 norm /=
static_cast<float> (histogram.size ());
253template <
typename Po
intInT,
typename Po
intNT,
typename Po
intOutT> std::uint32_t
257 for (
const auto &nn_index : indices)
259 std::uint32_t label = (*labels_)[nn_index].label;
263 const auto max_it = std::max_element (counts.cbegin (), counts.cend ());
264 if (max_it == counts.end ())
267 return std::distance(counts.cbegin (), max_it);
270#define PCL_INSTANTIATE_GFPFHEstimation(T,NT,OutT) template class PCL_EXPORTS pcl::GFPFHEstimation<T,NT,OutT>;
virtual bool initCompute()
This method should get called before starting the actual computation.
virtual bool deinitCompute()
This method should get called after ending the actual computation.
int descriptorSize() const
Return the size of the descriptor.
void computeDistancesToMean(const std::vector< std::vector< int > > &transition_histograms, std::vector< float > &distances)
Compute the distance of each transition histogram to the mean.
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
std::uint32_t getNumberOfClasses() const
Return the number of different classes.
void computeTransitionHistograms(const std::vector< std::vector< int > > &label_histograms, std::vector< std::vector< int > > &transition_histograms)
Compute the fixed-length histograms of transitions.
std::uint32_t getDominantLabel(const pcl::Indices &indices)
Return the dominant label of a set of points.
std::uint32_t emptyLabel() const
Return the empty label value.
void compute(PointCloudOut &output)
Overloaded computed method from pcl::Feature.
void computeMeanHistogram(const std::vector< std::vector< int > > &histograms, std::vector< float > &mean_histogram)
Compute the mean histogram of the given set of histograms.
float computeHIKDistance(const std::vector< int > &histogram, const std::vector< float > &mean_histogram)
Return the Intersection Kernel distance between two histograms.
void computeDistanceHistogram(const std::vector< float > &distances, std::vector< float > &histogram)
Compute the binned histogram of distance values.
void computeFeature(PointCloudOut &output) override
Estimate the Point Feature Histograms (PFH) descriptors at a set of points given by <setInputCloud ()...
PointCloudConstPtr input_
std::vector< PointT, Eigen::aligned_allocator< PointT > > VectorType
Octree pointcloud search class
IndicesAllocator<> Indices
Type used for indices in PCL.