MayaFlux
0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AxisRange.hpp
Go to the documentation of this file.
1
#pragma once
2
3
namespace
MayaFlux::Portal::Forma::Plot
{
4
5
/**
6
* @struct AxisRange
7
* @brief Scalar domain extent for one plot axis.
8
*
9
* Maps raw double values in [min, max] to the normalised render space
10
* expected by the geometry function. When auto_scaling is true, min and max
11
* are recomputed from the series data on every process() call, subject to
12
* any predicate set via scale_if().
13
*
14
* Fluent setters return @c AxisRange& for chained construction:
15
* @code
16
* AxisRange{}.range(-1.F, 1.F)
17
* AxisRange{}.auto_scale()
18
* AxisRange{}.range(0.F, 440.F).auto_scale(false)
19
* AxisRange{}.scale_if([&active]{ return active.load(); })
20
* @endcode
21
*/
22
struct
AxisRange
{
23
float
min
{ -1.F };
24
float
max
{ 1.F };
25
bool
auto_scaling
{
false
};
26
27
/// @brief When set, evaluated before applying a data-derived range.
28
/// Returns true to accept the new range, false to keep the current one.
29
std::function<bool()>
scale_predicate
;
30
31
// =========================================================================
32
// Fluent setters
33
// =========================================================================
34
35
/**
36
* @brief Set the explicit [min, max] domain.
37
* Has no effect while auto_scaling is true.
38
*/
39
AxisRange
&
range
(
float
lo,
float
hi)
40
{
41
min
= lo;
42
max
= hi;
43
return
*
this
;
44
}
45
46
/**
47
* @brief Enable or disable auto-scaling.
48
*
49
* When enabled, min and max are recomputed from series data on every
50
* process() call, subject to any predicate set via scale_if().
51
*/
52
AxisRange
&
auto_scale
(
bool
enabled =
true
)
53
{
54
auto_scaling
= enabled;
55
return
*
this
;
56
}
57
58
/**
59
* @brief Gate auto-scaling behind an arbitrary bool-returning callable.
60
*
61
* Any nullary callable returning bool is accepted: an atomic flag read,
62
* a node output comparison, a MappedState check, a lambda closing over
63
* external state. Implicitly enables auto_scaling.
64
*
65
* The predicate is evaluated once per process() call before the new
66
* data-derived range is applied. Returning false keeps the current range.
67
*
68
* @code
69
* // Only scale when signal exceeds a threshold:
70
* AxisRange{}.scale_if([node]{ return node->get_last_output() > 0.5; });
71
*
72
* // Gate on an atomic flag set elsewhere:
73
* AxisRange{}.scale_if([&active]{ return active.load(); });
74
* @endcode
75
*/
76
AxisRange
&
scale_if
(std::function<
bool
()> predicate)
77
{
78
scale_predicate
= std::move(predicate);
79
auto_scaling
=
true
;
80
return
*
this
;
81
}
82
83
// =========================================================================
84
// Mapping
85
// =========================================================================
86
87
/** @brief Map a value into [0, 1] within this range. */
88
[[nodiscard]]
float
normalise
(
float
v)
const
noexcept
89
{
90
if
(
max
==
min
)
91
return
0.F;
92
return
(v -
min
) / (
max
-
min
);
93
}
94
95
/** @brief Map a value into [-1, 1] NDC within this range. */
96
[[nodiscard]]
float
to_ndc
(
float
v)
const
noexcept
97
{
98
return
normalise
(v) * 2.F - 1.F;
99
}
100
};
101
102
}
// namespace MayaFlux::Portal::Forma::Plot
MayaFlux::Portal::Forma::Plot
Definition
AxisRange.hpp:3
MayaFlux::Portal::Forma::Plot::AxisRange::range
AxisRange & range(float lo, float hi)
Set the explicit [min, max] domain.
Definition
AxisRange.hpp:39
MayaFlux::Portal::Forma::Plot::AxisRange::normalise
float normalise(float v) const noexcept
Map a value into [0, 1] within this range.
Definition
AxisRange.hpp:88
MayaFlux::Portal::Forma::Plot::AxisRange::auto_scaling
bool auto_scaling
Definition
AxisRange.hpp:25
MayaFlux::Portal::Forma::Plot::AxisRange::auto_scale
AxisRange & auto_scale(bool enabled=true)
Enable or disable auto-scaling.
Definition
AxisRange.hpp:52
MayaFlux::Portal::Forma::Plot::AxisRange::scale_if
AxisRange & scale_if(std::function< bool()> predicate)
Gate auto-scaling behind an arbitrary bool-returning callable.
Definition
AxisRange.hpp:76
MayaFlux::Portal::Forma::Plot::AxisRange::to_ndc
float to_ndc(float v) const noexcept
Map a value into [-1, 1] NDC within this range.
Definition
AxisRange.hpp:96
MayaFlux::Portal::Forma::Plot::AxisRange::scale_predicate
std::function< bool()> scale_predicate
When set, evaluated before applying a data-derived range.
Definition
AxisRange.hpp:29
MayaFlux::Portal::Forma::Plot::AxisRange::min
float min
Definition
AxisRange.hpp:23
MayaFlux::Portal::Forma::Plot::AxisRange::max
float max
Definition
AxisRange.hpp:24
MayaFlux::Portal::Forma::Plot::AxisRange
Scalar domain extent for one plot axis.
Definition
AxisRange.hpp:22
src
MayaFlux
Portal
Forma
Plot
AxisRange.hpp
Generated by
1.9.8