HighMap library (C++)
|
Array class, helper to manipulate 2D float array with "(i, j)" indexing. More...
#include <array.hpp>
Public Member Functions | |
Array () | |
Constructs a new Array object. | |
Array (Vec2< int > shape) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array (Vec2< int > shape, float value) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array (const std::string &filename) | |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array & | operator= (const float value) |
Overloads the assignment operator for scalar assignment. | |
Array & | operator*= (const float value) |
Overloads the multiplication-assignment operator for scalar multiplication. | |
Array & | operator*= (const Array &array) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array & | operator/= (const float value) |
Overloads the division-assignment operator for scalar division. | |
Array & | operator/= (const Array &array) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array & | operator+= (const float value) |
Overloads the addition-assignment operator for scalar addition. | |
Array & | operator+= (const Array &array) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array & | operator-= (const float value) |
Overloads the subtraction-assignment operator for scalar subtraction. | |
Array & | operator-= (const Array &array) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Array | operator* (const float value) const |
Overloads the multiplication operator for scalar multiplication. | |
Array | operator* (const Array &array) const |
Overloads the multiplication operator for element-wise multiplication with another array. | |
Array | operator/ (const float value) const |
Overloads the division operator for scalar division. | |
Array | operator/ (const Array &array) const |
Overloads the division operator for element-wise division by another array. | |
Array | operator+ (const float value) const |
Overloads the addition operator for scalar addition. | |
Array | operator+ (const Array &array) const |
Overloads the addition operator for element-wise addition with another array. | |
Array | operator- () const |
Overloads the unary minus operator. | |
Array | operator- (const float value) const |
Overloads the subtraction operator for scalar subtraction. | |
Array | operator- (const Array &array) const |
Overloads the subtraction operator for element-wise subtraction with another array. | |
float & | operator() (int i, int j) |
Overloads the function call operator to access the array value at index (i, j). | |
const float & | operator() (int i, int j) const |
Overloads the function call operator to access the array value at index (i, j) (const version). | |
std::vector< float > | col_to_vector (int j) |
Extracts a column 'j' as a std::vector. | |
int | count_non_zero () |
Return the number of non-zero elements in the array. | |
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, j + 1) by "reversing" the bilinear interpolation. | |
void | depose_amount_kernel_bilinear_at (int i, int j, float u, float v, int ir, float amount) |
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 kernel applied in both horizontal and vertical directions. | |
void | dump (const std::string &fname="out.png") const |
Debug tool, dump some infos and generate an output file (16bits grayscale) | |
Array | extract_slice (Vec4< int > idx) const |
Extracts a subarray defined by the slice indices {i1, i2, j1, j2} from the original array, creating a new array. Note that i2 and j2 are excluded from the slice. | |
Array | extract_slice (int i1, int i2, int j1, int j2) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | from_file (const std::string &fname) |
Import array data from a raw binary file. | |
void | from_numpy (const std::string &fname) |
Import array data from a numpy binary file. | |
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 central difference scheme. | |
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 central difference scheme. | |
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, j) using bilinear interpolation. | |
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, j) using bilinear interpolation. | |
Vec3< float > | get_normal_at (int i, int j) const |
Calculates the surface normal vector at the index (i, j). | |
Vec2< int > | get_shape () |
Retrieves the shape of the array. | |
size_t | get_sizeof () const |
Retrieves the number of bytes occupied by the array data. | |
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. | |
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. | |
float | get_value_nearest (float x, float y, Vec4< float > bbox) |
Retrieves the nearest value at the location (x, y) within a bounded domain. | |
std::vector< float > | get_vector () const |
Retrieves the underlying data vector. | |
void | infos (std::string msg="") const |
Display various information about the array. | |
int | linear_index (int i, int j) const |
Return the linear index corresponding to the (i, j) cell in a 2D array. | |
Vec2< int > | linear_index_reverse (int k) const |
Convert a linear index to its corresponding (i, j) cell coordinates. | |
float | max () const |
Return the value of the greatest element in the array. | |
float | mean () const |
Return the mean value of the elements in the array. | |
float | min () const |
Return the value of the smallest element in the array. | |
void | normalize () |
Normalize array values so that the sum of all elements is equal to 1. | |
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, vmax]. | |
void | print () const |
Print the array values to the standard output (stdout). | |
float | ptp () const |
Return the peak-to-peak amplitude (i.e., the difference between the maximum and minimum values) of the array values. | |
Array | resample_to_shape (Vec2< int > new_shape) const |
Return a resampled array of shape new_shape using bilinear interpolation. | |
Array | resample_to_shape_bicubic (Vec2< int > new_shape) const |
Return a resampled array of shape new_shape using bicubic interpolation. | |
Array | resample_to_shape_bilinear (Vec2< int > new_shape) const |
Array | resample_to_shape_nearest (Vec2< int > new_shape) const |
Return a resampled array of shape new_shape using nearest neighbor interpolation. | |
std::vector< float > | row_to_vector (int i) |
Return a row i as a std::vector<float> . | |
void | set_shape (Vec2< int > new_shape) |
Sets a new shape for the array. | |
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. | |
void | set_slice (Vec4< int > idx, const Array &array) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
int | size () const |
Return the total number of elements in the array. | |
float | std () const |
Return the standard deviation of all array values. | |
float | sum () const |
Return the sum of all array values. | |
cv::Mat | to_cv_mat () |
Converts a 2D Array to an OpenCV cv::Mat . | |
void | to_exr (const std::string &fname) const |
Export the array as an OpenEXR image file. | |
void | to_file (const std::string &fname) const |
Export the array to a raw binary file. | |
void | to_numpy (const std::string &fname) const |
Export the array to a numpy binary file. | |
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. | |
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. | |
void | to_tiff (const std::string &fname) const |
Export the array as a TIFF image file. | |
void | to_raw_16bit (const std::string &fname) const |
Export the array as a 16-bit raw file for Unity terrain import. | |
std::vector< float > | unique_values () |
Return the unique elements of the array. | |
Public Attributes | |
Vec2< int > | shape |
The shape of the array {ni, nj}. | |
std::vector< float > | vector |
The underlying data storage, a vector of size shape.x * shape.y. | |
Friends | |
Array | operator* (const float value, const Array &array) |
Overloads the multiplication operator for scalar multiplication. | |
Array | operator/ (const float value, const Array &array) |
Overloads the division operator for scalar division. | |
Array | operator+ (const float value, const Array &array) |
Overloads the addition operator for scalar addition. | |
const Array | operator- (const float value, const Array &array) |
Overloads the subtraction operator for scalar subtraction. | |
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
hmap::Array::Array | ( | ) |
Constructs a new Array object.
shape | The shape of the array {ni, nj}. |
value | The initial value to fill the array with. |
Example #1
Example #2
hmap::Array::Array | ( | Vec2< int > | shape | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
hmap::Array::Array | ( | Vec2< int > | shape, |
float | value | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
hmap::Array::Array | ( | const std::string & | filename | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Array & hmap::Array::operator= | ( | const float | value | ) |
Array & hmap::Array::operator*= | ( | const float | value | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Array & hmap::Array::operator/= | ( | const float | value | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Array & hmap::Array::operator+= | ( | const float | value | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Array & hmap::Array::operator-= | ( | const float | value | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Array hmap::Array::operator* | ( | const float | value | ) | const |
Array hmap::Array::operator/ | ( | const float | value | ) | const |
Array hmap::Array::operator+ | ( | const float | value | ) | const |
Array hmap::Array::operator- | ( | ) | const |
Array hmap::Array::operator- | ( | const float | value | ) | const |
|
inline |
Overloads the function call operator to access the array value at index (i, j).
i | The row index. |
j | The column index. |
|
inline |
Overloads the function call operator to access the array value at index (i, j) (const version).
i | The row index. |
j | The column index. |
std::vector< float > hmap::Array::col_to_vector | ( | int | j | ) |
Extracts a column 'j' as a std::vector.
j | The column index. |
int hmap::Array::count_non_zero | ( | ) |
Return the number of non-zero elements in the array.
void hmap::Array::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, j + 1) by "reversing" the bilinear interpolation.
i | Index. |
j | Index. |
u | 'u' interpolation parameter, expected to be in [0, 1[. |
v | 'v' interpolation parameter, expected to be in [0, 1[. |
amount | Amount to be deposited. |
void hmap::Array::depose_amount_kernel_bilinear_at | ( | int | i, |
int | j, | ||
float | u, | ||
float | v, | ||
int | ir, | ||
float | amount | ||
) |
void hmap::Array::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 kernel applied in both horizontal and vertical directions.
i | Index of the cell in the array where the deposition starts. |
j | Index of the cell in the array where the deposition starts. |
kernel | 1D deposition kernel to be used for distribution. The kernel must contain an odd number of elements. |
amount | The amount of value to be distributed around the cell. |
void hmap::Array::dump | ( | const std::string & | fname = "out.png" | ) | const |
Debug tool, dump some infos and generate an output file (16bits grayscale)
Extracts a subarray defined by the slice indices {i1, i2, j1, j2} from the original array, creating a new array. Note that i2 and j2 are excluded from the slice.
idx | A Vec4<int> containing the slice extent indices {i1, i2, j1, j2}. |
Array hmap::Array::extract_slice | ( | int | i1, |
int | i2, | ||
int | j1, | ||
int | j2 | ||
) | const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void hmap::Array::from_file | ( | const std::string & | fname | ) |
Import array data from a raw binary file.
This function loads the array data from a binary file specified by
fname
. The file should contain raw binary data that corresponds to the internal representation of the array. The array's size and data type must match the expected format in the file.
fname | The name of the file to import data from. |
void hmap::Array::from_numpy | ( | const std::string & | fname | ) |
Import array data from a numpy binary file.
fname | The name of the file to import data from. |
Example
float hmap::Array::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 central difference scheme.
This function computes the gradient in the x-direction, which
measures the rate of change along the x-axis. Note that this function cannot be used at the borders of the data, as the central difference scheme requires values from both sides of the point of interest.
i | Index along the x-direction, expected to be in the range [1, shape.x - 2]. |
j | Index along the y-direction, expected to be in the range [1, shape.y - 2]. |
float hmap::Array::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 central difference scheme.
This function computes the gradient in the y-direction, which
measures the rate of change along the y-axis. Note that this function cannot be used at the borders of the data, as the central difference scheme requires values from both sides of the point of interest.
i | Index along the x-direction, expected to be in the range [1, shape.x - 2]. |
j | Index along the y-direction, expected to be in the range [1, shape.y - 2]. |
float hmap::Array::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, j) using bilinear interpolation.
This function uses bilinear interpolation to estimate the gradient
in the x-direction at a point within the cell defined by (i, j). The gradient is based on a 2nd order central difference scheme but interpolated to a finer resolution.
i | Index along the x-direction, expected to be in the range [1, shape.x - 2]. |
j | Index along the y-direction, expected to be in the range [1, shape.y - 2]. |
u | 'u' interpolation parameter, expected to be in the range [0, 1[. |
v | 'v' interpolation parameter, expected to be in the range [0, 1[. |
float hmap::Array::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, j) using bilinear interpolation.
This function uses bilinear interpolation to estimate the gradient
in the y-direction at a point within the cell defined by (i, j). The gradient is based on a 2nd order central difference scheme but interpolated to a finer resolution.
i | Index along the x-direction, expected to be in the range [1, shape.x - 2]. |
j | Index along the y-direction, expected to be in the range [1, shape.y - 2]. |
u | 'u' interpolation parameter, expected to be in the range [0, 1[. |
v | 'v' interpolation parameter, expected to be in the range [0, 1[. |
Vec3< float > hmap::Array::get_normal_at | ( | int | i, |
int | j | ||
) | const |
Calculates the surface normal vector at the index (i, j).
This function computes the surface normal at the specified index (i,
j) in the data array. The normal vector is a three-dimensional vector (x, y, z) that is perpendicular to the surface at that point.
i | Index along the x-direction. |
j | Index along the y-direction. |
Vec2< int > hmap::Array::get_shape | ( | ) |
Retrieves the shape of the array.
size_t hmap::Array::get_sizeof | ( | ) | const |
Retrieves the number of bytes occupied by the array data.
This function returns the total size in bytes of the underlying
storage vector that holds the array data. This can be useful for memory management or debugging purposes.
float hmap::Array::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.
This function uses bicubic interpolation to estimate the value at a
point within the cell defined by (i, j). Bicubic interpolation provides a smoother result compared to bilinear interpolation by taking into account the values of the surrounding 4x4 grid of points, resulting in better accuracy when interpolating in areas with gradients or curves.
i | Index along the x-direction, expected to be in the range [1, shape.x - 3]. |
j | Index along the y-direction, expected to be in the range [1, shape.y - 3]. |
u | 'u' interpolation parameter, expected to be in the range [0, 1[. |
v | 'v' interpolation parameter, expected to be in the range [0, 1[. |
float hmap::Array::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.
This function uses bilinear interpolation to estimate the value at a
point within the cell defined by (i, j). Bilinear interpolation is applied based on the surrounding values to approximate the value at the specified (x, y) location.
i | Index along the x-direction, expected to be in the range [0, shape.x - 2]. |
j | Index along the y-direction, expected to be in the range [0, shape.y - 2]. |
u | 'u' interpolation parameter, expected to be in the range [0, 1[. |
v | 'v' interpolation parameter, expected to be in the range [0, 1[. |
float hmap::Array::get_value_nearest | ( | float | x, |
float | y, | ||
Vec4< float > | bbox | ||
) |
Retrieves the nearest value at the location (x, y) within a bounded domain.
This function retrieves the nearest value to the specified (x, y)
coordinates from the array, assuming the array covers a domain defined by the bounding box bbox
. If the coordinates (x, y) are outside the domain, they are clamped to the nearest valid position within the bounding box.
x | Coordinate along the x-axis. |
y | Coordinate along the y-axis. |
bbox | Bounding box defining the domain of the array. It is expected to be in the form of {xmin, xmax, ymin, ymax}. |
std::vector< float > hmap::Array::get_vector | ( | ) | const |
Retrieves the underlying data vector.
void hmap::Array::infos | ( | std::string | msg = "" | ) | const |
Display various information about the array.
This function outputs details about the array, such as its
dimensions, data type, and any other relevant information. The optional msg
parameter can be used to include a custom message in the output.
msg | Optional message to include in the output. |
int hmap::Array::linear_index | ( | int | i, |
int | j | ||
) | const |
Return the linear index corresponding to the (i, j) cell in a 2D array.
This function calculates the linear index for a cell specified by
the (i, j) coordinates in a 2D array. The linear index is useful for accessing elements in a flattened or 1D representation of the array.
i | The 'i' index (row index). |
j | The 'j' index (column index). |
Vec2< int > hmap::Array::linear_index_reverse | ( | int | k | ) | const |
Convert a linear index to its corresponding (i, j) cell coordinates.
This function calculates the 2D cell coordinates (i, j) in the array
from a given linear index k
. This is useful for mapping between the 1D and 2D representations of the array.
k | The linear index. |
k
. float hmap::Array::max | ( | ) | const |
Return the value of the greatest element in the array.
This function computes the maximum value present in the array. If
the array is empty, the behavior of this function is undefined.
float hmap::Array::mean | ( | ) | const |
Return the mean value of the elements in the array.
This function calculates the average value of all elements in the
array. If the array is empty, the behavior of this function is undefined.
float hmap::Array::min | ( | ) | const |
Return the value of the smallest element in the array.
This function computes the minimum value present in the array. If
the array is empty, the behavior of this function is undefined.
void hmap::Array::normalize | ( | ) |
Normalize array values so that the sum of all elements is equal to 1.
This function adjusts the values in the array so that their total
sum is normalized to 1. This is often used in scenarios where the array represents a probability distribution.
Computes normalization coefficients (a, b) such that a * array + b maps the values to the range [vmin, vmax].
This function calculates the coefficients used to normalize the
array values so that they fit within the specified range [vmin, vmax]. The normalization is performed using the linear transformation: a * array + b
.
vmin | Lower bound of the desired range. |
vmax | Upper bound of the desired range. |
a
scales the values and b
shifts them. void hmap::Array::print | ( | ) | const |
Print the array values to the standard output (stdout).
This function prints the contents of the array in a human-readable
format to the standard output. This can be useful for debugging or inspecting the values of the array.
float hmap::Array::ptp | ( | ) | const |
Return the peak-to-peak amplitude (i.e., the difference between the maximum and minimum values) of the array values.
This function calculates the peak-to-peak amplitude of the array,
which is the difference between the maximum and minimum values in the array.
Return a resampled array of shape new_shape
using bilinear interpolation.
This function resamples the array to a new shape `new_shape` using
bilinear interpolation. The resampling changes the dimensions of the array while preserving the data's spatial relationships.
new_shape | The target shape for the resampled array. |
new_shape
.Example
Result
Return a resampled array of shape new_shape
using bicubic interpolation.
This function resamples the array to a new shape `new_shape` using
bicubic interpolation. The resampling changes the dimensions of the array while preserving the data's spatial relationships with a higher degree of smoothness compared to bilinear interpolation.
new_shape | The target shape for the resampled array. |
new_shape
.Example
Result
Return a resampled array of shape new_shape
using nearest neighbor interpolation.
This function resamples the array to a new shape `new_shape` using
nearest neighbor interpolation. This method selects the value from the nearest neighbor in the original array, which can be faster but may produce blocky artifacts compared to other interpolation methods.
new_shape | The target shape for the resampled array. |
new_shape
. std::vector< float > hmap::Array::row_to_vector | ( | int | i | ) |
Return a row i
as a std::vector<float>
.
This function extracts the specified row `i` from the array and
returns it as a std::vector<float>
. This is useful for operations where you need to work with individual rows outside of the array structure.
i | Row index to extract. |
void hmap::Array::set_shape | ( | Vec2< int > | new_shape | ) |
Sets a new shape for the array.
new_shape | The new shape of the array. |
void hmap::Array::set_slice | ( | Vec4< int > | idx, |
float | value | ||
) |
Set the value of a slice defined by indices {i1, i2, j1, j2} to a new value.
This function updates all elements within the specified slice of the
array to the given value
. The slice is defined by the extents {i1, i2, j1, j2}, where i1
and i2
specify the range for the rows, and j1
and j2
specify the range for the columns.
idx | Slice extent indices: {i1, i2, j1, j2}. |
value | The new value to set for the specified slice. |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
int hmap::Array::size | ( | ) | const |
Return the total number of elements in the array.
This function returns the size of the array, which is the total
number of elements it contains. This can be useful for iterating over the array or for checking its dimensions.
float hmap::Array::std | ( | ) | const |
Return the standard deviation of all array values.
float hmap::Array::sum | ( | ) | const |
Return the sum of all array values.
This function calculates and returns the sum of all elements in the
array. It can be used to obtain aggregate values or to check the overall magnitude of the array's contents.
cv::Mat hmap::Array::to_cv_mat | ( | ) |
Converts a 2D Array
to an OpenCV cv::Mat
.
This function converts a 2D Array
object into an OpenCV cv::Mat
. The conversion process does not involve copying the data; instead, it uses pointers to the original data in the Array
. As a result, any modifications to the Array
will directly affect the corresponding cv::Mat
and vice versa.
Array
object remains in scope and valid for the entire lifetime of the cv::Mat
. If the Array
is destroyed or goes out of scope, the cv::Mat
will reference invalid memory, which can lead to undefined behavior.cv::Mat
object that shares the data with the input Array
.Example
void hmap::Array::to_exr | ( | const std::string & | fname | ) | const |
Export the array as an OpenEXR image file.
This function saves the array data as an OpenEXR image file. OpenEXR
is a high dynamic range (HDR) image file format. The file will be created or overwritten with the name specified by fname
.
fname | The name of the OpenEXR file to be created or overwritten. |
Example
void hmap::Array::to_file | ( | const std::string & | fname | ) | const |
Export the array to a raw binary file.
This function writes the contents of the array to a file in raw
binary format. This can be useful for saving the array data to disk or for transferring it between programs. The file will be created or overwritten with the specified fname
.
fname | The name of the file to which the array data will be written. |
void hmap::Array::to_numpy | ( | const std::string & | fname | ) | const |
Export the array to a numpy binary file.
fname | The name of the file to which the array data will be written. |
Example
void hmap::Array::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.
This function saves the array data as a PNG image file. The colors
of the image are determined by the specified colormap (cmap
), and optional hillshading can be applied to enhance the visual representation of the data. The file will be created or overwritten with the name specified by fname
.
fname | The name of the PNG file to be created or overwritten. |
cmap | The colormap to be used for visualizing the data. Refer to cmap for available options. |
hillshading | Boolean flag to enable or disable hillshading. If true, hillshading will be applied. |
Example
void hmap::Array::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.
This function saves the array data as a grayscale PNG image file. The bit depth of the image is determined by the depth
parameter, allowing for either 8-bit (0-255) or 16-bit (0-65535) grayscale values. The resulting image will be created or overwritten with the name specified by fname
.
fname | The name of the PNG file to be created or overwritten. |
depth | The bit depth of the PNG image. Default is 8-bit (CV_8U). Use CV_16U for 16-bit depth if higher precision is needed. |
Example
void hmap::Array::to_tiff | ( | const std::string & | fname | ) | const |
Export the array as a TIFF image file.
This function saves the array data as a TIFF (Tagged Image File
Format) image file. The file will be created or overwritten with the name specified by fname
.
fname | The name of the TIFF file to be created or overwritten. |
Example
void hmap::Array::to_raw_16bit | ( | const std::string & | fname | ) | const |
Export the array as a 16-bit raw file for Unity terrain import.
This function saves the array data as a raw binary file with 16-bit
depth. The resulting file is suitable for use with Unity terrain import formats. The file will be created or overwritten with the name specified by fname
.
fname | The name of the raw file to be created or overwritten. |
Example
std::vector< float > hmap::Array::unique_values | ( | ) |
Return the unique elements of the array.
This function extracts and returns a vector containing all unique
values present in the array. The values are sorted in ascending order.
Vec2<int> hmap::Array::shape |
The shape of the array {ni, nj}.
std::vector<float> hmap::Array::vector |
The underlying data storage, a vector of size shape.x * shape.y.