Field3D
SparseField Class Reference

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

#include <SparseField.h>

Inheritance diagram for SparseField:
ResizableField< Data_T >

List of all members.

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 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.
void applyDataWindowOffset (int &i, int &j, int &k) const
 Applies data window offset.
int blockId (int blockI, int blockJ, int blockK) const
 Calculates the block number based on a block i,j,k index.
bool blockIndexIsValid (int bi, int bj, int bk) const
 Returns whether a block index is valid.
bool blockIsAllocated (int bi, int bj, int bk) const
 Checks if a block is allocated.
int blockOrder () const
 Returns the block order.
V3i blockRes () const
 Returns the resolution of the block array.
int blockSize () const
 Returns the block size.
virtual void clear (const Data_T &value)
 Clears all the voxels in the storage.
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 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.
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 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.
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.
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.
void setBlockOrder (int order)
 Sets the block order (i.e. the power-of-2 to use as block size.
void setupReferenceBlocks ()
 Internal function to setup the Reference's block pointers, for use with dynamic reading.
bool voxelIsInAllocatedBlock (int i, int j, int k) const
 Checks if a voxel is in an allocated block.
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.
From Field
virtual Data_T value (int i, int j, int k) const
virtual long long int memSize () const
From WritableField
virtual Data_T & lvalue (int i, int j, int k)
From FieldBase
virtual std::string className () const
virtual FieldBase::Ptr clone () const
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.

Static Public Member Functions

static const char * classType ()
static const char * staticClassName ()

Public Attributes

 DEFINE_FIELD_RTTI_CONCRETE_CLASS

Protected Types

typedef ResizableField< Data_T > base
typedef Sparse::SparseBlock
< Data_T > 
Block

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

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

Detailed Description

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!

Member Typedef Documentation

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

Reimplemented from ResizableField< Data_T >.

Definition at line 167 of file SparseField.h.

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

Definition at line 168 of file SparseField.h.

Definition at line 170 of file SparseField.h.

Definition at line 171 of file SparseField.h.

Reimplemented from ResizableField< Data_T >.

Definition at line 175 of file SparseField.h.

typedef ResizableField<Data_T> SparseField::base [protected]

Reimplemented from ResizableField< Data_T >.

Definition at line 366 of file SparseField.h.

typedef Sparse::SparseBlock<Data_T> SparseField::Block [protected]

Definition at line 367 of file SparseField.h.


Constructor & Destructor Documentation

SparseField::SparseField ( )

Constructs an empty buffer.

Definition at line 1014 of file SparseField.h.

References setupBlocks().

Referenced by clone().

SparseField::SparseField ( const SparseField o)

Copy constructor.

SparseField::~SparseField ( )

Destructor.

Definition at line 1034 of file SparseField.h.

{
  if (m_fileManager) {
    // this file is dynamically managed, so we need to ensure the
    // cache doesn't point to this field's blocks because they are
    // about to be deleted
    m_fileManager->removeFieldFromCache<Data_T>(m_fileId);
  }
}

Member Function Documentation

static const char* SparseField::staticClassName ( ) [inline, static]

Reimplemented from ResizableField< Data_T >.

Definition at line 178 of file SparseField.h.

Referenced by className().

  {
    return "SparseField";
  }
static const char* SparseField::classType ( ) [inline, static]

Reimplemented from ResizableField< Data_T >.

Definition at line 183 of file SparseField.h.

SparseField& SparseField::operator= ( const SparseField o)

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

void SparseField::clear ( const Data_T &  value) [virtual]

Clears all the voxels in the storage.

Definition at line 1158 of file SparseField.h.

{
  // If we're clearing, we can get rid of all current blocks
  setupBlocks();
  // Then just fill in the default values
  typename std::vector<Block>::iterator i;
  typename std::vector<Block>::iterator end;
  for (i = m_blocks.begin(), end = m_blocks.end(); i != end; ++i) {
    i->emptyValue = value;
  }
}
void SparseField::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().

{
  m_blockOrder = order;
  setupBlocks();
}
int SparseField::blockOrder ( ) const

Returns the block order.

Definition at line 1182 of file SparseField.h.

{
  return m_blockOrder;
}
int SparseField::blockSize ( ) const

Returns the block size.

Definition at line 1190 of file SparseField.h.

Referenced by SparseField::block_iterator::recomputeBlockBoundingBox().

{ 
  return 1 << m_blockOrder;
}
bool SparseField::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.

{
  int bi, bj, bk;
  applyDataWindowOffset(i, j, k);
  getBlockCoord(i, j, k, bi, bj, bk);
  return blockIsAllocated(bi, bj, bk);
}
bool SparseField::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::isAllocated.

{
  const Block &block = m_blocks[blockId(bi, bj, bk)];
  return block.isAllocated;
}
const Data_T SparseField::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.

{
  return m_blocks[blockId(bi, bj, bk)].emptyValue;
}
void SparseField::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::isAllocated, and Sparse::SparseBlock::emptyValue.

{
  Block &block = m_blocks[blockId(bi, bj, bk)];
  if (block.isAllocated) {
    deallocBlock(block, val);
  } else {
    block.emptyValue = val;
  }
}
bool SparseField::blockIndexIsValid ( int  bi,
int  bj,
int  bk 
) const

Returns whether a block index is valid.

Definition at line 1240 of file SparseField.h.

{
  return bi >= 0 && bj >= 0 && bk >= 0 && 
    bi < m_blockRes.x && bj < m_blockRes.y && bk < m_blockRes.z;
}
V3i SparseField::blockRes ( ) const

Returns the resolution of the block array.

Definition at line 1249 of file SparseField.h.

{
  return m_blockRes;
}
template<typename Functor_T >
int SparseField::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().

{
  Data_T emptyValue;
  int numDeallocs = 0;
  typename std::vector<Block>::iterator i;

  // If the block is on the edge of the field, it may have unused
  // voxels, with undefined values.  We need to pass the range of
  // valid voxels into the check function, so it only looks at valid
  // voxels.
  V3i dataRes = FieldRes::dataResolution();
  V3i validSize;
  V3i blockAllocSize(blockSize());
  int bx, by, bz;

  for (i = m_blocks.begin(), bx=0, by=0, bz=0; i != m_blocks.end(); ++i, ++bx) {
    if (bx >= m_blockRes.x) {
      bx = 0;
      ++by;
      if (by >= m_blockRes.y) {
        by = 0;
        ++bz;
      }
    }
    validSize = blockAllocSize;
    if (bx == m_blockRes.x-1) {
      validSize.x = dataRes.x - bx * blockAllocSize.x;
    }
    if (by == m_blockRes.y-1) {
      validSize.y = dataRes.y - by * blockAllocSize.y;
    }
    if (bz == m_blockRes.z-1) {
      validSize.z = dataRes.z - bz * blockAllocSize.z;
    }

    if (i->isAllocated) {
      if (func.check(*i, emptyValue, validSize, blockAllocSize)) {
        deallocBlock(*i, emptyValue);
        numDeallocs++;
      }
    }
  }
  return numDeallocs;
}
int SparseField::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.

{
  return blockK * m_blockXYSize + blockJ * m_blockRes.x + blockI;
}
void SparseField::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.

{
  assert(i >= 0);
  assert(j >= 0);
  assert(k >= 0);
  bi = i >> m_blockOrder;
  bj = j >> m_blockOrder;
  bk = k >> m_blockOrder;
}
void SparseField::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.

{
  assert(i >= 0);
  assert(j >= 0);
  assert(k >= 0);
  vi = i & ((1 << m_blockOrder) - 1);
  vj = j & ((1 << m_blockOrder) - 1);
  vk = k & ((1 << m_blockOrder) - 1);
}
void SparseField::applyDataWindowOffset ( int &  i,
int &  j,
int &  k 
) const [inline]

Applies data window offset.

Definition at line 265 of file SparseField.h.

  {
    i -= base::m_dataWindow.min.x;
    j -= base::m_dataWindow.min.y;
    k -= base::m_dataWindow.min.z;
  }
Data_T SparseField::value ( int  i,
int  j,
int  k 
) const [virtual]

Definition at line 1306 of file SparseField.h.

{
  return fastValue(i, j, k);
}
long long int SparseField::memSize ( ) const [virtual]

Definition at line 1404 of file SparseField.h.

{
  long long int blockSize = m_blocks.capacity() * sizeof(Block);
  long long int dataSize = 0;
  typename std::vector<Block>::const_iterator i;
  for (i = m_blocks.begin(); i != m_blocks.end(); ++i) {
    if (i->isAllocated) {
      dataSize += i->data.capacity() * sizeof(Data_T);
    }
  }
  return sizeof(*this) + dataSize + blockSize;
}
Data_T & SparseField::lvalue ( int  i,
int  j,
int  k 
) [virtual]

Definition at line 1314 of file SparseField.h.

{
  return fastLValue(i, j, k);
}
Data_T SparseField::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::isAllocated, Sparse::SparseBlock::value(), and Sparse::SparseBlock::emptyValue.

{
  assert (i >= base::m_dataWindow.min.x);
  assert (i <= base::m_dataWindow.max.x);
  assert (j >= base::m_dataWindow.min.y);
  assert (j <= base::m_dataWindow.max.y);
  assert (k >= base::m_dataWindow.min.z);
  assert (k <= base::m_dataWindow.max.z);
  // Add crop window offset
  applyDataWindowOffset(i, j, k);
  // Find block coord
  int bi, bj, bk;
  getBlockCoord(i, j, k, bi, bj, bk);
  // Find coord in block
  int vi, vj, vk;
  getVoxelInBlock(i, j, k, vi, vj, vk);
  // Get the actual block
  int id = blockId(bi, bj, bk);

  const Block &block = m_blocks[id];
  // Check if block data is allocated
  if (block.isAllocated) {
    if (m_fileManager) {
      m_fileManager->incBlockRef<Data_T>(m_fileId, id);
      m_fileManager->activateBlock<Data_T>(m_fileId, id);
      Data_T tmpValue = block.value(vi, vj, vk, m_blockOrder);
      m_fileManager->decBlockRef<Data_T>(m_fileId, id);
      return tmpValue;
    } else {
      return block.value(vi, vj, vk, m_blockOrder);
    }
  } else {
    return block.emptyValue;
  }
}
Data_T & SparseField::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 Msg::print(), Msg::SevWarning, Sparse::SparseBlock::isAllocated, Sparse::SparseBlock::value(), Sparse::SparseBlock::data, and Sparse::SparseBlock::emptyValue.

{
  assert (i >= base::m_dataWindow.min.x);
  assert (i <= base::m_dataWindow.max.x);
  assert (j >= base::m_dataWindow.min.y);
  assert (j <= base::m_dataWindow.max.y);
  assert (k >= base::m_dataWindow.min.z);
  assert (k <= base::m_dataWindow.max.z);

  if (m_fileManager) {
    assert(false && "Called fastLValue() on a dynamic-read sparse field");
    Msg::print(Msg::SevWarning, "Called fastLValue() on a dynamic-read "
              "sparse field");
    return m_dummy;
  }

  // Add crop window offset
  applyDataWindowOffset(i, j, k);
  // Find block coord
  int bi, bj, bk;
  getBlockCoord(i, j, k, bi, bj, bk);
  // Find coord in block
  int vi, vj, vk;
  getVoxelInBlock(i, j, k, vi, vj, vk);
  // Get the actual block
  int id = blockId(bi, bj, bk);
  Block &block = m_blocks[id];
  // If block is allocated, return a reference to the data
  if (block.isAllocated) {
    return block.value(vi, vj, vk, m_blockOrder);
  } else {
    // ... Otherwise, allocate block
    block.isAllocated = true;
    block.data.resize(1 << m_blockOrder << m_blockOrder << m_blockOrder);
    std::fill(block.data.begin(), block.data.end(), block.emptyValue);
    return block.value(vi, vj, vk, m_blockOrder);
  }
}
virtual std::string SparseField::className ( ) const [inline, virtual]

Definition at line 298 of file SparseField.h.

References staticClassName().

  { return staticClassName(); }
virtual FieldBase::Ptr SparseField::clone ( ) const [inline, virtual]

Definition at line 301 of file SparseField.h.

References SparseField().

  { return Ptr(new SparseField(*this)); }
SparseField< Data_T >::const_iterator SparseField::cbegin ( ) const

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

Definition at line 1421 of file SparseField.h.

References FieldRes::dataResolution().

{ 
  if (FieldRes::dataResolution() == V3i(0))
    return cend();
  return const_iterator(*this, base::m_dataWindow, base::m_dataWindow.min,
                        m_blockOrder); 
}
SparseField< Data_T >::const_iterator SparseField::cbegin ( const Box3i subset) const

Const iterator to first element of specific subset.

Definition at line 1433 of file SparseField.h.

{ 
  if (subset.isEmpty())
    return cend(subset);
  return const_iterator(*this, subset, subset.min, m_blockOrder); 
}
SparseField< Data_T >::const_iterator SparseField::cend ( ) const

Const iterator pointing one element past the last valid one.

Definition at line 1444 of file SparseField.h.

{ 
  return const_iterator(*this, base::m_dataWindow, 
                        V3i(base::m_dataWindow.min.x, 
                                   base::m_dataWindow.min.y,
                                   base::m_dataWindow.max.z + 1),
                        m_blockOrder);
}
SparseField< Data_T >::const_iterator SparseField::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.

{ 
  return const_iterator(*this, subset, 
                        V3i(subset.min.x, 
                                   subset.min.y,
                                   subset.max.z + 1), m_blockOrder);
}
SparseField< Data_T >::iterator SparseField::begin ( )

Iterator to first element.

Definition at line 1469 of file SparseField.h.

References FieldRes::dataResolution().

{ 
  if (FieldRes::dataResolution() == V3i(0))
    return end();
  return iterator(*this, base::m_dataWindow, 
                  base::m_dataWindow.min, m_blockOrder); }
SparseField< Data_T >::iterator SparseField::begin ( const Box3i subset)

Iterator to first element of specific subset.

Definition at line 1480 of file SparseField.h.

{ 
  if (subset.isEmpty())
    return end(subset);
  return iterator(*this, subset, subset.min, m_blockOrder); 
}
SparseField< Data_T >::iterator SparseField::end ( )

Iterator pointing one element past the last valid one.

Definition at line 1491 of file SparseField.h.

{ 
  return iterator(*this, base::m_dataWindow, 
                  V3i(base::m_dataWindow.min.x, 
                             base::m_dataWindow.min.y,
                             base::m_dataWindow.max.z + 1), m_blockOrder);
}
SparseField< Data_T >::iterator SparseField::end ( const Box3i subset)

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

Definition at line 1503 of file SparseField.h.

{ 
  return iterator(*this, subset, 
                  V3i(subset.min.x, subset.min.y, subset.max.z + 1), 
                  m_blockOrder);
}
SparseField< Data_T >::block_iterator SparseField::blockBegin ( ) const

Definition at line 1514 of file SparseField.h.

References FieldRes::dataResolution().

{ 
  if (FieldRes::dataResolution() == V3i(0))
    return blockEnd();
  return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)), 
                        V3i(0)); 
}
SparseField< Data_T >::block_iterator SparseField::blockEnd ( ) const

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

