ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MinFilter.h
Go to the documentation of this file.
1/**
2 * @file MinFilter.h
3 * @brief Implements a moving minimum filter for processing data streams.
4 *
5 * The `MinFilter` maintains a window of the smallest values over a specified
6 * memory range. It is useful for smoothing data while capturing minimum values.
7 *
8 * @date 22/12/2024
9 * @version 1.0
10 * @author Coela Can't
11 */
12
13#pragma once
14
15#include "../Math/Mathematics.h"
16
17/**
18 * @class MinFilter
19 * @brief Implements a minimum filter over a sliding window.
20 *
21 * This class filters input data by maintaining a history of minimum values
22 * over a specified memory window. It is particularly useful for detecting
23 * and tracking minimum values in data streams.
24 *
25 * @tparam memory The size of the memory window for tracking minimum values.
26 */
27template<size_t memory>
28class MinFilter {
29private:
30 const int minMemory = static_cast<int>(std::ceil(memory / 10.0)); ///< Number of memory blocks for minimum tracking.
31 float values[memory]; ///< Circular buffer of values.
32 float minValues[memory / 10]; ///< Array of minimum values in each block.
33 uint8_t currentAmount = 0; ///< Number of values currently stored in the buffer.
34 bool ignoreSame; ///< Whether to ignore consecutive identical values.
35
36 /**
37 * @brief Shifts the values in the specified array to make room for a new value.
38 *
39 * @param mem The size of the array.
40 * @param arr The array to shift.
41 */
42 void ShiftArray(uint8_t mem, float* arr);
43
44public:
45 /**
46 * @brief Constructs a `MinFilter` with the specified memory size and behavior.
47 *
48 * @param ignoreSame Whether to ignore consecutive identical values (default: true).
49 */
50 MinFilter(bool ignoreSame = true);
51
52 /**
53 * @brief Filters the given value, updating the minimum value within the memory window.
54 *
55 * @param value The input value to filter.
56 * @return The minimum value within the memory window after updating with the new value.
57 */
58 float Filter(float value);
59};
60
61#include "MinFilter.tpp" // Includes the implementation of the template class.
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
MinFilter(bool ignoreSame=true)
Constructs a MinFilter with the specified memory size and behavior.
const int minMemory
Number of memory blocks for minimum tracking.
Definition MinFilter.h:30
uint8_t currentAmount
Number of values currently stored in the buffer.
Definition MinFilter.h:33
void ShiftArray(uint8_t mem, float *arr)
Shifts the values in the specified array to make room for a new value.
float values[memory]
Circular buffer of values.
Definition MinFilter.h:31
float Filter(float value)
Filters the given value, updating the minimum value within the memory window.
bool ignoreSame
Whether to ignore consecutive identical values.
Definition MinFilter.h:34
float minValues[memory/10]
Array of minimum values in each block.
Definition MinFilter.h:32