37 glm::ivec2
shape = glm::ivec2(0, 0);
67 Array(
const std::string &filename,
bool flip_j =
false);
70 Array(
const std::vector<std::vector<float>> &data);
73 Array(
const std::initializer_list<std::initializer_list<float>> &data);
253 return this->vector[j * this->shape.x + i];
268 return this->vector[j * this->shape.x + i];
273 return this->vector[ij.y * this->shape.x + ij.x];
278 return this->vector[ij.y * this->shape.x + ij.x];
292 return this->vector[index];
304 return this->vector[index];
318 void argmax(
float &vmax,
int &i,
int &j)
const;
364 void dump(
const std::string &fname =
"out.png")
const;
369 void dump_histogram(
int bins = 32,
const std::string &msg =
"")
const;
395 void from_file(
const std::string &fname);
626 void infos(
const std::string &msg =
"")
const;
775 bool ignore_zeros =
false)
const;
867 void set_slice(glm::ivec4 idx,
float value);
890 float std(
float *p_mean =
nullptr,
917 void to_exr(
const std::string &fname)
const;
929 void to_file(
const std::string &fname)
const;
939 void to_numpy(
const std::string &fname)
const;
960 void to_png(
const std::string &fname,
962 bool hillshading =
false,
963 int depth = 0)
const;
984 float vmax = 0.f)
const;
998 void to_tiff(
const std::string &fname)
const;
1054 const int w = a.
shape.x;
1055 const int h = a.
shape.y;
1057 for (
int j = 0; j < h; ++j)
1058 for (
int i = 0; i < w; ++i)
1065 const int w = a.
shape.x;
1066 const int h = a.
shape.y;
1068 for (
int j = 0; j < h; ++j)
1069 for (
int i = 0; i < w; ++i)
Header file defining basic vector and matrix manipulation classes.
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:31
void from_file(const std::string &fname)
Import array data from a raw binary file.
Definition io.cpp:27
void dump(const std::string &fname="out.png") const
Debug tool, dump some infos and generate an output file (16bits grayscale).
Definition methods.cpp:109
glm::vec2 range(ICommunicator &comm=SingleArrayComm::instance()) const
Computes the minimum and maximum values of the array.
Definition methods.cpp:347
float mean(ICommunicator &comm=SingleArrayComm::instance()) const
Return the mean value of the elements in the array.
Definition methods.cpp:300
Array resample_to_shape(glm::ivec2 new_shape) const
Return a resampled array of shape new_shape using bilinear interpolation.
Definition methods.cpp:460
void normalize(ICommunicator &comm=SingleArrayComm::instance())
Normalize array values so that the sum of all elements is equal to 1.
Definition methods.cpp:328
void infos(const std::string &msg="") const
Display various information about the array.
Definition io.cpp:67
glm::vec2 range_percentile(float p_low, float p_high, size_t bins=1024, bool ignore_zeros=false) const
Computes an approximate percentile range using a histogram.
Definition methods.cpp:362
float get_value_bilinear_at(int i, int j, float u, float v) const
Retrieves the array value at the location (x, y) near the index (i, j) using bilinear interpolation.
Definition methods.cpp:231
glm::ivec2 linear_index_reverse(int k) const
Convert a linear index to its corresponding (i, j) cell coordinates.
Definition methods.cpp:285
int size() const
Return the total number of elements in the array.
Definition methods.cpp:527
float get_gradient_x_at(int i, int j) const
Calculates the gradient in the 'x' (or 'i') direction at a specified index (i, j) using a 2nd order c...
Definition methods.cpp:140
float sum(ICommunicator &comm=SingleArrayComm::instance()) const
Return the sum of all array values.
Definition methods.cpp:558
Array & operator=(const float value)
Overloads the assignment operator for scalar assignment.
Definition array.cpp:102
glm::ivec2 get_shape()
Retrieves the shape of the array.
Definition array.cpp:80
int linear_index(int i, int j) const
Return the linear index corresponding to the (i, j) cell in a 2D array.
Definition methods.cpp:280
Array extract_slice(glm::ivec4 idx) const
Extracts a subarray defined by the slice indices {i1, i2, j1, j2} from the original array,...
Definition methods.cpp:121
void to_numpy(const std::string &fname) const
Export the array to a numpy binary file.
Definition io.cpp:122
void dump_histogram(int bins=32, const std::string &msg="") const
Debug tool, dump array content as an ASCII histogram to the consol.
Definition methods.cpp:115
Array operator+(const float value) const
Overloads the addition operator for scalar addition.
Definition array.cpp:268
Array & operator*=(const float value)
Overloads the multiplication-assignment operator for scalar multiplication.
Definition array.cpp:108
Array & operator+=(const float value)
Overloads the addition-assignment operator for scalar addition.
Definition array.cpp:152
const float & operator()(int i, int j) const
Overloads the function call operator to access the array value at index (i, j) (const version).
Definition array.hpp:266
float & operator()(int index)
Overloads the function call operator to access the array value at the linear index 'index'.
Definition array.hpp:302
float & operator()(glm::ivec2 ij)
Definition array.hpp:271
void to_png(const std::string &fname, int cmap, bool hillshading=false, int depth=0) const
Export the array as a PNG image file with a specified colormap and hillshading.
Definition io.cpp:132
float get_gradient_y_bilinear_at(int i, int j, float u, float v) const
Calculates the gradient in the 'y' (or 'j') direction at a location (x, y) near the index (i,...
Definition methods.cpp:164
void to_png_grayscale(const std::string &fname, int depth=0, float vmin=0.f, float vmax=0.f) const
Export the array as a grayscale PNG image file with specified bit depth.
Definition io.cpp:146
void from_numpy(const std::string &fname)
Import array data from a numpy binary file.
Definition io.cpp:38
Array operator-() const
Overloads the unary minus operator.
Definition array.cpp:304
std::vector< float > get_vector() const
Retrieves the underlying data vector.
Definition array.cpp:85
void to_file(const std::string &fname) const
Export the array to a raw binary file.
Definition io.cpp:110
void to_tiff(const std::string &fname) const
Export the array as a TIFF image file.
Definition io.cpp:170
float std(float *p_mean=nullptr, ICommunicator &comm=SingleArrayComm::instance()) const
Return the standard deviation of all array values.
Definition methods.cpp:532
void print() const
Print the array values to the standard output (stdout).
Definition io.cpp:83
size_t get_sizeof() const
Retrieves the number of bytes occupied by the array data.
Definition methods.cpp:192
float get_gradient_x_bilinear_at(int i, int j, float u, float v) const
Calculates the gradient in the 'x' (or 'i') direction at a location (x, y) near the index (i,...
Definition methods.cpp:150
std::vector< float > row_to_vector(int i)
Return a row i as a std::vector<float>.
Definition methods.cpp:501
std::vector< float > col_to_vector(int j)
Extracts a column 'j' as a std::vector.
Definition methods.cpp:46
Array remapped() const
Return an array remapped to [0, 1].
Definition methods.cpp:453
void depose_amount_kernel_bilinear_at(int i, int j, float u, float v, int ir, float amount)
Definition methods.cpp:66
void depose_amount_kernel_at(int i, int j, const Array &kernel, float amount)
Distributes a specified amount of value around the cell located at (i, j) using a 1D deposition kerne...
Definition methods.cpp:92
float min(ICommunicator &comm=SingleArrayComm::instance()) const
Return the value of the smallest element in the array.
Definition methods.cpp:321
Array()
Constructs a new Array object.
Definition array.cpp:17
void argmax(float &vmax, int &i, int &j) const
Finds the maximum value in the array and its coordinates.
Definition methods.cpp:25
glm::ivec2 shape
The shape of the array {ni, nj}.
Definition array.hpp:37
const float & operator()(glm::ivec2 ij) const
Definition array.hpp:276
void to_exr(const std::string &fname) const
Export the array as an OpenEXR image file.
Definition io.cpp:96
Array & operator-=(const float value)
Overloads the subtraction-assignment operator for scalar subtraction.
Definition array.cpp:173
float median() const
Return the median value of the elements in the array.
Definition methods.cpp:315
Array resample_to_shape_bilinear(glm::ivec2 new_shape) const
Definition methods.cpp:479
std::vector< float > unique_values(ICommunicator &comm=SingleArrayComm::instance()) const
Return the unique elements of the array.
Definition methods.cpp:568
float ptp(ICommunicator &comm=SingleArrayComm::instance()) const
Return the peak-to-peak amplitude (i.e., the difference between the maximum and minimum values) of th...
Definition methods.cpp:341
void to_raw_16bit(const std::string &fname) const
Export the array as a 16-bit raw file for Unity terrain import.
Definition io.cpp:165
Array & operator/=(const float value)
Overloads the division-assignment operator for scalar division.
Definition array.cpp:129
glm::vec2 normalization_coeff(float vmin=0.f, float vmax=1.f) const
Computes normalization coefficients (a, b) such that a * array + b maps the values to the range [vmin...
Definition methods.cpp:197
float get_value_nearest(float x, float y, const UvRect &uv_rect=UvRect::unit()) const
Retrieves the nearest value at the location (x, y) within a bounded domain.
Definition methods.cpp:272
float get_gradient_y_at(int i, int j) const
Calculates the gradient in the 'y' (or 'j') direction at a specified index (i, j) using a 2nd order c...
Definition methods.cpp:145
Array operator/(const float value) const
Overloads the division operator for scalar division.
Definition array.cpp:230
Array operator*(const float value) const
Overloads the multiplication operator for scalar multiplication.
Definition array.cpp:194
float & operator()(int i, int j)
Overloads the function call operator to access the array value at index (i, j).
Definition array.hpp:251
Array resample_to_shape_bicubic(glm::ivec2 new_shape) const
Return a resampled array of shape new_shape using bicubic interpolation.
Definition methods.cpp:468
float get_value_bilinear(float x, float y, const UvRect &uv_rect=UvRect::unit()) const
Retrieves the value at the location (x, y) within a bounded domain using bilinear interpolation.
Definition methods.cpp:253
const float & operator()(int index) const
Overloads the function call operator to access the array value at the linear index 'index' (const ver...
Definition array.hpp:290
void set_slice(glm::ivec4 idx, float value)
Set the value of a slice defined by indices {i1, i2, j1, j2} to a new value.
Definition methods.cpp:509
float get_value_bicubic_at(int i, int j, float u, float v) const
Retrieves the array value at the location (x, y) near the index (i, j) using bicubic interpolation.
Definition methods.cpp:209
Array resample_to_shape_nearest(glm::ivec2 new_shape) const
Return a resampled array of shape new_shape using nearest neighbor interpolation.
Definition methods.cpp:490
void depose_amount_bilinear_at(int i, int j, float u, float v, float amount)
Distribute a value 'amount' around the four cells (i, j), (i + 1, j), (i, j + 1), (i + 1,...
Definition methods.cpp:54
std::vector< float > vector
The underlying data storage, a vector of size shape.x * shape.y.
Definition array.hpp:43
glm::vec3 get_normal_at(int i, int j) const
Calculates the surface normal vector at the index (i, j).
Definition methods.cpp:178
void set_shape(glm::ivec2 new_shape)
Sets a new shape for the array.
Definition array.cpp:90
float max(ICommunicator &comm=SingleArrayComm::instance()) const
Return the value of the greatest element in the array.
Definition methods.cpp:293
Abstract communicator interface providing MPI-style collective directives for single-source SPMD Arra...
Definition communicator_interface.hpp:60
static SingleArrayComm & instance()
Definition communicator.cpp:78
Lightweight abstract SPMD communicator interface for Array and VirtualArray collective operations.
void for_each_cell(Array &a, Fn &&fn)
Apply a function to every cell (mutable).
Definition array.hpp:1052
size_t count_non_zero(const Array &array)
Count the number of non-zero elements in the array.
Definition array_functions.cpp:12
size_t count_zero(const Array &array)
Count the number of zero elements in the array.
Definition array_functions.cpp:20
Axis-aligned rectangle in normalized [0, 1]^2 domain/UV space.
Definition uv_rect.hpp:30
static constexpr UvRect unit()
Definition uv_rect.hpp:46
Normalized domain/UV rectangle [u_min, u_max] x [v_min, v_max].