Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Array3D.hpp
1// INFINITY_API_PUBLIC
2
3#pragma once
4
5#include <Infinity/Types/Containers/Array.hpp>
6#include <Infinity/Types/Math/Vector2.hpp>
7#include <Infinity/Types/Math/Vector3.hpp>
8#include <Infinity/Types/Math/Vector4.hpp>
9
10#include <vector>
11#include <cassert>
12
13namespace Infinity::IO::Data
14{
16 template<typename T>
17 class Array3DSerializer;
19}
20
22{
23
89 template<typename T>
90 class INFINITY_API_TEMPLATE Array3D : public Array<T>
91 {
92 public:
98 Array3D() : Array<T>(), _width(0), _height(0), _depth(0) { }
99
112 Array3D(size_t width, size_t height, size_t depth) : Array<T>(width * height * depth), _width(width), _height(height), _depth(depth) { }
113
126 Array3D(size_t width, size_t height, size_t depth, Array<T> data) : Array<T>(data), _width(width), _height(height), _depth(depth) { }
127
138 Array3D(size_t width, size_t height, size_t depth, T* data) : Array<T>(data, width * height * depth), _width(width), _height(height), _depth(depth) { }
139
153 Array3D(size_t width, size_t height, size_t depth, const std::vector<T>& data) : Array<T>(data), _width(width), _height(height), _depth(depth) { }
154
160 virtual ~Array3D() { }
161
162 std::unique_ptr<Core::Base> clone() const override
163 {
164 return std::make_unique<Array3D<T>>(*this);
165 }
166
172 const Infinity::Types::TypeID& typeId() const override { return Infinity::Types::getTypeID<Array3D<T>>(); }
173
179 inline size_t width() const noexcept
180 {
181 return _width;
182 }
183
189 inline size_t height() const noexcept
190 {
191 return _height;
192 }
193
199 inline size_t depth() const noexcept
200 {
201 return _depth;
202 }
203
204 using Array<T>::at;
205
220 T& at(size_t x, size_t y, size_t z)
221 {
222 return at((z * _width * _height) + (y * _width) + x);
223 }
224
239 const T& at(size_t x, size_t y, size_t z) const
240 {
241 return at((z * _width * _height) + (y * _width) + x);
242 }
243
249 virtual size_t dimensions() const noexcept override
250 {
251 return 3;
252 }
253
268 void resize(size_t width, size_t height, size_t depth)
269 {
270 size_t newSize = width * height * depth;
271
272 if (newSize == Array<T>::size())
273 {
274 _width = width;
275 _height = height;
276 _depth = depth;
277 return;
278 }
279
280 Array<T>::resize(newSize);
281
282 _width = width;
283 _height = height;
284 _depth = depth;
285 }
286
287 protected:
288 using Array<T>::resize;
289
290 private:
291 size_t _width;
292 size_t _height;
293 size_t _depth;
294
295 friend class Infinity::IO::Data::Array3DSerializer<T>;
296 };
297
310}
311
312// Type registration for common scalar specializations
323
324// Type registration for Vector2 specializations
328
329// Type registration for Vector2d (double) specializations
333
334// Type registration for Vector2b (int8_t) specializations
338
339// Type registration for Vector2s (int16_t) specializations
343
344// Type registration for Vector2i (int32_t) specializations
348
349// Type registration for Vector2l (int64_t) specializations
353
354// Type registration for Vector2ub (uint8_t) specializations
358
359// Type registration for Vector2us (uint16_t) specializations
363
364// Type registration for Vector2ui (uint32_t) specializations
368
369// Type registration for Vector2ul (uint64_t) specializations
373
374// Type registration for common 3D texture array types (arrays of 3D textures)
376INFINITY_TYPE(Infinity::Types::Containers::Array<Infinity::Types::Containers::Array3D<int8_t>>)
377INFINITY_TYPE(Infinity::Types::Containers::Array<Infinity::Types::Containers::Array3D<float>>)
378INFINITY_TYPE(Infinity::Types::Containers::Array<Infinity::Types::Containers::Array3D<Infinity::Types::Math::Vector4ub>>)
Three-dimensional array container for volumetric data in procedural generation.
Definition Array3D.hpp:91
Array3D(size_t width, size_t height, size_t depth, T *data)
Constructs a 3D array by copying from a raw data pointer.
Definition Array3D.hpp:138
virtual size_t dimensions() const noexcept override
Gets the number of dimensions in this container.
Definition Array3D.hpp:249
const Infinity::Types::TypeID & typeId() const override
Gets the TypeID for this Array3D type.
Definition Array3D.hpp:172
Array3D(size_t width, size_t height, size_t depth, const std::vector< T > &data)
Constructs a 3D array from a std::vector with specified dimensions.
Definition Array3D.hpp:153
Array3D(size_t width, size_t height, size_t depth)
Constructs a 3D array with specified dimensions.
Definition Array3D.hpp:112
size_t width() const noexcept
Gets the width (number of columns, X dimension) of the 3D array.
Definition Array3D.hpp:179
size_t height() const noexcept
Gets the height (number of rows, Y dimension) of the 3D array.
Definition Array3D.hpp:189
std::unique_ptr< Core::Base > clone() const override
Definition Array3D.hpp:162
void resize(size_t width, size_t height, size_t depth)
Resizes the 3D array to new dimensions.
Definition Array3D.hpp:268
size_t depth() const noexcept
Gets the depth (number of layers, Z dimension) of the 3D array.
Definition Array3D.hpp:199
Array3D()
Default constructor.
Definition Array3D.hpp:98
T & at(size_t x, size_t y, size_t z)
Accesses element at 3D coordinates.
Definition Array3D.hpp:220
const T & at(size_t x, size_t y, size_t z) const
Accesses element at 3D coordinates (const).
Definition Array3D.hpp:239
virtual ~Array3D()
Destructor.
Definition Array3D.hpp:160
Array3D(size_t width, size_t height, size_t depth, Array< T > data)
Constructs a 3D array from existing Array data with specified dimensions.
Definition Array3D.hpp:126
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
Definition Array.hpp:17
Definition Array.hpp:25
Definition Asset.hpp:11
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71