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.
 
typedef std::vector< PtrVec
 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< 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 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.
 
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.
 
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 Box3idataWindow () const
 Returns the data window. Any coordinate inside this window is safe to pass to value() in the Field subclass.
 
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.
 
 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.
 
FieldMetadatametadata ()
 accessor to the m_metadata class
 
const FieldMetadatametadata () 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.
 
RefBaseoperator= (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 charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from ResizableField< Data_T >
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from WritableField< Data_T >
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from Field< Data_T >
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from FieldRes
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from FieldBase
static const charstaticClassName ()
 
static const charstaticClassType ()
 
- Static Public Member Functions inherited from RefBase
static const charstaticClassType ()
 

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.
 
Blockm_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.
 
SparseFileManagerm_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.

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

References SparseField< Data_T >::setupBlocks().

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

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

1300 : base(o),
1301 m_blockOrder(o.m_blockOrder),
1302 m_blocks(NULL),
1303 m_fileManager(o.m_fileManager)
1304{
1306}
void copySparseField(const SparseField &o)
Copies internal data, including blocks, from another SparseField, used by copy constructor and operat...

References SparseField< Data_T >::copySparseField(), and FIELD3D_MTX_T.

◆ ~SparseField()

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

Destructor.

Definition at line 1311 of file SparseField.h.

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}
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
void removeFieldFromCache(int refIdx)

Member Function Documentation

◆ staticClassName()

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 }

◆ staticClassType()

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

Definition at line 373 of file SparseField.h.

374 {
376 }
std::string name
Optional name of the field.
Definition Field.h:171
This Field subclass stores voxel data in block-allocated arrays.

References FieldBase::name.

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

1329{
1330 if (this != &o) {
1331 this->base::operator=(o);
1333 }
1334 return *this;
1335}
RefBase & operator=(const RefBase &)
Assignment operator.
Definition RefCount.h:134

References FIELD3D_MTX_T.

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

1453{
1454 // If we're clearing, we can get rid of all current blocks
1455 setupBlocks();
1457 while (p != end) {
1458 p->emptyValue = value;
1459 ++p;
1460 }
1461}
Sparse::SparseBlock< Data_T > Block
iterator end()
Iterator pointing one element past the last valid one.
size_t m_numBlocks
Number of blocks in field.
virtual Data_T value(int i, int j, int k) const
Read access to a voxel. The coordinates are in integer voxel space .
Data_T emptyValue
The value to use if the block isn't allocated. We allow setting this per block so that we for example...

References Sparse::SparseBlock< Data_T >::emptyValue, and FIELD3D_MTX_T.

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

1467{
1469 setupBlocks();
1470}

References FIELD3D_MTX_T.

◆ blockOrder()

template<class Data_T >
int SparseField< Data_T >::blockOrder ( ) const

Returns the block order.

Definition at line 1475 of file SparseField.h.

1476{
1477 return m_blockOrder;
1478}

Referenced by 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.

1484{
1485 return 1 << m_blockOrder;
1486}

Referenced by SparseField< Data_T >::block_iterator::recomputeBlockBoundingBox().

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

1492{
1493 int bi, bj, bk;
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.
bool blockIsAllocated(int bi, int bj, int bk) const
Checks if a block is allocated.
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.

References FIELD3D_MTX_T.

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

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.
bool isAllocated
Whether the block is allocated or not.

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

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

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

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

References FIELD3D_MTX_T.

Referenced by 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.

1521{
1523 if (block.isAllocated) {
1525 } else {
1526 block.emptyValue = val;
1527 }
1528}
void deallocBlock(Block &block, const Data_T &emptyValue)
Deallocated the data of the given block and sets its empty value.

References FIELD3D_MTX_T.

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

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.

References FIELD3D_MTX_T.

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

1543{
1544 return m_blockRes;
1545}

◆ 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
funcA function object with the method "bool check(SparseBlock&)"
Returns
Number of released blocks

Definition at line 1551 of file SparseField.h.

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.
1561 V3i validSize;
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 }
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}
Imath::V3i V3i
Definition SpiMathLib.h:71
V3i const dataResolution() const
Definition Field.h:256
int blockSize() const
Returns the block size.

References FieldRes::dataResolution(), and FIELD3D_MTX_T.

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

1882{
1883 return blockK * m_blockXYSize + blockJ * m_blockRes.x + blockI;
1884}
int m_blockXYSize
Block array res.x * res.y.

