Go to the documentation of this file.
17 #ifndef GZ_MATH_MOVINGWINDOWFILTER_HH_
18 #define GZ_MATH_MOVINGWINDOWFILTER_HH_
22 #include "gz/math/Export.hh"
29 inline namespace IGNITION_MATH_VERSION_NAMESPACE {
36 class MovingWindowFilterPrivate
39 public: MovingWindowFilterPrivate();
42 public:
unsigned int valWindowSize = 4;
54 public:
unsigned int samples = 0;
59 MovingWindowFilterPrivate<T>::MovingWindowFilterPrivate()
62 this->valHistory.
resize(this->valWindowSize);
63 this->valIter = this->valHistory.begin();
83 public:
void Update(
const T _val);
87 public:
void SetWindowSize(
const unsigned int _n);
91 public:
unsigned int WindowSize()
const;
95 public:
bool WindowFilled()
const;
99 public: T Value()
const;
108 : dataPtr(new MovingWindowFilterPrivate<T>())
116 this->dataPtr->valHistory.clear();
126 this->dataPtr->sum += _val;
129 ++this->dataPtr->valIter;
130 if (this->dataPtr->valIter == this->dataPtr->valHistory.end())
133 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
137 ++this->dataPtr->samples;
139 if (this->dataPtr->samples > this->dataPtr->valWindowSize)
142 this->dataPtr->sum -= (*this->dataPtr->valIter);
144 (*this->dataPtr->valIter) = _val;
146 --this->dataPtr->samples;
151 (*this->dataPtr->valIter) = _val;
159 this->dataPtr->valWindowSize = _n;
160 this->dataPtr->valHistory.clear();
161 this->dataPtr->valHistory.resize(this->dataPtr->valWindowSize);
162 this->dataPtr->valIter = this->dataPtr->valHistory.begin();
163 this->dataPtr->sum = T();
164 this->dataPtr->samples = 0;
171 return this->dataPtr->valWindowSize;
178 return this->dataPtr->samples == this->dataPtr->valWindowSize;
185 return this->dataPtr->sum /
static_cast<double>(this->dataPtr->samples);
Base class for MovingWindowFilter. This replaces the version of MovingWindowFilter in the Ignition Co...
Definition: gz/math/MovingWindowFilter.hh:73
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
T Value() const
Get filtered result.
Definition: gz/math/MovingWindowFilter.hh:183
MovingWindowFilter()
Constructor.
Definition: gz/math/MovingWindowFilter.hh:107
void Update(const T _val)
Update value of filter.
Definition: gz/math/MovingWindowFilter.hh:121
void SetWindowSize(const unsigned int _n)
Set window size.
Definition: gz/math/MovingWindowFilter.hh:157
unsigned int WindowSize() const
Get the window size.
Definition: gz/math/MovingWindowFilter.hh:169
bool WindowFilled() const
Get whether the window has been filled.
Definition: gz/math/MovingWindowFilter.hh:176
virtual ~MovingWindowFilter()
Destructor.
Definition: gz/math/MovingWindowFilter.hh:114