Definition at line 1526 of file SparseField.h.

{ 
  return block_iterator(*this, Box3i(V3i(0), m_blockRes - V3i(1)), 
                        V3i(0, 0, m_blockRes.z));
}
void SparseField::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().

Referenced by SparseFieldIO::readData().

{
  m_fileManager = &SparseFileManager::singleton();
  m_fileId = m_fileManager->getNextId<Data_T>(filename, layerPath);
  // Set up the manager data
  SparseFile::Reference<Data_T> &reference = 
    m_fileManager->reference<Data_T>(m_fileId);
  reference.valuesPerBlock = valuesPerBlock;
  reference.occupiedBlocks = occupiedBlocks;
  reference.setNumBlocks(m_blocks.size());
}
void SparseField::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::fileBlockIndices, and SparseFile::Reference::blocks.

Referenced by SparseFieldIO::readData().

{
  if (!m_fileManager || m_fileId < 0) return;

  SparseFile::Reference<Data_T> &reference = 
    m_fileManager->reference<Data_T>(m_fileId);

  std::vector<int>::iterator fb = reference.fileBlockIndices.begin();
  typename SparseFile::Reference<Data_T>::BlockPtrs::iterator bp = 
    reference.blocks.begin();
  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator b =
    m_blocks.begin();
  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator bend =
    m_blocks.end();
  int nextBlockIdx = 0;

  for (; b != bend; ++b, ++fb, ++bp) {
    if (b->isAllocated) {
      *fb = nextBlockIdx;
      *bp = &(*b);
      nextBlockIdx++;
    } else {
      *fb = -1;
    }
  }
}
virtual void SparseField::sizeChanged ( ) [inline, protected, virtual]

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

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

