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.
 
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 SparseBlockoperator= (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 79 of file SparseFile.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 */ }
bool isAllocated
Whether the block is allocated or not.
Data_T emptyValue
The value to use if the block isn't allocated. We allow setting this per block so that we for example...
Data_T * data
Pointer to data. Null if block is unallocated.

◆ ~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 }
static boost::mutex ms_resizeMutex
Prevents concurrent allocation of blocks. There should be little contention, and this prevents multip...

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 }
void resize(int n)
Alloc data.
void clear()
Remove data.

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 files: