2022-04-20 03:05:34 +02:00
|
|
|
#ifndef FAST_WFC_UTILS_ARRAY3D_HPP_
|
|
|
|
#define FAST_WFC_UTILS_ARRAY3D_HPP_
|
|
|
|
|
2022-04-21 16:31:03 +02:00
|
|
|
#include "core/vector.h"
|
2022-04-20 03:05:34 +02:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Array3D {
|
|
|
|
public:
|
2022-04-21 16:36:33 +02:00
|
|
|
uint32_t height;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t depth;
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-21 16:31:03 +02:00
|
|
|
Vector<T> data;
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-21 23:31:25 +02:00
|
|
|
Array3D() {
|
|
|
|
height = 0;
|
|
|
|
width = 0;
|
|
|
|
depth = 0;
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:36:33 +02:00
|
|
|
Array3D(uint32_t p_height, uint32_t p_width, uint32_t p_depth) {
|
2022-04-20 03:24:50 +02:00
|
|
|
height = p_height;
|
|
|
|
width = p_width;
|
|
|
|
depth = p_depth;
|
|
|
|
data.resize(width * height * depth);
|
|
|
|
}
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-21 16:36:33 +02:00
|
|
|
Array3D(uint32_t p_height, uint32_t p_width, uint32_t p_depth, T value) {
|
2022-04-20 03:24:50 +02:00
|
|
|
height = p_height;
|
|
|
|
width = p_width;
|
|
|
|
depth = p_depth;
|
2022-04-21 16:31:03 +02:00
|
|
|
data.resize(width * height * depth);
|
|
|
|
data.fill(value);
|
2022-04-20 03:24:50 +02:00
|
|
|
}
|
2022-04-20 03:05:34 +02:00
|
|
|
|
2022-04-21 23:31:25 +02:00
|
|
|
void resize(uint32_t p_height, uint32_t p_width, uint32_t p_depth) {
|
|
|
|
height = p_height;
|
|
|
|
width = p_width;
|
|
|
|
depth = p_depth;
|
|
|
|
data.resize(width * height * depth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void resize_fill(uint32_t p_height, uint32_t p_width, uint32_t p_depth, T value) {
|
|
|
|
height = p_height;
|
|
|
|
width = p_width;
|
|
|
|
depth = p_depth;
|
|
|
|
data.resize(width * height * depth);
|
|
|
|
data.fill(value);
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:36:33 +02:00
|
|
|
const T &get(uint32_t i, uint32_t j, uint32_t k) const {
|
2022-04-21 16:51:10 +02:00
|
|
|
CRASH_BAD_INDEX(i, height);
|
|
|
|
CRASH_BAD_INDEX(j, width);
|
|
|
|
CRASH_BAD_INDEX(k, depth);
|
|
|
|
|
2022-04-20 03:05:34 +02:00
|
|
|
return data[i * width * depth + j * depth + k];
|
|
|
|
}
|
|
|
|
|
2022-04-21 16:36:33 +02:00
|
|
|
T &get(uint32_t i, uint32_t j, uint32_t k) {
|
2022-04-21 16:51:10 +02:00
|
|
|
CRASH_BAD_INDEX(i, height);
|
|
|
|
CRASH_BAD_INDEX(j, width);
|
|
|
|
CRASH_BAD_INDEX(k, depth);
|
|
|
|
|
2022-04-21 16:31:03 +02:00
|
|
|
return data.write[i * width * depth + j * depth + k];
|
2022-04-20 03:05:34 +02:00
|
|
|
}
|
|
|
|
|
2022-04-20 03:24:50 +02:00
|
|
|
bool operator==(const Array3D &a) const {
|
2022-04-20 03:05:34 +02:00
|
|
|
if (height != a.height || width != a.width || depth != a.depth) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-21 17:33:44 +02:00
|
|
|
for (int i = 0; i < data.size(); i++) {
|
2022-04-20 03:05:34 +02:00
|
|
|
if (a.data[i] != data[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // FAST_WFC_UTILS_ARRAY3D_HPP_
|