Point Cloud Library (PCL)  1.14.0-dev
farthest_point_sampling.h
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2020-, Open Perception, Inc.
6  *
7  * All rights reserved
8  */
9 
10 #pragma once
11 
12 #include <pcl/filters/filter_indices.h>
13 
14 #include <climits>
15 #include <random>
16 
17 namespace pcl
18  {
19  /** \brief @b FarthestPointSampling applies farthest point sampling using euclidean
20  * distance, starting with a random point, utilizing a naive method.
21  * \author Haritha Jayasinghe
22  * \ingroup filters
23  * \todo add support to export/import distance metric
24  */
25  template<typename PointT>
26  class FarthestPointSampling : public FilterIndices<PointT>
27  {
35 
36  using typename FilterIndices<PointT>::PointCloud;
37 
38  public:
39  /** \brief Empty constructor. */
40  FarthestPointSampling (bool extract_removed_indices = false) :
41  FilterIndices<PointT> (extract_removed_indices),
42  sample_size_ (std::numeric_limits<int>::max ()),
43  seed_ (std::random_device()())
44  {
45  filter_name_ = "FarthestPointSamping";
46  }
47 
48  /** \brief Set number of points to be sampled.
49  * \param sample_size the number of points to sample
50  */
51  inline void
52  setSample (std::size_t sample_size)
53  {
54  sample_size_ = sample_size;
55  }
56 
57  /** \brief Get the value of the internal \a sample_size parameter.
58  */
59  inline std::size_t
60  getSample () const
61  {
62  return (sample_size_);
63  }
64 
65  /** \brief Set seed of random function.
66  * \param seed for the random number generator, to choose the first sample point
67  */
68  inline void
69  setSeed (unsigned int seed)
70  {
71  seed_ = seed;
72  }
73 
74  /** \brief Get the value of the internal \a seed_ parameter.
75  */
76  inline unsigned int
77  getSeed () const
78  {
79  return (seed_);
80  }
81 
82  protected:
83 
84  /** \brief Number of points that will be returned. */
85  std::size_t sample_size_;
86  /** \brief Random number seed. */
87  unsigned int seed_;
88 
89  /** \brief Sample of point indices
90  * \param indices indices of the filtered point cloud
91  */
92  void
93  applyFilter (pcl::Indices &indices) override;
94 
95  };
96  }
97 
98 #ifdef PCL_NO_PRECOMPILE
99 #include <pcl/filters/impl/farthest_point_sampling.hpp>
100 #endif
FarthestPointSampling applies farthest point sampling using euclidean distance, starting with a rando...
unsigned int seed_
Random number seed.
void setSample(std::size_t sample_size)
Set number of points to be sampled.
std::size_t getSample() const
Get the value of the internal sample_size parameter.
unsigned int getSeed() const
Get the value of the internal seed_ parameter.
void applyFilter(pcl::Indices &indices) override
Sample of point indices.
std::size_t sample_size_
Number of points that will be returned.
void setSeed(unsigned int seed)
Set seed of random function.
FarthestPointSampling(bool extract_removed_indices=false)
Empty constructor.
Filter represents the base filter class.
Definition: filter.h:81
std::string filter_name_
The filter name.
Definition: filter.h:158
FilterIndices represents the base class for filters that are about binary point removal.
PCL base class.
Definition: pcl_base.h:70
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.