SparseField< Data_T > Class Template Reference
Fields

This Field subclass stores voxel data in block-allocated arrays. More...

`#include <SparseField.h>`

Inheritance diagram for SparseField< Data_T >:

## Classes

class | block_iterator
class | const_iterator
class | iterator

## Public Types

typedef SparseField< Data_T > | class_type
typedef CubicGenericFieldInterp< SparseField< Data_T > > | CubicInterp
typedef LinearSparseFieldInterp< Data_T > | LinearInterp
typedef boost::intrusive_ptr< SparseField > | Ptr
typedef std::vector< Ptr > | Vec
Public Types inherited from ResizableField< Data_T >
typedef ResizableField< Data_T > | class_type
typedef boost::intrusive_ptr< ResizableField > | Ptr
Public Types inherited from WritableField< Data_T >
typedef WritableField< Data_T > | class_type
typedef boost::intrusive_ptr< WritableField > | Ptr
Public Types inherited from Field< Data_T >
typedef Field< Data_T > | class_type
typedef boost::intrusive_ptr< Field > | Ptr
typedef Data_T | value_type
| Allows us to reference the template class.
typedef std::vector< Ptr > | Vec
| This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInputFile::readVectorLayers() will return its data in.
Public Types inherited from FieldRes
typedef FieldRes | class_type
typedef boost::intrusive_ptr< FieldRes > | Ptr
typedef std::vector< Ptr > | Vec
Public Types inherited from FieldBase
typedef FieldBase | class_type
typedef boost::intrusive_ptr< FieldBase > | Ptr
Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBase > | Ptr
typedef boost::weak_ptr< RefBase > | WeakPtr

## Public Member Functions

