Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Namespace Members | Data Fields | Globals

PFGenericParticleFilter.h

Go to the documentation of this file.
00001 /* Copyright (C) 2005 Pierre Moisan (Pierre.Moisan@USherbrooke.ca) 
00002 
00003    This library is free software; you can redistribute it and/or
00004    modify it under the terms of the GNU Lesser General Public
00005    License as published by the Free Software Foundation; either
00006    version 2.1 of the License, or (at your option) any later version.
00007    
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Lesser General Public License for more details.
00012    
00013    You should have received a copy of the GNU Lesser General Public
00014    License along with this library; if not, write to the Free Software
00015    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 */
00017 
00018 #ifndef _PFGENERICPARTICLEFILTER_H_
00019 #define _PFGENERICPARTICLEFILTER_H_
00020 
00021 #include "PFParticleFilter.h"
00022 #include "PFGenericParticle.h"
00023 
00024 namespace RobotFlow {
00025 //
00026 // Generic implementation of a particle filter
00027 // For more information, refer to the following publication
00028 // M. S. Arulampalam, S. Maskell, N. Gordon, T. Clapp.
00029 // "A Tutorial on Particle Filters for On-line Nonlinear/Non-Gaussian 
00030 // Bayesian Tracking"  (2001) 
00031 //
00032 class PFGenericParticleFilter : public PFParticleFilter
00033 {
00034 public:
00035         PFGenericParticleFilter();
00036         
00037         PFGenericParticleFilter(unsigned int i_numSamples, 
00038                 unsigned int i_sampleStateSize, const FD::Vector<float> *i_initVariance);
00039         
00040         PFGenericParticleFilter(std::string nodeName, FD::ParameterSet params);
00041 
00042         virtual ~PFGenericParticleFilter();
00043 
00044         // Default routine to print a PFGenericParticleFilter object to an output stream
00045         void printOn(std::ostream &out) const
00046         {
00047                 throw new FD::GeneralException("Exception in PFGenericParticleFilter::printOn: method not yet implemented.",__FILE__,__LINE__);
00048         }
00049 
00050         // Default routine to read a PFGenericParticleFilter object from an input stream
00051         void readFrom(std::istream &in)
00052         {
00053                 throw new FD::GeneralException("Exception in PFGenericParticleFilter::printOn: method not yet implemented.",__FILE__,__LINE__);
00054         }
00055         
00056         virtual void request(int output_id, const FD::ParameterSet &req);
00057         
00058         void calculate(int output_id, int count, FD::Buffer &out);
00059         
00060         void Initialize(const FD::Vector<float> *i_variance);
00061         
00062         void InitSamples();
00063         
00064         void Update();
00065         
00066         void ComputeMeanState();
00067         
00068         void Resample();
00069         
00070         FD::RCPtr<PFGenericParticle> GetCurSample();
00071         
00072         FD::RCPtr<PFGenericParticle> GetFirstSample();
00073         
00074         FD::RCPtr<PFGenericParticle> GetSampleByIdx(int i_idx);
00075         
00076         FD::RCPtr<PFGenericParticle> GetMeanState();
00077         
00078         void SetRefMeanSample(PFGenericParticle *i_curSample);
00079         
00080         void InitLikelihoodsSum();
00081         
00082         void IncLikelihoodsSum(float i_likelihood);
00083 
00084 private:
00085         void CopyTmpSamples();
00086 
00087 private:
00088         // Input IDs (for BufferedNode)
00089         int m_initVarianceInID;
00090         int m_refMeanStateInID;
00091         int m_predictInID;
00092         int m_likelihoodInID;
00093         
00094         // Output IDs (for BufferedNode)
00095         int m_finishedOutID;
00096         int m_particleOutID;
00097         int m_meanStateOutID;
00098         
00099         bool m_init;
00100         bool m_initPF;
00101         bool m_initSamples;
00102         bool m_finished;
00103         
00104         int m_curSampleIdx;
00105         unsigned int m_numSamples;
00106         unsigned int m_sampleStateSize;
00107         FD::RCPtr<PFGenericParticle> *m_samples;
00108         FD::RCPtr<PFGenericParticle> *m_tmpSamples;
00109         float m_likelihoodsSum;
00110         float *m_cumulWeight;
00111         FD::Vector<float> *m_initVariance;
00112         
00113         FD::RCPtr<PFGenericParticle> m_curSample;
00114         FD::RCPtr<PFGenericParticle> m_refMeanState;
00115         FD::RCPtr<PFGenericParticle> m_outMeanState;
00116 };
00117 
00118 }
00119 
00120 #endif

Generated on Wed Oct 5 14:36:12 2005 for RobotFlow by  doxygen 1.4.4