Field3D
SparseField::const_iterator Class Reference

#include <SparseField.h>

List of all members.

Public Types

typedef SparseField< Data_T > class_type

Public Member Functions

 const_iterator (const class_type &field, const Box3i &window, const V3i &currentPos, int blockOrder)
template<class Iter_T >
bool operator!= (const Iter_T &rhs) const
const Data_T & operator* () const
const const_iteratoroperator++ ()
const Data_T * operator-> () const
template<class Iter_T >
bool operator== (const Iter_T &rhs) const
 ~const_iterator ()

Public Attributes

int x
 Current x/y/z coord.
int y
int z

Private Types

typedef Sparse::SparseBlock
< Data_T > 
Block

Private Member Functions

void setupNextBlock (int i, int j, int k)

Private Attributes

int m_blockI
 Current block index.
int m_blockId
bool m_blockIsActivated
 Used with delayed-load fields. Check if we've already activated the current blocks.
int m_blockJ
int m_blockK
int m_blockOrder
 Block size.
int m_blockStepsTicker
 Ticker for how many more steps to take before resetting the pointer.
const class_typem_field
 Reference to field we're traversing.
bool m_isEmptyBlock
 Whether we're at an empty block and we don't increment m_p.
SparseFileManagerm_manager
 Pointer to the singleton file manager.
const Data_T * m_p
 Current pointed-to element.
Box3i m_window
 Window to traverse.

Detailed Description

Todo:
Code duplication between this and iterator!!!!!!!!!!!!!!!!!!!!!!

Member Typedef Documentation

Definition at line 633 of file SparseField.h.

Definition at line 730 of file SparseField.h.


Constructor & Destructor Documentation

SparseField::const_iterator::const_iterator ( const class_type field,
const Box3i window,
const V3i currentPos,
int  blockOrder 
) [inline]

Definition at line 634 of file SparseField.h.

    : x(currentPos.x), y(currentPos.y), z(currentPos.z), 
      m_p(NULL), m_blockIsActivated(false), 
      m_blockStepsTicker(0), m_blockOrder(blockOrder), 
      m_blockId(-1), m_window(window), m_field(&field)
  {
    m_manager = m_field->m_fileManager;
    setupNextBlock(x, y, z);
  }
SparseField::const_iterator::~const_iterator ( ) [inline]

Definition at line 645 of file SparseField.h.

                    {
    if (m_manager && m_blockId >= 0 && 
        m_blockId < static_cast<int>(m_field->m_blocks.size())) {
      if (m_field->m_blocks[m_blockId].isAllocated)
        m_manager->decBlockRef<Data_T>(m_field->m_fileId, m_blockId);
    }
  }

Member Function Documentation

const const_iterator& SparseField::const_iterator::operator++ ( ) [inline]

Definition at line 652 of file SparseField.h.

References x, and SparseField::m_blockOrder.

  {
    bool resetPtr = false;
    // Check against end of data window
    if (x == m_window.max.x) {
      if (y == m_window.max.y) {
        x = m_window.min.x;
        y = m_window.min.y;
        ++z;
        resetPtr = true;
      } else {
        x = m_window.min.x;
        ++y;
        resetPtr = true;
      }
    } else {
      ++x;
    }
    // These can both safely be incremented here
    ++m_blockStepsTicker;
    // ... but only step forward if we're in a non-empty block
    if (!m_isEmptyBlock && (!m_manager || m_blockIsActivated))
      ++m_p;   
    // Check if we've reached the end of this block
    if (m_blockStepsTicker == (1 << m_blockOrder))
      resetPtr = true;
    if (resetPtr) {
      // If we have, we need to reset the current block, etc.
      m_blockStepsTicker = 0;
      setupNextBlock(x, y, z);
    }
    return *this;
  }
template<class Iter_T >
bool SparseField::const_iterator::operator== ( const Iter_T &  rhs) const [inline]

Definition at line 686 of file SparseField.h.

  {
    return x == rhs.x && y == rhs.y && z == rhs.z;
  }
template<class Iter_T >
bool SparseField::const_iterator::operator!= ( const Iter_T &  rhs) const [inline]

Definition at line 691 of file SparseField.h.

  {
    return x != rhs.x || y != rhs.y || z != rhs.z;
  }
const Data_T& SparseField::const_iterator::operator* ( ) const [inline]

Definition at line 695 of file SparseField.h.

