17#include <opencv2/core/mat.hpp>
65 Array(
const std::string &filename);
242 return this->vector[j * this->shape.
x + i];
255 return this->vector[j * this->shape.
x + i];
313 void dump(
const std::string &fname =
"out.png")
const;
337 void from_file(
const std::string &fname);
552 void infos(std::string msg =
"")
const;
810 void to_exr(
const std::string &fname)
const;
822 void to_file(
const std::string &fname)
const;
832 void to_numpy(
const std::string &fname)
const;
853 void to_png(
const std::string &fname,
855 bool hillshading =
false,
856 int depth = CV_8U)
const;
888 void to_tiff(
const std::string &fname)
const;
Header file defining basic vector and matrix manipulation classes.
unsigned int uint
Definition array.hpp:14
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:32
void from_file(const std::string &fname)
Import array data from a raw binary file.
Definition io.cpp:18
void dump(const std::string &fname="out.png") const
Debug tool, dump some infos and generate an output file (16bits grayscale)
Definition methods.cpp:93
Vec3< float > get_normal_at(int i, int j) const
Calculates the surface normal vector at the index (i, j).
Definition methods.cpp:155
int count_non_zero()
Return the number of non-zero elements in the array.
Definition methods.cpp:30
void set_slice(Vec4< int > idx, float value)
Set the value of a slice defined by indices {i1, i2, j1, j2} to a new value.
Definition methods.cpp:319
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:208
int size() const
Return the total number of elements in the array.
Definition methods.cpp:333
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:117
Array resample_to_shape(Vec2< int > new_shape) const
Return a resampled array of shape new_shape using bilinear interpolation.
Definition methods.cpp:282
float mean() const
Return the mean value of the elements in the array.
Definition methods.cpp:257
Vec2< int > linear_index_reverse(int k) const
Convert a linear index to its corresponding (i, j) cell coordinates.
Definition methods.cpp:244
Array & operator=(const float value)
Overloads the assignment operator for scalar assignment.
Definition array.cpp:51
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:239
friend Array operator+(const float value, const Array &array)
Overloads the addition operator for scalar addition.
Definition array.cpp:224
void infos(std::string msg="") const
Display various information about the array.
Definition io.cpp:58
void to_numpy(const std::string &fname) const
Export the array to a numpy binary file.
Definition io.cpp:112
Vec2< int > shape
The shape of the array {ni, nj}.
Definition array.hpp:38
Array & operator*=(const float value)
Overloads the multiplication-assignment operator for scalar multiplication.
Definition array.cpp:57
Array & operator+=(const float value)
Overloads the addition-assignment operator for scalar addition.
Definition array.cpp:95
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:253
float min() const
Return the value of the smallest element in the array.
Definition methods.cpp:262
Array extract_slice(Vec4< int > idx) const
Extracts a subarray defined by the slice indices {i1, i2, j1, j2} from the original array,...
Definition methods.cpp:100
friend Array operator*(const float value, const Array &array)
Overloads the multiplication operator for scalar multiplication.
Definition array.cpp:156
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:141
void from_numpy(const std::string &fname)
Import array data from a numpy binary file.
Definition io.cpp:29
Array operator-() const
Overloads the unary minus operator.
Definition array.cpp:235
std::vector< float > get_vector() const
Retrieves the underlying data vector.
Definition array.cpp:40
float max() const
Return the value of the greatest element in the array.
Definition methods.cpp:252
void to_file(const std::string &fname) const
Export the array to a raw binary file.
Definition io.cpp:100
Array resample_to_shape_bilinear(Vec2< int > new_shape) const
Definition methods.cpp:295
void to_tiff(const std::string &fname) const
Export the array as a TIFF image file.
Definition io.cpp:153
Vec2< float > 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:174
void print() const
Print the array values to the standard output (stdout).
Definition io.cpp:72
float sum() const
Return the sum of all array values.
Definition methods.cpp:346
size_t get_sizeof() const
Retrieves the number of bytes occupied by the array data.
Definition methods.cpp:169
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:127
std::vector< float > row_to_vector(int i)
Return a row i as a std::vector<float>.
Definition methods.cpp:311
std::vector< float > col_to_vector(int j)
Extracts a column 'j' as a std::vector.
Definition methods.cpp:22
void depose_amount_kernel_bilinear_at(int i, int j, float u, float v, int ir, float amount)
Definition methods.cpp:50
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:76
void set_shape(Vec2< int > new_shape)
Sets a new shape for the array.
Definition array.cpp:45
Array()
Constructs a new Array object.
Definition array.cpp:15
float get_value_nearest(float x, float y, Vec4< float > bbox)
Retrieves the nearest value at the location (x, y) within a bounded domain.
Definition methods.cpp:230
void to_png(const std::string &fname, int cmap, bool hillshading=false, int depth=CV_8U) const
Export the array as a PNG image file with a specified colormap and hillshading.
Definition io.cpp:122
void to_exr(const std::string &fname) const
Export the array as an OpenEXR image file.
Definition io.cpp:85
Array & operator-=(const float value)
Overloads the subtraction-assignment operator for scalar subtraction.
Definition array.cpp:114
float std() const
Return the standard deviation of all array values.
Definition methods.cpp:338
friend Array operator/(const float value, const Array &array)
Overloads the division operator for scalar division.
Definition array.cpp:190
void normalize()
Normalize array values so that the sum of all elements is equal to 1.
Definition methods.cpp:267
cv::Mat to_cv_mat()
Converts a 2D Array to an OpenCV cv::Mat.
Definition opencv_wrapper.cpp:12
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:148
Array & operator/=(const float value)
Overloads the division-assignment operator for scalar division.
Definition array.cpp:76
float ptp() const
Return the peak-to-peak amplitude (i.e., the difference between the maximum and minimum values) of th...
Definition methods.cpp:277
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:122
std::vector< float > unique_values()
Return the unique elements of the array.
Definition methods.cpp:351
Vec2< int > get_shape()
Retrieves the shape of the array.
Definition array.cpp:35
Array resample_to_shape_nearest(Vec2< int > new_shape) const
Return a resampled array of shape new_shape using nearest neighbor interpolation.
Definition methods.cpp:303
void to_png_grayscale(const std::string &fname, int depth=CV_8U) const
Export the array as a grayscale PNG image file with specified bit depth.
Definition io.cpp:136
float & operator()(int i, int j)
Overloads the function call operator to access the array value at index (i, j).
Definition array.hpp:240
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:186
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:38
Array resample_to_shape_bicubic(Vec2< int > new_shape) const
Return a resampled array of shape new_shape using bicubic interpolation.
Definition methods.cpp:287
std::vector< float > vector
The underlying data storage, a vector of size shape.x * shape.y.
Definition array.hpp:44
Predefined color mapping schemes for data visualization, including perceptual uniform (Viridis,...
Definition algebra.hpp:28
Array cv_mat_to_array(const cv::Mat &mat, bool remap_values=true)
Converts an OpenCV cv::Mat to a 2D Array with optional value scaling to [0, 1].
Definition opencv_wrapper.cpp:26
Vec2 class for basic manipulation of 2D vectors.
Definition algebra.hpp:40
T x
Definition algebra.hpp:41
Vec3 class for basic manipulation of 3D vectors.
Definition algebra.hpp:281
Vec4 class for basic manipulation of 4D vectors.
Definition algebra.hpp:564