Sparse::SparseBlock< Data_T > Class Template Reference
Classes and functions used to implement this library » Field classes under-the-hood

Storage for one individual block of a SparseField. More...

`#include <SparseField.h>`

Inheritance diagram for Sparse::SparseBlock< Data_T >:

## Public Member Functions

void | clear ()
| Remove data.
void | copy (const SparseBlock &other, size_t n)
| Copy data from another block.
void | resize (int n)
| Alloc data.
| SparseBlock ()
| Ctor.
Data_T & | value (int i, int j, int k, int blockOrder)
| Gets the value of a given voxel.
const Data_T & | value (int i, int j, int k, int blockOrder) const
| Gets the const value of a given voxel.
| ~SparseBlock ()
| Dtor.

## Public Attributes

Data_T * | data
| Pointer to data. Null if block is unallocated.
Data_T | emptyValue
| The value to use if the block isn't allocated. We allow setting this per block so that we for example can have different inside/outside values when storing narrow-band levelsets.
bool | isAllocated
| Whether the block is allocated or not.

## Private Member Functions

const SparseBlock & | operator= (const SparseBlock &)
| Non-copyable.
| SparseBlock (const SparseBlock &)
| Non-copyable.

## Static Private Attributes

static boost::mutex | ms_resizeMutex
| Prevents concurrent allocation of blocks. There should be little contention, and this prevents multiple threads from trying to allocate the same field.

## Detailed Description

template<typename Data_T>
class Sparse::SparseBlock< Data_T >

Storage for one individual block of a SparseField.

Definition at line 227 of file SparseField.h.

## Constructor & Destructor Documentation

## SparseBlock() [1/2]

template<typename Data_T>

Sparse::SparseBlock< Data_T >::SparseBlock | ( |  | ) |

inline

Ctor.

Definition at line 232 of file SparseField.h.

: isAllocated(false),
emptyValue(static_cast<Data_T>(0)),
data(NULL)
{ /* Empty */ }
Sparse::SparseBlock
Storage for one individual block of a SparseField.
Definition SparseField.h:228
Sparse::SparseBlock::isAllocated
bool isAllocated
Whether the block is allocated or not.
Definition SparseField.h:303
Sparse::SparseBlock::emptyValue
Data_T emptyValue
The value to use if the block isn't allocated. We allow setting this per block so that we for example...
Definition SparseField.h:308
Sparse::SparseBlock::data
Data_T * data
Pointer to data. Null if block is unallocated.
Definition SparseField.h:311

## ~SparseBlock()

template<typename Data_T>

Sparse::SparseBlock< Data_T >::~SparseBlock | ( |  | ) |

inline

Dtor.

Definition at line 239 of file SparseField.h.

{
if (data) {
delete[] data;
}
}

## SparseBlock() [2/2]

template<typename Data_T>

Sparse::SparseBlock< Data_T >::SparseBlock | ( | const SparseBlock< Data_T > & |  | ) |

private

Non-copyable.

## Member Function Documentation

## value() [1/2]

template<typename Data_T>

Data_T & Sparse::SparseBlock< Data_T >::value | ( | int | i,
|  | int | j,
|  | int | k,
|  | int | blockOrder )

inline

Gets the value of a given voxel.

Note
  Bit shift should be ok, indices are always positive.

Definition at line 249 of file SparseField.h.

{ return data[(k << blockOrder << blockOrder) + (j << blockOrder) + i]; }

Referenced by SparseField< Data_T >::fastLValue(), SparseField< Data_T >::fastValue(), SparseField< Data_T >::const_iterator::operator*(), SparseField< Data_T >::const_iterator::operator->(), SparseField< Data_T >::const_iterator::setupNextBlock(), and SparseField< Data_T >::iterator::setupNextBlock().

## value() [2/2]

template<typename Data_T>

const Data_T & Sparse::SparseBlock< Data_T >::value | ( | int | i,
|  | int | j,
|  | int | k,
|  | int | blockOrder ) const

inline

Gets the const value of a given voxel.

Note
  Bit shift should be ok, indices are always positive.

Definition at line 255 of file SparseField.h.

{ return data[(k << blockOrder << blockOrder) + (j << blockOrder) + i]; }

## resize()

template<typename Data_T>

void Sparse::SparseBlock< Data_T >::resize | ( | int | n | ) |

