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

Private Attributes

int m_blockI
 Current block index. More...
 
int m_blockId
 
int m_blockJ
 
int m_blockK
 
int m_blockOrder
 Block size. More...
 
int m_blockStepsTicker
 Ticker for how many more steps to take before resetting the pointer. More...
 
class_typem_field
 Reference to field we're traversing. More...
 
bool m_isEmptyBlock
 Whether we're at an empty block and we don't increment m_p. More...
 
Data_T * m_p
 Current pointed-to element. More...
 
Box3i m_window
 Window to traverse. More...
 

Detailed Description

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

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

Definition at line 1054 of file SparseField.h.

Member Typedef Documentation

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

Definition at line 1066 of file SparseField.h.

template<class Data_T>
typedef Sparse::SparseBlock<Data_T> SparseField< Data_T >::iterator::Block
private

Definition at line 1154 of file SparseField.h.

Constructor & Destructor Documentation

template<class Data_T>
SparseField< Data_T >::iterator::iterator ( class_type field,
const Box3i window,
const V3i currentPos,
int  blockOrder 
)
inline

Definition at line 1067 of file SparseField.h.

1070  : x(currentPos.x), y(currentPos.y), z(currentPos.z),
1072  m_blockId(-1), m_window(window), m_field(&field)
1073  {
1074  setupNextBlock(x, y, z);
1075  }
int m_blockOrder
Block size.
Definition: SparseField.h:1184
Box3i m_window
Window to traverse.
Definition: SparseField.h:1188
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1178
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1182
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:1156
int blockOrder() const
Returns the block order.
Definition: SparseField.h:1445
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1190

Member Function Documentation

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

Definition at line 1076 of file SparseField.h.

References SparseField< Data_T >::iterator::x.

1077  {
1078  bool resetPtr = false;
1079  // Check against end of data window
1080  if (x == m_window.max.x) {
1081  if (y == m_window.max.y) {
1082  x = m_window.min.x;
1083  y = m_window.min.y;
1084  ++z;
1085  resetPtr = true;
1086  } else {
1087  x = m_window.min.x;
1088  ++y;
1089  resetPtr = true;
1090  }
1091  } else {
1092  ++x;
1093  }
1094  // These can both safely be incremented here
1096  // ... but only step forward if we're in a non-empty block
1097  if (!m_isEmptyBlock)
1098  ++m_p;
1099  // Check if we've reached the end of this block
1100  if (m_blockStepsTicker == (1 << m_blockOrder))
1101  resetPtr = true;
1102  if (resetPtr) {
1103  // If we have, we need to reset the current block, etc.
1104  m_blockStepsTicker = 0;
1105  setupNextBlock(x, y, z);
1106  }
1107  return *this;
1108  }
int m_blockOrder
Block size.
Definition: SparseField.h:1184
Box3i m_window
Window to traverse.
Definition: SparseField.h:1188
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1178
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1182
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:1156
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1180
template<class Data_T>
bool SparseField< Data_T >::iterator::operator== ( const iterator rhs) const
inline

Definition at line 1109 of file SparseField.h.

References SparseField< Data_T >::iterator::x, SparseField< Data_T >::iterator::y, and SparseField< Data_T >::iterator::z.

1110  {
1111  return x == rhs.x && y == rhs.y && z == rhs.z;
1112  }
template<class Data_T>
bool SparseField< Data_T >::iterator::operator!= ( const iterator rhs) const
inline

Definition at line 1113 of file SparseField.h.

References SparseField< Data_T >::iterator::x, SparseField< Data_T >::iterator::y, and SparseField< Data_T >::iterator::z.

1114  {
1115  return x != rhs.x || y != rhs.y || z != rhs.z;
1116  }
template<class Data_T>
Data_T& SparseField< Data_T >::iterator::operator* ( )
inline

Definition at line 1117 of file SparseField.h.

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

1118  {
1119  if (m_field->m_fileManager) {
1120  assert(false && "Dereferencing iterator on a dynamic-read sparse field");
1121  Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
1122  "sparse field");
1123  return *m_p;
1124  }
1125  // If the block is currently empty, we must allocate it
1126  if (m_isEmptyBlock) {
1127  // Touch the voxel to allocate the block
1128  m_field->lvalue(x, y, z);
1129  // Set up the block again
1130  setupNextBlock(x, y, z);
1131  }
1132  return *m_p;
1133  }
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1178
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:66
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:1156
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
Definition: SparseField.h:1576
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1180
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1190
template<class Data_T>
Data_T* SparseField< Data_T >::iterator::operator-> ( )
inline

Definition at line 1134 of file SparseField.h.

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

1135  {
1136  if (m_field->m_fileManager) {
1137  assert(false && "Dereferencing iterator on a dynamic-read sparse field");
1138  Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
1139  "sparse field");
1140  return m_p;
1141  }
1142  // If the block is currently empty, we must allocate it
1143  if (m_isEmptyBlock) {
1144  // Touch the voxel to allocate the block
1145  m_field->lvalue(x, y, z);
1146  // Set up the block again
1147  setupNextBlock(x, y, z);
1148  }
1149  return m_p;
1150  }
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1178
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:66
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:1156
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
Definition: SparseField.h:1576
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1180
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1190
template<class Data_T>
void SparseField< Data_T >::iterator::setupNextBlock ( int  i,
int  j,
int  k 
)
inlineprivate

Convenience.

Definition at line 1156 of file SparseField.h.

References Sparse::SparseBlock< Data_T >::emptyValue, Sparse::SparseBlock< Data_T >::isAllocated, and Sparse::SparseBlock< Data_T >::value().

1157  {
1158  m_field->applyDataWindowOffset(i, j, k);
1162  m_isEmptyBlock = true;
1163  return;
1164  }
1165  Block &block = m_field->m_blocks[m_blockId];
1166  int vi, vj, vk;
1167  m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
1168  m_blockStepsTicker = vi;
1169  if (block.isAllocated) {
1170  m_p = &block.value(vi, vj, vk, m_blockOrder);
1171  m_isEmptyBlock = false;
1172  } else {
1173  m_p = &block.emptyValue;
1174  m_isEmptyBlock = true;
1175  }
1176  }
int m_blockOrder
Block size.
Definition: SparseField.h:1184
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:455
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:614
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1851
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1178
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1182
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:1154
int m_blockI
Current block index.
Definition: SparseField.h:1186
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.
Definition: SparseField.h:1875
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.
Definition: SparseField.h:1860
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1180
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1190

Member Data Documentation

template<class Data_T>
int SparseField< Data_T >::iterator::y
template<class Data_T>
int SparseField< Data_T >::iterator::z
template<class Data_T>
Data_T* SparseField< Data_T >::iterator::m_p
private

Current pointed-to element.

Definition at line 1178 of file SparseField.h.

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 1180 of file SparseField.h.

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 1182 of file SparseField.h.

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

Block size.

Definition at line 1184 of file SparseField.h.

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

Current block index.

Definition at line 1186 of file SparseField.h.

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

Definition at line 1186 of file SparseField.h.

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

Definition at line 1186 of file SparseField.h.

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

Definition at line 1186 of file SparseField.h.

template<class Data_T>
Box3i SparseField< Data_T >::iterator::m_window
private

Window to traverse.

Definition at line 1188 of file SparseField.h.

template<class Data_T>
class_type* SparseField< Data_T >::iterator::m_field
private

Reference to field we're traversing.

Definition at line 1190 of file SparseField.h.


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