Voxelyze
|
A generic 3D multi-size array template. More...
#include <Array3D.h>
Public Member Functions | |
CArray3D () | |
Constructor. | |
~CArray3D (void) | |
Destructor. | |
CArray3D (const CArray3D &rArray) | |
Copy constructor. | |
CArray3D & | operator= (const CArray3D &rArray) |
Operator "=" overload. | |
const T & | operator[] (const Index3D i3D) const |
Operator "[]" overload (takes an Index3D) const version. | |
T & | operator[] (const Index3D i3D) |
Operator "[]" overload (takes an Index3D) | |
const T & | operator() (int i, int j, int k) const |
Operator "()" overloads (takes individual x, y, z indices) const verison. | |
T & | operator() (int i, int j, int k) |
Operator "()" overloads (takes individual x, y, z indices) | |
void | clear () |
Clears all data from the array and frees up all memory. | |
void | setDefaultValue (T newDefaultValue) |
Sets the value to which all new allocations default to. | |
Index3D | minIndices () const |
Returns the minimum i, j, and k indices utilized by any element in the array. | |
Index3D | maxIndices () const |
Returns the maximum i, j, and k indices utilized by any element in the array. | |
const T & | at (const Index3D &i3D) const |
Returns the value at the specified 3d index or the default value otherwise. Const version. | |
const T & | at (int i, int j, int k) const |
Returns the value at the specified 3d index or the default value otherwise. Const version. | |
T & | at (const Index3D &i3D) |
Returns the value at the specified 3d index or the default value otherwise. | |
T & | at (int i, int j, int k) |
Returns the value at the specified 3d index or the default value otherwise. | |
bool | resize (const Index3D &newSize, const Index3D &newOffset=Index3D(0, 0, 0)) |
Resize the internal data allocation to new specified size and offset. Any data ouside the new range is discarded. The range of allocated values in a given dimension spans from newOffset to newOffset+newsize. | |
bool | resize (int iSize, int jSize, int kSize, int iOffset=0, int jOffset=0, int kOffset=0) |
Resize the internal data allocation to new specified sizes and offsets in i j and k. Any data ouside the new range is discarded. The range of allocated values in a given dimension spans from iOffset to iOffset+iSize (and the same for j and k. | |
bool | shrink_to_fit () |
Deallocates as much memory as possible by reducing the allocated area to minimum span of existing elements. | |
bool | addValue (const Index3D &index, T value) |
Adds a value to the array or overwrites what was there. Allocates more space if needed in a (semi smart) manner. Use removeValue to remove it. | |
bool | addValue (int i, int j, int k, T value) |
Adds a value to the array or overwrites what was there. Allocates more space if needed in a (semi smart) manner. Use removeValue to remove it. | |
void | removeValue (const Index3D &index) |
Removes any value at the specified index and returns its value to the default value. Never triggers a reallocation - use shrink_to_fit() to try to reduce the memory usage after removing element(s). | |
void | removeValue (int i, int j, int k) |
Removes any value at the specified index and returns its value to the default value. Never triggers a reallocation - use shrink_to_fit() to try to reduce the memory usage after removing element(s). Use removeValue to remove it. |
A generic 3D multi-size array template.
An array template with a user-definable default value that is returned for any 3D index not specified otherwise. Otherwise the functions will be generally familiar to anyone used to the standard library containers.
There are three dimensions of indices, referred to i, j, and k. In many uses these will be synonomous with x, y, and z.
Memory allocation is managed internally and totally abstracted from the user. Whenever addvalue is called the internal array is smartly resized if the index falls outside of the currently allocated area. If the dimensions are known in advance, resize() may be called once to reduce costly memory reallocations.
The value of an element can be accesed with [], (), or at(). Empty elements (or elements outside the allocated area) are synonomous with the element being defaultValue.
bool CArray3D< T >::addValue | ( | const Index3D & | index, |
T | value | ||
) | [inline] |
Adds a value to the array or overwrites what was there. Allocates more space if needed in a (semi smart) manner. Use removeValue to remove it.
[in] | index | the index to add this value at. |
[in] | value | The value to add. |
Adds a value to the array or overwrites what was there. Allocates more space if needed in a (semi smart) manner. Use removeValue to remove it.
[in] | i | The i index to add this value at. |
[in] | j | The j index to add this value at. |
[in] | k | The k index to add this value at. |
[in] | value | The value to add. |
Returns the value at the specified 3d index or the default value otherwise. Const version.
[in] | i3D | the 3D index (i,j,k) in question. |
Returns the value at the specified 3d index or the default value otherwise. Const version.
[in] | i | the i index in question. |
[in] | j | the j index in question. |
[in] | k | the k index in question. |
Returns the value at the specified 3d index or the default value otherwise.
[in] | i3D | the 3D index (i,j,k) in question. |
Returns the value at the specified 3d index or the default value otherwise.
[in] | i | the i index in question. |
[in] | j | the j index in question. |
[in] | k | the k index in question. |
void CArray3D< T >::removeValue | ( | const Index3D & | index | ) | [inline] |
Removes any value at the specified index and returns its value to the default value. Never triggers a reallocation - use shrink_to_fit() to try to reduce the memory usage after removing element(s).
[in] | index | the index to remove a value from if it exists. |
void CArray3D< T >::removeValue | ( | int | i, |
int | j, | ||
int | k | ||
) | [inline] |
Removes any value at the specified index and returns its value to the default value. Never triggers a reallocation - use shrink_to_fit() to try to reduce the memory usage after removing element(s). Use removeValue to remove it.
[in] | i | The i index to remove a value from if it exists. |
[in] | j | The j index to remove a value from if it exists. |
[in] | k | The k index to remove a value from if it exists. |
bool CArray3D< T >::resize | ( | const Index3D & | newSize, |
const Index3D & | newOffset = Index3D(0,0,0) |
||
) | [inline] |
Resize the internal data allocation to new specified size and offset. Any data ouside the new range is discarded. The range of allocated values in a given dimension spans from newOffset to newOffset+newsize.
[in] | newSize | the number of elements in i, j, and k to allocate |
[in] | newOffset | the offset in i, j, and k of the allocated elements. |
bool CArray3D< T >::resize | ( | int | iSize, |
int | jSize, | ||
int | kSize, | ||
int | iOffset = 0 , |
||
int | jOffset = 0 , |
||
int | kOffset = 0 |
||
) | [inline] |
Resize the internal data allocation to new specified sizes and offsets in i j and k. Any data ouside the new range is discarded. The range of allocated values in a given dimension spans from iOffset to iOffset+iSize (and the same for j and k.
[in] | iSize | the number of elements in i. |
[in] | jSize | the number of elements in j. |
[in] | kSize | the number of elements in k. |
[in] | iOffset | the offset of allocated i elements. |
[in] | jOffset | the offset of allocated j elements. |
[in] | kOffset | the offset of allocated k elements. |
void CArray3D< T >::setDefaultValue | ( | T | newDefaultValue | ) | [inline] |
Sets the value to which all new allocations default to.
[in] | newDefaultValue | the value returned from any index that has not been set otherwise. |