Field3D
SparseField< Data_T > Class Template Reference

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

#include <SparseField.h>

Inheritance diagram for SparseField< Data_T >:
ResizableField< Data_T > WritableField< Data_T > Field< Data_T > FieldRes FieldBase RefBase MetadataCallback

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< SparseFieldPtr
 
typedef std::vector< PtrVec
 
- Public Types inherited from ResizableField< Data_T >
typedef ResizableField< Data_T > class_type
 
typedef boost::intrusive_ptr< ResizableFieldPtr
 
- Public Types inherited from WritableField< Data_T >
typedef WritableField< Data_T > class_type
 
typedef boost::intrusive_ptr< WritableFieldPtr
 
- Public Types inherited from Field< Data_T >
typedef Field< Data_T > class_type
 
typedef boost::intrusive_ptr< FieldPtr
 
typedef Data_T value_type
 Allows us to reference the template class. More...
 
typedef std::vector< PtrVec
 This is a convenience typedef for the list that Field3DInputFile::readScalarLayers() and Field3DInputFile::readVectorLayers() will return its data in. More...
 
- Public Types inherited from FieldRes
typedef FieldRes class_type
 
typedef boost::intrusive_ptr< FieldResPtr
 
typedef std::vector< PtrVec
 
- Public Types inherited from FieldBase
typedef FieldBase class_type
 
typedef boost::intrusive_ptr< FieldBasePtr
 
- Public Types inherited from RefBase
typedef boost::intrusive_ptr< RefBasePtr
 
typedef boost::weak_ptr< RefBaseWeakPtr
 

Public Member Functions

void activateBlock (const int blockId) const
 Activates a given block. More...
 
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. More...
 
void applyDataWindowOffset (int &i, int &j, int &k) const
 Applies data window offset. More...
 
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. More...
 
int blockId (int blockI, int blockJ, int blockK) const
 Calculates the block number based on a block i,j,k index. More...
 
bool blockIndexIsValid (int bi, int bj, int bk) const
 Returns whether a block index is valid. More...
 
bool blockIsAllocated (int bi, int bj, int bk) const
 Checks if a block is allocated. More...
 
int blockOrder () const
 Returns the block order. More...
 
V3i blockRes () const
 Returns the resolution of the block array. More...
 
int blockSize () const
 Returns the block size. More...
 
virtual void clear (const Data_T &value)
 Clears all the voxels in the storage. More...
 
void decBlockRef (const int blockId) const
 Decrements the block ref count for the given block. More...
 
Data_T & fastLValue (int i, int j, int k)
 Write access to voxel. Notice that this is non-virtual. More...
 
Data_T fastValue (int i, int j, int k) const
 Read access to voxel. Notice that this is non-virtual. More...
 
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. More...
 
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.. More...
 
bool getGrainBounds (const size_t idx, Box3i &vsBounds) const
 Bounding box of the given 'grain'. More...
 
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. More...
 
void incBlockRef (const int blockId) const
 Increments the block ref count for the given block. More...
 
bool isDynamicLoad () const
 Whether the field is dynamically loaded. More...
 
size_t numGrains () const
 Number of 'grains' to use with threaded access. More...
 
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. More...
 
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. More...
 
