Field3D
Sparse::SparseBlock< Data_T > Class Template Reference

#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

◆ SparseBlock() [1/2]

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 */ }

◆ ~SparseBlock()

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  }

References Sparse::SparseBlock< Data_T >::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.

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

References Sparse::SparseBlock< Data_T >::data.

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.

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

References Sparse::SparseBlock< Data_T >::data.

◆ resize()

template<typename Data_T>
void Sparse::SparseBlock< Data_T >::resize ( int  n)
inline

Alloc data.

Definition at line 259 of file SparseField.h.

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  }

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

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.

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  }

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

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.

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  }

References Sparse::SparseBlock< Data_T >::clear(), Sparse::SparseBlock< Data_T >::data, Sparse::SparseBlock< Data_T >::isAllocated, and Sparse::SparseBlock< Data_T >::resize().

◆ operator=()

template<typename Data_T>
const SparseBlock& Sparse::SparseBlock< Data_T >::operator= ( const SparseBlock< Data_T > &  )
private

Non-copyable.

Member Data Documentation

◆ isAllocated

◆ emptyValue

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

◆ data

◆ ms_resizeMutex

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.

Referenced by Sparse::SparseBlock< Data_T >::clear(), and Sparse::SparseBlock< Data_T >::resize().


The documentation for this class was generated from the following file:
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::clear
void clear()
Remove data.
Definition: SparseField.h:273
Sparse::SparseBlock::resize
void resize(int n)
Alloc data.
Definition: SparseField.h:259
Sparse::SparseBlock::isAllocated
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
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
Sparse::SparseBlock::data
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311