Reimplemented from ResizableField< Data_T >.

Definition at line 371 of file SparseField.h.

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

  { 
    // Call base class
    base::sizeChanged();
    setupBlocks(); 
  }
void SparseField::setupBlocks ( ) [protected]

Initializes the block structure. Will clear any existing data.

Definition at line 1535 of file SparseField.h.

Referenced by sizeChanged(), and SparseField().

{
  // Do calculation in floating point so we can round up later
  V3f res(base::m_dataWindow.size() + V3i(1));
  V3f blockRes(res / (1 << m_blockOrder));
  blockRes.x = ceil(blockRes.x);
  blockRes.y = ceil(blockRes.y);
  blockRes.z = ceil(blockRes.z);
  V3i intBlockRes(static_cast<int>(blockRes.x),
                         static_cast<int>(blockRes.y),
                         static_cast<int>(blockRes.z));
  m_blockRes = intBlockRes;
  m_blockXYSize = m_blockRes.x * m_blockRes.y;
  // clear() won't deallocate data. Do the swap trick.
  //m_blocks.clear();
  std::vector<Block>().swap(m_blocks);
  
  m_blocks.resize(intBlockRes.x * intBlockRes.y * intBlockRes.z);
}
void SparseField::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::isAllocated, Sparse::SparseBlock::clear(), and Sparse::SparseBlock::emptyValue.