void | addReference (const std::string &filename, const std::string &layerPath, int valuesPerBlock, int numVoxels, int occupiedBlocks)
| Internal function to create a Reference for the current field, for use in dynamic reading.
Data_T * | blockData (int bi, int bj, int bk) const
| Returns a pointer to the data in a block, or null if the given block is unallocated.
Data_T & | fastLValue (int i, int j, int k)
| Write access to voxel. Notice that this is non-virtual.
Data_T | fastValue (int i, int j, int k) const
| Read access to voxel. Notice that this is non-virtual.
void | setupReferenceBlocks ()
| Internal function to setup the Reference's block pointers, for use with dynamic reading.
Constructors & destructor
| SparseField ()
| Constructs an empty buffer.
| SparseField (const SparseField &o)
| Copy constructor.
| ~SparseField ()
| Destructor.
SparseField & | operator= (const SparseField &o)
| Assignment operator. For cache-managed fields, it creates a new file reference, and for non-managed fields, it copies the data.
virtual void | clear (const Data_T &value)
| Clears all the voxels in the storage.
void | setBlockOrder (int order)
| Sets the block order (i.e. the power-of-2 to use as block size.
int | blockOrder () const
| Returns the block order.
int | blockSize () const
| Returns the block size.
bool | voxelIsInAllocatedBlock (int i, int j, int k) const
| Checks if a voxel is in an allocated block.
bool | blockIsAllocated (int bi, int bj, int bk) const
| Checks if a block is allocated.
const Data_T | getBlockEmptyValue (int bi, int bj, int bk) const
| Returns the constant value of an block, whether it's allocated already or not..
void | setBlockEmptyValue (int bi, int bj, int bk, const Data_T &val)
| Sets the constant value of an block. If the block is already allocated, it gets deallocated.
bool | blockIndexIsValid (int bi, int bj, int bk) const
| Returns whether a block index is valid.
V3i | blockRes () const
| Returns the resolution of the block array.
template<typename Functor_T>
int | releaseBlocks (Functor_T func)
| Releases any blocks that are deemed empty. This can be used to clean up after algorithms that write "zero" values to the buffer, as well as after any narrow band levelset algorithms.
int | blockId (int blockI, int blockJ, int blockK) const
| Calculates the block number based on a block i,j,k index.
void | getBlockCoord (int i, int j, int k, int &bi, int &bj, int &bk) const
| Calculates the block coordinates that a given set of voxel coords are in.
void | getVoxelInBlock (int i, int j, int k, int &vi, int &vj, int &vk) const
| Calculates the coordinates in a block for the given voxel index.
void | applyDataWindowOffset (int &i, int &j, int &k) const
| Applies data window offset.
bool | isDynamicLoad () const
| Whether the field is dynamically loaded.
void | incBlockRef (const int blockId) const
| Increments the block ref count for the given block.
void | activateBlock (const int blockId) const
| Activates a given block.
void | decBlockRef (const int blockId) const
| Decrements the block ref count for the given block.
size_t | numGrains () const
| Number of 'grains' to use with threaded access.
bool | getGrainBounds (const size_t idx, Box3i &vsBounds) const
| Bounding box of the given 'grain'.
From Field
virtual Data_T | value (int i, int j, int k) const
| Read access to a voxel. The coordinates are in integer voxel space .
virtual long long int | memSize () const
| Returns the memory usage (in bytes).
virtual size_t | voxelCount () const
| Counts the number of voxels. For most fields, this is just the volume of the data window, but sparse data structures can override this to return a better value.
From WritableField
virtual Data_T & | lvalue (int i, int j, int k)
| Write access to a voxel. The coordinates are global coordinates.
Iterators
const_iterator | cbegin () const
| Const iterator to first element. "cbegin" matches the tr1 c++ standard.
const_iterator | cbegin (const Box3i &subset) const
| Const iterator to first element of specific subset.
const_iterator | cend () const
| Const iterator pointing one element past the last valid one.
const_iterator | cend (const Box3i &subset) const
| Const iterator pointing one element past the last valid one (for a subset).
iterator | begin ()
| Iterator to first element.
iterator | begin (const Box3i &subset)
| Iterator to first element of specific subset.
iterator | end ()
| Iterator pointing one element past the last valid one.
iterator | end (const Box3i &subset)
| Iterator pointing one element past the last valid one (for a subset).
block_iterator | blockBegin () const
block_iterator | blockEnd () const
| Const iterator pointing to element one past the last valid block.
Public Member Functions inherited from ResizableField< Data_T >
void | copyFrom (typename Field< Data_T >::Ptr other)
| Copies the data from another Field, also resizes.
template<class Data_T2>
void | copyFrom (typename Field< Data_T2 >::Ptr other)
| Copies the data from another Field of another template class, also resizes.
void | matchDefinition (FieldRes::Ptr fieldToMatch)
| Sets up this field so that resolution and mapping matches the other.
void | setSize (const Box3i &extents)
| Resizes the object.
void | setSize (const Box3i &extents, const Box3i &dataWindow)
| Resizes the object.
void | setSize (const V3i &size)
| Resizes the object.
void | setSize (const V3i &size, int padding)
| Resizes the object with padding.
Public Member Functions inherited from WritableField< Data_T >
iterator | begin ()
| Iterator to first element.
iterator | begin (const Box3i &subset)
| Iterator to first element of specific subset.
iterator | end ()
| Iterator pointing one element past the last valid one.
iterator | end (const Box3i &subset)
| Iterator pointing one element past the last valid one (for a subset).
Public Member Functions inherited from Field< Data_T >
const_iterator | cbegin () const
| Const iterator to first element. "cbegin" matches the tr1 c++ standard.
const_iterator | cbegin (const Box3i &subset) const
| Const iterator to first element of specific subset.
const_iterator | cend () const
| Const iterator pointing one element past the last valid one.
const_iterator | cend (const Box3i &subset) const
| Const iterator pointing one element past the last valid one (for a subset).
virtual std::string | dataTypeString () const
virtual | ~Field ()
| Dtor.
Public Member Functions inherited from FieldRes
V3i const | dataResolution () const
const Box3i & | dataWindow () const
| Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field subclass.
const Box3i & | extents () const
| Returns the extents of the data. This signifies the relevant area that the data exists over. However, the data window (below) may be smaller than the extents, in which case it is only safe to call value() for those coordinate inside the data window.
| FieldRes ()
| This constructor ensures that we have a valid mapping at all times.
| FieldRes (const FieldRes &src)
| Base class copy constructor.
bool | isInBounds (int i, int j, int k) const
| Returns true is the indicies are in bounds of the data window.
FieldMapping::Ptr | mapping ()
| Returns a pointer to the mapping.
const FieldMapping::Ptr | mapping () const
| Returns a pointer to the mapping.
virtual void | mappingChanged ()
| Tells the subclass that the mapping changed.
void | setMapping (FieldMapping::Ptr mapping)
| Sets the field's mapping.
Public Member Functions inherited from FieldBase
| FieldBase ()
| Constructor.
| FieldBase (const FieldBase &)
| Copy Constructor.
virtual | ~FieldBase ()
| Destructor.
virtual std::string | className () const =0
| Returns the class name of the object. Used by the class pool and when writing the data to disk.
virtual std::string | classType () const =0
| Returns the full class type string.
FieldMetadata & | metadata ()
| accessor to the m_metadata class
const FieldMetadata & | metadata () const
| Read only access to the m_metadata class.
void | copyMetadata (const FieldBase &field)
| Copies the metadata from a second field.
Public Member Functions inherited from RefBase
void | ref () const
| Used by boost::intrusive_pointer.
size_t | refcnt ()
| Used by boost::intrusive_pointer.
void | unref () const
| Used by boost::intrusive_pointer.
WeakPtr | weakPtr () const
| RefBase ()
| RefBase (const RefBase &)
| Copy constructor.
RefBase & | operator= (const RefBase &)
| Assignment operator.
virtual | ~RefBase ()
| Destructor.
virtual bool | checkRTTI (const char *typenameStr)=0
| This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();.
bool | matchRTTI (const char *typenameStr)
| Performs a check to see if the given typename string matches this class' This needs to be implemented in -all- subclasses, even abstract ones.
Public Member Functions inherited from MetadataCallback
virtual void | metadataHasChanged (const std::string &)
| Alerts the callback holder that the metadata has changed.

## Static Public Member Functions

static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from ResizableField< Data_T >
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from WritableField< Data_T >
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from Field< Data_T >
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from FieldRes
static const char * | staticClassName ()
static const char * | staticClassType ()
Static Public Member Functions inherited from FieldBase
static const char * | staticClassName ()
static const char * | staticClassType ()
static const char * | staticClassType ()

## Public Attributes

| DEFINE_FIELD_RTTI_CONCRETE_CLASS
Public Attributes inherited from ResizableField< Data_T >
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from WritableField< Data_T >
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from Field< Data_T >
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from FieldRes
| DEFINE_FIELD_RTTI_ABSTRACT_CLASS
Public Attributes inherited from FieldBase
std::string | attribute
| Optional name of the attribute the field represents.
std::string | name
| Optional name of the field.

## Protected Types

typedef ResizableField< Data_T > | base
typedef Sparse::SparseBlock< Data_T > | Block
Protected Types inherited from ResizableField< Data_T >
typedef WritableField< Data_T > | base
Protected Types inherited from FieldRes
typedef MatrixFieldMapping | default_mapping

## Protected Member Functions

virtual void | sizeChanged ()
| Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.
Convenience methods
void | setupBlocks ()
| Initializes the block structure. Will clear any existing data.
void | deallocBlock (Block &block, const Data_T &emptyValue)
| Deallocated the data of the given block and sets its empty value.

## Protected Attributes

int | m_blockOrder
| Block order (size = 2^blockOrder).
V3i | m_blockRes
| Block array resolution.
Block * | m_blocks
| Array of blocks. Not using std::vector since SparseBlock is noncopyable.
int | m_blockXYSize
| Block array res.x * res.y.
Data_T | m_dummy
| Dummy value used when needing to return but indicating a failed call.
int | m_fileId
| File id. Used with m_fileManager if active. Otherwise -1.
SparseFileManager * | m_fileManager
| Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
size_t | m_numBlocks
| Number of blocks in field.
Protected Attributes inherited from FieldRes
Box3i | m_dataWindow
| Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Box3i | m_extents
| Defines the extents of the the storage. This may be larger or smaller than the data window, and in the case where it is larger, care must be taken not to access voxels outside the data window. This should be treated as a closed (i.e. inclusive) interval.
FieldMapping::Ptr | m_mapping
| Pointer to the field's mapping.

## Private Member Functions

void | copyBlockStates (const SparseField< Data_T > &o)
| Internal function to copy empty values and allocated flags, without copying data, used when copying a dynamically read field.
void | copySparseField (const SparseField &o)
| Copies internal data, including blocks, from another SparseField, used by copy constructor and operator=.

## Static Private Attributes

static TemplatedFieldType< SparseField< Data_T > > | ms_classType

## Friends

class | SparseFieldIO

## From FieldBase

| FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION
virtual FieldBase::Ptr | clone () const
| Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement it.

## Additional Inherited Members

Static Protected Attributes inherited from ResizableField< Data_T >
static TemplatedFieldType< ResizableField< Data_T > > | ms_classType

## Detailed Description

template<class Data_T>
class SparseField< Data_T >

This Field subclass stores voxel data in block-allocated arrays.

Empty blocks aren't allocated. This effectively optimizes away memory use for "empty" voxels.

Refer to using_fields for examples of how to use this in your code.

Todo
  Make this class thread safe!

Definition at line 350 of file SparseField.h.

## Member Typedef Documentation

## Ptr

template<class Data_T>

typedef boost::intrusive_ptr<SparseField> SparseField< Data_T >::Ptr

Definition at line 357 of file SparseField.h.

## Vec

template<class Data_T>

typedef std::vector<Ptr> SparseField< Data_T >::Vec

Definition at line 358 of file SparseField.h.

## LinearInterp

template<class Data_T>

typedef LinearSparseFieldInterp<Data_T> SparseField< Data_T >::LinearInterp

Definition at line 360 of file SparseField.h.

## CubicInterp

template<class Data_T>

typedef CubicGenericFieldInterp<SparseField<Data_T> > SparseField< Data_T >::CubicInterp

Definition at line 361 of file SparseField.h.

## class_type

template<class Data_T>

typedef SparseField<Data_T> SparseField< Data_T >::class_type

Definition at line 365 of file SparseField.h.

## base

template<class Data_T>

typedef ResizableField<Data_T> SparseField< Data_T >::base

protected

Definition at line 582 of file SparseField.h.

## Block

template<class Data_T>

typedef Sparse::SparseBlock<Data_T> SparseField< Data_T >::Block

protected

Definition at line 583 of file SparseField.h.

## Constructor & Destructor Documentation

## SparseField() [1/2]

template<class Data_T>

SparseField< Data_T >::SparseField | ( |  | ) |

Constructs an empty buffer.

Definition at line 1287 of file SparseField.h.

: base(),
m_blockOrder(BLOCK_ORDER),
m_blocks(NULL),
m_fileManager(NULL)
{
setupBlocks();
}
SparseField
This Field subclass stores voxel data in block-allocated arrays.
Definition SparseField.h:352
SparseField::m_fileManager
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition SparseField.h:622
SparseField::setupBlocks
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition SparseField.h:1858
SparseField::m_blocks
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition SparseField.h:616
SparseField::base
ResizableField< Data_T > base
Definition SparseField.h:582
SparseField::m_blockOrder
int m_blockOrder
Block order (size = 2^blockOrder).
Definition SparseField.h:610

References BLOCK_ORDER, m_blockOrder, m_blocks, m_fileManager, and setupBlocks().

Referenced by SparseField< half >::clone(), copyBlockStates(), copySparseField(), operator=(), and SparseField().

## SparseField() [2/2]

template<class Data_T>

SparseField< Data_T >::SparseField | ( | const SparseField< Data_T > & | o | ) |

Copy constructor.

Definition at line 1299 of file SparseField.h.

: base(o),
m_blockOrder(o.m_blockOrder),
m_blocks(NULL),
m_fileManager(o.m_fileManager)
{
copySparseField(o);
}
SparseField::copySparseField
void copySparseField(const SparseField &o)
Copies internal data, including blocks, from another SparseField, used by copy constructor and operat...
Definition SparseField.h:1341

References copySparseField(), m_blockOrder, m_blocks, m_fileManager, and SparseField().

## ~SparseField()

template<class Data_T>

SparseField< Data_T >::~SparseField | ( |  | ) |

Destructor.

Definition at line 1311 of file SparseField.h.

{
if (m_fileManager) {
// this file is dynamically managed, so we need to ensure the
// cache doesn't point to this field's blocks because they are
// about to be deleted
m_fileManager->removeFieldFromCache<Data_T>(m_fileId);
}
if (m_blocks) {
delete[] m_blocks;
}
}
SparseField::m_fileId
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition SparseField.h:624

References m_blocks, m_fileId, and m_fileManager.

## Member Function Documentation

## staticClassName()

template<class Data_T>

const char * SparseField< Data_T >::staticClassName | ( |  | ) |

inline static

Definition at line 368 of file SparseField.h.

{
return "SparseField";
}

## staticClassType()

template<class Data_T>

const char * SparseField< Data_T >::staticClassType | ( |  | ) |

inline static

Definition at line 373 of file SparseField.h.

{
return SparseField<Data_T>::ms_classType.name();
}
FieldBase::name
std::string name
Optional name of the field.
Definition Field.h:171

## operator=()

template<class Data_T>

SparseField< Data_T > & SparseField< Data_T >::operator= | ( | const SparseField< Data_T > & | o | ) |

Assignment operator. For cache-managed fields, it creates a new file reference, and for non-managed fields, it copies the data.

Definition at line 1328 of file SparseField.h.

{
if (this != &o) {
this->base::operator=(o);
copySparseField(o);
}
return *this;
}
RefBase::operator=
RefBase & operator=(const RefBase &)
Assignment operator.
Definition RefCount.h:134

References copySparseField(), RefBase::operator=(), and SparseField().

## clear()

template<class Data_T>

void SparseField< Data_T >::clear | ( | const Data_T & | value | ) |

virtual

Clears all the voxels in the storage.

Reimplemented from WritableField< Data_T >.

Definition at line 1452 of file SparseField.h.

{
// If we're clearing, we can get rid of all current blocks
setupBlocks();
Block *p = m_blocks, *end = m_blocks + m_numBlocks;
while (p != end) {
p->emptyValue = value;
++p;
}
}
SparseField::Block
Sparse::SparseBlock< Data_T > Block
Definition SparseField.h:583
SparseField::end
iterator end()
Iterator pointing one element past the last valid one.
Definition SparseField.h:1814
SparseField::m_numBlocks
size_t m_numBlocks
Number of blocks in field.
Definition SparseField.h:618
SparseField::value
virtual Data_T value(int i, int j, int k) const
Read access to a voxel. The coordinates are in integer voxel space .
Definition SparseField.h:1598

References Sparse::SparseBlock< Data_T >::emptyValue, end(), m_blocks, m_numBlocks, setupBlocks(), and value().

## setBlockOrder()

template<class Data_T>

void SparseField< Data_T >::setBlockOrder | ( | int | order | ) |

Sets the block order (i.e. the power-of-2 to use as block size.

Note
  This will clear out any existing data.

Definition at line 1466 of file SparseField.h.

{
m_blockOrder = order;
setupBlocks();
}

References m_blockOrder, and setupBlocks().

## blockOrder()

template<class Data_T>

int SparseField< Data_T >::blockOrder | ( |  | ) | const

Returns the block order.

Definition at line 1475 of file SparseField.h.

{
return m_blockOrder;
}

References m_blockOrder.

Referenced by SparseField< Data_T >::const_iterator::const_iterator(), SparseField< Data_T >::iterator::iterator(), and LinearSparseFieldInterp< Data_T >::sample().

## blockSize()

template<class Data_T>

int SparseField< Data_T >::blockSize | ( |  | ) | const

Returns the block size.

Definition at line 1483 of file SparseField.h.

{
return 1 << m_blockOrder;
}

References m_blockOrder.

Referenced by fastLValue(), memSize(), SparseField< Data_T >::block_iterator::recomputeBlockBoundingBox(), releaseBlocks(), detail::threadingBlockSize(), and voxelCount().

## voxelIsInAllocatedBlock()

template<class Data_T>

bool SparseField< Data_T >::voxelIsInAllocatedBlock | ( | int | i,
|  | int | j,
|  | int | k ) const

Checks if a voxel is in an allocated block.

Definition at line 1491 of file SparseField.h.

{
int bi, bj, bk;
applyDataWindowOffset(i, j, k);
getBlockCoord(i, j, k, bi, bj, bk);
return blockIsAllocated(bi, bj, bk);
}
SparseField::applyDataWindowOffset
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition SparseField.h:455
SparseField::blockIsAllocated
bool blockIsAllocated(int bi, int bj, int bk) const
Checks if a block is allocated.
Definition SparseField.h:1502
SparseField::getBlockCoord
void getBlockCoord(int i, int j, int k, int &bi, int &bj, int &bk) const
Calculates the block coordinates that a given set of voxel coords are in.
Definition SparseField.h:1890

References applyDataWindowOffset(), blockIsAllocated(), and getBlockCoord().

## blockIsAllocated()

template<class Data_T>

bool SparseField< Data_T >::blockIsAllocated | ( | int | bi,
|  | int | bj,
|  | int | bk ) const

Checks if a block is allocated.

Definition at line 1502 of file SparseField.h.

{
const Block &block = m_blocks[blockId(bi, bj, bk)];
return block.isAllocated;
}
SparseField::blockId
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition SparseField.h:1881

References blockId(), Sparse::SparseBlock< Data_T >::isAllocated, and m_blocks.

Referenced by detail::checkInputEmpty(), LinearSparseFieldInterp< Data_T >::sample(), and voxelIsInAllocatedBlock().

## getBlockEmptyValue()

template<class Data_T>

const Data_T SparseField< Data_T >::getBlockEmptyValue | ( | int | bi,
|  | int | bj,
|  | int | bk ) const

Returns the constant value of an block, whether it's allocated already or not..

Definition at line 1511 of file SparseField.h.

{
return m_blocks[blockId(bi, bj, bk)].emptyValue;
}

References blockId(), and m_blocks.

Referenced by detail::checkInputEmpty(), and LinearSparseFieldInterp< Data_T >::sample().

## setBlockEmptyValue()

template<class Data_T>

void SparseField< Data_T >::setBlockEmptyValue | ( | int | bi,
|  | int | bj,
|  | int | bk,
|  | const Data_T & | val )

Sets the constant value of an block. If the block is already allocated, it gets deallocated.

Definition at line 1519 of file SparseField.h.

{
Block &block = m_blocks[blockId(bi, bj, bk)];
if (block.isAllocated) {
deallocBlock(block, val);
} else {
block.emptyValue = val;
}
}
SparseField::deallocBlock
void deallocBlock(Block &block, const Data_T &emptyValue)
Deallocated the data of the given block and sets its empty value.
Definition SparseField.h:1970

References blockId(), deallocBlock(), Sparse::SparseBlock< Data_T >::emptyValue, Sparse::SparseBlock< Data_T >::isAllocated, and m_blocks.

## blockIndexIsValid()

template<class Data_T>

bool SparseField< Data_T >::blockIndexIsValid | ( | int | bi,
|  | int | bj,
|  | int | bk ) const

Returns whether a block index is valid.

Definition at line 1533 of file SparseField.h.

{
return bi >= 0 && bj >= 0 && bk >= 0 &&
bi < m_blockRes.x && bj < m_blockRes.y && bk < m_blockRes.z;
}
SparseField::m_blockRes
V3i m_blockRes
Block array resolution.
Definition SparseField.h:612

References m_blockRes.

## blockRes()

template<class Data_T>

V3i SparseField< Data_T >::blockRes | ( |  | ) | const

Returns the resolution of the block array.

Definition at line 1542 of file SparseField.h.

{
return m_blockRes;
}

References m_blockRes.

Referenced by setupBlocks().

## releaseBlocks()

template<class Data_T>
template<typename Functor_T>

int SparseField< Data_T >::releaseBlocks | ( | Functor_T | func | ) |

Releases any blocks that are deemed empty. This can be used to clean up after algorithms that write "zero" values to the buffer, as well as after any narrow band levelset algorithms.

Parameters

  func | A function object with the method "bool check(SparseBlock&)"

Returns
  Number of released blocks

Definition at line 1551 of file SparseField.h.

{
Data_T emptyValue;
int numDeallocs = 0;
// If the block is on the edge of the field, it may have unused
// voxels, with undefined values. We need to pass the range of
// valid voxels into the check function, so it only looks at valid
// voxels.
V3i dataRes = FieldRes::dataResolution();
V3i validSize;
V3i blockAllocSize(blockSize());
int bx = 0, by = 0, bz = 0;
for (size_t i = 0; i < m_numBlocks; ++i, ++bx) {
if (bx >= m_blockRes.x) {
bx = 0;
++by;
if (by >= m_blockRes.y) {
by = 0;
++bz;
}
}
validSize = blockAllocSize;
if (bx == m_blockRes.x-1) {
validSize.x = dataRes.x - bx * blockAllocSize.x;
}
if (by == m_blockRes.y-1) {
validSize.y = dataRes.y - by * blockAllocSize.y;
}
if (bz == m_blockRes.z-1) {
validSize.z = dataRes.z - bz * blockAllocSize.z;
}
if (m_blocks[i].isAllocated) {
if (func.check(m_blocks[i], emptyValue, validSize, blockAllocSize)) {
deallocBlock(m_blocks[i], emptyValue);
numDeallocs++;
}
}
}
return numDeallocs;
}
FieldRes::dataResolution
V3i const dataResolution() const
Definition Field.h:256
SparseField::blockSize
int blockSize() const
Returns the block size.
Definition SparseField.h:1483

References blockSize(), FieldRes::dataResolution(), deallocBlock(), m_blockRes, m_blocks, and m_numBlocks.

## blockId()

template<class Data_T>

int SparseField< Data_T >::blockId | ( | int | blockI,
|  | int | blockJ,
|  | int | blockK ) const

Calculates the block number based on a block i,j,k index.

Definition at line 1881 of file SparseField.h.

{
return blockK * m_blockXYSize + blockJ * m_blockRes.x + blockI;
}
SparseField::m_blockXYSize
int m_blockXYSize
Block array res.x * res.y.
Definition SparseField.h:614

References m_blockRes, and m_blockXYSize.

Referenced by activateBlock(), blockData(), blockIsAllocated(), decBlockRef(), fastLValue(), fastValue(), getBlockEmptyValue(), incBlockRef(), LinearSparseFieldInterp< Data_T >::sample(), and setBlockEmptyValue().

## getBlockCoord()

template<class Data_T>

void SparseField< Data_T >::getBlockCoord | ( | int | i,
|  | int | j,
|  | int | k,
|  | int & | bi,
|  | int & | bj,
|  | int & | bk ) const

Calculates the block coordinates that a given set of voxel coords are in.

Note
  The i,j,k coordinates are strictly positive, and refer to the coordinates of a voxel -after- the data window offset has been applied.
  Bit shift should be ok, indices are always positive.

Definition at line 1890 of file SparseField.h.

{
assert(i >= 0);
assert(j >= 0);
assert(k >= 0);
bi = i >> m_blockOrder;
bj = j >> m_blockOrder;
bk = k >> m_blockOrder;
}

References m_blockOrder.

Referenced by blockCoords(), fastLValue(), fastValue(), LinearSparseFieldInterp< Data_T >::sample(), and voxelIsInAllocatedBlock().

## getVoxelInBlock()

template<class Data_T>

void SparseField< Data_T >::getVoxelInBlock | ( | int | i,
|  | int | j,
|  | int | k,
|  | int & | vi,
|  | int & | vj,
|  | int & | vk ) const

Calculates the coordinates in a block for the given voxel index.

Note
  The i,j,k coordinates are strictly positive, and refer to the coordinates of a voxel -after- the data window offset has been applied.
  Bit shift should be ok, indices are always positive.

Definition at line 1905 of file SparseField.h.

{
assert(i >= 0);
assert(j >= 0);
assert(k >= 0);
vi = i & ((1 << m_blockOrder) - 1);
vj = j & ((1 << m_blockOrder) - 1);
vk = k & ((1 << m_blockOrder) - 1);
}

References m_blockOrder.

Referenced by fastLValue(), fastValue(), and LinearSparseFieldInterp< Data_T >::sample().

## applyDataWindowOffset()

template<class Data_T>

void SparseField< Data_T >::applyDataWindowOffset | ( | int & | i,
|  | int & | j,
|  | int & | k ) const

inline

Applies data window offset.

Definition at line 455 of file SparseField.h.

{
i -= base::m_dataWindow.min.x;
j -= base::m_dataWindow.min.y;
k -= base::m_dataWindow.min.z;
}
FieldRes::m_dataWindow
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e....
Definition Field.h:310

Referenced by blockCoords(), fastLValue(), fastValue(), LinearSparseFieldInterp< Data_T >::sample(), and voxelIsInAllocatedBlock().

## isDynamicLoad()

template<class Data_T>

bool SparseField< Data_T >::isDynamicLoad | ( |  | ) | const

inline

Whether the field is dynamically loaded.

Definition at line 463 of file SparseField.h.

{ return m_fileManager != NULL; }

Referenced by LinearSparseFieldInterp< Data_T >::sample().

## incBlockRef()

template<class Data_T>

void SparseField< Data_T >::incBlockRef | ( | const int | blockId | ) | const

Increments the block ref count for the given block.

Definition at line 1919 of file SparseField.h.

{
m_fileManager->incBlockRef<Data_T>(m_fileId, blockId);
}

References blockId(), m_fileId, and m_fileManager.

Referenced by LinearSparseFieldInterp< Data_T >::sample().

## activateBlock()

template<class Data_T>

void SparseField< Data_T >::activateBlock | ( | const int | blockId | ) | const

Activates a given block.

Definition at line 1927 of file SparseField.h.

{
m_fileManager->activateBlock<Data_T>(m_fileId, blockId);
}

References blockId(), m_fileId, and m_fileManager.

Referenced by LinearSparseFieldInterp< Data_T >::sample().

## decBlockRef()

template<class Data_T>

void SparseField< Data_T >::decBlockRef | ( | const int | blockId | ) | const

Decrements the block ref count for the given block.

Definition at line 1935 of file SparseField.h.

{
m_fileManager->decBlockRef<Data_T>(m_fileId, blockId);
}

References blockId(), m_fileId, and m_fileManager.

Referenced by LinearSparseFieldInterp< Data_T >::sample().

## numGrains()

template<class Data_T>

size_t SparseField< Data_T >::numGrains | ( |  | ) | const

Number of 'grains' to use with threaded access.

Definition at line 1943 of file SparseField.h.

{
return m_numBlocks;
}

References m_numBlocks.

## getGrainBounds()

template<class Data_T>

bool SparseField< Data_T >::getGrainBounds | ( | const size_t | idx,
|  | Box3i & | vsBounds ) const

Bounding box of the given 'grain'.

Returns
  Whether the grain is contiguous in memory

Definition at line 1951 of file SparseField.h.

{
// Block size
const size_t blockSide = (1 << m_blockOrder);
// Block coordinate
const V3i bCoord = indexToCoord(idx, m_blockRes);
// Block bbox
const V3i start(bCoord * blockSide + base::m_dataWindow.min);
const V3i end (start + Imath::V3i(blockSide - 1));
// Bounds must be clipped against data window
const Box3i unclipped(start, end);
bounds = clipBounds(unclipped, base::m_dataWindow);
// Whether it's a contiguous block
return bounds == unclipped;
}
clipBounds
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Definition Field.h:1145
indexToCoord
V3i indexToCoord(const size_t idx, const V3i &res)
Definition Field.h:1187

References clipBounds(), end(), indexToCoord(), m_blockOrder, m_blockRes, and FieldRes::m_dataWindow.

## value()

template<class Data_T>

Data_T SparseField< Data_T >::value | ( | int | i,
|  | int | j,
|  | int | k ) const

virtual

Read access to a voxel. The coordinates are in integer voxel space .

Note
  Before the internal storage is accessed, the subclass must compute the data window coordinates by looking at Field::m_dataWindow.
  Virtual functions are known not to play nice with threading. Therefor, concrete classes can implement (by convention) fastValue() as a non-virtual function.

Implements Field< Data_T >.

Definition at line 1598 of file SparseField.h.

{
return fastValue(i, j, k);
}
SparseField::fastValue
Data_T fastValue(int i, int j, int k) const
Read access to voxel. Notice that this is non-virtual.
Definition SparseField.h:1614

References fastValue().

Referenced by clear().

## memSize()

template<class Data_T>

long long int SparseField< Data_T >::memSize | ( |  | ) | const

virtual

Returns the memory usage (in bytes).

Note
  This needs to be re-implemented for any subclass that adds data members. Those classes should also call their superclass and add the combined memory use.

Reimplemented from FieldRes.

Definition at line 1708 of file SparseField.h.

{
long long int blockSize = m_numBlocks * sizeof(Block);
long long int dataSize = 0;
for (size_t i = 0; i < m_numBlocks; ++i) {
if (m_blocks[i].data) {
dataSize += (1 << m_blockOrder << m_blockOrder << m_blockOrder) *
sizeof(Data_T);
}
}
return sizeof(*this) + dataSize + blockSize;
}

References blockSize(), m_blockOrder, m_blocks, and m_numBlocks.

## voxelCount()

template<class Data_T>

size_t SparseField< Data_T >::voxelCount | ( |  | ) | const

virtual

Counts the number of voxels. For most fields, this is just the volume of the data window, but sparse data structures can override this to return a better value.

Reimplemented from FieldRes.

Definition at line 1726 of file SparseField.h.

{
size_t count = 0;
const size_t blockSize = (1 << m_blockOrder << m_blockOrder << m_blockOrder);
for (size_t i = 0; i < m_numBlocks; ++i) {
if (m_blocks[i].isAllocated) {
count += blockSize;
}
}
return count;
}

References blockSize(), m_blockOrder, m_blocks, and m_numBlocks.

## lvalue()

template<class Data_T>

Data_T & SparseField< Data_T >::lvalue | ( | int | i,
|  | int | j,
|  | int | k )

virtual

Write access to a voxel. The coordinates are global coordinates.

Note
  Before the internal storage is accessed, the subclass must compute the crop window coordinates by looking at Field::m_dataWindow.
  This is named differently from the const value so that non-const objects still have a clear way of accessing data in a const way.
  Virtual functions are known not to play nice with threading. Therefor, concrete classes can implement (by convention) fastLValue() as a non-virtual function.

Implements WritableField< Data_T >.

Definition at line 1606 of file SparseField.h.

{
return fastLValue(i, j, k);
}
SparseField::fastLValue
Data_T & fastLValue(int i, int j, int k)
Write access to voxel. Notice that this is non-virtual.
Definition SparseField.h:1653

References fastLValue().

## fastValue()

template<class Data_T>

Data_T SparseField< Data_T >::fastValue | ( | int | i,
|  | int | j,
|  | int | k ) const

Read access to voxel. Notice that this is non-virtual.

Definition at line 1614 of file SparseField.h.

{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z);
// Add crop window offset
applyDataWindowOffset(i, j, k);
// Find block coord
int bi, bj, bk;
getBlockCoord(i, j, k, bi, bj, bk);
// Find coord in block
int vi, vj, vk;
getVoxelInBlock(i, j, k, vi, vj, vk);
// Get the actual block
int id = blockId(bi, bj, bk);
const Block &block = m_blocks[id];
// Check if block data is allocated
if (block.isAllocated) {
if (m_fileManager) {
m_fileManager->incBlockRef<Data_T>(m_fileId, id);
m_fileManager->activateBlock<Data_T>(m_fileId, id);
Data_T tmpValue = block.value(vi, vj, vk, m_blockOrder);
m_fileManager->decBlockRef<Data_T>(m_fileId, id);
return tmpValue;
} else {
return block.value(vi, vj, vk, m_blockOrder);
}
} else {
return block.emptyValue;
}
}
SparseField::getVoxelInBlock
void getVoxelInBlock(int i, int j, int k, int &vi, int &vj, int &vk) const
Calculates the coordinates in a block for the given voxel index.
Definition SparseField.h:1905

References applyDataWindowOffset(), blockId(), Sparse::SparseBlock< Data_T >::emptyValue, getBlockCoord(), getVoxelInBlock(), Sparse::SparseBlock< Data_T >::isAllocated, m_blockOrder, m_blocks, FieldRes::m_dataWindow, m_fileId, m_fileManager, and Sparse::SparseBlock< Data_T >::value().

Referenced by LinearSparseFieldInterp< Data_T >::sample(), and value().

## fastLValue()

template<class Data_T>

Data_T & SparseField< Data_T >::fastLValue | ( | int | i,
|  | int | j,
|  | int | k )

Write access to voxel. Notice that this is non-virtual.

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

Definition at line 1653 of file SparseField.h.

{
assert (i >= base::m_dataWindow.min.x);
assert (i <= base::m_dataWindow.max.x);
assert (j >= base::m_dataWindow.min.y);
assert (j <= base::m_dataWindow.max.y);
assert (k >= base::m_dataWindow.min.z);
assert (k <= base::m_dataWindow.max.z);
if (m_fileManager) {
assert(false && "Called fastLValue() on a dynamic-read sparse field");
Msg::print(Msg::SevWarning, "Called fastLValue() on a dynamic-read "
"sparse field");
return m_dummy;
}
// Add crop window offset
applyDataWindowOffset(i, j, k);
// Find block coord
int bi, bj, bk;
getBlockCoord(i, j, k, bi, bj, bk);
// Find coord in block
int vi, vj, vk;
getVoxelInBlock(i, j, k, vi, vj, vk);
// Get the actual block
int id = blockId(bi, bj, bk);
Block &block = m_blocks[id];
// If block is allocated, return a reference to the data
if (block.isAllocated) {
return block.value(vi, vj, vk, m_blockOrder);
} else {
// ... Otherwise, allocate block
size_t blockSize = 1 << m_blockOrder << m_blockOrder << m_blockOrder;
block.resize(blockSize);
return block.value(vi, vj, vk, m_blockOrder);
}
}
SparseField::m_dummy
Data_T m_dummy
Dummy value used when needing to return but indicating a failed call.
Definition SparseField.h:627
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References applyDataWindowOffset(), blockId(), blockSize(), getBlockCoord(), getVoxelInBlock(), Sparse::SparseBlock< Data_T >::isAllocated, m_blockOrder, m_blocks, FieldRes::m_dataWindow, m_dummy, m_fileManager, Msg::print(), Sparse::SparseBlock< Data_T >::resize(), Msg::SevWarning, and Sparse::SparseBlock< Data_T >::value().

Referenced by lvalue().

## blockData()

template<class Data_T>

Data_T * SparseField< Data_T >::blockData | ( | int | bi,
|  | int | bj,
|  | int | bk ) const

Returns a pointer to the data in a block, or null if the given block is unallocated.

Definition at line 1694 of file SparseField.h.

{
int id = blockId(bi, bj, bk);
const Block &block = m_blocks[id];
if (block.isAllocated) {
return block.data;
} else {
return NULL;
}
}

References blockId(), Sparse::SparseBlock< Data_T >::data, Sparse::SparseBlock< Data_T >::isAllocated, and m_blocks.

Referenced by LinearSparseFieldInterp< Data_T >::sample().

## clone()

template<class Data_T>

virtual FieldBase::Ptr SparseField< Data_T >::clone | ( |  | ) | const

inline virtual

Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement it.

Implements FieldBase.

Definition at line 517 of file SparseField.h.

{ return Ptr(new SparseField(*this)); }
SparseField::SparseField
SparseField()
Constructs an empty buffer.
Definition SparseField.h:1287
SparseField::Ptr
boost::intrusive_ptr< SparseField > Ptr
Definition SparseField.h:357

## cbegin() [1/2]

template<class Data_T>

SparseField< Data_T >::const_iterator SparseField< Data_T >::cbegin | ( |  | ) | const

Const iterator to first element. "cbegin" matches the tr1 c++ standard.

Definition at line 1744 of file SparseField.h.

{
if (FieldRes::dataResolution() == V3i(0))
return cend();
return const_iterator(*this, base::m_dataWindow, base::m_dataWindow.min,
m_blockOrder);
}
V3i
Imath::V3i V3i
Definition SpiMathLib.h:71
SparseField::const_iterator
Definition SparseField.h:886
SparseField::cend
const_iterator cend() const
Const iterator pointing one element past the last valid one.
Definition SparseField.h:1767

References cend(), FieldRes::dataResolution(), m_blockOrder, and FieldRes::m_dataWindow.

## cbegin() [2/2]

template<class Data_T>

SparseField< Data_T >::const_iterator SparseField< Data_T >::cbegin | ( | const Box3i & | subset | ) | const

Const iterator to first element of specific subset.

Definition at line 1756 of file SparseField.h.

{
if (subset.isEmpty())
return cend(subset);
return const_iterator(*this, subset, subset.min, m_blockOrder);
}

References cend(), and m_blockOrder.

## cend() [1/2]

template<class Data_T>

SparseField< Data_T >::const_iterator SparseField< Data_T >::cend | ( |  | ) | const

Const iterator pointing one element past the last valid one.

Definition at line 1767 of file SparseField.h.

{
return const_iterator(*this, base::m_dataWindow,
V3i(base::m_dataWindow.min.x,
base::m_dataWindow.min.y,
base::m_dataWindow.max.z + 1),
m_blockOrder);
}

References m_blockOrder, and FieldRes::m_dataWindow.

Referenced by cbegin(), and cbegin().

## cend() [2/2]

template<class Data_T>

SparseField< Data_T >::const_iterator SparseField< Data_T >::cend | ( | const Box3i & | subset | ) | const

Const iterator pointing one element past the last valid one (for a subset).

Definition at line 1780 of file SparseField.h.

{
return const_iterator(*this, subset,
V3i(subset.min.x,
subset.min.y,
subset.max.z + 1), m_blockOrder);
}

References m_blockOrder.

## begin() [1/2]

template<class Data_T>

SparseField< Data_T >::iterator SparseField< Data_T >::begin | ( |  | ) |

Iterator to first element.

Definition at line 1792 of file SparseField.h.

{
if (FieldRes::dataResolution() == V3i(0))
return end();
return iterator(*this, base::m_dataWindow,
base::m_dataWindow.min, m_blockOrder); }
SparseField::iterator
Definition SparseField.h:1068

References FieldRes::dataResolution(), end(), m_blockOrder, and FieldRes::m_dataWindow.

## begin() [2/2]

template<class Data_T>

SparseField< Data_T >::iterator SparseField< Data_T >::begin | ( | const Box3i & | subset | ) |

Iterator to first element of specific subset.

Definition at line 1803 of file SparseField.h.

{
if (subset.isEmpty())
return end(subset);
return iterator(*this, subset, subset.min, m_blockOrder);
}

References end(), and m_blockOrder.

## end() [1/2]

template<class Data_T>

SparseField< Data_T >::iterator SparseField< Data_T >::end | ( |  | ) |

Iterator pointing one element past the last valid one.

Definition at line 1814 of file SparseField.h.

{
return iterator(*this, base::m_dataWindow,
V3i(base::m_dataWindow.min.x,
base::m_dataWindow.min.y,
base::m_dataWindow.max.z + 1), m_blockOrder);
}

References m_blockOrder, and FieldRes::m_dataWindow.

Referenced by begin(), begin(), clear(), and getGrainBounds().

## end() [2/2]

template<class Data_T>

SparseField< Data_T >::iterator SparseField< Data_T >::end | ( | const Box3i & | subset | ) |

Iterator pointing one element past the last valid one (for a subset).

Definition at line 1826 of file SparseField.h.

{
return iterator(*this, subset,
V3i(subset.min.x, subset.min.y, subset.max.z + 1),
m_blockOrder);
}

References m_blockOrder.

## blockBegin()

template<class Data_T>

SparseField< Data_T >::block_iterator SparseField< Data_T >::blockBegin | ( |  | ) | const

Definition at line 1837 of file SparseField.h.

{
if (FieldRes::dataResolution() == V3i(0))
return blockEnd();
return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)),
V3i(0));
}
Box3i
Imath::Box3i Box3i
Definition SpiMathLib.h:77
SparseField::block_iterator
Definition SparseField.h:1214
SparseField::blockEnd
block_iterator blockEnd() const
Const iterator pointing to element one past the last valid block.
Definition SparseField.h:1849

References blockEnd(), FieldRes::dataResolution(), and m_blockRes.

## blockEnd()

template<class Data_T>

SparseField< Data_T >::block_iterator SparseField< Data_T >::blockEnd | ( |  | ) | const

Const iterator pointing to element one past the last valid block.

Definition at line 1849 of file SparseField.h.

{
return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)),
V3i(0, 0, m_blockRes.z));
}

References m_blockRes.

Referenced by blockBegin().

## addReference()

template<class Data_T>

void SparseField< Data_T >::addReference | ( | const std::string & | filename,
|  | const std::string & | layerPath,
|  | int | valuesPerBlock,
|  | int | numVoxels,
|  | int | occupiedBlocks )

Internal function to create a Reference for the current field, for use in dynamic reading.

Definition at line 1379 of file SparseField.h.

{
m_fileManager = &SparseFileManager::singleton();
m_fileId = m_fileManager->getNextId<Data_T>(filename, layerPath);
// Set up the manager data
SparseFile::Reference<Data_T> *reference =
m_fileManager->reference<Data_T>(m_fileId);
reference->valuesPerBlock = valuesPerBlock;
reference->numVoxels = numVoxels;
reference->occupiedBlocks = occupiedBlocks;
reference->setNumBlocks(m_numBlocks);
}
SparseFileManager::singleton
static SparseFileManager & singleton()
Returns a reference to the singleton instance.
Definition SparseFile.cpp:66

References m_fileId, m_fileManager, m_numBlocks, and SparseFileManager::singleton().

Referenced by copySparseField().

## setupReferenceBlocks()

template<class Data_T>

void SparseField< Data_T >::setupReferenceBlocks | ( |  | ) |

Internal function to setup the Reference's block pointers, for use with dynamic reading.

Definition at line 1413 of file SparseField.h.

{
if (!m_fileManager || m_fileId < 0) return;
SparseFile::Reference<Data_T> *reference =
m_fileManager->reference<Data_T>(m_fileId);
#if F3D_NO_BLOCKS_ARRAY
std::vector<int>::iterator fb = reference->fileBlockIndices.begin();
reference->blocks = m_blocks;
int nextBlockIdx = 0;
for (size_t i = 0; i < m_numBlocks; ++i, ++fb) {
if (m_blocks[i].isAllocated) {
*fb = nextBlockIdx;
nextBlockIdx++;
} else {
*fb = -1;
}
}
#else
std::vector<int>::iterator fb = reference->fileBlockIndices.begin();
typename SparseFile::Reference<Data_T>::BlockPtrs::iterator bp =
reference->blocks.begin();
int nextBlockIdx = 0;
for (size_t i = 0; i < m_numBlocks; ++i, ++fb, ++bp) {
if (m_blocks[i].isAllocated) {
*fb = nextBlockIdx;
*bp = m_blocks + i;
nextBlockIdx++;
} else {
*fb = -1;
}
}
#endif
}
SparseField::begin
iterator begin()
Iterator to first element.
Definition SparseField.h:1792