void setBlockOrder (int order)
 Sets the block order (i.e. the power-of-2 to use as block size. More...
 
void setupReferenceBlocks ()
 Internal function to setup the Reference's block pointers, for use with dynamic reading. More...
 
bool voxelIsInAllocatedBlock (int i, int j, int k) const
 Checks if a voxel is in an allocated block. More...
 
Constructors & destructor
 SparseField ()
 Constructs an empty buffer. More...
 
 SparseField (const SparseField &o)
 Copy constructor. More...
 
 ~SparseField ()
 Destructor. More...
 
SparseFieldoperator= (const SparseField &o)
 Assignment operator. For cache-managed fields, it creates a new file reference, and for non-managed fields, it copies the data. More...
 
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 . More...
 
virtual long long int memSize () const
 Returns the memory usage (in bytes) More...
 
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. More...
 
From WritableField
virtual Data_T & lvalue (int i, int j, int k)
 Write access to a voxel. The coordinates are global coordinates. More...
 
Iterators
const_iterator cbegin () const
 Const iterator to first element. "cbegin" matches the tr1 c++ standard. More...
 
const_iterator cbegin (const Box3i &subset) const
 Const iterator to first element of specific subset. More...
 
const_iterator cend () const
 Const iterator pointing one element past the last valid one. More...
 
const_iterator cend (const Box3i &subset) const
 Const iterator pointing one element past the last valid one (for a subset) More...
 
iterator begin ()
 Iterator to first element. More...
 
iterator begin (const Box3i &subset)
 Iterator to first element of specific subset. More...
 
iterator end ()
 Iterator pointing one element past the last valid one. More...
 
iterator end (const Box3i &subset)
 Iterator pointing one element past the last valid one (for a subset) More...
 
block_iterator blockBegin () const
 
block_iterator blockEnd () const
 Const iterator pointing to element one past the last valid block. More...
 
- Public Member Functions inherited from ResizableField< Data_T >
void copyFrom (typename Field< Data_T >::Ptr other)
 Copies the data from another Field, also resizes. More...
 
template<class Data_T2 >
void copyFrom (typename Field< Data_T2 >::Ptr other)
 Copies the data from another Field of another template class, also resizes. More...
 
void matchDefinition (FieldRes::Ptr fieldToMatch)
 Sets up this field so that resolution and mapping matches the other. More...
 
void setSize (const V3i &size)
 Resizes the object. More...
 
void setSize (const Box3i &extents)
 Resizes the object. More...
 
void setSize (const Box3i &extents, const Box3i &dataWindow)
 Resizes the object. More...
 
void setSize (const V3i &size, int padding)
 Resizes the object with padding. More...
 
- Public Member Functions inherited from WritableField< Data_T >
iterator begin ()
 Iterator to first element. More...
 
iterator begin (const Box3i &subset)
 Iterator to first element of specific subset. More...
 
iterator end ()
 Iterator pointing one element past the last valid one. More...
 
iterator end (const Box3i &subset)
 Iterator pointing one element past the last valid one (for a subset) More...
 
- Public Member Functions inherited from Field< Data_T >
const_iterator cbegin () const
 Const iterator to first element. "cbegin" matches the tr1 c++ standard. More...
 
const_iterator cbegin (const Box3i &subset) const
 Const iterator to first element of specific subset. More...
 
const_iterator cend () const
 Const iterator pointing one element past the last valid one. More...
 
const_iterator cend (const Box3i &subset) const
 Const iterator pointing one element past the last valid one (for a subset) More...
 
virtual std::string dataTypeString () const
 
virtual ~Field ()
 Dtor. More...
 
- Public Member Functions inherited from FieldRes
V3i const dataResolution () const
 
const Box3idataWindow () const
 Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field subclass. More...
 
const Box3iextents () 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. More...
 
 FieldRes ()
 This constructor ensures that we have a valid mapping at all times. More...
 
 FieldRes (const FieldRes &src)
 Base class copy constructor. More...
 
bool isInBounds (int i, int j, int k) const
 Returns true is the indicies are in bounds of the data window. More...
 
FieldMapping::Ptr mapping ()
 Returns a pointer to the mapping. More...
 
const FieldMapping::Ptr mapping () const
 Returns a pointer to the mapping. More...
 
virtual void mappingChanged ()
 Tells the subclass that the mapping changed. More...
 
void setMapping (FieldMapping::Ptr mapping)
 Sets the field's mapping. More...
 
- Public Member Functions inherited from FieldBase
 FieldBase ()
 Constructor. More...
 
 FieldBase (const FieldBase &)
 Copy Constructor. More...
 
virtual ~FieldBase ()
 Destructor. More...
 
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. More...
 
virtual std::string classType () const =0
 Returns the full class type string. More...
 
FieldMetadatametadata ()
 accessor to the m_metadata class More...
 
const FieldMetadatametadata () const
 Read only access to the m_metadata class. More...
 
void copyMetadata (const FieldBase &field)
 Copies the metadata from a second field. More...
 
- Public Member Functions inherited from RefBase
void ref () const
 Used by boost::intrusive_pointer. More...
 
size_t refcnt ()
 Used by boost::intrusive_pointer. More...
 
void unref () const
 Used by boost::intrusive_pointer. More...
 
WeakPtr weakPtr () const
 
 RefBase ()
 
 RefBase (const RefBase &)
 Copy constructor. More...
 
RefBaseoperator= (const RefBase &)
 Assignment operator. More...
 
virtual ~RefBase ()
 Destructor. More...
 
virtual bool checkRTTI (const char *typenameStr)=0
 This function is only implemented by concrete classes and triggers the actual RTTI check through matchRTTI();. More...
 
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. More...
 
- Public Member Functions inherited from MetadataCallback
virtual void metadataHasChanged (const std::string &)
 Alerts the callback holder that the metadata has changed. More...
 

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 Public Member Functions inherited from RefBase
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. More...
 
std::string name
 Optional name of the field. More...
 

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. More...
 
Convenience methods
void setupBlocks ()
 Initializes the block structure. Will clear any existing data. More...
 
void deallocBlock (Block &block, const Data_T &emptyValue)
 Deallocated the data of the given block and sets its empty value. More...
 

Protected Attributes

int m_blockOrder
 Block order (size = 2^blockOrder) More...
 
V3i m_blockRes
 Block array resolution. More...
 
Blockm_blocks
 Array of blocks. Not using std::vector since SparseBlock is noncopyable. More...
 
int m_blockXYSize
 Block array res.x * res.y. More...
 
Data_T m_dummy
 Dummy value used when needing to return but indicating a failed call. More...
 
int m_fileId
 File id. Used with m_fileManager if active. Otherwise -1. More...
 
SparseFileManagerm_fileManager
 Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use. More...
 
size_t m_numBlocks
 Number of blocks in field. More...
 
- 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. More...
 
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. More...
 
FieldMapping::Ptr m_mapping
 Pointer to the field's mapping. More...
 

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. More...
 
void copySparseField (const SparseField &o)
 Copies internal data, including blocks, from another SparseField, used by copy constructor and operator=. More...
 

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

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

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

Definition at line 357 of file SparseField.h.

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

Definition at line 358 of file SparseField.h.

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

Definition at line 360 of file SparseField.h.

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

Definition at line 361 of file SparseField.h.

template<class Data_T>
typedef SparseField<Data_T> SparseField< Data_T >::class_type

Definition at line 365 of file SparseField.h.

template<class Data_T>
typedef ResizableField<Data_T> SparseField< Data_T >::base
protected

Definition at line 582 of file SparseField.h.

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

template<class Data_T >
SparseField< Data_T >::SparseField ( )

Constructs an empty buffer.

Definition at line 1287 of file SparseField.h.

References SparseField< Data_T >::setupBlocks().

1288  : base(),
1290  m_blocks(NULL),
1291  m_fileManager(NULL)
1292 {
1293  setupBlocks();
1294 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
#define BLOCK_ORDER
Definition: SparseField.h:57
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1858
ResizableField< Data_T > base
Definition: SparseField.h:582
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T >
SparseField< Data_T >::SparseField ( const SparseField< Data_T > &  o)

Copy constructor.

Definition at line 1299 of file SparseField.h.

References SparseField< Data_T >::copySparseField().

1300  : base(o),
1302  m_blocks(NULL),
1304 {
1305  copySparseField(o);
1306 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
void copySparseField(const SparseField &o)
Copies internal data, including blocks, from another SparseField, used by copy constructor and operat...
Definition: SparseField.h:1341
ResizableField< Data_T > base
Definition: SparseField.h:582
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T >
SparseField< Data_T >::~SparseField ( )

Destructor.

Definition at line 1311 of file SparseField.h.

References SparseField< Data_T >::m_blocks, SparseField< Data_T >::m_fileId, SparseField< Data_T >::m_fileManager, and SparseFileManager::removeFieldFromCache().

1312 {
1313  if (m_fileManager) {
1314  // this file is dynamically managed, so we need to ensure the
1315  // cache doesn't point to this field's blocks because they are
1316  // about to be deleted
1318  }
1319  if (m_blocks) {
1320  delete[] m_blocks;
1321  }
1322 }
void removeFieldFromCache(int refIdx)
Definition: SparseFile.h:1198
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616

Member Function Documentation

template<class Data_T>
static const char* SparseField< Data_T >::staticClassName ( )
inlinestatic

Definition at line 368 of file SparseField.h.

369  {
370  return "SparseField";
371  }
template<class Data_T>
static const char* SparseField< Data_T >::staticClassType ( )
inlinestatic

Definition at line 373 of file SparseField.h.

References FieldBase::name, and RefBase::operator=().

374  {
376  }
This Field subclass stores voxel data in block-allocated arrays.
Definition: SparseField.h:350
std::string name
Optional name of the field.
Definition: Field.h:171
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.

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

1329 {
1330  if (this != &o) {
1331  this->base::operator=(o);
1332  copySparseField(o);
1333  }
1334  return *this;
1335 }
RefBase & operator=(const RefBase &)
Assignment operator.
Definition: RefCount.h:134
void copySparseField(const SparseField &o)
Copies internal data, including blocks, from another SparseField, used by copy constructor and operat...
Definition: SparseField.h:1341
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.

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

1453 {
1454  // If we're clearing, we can get rid of all current blocks
1455  setupBlocks();
1456  Block *p = m_blocks, *end = m_blocks + m_numBlocks;
1457  while (p != end) {
1458  p->emptyValue = value;
1459  ++p;
1460  }
1461 }
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1814
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
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1858
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

References SparseField< Data_T >::m_blockOrder, and SparseField< Data_T >::setupBlocks().

1467 {
1468  m_blockOrder = order;
1469  setupBlocks();
1470 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1858
template<class Data_T >
int SparseField< Data_T >::blockOrder ( ) const

Returns the block order.

Definition at line 1475 of file SparseField.h.

References SparseField< Data_T >::m_blockOrder.

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

1476 {
1477  return m_blockOrder;
1478 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
template<class Data_T >
int SparseField< Data_T >::blockSize ( ) const

Returns the block size.

Definition at line 1483 of file SparseField.h.

References SparseField< Data_T >::m_blockOrder.

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

1484 {
1485  return 1 << m_blockOrder;
1486 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
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.

References SparseField< Data_T >::applyDataWindowOffset(), SparseField< Data_T >::blockIsAllocated(), and SparseField< Data_T >::getBlockCoord().

1492 {
1493  int bi, bj, bk;
1494  applyDataWindowOffset(i, j, k);
1495  getBlockCoord(i, j, k, bi, bj, bk);
1496  return blockIsAllocated(bi, bj, bk);
1497 }
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:455
bool blockIsAllocated(int bi, int bj, int bk) const
Checks if a block is allocated.
Definition: SparseField.h:1502
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
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.

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

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

1503 {
1504  const Block &block = m_blocks[blockId(bi, bj, bk)];
1505  return block.isAllocated;
1506 }
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
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

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

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

1512 {
1513  return m_blocks[blockId(bi, bj, bk)].emptyValue;
1514 }
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
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
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

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

1521 {
1522  Block &block = m_blocks[blockId(bi, bj, bk)];
1523  if (block.isAllocated) {
1524  deallocBlock(block, val);
1525  } else {
1526  block.emptyValue = val;
1527  }
1528 }
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
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
void deallocBlock(Block &block, const Data_T &emptyValue)
Deallocated the data of the given block and sets its empty value.
Definition: SparseField.h:1970
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

References SparseField< Data_T >::m_blockRes.

1534 {
1535  return bi >= 0 && bj >= 0 && bk >= 0 &&
1536  bi < m_blockRes.x && bj < m_blockRes.y && bk < m_blockRes.z;
1537 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
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.

References SparseField< Data_T >::m_blockRes.

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

1543 {
1544  return m_blockRes;
1545 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
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
funcA function object with the method "bool check(SparseBlock&)"
Returns
Number of released blocks

Definition at line 1551 of file SparseField.h.

References SparseField< Data_T >::blockSize(), FieldRes::dataResolution(), SparseField< Data_T >::deallocBlock(), SparseField< Data_T >::m_blockRes, SparseField< Data_T >::m_blocks, and SparseField< Data_T >::m_numBlocks.

1552 {
1553  Data_T emptyValue;
1554  int numDeallocs = 0;
1555 
1556  // If the block is on the edge of the field, it may have unused
1557  // voxels, with undefined values. We need to pass the range of
1558  // valid voxels into the check function, so it only looks at valid
1559  // voxels.
1560  V3i dataRes = FieldRes::dataResolution();
1561  V3i validSize;
1562  V3i blockAllocSize(blockSize());
1563 
1564  int bx = 0, by = 0, bz = 0;
1565  for (size_t i = 0; i < m_numBlocks; ++i, ++bx) {
1566  if (bx >= m_blockRes.x) {
1567  bx = 0;
1568  ++by;
1569  if (by >= m_blockRes.y) {
1570  by = 0;
1571  ++bz;
1572  }
1573  }
1574  validSize = blockAllocSize;
1575  if (bx == m_blockRes.x-1) {
1576  validSize.x = dataRes.x - bx * blockAllocSize.x;
1577  }
1578  if (by == m_blockRes.y-1) {
1579  validSize.y = dataRes.y - by * blockAllocSize.y;
1580  }
1581  if (bz == m_blockRes.z-1) {
1582  validSize.z = dataRes.z - bz * blockAllocSize.z;
1583  }
1584 
1585  if (m_blocks[i].isAllocated) {
1586  if (func.check(m_blocks[i], emptyValue, validSize, blockAllocSize)) {
1587  deallocBlock(m_blocks[i], emptyValue);
1588  numDeallocs++;
1589  }
1590  }
1591  }
1592  return numDeallocs;
1593 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:256
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
void deallocBlock(Block &block, const Data_T &emptyValue)
Deallocated the data of the given block and sets its empty value.
Definition: SparseField.h:1970
int blockSize() const
Returns the block size.
Definition: SparseField.h:1483
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T >
int SparseField< Data_T >::blockId ( int  blockI,
int  blockJ,
int  blockK 
) const
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.

References SparseField< Data_T >::m_blockOrder.

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

1892 {
1893  assert(i >= 0);
1894  assert(j >= 0);
1895  assert(k >= 0);
1896  bi = i >> m_blockOrder;
1897  bj = j >> m_blockOrder;
1898  bk = k >> m_blockOrder;
1899 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
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.

References SparseField< Data_T >::m_blockOrder.

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

1907 {
1908  assert(i >= 0);
1909  assert(j >= 0);
1910  assert(k >= 0);
1911  vi = i & ((1 << m_blockOrder) - 1);
1912  vj = j & ((1 << m_blockOrder) - 1);
1913  vk = k & ((1 << m_blockOrder) - 1);
1914 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
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.

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

456  {
457  i -= base::m_dataWindow.min.x;
458  j -= base::m_dataWindow.min.y;
459  k -= base::m_dataWindow.min.z;
460  }
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
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.

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

464  { return m_fileManager != NULL; }
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
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.

References SparseField< Data_T >::blockId(), SparseFileManager::incBlockRef(), SparseField< Data_T >::m_fileId, and SparseField< Data_T >::m_fileManager.

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

1920 {
1922 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
void incBlockRef(int fileId, int blockIdx)
Increments the usage reference count on the specified block, to prevent it from getting unloaded whil...
Definition: SparseFile.h:1297
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
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
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.

References SparseFileManager::activateBlock(), SparseField< Data_T >::blockId(), SparseField< Data_T >::m_fileId, and SparseField< Data_T >::m_fileManager.

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

1928 {
1930 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
void activateBlock(int fileId, int blockIdx)
Called by SparseField when it&#39;s about to read from a block. This should not be called by the user...
Definition: SparseFile.h:1256
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
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
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.

References SparseField< Data_T >::blockId(), SparseFileManager::decBlockRef(), SparseField< Data_T >::m_fileId, and SparseField< Data_T >::m_fileManager.

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

1936 {
1938 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
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
void decBlockRef(int fileId, int blockIdx)
Decrements the usage reference count on the specified block, after its value is no longer being used ...
Definition: SparseFile.h:1310
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
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.

References SparseField< Data_T >::m_numBlocks.

1944 {
1945  return m_numBlocks;
1946 }
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
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.

References clipBounds(), SparseField< Data_T >::end(), indexToCoord(), SparseField< Data_T >::m_blockOrder, SparseField< Data_T >::m_blockRes, FieldRes::m_dataWindow, and detail::min().

1952 {
1953  // Block size
1954  const size_t blockSide = (1 << m_blockOrder);
1955  // Block coordinate
1956  const V3i bCoord = indexToCoord(idx, m_blockRes);
1957  // Block bbox
1958  const V3i start(bCoord * blockSide + base::m_dataWindow.min);
1959  const V3i end (start + Imath::V3i(blockSide - 1));
1960  // Bounds must be clipped against data window
1961  const Box3i unclipped(start, end);
1962  bounds = clipBounds(unclipped, base::m_dataWindow);
1963  // Whether it's a contiguous block
1964  return bounds == unclipped;
1965 }
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Definition: Field.h:1145
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1814
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i indexToCoord(const size_t idx, const V3i &res)
Definition: Field.h:1187
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
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.

References SparseField< Data_T >::fastValue().

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

1599 {
1600  return fastValue(i, j, k);
1601 }
Data_T fastValue(int i, int j, int k) const
Read access to voxel. Notice that this is non-virtual.
Definition: SparseField.h:1614
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.

References SparseField< Data_T >::blockSize(), SparseField< Data_T >::m_blockOrder, SparseField< Data_T >::m_blocks, and SparseField< Data_T >::m_numBlocks.

1709 {
1710  long long int blockSize = m_numBlocks * sizeof(Block);
1711  long long int dataSize = 0;
1712 
1713  for (size_t i = 0; i < m_numBlocks; ++i) {
1714  if (m_blocks[i].data) {
1715  dataSize += (1 << m_blockOrder << m_blockOrder << m_blockOrder) *
1716  sizeof(Data_T);
1717  }
1718  }
1719 
1720  return sizeof(*this) + dataSize + blockSize;
1721 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
int blockSize() const
Returns the block size.
Definition: SparseField.h:1483
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

References SparseField< Data_T >::blockSize(), SparseField< Data_T >::m_blockOrder, SparseField< Data_T >::m_blocks, and SparseField< Data_T >::m_numBlocks.

1727 {
1728  size_t count = 0;
1729  const size_t blockSize = (1 << m_blockOrder << m_blockOrder << m_blockOrder);
1730 
1731  for (size_t i = 0; i < m_numBlocks; ++i) {
1732  if (m_blocks[i].isAllocated) {
1733  count += blockSize;
1734  }
1735  }
1736 
1737  return count;
1738 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
int blockSize() const
Returns the block size.
Definition: SparseField.h:1483
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

References SparseField< Data_T >::fastLValue().

1607 {
1608  return fastLValue(i, j, k);
1609 }
Data_T & fastLValue(int i, int j, int k)
Write access to voxel. Notice that this is non-virtual.
Definition: SparseField.h:1653
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.

References SparseFileManager::activateBlock(), SparseField< Data_T >::applyDataWindowOffset(), SparseField< Data_T >::blockId(), SparseFileManager::decBlockRef(), Sparse::SparseBlock< Data_T >::emptyValue, SparseField< Data_T >::getBlockCoord(), SparseField< Data_T >::getVoxelInBlock(), SparseFileManager::incBlockRef(), Sparse::SparseBlock< Data_T >::isAllocated, SparseField< Data_T >::m_blockOrder, SparseField< Data_T >::m_blocks, FieldRes::m_dataWindow, SparseField< Data_T >::m_fileId, SparseField< Data_T >::m_fileManager, detail::max(), detail::min(), and Sparse::SparseBlock< Data_T >::value().

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

1615 {
1616  assert (i >= base::m_dataWindow.min.x);
1617  assert (i <= base::m_dataWindow.max.x);
1618  assert (j >= base::m_dataWindow.min.y);
1619  assert (j <= base::m_dataWindow.max.y);
1620  assert (k >= base::m_dataWindow.min.z);
1621  assert (k <= base::m_dataWindow.max.z);
1622  // Add crop window offset
1623  applyDataWindowOffset(i, j, k);
1624  // Find block coord
1625  int bi, bj, bk;
1626  getBlockCoord(i, j, k, bi, bj, bk);
1627  // Find coord in block
1628  int vi, vj, vk;
1629  getVoxelInBlock(i, j, k, vi, vj, vk);
1630  // Get the actual block
1631  int id = blockId(bi, bj, bk);
1632  const Block &block = m_blocks[id];
1633  // Check if block data is allocated
1634  if (block.isAllocated) {
1635  if (m_fileManager) {
1636  m_fileManager->incBlockRef<Data_T>(m_fileId, id);
1637  m_fileManager->activateBlock<Data_T>(m_fileId, id);
1638  Data_T tmpValue = block.value(vi, vj, vk, m_blockOrder);
1639  m_fileManager->decBlockRef<Data_T>(m_fileId, id);
1640  return tmpValue;
1641  } else {
1642  return block.value(vi, vj, vk, m_blockOrder);
1643  }
1644  } else {
1645  return block.emptyValue;
1646  }
1647 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
void activateBlock(int fileId, int blockIdx)
Called by SparseField when it&#39;s about to read from a block. This should not be called by the user...
Definition: SparseFile.h:1256
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:455
void incBlockRef(int fileId, int blockIdx)
Increments the usage reference count on the specified block, to prevent it from getting unloaded whil...
Definition: SparseFile.h:1297
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
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
T max(const T a, const T2 b)
Max operation on mixed types.
Definition: FieldSampler.h:32
void decBlockRef(int fileId, int blockIdx)
Decrements the usage reference count on the specified block, after its value is no longer being used ...
Definition: SparseFile.h:1310
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
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
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

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

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

1654 {
1655  assert (i >= base::m_dataWindow.min.x);
1656  assert (i <= base::m_dataWindow.max.x);
1657  assert (j >= base::m_dataWindow.min.y);
1658  assert (j <= base::m_dataWindow.max.y);
1659  assert (k >= base::m_dataWindow.min.z);
1660  assert (k <= base::m_dataWindow.max.z);
1661 
1662  if (m_fileManager) {
1663  assert(false && "Called fastLValue() on a dynamic-read sparse field");
1664  Msg::print(Msg::SevWarning, "Called fastLValue() on a dynamic-read "
1665  "sparse field");
1666  return m_dummy;
1667  }
1668 
1669  // Add crop window offset
1670  applyDataWindowOffset(i, j, k);
1671  // Find block coord
1672  int bi, bj, bk;
1673  getBlockCoord(i, j, k, bi, bj, bk);
1674  // Find coord in block
1675  int vi, vj, vk;
1676  getVoxelInBlock(i, j, k, vi, vj, vk);
1677  // Get the actual block
1678  int id = blockId(bi, bj, bk);
1679  Block &block = m_blocks[id];
1680  // If block is allocated, return a reference to the data
1681  if (block.isAllocated) {
1682  return block.value(vi, vj, vk, m_blockOrder);
1683  } else {
1684  // ... Otherwise, allocate block
1685  size_t blockSize = 1 << m_blockOrder << m_blockOrder << m_blockOrder;
1686  block.resize(blockSize);
1687  return block.value(vi, vj, vk, m_blockOrder);
1688  }
1689 }
Data_T & value(int i, int j, int k, int blockOrder)
Gets the value of a given voxel.
Definition: SparseField.h:249
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:455
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
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
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
T max(const T a, const T2 b)
Max operation on mixed types.
Definition: FieldSampler.h:32
Data_T m_dummy
Dummy value used when needing to return but indicating a failed call.
Definition: SparseField.h:627
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
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
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
int blockSize() const
Returns the block size.
Definition: SparseField.h:1483
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

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

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

1695 {
1696  int id = blockId(bi, bj, bk);
1697  const Block &block = m_blocks[id];
1698  if (block.isAllocated) {
1699  return block.data;
1700  } else {
1701  return NULL;
1702  }
1703 }
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
Data_T * data
Pointer to data. Null if block is unallocated.
Definition: SparseField.h:311
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T>
virtual FieldBase::Ptr SparseField< Data_T >::clone ( ) const
inlinevirtual

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.

518  { return Ptr(new SparseField(*this)); }
boost::intrusive_ptr< SparseField > Ptr
Definition: SparseField.h:357
SparseField()
Constructs an empty buffer.
Definition: SparseField.h:1287
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.

References SparseField< Data_T >::cend(), FieldRes::dataResolution(), SparseField< Data_T >::m_blockOrder, FieldRes::m_dataWindow, and detail::min().

1745 {
1746  if (FieldRes::dataResolution() == V3i(0))
1747  return cend();
1748  return const_iterator(*this, base::m_dataWindow, base::m_dataWindow.min,
1749  m_blockOrder);
1750 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:256
const_iterator cend() const
Const iterator pointing one element past the last valid one.
Definition: SparseField.h:1767
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
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.

References SparseField< Data_T >::cend(), and SparseField< Data_T >::m_blockOrder.

1757 {
1758  if (subset.isEmpty())
1759  return cend(subset);
1760  return const_iterator(*this, subset, subset.min, m_blockOrder);
1761 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
const_iterator cend() const
Const iterator pointing one element past the last valid one.
Definition: SparseField.h:1767
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.

References SparseField< Data_T >::m_blockOrder, FieldRes::m_dataWindow, and detail::min().

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

1768 {
1769  return const_iterator(*this, base::m_dataWindow,
1771  base::m_dataWindow.min.y,
1772  base::m_dataWindow.max.z + 1),
1773  m_blockOrder);
1774 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
Imath::V3i V3i
Definition: SpiMathLib.h:71
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
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.

References SparseField< Data_T >::m_blockOrder.

1781 {
1782  return const_iterator(*this, subset,
1783  V3i(subset.min.x,
1784  subset.min.y,
1785  subset.max.z + 1), m_blockOrder);
1786 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Imath::V3i V3i
Definition: SpiMathLib.h:71
template<class Data_T >
SparseField< Data_T >::iterator SparseField< Data_T >::begin ( )

Iterator to first element.

Definition at line 1792 of file SparseField.h.

References FieldRes::dataResolution(), SparseField< Data_T >::end(), SparseField< Data_T >::m_blockOrder, FieldRes::m_dataWindow, and detail::min().

1793 {
1794  if (FieldRes::dataResolution() == V3i(0))
1795  return end();
1796  return iterator(*this, base::m_dataWindow,
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1814
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:256
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
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.

References SparseField< Data_T >::end(), and SparseField< Data_T >::m_blockOrder.

1804 {
1805  if (subset.isEmpty())
1806  return end(subset);
1807  return iterator(*this, subset, subset.min, m_blockOrder);
1808 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1814
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.

References SparseField< Data_T >::m_blockOrder, FieldRes::m_dataWindow, and detail::min().

Referenced by SparseField< Data_T >::begin(), SparseField< Data_T >::clear(), and SparseField< Data_T >::getGrainBounds().

1815 {
1816  return iterator(*this, base::m_dataWindow,
1818  base::m_dataWindow.min.y,
1819  base::m_dataWindow.max.z + 1), m_blockOrder);
1820 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
Imath::V3i V3i
Definition: SpiMathLib.h:71
T min(const T a, const T2 b)
Min operation on mixed types.
Definition: FieldSampler.h:25
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.

References SparseField< Data_T >::m_blockOrder.

1827 {
1828  return iterator(*this, subset,
1829  V3i(subset.min.x, subset.min.y, subset.max.z + 1),
1830  m_blockOrder);
1831 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Imath::V3i V3i
Definition: SpiMathLib.h:71
template<class Data_T >
SparseField< Data_T >::block_iterator SparseField< Data_T >::blockBegin ( ) const

Definition at line 1837 of file SparseField.h.

References SparseField< Data_T >::blockEnd(), FieldRes::dataResolution(), and SparseField< Data_T >::m_blockRes.

1838 {
1839  if (FieldRes::dataResolution() == V3i(0))
1840  return blockEnd();
1841  return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)),
1842  V3i(0));
1843 }
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:256
block_iterator blockEnd() const
Const iterator pointing to element one past the last valid block.
Definition: SparseField.h:1849
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.

References SparseField< Data_T >::m_blockRes.

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

1850 {
1851  return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)),
1852  V3i(0, 0, m_blockRes.z));
1853 }
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
Imath::V3i V3i
Definition: SpiMathLib.h:71
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.

References SparseFileManager::getNextId(), SparseField< Data_T >::m_fileId, SparseField< Data_T >::m_fileManager, SparseField< Data_T >::m_numBlocks, SparseFileManager::reference(), and SparseFileManager::singleton().

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

1384 {
1386  m_fileId = m_fileManager->getNextId<Data_T>(filename, layerPath);
1387  // Set up the manager data
1388  SparseFile::Reference<Data_T> *reference =
1389  m_fileManager->reference<Data_T>(m_fileId);
1390  reference->valuesPerBlock = valuesPerBlock;
1391  reference->numVoxels = numVoxels;
1392  reference->occupiedBlocks = occupiedBlocks;
1393  reference->setNumBlocks(m_numBlocks);
1394 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
int getNextId(const std::string filename, const std::string layerPath)
Returns the id of the next cache item. This is stored in the SparseField in order to reference its fi...
Definition: SparseFile.h:1181
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
SparseFile::Reference< Data_T > * reference(int index)
Returns a reference to the Reference object with the given index.
Definition: SparseFile.h:1247
static SparseFileManager & singleton()
Returns a reference to the singleton instance.
Definition: SparseFile.cpp:66
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
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.

References SparseFile::Reference< Data_T >::blocks, SparseFile::Reference< Data_T >::fileBlockIndices, SparseField< Data_T >::m_blocks, SparseField< Data_T >::m_fileId, SparseField< Data_T >::m_fileManager, SparseField< Data_T >::m_numBlocks, and SparseFileManager::reference().

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

1414 {
1415  if (!m_fileManager || m_fileId < 0) return;
1416 
1417  SparseFile::Reference<Data_T> *reference =
1418  m_fileManager->reference<Data_T>(m_fileId);
1419 
1420 #if F3D_NO_BLOCKS_ARRAY
1421  std::vector<int>::iterator fb = reference->fileBlockIndices.begin();
1422  reference->blocks = m_blocks;
1423  int nextBlockIdx = 0;
1424  for (size_t i = 0; i < m_numBlocks; ++i, ++fb) {
1425  if (m_blocks[i].isAllocated) {
1426  *fb = nextBlockIdx;
1427  nextBlockIdx++;
1428  } else {
1429  *fb = -1;
1430  }
1431  }
1432 #else
1433  std::vector<int>::iterator fb = reference->fileBlockIndices.begin();
1435  reference->blocks.begin();
1436  int nextBlockIdx = 0;
1437  for (size_t i = 0; i < m_numBlocks; ++i, ++fb, ++bp) {
1438  if (m_blocks[i].isAllocated) {
1439  *fb = nextBlockIdx;
1440  *bp = m_blocks + i;
1441  nextBlockIdx++;
1442  } else {
1443  *fb = -1;
1444  }
1445  }
1446 #endif
1447 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
std::vector< int > fileBlockIndices
Index in file for each block.
Definition: SparseFile.h:134
BlockPtrs blocks
Pointers to each block. This is so we can go in and manipulate them as we please. ...
Definition: SparseFile.h:140
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
SparseFile::Reference< Data_T > * reference(int index)
Returns a reference to the Reference object with the given index.
Definition: SparseFile.h:1247
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T>
virtual void SparseField< Data_T >::sizeChanged ( )
inlineprotectedvirtual

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.

588  {
589  // Call base class
591  setupBlocks();
592  }
virtual void sizeChanged()
Subclasses should re-implement this if they need to perform memory allocations, etc. every time the size of the storage changes.
Definition: Field.h:901
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1858
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.

References SparseField< Data_T >::blockRes(), detail::ceil(), SparseField< Data_T >::m_blockOrder, SparseField< Data_T >::m_blockRes, SparseField< Data_T >::m_blocks, SparseField< Data_T >::m_blockXYSize, FieldRes::m_dataWindow, and SparseField< Data_T >::m_numBlocks.

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

1859 {
1860  // Do calculation in floating point so we can round up later
1861  V3f res(base::m_dataWindow.size() + V3i(1));
1862  V3f blockRes(res / (1 << m_blockOrder));
1863  blockRes.x = ceil(blockRes.x);
1864  blockRes.y = ceil(blockRes.y);
1865  blockRes.z = ceil(blockRes.z);
1866  V3i intBlockRes(static_cast<int>(blockRes.x),
1867  static_cast<int>(blockRes.y),
1868  static_cast<int>(blockRes.z));
1869  m_blockRes = intBlockRes;
1871  if (m_blocks) {
1872  delete[] m_blocks;
1873  }
1874  m_numBlocks = intBlockRes.x * intBlockRes.y * intBlockRes.z;
1875  m_blocks = new Block[m_numBlocks];
1876 }
V3i blockRes() const
Returns the resolution of the block array.
Definition: SparseField.h:1542
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:614
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:310
Imath::V3i V3i
Definition: SpiMathLib.h:71
Imath::V3f V3f
Definition: SpiMathLib.h:73
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:583
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
FIELD3D_VEC3_T< T > ceil(const FIELD3D_VEC3_T< T > &v)
Ceil function for Vec3.
Definition: CoordSys.h:114
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

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

Referenced by SparseField< Data_T >::releaseBlocks(), and SparseField< Data_T >::setBlockEmptyValue().

1971 {
1972  block.isAllocated = false;
1974  block.clear();
1975  block.emptyValue = emptyValue;
1976 }
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.

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

Referenced by SparseField< Data_T >::operator=(), and SparseField< Data_T >::SparseField().

1342 {
1344  if (o.m_fileManager) {
1345  // allocate m_blocks, sets m_blockRes, m_blockXYSize, m_blocks
1346  setupBlocks();
1348  SparseFile::Reference<Data_T> *oldReference =
1349  m_fileManager->reference<Data_T>(o.m_fileId);
1350  addReference(oldReference->filename, oldReference->layerPath,
1351  oldReference->valuesPerBlock,
1352  oldReference->numVoxels,
1353  oldReference->occupiedBlocks);
1354  copyBlockStates(o);
1356  } else {
1357  // directly copy all values and blocks from the source, no extra setup
1358  m_blockRes = o.m_blockRes;
1360  if (m_blocks) {
1361  delete[] m_blocks;
1362  }
1364  m_blocks = new Block[m_numBlocks];
1365  for (size_t i = 0; i < m_numBlocks; ++i) {
1368  m_blocks[i].copy(o.m_blocks[i],
1370  }
1371  m_fileId = -1;
1372  m_fileManager = NULL;
1373  }
1374 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:614
void setupReferenceBlocks()
Internal function to setup the Reference&#39;s block pointers, for use with dynamic reading.
Definition: SparseField.h:1413
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:610
std::string layerPath
Definition: SparseFile.h:127
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
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
void copy(const SparseBlock &other, size_t n)
Copy data from another block.
Definition: SparseField.h:285
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1858
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
std::string filename
Definition: SparseFile.h:126
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< Data_T > Block
Definition: SparseField.h:583
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
SparseFile::Reference< Data_T > * reference(int index)
Returns a reference to the Reference object with the given index.
Definition: SparseFile.h:1247
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
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.

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

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

1400 {
1401  if (m_numBlocks != o.m_numBlocks) return;
1402 
1403  for (size_t i = 0; i < m_numBlocks; ++i) {
1406  m_blocks[i].clear();
1407  }
1408 }
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
void clear()
Remove data.
Definition: SparseField.h:273
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616

Friends And Related Function Documentation

template<class Data_T>
friend class SparseFieldIO
friend

Definition at line 578 of file SparseField.h.

Member Data Documentation

template<class Data_T>
SparseField< Data_T >::DEFINE_FIELD_RTTI_CONCRETE_CLASS

Definition at line 366 of file SparseField.h.

template<class Data_T>
SparseField< Data_T >::FIELD3D_CLASSNAME_CLASSTYPE_IMPLEMENTATION

Definition at line 515 of file SparseField.h.

template<class Data_T>
int SparseField< Data_T >::m_blockXYSize
protected
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 SparseField< Data_T >::fastLValue().

template<class Data_T>
TemplatedFieldType<SparseField<Data_T> > SparseField< Data_T >::ms_classType
staticprivate

Definition at line 633 of file SparseField.h.


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