|
HighMap library (C++)
|
A class to represent a multi-dimensional tensor. More...
#include <tensor.hpp>

Public Member Functions | |
| Tensor (Vec3< int > shape) | |
| Construct a new Tensor object. | |
| Tensor (Vec2< int > shape_xy, int shape_z) | |
| Construct a new Tensor object. | |
| Tensor (const std::string &fname, bool flip_j=false) | |
| Constructs a new Tensor object from a file. | |
| float & | operator() (int i, int j, int k) |
| Access an element of the tensor. | |
| const float & | operator() (int i, int j, int k) const |
| Access an element of the tensor (const version). | |
| Array | get_slice (int k) const |
| Get a 2D slice of the tensor along the z-axis. | |
| float | max () const |
| Find the maximum value in the tensor. | |
| float | min () const |
| Find the minimum value in the tensor. | |
| void | remap (float vmin=0.f, float vmax=1.f) |
| Remap the tensor values to a new range. | |
| Tensor | resample_to_shape_xy (Vec2< int > new_shape_xy) |
| Resamples the tensor to a new 2D shape (x, y), shape along z is not changed. | |
| void | set_slice (int k, const Array &slice) |
| Set a 2D slice of the tensor along the z-axis. | |
| cv::Mat | to_cv_mat () |
| Convert the tensor to an OpenCV matrix. | |
| std::vector< uint8_t > | to_img_8bit () |
| Convert the tensor to an 8-bit image represented as a vector. | |
| void | to_png (const std::string &fname, int depth=CV_8U) |
| Saves the Tensor as a PNG image file. | |
Public Attributes | |
| Vec3< int > | shape |
| Shape of the tensor in 3D space. | |
| std::vector< float > | vector |
| Flattened vector containing the tensor's elements. | |
A class to represent a multi-dimensional tensor.
The Tensor class is used to store and manipulate multi-dimensional arrays (tensors) of floating-point numbers. It supports element access, basic operations such as finding the minimum and maximum values, remapping the tensor values, and exporting the data to images.
Construct a new Tensor object.
| shape | 3D shape of the tensor. |
Construct a new Tensor object.
| shape_xy | 2D shape (x, y) of the tensor. |
| shape_z | Size along the z-axis. |
Constructs a new Tensor object from a file.
| fname | The name of the file to load the tensor from. |
| float & hmap::Tensor::operator() | ( | int | i, |
| int | j, | ||
| int | k | ||
| ) |
Access an element of the tensor.
| i | Index along the x-axis. |
| j | Index along the y-axis. |
| k | Index along the z-axis. |
Access an element of the tensor (const version).
<This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| i | Index along the x-axis. |
| j | Index along the y-axis. |
| k | Index along the z-axis. |
Get a 2D slice of the tensor along the z-axis.
| k | Index along the z-axis. |
| float hmap::Tensor::max | ( | ) | const |
Find the maximum value in the tensor.
| float hmap::Tensor::min | ( | ) | const |
Find the minimum value in the tensor.
Remap the tensor values to a new range.
| vmin | Minimum value of the new range (default is 0.0). |
| vmax | Maximum value of the new range (default is 1.0). |
Resamples the tensor to a new 2D shape (x, y), shape along z is not changed.
| new_shape_xy | A 2D vector representing the new shape (x, y) of the tensor. |
Set a 2D slice of the tensor along the z-axis.
| k | Index along the z-axis. |
| slice | The 2D array (slice) to set. |
| cv::Mat hmap::Tensor::to_cv_mat | ( | ) |
Convert the tensor to an OpenCV matrix.
| std::vector< uint8_t > hmap::Tensor::to_img_8bit | ( | ) |
Convert the tensor to an 8-bit image represented as a vector.
Saves the Tensor as a PNG image file.
This function converts the Tensor into a cv::Mat object and then saves it as a PNG image file. The image can be saved in either 8-bit or 16-bit depth, based on the depth parameter. The image is rotated 90 degrees counterclockwise before saving.
| fname | The filename for the output PNG image, including the path. |
| depth | The bit depth of the output image. The default is 8-bit (CV_8U). Set to CV_16U for 16-bit output. |
| std::vector<float> hmap::Tensor::vector |
Flattened vector containing the tensor's elements.