References SparseFile::Reference< Data_T >::blocks, SparseFile::Reference< Data_T >::fileBlockIndices, m_blocks, m_fileId, m_fileManager, and m_numBlocks.

Referenced by copySparseField().

## sizeChanged()

template<class Data_T>

virtual void SparseField< Data_T >::sizeChanged | ( |  | ) |

inline protected virtual

Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.

Note
  Make sure to call the base class version in subclasses!

Reimplemented from ResizableField< Data_T >.

Definition at line 587 of file SparseField.h.

{
// Call base class
base::sizeChanged();
setupBlocks();
}
ResizableField::sizeChanged
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc....
Definition Field.h:901

## setupBlocks()

template<class Data_T>

void SparseField< Data_T >::setupBlocks | ( |  | ) |

protected

Initializes the block structure. Will clear any existing data.

Definition at line 1858 of file SparseField.h.

{
// Do calculation in floating point so we can round up later
V3f res(base::m_dataWindow.size() + V3i(1));
V3f blockRes(res / (1 << m_blockOrder));
blockRes.x = ceil(blockRes.x);
blockRes.y = ceil(blockRes.y);
blockRes.z = ceil(blockRes.z);
V3i intBlockRes(static_cast<int>(blockRes.x),
static_cast<int>(blockRes.y),
static_cast<int>(blockRes.z));
m_blockRes = intBlockRes;
m_blockXYSize = m_blockRes.x * m_blockRes.y;
if (m_blocks) {
delete[] m_blocks;
}
m_numBlocks = intBlockRes.x * intBlockRes.y * intBlockRes.z;
m_blocks = new Block[m_numBlocks];
}
SparseField::blockRes
V3i blockRes() const
Returns the resolution of the block array.
Definition SparseField.h:1542

