Go to the documentation of this file.
17 #ifndef IGNITION_COMMON_MOVINGWINDOWFILTER_HH_
18 #define IGNITION_COMMON_MOVINGWINDOWFILTER_HH_
23 #include <gz/common/config.hh>
33 class MovingWindowFilterPrivate
36 public: MovingWindowFilterPrivate();
39 public:
unsigned int valWindowSize = 4;
51 public:
unsigned int samples = 0;
57 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate()
60 this->valHistory.
resize(this->valWindowSize);
61 this->valIter = this->valHistory.begin();
77 public:
void Update(T _val);
98 MovingWindowFilterPrivate<T> &_d);
107 : dataPtr(new MovingWindowFilterPrivate<T>())
115 this->dataPtr->valHistory.clear();
125 this->dataPtr->sum += _val;
128 ++this->dataPtr->valIter;
129 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
132 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
136 ++this->dataPtr->samples;
138 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
141 this->dataPtr->sum -= (*this->dataPtr->valIter);
143 (*this->dataPtr->valIter) = _val;
145 --this->dataPtr->samples;
150 (*this->dataPtr->valIter) = _val;
158 this->dataPtr->valWindowSize = _n;
159 this->dataPtr->valHistory.clear();
160 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
161 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
162 this->dataPtr->sum = T();
163 this->dataPtr->samples = 0;
170 return this->dataPtr->valWindowSize;
177 return this->dataPtr->samples == this->dataPtr->valWindowSize;
184 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
MovingWindowFilter()
Constructor.
Definition: gz/common/MovingWindowFilter.hh:106
Forward declarations for the common classes.
std::unique_ptr< MovingWindowFilterPrivate< T > > dataPtr
Data pointer.
Definition: gz/common/MovingWindowFilter.hh:101
unsigned int WindowSize() const
Get the window size.
Definition: gz/common/MovingWindowFilter.hh:168
void Update(T _val)
Update value of filter.
Definition: gz/common/MovingWindowFilter.hh:120
T Value()
Get filtered result.
Definition: gz/common/MovingWindowFilter.hh:182
bool WindowFilled() const
Get whether the window has been filled.
Definition: gz/common/MovingWindowFilter.hh:175
Base class for MovingWindowFilter.
Definition: gz/common/MovingWindowFilter.hh:67
virtual ~MovingWindowFilter()
Destructor.
Definition: gz/common/MovingWindowFilter.hh:113
void SetWindowSize(unsigned int _n)
Set window size.
Definition: gz/common/MovingWindowFilter.hh:156