24 inline std::ostream&
operator<< (std::ostream &out,
const Data3D<T>& d);
34 void Initialize(
size_t new_d_size1,
size_t new_d_size2,
36 d_size1 = new_d_size1;
37 d_size2 = new_d_size2;
38 d_size3 = new_d_size3;
41 for (
size_t i=0; i<d_size3; i++) {
64 explicit Data3D(
size_t d_size1,
size_t d_size2,
size_t d_size3) {
65 Initialize(d_size1, d_size2, d_size3);
73 : d_size1 (copy.d_size1),
74 d_size2 (copy.d_size2),
75 d_size3 (copy.d_size3) {
85 d_size3(new_data.size()),
86 data(new_data.size()) {
87 std::copy(new_data.begin(), new_data.end(), data.Raw());
89 d_size2 = data[0].size2();
90 d_size1 = data[0].size1();
125 for (
size_t i=0; i<d_size3; i++) {
136 return ( (d_size1 == 0) || (d_size2 == 0) || (d_size3 == 0) );
145 if (
this != &other) {
146 d_size1 = other.d_size1;
147 d_size2 = other.d_size2;
148 d_size3 = other.d_size3;
181 return data[z][y][x];
184 inline const T&
operator() (
size_t x,
size_t y,
size_t z)
const {
185 return data[z][y][x];
188 inline T&
At(
size_t x,
size_t y,
size_t z) {
189 return data[z][y][x];
192 inline const T&
At(
size_t x,
size_t y,
size_t z)
const {
193 return data[z][y][x];
197 inline size_t size1()
const {
return d_size1; }
199 inline size_t size2()
const {
return d_size2; }
201 inline size_t size3()
const {
return d_size3; }
204 inline size_t TypeSize()
const {
return sizeof(T); }
212 for (y=0; y<d_size3; y++) {
224 inline bool Check(
const size_t x,
const size_t y,
const size_t z)
const {
225 if ( ! ((x < d_size1) && (y < d_size2) && (z < d_size3)) ) {
240 inline void Assert(
const size_t x,
const size_t y,
const size_t z)
const {
241 if ( !
Check(x, y, z) ) {
256 inline void Resize(
const size_t resize_size1,
257 const size_t resize_size2,
258 const size_t resize_size3) {
259 data.Resize(resize_size3);
260 for (
size_t i=0; i<resize_size2; i++) {
261 data[i].Resize(resize_size1, resize_size2);
263 d_size3 = resize_size3;
264 d_size2 = resize_size2;
265 d_size1 = resize_size1;
277 if (cptrs.size() != d_size3) {
278 cptrs.Resize(d_size3);
279 for (
size_t i=0; i<d_size3; i++) {
280 cptrs[i] = data[i].Raw();
305 for (
size_t z=0; z<d_size3; z++) {
306 for (
size_t y=0; y<d_size2; y++) {
307 for (
size_t x=0; x<d_size1; x++) {
320 for (
size_t z=0; z<d_size3; z++) {
321 for (
size_t y=0; y<d_size2; y++) {
322 for (
size_t x=0; x<d_size1; x++) {
355 swap(a.data, b.data);
369 if (d.
size3() == 0) {
370 out <<
"{ { { } } }";
374 for (i=1; i<d.size3(); i++) {
Provides a one-dimensional vector-like structure.
Provides a bounds-safe two-dimensional resizeable structure.
Provides informative exception handling.
#define Throw_RC_Type(Type, err)
Use this to throw an RC:ErrorMsg subtype exception.
Definition: Errors.h:282
A bounds-safe one-dimensional vector-like structure.
Definition: Data1D.h:49
A bounds-safe two-dimensional resizeable structure.
Definition: Data2D.h:32
A bounds-safe three-dimensional resizeable structure.
Definition: Data3D.h:31
bool IsEmpty() const
Definition: Data3D.h:135
void Clear()
Identical to Delete().
Definition: Data3D.h:112
Data1D< Data2D< T > > & RawData()
Const version of RawData().
Definition: Data3D.h:297
Data3D(const Data3D< T > ©)
Copy constructor that copies all elements.
Definition: Data3D.h:72
const T & At(size_t x, size_t y, size_t z) const
Const version of Data3D::operator()(size_t x, size_t y, size_t z))
Definition: Data3D.h:192
void Zero()
Sets all elements equal to 0.
Definition: Data3D.h:209
size_t size1() const
Get the size of dimension 1.
Definition: Data3D.h:197
Data3D(size_t d_size1, size_t d_size2, size_t d_size3)
Constructor which sets the initial sizes.
Definition: Data3D.h:64
void Resize(const size_t resize_size1, const size_t resize_size2, const size_t resize_size3)
Resize the array, reallocating if necessary.
Definition: Data3D.h:256
void Crop()
Reduces memory consumption to only that necessary for the current size.
Definition: Data3D.h:122
void ToLilEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data3D.h:303
~Data3D()
Deletes all contents upon destruction.
Definition: Data3D.h:96
Data3D()
Default constructor which initializes to size 0, 0, 0.
Definition: Data3D.h:50
bool Check(const size_t x, const size_t y, const size_t z) const
Check if the indices x, y, and z are in bounds.
Definition: Data3D.h:224
const Data1D< Data2D< T > > & RawData() const
Access the underlying nested Data1D/Data2D structure for this object.
Definition: Data3D.h:292
size_t size2() const
Get the size of dimension 2.
Definition: Data3D.h:199
void FromBigEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data3D.h:330
void Assert(const size_t x, const size_t y, const size_t z) const
Throw an ErrorMsgBounds exception if either x, y, or z is out of bounds.
Definition: Data3D.h:240
void ToBigEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data3D.h:318
Data3D & operator=(const Data3D &other)
Assignment operator which copies all contents from other.
Definition: Data3D.h:144
friend void swap(Data3D< T2 > &a, Data3D< T2 > &b)
Efficiently swap all the contents of a and b.
Definition: Data3D.h:351
Data2D< T > & operator[](size_t x)
Bounds-checked access of a Data2D corresponding to the data at index x in dimension 3.
Definition: Data3D.h:164
T & At(size_t x, size_t y, size_t z)
Equivalent to Data3D::operator()(size_t x, size_t y, size_t z)
Definition: Data3D.h:188
T *** Raw()
Access a raw unprotected 3-dimensional C-array for the enclosed data.
Definition: Data3D.h:276
void Delete()
Delete all the elements and free all allocated memory.
Definition: Data3D.h:102
size_t TypeSize() const
Returns sizeof(T).
Definition: Data3D.h:204
Data2D< T > & operator()(size_t x)
Identical to Data3D::operator[].
Definition: Data3D.h:166
size_t size3() const
Get the size of dimension 3.
Definition: Data3D.h:201
void FromLilEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data3D.h:315
Data3D(const std::initializer_list< Data2D< T >> &new_data)
Initializer list constructor, initializes with nested brackets.
Definition: Data3D.h:82
static bool IsLittle()
True if this system is little-endian.
Definition: Types.h:335
static bool IsBig()
True if this system is big-endian.
Definition: Types.h:341
static T ToBig(const T &x)
Converts x to big-endian.
Definition: Types.h:319
static T ToLittle(const T &x)
Converts x to little-endian.
Definition: Types.h:302
std::ostream & operator<<(std::ostream &out, APtr< T > obj)
A convenience stream output for displaying the enclosed object.
Definition: APtr.h:120
void swap(RC::Data1D< T > &a, RC::Data1D< T > &b)
Efficiently swap all the contents of a and b.
Definition: Data1D.h:1184
void swap(Data3D< T2 > &a, Data3D< T2 > &b)
Efficiently swap all the contents of a and b.
Definition: Data3D.h:351