References blockRes(), m_blockOrder, m_blockRes, m_blocks, m_blockXYSize, FieldRes::m_dataWindow, and m_numBlocks.

Referenced by clear(), copySparseField(), setBlockOrder(), SparseField< half >::sizeChanged(), and SparseField().

## deallocBlock()

template<class Data_T>

void SparseField< Data_T >::deallocBlock | ( | Block & | block,
|  | const Data_T & | emptyValue )

protected

Deallocated the data of the given block and sets its empty value.

Block::clear() deallocates the data

Definition at line 1970 of file SparseField.h.

{
block.isAllocated = false;
block.clear();
block.emptyValue = emptyValue;
}
SparseField::clear
virtual void clear(const Data_T &value)
Clears all the voxels in the storage.
Definition SparseField.h:1452

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

Referenced by releaseBlocks(), and setBlockEmptyValue().

## copySparseField()

template<class Data_T>

void SparseField< Data_T >::copySparseField | ( | const SparseField< Data_T > & | o | ) |

private

Copies internal data, including blocks, from another SparseField, used by copy constructor and operator=.

Definition at line 1341 of file SparseField.h.

{
m_blockOrder = o.m_blockOrder;
if (o.m_fileManager) {
// allocate m_blocks, sets m_blockRes, m_blockXYSize, m_blocks
setupBlocks();
m_fileManager = o.m_fileManager;
SparseFile::Reference<Data_T> *oldReference =
m_fileManager->reference<Data_T>(o.m_fileId);
addReference(oldReference->filename, oldReference->layerPath,
oldReference->valuesPerBlock,
oldReference->numVoxels,
oldReference->occupiedBlocks);
copyBlockStates(o);
setupReferenceBlocks();
} else {
// directly copy all values and blocks from the source, no extra setup
m_blockRes = o.m_blockRes;
m_blockXYSize = o.m_blockXYSize;
if (m_blocks) {
delete[] m_blocks;
}
m_numBlocks = o.m_numBlocks;
m_blocks = new Block[m_numBlocks];
for (size_t i = 0; i < m_numBlocks; ++i) {
m_blocks[i].isAllocated = o.m_blocks[i].isAllocated;
m_blocks[i].emptyValue = o.m_blocks[i].emptyValue;
m_blocks[i].copy(o.m_blocks[i],
1 << m_blockOrder << m_blockOrder << m_blockOrder);
}
m_fileId = -1;
m_fileManager = NULL;
}
}
SparseField::addReference
void addReference(const std::string &filename, const std::string &layerPath, int valuesPerBlock, int numVoxels, int occupiedBlocks)
Internal function to create a Reference for the current field, for use in dynamic reading.
Definition SparseField.h:1379
SparseField::setupReferenceBlocks
void setupReferenceBlocks()
Internal function to setup the Reference's block pointers, for use with dynamic reading.
Definition SparseField.h:1413
SparseField::copyBlockStates
void copyBlockStates(const SparseField< Data_T > &o)
Internal function to copy empty values and allocated flags, without copying data, used when copying a...
Definition SparseField.h:1399
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

