Go to the documentation of this file.
17 #ifndef GZ_COMMON_MOVINGWINDOWFILTER_HH_
18 #define GZ_COMMON_MOVINGWINDOWFILTER_HH_
31 class MovingWindowFilterPrivate
34 public: MovingWindowFilterPrivate();
37 public:
unsigned int valWindowSize = 4;
49 public:
unsigned int samples = 0;
55 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate()
58 this->valHistory.
resize(this->valWindowSize);
59 this->valIter = this->valHistory.begin();
75 public:
void Update(T _val);
96 MovingWindowFilterPrivate<T> &_d);
105 : dataPtr(new MovingWindowFilterPrivate<T>())
113 this->dataPtr->valHistory.clear();
123 this->dataPtr->sum += _val;
126 ++this->dataPtr->valIter;
127 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
130 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
134 ++this->dataPtr->samples;
136 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
139 this->dataPtr->sum -= (*this->dataPtr->valIter);
141 (*this->dataPtr->valIter) = _val;
143 --this->dataPtr->samples;
148 (*this->dataPtr->valIter) = _val;
156 this->dataPtr->valWindowSize = _n;
157 this->dataPtr->valHistory.clear();
158 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
159 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
160 this->dataPtr->sum = T();
161 this->dataPtr->samples = 0;
168 return this->dataPtr->valWindowSize;
175 return this->dataPtr->samples == this->dataPtr->valWindowSize;
182 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
MovingWindowFilter()
Constructor.
Definition: gz/common/MovingWindowFilter.hh:104
Forward declarations for the common classes.
std::unique_ptr< MovingWindowFilterPrivate< T > > dataPtr
Data pointer.
Definition: gz/common/MovingWindowFilter.hh:99
unsigned int WindowSize() const
Get the window size.
Definition: gz/common/MovingWindowFilter.hh:166
void Update(T _val)
Update value of filter.
Definition: gz/common/MovingWindowFilter.hh:118
T Value()
Get filtered result.
Definition: gz/common/MovingWindowFilter.hh:180
bool WindowFilled() const
Get whether the window has been filled.
Definition: gz/common/MovingWindowFilter.hh:173
Base class for MovingWindowFilter.
Definition: gz/common/MovingWindowFilter.hh:65
virtual ~MovingWindowFilter()
Destructor.
Definition: gz/common/MovingWindowFilter.hh:111
void SetWindowSize(unsigned int _n)
Set window size.
Definition: gz/common/MovingWindowFilter.hh:154