18 #ifndef _GAZEBO_MOVING_WINDOW_FILTER_HH_
19 #define _GAZEBO_MOVING_WINDOW_FILTER_HH_
25 #include <boost/function.hpp>
26 #include <boost/bind.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/thread/mutex.hpp>
30 #include <gazebo/gazebo_config.h>
46 class MovingWindowFilterPrivate
49 public: MovingWindowFilterPrivate();
52 public:
unsigned int valWindowSize;
55 public: std::vector<T> valHistory;
58 public:
typename std::vector<T>::iterator valIter;
64 public:
unsigned int samples;
70 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate()
73 this->valWindowSize = 4;
74 this->valHistory.resize(this->valWindowSize);
75 this->valIter = this->valHistory.begin();
93 public:
void Update(T _val);
116 protected: MovingWindowFilterPrivate<T> *
dataPtr;
122 : dataPtr(new MovingWindowFilterPrivate<T>())
130 this->dataPtr->valHistory.clear();
131 delete this->dataPtr;
132 this->dataPtr =
NULL;
142 this->dataPtr->sum += _val;
145 ++this->dataPtr->valIter;
146 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
149 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
153 ++this->dataPtr->samples;
155 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
158 this->dataPtr->sum -= (*this->dataPtr->valIter);
160 (*this->dataPtr->valIter) = _val;
162 --this->dataPtr->samples;
167 (*this->dataPtr->valIter) = _val;
175 this->dataPtr->valWindowSize = _n;
176 this->dataPtr->valHistory.clear();
177 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
178 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
179 this->dataPtr->sum = T();
180 this->dataPtr->samples = 0;
187 return this->dataPtr->valWindowSize;
194 return this->dataPtr->samples == this->dataPtr->valWindowSize;
201 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
bool GetWindowFilled() const
Get whether the window has been filled.
Definition: MovingWindowFilter.hh:192
virtual ~MovingWindowFilter()
Destructor.
Definition: MovingWindowFilter.hh:128
MovingWindowFilterPrivate< T > * dataPtr
Data pointer.
Definition: MovingWindowFilter.hh:116
void SetWindowSize(unsigned int _n)
Set window size.
Definition: MovingWindowFilter.hh:173
unsigned int GetWindowSize() const
Get the window size.
Definition: MovingWindowFilter.hh:185
Base class for MovingWindowFilter.
Definition: MovingWindowFilter.hh:83
T Get()
Get filtered result.
Definition: MovingWindowFilter.hh:199
#define NULL
Definition: CommonTypes.hh:31
void Update(T _val)
Update value of filter.
Definition: MovingWindowFilter.hh:137
MovingWindowFilter()
Constructor.
Definition: MovingWindowFilter.hh:121