SparseField< Data_T >::const_iterator Class Reference

`#include <SparseField.h>`

## 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_iterator & | operator++ ()
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_type * | m_field
| Reference to field we're traversing.
bool | m_isEmptyBlock
| Whether we're at an empty block and we don't increment m_p.
SparseFileManager * | m_manager
| Pointer to the singleton file manager.
const Data_T * | m_p
| Current pointed-to element.
Box3i | m_window
| Window to traverse.

## Detailed Description

template<class Data_T>
class SparseField< Data_T >::const_iterator

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

Definition at line 885 of file SparseField.h.

## Member Typedef Documentation

## class_type

template<class Data_T>

typedef SparseField<Data_T> SparseField< Data_T >::const_iterator::class_type

Definition at line 897 of file SparseField.h.

## Block

template<class Data_T>

typedef Sparse::SparseBlock<Data_T> SparseField< Data_T >::const_iterator::Block

private

Definition at line 994 of file SparseField.h.

## Constructor & Destructor Documentation

## const_iterator()

template<class Data_T>

SparseField< Data_T >::const_iterator::const_iterator | ( | const class_type & | field,
|  | const Box3i & | window,
|  | const V3i & | currentPos,
|  | int | blockOrder )

inline

Definition at line 898 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::m_blockIsActivated
bool m_blockIsActivated
Used with delayed-load fields. Check if we've already activated the current blocks.
Definition SparseField.h:1046
SparseField::const_iterator::z
int z
Definition SparseField.h:988
SparseField::const_iterator::m_window
Box3i m_window
Window to traverse.
Definition SparseField.h:1054
SparseField::const_iterator::m_blockStepsTicker
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition SparseField.h:1048
SparseField::const_iterator::setupNextBlock
void setupNextBlock(int i, int j, int k)
Definition SparseField.h:998
SparseField::const_iterator::m_manager
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition SparseField.h:1058
SparseField::const_iterator::m_field
const class_type * m_field
Reference to field we're traversing.
Definition SparseField.h:1056
SparseField::const_iterator::m_blockOrder
int m_blockOrder
Block size.
Definition SparseField.h:1050
SparseField::const_iterator::x
int x
Current x/y/z coord.
Definition SparseField.h:988
SparseField::const_iterator::m_blockId
int m_blockId
Definition SparseField.h:1052
SparseField::const_iterator::y
int y
Definition SparseField.h:988
SparseField::const_iterator::m_p
const Data_T * m_p
Current pointed-to element.
Definition SparseField.h:1041
SparseField
This Field subclass stores voxel data in block-allocated arrays.
Definition SparseField.h:352

References SparseField< Data_T >::blockOrder(), m_blockId, m_blockIsActivated, m_blockOrder, m_blockStepsTicker, m_field, m_manager, m_p, m_window, setupNextBlock(), x, y, and z.

Referenced by operator++().

## ~const_iterator()

template<class Data_T>

SparseField< Data_T >::const_iterator::~const_iterator | ( |  | ) |

inline

Definition at line 909 of file SparseField.h.

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

References m_blockId, m_field, and m_manager.

## Member Function Documentation

## operator++()

template<class Data_T>

const const_iterator & SparseField< Data_T >::const_iterator::operator++ | ( |  | ) |

inline

Definition at line 916 of file SparseField.h.

{
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;
}
SparseField::const_iterator::m_isEmptyBlock
bool m_isEmptyBlock
Whether we're at an empty block and we don't increment m_p.
Definition SparseField.h:1043

References const_iterator(), m_blockIsActivated, m_blockOrder, m_blockStepsTicker, m_isEmptyBlock, m_manager, m_p, m_window, setupNextBlock(), x, y, and z.

## operator==()

template<class Data_T>
template<class Iter_T>

bool SparseField< Data_T >::const_iterator::operator== | ( | const Iter_T & | rhs | ) | const

inline

Definition at line 950 of file SparseField.h.

{
return x == rhs.x && y == rhs.y && z == rhs.z;
}

References x, y, and z.

## operator!=()

template<class Data_T>
template<class Iter_T>

bool SparseField< Data_T >::const_iterator::operator!= | ( | const Iter_T & | rhs | ) | const

inline

Definition at line 955 of file SparseField.h.

{
return x != rhs.x || y != rhs.y || z != rhs.z;
}

References x, y, and z.

## operator*()

template<class Data_T>

const Data_T & SparseField< Data_T >::const_iterator::operator* | ( |  | ) | const

inline

Definition at line 959 of file SparseField.h.

{
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;
}
SparseField::const_iterator::Block
Sparse::SparseBlock< Data_T > Block
Definition SparseField.h:994
SparseField::value
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:1598

References m_blockId, m_blockIsActivated, m_blockOrder, m_field, m_isEmptyBlock, m_manager, m_p, Sparse::SparseBlock< Data_T >::value(), x, y, and z.

## operator->()

template<class Data_T>

const Data_T * SparseField< Data_T >::const_iterator::operator-> | ( |  | ) | const

inline

Definition at line 971 of file SparseField.h.