inline

Alloc data.

Definition at line 259 of file SparseField.h.

{
// First hold lock
boost::mutex::scoped_lock lock(ms_resizeMutex);
// Perform work
if (data) {
delete[] data;
}
data = new Data_T[n];
isAllocated = true;
std::fill_n(data, n, emptyValue);
}
Sparse::SparseBlock::ms_resizeMutex
static boost::mutex ms_resizeMutex
Prevents concurrent allocation of blocks. There should be little contention, and this prevents multip...
Definition SparseField.h:325

Referenced by Sparse::SparseBlock< Data_T > *::copy(), and SparseField< Data_T >::fastLValue().

## clear()

template<typename Data_T>

void Sparse::SparseBlock< Data_T >::clear | ( |  | ) |

inline

Remove data.

Definition at line 273 of file SparseField.h.

{
// First hold lock
boost::mutex::scoped_lock lock(ms_resizeMutex);
// Perform work
if (data) {
delete[] data;
data = NULL;
}
}

Referenced by Sparse::SparseBlock< Data_T > *::copy(), and SparseField< Data_T >::deallocBlock().

## copy()

template<typename Data_T>

void Sparse::SparseBlock< Data_T >::copy | ( | const SparseBlock< Data_T > & | other,
|  | size_t | n )

inline

Copy data from another block.

Definition at line 285 of file SparseField.h.

{
if (other.isAllocated) {
if (!data) {
resize(n);
}
Data_T *p = data, *end = data + n, *o = other.data;
while (p != end) {
*p++ = *o++;
}
} else {
clear();
}
}
Sparse::SparseBlock::resize
void resize(int n)
Alloc data.
Definition SparseField.h:259
Sparse::SparseBlock::clear
void clear()
Remove data.
Definition SparseField.h:273

## operator=()

template<typename Data_T>

const SparseBlock & Sparse::SparseBlock< Data_T >::operator= | ( | const SparseBlock< Data_T > & |  | ) |

private

Non-copyable.

## Member Data Documentation

## isAllocated

template<typename Data_T>

bool Sparse::SparseBlock< Data_T >::isAllocated

Whether the block is allocated or not.

Definition at line 303 of file SparseField.h.

Referenced by SparseField< Data_T >::blockData(), SparseField< Data_T >::blockIsAllocated(), Sparse::SparseBlock< Data_T > *::copy(), SparseField< Data_T >::copyBlockStates(), SparseField< Data_T >::copySparseField(), SparseField< Data_T >::deallocBlock(), SparseField< Data_T >::fastLValue(), SparseField< Data_T >::fastValue(), SparseField< Data_T >::setBlockEmptyValue(), SparseField< Data_T >::const_iterator::setupNextBlock(), and SparseField< Data_T >::iterator::setupNextBlock().

## emptyValue

template<typename Data_T>

Data_T Sparse::SparseBlock< Data_T >::emptyValue

The value to use if the block isn't allocated. We allow setting this per block so that we for example can have different inside/outside values when storing narrow-band levelsets.

Definition at line 308 of file SparseField.h.

Referenced by SparseField< Data_T >::clear(), SparseField< Data_T >::copyBlockStates(), SparseField< Data_T >::copySparseField(), SparseField< Data_T >::deallocBlock(), SparseField< Data_T >::fastValue(), SparseField< Data_T >::setBlockEmptyValue(), SparseField< Data_T >::const_iterator::setupNextBlock(), and SparseField< Data_T >::iterator::setupNextBlock().

## data

template<typename Data_T>

Data_T* Sparse::SparseBlock< Data_T >::data

Pointer to data. Null if block is unallocated.

Definition at line 311 of file SparseField.h.

Referenced by SparseField< Data_T >::blockData(), Sparse::CheckAllEqual< Data_T >::check(), Sparse::CheckMaxAbs< Data_T >::check(), and Sparse::SparseBlock< Data_T > *::copy().

## ms_resizeMutex

template<typename Data_T>

boost::mutex Sparse::SparseBlock< Data_T >::ms_resizeMutex

static private

Prevents concurrent allocation of blocks. There should be little contention, and this prevents multiple threads from trying to allocate the same field.

Definition at line 325 of file SparseField.h.

The documentation for this class was generated from the following file:

- export/SparseField.h