22#include <source_location>
36 const std::source_location &loc = std::source_location::current())
38 if (shape.x <= 0 || shape.y <= 0)
41 "Invalid array shape ({}, {}): dimensions must be positive",
60 const std::source_location &loc = std::source_location::current())
66 "Array is empty or uninitialized (shape: {}x{}, buffer size: {})",
72 if (array.
vector.size() !=
static_cast<size_t>(array.
shape.x * array.
shape.y))
76 "Array buffer size ({}) does not match shape dimensions ({}x{} = {})",
96 requires requires(
const T &t) {
97 { t.empty() } -> std::convertible_to<bool>;
101 std::string_view name =
"Container",
102 const std::source_location &loc = std::source_location::current())
104 if (container.empty())
123 requires requires(
const T &t) {
124 { t.size() } -> std::convertible_to<size_t>;
129 std::string_view name =
"Container",
130 const std::source_location &loc = std::source_location::current())
132 if (container.size() < min_size)
135 "{} has {} elements, but at least {} are required",
155 const std::source_location &loc = std::source_location::current())
161 "Array shape mismatch: lhs is ({}, {}) [size: {}], rhs is ({}, {}) "
186 const std::source_location &loc = std::source_location::current())
188 if (shape != b.
shape ||
189 static_cast<size_t>(shape.x * shape.y) != b.
vector.size())
193 "Array shape mismatch: expected shape ({}, {}), actual is ({}, {}) "
217 int min_channels = 1,
218 const std::source_location &loc = std::source_location::current())
224 "Texture is empty or uninitialized (shape: {}x{}, channels: {})",
230 if (
static_cast<int>(tex.
channels.size()) < min_channels)
233 "Texture has {} channels, but at least {} are required",
238 for (
size_t k = 0; k < tex.
channels.size(); ++k)
244 "Texture channel {} shape mismatch: channel is ({}, {}), "
245 "texture is ({}, {})",
267 int expected_channels,
268 const std::source_location &loc = std::source_location::current())
270 if (
static_cast<int>(tex.
channels.size()) != expected_channels)
273 "Texture has {} channels, but exactly {} are required",
292 const std::source_location &loc = std::source_location::current())
297 "Texture shape mismatch: lhs is ({}, {}), rhs is ({}, {})",
318 const std::source_location &loc = std::source_location::current())
324 "Texture/Array shape mismatch: texture is ({}, {}), array is ({}, {})",
346 const std::source_location &loc = std::source_location::current())
348 if (idx.x < 0 || idx.y > array.
shape.x || idx.x >= idx.y || idx.z < 0 ||
349 idx.w > array.
shape.y || idx.z >= idx.w)
352 "Invalid slice [{}, {}, {}, {}] for array shape ({}, {})",
378 const std::source_location &loc = std::source_location::current())
382 const int slice_w = idx.y - idx.x;
383 const int slice_h = idx.w - idx.z;
384 if (src.
shape.x != slice_w || src.
shape.y != slice_h)
388 "Slice dimensions ({}, {}) do not match source array shape ({}, {})",
407 const std::source_location &loc = std::source_location::current())
433 std::string_view param_name =
"Range",
434 const std::source_location &loc = std::source_location::current())
436 if (range.x < min_val || range.y > max_val || range.x > range.y)
439 "{} [{}, {}] is invalid: expected values within [{}, {}] "
460 const std::source_location &loc = std::source_location::current())
464 for (
size_t k = 0; k < array.
vector.size(); ++k)
466 float val = array.
vector[k];
468 std::memcpy(&bits, &val,
sizeof(
float));
469 if ((bits & 0x7F800000u) == 0x7F800000u)
472 "Non-finite value ({}) encountered at linear index {}",
490 const std::source_location &loc = std::source_location::current())
Declaration of the Array class for 2D floating-point arrays with various mathematical operations and ...
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
glm::ivec2 shape
The shape of the array {ni, nj}.
Definition array.hpp:38
std::vector< float > vector
The underlying data storage, a vector of size shape.x * shape.y.
Definition array.hpp:44
A class to represent a multi-channel texture using planar hmap::Array storage.
Definition texture.hpp:37
std::vector< Array > channels
Vector of planar Array channels.
Definition texture.hpp:47
glm::ivec2 shape
Shape of the texture in 2D space (x, y).
Definition texture.hpp:42
Predefined color mapping schemes for data visualization, including perceptual uniform (Viridis,...
Custom logger utility with spdlog-like formatting and source location.
void warn(Args &&...args)
Definition logger.hpp:48
Definition algebra.hpp:23
bool validate_cmap(int cmap, const std::source_location &loc=std::source_location::current())
Validates that a colormap ID corresponds to a valid Cmap enum value.
Definition validation.hpp:488
bool validate_min_size(const T &container, size_t min_size, std::string_view name="Container", const std::source_location &loc=std::source_location::current())
Validates that a container has at least min_size elements.
Definition validation.hpp:126
bool validate_shape(glm::ivec2 shape, const std::source_location &loc=std::source_location::current())
Validates that array dimensions are strictly positive.
Definition validation.hpp:34
bool validate_parameter_range(glm::vec2 range, float min_val, float max_val, std::string_view param_name="Range", const std::source_location &loc=std::source_location::current())
Validates that a 2D range vector {low, high} lies within [min_val, max_val] with low <= high.
Definition validation.hpp:429
bool validate_finite(const Array &array, const std::source_location &loc=std::source_location::current())
Validates that all elements of an array are finite (not NaN or Inf).
Definition validation.hpp:458
bool validate_slice_for_array(const Array &dest, glm::ivec4 idx, const Array &src, const std::source_location &loc=std::source_location::current())
Validates that a slice extent matches the dimensions of a source array.
Definition validation.hpp:374
bool validate_not_zero(float value, const std::source_location &loc=std::source_location::current())
Validates that a divisor value is not zero.
Definition validation.hpp:405
bool validate_channels(const Texture &tex, int expected_channels, const std::source_location &loc=std::source_location::current())
Validates exact channel count of a Texture.
Definition validation.hpp:265
bool validate_same_shape(const Array &a, const Array &b, const std::source_location &loc=std::source_location::current())
Validates that two arrays have identical shapes and buffer sizes.
Definition validation.hpp:152
@ WHITE_UNIFORM
Definition colormaps.hpp:95
@ BONE
Definition colormaps.hpp:84
bool validate_non_empty(const Array &array, const std::source_location &loc=std::source_location::current())
Validates that an array is initialized, non-empty, and has a consistent buffer size.
Definition validation.hpp:58
bool validate_slice(const Array &array, glm::ivec4 idx, const std::source_location &loc=std::source_location::current())
Validates that a slice extent {i1, i2, j1, j2} is valid and within array boundaries.
Definition validation.hpp:343
Header file for the Texture class.