18 #ifndef _GAZEBO_MOVING_WINDOW_FILTER_HH_
19 #define _GAZEBO_MOVING_WINDOW_FILTER_HH_
26 #ifndef BOOST_BIND_GLOBAL_PLACEHOLDERS
27 #define BOOST_BIND_GLOBAL_PLACEHOLDERS
29 #include <boost/bind.hpp>
30 #include <boost/function.hpp>
31 #include <boost/shared_ptr.hpp>
32 #include <boost/thread/mutex.hpp>
34 #include <gazebo/gazebo_config.h>
49 class MovingWindowFilterPrivate
52 public: MovingWindowFilterPrivate<T>();
55 public:
unsigned int valWindowSize;
58 public: std::vector<T> valHistory;
61 public:
typename std::vector<T>::iterator valIter;
66 public:
unsigned int samples;
73 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate() :
78 this->valHistory.resize(this->valWindowSize);
79 this->valIter = this->valHistory.begin();
95 public:
void Update(T _val);
116 MovingWindowFilterPrivate<T> &_d);
119 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);
common
Definition: FuelModelDatabase.hh:42
Base class for MovingWindowFilter.
Definition: MovingWindowFilter.hh:86
MovingWindowFilterPrivate< T > * dataPtr
Data pointer.
Definition: MovingWindowFilter.hh:119
void Update(T _val)
Update value of filter.
Definition: MovingWindowFilter.hh:140
unsigned int GetWindowSize() const
Get the window size.
Definition: MovingWindowFilter.hh:188
bool GetWindowFilled() const
Get whether the window has been filled.
Definition: MovingWindowFilter.hh:195
MovingWindowFilter()
Constructor.
Definition: MovingWindowFilter.hh:124
void SetWindowSize(unsigned int _n)
Set window size.
Definition: MovingWindowFilter.hh:176
T Get()
Get filtered result.
Definition: MovingWindowFilter.hh:202
virtual ~MovingWindowFilter()
Destructor.
Definition: MovingWindowFilter.hh:131
Forward declarations for the common classes.
Definition: Animation.hh:27