Point Cloud Library (PCL) 1.15.1
Loading...
Searching...
No Matches
kld_adaptive_particle_filter.hpp
1#ifndef PCL_TRACKING_IMPL_KLD_ADAPTIVE_PARTICLE_FILTER_H_
2#define PCL_TRACKING_IMPL_KLD_ADAPTIVE_PARTICLE_FILTER_H_
3
4#include <pcl/tracking/kld_adaptive_particle_filter.h>
5
6namespace pcl {
7namespace tracking {
8template <typename PointInT, typename StateT>
9bool
11{
13 PCL_ERROR("[pcl::%s::initCompute] Init failed.\n", getClassName().c_str());
14 return (false);
15 }
16
17 if (transed_reference_vector_.empty()) {
18 // only one time allocation
20 for (unsigned int i = 0; i < maximum_particle_number_; i++) {
22 }
23 }
24
25 coherence_->setTargetCloud(input_);
26
30
31 if (!particles_ || particles_->points.empty())
32 initParticles(true);
33 return (true);
34}
35
36template <typename PointInT, typename StateT>
37bool
39 std::vector<int>&& new_bin, std::vector<std::vector<int>>& bins)
40{
41 for (auto& existing_bin : bins) {
42 if (equalBin(new_bin, existing_bin))
43 return false;
44 }
45 bins.push_back(std::move(new_bin));
46 return true;
47}
48
49template <typename PointInT, typename StateT>
50void
52{
53 unsigned int k = 0;
54 unsigned int n = 0;
56 std::vector<std::vector<int>> bins;
57
58 // initializing for sampling without replacement
59 std::vector<int> a(particles_->size());
60 std::vector<double> q(particles_->size());
61 this->genAliasTable(a, q, particles_);
62
63 const std::vector<double> zero_mean(StateT::stateDimension(), 0.0);
64
65 // select the particles with KLD sampling
66 do {
67 int j_n = sampleWithReplacement(a, q);
68 StateT x_t = (*particles_)[j_n];
69 x_t.sample(zero_mean, step_noise_covariance_);
70
71 // motion
72 if (rand() / static_cast<double>(RAND_MAX) < motion_ratio_)
73 x_t = x_t + motion_;
74
75 S->points.push_back(x_t);
76 // calc bin
77 std::vector<int> new_bin(StateT::stateDimension());
78 for (int i = 0; i < StateT::stateDimension(); i++)
79 new_bin[i] = static_cast<int>(x_t[i] / bin_size_[i]);
80
81 // calc bin index... how?
82 if (insertIntoBins(std::move(new_bin), bins))
83 ++k;
84 ++n;
85 } while (n < maximum_particle_number_ && (k < 2 || n < calcKLBound(k)));
86
87 particles_ = S; // swap
88 particle_num_ = static_cast<int>(particles_->size());
89}
90} // namespace tracking
91} // namespace pcl
92
93#define PCL_INSTANTIATE_KLDAdaptiveParticleFilterTracker(T, ST) \
94 template class PCL_EXPORTS pcl::tracking::KLDAdaptiveParticleFilterTracker<T, ST>;
95
96#endif
PointCloudConstPtr input_
Definition pcl_base.h:147
virtual double calcKLBound(int k)
calculate K-L boundary.
void resample() override
resampling phase of particle filter method.
unsigned int maximum_particle_number_
the maximum number of the particles.
virtual bool insertIntoBins(std::vector< int > &&new_bin, std::vector< std::vector< int > > &bins)
insert a bin into the set of the bins.
typename Tracker< PointInT, StateT >::PointCloudIn PointCloudIn
typename Tracker< PointInT, StateT >::PointCloudState PointCloudState
bool initCompute() override
This method should get called before starting the actual computation.
virtual bool equalBin(const std::vector< int > &a, const std::vector< int > &b)
return true if the two bins are equal.
void genAliasTable(std::vector< int > &a, std::vector< double > &q, const PointCloudStateConstPtr &particles)
Generate the tables for walker's alias method.
double motion_ratio_
Ratio of hypothesis to use motion model.
void initParticles(bool reset)
Initialize the particles.
CloudCoherencePtr coherence_
A pointer to PointCloudCoherence.
int sampleWithReplacement(const std::vector< int > &a, const std::vector< double > &q)
Implementation of "sample with replacement" using Walker's alias method.
pcl::octree::OctreePointCloudChangeDetector< PointInT >::Ptr change_detector_
Change detector used as a trigger to track.
double change_detector_resolution_
Resolution of change detector.
std::vector< double > step_noise_covariance_
The diagonal elements of covariance matrix of the step noise.
std::vector< PointCloudInPtr > transed_reference_vector_
A list of the pointers to pointclouds.
PointCloudStatePtr particles_
A pointer to the particles.
int particle_num_
The number of the particles.
StateT motion_
Difference between the result in t and t-1.
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition tracker.h:97
virtual bool initCompute()
This method should get called before starting the actual computation.
Definition tracker.hpp:10