14#include <opencv2/core.hpp>
26template <
typename DType>
42 std::size_t x, std::size_t y, std::size_t z,
bool zero =
true)
52 for (std::size_t i = 0; i <
dz_; ++i) {
56 for (std::size_t i = 0; i <
dz_; ++i) {
66 const DType&
operator()(std::size_t x, std::size_t y, std::size_t z)
const
68 assert(x < dx_ && x >= 0 &&
"index out of range");
69 assert(y < dy_ && y >= 0 &&
"index out of range");
70 assert(z < dz_ && z >= 0 &&
"index out of range");
75 DType&
operator()(std::size_t x, std::size_t y, std::size_t z)
77 assert(x < dx_ && x >= 0 &&
"index out of range");
78 assert(y < dy_ && y >= 0 &&
"index out of range");
79 assert(z < dz_ && z >= 0 &&
"index out of range");
86 std::size_t
dx() {
return dx_; }
89 std::size_t
dx()
const {
return dx_; }
92 std::size_t
dy() {
return dy_; }
95 std::size_t
dy()
const {
return dy_; }
98 std::size_t
dz() {
return dz_; }
101 std::size_t
dz()
const {
return dz_; }
114 cv::Mat_<DType> zSlice(
dz_,
dx_);
115 for (std::size_t z = 0; z <
dz_; ++z) {
116 tensor_[z].row(y).copyTo(zSlice.row(z));
126 auto buf = std::make_unique<DType[]>(
dx_ *
dy_ *
dz_);
127 for (std::size_t z = 0; z <
dz_; ++z) {
128 for (std::size_t y = 0; y <
dy_; ++y) {
129 for (std::size_t x = 0; x <
dx_; ++x) {
154template <
typename DType>
158 for (std::size_t z = 0; z < tensor.
dz_; ++z) {
159 s << tensor.
xySlice(z) << std::endl;
A 3rd-order tensor object.
std::size_t dx()
Get the size of the X-axis.
DType & operator()(std::size_t x, std::size_t y, std::size_t z)
Get the tensor value at x, y, z.
cv::Mat_< DType > xzSlice(std::size_t y) const
Get an XZ cross section of the Tensor at y.
std::size_t dz() const
Get the size of the Z-axis.
std::ostream & operator<<(std::ostream &s, const volcart::Tensor3D< DType > &tensor)
Write a Tensor3D to an output stream.
std::vector< cv::Mat_< DType > > tensor_
std::size_t dz()
Get the size of the Z-axis.
cv::Mat_< DType > & xySlice(std::size_t z)
Get an XY cross section of the Tensor at z.
const DType & operator()(std::size_t x, std::size_t y, std::size_t z) const
Get the tensor value at x, y, z.
std::size_t dy() const
Get the size of the Y-axis.
std::unique_ptr< DType[]> buffer() const
Get a copy of the Tensor as a raw array.
const cv::Mat_< DType > & xySlice(std::size_t z) const
Get an XY cross section of the Tensor at z.
std::size_t dy()
Get the size of the Y-axis.
std::size_t dx() const
Get the size of the X-axis.
Volume Cartographer library