References FIELD3D_MTX_T.

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

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

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}

References FIELD3D_MTX_T.

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

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

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}

References FIELD3D_MTX_T.

Referenced by 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.

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....
Definition Field.h:310

References FIELD3D_MTX_T, and FieldRes::m_dataWindow.

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

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

464 { return m_fileManager != NULL; }

References FIELD3D_MTX_T, and SparseField< Data_T >::m_fileManager.

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.

1920{
1922}
void incBlockRef(int fileId, int blockIdx)
Increments the usage reference count on the specified block, to prevent it from getting unloaded whil...

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.

1928{
1930}
void activateBlock(int fileId, int blockIdx)
Called by SparseField when it's about to read from a block. This should not be called by the user,...

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.

1936{
1938}
void decBlockRef(int fileId, int blockIdx)
Decrements the usage reference count on the specified block, after its value is no longer being used ...

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.

1944{
1945 return m_numBlocks;
1946}

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

1952{
1953 // Block size
1954 const size_t blockSide = (1 << m_blockOrder);
1955 // Block coordinate
1957 // Block bbox
1959 const V3i end (start + Imath::V3i(blockSide - 1));
1960 // Bounds must be clipped against data window
1961 const Box3i unclipped(start, end);
1963 // Whether it's a contiguous block
1964 return bounds == unclipped;
1965}
Box3i clipBounds(const Box3i &bbox, const Box3i &bounds)
Definition Field.h:1145
V3i indexToCoord(const size_t idx, const V3i &res)
Definition Field.h:1187
Imath::Box3i Box3i
Definition SpiMathLib.h:77

References clipBounds(), FIELD3D_MTX_T, and indexToCoord().

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

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.

References FIELD3D_MTX_T.

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

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) {
1716 sizeof(Data_T);
1717 }
1718 }
1719
1720 return sizeof(*this) + dataSize + blockSize;
1721}

References FIELD3D_MTX_T.

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

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}

References FIELD3D_MTX_T.

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

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.

References FIELD3D_MTX_T.

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

1615{
1622 // Add crop window offset
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}
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.
T max(const T a, const T2 b)
Max operation on mixed types.
T min(const T a, const T2 b)
Min operation on mixed types.

References FIELD3D_MTX_T, and Sparse::SparseBlock< Data_T >::value().

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

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

1654{
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
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 m_dummy
Dummy value used when needing to return but indicating a failed call.
@ SevWarning
Definition Log.h:68
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
Data_T & value(int i, int j, int k, int blockOrder)
Gets the value of a given voxel.

References FIELD3D_MTX_T, Msg::print(), Msg::SevWarning, and Sparse::SparseBlock< Data_T >::value().

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

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}
Data_T * data
Pointer to data. Null if block is unallocated.

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

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

◆ clone()

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)); }
SparseField()
Constructs an empty buffer.
boost::intrusive_ptr< SparseField > Ptr

References SparseField< Data_T >::SparseField().

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

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}
const_iterator cend() const
Const iterator pointing one element past the last valid one.

References FieldRes::dataResolution().

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

1757{
1758 if (subset.isEmpty())
1759 return cend(subset);
1760 return const_iterator(*this, subset, subset.min, m_blockOrder);
1761}

References FIELD3D_MTX_T.

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

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}

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

1781{
1782 return const_iterator(*this, subset,
1783 V3i(subset.min.x,
1784 subset.min.y,
1785 subset.max.z + 1), m_blockOrder);
1786}

References FIELD3D_MTX_T.

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

1793{
1794 if (FieldRes::dataResolution() == V3i(0))
1795 return end();
1796 return iterator(*this, base::m_dataWindow,

References FieldRes::dataResolution().

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

1804{
1805 if (subset.isEmpty())
1806 return end(subset);
1807 return iterator(*this, subset, subset.min, m_blockOrder);
1808}

References FIELD3D_MTX_T.

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

1815{
1816 return iterator(*this, base::m_dataWindow,
1818 base::m_dataWindow.min.y,
1819 base::m_dataWindow.max.z + 1), m_blockOrder);
1820}

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

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

References FIELD3D_MTX_T.

◆ blockBegin()

template<class Data_T >
SparseField< Data_T >::block_iterator SparseField< Data_T >::blockBegin ( ) const

Definition at line 1837 of file SparseField.h.

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}
block_iterator blockEnd() const
Const iterator pointing to element one past the last valid block.

