Go to the documentation of this file.00001 #ifndef PCL_TRACKING_IMPL_KLD_ADAPTIVE_PARTICLE_FILTER_H_
00002 #define PCL_TRACKING_IMPL_KLD_ADAPTIVE_PARTICLE_FILTER_H_
00003
00004 template <typename PointInT, typename StateT> bool
00005 pcl::tracking::KLDAdaptiveParticleFilterTracker<PointInT, StateT>::initCompute ()
00006 {
00007 if (!Tracker<PointInT, StateT>::initCompute ())
00008 {
00009 PCL_ERROR ("[pcl::%s::initCompute] Init failed.\n", getClassName ().c_str ());
00010 return (false);
00011 }
00012
00013 if (transed_reference_vector_.empty ())
00014 {
00015
00016 transed_reference_vector_.resize (maximum_particle_number_);
00017 for (unsigned int i = 0; i < maximum_particle_number_; i++)
00018 {
00019 transed_reference_vector_[i] = PointCloudInPtr (new PointCloudIn ());
00020 }
00021 }
00022
00023 coherence_->setTargetCloud (input_);
00024
00025 if (!change_detector_)
00026 change_detector_ = boost::shared_ptr<pcl::octree::OctreePointCloudChangeDetector<PointInT> >(new pcl::octree::OctreePointCloudChangeDetector<PointInT> (change_detector_resolution_));
00027
00028 if (!particles_ || particles_->points.empty ())
00029 initParticles (true);
00030 return (true);
00031 }
00032
00033 template <typename PointInT, typename StateT> bool
00034 pcl::tracking::KLDAdaptiveParticleFilterTracker<PointInT, StateT>::insertIntoBins
00035 (std::vector<int> bin, std::vector<std::vector<int> > &B)
00036 {
00037 for (size_t i = 0; i < B.size (); i++)
00038 {
00039 if (equalBin (bin, B[i]))
00040 return false;
00041 }
00042 B.push_back (bin);
00043 return true;
00044 }
00045
00046 template <typename PointInT, typename StateT> void
00047 pcl::tracking::KLDAdaptiveParticleFilterTracker<PointInT, StateT>::resample ()
00048 {
00049 unsigned int k = 0;
00050 unsigned int n = 0;
00051 PointCloudStatePtr S (new PointCloudState);
00052 std::vector<std::vector<int> > B;
00053
00054
00055 std::vector<int> a (particles_->points.size ());
00056 std::vector<double> q (particles_->points.size ());
00057 this->genAliasTable (a, q, particles_);
00058
00059 const std::vector<double> zero_mean (StateT::stateDimension (), 0.0);
00060
00061
00062 do
00063 {
00064 int j_n = sampleWithReplacement (a, q);
00065 StateT x_t = particles_->points[j_n];
00066 x_t.sample (zero_mean, step_noise_covariance_);
00067
00068
00069 if (rand () / double (RAND_MAX) < motion_ratio_)
00070 x_t = x_t + motion_;
00071
00072 S->points.push_back (x_t);
00073
00074 std::vector<int> bin (StateT::stateDimension ());
00075 for (int i = 0; i < StateT::stateDimension (); i++)
00076 bin[i] = static_cast<int> (x_t[i] / bin_size_[i]);
00077
00078
00079 if (insertIntoBins (bin, B))
00080 ++k;
00081 ++n;
00082 }
00083 while (k < 2 || (n < maximum_particle_number_ && n < calcKLBound (k)));
00084
00085 particles_ = S;
00086 particle_num_ = static_cast<int> (particles_->points.size ());
00087 }
00088
00089
00090 #define PCL_INSTANTIATE_KLDAdaptiveParticleFilterTracker(T,ST) template class PCL_EXPORTS pcl::tracking::KLDAdaptiveParticleFilterTracker<T,ST>;
00091
00092 #endif