{
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;
}
SparseField::activateBlock
void activateBlock(const int blockId) const
Activates a given block.
Definition SparseField.h:1927

References SparseFileManager::activateBlock(), m_blockId, m_blockIsActivated, m_blockOrder, m_field, m_isEmptyBlock, m_manager, m_p, Sparse::SparseBlock< Data_T >::value(), x, y, and z.

## setupNextBlock()

template<class Data_T>

void SparseField< Data_T >::const_iterator::setupNextBlock | ( | int | i,
|  | int | j,
|  | int | k )

inline private

Definition at line 998 of file SparseField.h.

{
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_numBlocks) &&
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;
}
}
SparseField::const_iterator::m_blockK
int m_blockK
Definition SparseField.h:1052
SparseField::const_iterator::m_blockJ
int m_blockJ
Definition SparseField.h:1052
SparseField::const_iterator::m_blockI
int m_blockI
Current block index.
Definition SparseField.h:1052

References Sparse::SparseBlock< Data_T >::emptyValue, Sparse::SparseBlock< Data_T >::isAllocated, m_blockI, m_blockId, m_blockIsActivated, m_blockJ, m_blockK, m_blockOrder, m_blockStepsTicker, m_field, m_isEmptyBlock, m_manager, m_p, and Sparse::SparseBlock< Data_T >::value().

Referenced by const_iterator(), and operator++().

## Member Data Documentation

## x

template<class Data_T>

int SparseField< Data_T >::const_iterator::x

Current x/y/z coord.

Definition at line 988 of file SparseField.h.

Referenced by const_iterator(), operator!=(), operator*(), operator++(), operator->(), and operator==().

## y

template<class Data_T>

int SparseField< Data_T >::const_iterator::y

Definition at line 988 of file SparseField.h.

Referenced by const_iterator(), operator!=(), operator*(), operator++(), operator->(), and operator==().

## z

template<class Data_T>

int SparseField< Data_T >::const_iterator::z

Definition at line 988 of file SparseField.h.

Referenced by const_iterator(), operator!=(), operator*(), operator++(), operator->(), and operator==().

## m_p

template<class Data_T>

const Data_T* SparseField< Data_T >::const_iterator::m_p

mutable private

Current pointed-to element.

Definition at line 1041 of file SparseField.h.

Referenced by const_iterator(), operator*(), operator++(), operator->(), and setupNextBlock().

## m_isEmptyBlock

template<class Data_T>

bool SparseField< Data_T >::const_iterator::m_isEmptyBlock

private

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

Definition at line 1043 of file SparseField.h.

Referenced by operator*(), operator++(), operator->(), and setupNextBlock().

## m_blockIsActivated

template<class Data_T>

bool SparseField< Data_T >::const_iterator::m_blockIsActivated

mutable private

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

Definition at line 1046 of file SparseField.h.

Referenced by const_iterator(), operator*(), operator++(), operator->(), and setupNextBlock().

## m_blockStepsTicker

template<class Data_T>

int SparseField< Data_T >::const_iterator::m_blockStepsTicker

private

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

Definition at line 1048 of file SparseField.h.

Referenced by const_iterator(), operator++(), and setupNextBlock().

## m_blockOrder

template<class Data_T>

int SparseField< Data_T >::const_iterator::m_blockOrder

private

Block size.

Definition at line 1050 of file SparseField.h.

Referenced by const_iterator(), operator*(), operator++(), operator->(), and setupNextBlock().

## m_blockI

template<class Data_T>

int SparseField< Data_T >::const_iterator::m_blockI

private

Current block index.

Definition at line 1052 of file SparseField.h.

Referenced by setupNextBlock().

## m_blockJ

template<class Data_T>

int SparseField< Data_T >::const_iterator::m_blockJ

private

Definition at line 1052 of file SparseField.h.

Referenced by setupNextBlock().

## m_blockK

template<class Data_T>

int SparseField< Data_T >::const_iterator::m_blockK

private

Definition at line 1052 of file SparseField.h.

Referenced by setupNextBlock().

## m_blockId

template<class Data_T>

int SparseField< Data_T >::const_iterator::m_blockId

private

Definition at line 1052 of file SparseField.h.

Referenced by const_iterator(), operator*(), operator->(), setupNextBlock(), and ~const_iterator().

## m_window

template<class Data_T>

Box3i SparseField< Data_T >::const_iterator::m_window

private

Window to traverse.

Definition at line 1054 of file SparseField.h.

Referenced by const_iterator(), and operator++().

## m_field

template<class Data_T>

const class_type* SparseField< Data_T >::const_iterator::m_field

private

Reference to field we're traversing.

Definition at line 1056 of file SparseField.h.

Referenced by const_iterator(), operator*(), operator->(), setupNextBlock(), and ~const_iterator().

## m_manager

template<class Data_T>

SparseFileManager* SparseField< Data_T >::const_iterator::m_manager

private

Pointer to the singleton file manager.

Definition at line 1058 of file SparseField.h.

Referenced by const_iterator(), operator*(), operator++(), operator->(), setupNextBlock(), and ~const_iterator().

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

- export/SparseField.h