Field3D
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 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

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.

1083 : x(currentPos.x), y(currentPos.y), z(currentPos.z),
1085 m_blockId(-1), m_window(window), m_field(&field)
1086 {
1087 setupNextBlock(x, y, z);
1088 }
#define FIELD3D_MTX_T
Definition StdMathLib.h:99
int m_blockOrder
Block size.
Box3i m_window
Window to traverse.
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
void setupNextBlock(int i, int j, int k)
Convenience.
class_type * m_field
Reference to field we're traversing.
Data_T * m_p
Current pointed-to element.
int blockOrder() const
Returns the block order.

Member Function Documentation

◆ operator++()

template<class Data_T >
const iterator & SparseField< Data_T >::iterator::operator++ ( )
inline

Definition at line 1089 of file SparseField.h.

1090 {
1091 bool resetPtr = false;
1092 // Check against end of data window
1093 if (x == m_window.max.x) {
1094 if (y == m_window.max.y) {
1095 x = m_window.min.x;
1096 y = m_window.min.y;
1097 ++z;
1098 resetPtr = true;
1099 } else {
1100 x = m_window.min.x;
1101 ++y;
1102 resetPtr = true;
1103 }
1104 } else {
1105 ++x;
1106 }
1107 // These can both safely be incremented here
1109 // ... but only step forward if we're in a non-empty block
1110 if (!m_isEmptyBlock)
1111 ++m_p;
1112 // Check if we've reached the end of this block
1113 if (m_blockStepsTicker == (1 << m_blockOrder))
1114 resetPtr = true;
1115 if (resetPtr) {
1116 // If we have, we need to reset the current block, etc.
1118 setupNextBlock(x, y, z);
1119 }
1120 return *this;
1121 }
bool m_isEmptyBlock
Whether we're at an empty block and we don't increment m_p.

References FIELD3D_MTX_T, SparseField< Data_T >::m_blockOrder, and SparseField< Data_T >::iterator::x.

◆ operator==()

template<class Data_T >
bool SparseField< Data_T >::iterator::operator== ( const iterator & rhs) const
inline

Definition at line 1122 of file SparseField.h.

1123 {
1124 return x == rhs.x && y == rhs.y && z == rhs.z;
1125 }

References FIELD3D_MTX_T.

◆ operator!=()

template<class Data_T >
bool SparseField< Data_T >::iterator::operator!= ( const iterator & rhs) const
inline

Definition at line 1126 of file SparseField.h.

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

References FIELD3D_MTX_T.

◆ operator*()

template<class Data_T >
Data_T & SparseField< Data_T >::iterator::operator* ( )
inline

Definition at line 1130 of file SparseField.h.

1131 {
1132 if (m_field->m_fileManager) {
1133 assert(false && "Dereferencing iterator on a dynamic-read sparse field");
1134 Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
1135 "sparse field");
1136 return *m_p;
1137 }
1138 // If the block is currently empty, we must allocate it
1139 if (m_isEmptyBlock) {
1140 // Touch the voxel to allocate the block
1141 m_field->lvalue(x, y, z);
1142 // Set up the block again
1143 setupNextBlock(x, y, z);
1144 }
1145 return *m_p;
1146 }
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
@ SevWarning
Definition Log.h:68
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 FIELD3D_MTX_T, Msg::print(), and Msg::SevWarning.

◆ operator->()

template<class Data_T >
Data_T * SparseField< Data_T >::iterator::operator-> ( )
inline

Definition at line 1147 of file SparseField.h.

1148 {
1149 if (m_field->m_fileManager) {
1150 assert(false && "Dereferencing iterator on a dynamic-read sparse field");
1151 Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
1152 "sparse field");
1153 return m_p;
1154 }
1155 // If the block is currently empty, we must allocate it
1156 if (m_isEmptyBlock) {
1157 // Touch the voxel to allocate the block
1158 m_field->lvalue(x, y, z);
1159 // Set up the block again
1160 setupNextBlock(x, y, z);
1161 }
1162 return m_p;
1163 }

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

◆ setupNextBlock()

template<class Data_T >
void SparseField< Data_T >::iterator::setupNextBlock ( int i,
int j,
int k )
inlineprivate

Convenience.

Definition at line 1169 of file SparseField.h.

1170 {
1175 m_isEmptyBlock = true;
1176 return;
1177 }
1179 int vi, vj, vk;
1180 m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
1182 if (block.isAllocated) {
1183 m_p = &block.value(vi, vj, vk, m_blockOrder);
1184 m_isEmptyBlock = false;
1185 } else {
1186 m_p = &block.emptyValue;
1187 m_isEmptyBlock = true;
1188 }
1189 }
Sparse::SparseBlock< Data_T > Block
int m_blockI
Current block index.
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
int m_blockXYSize
Block array res.x * res.y.
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.
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.
V3i m_blockRes
Block array resolution.
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.

References FIELD3D_MTX_T, SparseField< Data_T >::m_blockOrder, and Sparse::SparseBlock< Data_T >::value().

Member Data Documentation

◆ x

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

Definition at line 1165 of file SparseField.h.

Referenced by SparseField< Data_T >::iterator::operator++().

◆ y

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

Definition at line 1165 of file SparseField.h.

◆ z

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

Definition at line 1165 of file SparseField.h.

◆ 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.

◆ 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.

◆ 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.

◆ m_blockOrder

template<class Data_T >
int SparseField< Data_T >::iterator::m_blockOrder
private

Block size.

Definition at line 1197 of file SparseField.h.

◆ 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.

◆ m_blockJ

template<class Data_T >
int SparseField< Data_T >::iterator::m_blockJ
private

Definition at line 1199 of file SparseField.h.

◆ m_blockK

template<class Data_T >
int SparseField< Data_T >::iterator::m_blockK
private

Definition at line 1199 of file SparseField.h.

◆ m_blockId

template<class Data_T >
int SparseField< Data_T >::iterator::m_blockId
private

Definition at line 1199 of file SparseField.h.

◆ 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.

◆ 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.


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