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>
58 public:
typename std::vector<T>::iterator
valIter;
72 this->valWindowSize = 4;
73 this->valHistory.resize(this->valWindowSize);
74 this->valIter = this->valHistory.begin();
92 public:
void Update(T _val);
129 this->dataPtr->valHistory.clear();
130 delete this->dataPtr;
131 this->dataPtr =
NULL;
141 this->dataPtr->sum += _val;
144 ++this->dataPtr->valIter;
145 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
148 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
152 ++this->dataPtr->samples;
154 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
157 this->dataPtr->sum -= (*this->dataPtr->valIter);
159 (*this->dataPtr->valIter) = _val;
161 --this->dataPtr->samples;
166 (*this->dataPtr->valIter) = _val;
174 this->dataPtr->valWindowSize = _n;
175 this->dataPtr->valHistory.clear();
176 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
177 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
178 this->dataPtr->sum = T();
179 this->dataPtr->samples = 0;
186 return this->dataPtr->valWindowSize;
193 return this->dataPtr->samples == this->dataPtr->valWindowSize;
200 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);