References FieldRes::dataResolution().

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

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

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

1384{
1386 m_fileId = m_fileManager->getNextId<Data_T>(filename, layerPath);
1387 // Set up the manager data
1390 reference->valuesPerBlock = valuesPerBlock;
1391 reference->numVoxels = numVoxels;
1392 reference->occupiedBlocks = occupiedBlocks;
1393 reference->setNumBlocks(m_numBlocks);
1394}
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...
static SparseFileManager & singleton()
Returns a reference to the singleton instance.
SparseFile::Reference< Data_T > * reference(int index)
Returns a reference to the Reference object with the given index.

References SparseFileManager::singleton(), and SparseFile::Reference< Data_T >::valuesPerBlock.

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

1414{
1415 if (!m_fileManager || m_fileId < 0) return;
1416
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}
BlockPtrs blocks
Pointers to each block. This is so we can go in and manipulate them as we please.
Definition SparseFile.h:141
std::vector< int > fileBlockIndices
Index in file for each block.
Definition SparseFile.h:135

References SparseFile::Reference< Data_T >::blocks, FIELD3D_MTX_T, and SparseFile::Reference< Data_T >::fileBlockIndices.

◆ sizeChanged()

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....
Definition Field.h:901

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

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

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));
1871 if (m_blocks) {
1872 delete[] m_blocks;
1873 }
1875 m_blocks = new Block[m_numBlocks];
1876}
Imath::V3f V3f
Definition SpiMathLib.h:73
V3i blockRes() const
Returns the resolution of the block array.
FIELD3D_VEC3_T< T > ceil(const FIELD3D_VEC3_T< T > &v)
Ceil function for Vec3.
Definition CoordSys.h:114

References FIELD3D_MTX_T.

Referenced by SparseField< Data_T >::sizeChanged(), and SparseField< Data_T >::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.

1971{
1972 block.isAllocated = false;
1974 block.clear();
1975 block.emptyValue = emptyValue;
1976}

References FIELD3D_MTX_T.

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

1342{
1343 m_blockOrder = o.m_blockOrder;
1344 if (o.m_fileManager) {
1345 // allocate m_blocks, sets m_blockRes, m_blockXYSize, m_blocks
1346 setupBlocks();
1347 m_fileManager = o.m_fileManager;
1349 m_fileManager->reference<Data_T>(o.m_fileId);
1350 addReference(oldReference->filename, oldReference->layerPath,
1351 oldReference->valuesPerBlock,
1352 oldReference->numVoxels,
1353 oldReference->occupiedBlocks);
1356 } else {
1357 // directly copy all values and blocks from the source, no extra setup
1358 m_blockRes = o.m_blockRes;
1359 m_blockXYSize = o.m_blockXYSize;
1360 if (m_blocks) {
1361 delete[] m_blocks;
1362 }
1363 m_numBlocks = o.m_numBlocks;
1364 m_blocks = new Block[m_numBlocks];
1365 for (size_t i = 0; i < m_numBlocks; ++i) {
1366 m_blocks[i].isAllocated = o.m_blocks[i].isAllocated;
1367 m_blocks[i].emptyValue = o.m_blocks[i].emptyValue;
1368 m_blocks[i].copy(o.m_blocks[i],
1370 }
1371 m_fileId = -1;
1373 }
1374}
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.
void setupReferenceBlocks()
Internal function to setup the Reference's block pointers, for use with dynamic reading.
void copyBlockStates(const SparseField< Data_T > &o)
Internal function to copy empty values and allocated flags, without copying data, used when copying a...
void copy(const SparseBlock &other, size_t n)
Copy data from another block.

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

Referenced by SparseField< Data_T >::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.

1400{
1401 if (m_numBlocks != o.m_numBlocks) return;
1402
1403 for (size_t i = 0; i < m_numBlocks; ++i) {
1404 m_blocks[i].isAllocated = o.m_blocks[i].isAllocated;
1405 m_blocks[i].emptyValue = o.m_blocks[i].emptyValue;
1406 m_blocks[i].clear();
1407 }
1408}
void clear()
Remove data.

References FIELD3D_MTX_T.

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

◆ m_blockRes

template<class Data_T >
V3i SparseField< Data_T >::m_blockRes
protected

Block array resolution.

Definition at line 612 of file SparseField.h.

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

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

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

◆ 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 SparseField< Data_T >::isDynamicLoad().

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

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

◆ ms_classType

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: