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);
116 protected: MovingWindowFilterPrivate<T> *
dataPtr;
124 : dataPtr(new MovingWindowFilterPrivate<T>())
132 this->dataPtr->valHistory.clear();
133 delete this->dataPtr;
134 this->dataPtr =
nullptr;
144 this->dataPtr->sum += _val;
147 ++this->dataPtr->valIter;
148 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
151 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
155 ++this->dataPtr->samples;
157 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
160 this->dataPtr->sum -= (*this->dataPtr->valIter);
162 (*this->dataPtr->valIter) = _val;
164 --this->dataPtr->samples;
169 (*this->dataPtr->valIter) = _val;
177 this->dataPtr->valWindowSize = _n;
178 this->dataPtr->valHistory.clear();
179 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
180 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
181 this->dataPtr->sum = T();
182 this->dataPtr->samples = 0;
189 return this->dataPtr->valWindowSize;
196 return this->dataPtr->samples == this->dataPtr->valWindowSize;
203 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
bool GetWindowFilled() const
Get whether the window has been filled.
Definition: MovingWindowFilter.hh:194
virtual ~MovingWindowFilter()
Destructor.
Definition: MovingWindowFilter.hh:130
MovingWindowFilterPrivate< T > * dataPtr
Data pointer.
Definition: MovingWindowFilter.hh:116
void SetWindowSize(unsigned int _n)
Set window size.
Definition: MovingWindowFilter.hh:175
unsigned int GetWindowSize() const
Get the window size.
Definition: MovingWindowFilter.hh:187
Base class for MovingWindowFilter.
Definition: MovingWindowFilter.hh:83
T Get()
Get filtered result.
Definition: MovingWindowFilter.hh:201
void Update(T _val)
Update value of filter.
Definition: MovingWindowFilter.hh:139
MovingWindowFilter()
Constructor.
Definition: MovingWindowFilter.hh:123