HighMap library (C++)
Loading...
Searching...
No Matches
tensor.hpp
Go to the documentation of this file.
1/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
2 Public License. The full license is in the file LICENSE, distributed with
3 this software. */
4
18#pragma once
19#include <opencv2/core/mat.hpp>
20
21#include "highmap/algebra.hpp"
22#include "highmap/array.hpp"
23
24namespace hmap
25{
26
36class Tensor
37{
38public:
43
47 std::vector<float> vector;
48
55
62 Tensor(Vec2<int> shape_xy, int shape_z);
63
69 Tensor(const std::string &fname);
70
79 float &operator()(int i, int j, int k);
80
89 const float &operator()(int i, int j, int k) const;
90
98 Array get_slice(int k) const;
99
105 float max() const;
106
112 float min() const;
113
120 void remap(float vmin = 0.f, float vmax = 1.f);
121
131
138 void set_slice(int k, const Array &slice);
139
145 cv::Mat to_cv_mat();
146
152 std::vector<uint8_t> to_img_8bit();
153
166 void to_png(const std::string &fname, int depth = CV_8U);
167};
168
169} // namespace hmap
Header file defining basic vector and matrix manipulation classes.
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
A class to represent a multi-dimensional tensor.
Definition tensor.hpp:37
void remap(float vmin=0.f, float vmax=1.f)
Remap the tensor values to a new range.
Definition tensor.cpp:84
float min() const
Find the minimum value in the tensor.
Definition tensor.cpp:79
Array get_slice(int k) const
Get a 2D slice of the tensor along the z-axis.
Definition tensor.cpp:63
float max() const
Find the maximum value in the tensor.
Definition tensor.cpp:74
Vec3< int > shape
Shape of the tensor in 3D space.
Definition tensor.hpp:42
float & operator()(int i, int j, int k)
Access an element of the tensor.
Definition tensor.cpp:53
std::vector< uint8_t > to_img_8bit()
Convert the tensor to an 8-bit image represented as a vector.
Definition tensor.cpp:149
void set_slice(int k, const Array &slice)
Set a 2D slice of the tensor along the z-axis.
Definition tensor.cpp:110
cv::Mat to_cv_mat()
Convert the tensor to an OpenCV matrix.
Definition tensor.cpp:119
std::vector< float > vector
Flattened vector containing the tensor's elements.
Definition tensor.hpp:47
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.
Definition tensor.cpp:97
void to_png(const std::string &fname, int depth=CV_8U)
Saves the Tensor as a PNG image file.
Definition tensor.cpp:140
Definition algebra.hpp:28
Vec2 class for basic manipulation of 2D vectors.
Definition algebra.hpp:40
Vec3 class for basic manipulation of 3D vectors.
Definition algebra.hpp:281