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>
45 class MovingWindowFilterPrivate
48 public: MovingWindowFilterPrivate<T>();
51 public:
unsigned int valWindowSize;
54 public: std::vector<T> valHistory;
57 public:
typename std::vector<T>::iterator valIter;
62 public:
unsigned int samples;
71 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate() :
76 this->valHistory.resize(this->valWindowSize);
77 this->valIter = this->valHistory.begin();
93 public:
void Update(T _val);
114 MovingWindowFilterPrivate<T> &_d);
117 protected: MovingWindowFilterPrivate<T> *
dataPtr;
125 : dataPtr(new MovingWindowFilterPrivate<T>())
133 this->dataPtr->valHistory.clear();
134 delete this->dataPtr;
135 this->dataPtr =
nullptr;
145 this->dataPtr->sum += _val;
148 ++this->dataPtr->valIter;
149 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
152 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
156 ++this->dataPtr->samples;
158 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
161 this->dataPtr->sum -= (*this->dataPtr->valIter);
163 (*this->dataPtr->valIter) = _val;
165 --this->dataPtr->samples;
170 (*this->dataPtr->valIter) = _val;
178 this->dataPtr->valWindowSize = _n;
179 this->dataPtr->valHistory.clear();
180 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
181 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
182 this->dataPtr->sum = T();
183 this->dataPtr->samples = 0;
190 return this->dataPtr->valWindowSize;
197 return this->dataPtr->samples == this->dataPtr->valWindowSize;
204 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
bool GetWindowFilled() const
Get whether the window has been filled.
Definition: MovingWindowFilter.hh:195
virtual ~MovingWindowFilter()
Destructor.
Definition: MovingWindowFilter.hh:131
MovingWindowFilterPrivate< T > * dataPtr
Data pointer.
Definition: MovingWindowFilter.hh:117
void SetWindowSize(unsigned int _n)
Set window size.
Definition: MovingWindowFilter.hh:176
unsigned int GetWindowSize() const
Get the window size.
Definition: MovingWindowFilter.hh:188
Base class for MovingWindowFilter.
Definition: MovingWindowFilter.hh:83
T Get()
Get filtered result.
Definition: MovingWindowFilter.hh:202
void Update(T _val)
Update value of filter.
Definition: MovingWindowFilter.hh:140
MovingWindowFilter()
Constructor.
Definition: MovingWindowFilter.hh:124