Voxelyze
Public Member Functions
CArray3D< T > Class Template Reference

A generic 3D multi-size array template. More...

#include <Array3D.h>

List of all members.

Public Member Functions

 CArray3D ()
 Constructor.
 ~CArray3D (void)
 Destructor.
 CArray3D (const CArray3D &rArray)
 Copy constructor.
CArray3Doperator= (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.

Detailed Description

template<typename T = float>
class CArray3D< T >

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.


Member Function Documentation

template<typename T = float>
bool CArray3D< T >::addValue ( const Index3D index,
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.

Parameters:
[in]indexthe index to add this value at.
[in]valueThe value to add.
template<typename T = float>
bool CArray3D< T >::addValue ( int  i,
int  j,
int  k,
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.

Parameters:
[in]iThe i index to add this value at.
[in]jThe j index to add this value at.
[in]kThe k index to add this value at.
[in]valueThe value to add.
template<typename T = float>
const T& CArray3D< T >::at ( const Index3D i3D) const [inline]

Returns the value at the specified 3d index or the default value otherwise. Const version.

Parameters:
[in]i3Dthe 3D index (i,j,k) in question.
template<typename T = float>
const T& CArray3D< T >::at ( int  i,
int  j,
int  k 
) const [inline]

Returns the value at the specified 3d index or the default value otherwise. Const version.

Parameters:
[in]ithe i index in question.
[in]jthe j index in question.
[in]kthe k index in question.
template<typename T = float>
T& CArray3D< T >::at ( const Index3D i3D) [inline]

Returns the value at the specified 3d index or the default value otherwise.

Parameters:
[in]i3Dthe 3D index (i,j,k) in question.
template<typename T = float>
T& CArray3D< T >::at ( int  i,
int  j,
int  k 
) [inline]

Returns the value at the specified 3d index or the default value otherwise.

Parameters:
[in]ithe i index in question.
[in]jthe j index in question.
[in]kthe k index in question.
template<typename T = float>
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).

Parameters:
[in]indexthe index to remove a value from if it exists.
template<typename T = float>
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.

Parameters:
[in]iThe i index to remove a value from if it exists.
[in]jThe j index to remove a value from if it exists.
[in]kThe k index to remove a value from if it exists.
template<typename T = float>
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.

Parameters:
[in]newSizethe number of elements in i, j, and k to allocate
[in]newOffsetthe offset in i, j, and k of the allocated elements.
template<typename T = float>
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.

Parameters:
[in]iSizethe number of elements in i.
[in]jSizethe number of elements in j.
[in]kSizethe number of elements in k.
[in]iOffsetthe offset of allocated i elements.
[in]jOffsetthe offset of allocated j elements.
[in]kOffsetthe offset of allocated k elements.
template<typename T = float>
void CArray3D< T >::setDefaultValue ( newDefaultValue) [inline]

Sets the value to which all new allocations default to.

Parameters:
[in]newDefaultValuethe value returned from any index that has not been set otherwise.

The documentation for this class was generated from the following file:
 All Classes Functions Variables Enumerations Enumerator Friends