Field3D
Sparse::SparseBlock< Data_T > Class Template Reference

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. More...
 
void copy (const SparseBlock &other, size_t n)
 Copy data from another block. More...
 
void resize (int n)
 Alloc data. More...
 
 SparseBlock ()
 Ctor. More...
 
Data_T & value (int i, int j, int k, int blockOrder)
 Gets the value of a given voxel. More...
 
const Data_T & value (int i, int j, int k, int blockOrder) const
 Gets the const value of a given voxel. More...
 
 ~SparseBlock ()
 Dtor. More...
 

Public Attributes

Data_T * data
 Pointer to data. Null if block is unallocated. More...
 
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. More...
 
bool isAllocated
 Whether the block is allocated or not. More...
 

Private Member Functions

const SparseBlockoperator= (const SparseBlock &)
 Non-copyable. More...
 
 SparseBlock (const SparseBlock &)
 Non-copyable. More...
 

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. More...
 

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

template<typename Data_T>
Sparse::SparseBlock< Data_T >::SparseBlock ( )
inline

Ctor.

Definition at line 232 of file SparseField.h.

233  : isAllocated(false),
234  emptyValue(static_cast<Data_T>(0)),
235  data(NULL)
236  { /* Empty */ }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
Data_T emptyValue
The value to use if the block isn&#39;t allocated. We allow setting this per block so that we for example...
Definition: SparseField.h:308
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
template<typename Data_T>
Sparse::SparseBlock< Data_T >::~SparseBlock ( )
inline

Dtor.

Definition at line 239 of file SparseField.h.

240  {
241  if (data) {
242  delete[] data;
243  }
244  }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
template<typename Data_T>
Sparse::SparseBlock< Data_T >::SparseBlock ( const SparseBlock< Data_T > &  )
private

Non-copyable.

Member Function Documentation

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.

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().

251  { return data[(k << blockOrder << blockOrder) + (j << blockOrder) + i]; }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
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.

256  { return data[(k << blockOrder << blockOrder) + (j << blockOrder) + i]; }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
template<typename Data_T>
void Sparse::SparseBlock< Data_T >::resize ( int  n)
inline

Alloc data.

Definition at line 259 of file SparseField.h.

Referenced by SparseField< Data_T >::fastLValue(), and SparseFieldIO::readData().

260  {
261  // First hold lock
262  boost::mutex::scoped_lock lock(ms_resizeMutex);
263  // Perform work
264  if (data) {
265  delete[] data;
266  }
267  data = new Data_T[n];
268  isAllocated = true;
269  std::fill_n(data, n, emptyValue);
270  }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
Data_T emptyValue
The value to use if the block isn&#39;t allocated. We allow setting this per block so that we for example...
Definition: SparseField.h:308
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
static boost::mutex ms_resizeMutex
Prevents concurrent allocation of blocks. There should be little contention, and this prevents multip...
Definition: SparseField.h:325
template<typename Data_T>
void Sparse::SparseBlock< Data_T >::clear ( )
inline

Remove data.

Definition at line 273 of file SparseField.h.

Referenced by SparseField< Data_T >::copyBlockStates(), and SparseField< Data_T >::deallocBlock().

274  {
275  // First hold lock
276  boost::mutex::scoped_lock lock(ms_resizeMutex);
277  // Perform work
278  if (data) {
279  delete[] data;
280  data = NULL;
281  }
282  }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
static boost::mutex ms_resizeMutex
Prevents concurrent allocation of blocks. There should be little contention, and this prevents multip...
Definition: SparseField.h:325
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.

References Sparse::SparseBlock< Data_T >::data, and Sparse::SparseBlock< Data_T >::isAllocated.

Referenced by SparseField< Data_T >::copySparseField().

286  {
287  if (other.isAllocated) {
288  if (!data) {
289  resize(n);
290  }
291  Data_T *p = data, *end = data + n, *o = other.data;
292  while (p != end) {
293  *p++ = *o++;
294  }
295  } else {
296  clear();
297  }
298  }
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
void resize(int n)
Alloc data.
Definition: SparseField.h:259
void clear()
Remove data.
Definition: SparseField.h:273
template<typename Data_T>
const SparseBlock& Sparse::SparseBlock< Data_T >::operator= ( const SparseBlock< Data_T > &  )
private

Non-copyable.

Member Data Documentation

template<typename Data_T>
Data_T* Sparse::SparseBlock< Data_T >::data
template<typename Data_T>
boost::mutex Sparse::SparseBlock< Data_T >::ms_resizeMutex
staticprivate

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: