Field3D
SparseField::iterator Class Reference

#include <SparseField.h>

List of all members.

Public Types

typedef SparseField< Data_T > class_type

Public Member Functions

 iterator (class_type &field, const Box3i &window, const V3i &currentPos, int blockOrder)
bool operator!= (const iterator &rhs) const
Data_T & operator* ()
const iteratoroperator++ ()
Data_T * operator-> ()
bool operator== (const iterator &rhs) const

Public Attributes

int x
int y
int z

Private Types

typedef Sparse::SparseBlock
< Data_T > 
Block

Private Member Functions

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

Private Attributes

int m_blockI
 Current block index.
int m_blockId
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.
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.
Data_T * m_p
 Current pointed-to element.
Box3i m_window
 Window to traverse.

Detailed Description

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

Member Typedef Documentation

Definition at line 806 of file SparseField.h.

Definition at line 894 of file SparseField.h.


Constructor & Destructor Documentation

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

Definition at line 807 of file SparseField.h.

    : x(currentPos.x), y(currentPos.y), z(currentPos.z),
      m_p(NULL), m_blockStepsTicker(0), m_blockOrder(blockOrder), 
      m_blockId(-1), m_window(window), m_field(&field)
  {
    setupNextBlock(x, y, z);
  }

Member Function Documentation

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

Definition at line 816 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_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;
  }
bool SparseField::iterator::operator== ( const iterator rhs) const [inline]

Definition at line 849 of file SparseField.h.

References x, y, and z.

  {
    return x == rhs.x && y == rhs.y && z == rhs.z;
  }
bool SparseField::iterator::operator!= ( const iterator rhs) const [inline]

Definition at line 853 of file SparseField.h.

References x, y, and z.

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

Definition at line 857 of file SparseField.h.

References Msg::print(), and Msg::SevWarning.

  {
    if (m_field->m_fileManager) {
      assert(false && "Dereferencing iterator on a dynamic-read sparse field");
      Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
                "sparse field");
      return *m_p;      
    }
    // If the block is currently empty, we must allocate it
    if (m_isEmptyBlock) {
      // Touch the voxel to allocate the block
      m_field->lvalue(x, y, z);
      // Set up the block again
      setupNextBlock(x, y, z);
    }
    return *m_p;
  }
Data_T* SparseField::iterator::operator-> ( ) [inline]

Definition at line 874 of file SparseField.h.

References Msg::print(), and Msg::SevWarning.

  {
    if (m_field->m_fileManager) {
      assert(false && "Dereferencing iterator on a dynamic-read sparse field");
      Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
                "sparse field");
      return m_p;      
    }
    // If the block is currently empty, we must allocate it
    if (m_isEmptyBlock) {
      // Touch the voxel to allocate the block
      m_field->lvalue(x, y, z);
      // Set up the block again
      setupNextBlock(x, y, z);
    }
    return m_p;
  }
void SparseField::iterator::setupNextBlock ( int  i,
int  j,
int  k 
) [inline, private]

Convenience.

Definition at line 896 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);
    m_blockId = m_field->blockId(m_blockI, m_blockJ, m_blockK);
    if (m_blockId >= m_field->m_blockXYSize * m_field->m_blockRes.z) {
      m_isEmptyBlock = true;
      return;
    }
    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) {
      m_p = &block.value(vi, vj, vk, m_blockOrder);
      m_isEmptyBlock = false;
    } else {
      m_p = &block.emptyValue;
      m_isEmptyBlock = true;
    }
  }

Member Data Documentation

Definition at line 892 of file SparseField.h.

Referenced by operator++(), operator==(), and operator!=().

Definition at line 892 of file SparseField.h.

Referenced by operator==(), and operator!=().

Definition at line 892 of file SparseField.h.

Referenced by operator==(), and operator!=().

Data_T* SparseField::iterator::m_p [private]

Current pointed-to element.

Definition at line 918 of file SparseField.h.

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

Definition at line 920 of file SparseField.h.

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

Definition at line 922 of file SparseField.h.

Block size.

Definition at line 924 of file SparseField.h.

Current block index.

Definition at line 926 of file SparseField.h.

Definition at line 926 of file SparseField.h.

Definition at line 926 of file SparseField.h.

Definition at line 926 of file SparseField.h.

Window to traverse.

Definition at line 928 of file SparseField.h.

Reference to field we're traversing.

Definition at line 930 of file SparseField.h.


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