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

Classes

class  block_iterator
 
class  const_iterator
 
class  iterator
 

Public Types

typedef SparseField< Data_T > class_type
 
typedef
CubicGenericFieldInterp
< SparseField< Data_T > > 
CubicInterp
 
typedef
LinearGenericFieldInterp
< SparseField< Data_T > > 
LinearInterp
 
typedef boost::intrusive_ptr
< SparseField
Ptr
 
typedef std::vector< PtrVec
 
- Public Types inherited from ResizableField< Data_T >
typedef ResizableField< Data_T > class_type
 
typedef boost::intrusive_ptr
< ResizableField
Ptr
 
- Public Types inherited from WritableField< Data_T >
typedef WritableField< Data_T > class_type
 
typedef boost::intrusive_ptr
< WritableField
Ptr
 
- Public Types inherited from Field< Data_T >
typedef Field< Data_T > class_type
 
typedef boost::intrusive_ptr
< Field
Ptr
 
typedef Data_T value_type
 Allows us to reference the template class. 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
< FieldRes
Ptr
 
typedef std::vector< PtrVec
 
- Public Types inherited from FieldBase
typedef FieldBase class_type
 
typedef boost::intrusive_ptr
< FieldBase
Ptr
 
- Public Types inherited from RefBase
typedef boost::intrusive_ptr
< RefBase
Ptr
 

Public Member Functions

