SparseField< Data_T >::iterator Class Reference

`#include <SparseField.h>`

## 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 iterator & | operator++ ()
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_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.
Data_T * | m_p
| Current pointed-to element.
Box3i | m_window
| Window to traverse.

## Detailed Description

template<class Data_T>
class SparseField< Data_T >::iterator

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

Definition at line 1067 of file SparseField.h.

## Member Typedef Documentation

## class_type

template<class Data_T>

typedef SparseField<Data_T> SparseField< Data_T >::iterator::class_type

Definition at line 1079 of file SparseField.h.

## Block

template<class Data_T>

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

private

Definition at line 1167 of file SparseField.h.

## Constructor & Destructor Documentation

## iterator()

template<class Data_T>

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

inline

Definition at line 1080 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);
}
SparseField::iterator::m_blockOrder
int m_blockOrder
Block size.
Definition SparseField.h:1197
SparseField::iterator::m_blockId
int m_blockId
Definition SparseField.h:1199
SparseField::iterator::m_window
Box3i m_window
Window to traverse.
Definition SparseField.h:1201
SparseField::iterator::m_blockStepsTicker
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition SparseField.h:1195
SparseField::iterator::setupNextBlock
void setupNextBlock(int i, int j, int k)
Convenience.
Definition SparseField.h:1169
SparseField::iterator::y
int y
Definition SparseField.h:1165
SparseField::iterator::z
int z
Definition SparseField.h:1165
SparseField::iterator::m_field
class_type * m_field
Reference to field we're traversing.
Definition SparseField.h:1203
SparseField::iterator::m_p
Data_T * m_p
Current pointed-to element.
Definition SparseField.h:1191
SparseField::iterator::x
int x
Definition SparseField.h:1165
SparseField
This Field subclass stores voxel data in block-allocated arrays.
Definition SparseField.h:352

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

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

## Member Function Documentation

## operator++()

template<class Data_T>

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

inline

Definition at line 1089 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_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::iterator::m_isEmptyBlock
bool m_isEmptyBlock
Whether we're at an empty block and we don't increment m_p.
Definition SparseField.h:1193

References iterator(), m_blockOrder, m_blockStepsTicker, m_isEmptyBlock, m_p, m_window, setupNextBlock(), x, y, and z.

## operator==()

template<class Data_T>

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

inline

Definition at line 1122 of file SparseField.h.

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

References iterator(), x, y, and z.

## operator!=()

template<class Data_T>

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

inline

Definition at line 1126 of file SparseField.h.

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

References iterator(), x, y, and z.

## operator*()

template<class Data_T>

Data_T & SparseField< Data_T >::iterator::operator* | ( |  | ) |

inline

Definition at line 1130 of file SparseField.h.

{
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;
}
Msg::print
FIELD3D_API void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity.
Definition Log.cpp:70

References m_field, m_isEmptyBlock, m_p, Msg::print(), setupNextBlock(), Msg::SevWarning, x, y, and z.

## operator->()

template<class Data_T>

Data_T * SparseField< Data_T >::iterator::operator-> | ( |  | ) |

inline

Definition at line 1147 of file SparseField.h.

{
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;
}

References m_field, m_isEmptyBlock, m_p, Msg::print(), setupNextBlock(), Msg::SevWarning, x, y, and z.

## setupNextBlock()

template<class Data_T>

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

inline private

Convenience.

Definition at line 1169 of file SparseField.h.

{
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;
}
}
SparseField::iterator::Block
Sparse::SparseBlock< Data_T > Block
Definition SparseField.h:1167
SparseField::iterator::m_blockI
int m_blockI
Current block index.
Definition SparseField.h:1199
SparseField::iterator::m_blockK
int m_blockK
Definition SparseField.h:1199
SparseField::iterator::m_blockJ
int m_blockJ
Definition SparseField.h:1199
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 Sparse::SparseBlock< Data_T >::emptyValue, Sparse::SparseBlock< Data_T >::isAllocated, m_blockI, m_blockId, m_blockJ, m_blockK, m_blockOrder, m_blockStepsTicker, m_field, m_isEmptyBlock, m_p, and Sparse::SparseBlock< Data_T >::value().

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

## Member Data Documentation

## x

template<class Data_T>

int SparseField< Data_T >::iterator::x

Definition at line 1165 of file SparseField.h.

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

## y

template<class Data_T>

int SparseField< Data_T >::iterator::y

Definition at line 1165 of file SparseField.h.

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

## z

template<class Data_T>

int SparseField< Data_T >::iterator::z

Definition at line 1165 of file SparseField.h.

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

## m_p

template<class Data_T>

Data_T* SparseField< Data_T >::iterator::m_p

private

Current pointed-to element.

Definition at line 1191 of file SparseField.h.

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

## m_isEmptyBlock

template<class Data_T>

bool SparseField< Data_T >::iterator::m_isEmptyBlock

private

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

Definition at line 1193 of file SparseField.h.

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

## m_blockStepsTicker

template<class Data_T>

int SparseField< Data_T >::iterator::m_blockStepsTicker

private

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

Definition at line 1195 of file SparseField.h.

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

## m_blockOrder

template<class Data_T>

int SparseField< Data_T >::iterator::m_blockOrder

private

Block size.

Definition at line 1197 of file SparseField.h.

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

## m_blockI

template<class Data_T>

int SparseField< Data_T >::iterator::m_blockI

private

Current block index.

Definition at line 1199 of file SparseField.h.

Referenced by setupNextBlock().

## m_blockJ

template<class Data_T>

int SparseField< Data_T >::iterator::m_blockJ

private

Definition at line 1199 of file SparseField.h.

Referenced by setupNextBlock().

## m_blockK

template<class Data_T>

int SparseField< Data_T >::iterator::m_blockK

private

Definition at line 1199 of file SparseField.h.

Referenced by setupNextBlock().

## m_blockId

template<class Data_T>

int SparseField< Data_T >::iterator::m_blockId

private

Definition at line 1199 of file SparseField.h.

Referenced by iterator(), and setupNextBlock().

## m_window

template<class Data_T>

Box3i SparseField< Data_T >::iterator::m_window

private

Window to traverse.

Definition at line 1201 of file SparseField.h.

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

## m_field

template<class Data_T>

class_type* SparseField< Data_T >::iterator::m_field

private

Reference to field we're traversing.

Definition at line 1203 of file SparseField.h.

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

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

- export/SparseField.h