References addReference(), copyBlockStates(), Sparse::SparseBlock< Data_T >::emptyValue, SparseFile::Reference< Data_T >::filename, Sparse::SparseBlock< Data_T >::isAllocated, SparseFile::Reference< Data_T >::layerPath, m_blockOrder, m_blockRes, m_blocks, m_blockXYSize, m_fileId, m_fileManager, m_numBlocks, SparseFile::Reference< Data_T >::numVoxels, SparseFile::Reference< Data_T >::occupiedBlocks, setupBlocks(), setupReferenceBlocks(), SparseField(), and SparseFile::Reference< Data_T >::valuesPerBlock.

Referenced by operator=(), and SparseField().

## copyBlockStates()

template<class Data_T>

void SparseField< Data_T >::copyBlockStates | ( | const SparseField< Data_T > & | o | ) |

private

Internal function to copy empty values and allocated flags, without copying data, used when copying a dynamically read field.

Definition at line 1399 of file SparseField.h.

{
if (m_numBlocks != o.m_numBlocks) return;
for (size_t i = 0; i < m_numBlocks; ++i) {
m_blocks[i].isAllocated = o.m_blocks[i].isAllocated;
m_blocks[i].emptyValue = o.m_blocks[i].emptyValue;
m_blocks[i].clear();
}
}

