17#ifndef GZ_COMMON_MOVINGWINDOWFILTER_HH_
18#define GZ_COMMON_MOVINGWINDOWFILTER_HH_
22#include <gz/common/Export.hh>
32 class MovingWindowFilterPrivate
35 public: MovingWindowFilterPrivate();
38 public:
unsigned int valWindowSize = 4;
50 public:
unsigned int samples = 0;
56 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate()
59 this->valHistory.
resize(this->valWindowSize);
60 this->valIter = this->valHistory.begin();
76 public:
void Update(T _val);
97 MovingWindowFilterPrivate<T> &_d);
100 protected:
std::unique_ptr<MovingWindowFilterPrivate<T>>
dataPtr;
106 :
dataPtr(new MovingWindowFilterPrivate<T>())
114 this->
dataPtr->valHistory.clear();
128 if (this->
dataPtr->valIter == this->dataPtr->valHistory.end())
137 if (this->
dataPtr->samples > this->dataPtr->valWindowSize)
142 (*this->
dataPtr->valIter) = _val;
149 (*this->
dataPtr->valIter) = _val;
157 this->
dataPtr->valWindowSize = _n;
158 this->
dataPtr->valHistory.clear();
169 return this->
dataPtr->valWindowSize;
183 return this->
dataPtr->sum /
static_cast<double>(this->
dataPtr->samples);