Point Cloud Library (PCL)  1.11.1-dev
kld_adaptive_particle_filter.h
1 #pragma once
2 
3 #include <pcl/tracking/coherence.h>
4 #include <pcl/tracking/particle_filter.h>
5 #include <pcl/tracking/tracking.h>
6 
7 namespace pcl {
8 namespace tracking {
9 
10 /** \brief @b KLDAdaptiveParticleFilterTracker tracks the PointCloud which is given by
11  * setReferenceCloud within the measured PointCloud using particle filter method. The
12  * number of the particles changes adaptively based on KLD sampling [D. Fox, NIPS-01],
13  * [D.Fox, IJRR03].
14  * \author Ryohei Ueda
15  * \ingroup tracking
16  */
17 template <typename PointInT, typename StateT>
19 : public ParticleFilterTracker<PointInT, StateT> {
20 public:
42 
44 
45  using Ptr = shared_ptr<KLDAdaptiveParticleFilterTracker<PointInT, StateT>>;
46  using ConstPtr = shared_ptr<const KLDAdaptiveParticleFilterTracker<PointInT, StateT>>;
47 
49  using PointCloudInPtr = typename PointCloudIn::Ptr;
50  using PointCloudInConstPtr = typename PointCloudIn::ConstPtr;
51 
53  using PointCloudStatePtr = typename PointCloudState::Ptr;
54  using PointCloudStateConstPtr = typename PointCloudState::ConstPtr;
55 
57  using CoherencePtr = typename Coherence::Ptr;
59 
63 
64  /** \brief Empty constructor. */
66  : ParticleFilterTracker<PointInT, StateT>()
68  , epsilon_(0)
69  , delta_(0.99)
70  , bin_size_()
71  {
72  tracker_name_ = "KLDAdaptiveParticleFilterTracker";
73  }
74 
75  /** \brief set the bin size.
76  * \param bin_size the size of a bin
77  */
78  inline void
79  setBinSize(const StateT& bin_size)
80  {
81  bin_size_ = bin_size;
82  }
83 
84  /** \brief get the bin size. */
85  inline StateT
86  getBinSize() const
87  {
88  return (bin_size_);
89  }
90 
91  /** \brief set the maximum number of the particles.
92  * \param nr the maximum number of the particles.
93  */
94  inline void
95  setMaximumParticleNum(unsigned int nr)
96  {
98  }
99 
100  /** \brief get the maximum number of the particles.*/
101  inline unsigned int
103  {
104  return (maximum_particle_number_);
105  }
106 
107  /** \brief set epsilon to be used to calc K-L boundary.
108  * \param eps epsilon
109  */
110  inline void
111  setEpsilon(double eps)
112  {
113  epsilon_ = eps;
114  }
115 
116  /** \brief get epsilon to be used to calc K-L boundary. */
117  inline double
118  getEpsilon() const
119  {
120  return (epsilon_);
121  }
122 
123  /** \brief set delta to be used in chi-squared distribution.
124  * \param delta delta of chi-squared distribution.
125  */
126  inline void
127  setDelta(double delta)
128  {
129  delta_ = delta;
130  }
131 
132  /** \brief get delta to be used in chi-squared distribution.*/
133  inline double
134  getDelta() const
135  {
136  return (delta_);
137  }
138 
139 protected:
140  /** \brief return true if the two bins are equal.
141  * \param a index of the bin
142  * \param b index of the bin
143  */
144  virtual bool
145  equalBin(const std::vector<int>& a, const std::vector<int>& b)
146  {
147  int dimension = StateT::stateDimension();
148  for (int i = 0; i < dimension; i++)
149  if (a[i] != b[i])
150  return (false);
151  return (true);
152  }
153 
154  /** \brief return upper quantile of standard normal distribution.
155  * \param[in] u ratio of quantile.
156  */
157  double
158  normalQuantile(double u)
159  {
160  const double a[9] = {1.24818987e-4,
161  -1.075204047e-3,
162  5.198775019e-3,
163  -0.019198292004,
164  0.059054035642,
165  -0.151968751364,
166  0.319152932694,
167  -0.5319230073,
168  0.797884560593};
169  const double b[15] = {-4.5255659e-5,
170  1.5252929e-4,
171  -1.9538132e-5,
172  -6.76904986e-4,
173  1.390604284e-3,
174  -7.9462082e-4,
175  -2.034254874e-3,
176  6.549791214e-3,
177  -0.010557625006,
178  0.011630447319,
179  -9.279453341e-3,
180  5.353579108e-3,
181  -2.141268741e-3,
182  5.35310549e-4,
183  0.999936657524};
184  double w, y, z;
185 
186  if (u == 0.)
187  return (0.5);
188  y = u / 2.0;
189  if (y < -3.)
190  return (0.0);
191  if (y > 3.)
192  return (1.0);
193  if (y < 0.0)
194  y = -y;
195  if (y < 1.0) {
196  w = y * y;
197  z = a[0];
198  for (int i = 1; i < 9; i++)
199  z = z * w + a[i];
200  z *= (y * 2.0);
201  }
202  else {
203  y -= 2.0;
204  z = b[0];
205  for (int i = 1; i < 15; i++)
206  z = z * y + b[i];
207  }
208 
209  if (u < 0.0)
210  return ((1. - z) / 2.0);
211  return ((1. + z) / 2.0);
212  }
213 
214  /** \brief calculate K-L boundary. K-L boundary follows 1/2e*chi(k-1, 1-d)^2.
215  * \param[in] k the number of bins and the first parameter of chi distribution.
216  */
217  virtual double
218  calcKLBound(int k)
219  {
220  double z = normalQuantile(delta_);
221  double chi = 1.0 - 2.0 / (9.0 * (k - 1)) + sqrt(2.0 / (9.0 * (k - 1))) * z;
222  return ((k - 1.0) / (2.0 * epsilon_) * chi * chi * chi);
223  }
224 
225  /** \brief insert a bin into the set of the bins. if that bin is already registered,
226  * return false. if not, return true.
227  * \param new_bin a bin to be inserted.
228  * \param bins a set of the bins
229  */
230  virtual bool
231  insertIntoBins(std::vector<int>&& new_bin, std::vector<std::vector<int>>& bins);
232 
233  /** \brief This method should get called before starting the actual
234  * computation. */
235  bool
236  initCompute() override;
237 
238  /** \brief resampling phase of particle filter method. sampling the particles
239  * according to the weights calculated in weight method. in particular, "sample with
240  * replacement" is archieved by walker's alias method.
241  */
242  void
243  resample() override;
244 
245  /** \brief the maximum number of the particles. */
247 
248  /** \brief error between K-L distance and MLE*/
249  double epsilon_;
250 
251  /** \brief probability of distance between K-L distance and MLE is less than
252  * epsilon_*/
253  double delta_;
254 
255  /** \brief the size of a bin.*/
256  StateT bin_size_;
257 };
258 } // namespace tracking
259 } // namespace pcl
260 
261 #ifdef PCL_NO_PRECOMPILE
262 #include <pcl/tracking/impl/kld_adaptive_particle_filter.hpp>
263 #endif
pcl::tracking::KLDAdaptiveParticleFilterTracker::ConstPtr
shared_ptr< const KLDAdaptiveParticleFilterTracker< PointInT, StateT > > ConstPtr
Definition: kld_adaptive_particle_filter.h:46
pcl::tracking::KLDAdaptiveParticleFilterTracker::CoherenceConstPtr
typename Coherence::ConstPtr CoherenceConstPtr
Definition: kld_adaptive_particle_filter.h:58
pcl
Definition: convolution.h:46
pcl::tracking::ParticleFilterTracker
ParticleFilterTracker tracks the PointCloud which is given by setReferenceCloud within the measured P...
Definition: particle_filter.h:18
pcl::tracking::KLDAdaptiveParticleFilterTracker::epsilon_
double epsilon_
error between K-L distance and MLE
Definition: kld_adaptive_particle_filter.h:249
pcl::tracking::KLDAdaptiveParticleFilterTracker::equalBin
virtual bool equalBin(const std::vector< int > &a, const std::vector< int > &b)
return true if the two bins are equal.
Definition: kld_adaptive_particle_filter.h:145
pcl::tracking::PointCloudCoherence::ConstPtr
shared_ptr< const PointCloudCoherence< PointInT > > ConstPtr
Definition: coherence.h:62
pcl::tracking::KLDAdaptiveParticleFilterTracker::PointCloudInPtr
typename PointCloudIn::Ptr PointCloudInPtr
Definition: kld_adaptive_particle_filter.h:49
pcl::tracking::KLDAdaptiveParticleFilterTracker::PointCloudIn
typename Tracker< PointInT, StateT >::PointCloudIn PointCloudIn
Definition: kld_adaptive_particle_filter.h:48
pcl::tracking::PointCoherence::Ptr
shared_ptr< PointCoherence< PointInT > > Ptr
Definition: coherence.h:17
pcl::tracking::KLDAdaptiveParticleFilterTracker::setDelta
void setDelta(double delta)
set delta to be used in chi-squared distribution.
Definition: kld_adaptive_particle_filter.h:127
pcl::tracking::KLDAdaptiveParticleFilterTracker::CloudCoherenceConstPtr
typename CloudCoherence::ConstPtr CloudCoherenceConstPtr
Definition: kld_adaptive_particle_filter.h:62
pcl::tracking::KLDAdaptiveParticleFilterTracker::CloudCoherencePtr
typename CloudCoherence::Ptr CloudCoherencePtr
Definition: kld_adaptive_particle_filter.h:61
pcl::tracking::KLDAdaptiveParticleFilterTracker::bin_size_
StateT bin_size_
the size of a bin.
Definition: kld_adaptive_particle_filter.h:256
pcl::PointCloud< PointInT >
pcl::tracking::KLDAdaptiveParticleFilterTracker::PointCloudStatePtr
typename PointCloudState::Ptr PointCloudStatePtr
Definition: kld_adaptive_particle_filter.h:53
pcl::tracking::KLDAdaptiveParticleFilterTracker::initCompute
bool initCompute() override
This method should get called before starting the actual computation.
Definition: kld_adaptive_particle_filter.hpp:10
pcl::tracking::Tracker::tracker_name_
std::string tracker_name_
The tracker name.
Definition: tracker.h:90
pcl::tracking::KLDAdaptiveParticleFilterTracker::getBinSize
StateT getBinSize() const
get the bin size.
Definition: kld_adaptive_particle_filter.h:86
pcl::tracking::KLDAdaptiveParticleFilterTracker::calcKLBound
virtual double calcKLBound(int k)
calculate K-L boundary.
Definition: kld_adaptive_particle_filter.h:218
pcl::tracking::KLDAdaptiveParticleFilterTracker::CoherencePtr
typename Coherence::Ptr CoherencePtr
Definition: kld_adaptive_particle_filter.h:57
pcl::tracking::KLDAdaptiveParticleFilterTracker::PointCloudState
typename Tracker< PointInT, StateT >::PointCloudState PointCloudState
Definition: kld_adaptive_particle_filter.h:52
pcl::tracking::KLDAdaptiveParticleFilterTracker::getMaximumParticleNum
unsigned int getMaximumParticleNum() const
get the maximum number of the particles.
Definition: kld_adaptive_particle_filter.h:102
pcl::tracking::KLDAdaptiveParticleFilterTracker::normalQuantile
double normalQuantile(double u)
return upper quantile of standard normal distribution.
Definition: kld_adaptive_particle_filter.h:158
pcl::tracking::PointCoherence::ConstPtr
shared_ptr< const PointCoherence< PointInT > > ConstPtr
Definition: coherence.h:18
pcl::tracking::KLDAdaptiveParticleFilterTracker::KLDAdaptiveParticleFilterTracker
KLDAdaptiveParticleFilterTracker()
Empty constructor.
Definition: kld_adaptive_particle_filter.h:65
pcl::tracking::KLDAdaptiveParticleFilterTracker::setMaximumParticleNum
void setMaximumParticleNum(unsigned int nr)
set the maximum number of the particles.
Definition: kld_adaptive_particle_filter.h:95
pcl::tracking::KLDAdaptiveParticleFilterTracker::PointCloudInConstPtr
typename PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: kld_adaptive_particle_filter.h:50
pcl::tracking::KLDAdaptiveParticleFilterTracker::delta_
double delta_
probability of distance between K-L distance and MLE is less than epsilon_
Definition: kld_adaptive_particle_filter.h:253
pcl::tracking::PointCloudCoherence
PointCloudCoherence is a base class to compute coherence between the two PointClouds.
Definition: coherence.h:59
pcl::tracking::KLDAdaptiveParticleFilterTracker::Ptr
shared_ptr< KLDAdaptiveParticleFilterTracker< PointInT, StateT > > Ptr
Definition: kld_adaptive_particle_filter.h:45
pcl::tracking::PointCoherence
PointCoherence is a base class to compute coherence between the two points.
Definition: coherence.h:15
pcl::tracking::KLDAdaptiveParticleFilterTracker::resample
void resample() override
resampling phase of particle filter method.
Definition: kld_adaptive_particle_filter.hpp:51
pcl::tracking::KLDAdaptiveParticleFilterTracker::insertIntoBins
virtual bool insertIntoBins(std::vector< int > &&new_bin, std::vector< std::vector< int >> &bins)
insert a bin into the set of the bins.
Definition: kld_adaptive_particle_filter.hpp:38
pcl::tracking::KLDAdaptiveParticleFilterTracker::getDelta
double getDelta() const
get delta to be used in chi-squared distribution.
Definition: kld_adaptive_particle_filter.h:134
pcl::tracking::PointCloudCoherence::Ptr
shared_ptr< PointCloudCoherence< PointInT > > Ptr
Definition: coherence.h:61
pcl::tracking::KLDAdaptiveParticleFilterTracker::maximum_particle_number_
unsigned int maximum_particle_number_
the maximum number of the particles.
Definition: kld_adaptive_particle_filter.h:246
pcl::tracking::KLDAdaptiveParticleFilterTracker::setBinSize
void setBinSize(const StateT &bin_size)
set the bin size.
Definition: kld_adaptive_particle_filter.h:79
pcl::tracking::KLDAdaptiveParticleFilterTracker::getEpsilon
double getEpsilon() const
get epsilon to be used to calc K-L boundary.
Definition: kld_adaptive_particle_filter.h:118
pcl::tracking::Tracker
Tracker represents the base tracker class.
Definition: tracker.h:55
pcl::tracking::KLDAdaptiveParticleFilterTracker
KLDAdaptiveParticleFilterTracker tracks the PointCloud which is given by setReferenceCloud within the...
Definition: kld_adaptive_particle_filter.h:18
pcl::tracking::KLDAdaptiveParticleFilterTracker::setEpsilon
void setEpsilon(double eps)
set epsilon to be used to calc K-L boundary.
Definition: kld_adaptive_particle_filter.h:111
pcl::tracking::KLDAdaptiveParticleFilterTracker::PointCloudStateConstPtr
typename PointCloudState::ConstPtr PointCloudStateConstPtr
Definition: kld_adaptive_particle_filter.h:54