References Sparse::SparseBlock< Data_T >::emptyValue, Sparse::SparseBlock< Data_T >::isAllocated, m_blocks, m_numBlocks, and SparseField().

Referenced by copySparseField().

## Friends And Related Symbol Documentation

## SparseFieldIO

template<class Data_T>

friend class SparseFieldIO

friend

Definition at line 578 of file SparseField.h.

## Member Data Documentation

## DEFINE_FIELD_RTTI_CONCRETE_CLASS

template<class Data_T>

SparseField< Data_T >::DEFINE_FIELD_RTTI_CONCRETE_CLASS

Definition at line 366 of file SparseField.h.

## FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION

template<class Data_T>

SparseField< Data_T >::FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION

Definition at line 515 of file SparseField.h.

## m_blockOrder

template<class Data_T>

int SparseField< Data_T >::m_blockOrder

protected

Block order (size = 2^blockOrder).

Definition at line 610 of file SparseField.h.

Referenced by begin(), begin(), blockOrder(), blockSize(), cbegin(), cbegin(), cend(), cend(), copySparseField(), end(), end(), fastLValue(), fastValue(), getBlockCoord(), getGrainBounds(), getVoxelInBlock(), memSize(), setBlockOrder(), setupBlocks(), SparseField(), SparseField(), and voxelCount().

## m_blockRes

template<class Data_T>

V3i SparseField< Data_T >::m_blockRes

protected

Block array resolution.

Definition at line 612 of file SparseField.h.

Referenced by blockBegin(), blockEnd(), blockId(), blockIndexIsValid(), blockRes(), copySparseField(), getGrainBounds(), releaseBlocks(), and setupBlocks().

## m_blockXYSize

template<class Data_T>

int SparseField< Data_T >::m_blockXYSize

protected

Block array res.x * res.y.

Definition at line 614 of file SparseField.h.

Referenced by blockId(), copySparseField(), and setupBlocks().

## m_blocks

template<class Data_T>

Block* SparseField< Data_T >::m_blocks

protected

Array of blocks. Not using std::vector since SparseBlock is noncopyable.

Definition at line 616 of file SparseField.h.

Referenced by blockData(), blockIsAllocated(), clear(), copyBlockStates(), copySparseField(), fastLValue(), fastValue(), getBlockEmptyValue(), memSize(), releaseBlocks(), setBlockEmptyValue(), setupBlocks(), setupReferenceBlocks(), SparseField(), SparseField(), voxelCount(), and ~SparseField().

## m_numBlocks

template<class Data_T>

size_t SparseField< Data_T >::m_numBlocks

protected

Number of blocks in field.

Definition at line 618 of file SparseField.h.

Referenced by addReference(), clear(), copyBlockStates(), copySparseField(), memSize(), numGrains(), releaseBlocks(), setupBlocks(), setupReferenceBlocks(), and voxelCount().

## m_fileManager

template<class Data_T>

SparseFileManager* SparseField< Data_T >::m_fileManager

protected

Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.

Definition at line 622 of file SparseField.h.

Referenced by activateBlock(), addReference(), copySparseField(), decBlockRef(), fastLValue(), fastValue(), incBlockRef(), setupReferenceBlocks(), SparseField(), SparseField(), and ~SparseField().

## m_fileId

template<class Data_T>

int SparseField< Data_T >::m_fileId

protected

File id. Used with m_fileManager if active. Otherwise -1.

Definition at line 624 of file SparseField.h.

Referenced by activateBlock(), addReference(), copySparseField(), decBlockRef(), fastValue(), incBlockRef(), setupReferenceBlocks(), and ~SparseField().

## m_dummy

template<class Data_T>

Data_T SparseField< Data_T >::m_dummy

protected

Dummy value used when needing to return but indicating a failed call.

Definition at line 627 of file SparseField.h.

Referenced by fastLValue().

## ms_classType

template<class Data_T>

TemplatedFieldType<SparseField<Data_T> > SparseField< Data_T >::ms_classType

static private

Definition at line 633 of file SparseField.h.

Referenced by SparseField< half >::staticClassType().

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

- export/SparseField.h