References Sparse::SparseBlock::value(), and SparseField::m_blockOrder.

  {
    if (!m_isEmptyBlock && m_manager && !m_blockIsActivated) {
      m_manager->activateBlock<Data_T>(m_field->m_fileId, m_blockId);
      m_blockIsActivated = true;
      const Block &block = m_field->m_blocks[m_blockId];
      int vi, vj, vk;
      m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
      m_p = &block.value(vi, vj, vk, m_blockOrder);
    }
    return *m_p;
  }
const Data_T* SparseField::const_iterator::operator-> ( ) const [inline]

Definition at line 707 of file SparseField.h.

References SparseFileManager::activateBlock(), Sparse::SparseBlock::value(), and SparseField::m_blockOrder.

  {
    if (!m_isEmptyBlock && m_manager && !m_blockIsActivated) {
      SparseFileManager *manager = m_field->m_fileManager;
      manager->activateBlock<Data_T>(m_field->m_fileId, m_blockId);
      m_blockIsActivated = true;
      const Block &block = m_field->m_blocks[m_blockId];
      int vi, vj, vk;
      m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
      m_p = &block.value(vi, vj, vk, m_blockOrder);
    }
    return m_p;
  }
void SparseField::const_iterator::setupNextBlock ( int  i,
int  j,
int  k 
) [inline, private]

Definition at line 734 of file SparseField.h.

References Sparse::SparseBlock::isAllocated, Sparse::SparseBlock::value(), SparseField::m_blockOrder, and Sparse::SparseBlock::emptyValue.

  {
    m_field->applyDataWindowOffset(i, j, k);
    m_field->getBlockCoord(i, j, k, m_blockI, m_blockJ, m_blockK);
    int oldBlockId = m_blockId;
    m_blockId = m_field->blockId(m_blockI, m_blockJ, m_blockK);
    if (m_manager && oldBlockId != m_blockId &&
        oldBlockId >= 0 && 
        oldBlockId < static_cast<int>(m_field->m_blocks.size()) &&
        m_field->m_blocks[oldBlockId].isAllocated) {
      m_manager->decBlockRef<Data_T>(m_field->m_fileId, oldBlockId);
    }
    if (m_blockId >= m_field->m_blockXYSize * m_field->m_blockRes.z) {
      m_isEmptyBlock = true;
      return;
    }

    const Block &block = m_field->m_blocks[m_blockId];
    int vi, vj, vk;
    m_field->getVoxelInBlock(i, j, k, vi, vj, vk);      
    m_blockStepsTicker = vi;
    if (block.isAllocated) {
      if (m_manager && oldBlockId != m_blockId && m_blockId >= 0) {
        m_manager->incBlockRef<Data_T>(m_field->m_fileId, m_blockId);
        // this is a managed field, so the block may not be loaded
        // yet, so don't bother setting m_p yet (it'll get set in the
        // * and -> operators when the block is activated)
      } else {
        // only set m_p to the voxel's address if this is not a
        // managed field, i.e., if the data is already in memory.
        m_p = &block.value(vi, vj, vk, m_blockOrder);
      }
      m_isEmptyBlock = false;
    } else {
      m_p = &block.emptyValue;
      m_isEmptyBlock = true;
    }
    if (m_field->m_fileManager) {
      m_blockIsActivated = false;
    }
  }

Member Data Documentation

Current x/y/z coord.

Definition at line 724 of file SparseField.h.

Referenced by operator++().

Definition at line 724 of file SparseField.h.

Definition at line 724 of file SparseField.h.

const Data_T* SparseField::const_iterator::m_p [mutable, private]

Current pointed-to element.

Definition at line 777 of file SparseField.h.

Whether we're at an empty block and we don't increment m_p.

Definition at line 779 of file SparseField.h.

Used with delayed-load fields. Check if we've already activated the current blocks.

Definition at line 782 of file SparseField.h.

Ticker for how many more steps to take before resetting the pointer.

Definition at line 784 of file SparseField.h.

Block size.

Definition at line 786 of file SparseField.h.

Current block index.

Definition at line 788 of file SparseField.h.

Definition at line 788 of file SparseField.h.

Definition at line 788 of file SparseField.h.

Definition at line 788 of file SparseField.h.

Window to traverse.

Definition at line 790 of file SparseField.h.

Reference to field we're traversing.

Definition at line 792 of file SparseField.h.

Pointer to the singleton file manager.

Definition at line 794 of file SparseField.h.


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