void addReference (const std::string &filename, const std::string &layerPath, int valuesPerBlock, 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...
 
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...
 
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...
 
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...
 
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...
 
From WritableField
virtual Data_T & lvalue (int i, int j, int k)
 Write access to a voxel. The coordinates are global coordinates. More...
 
From FieldBase
virtual std::string className () const
 Returns the class name of the object. Used by the class pool and when writing the data to disk. More...
 
virtual FieldBase::Ptr clone () const
 Returns a pointer to a copy of the field, pure virtual so ensure derived classes properly implement it. 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...
 
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...
 
FieldMetadata< FieldBase > & metadata ()
 accessor to the m_metadata class More...
 
const FieldMetadata< FieldBase > & metadata () const
 Read only access to the m_metadata class. More...
 
virtual void metadataHasChanged (const std::string &)
 This function should implemented by concrete classes to get the callback when metadata changes. 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...
 
 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...
 

Static Public Member Functions

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

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...
 
std::vector< Blockm_blocks
 Information for all blocks in the field. 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...
 
- 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
 

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 160 of file SparseField.h.

Member Typedef Documentation

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

Definition at line 167 of file SparseField.h.

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

Definition at line 168 of file SparseField.h.

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

Definition at line 170 of file SparseField.h.

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

Definition at line 171 of file SparseField.h.

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

Definition at line 175 of file SparseField.h.

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

Definition at line 366 of file SparseField.h.

template<class Data_T>
typedef Sparse::SparseBlock<Data_T> SparseField< Data_T >::Block
protected

Definition at line 367 of file SparseField.h.

Constructor & Destructor Documentation

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

Constructs an empty buffer.

Definition at line 1014 of file SparseField.h.

References SparseField< Data_T >::setupBlocks().

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

1015  : base(),
1017  m_fileManager(NULL)
1018 {
1019  setupBlocks();
1020 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
#define BLOCK_ORDER
Definition: SparseField.h:56
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1535
ResizableField< Data_T > base
Definition: SparseField.h:366
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
template<class Data_T >
SparseField< Data_T >::SparseField ( const SparseField< Data_T > &  o)

Copy constructor.

Definition at line 1025 of file SparseField.h.

References SparseField< Data_T >::copySparseField().

1025  :
1026  base(o)
1027 {
1028  copySparseField(o);
1029 }
void copySparseField(const SparseField &o)
Copies internal data, including blocks, from another SparseField, used by copy constructor and operat...
Definition: SparseField.h:1061
ResizableField< Data_T > base
Definition: SparseField.h:366
template<class Data_T >
SparseField< Data_T >::~SparseField ( )

Destructor.

Definition at line 1034 of file SparseField.h.

1035 {
1036  if (m_fileManager) {
1037  // this file is dynamically managed, so we need to ensure the
1038  // cache doesn't point to this field's blocks because they are
1039  // about to be deleted
1041  }
1042 }
void removeFieldFromCache(int refIdx)
Definition: SparseFile.h:968
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404

Member Function Documentation

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

Definition at line 178 of file SparseField.h.

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

179  {
180  return "SparseField";
181  }
template<class Data_T>
static const char* SparseField< Data_T >::classType ( )
inlinestatic

Definition at line 183 of file SparseField.h.

References FieldBase::name.

184  {
186  }
This Field subclass stores voxel data in block-allocated arrays.
Definition: SparseField.h:160
std::string name
Optional name of the field.
Definition: Field.h:173
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 1048 of file SparseField.h.

1049 {
1050  if (this != &o) {
1051  this->base::operator=(o);
1052  copySparseField(o);
1053  }
1054  return *this;
1055 }
RefBase & operator=(const RefBase &)
Assignment operator.
Definition: RefCount.h:113
void copySparseField(const SparseField &o)
Copies internal data, including blocks, from another SparseField, used by copy constructor and operat...
Definition: SparseField.h:1061
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 1158 of file SparseField.h.

1159 {
1160  // If we're clearing, we can get rid of all current blocks
1161  setupBlocks();
1162  // Then just fill in the default values
1163  typename std::vector<Block>::iterator i;
1164  typename std::vector<Block>::iterator end;
1165  for (i = m_blocks.begin(), end = m_blocks.end(); i != end; ++i) {
1166  i->emptyValue = value;
1167  }
1168 }
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1491
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:1306
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1535
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 1173 of file SparseField.h.

Referenced by SparseFieldIO::read().

1174 {
1175  m_blockOrder = order;
1176  setupBlocks();
1177 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1535
template<class Data_T >
int SparseField< Data_T >::blockOrder ( ) const

Returns the block order.

Definition at line 1182 of file SparseField.h.

1183 {
1184  return m_blockOrder;
1185 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
template<class Data_T >
int SparseField< Data_T >::blockSize ( ) const

Returns the block size.

Definition at line 1190 of file SparseField.h.

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

1191 {
1192  return 1 << m_blockOrder;
1193 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
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 1198 of file SparseField.h.

1199 {
1200  int bi, bj, bk;
1201  applyDataWindowOffset(i, j, k);
1202  getBlockCoord(i, j, k, bi, bj, bk);
1203  return blockIsAllocated(bi, bj, bk);
1204 }
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:265
bool blockIsAllocated(int bi, int bj, int bk) const
Checks if a block is allocated.
Definition: SparseField.h:1209
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:1567
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 1209 of file SparseField.h.

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

1210 {
1211  const Block &block = m_blocks[blockId(bi, bj, bk)];
1212  return block.isAllocated;
1213 }
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1558
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:367
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 1218 of file SparseField.h.

1219 {
1220  return m_blocks[blockId(bi, bj, bk)].emptyValue;
1221 }
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1558
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
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 1226 of file SparseField.h.

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

1228 {
1229  Block &block = m_blocks[blockId(bi, bj, bk)];
1230  if (block.isAllocated) {
1231  deallocBlock(block, val);
1232  } else {
1233  block.emptyValue = val;
1234  }
1235 }
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1558
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:367
void deallocBlock(Block &block, const Data_T &emptyValue)
Deallocated the data of the given block and sets its empty value.
Definition: SparseField.h:1596
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 1240 of file SparseField.h.

1241 {
1242  return bi >= 0 && bj >= 0 && bk >= 0 &&
1243  bi < m_blockRes.x && bj < m_blockRes.y && bk < m_blockRes.z;
1244 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
template<class Data_T >
V3i SparseField< Data_T >::blockRes ( ) const

Returns the resolution of the block array.

Definition at line 1249 of file SparseField.h.

1250 {
1251  return m_blockRes;
1252 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
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 1258 of file SparseField.h.

References FieldRes::dataResolution().

1259 {
1260  Data_T emptyValue;
1261  int numDeallocs = 0;
1262  typename std::vector<Block>::iterator i;
1263 
1264  // If the block is on the edge of the field, it may have unused
1265  // voxels, with undefined values. We need to pass the range of
1266  // valid voxels into the check function, so it only looks at valid
1267  // voxels.
1268  V3i dataRes = FieldRes::dataResolution();
1269  V3i validSize;
1270  V3i blockAllocSize(blockSize());
1271  int bx, by, bz;
1272 
1273  for (i = m_blocks.begin(), bx=0, by=0, bz=0; i != m_blocks.end(); ++i, ++bx) {
1274  if (bx >= m_blockRes.x) {
1275  bx = 0;
1276  ++by;
1277  if (by >= m_blockRes.y) {
1278  by = 0;
1279  ++bz;
1280  }
1281  }
1282  validSize = blockAllocSize;
1283  if (bx == m_blockRes.x-1) {
1284  validSize.x = dataRes.x - bx * blockAllocSize.x;
1285  }
1286  if (by == m_blockRes.y-1) {
1287  validSize.y = dataRes.y - by * blockAllocSize.y;
1288  }
1289  if (bz == m_blockRes.z-1) {
1290  validSize.z = dataRes.z - bz * blockAllocSize.z;
1291  }
1292 
1293  if (i->isAllocated) {
1294  if (func.check(*i, emptyValue, validSize, blockAllocSize)) {
1295  deallocBlock(*i, emptyValue);
1296  numDeallocs++;
1297  }
1298  }
1299  }
1300  return numDeallocs;
1301 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:258
void deallocBlock(Block &block, const Data_T &emptyValue)
Deallocated the data of the given block and sets its empty value.
Definition: SparseField.h:1596
int blockSize() const
Returns the block size.
Definition: SparseField.h:1190
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 1558 of file SparseField.h.

1559 {
1560  return blockK * m_blockXYSize + blockJ * m_blockRes.x + blockI;
1561 }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:398
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 1567 of file SparseField.h.

1569 {
1570  assert(i >= 0);
1571  assert(j >= 0);
1572  assert(k >= 0);
1573  bi = i >> m_blockOrder;
1574  bj = j >> m_blockOrder;
1575  bk = k >> m_blockOrder;
1576 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
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 1582 of file SparseField.h.

1584 {
1585  assert(i >= 0);
1586  assert(j >= 0);
1587  assert(k >= 0);
1588  vi = i & ((1 << m_blockOrder) - 1);
1589  vj = j & ((1 << m_blockOrder) - 1);
1590  vk = k & ((1 << m_blockOrder) - 1);
1591 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
template<class Data_T>
void SparseField< Data_T >::applyDataWindowOffset ( int &  i,
int &  j,
int &  k 
) const
inline

Applies data window offset.

Definition at line 265 of file SparseField.h.

References FieldRes::m_dataWindow.

266  {
267  i -= base::m_dataWindow.min.x;
268  j -= base::m_dataWindow.min.y;
269  k -= base::m_dataWindow.min.z;
270  }
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
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 1306 of file SparseField.h.

1307 {
1308  return fastValue(i, j, k);
1309 }
Data_T fastValue(int i, int j, int k) const
Read access to voxel. Notice that this is non-virtual.
Definition: SparseField.h:1322
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 1404 of file SparseField.h.

1405 {
1406  long long int blockSize = m_blocks.capacity() * sizeof(Block);
1407  long long int dataSize = 0;
1408  typename std::vector<Block>::const_iterator i;
1409  for (i = m_blocks.begin(); i != m_blocks.end(); ++i) {
1410  if (i->isAllocated) {
1411  dataSize += i->data.capacity() * sizeof(Data_T);
1412  }
1413  }
1414  return sizeof(*this) + dataSize + blockSize;
1415 }
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:367
int blockSize() const
Returns the block size.
Definition: SparseField.h:1190
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 1314 of file SparseField.h.

1315 {
1316  return fastLValue(i, j, k);
1317 }
Data_T & fastLValue(int i, int j, int k)
Write access to voxel. Notice that this is non-virtual.
Definition: SparseField.h:1362
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 1322 of file SparseField.h.

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

1323 {
1324  assert (i >= base::m_dataWindow.min.x);
1325  assert (i <= base::m_dataWindow.max.x);
1326  assert (j >= base::m_dataWindow.min.y);
1327  assert (j <= base::m_dataWindow.max.y);
1328  assert (k >= base::m_dataWindow.min.z);
1329  assert (k <= base::m_dataWindow.max.z);
1330  // Add crop window offset
1331  applyDataWindowOffset(i, j, k);
1332  // Find block coord
1333  int bi, bj, bk;
1334  getBlockCoord(i, j, k, bi, bj, bk);
1335  // Find coord in block
1336  int vi, vj, vk;
1337  getVoxelInBlock(i, j, k, vi, vj, vk);
1338  // Get the actual block
1339  int id = blockId(bi, bj, bk);
1340 
1341  const Block &block = m_blocks[id];
1342  // Check if block data is allocated
1343  if (block.isAllocated) {
1344  if (m_fileManager) {
1345  m_fileManager->incBlockRef<Data_T>(m_fileId, id);
1346  m_fileManager->activateBlock<Data_T>(m_fileId, id);
1347  Data_T tmpValue = block.value(vi, vj, vk, m_blockOrder);
1348  m_fileManager->decBlockRef<Data_T>(m_fileId, id);
1349  return tmpValue;
1350  } else {
1351  return block.value(vi, vj, vk, m_blockOrder);
1352  }
1353  } else {
1354  return block.emptyValue;
1355  }
1356 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
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...
Definition: SparseFile.h:1020
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:265
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:1056
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1558
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
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:1069
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:1582
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:1567
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:367
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
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 1362 of file SparseField.h.

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

1363 {
1364  assert (i >= base::m_dataWindow.min.x);
1365  assert (i <= base::m_dataWindow.max.x);
1366  assert (j >= base::m_dataWindow.min.y);
1367  assert (j <= base::m_dataWindow.max.y);
1368  assert (k >= base::m_dataWindow.min.z);
1369  assert (k <= base::m_dataWindow.max.z);
1370 
1371  if (m_fileManager) {
1372  assert(false && "Called fastLValue() on a dynamic-read sparse field");
1373  Msg::print(Msg::SevWarning, "Called fastLValue() on a dynamic-read "
1374  "sparse field");
1375  return m_dummy;
1376  }
1377 
1378  // Add crop window offset
1379  applyDataWindowOffset(i, j, k);
1380  // Find block coord
1381  int bi, bj, bk;
1382  getBlockCoord(i, j, k, bi, bj, bk);
1383  // Find coord in block
1384  int vi, vj, vk;
1385  getVoxelInBlock(i, j, k, vi, vj, vk);
1386  // Get the actual block
1387  int id = blockId(bi, bj, bk);
1388  Block &block = m_blocks[id];
1389  // If block is allocated, return a reference to the data
1390  if (block.isAllocated) {
1391  return block.value(vi, vj, vk, m_blockOrder);
1392  } else {
1393  // ... Otherwise, allocate block
1394  block.isAllocated = true;
1395  block.data.resize(1 << m_blockOrder << m_blockOrder << m_blockOrder);
1396  std::fill(block.data.begin(), block.data.end(), block.emptyValue);
1397  return block.value(vi, vj, vk, m_blockOrder);
1398  }
1399 }
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:265
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1558
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
Data_T m_dummy
Dummy value used when needing to return but indicating a failed call.
Definition: SparseField.h:409
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:1582
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:1567
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:367
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
template<class Data_T>
virtual std::string SparseField< Data_T >::className ( ) const
inlinevirtual

Returns the class name of the object. Used by the class pool and when writing the data to disk.

Note
This is different from classType for any templated class, as classType() will include the template parameter(s) but className remains just the name of the template itself.

Implements FieldBase.

Definition at line 298 of file SparseField.h.

References SparseField< Data_T >::staticClassName().

299  { return staticClassName(); }
static const char * staticClassName()
Definition: SparseField.h:178
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 301 of file SparseField.h.

References SparseField< Data_T >::SparseField().

302  { return Ptr(new SparseField(*this)); }
boost::intrusive_ptr< SparseField > Ptr
Definition: SparseField.h:167
SparseField()
Constructs an empty buffer.
Definition: SparseField.h:1014
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 1421 of file SparseField.h.

References FieldRes::dataResolution().

1422 {
1423  if (FieldRes::dataResolution() == V3i(0))
1424  return cend();
1425  return const_iterator(*this, base::m_dataWindow, base::m_dataWindow.min,
1426  m_blockOrder);
1427 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:258
const_iterator cend() const
Const iterator pointing one element past the last valid one.
Definition: SparseField.h:1444
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 1433 of file SparseField.h.

1434 {
1435  if (subset.isEmpty())
1436  return cend(subset);
1437  return const_iterator(*this, subset, subset.min, m_blockOrder);
1438 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
const_iterator cend() const
Const iterator pointing one element past the last valid one.
Definition: SparseField.h:1444
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 1444 of file SparseField.h.

1445 {
1446  return const_iterator(*this, base::m_dataWindow,
1447  V3i(base::m_dataWindow.min.x,
1448  base::m_dataWindow.min.y,
1449  base::m_dataWindow.max.z + 1),
1450  m_blockOrder);
1451 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
Imath::V3i V3i
Definition: SpiMathLib.h:71
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 1457 of file SparseField.h.

1458 {
1459  return const_iterator(*this, subset,
1460  V3i(subset.min.x,
1461  subset.min.y,
1462  subset.max.z + 1), m_blockOrder);
1463 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
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 1469 of file SparseField.h.

References FieldRes::dataResolution().

1470 {
1471  if (FieldRes::dataResolution() == V3i(0))
1472  return end();
1473  return iterator(*this, base::m_dataWindow,
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1491
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:258
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 1480 of file SparseField.h.

1481 {
1482  if (subset.isEmpty())
1483  return end(subset);
1484  return iterator(*this, subset, subset.min, m_blockOrder);
1485 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
iterator end()
Iterator pointing one element past the last valid one.
Definition: SparseField.h:1491
template<class Data_T >
SparseField< Data_T >::iterator SparseField< Data_T >::end ( )

Iterator pointing one element past the last valid one.

Definition at line 1491 of file SparseField.h.

1492 {
1493  return iterator(*this, base::m_dataWindow,
1494  V3i(base::m_dataWindow.min.x,
1495  base::m_dataWindow.min.y,
1496  base::m_dataWindow.max.z + 1), m_blockOrder);
1497 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
Imath::V3i V3i
Definition: SpiMathLib.h:71
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 1503 of file SparseField.h.

1504 {
1505  return iterator(*this, subset,
1506  V3i(subset.min.x, subset.min.y, subset.max.z + 1),
1507  m_blockOrder);
1508 }
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
Imath::V3i V3i
Definition: SpiMathLib.h:71
template<class Data_T >
SparseField< Data_T >::block_iterator SparseField< Data_T >::blockBegin ( ) const

Definition at line 1514 of file SparseField.h.

References FieldRes::dataResolution().

1515 {
1516  if (FieldRes::dataResolution() == V3i(0))
1517  return blockEnd();
1518  return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)),
1519  V3i(0));
1520 }
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
Imath::V3i V3i
Definition: SpiMathLib.h:71
V3i const dataResolution() const
Definition: Field.h:258
block_iterator blockEnd() const
Const iterator pointing to element one past the last valid block.
Definition: SparseField.h:1526
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 1526 of file SparseField.h.

1527 {
1528  return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)),
1529  V3i(0, 0, m_blockRes.z));
1530 }
Imath::Box3i Box3i
Definition: SpiMathLib.h:77
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
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  occupiedBlocks 
)

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

Definition at line 1089 of file SparseField.h.

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

Referenced by SparseFieldIO::readData().

1093 {
1095  m_fileId = m_fileManager->getNextId<Data_T>(filename, layerPath);
1096  // Set up the manager data
1097  SparseFile::Reference<Data_T> &reference =
1098  m_fileManager->reference<Data_T>(m_fileId);
1099  reference.valuesPerBlock = valuesPerBlock;
1100  reference.occupiedBlocks = occupiedBlocks;
1101  reference.setNumBlocks(m_blocks.size());
1102 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
SparseFile::Reference< Data_T > & reference(int index)
Returns a reference to the Reference object with the given index.
Definition: SparseFile.h:1011
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:955
static SparseFileManager & singleton()
Returns a reference to the singleton instance.
Definition: SparseFile.cpp:63
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
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 1128 of file SparseField.h.

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

Referenced by SparseFieldIO::readData().

1129 {
1130  if (!m_fileManager || m_fileId < 0) return;
1131 
1132  SparseFile::Reference<Data_T> &reference =
1133  m_fileManager->reference<Data_T>(m_fileId);
1134 
1135  std::vector<int>::iterator fb = reference.fileBlockIndices.begin();
1137  reference.blocks.begin();
1138  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator b =
1139  m_blocks.begin();
1140  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator bend =
1141  m_blocks.end();
1142  int nextBlockIdx = 0;
1143 
1144  for (; b != bend; ++b, ++fb, ++bp) {
1145  if (b->isAllocated) {
1146  *fb = nextBlockIdx;
1147  *bp = &(*b);
1148  nextBlockIdx++;
1149  } else {
1150  *fb = -1;
1151  }
1152  }
1153 }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
std::vector< int > fileBlockIndices
Index in file for each block.
Definition: SparseFile.h:111
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
BlockPtrs blocks
Pointers to each block. This is so we can go in and manipulate them as we please. ...
Definition: SparseFile.h:117
SparseFile::Reference< Data_T > & reference(int index)
Returns a reference to the Reference object with the given index.
Definition: SparseFile.h:1011
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
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 371 of file SparseField.h.

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

372  {
373  // Call base class
375  setupBlocks();
376  }
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:866
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1535
template<class Data_T >
void SparseField< Data_T >::setupBlocks ( )
protected

Initializes the block structure. Will clear any existing data.

Definition at line 1535 of file SparseField.h.

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

1536 {
1537  // Do calculation in floating point so we can round up later
1538  V3f res(base::m_dataWindow.size() + V3i(1));
1539  V3f blockRes(res / (1 << m_blockOrder));
1540  blockRes.x = ceil(blockRes.x);
1541  blockRes.y = ceil(blockRes.y);
1542  blockRes.z = ceil(blockRes.z);
1543  V3i intBlockRes(static_cast<int>(blockRes.x),
1544  static_cast<int>(blockRes.y),
1545  static_cast<int>(blockRes.z));
1546  m_blockRes = intBlockRes;
1548  // clear() won't deallocate data. Do the swap trick.
1549  //m_blocks.clear();
1550  std::vector<Block>().swap(m_blocks);
1551 
1552  m_blocks.resize(intBlockRes.x * intBlockRes.y * intBlockRes.z);
1553 }
V3i blockRes() const
Returns the resolution of the block array.
Definition: SparseField.h:1249
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:398
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Box3i m_dataWindow
Defines the area where data is allocated. This should be treated as a closed (i.e. inclusive) interval.
Definition: Field.h:299
Imath::V3i V3i
Definition: SpiMathLib.h:71
Imath::V3f V3f
Definition: SpiMathLib.h:73
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 1596 of file SparseField.h.

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

1597 {
1598  block.isAllocated = false;
1600  block.clear();
1601  block.emptyValue = emptyValue;
1602 }
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 1061 of file SparseField.h.

References SparseFile::Reference< Data_T >::filename, 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, SparseFile::Reference< Data_T >::occupiedBlocks, and SparseFile::Reference< Data_T >::valuesPerBlock.

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

1062 {
1064  if (o.m_fileManager) {
1065  // allocate m_blocks, sets m_blockRes, m_blockXYSize, m_blocks
1066  setupBlocks();
1067 
1069  SparseFile::Reference<Data_T> &oldReference =
1070  m_fileManager->reference<Data_T>(o.m_fileId);
1071  addReference(oldReference.filename, oldReference.layerPath,
1072  oldReference.valuesPerBlock,
1073  oldReference.occupiedBlocks);
1074  copyBlockStates(o);
1076  } else {
1077  // directly copy all values and blocks from the source, no extra setup
1078  m_blockRes = o.m_blockRes;
1080  m_blocks = o.m_blocks;
1081  m_fileId = -1;
1082  m_fileManager = NULL;
1083  }
1084 }
void addReference(const std::string &filename, const std::string &layerPath, int valuesPerBlock, int occupiedBlocks)
Internal function to create a Reference for the current field, for use in dynamic reading...
Definition: SparseField.h:1089
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:398
void setupReferenceBlocks()
Internal function to setup the Reference's block pointers, for use with dynamic reading.
Definition: SparseField.h:1128
int m_blockOrder
Block order (size = 2^blockOrder)
Definition: SparseField.h:394
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
std::string layerPath
Definition: SparseFile.h:106
void setupBlocks()
Initializes the block structure. Will clear any existing data.
Definition: SparseField.h:1535
SparseFile::Reference< Data_T > & reference(int index)
Returns a reference to the Reference object with the given index.
Definition: SparseFile.h:1011
std::string filename
Definition: SparseFile.h:105
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:1107
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
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 1107 of file SparseField.h.

References SparseField< Data_T >::m_blocks.

1108 {
1109  if (m_blocks.size() != o.m_blocks.size()) return;
1110 
1111  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator b =
1112  m_blocks.begin();
1113  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator bend =
1114  m_blocks.end();
1115  typename std::vector<Sparse::SparseBlock<Data_T> >::const_iterator ob =
1116  o.m_blocks.begin();
1117 
1118  for (; b != bend; ++b, ++ob) {
1119  b->isAllocated = ob->isAllocated;
1120  b->emptyValue = ob->emptyValue;
1121  b->clear();
1122  }
1123 }
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400

Friends And Related Function Documentation

template<class Data_T>
friend class SparseFieldIO
friend

Definition at line 362 of file SparseField.h.

Member Data Documentation

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

Definition at line 176 of file SparseField.h.

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

Block array resolution.

Definition at line 396 of file SparseField.h.

Referenced by SparseField< Data_T >::copySparseField(), and SparseFieldIO::writeInternal().

template<class Data_T>
int SparseField< Data_T >::m_blockXYSize
protected

Block array res.x * res.y.

Definition at line 398 of file SparseField.h.

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

template<class Data_T>
std::vector<Block> SparseField< Data_T >::m_blocks
protected
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 404 of file SparseField.h.

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

template<class Data_T>
int SparseField< Data_T >::m_fileId
protected

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

Definition at line 406 of file SparseField.h.

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

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 409 of file SparseField.h.

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

Definition at line 415 of file SparseField.h.


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