8#include "../global.hpp"
9#include "utilities.hpp"
10#include "stop_watch.hpp"
88 , windowSize_(windowSize)
101 , windowSize_(windowSize)
127 return stopWatch_.
Mode();
148 if (windowSize_ == windowSize)
154 windowSize_ = windowSize;
156 while (
static_cast<int>(measurements_.size()) > windowSize_)
157 measurements_.pop_front();
170 double sum = std::accumulate(measurements_.begin(), measurements_.end(), 0.0);
171 if (!measurements_.size())
174 auto result = std::round(sum /
static_cast<double>(measurements_.size()));
186 if (measurements_.size() < 2)
190 return 1000.0 /
static_cast<double>(averageTimeSpan.count());
210 measurements_.clear();
221 if (std::isnan(lastReading_))
228 auto now =
static_cast<double>(stopWatch_.
TimeSpan().count());
229 measurements_.push_back(now - lastReading_);
233 while (
static_cast<int>(measurements_.size()) > windowSize_)
234 measurements_.pop_front();
Frame rate measurement counter with selectable averaging window.
Definition: rate_counter.hpp:25
RateCounter(int windowSize, StopWatchMode mode)
Constructor for a rate counter object.
Definition: rate_counter.hpp:99
static constexpr int MinimumWindowSize
Minimal selectable averaging window size.Trying to select a smaller window will result in an exceptio...
Definition: rate_counter.hpp:31
std::chrono::milliseconds AverageTimeSpan() const noexcept
Average time span between two steps or since the creation of the counter or the most recent reset.
Definition: rate_counter.hpp:168
void SetWindowSize(int windowSize)
Sets the currently used averaging window size.
Definition: rate_counter.hpp:146
static std::unique_ptr< RateCounter > Create(int windowSize)
Creates a frame counter object for multi CPU.
Definition: rate_counter.hpp:55
void Reset() noexcept
Erase all measurements so far.
Definition: rate_counter.hpp:208
static std::unique_ptr< RateCounter > Create()
Creates a frame counter object for multi CPU with default averaging window (25).
Definition: rate_counter.hpp:44
double Rate() const noexcept
Returns the rate(1 / s) at which the steps occurred.
Definition: rate_counter.hpp:184
int NumSteps() const noexcept
Number of steps called since construction or since last reset.
Definition: rate_counter.hpp:199
static constexpr int MaximumWindowSize
Maximum selectable averaging window size. Trying to select a larger window will result in an exceptio...
Definition: rate_counter.hpp:37
void Step() noexcept
Reading step (first reading step will not yield a measurement result, but define the starting point).
Definition: rate_counter.hpp:219
RateCounter(RateCounter &&other)=default
Move constructor.
RateCounter()
Constructor for a rate counter object for multi-CPU architectures with default averaging window size ...
Definition: rate_counter.hpp:76
int WindowSize() const noexcept
Gets the currently used averaging window size.
Definition: rate_counter.hpp:135
static std::unique_ptr< RateCounter > Create(int windowSize, StopWatchMode mode)
Creates a frame counter object.
Definition: rate_counter.hpp:67
static constexpr int DefaultWindowSize
Default averaging window size.
Definition: rate_counter.hpp:34
StopWatchMode Mode() const noexcept
The stop watch mode used internally.
Definition: rate_counter.hpp:125
RateCounter(int windowSize)
Constructor for a rate counter object for multi-CPU architectures.
Definition: rate_counter.hpp:86
Speed measurement object.
Definition: stop_watch.hpp:47
void Start()
Start (or re-start) the stopwatch.
Definition: stop_watch.hpp:139
std::chrono::milliseconds TimeSpan() const
Gets the time, that has elapsed since start (or since the construction of the object,...
Definition: stop_watch.hpp:150
StopWatchMode Mode() const noexcept
Mode for which the stop watch was created.
Definition: stop_watch.hpp:163
StopWatchMode
Mode at which the StopWatch should work.
Definition: utilities.hpp:31
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24