SpectralBins¶
-
struct Bin¶
Represents a wavelength bin with minimum, maximum, and center wavelengths.
Wavelengths are stored in meters (SI units).
-
template<std::size_t N, auto... Args>
class SpectralBins¶ A template class representing spectral data distributed across wavelength bins.
SpectralBins provides a container for spectral values (e.g., radiance, irradiance) discretized into wavelength bins. The bins can be configured with:
Uniform spacing (2 args: min, max wavelengths in nm)
Explicit pairs (2N args: min1, max1, min2, max2, …)
Bin edges (N+1 args: edge0, edge1, …, edgeN)
The template arguments are to be given in units of nanometers.
Supports standard container operations, arithmetic operations (element-wise and scalar), and spectral analysis functions.
- Template Parameters:
N – The number of spectral bins.
Args – Variadic template parameters defining bin configuration.
Public Types
-
using value_type = float¶
-
using size_type = std::size_t¶
-
using reference = float&¶
-
using const_reference = const float&¶
Public Functions
-
constexpr SpectralBins()¶
Default constructor initializing all bins to zero.
-
explicit constexpr SpectralBins(const float &value)¶
Constructs a SpectralBins with all bins set to the same value.
- Parameters:
value – The value to assign to all bins.
-
constexpr SpectralBins(std::initializer_list<float> init)¶
Constructs from an initializer list.
If the list has one element, fills all bins with that value. Otherwise, copies values from the list (up to N elements).
- Parameters:
init – Initializer list of float values.
-
template<typename ...Args2>
constexpr SpectralBins(Args2&&... args)¶ Constructs from exactly N values.
- Template Parameters:
Args2 – Parameter pack of convertible-to-float types.
- Parameters:
args – Values for each bin (must be exactly N values).
-
constexpr SpectralBins(const SpectralBins&) = default¶
-
constexpr SpectralBins(SpectralBins&&) = default¶
-
SpectralBins &operator=(const SpectralBins&) = default¶
-
SpectralBins &operator=(SpectralBins&&) = default¶
-
inline const_reference operator[](size_type pos) const¶
-
inline const_reference at(size_type pos) const¶
-
inline const_reference front() const¶
-
inline const_reference back() const¶
-
inline float *data() noexcept¶
-
inline const float *data() const noexcept¶
-
inline const_iterator begin() const noexcept¶
-
inline const_iterator cbegin() const noexcept¶
-
inline const_iterator end() const noexcept¶
-
inline const_iterator cend() const noexcept¶
-
inline void fill(const float &value)¶
-
float total() const¶
Sum of all spectral values.
Computes the sum of all spectral values.
- Returns:
The total sum across all bins.
-
float magnitude() const¶
Euclidean magnitude (L2 norm) of the spectral vector.
Computes the Euclidean magnitude (L2 norm).
- Returns:
The square root of the sum of squared values.
-
float max() const¶
Maximum value across all bins.
Finds the maximum value across all bins.
- Returns:
The maximum spectral value, or 0.0 if N is 0.
-
float min() const¶
Minimum value across all bins.
Finds the minimum value across all bins.
- Returns:
The minimum spectral value, or 0.0 if N is 0.
-
float integrate() const¶
Wavelength-weighted integral over all bins.
Computes the wavelength-weighted integral.
Integrates the spectral distribution by summing each bin’s value multiplied by its wavelength width.
- Returns:
The integrated value over wavelength.
-
bool valid() const¶
Checks if all spectral values are valid (non-negative, not NaN, not infinite).
Checks if all spectral values are valid.
Validates that all values are non-negative, not NaN, and not infinite.
- Returns:
True if all values are valid.
-
bool valid_ratio() const¶
Checks if all spectral values are valid ratios (between 0 and 1, not NaN, not infinite).
Checks if all spectral values are valid albedo values.
Validates that all values are between 0 and 1, not NaN, and not infinite.
- Returns:
True if all values are valid abledo values.
-
SpectralBins &operator+=(const SpectralBins &other)¶
-
SpectralBins &operator-=(const SpectralBins &other)¶
-
SpectralBins &operator*=(const SpectralBins &other)¶
-
SpectralBins &operator/=(const SpectralBins &other)¶
-
template<typename U>
SpectralBins &operator+=(const U &scalar)¶
-
template<typename U>
SpectralBins &operator-=(const U &scalar)¶
-
template<typename U>
SpectralBins &operator*=(const U &scalar)¶
-
template<typename U>
SpectralBins &operator/=(const U &scalar)¶
-
SpectralBins operator+() const¶
-
SpectralBins operator-() const¶
-
bool operator==(const SpectralBins &other) const¶
-
bool operator!=(const SpectralBins &other) const¶
-
std::string to_string() const¶
-
template<typename U>
SpectralBins<N, Args...> &operator+=(const U &scalar)¶
-
template<typename U>
SpectralBins<N, Args...> &operator-=(const U &scalar)¶
-
template<typename U>
SpectralBins<N, Args...> &operator*=(const U &scalar)¶
-
template<typename U>
SpectralBins<N, Args...> &operator/=(const U &scalar)¶
Public Static Functions
-
static inline bool empty() noexcept¶
-
static SpectralBins from_total(float total)¶
Creates a spectral distribution from a total value.
Distributes the total value proportionally across bins based on their wavelength widths. Wider bins receive proportionally more of the total.
- Parameters:
total – The total value to distribute.
- Returns:
A SpectralBins instance with distributed values.
-
static SpectralBins photon_energies()¶
Computes photon energies for each bin’s center wavelength.
Calculates the energy of a photon at each bin’s center wavelength using the relation E = hc/lambda.
- Returns:
A SpectralBins instance containing photon energies in Joules.