{
  block.isAllocated = false;
  block.clear();
  block.emptyValue = emptyValue;
}
void SparseField::copySparseField ( const SparseField 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 m_blockOrder, m_fileManager, SparseFileManager::reference(), m_fileId, SparseFile::Reference::filename, SparseFile::Reference::layerPath, SparseFile::Reference::valuesPerBlock, SparseFile::Reference::occupiedBlocks, m_blockRes, m_blockXYSize, and m_blocks.

{
  m_blockOrder = o.m_blockOrder;
  if (o.m_fileManager) {
    // allocate m_blocks, sets m_blockRes, m_blockXYSize, m_blocks
    setupBlocks();

    m_fileManager = o.m_fileManager;
    SparseFile::Reference<Data_T> &oldReference = 
      m_fileManager->reference<Data_T>(o.m_fileId);
    addReference(oldReference.filename, oldReference.layerPath,
                 oldReference.valuesPerBlock,
                 oldReference.occupiedBlocks);
    copyBlockStates(o);
    setupReferenceBlocks();
  } else {
    // directly copy all values and blocks from the source, no extra setup
    m_blockRes = o.m_blockRes;
    m_blockXYSize = o.m_blockXYSize;
    m_blocks = o.m_blocks;
    m_fileId = -1;
    m_fileManager = NULL;
  }
}
void SparseField::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 m_blocks.

{
  if (m_blocks.size() != o.m_blocks.size()) return;

  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator b =
    m_blocks.begin();
  typename std::vector<Sparse::SparseBlock<Data_T> >::iterator bend = 
    m_blocks.end();
  typename std::vector<Sparse::SparseBlock<Data_T> >::const_iterator ob =
    o.m_blocks.begin();

  for (; b != bend; ++b, ++ob) {
    b->isAllocated = ob->isAllocated;
    b->emptyValue = ob->emptyValue;
    b->clear();
  }
}

Friends And Related Function Documentation

friend class SparseFieldIO [friend]

Definition at line 362 of file SparseField.h.


Member Data Documentation

Block array resolution.

Definition at line 396 of file SparseField.h.

Referenced by copySparseField(), and SparseFieldIO::writeInternal().

int SparseField::m_blockXYSize [protected]

Block array res.x * res.y.

Definition at line 398 of file SparseField.h.

Referenced by copySparseField().

std::vector<Block> SparseField::m_blocks [protected]

Information for all blocks in the field.

Definition at line 400 of file SparseField.h.

Referenced by copySparseField(), copyBlockStates(), SparseFieldIO::writeInternal(), and SparseFieldIO::readData().

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

Definition at line 404 of file SparseField.h.

Referenced by copySparseField().

int SparseField::m_fileId [protected]

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

Definition at line 406 of file SparseField.h.

Referenced by copySparseField().

Data_T SparseField::m_dummy [protected]

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

Definition at line 409 of file SparseField.h.

Reimplemented from ResizableField< Data_T >.

Definition at line 415 of file SparseField.h.


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