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

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.
1117  m_blockStepsTicker = 0;
1118  setupNextBlock(x, y, z);
1119  }
1120  return *this;
1121  }

References 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 SparseField< Data_T >::iterator::x, SparseField< Data_T >::iterator::y, and SparseField< Data_T >::iterator::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.

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

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

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

References 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 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  {
1171  m_field->applyDataWindowOffset(i, j, k);
1175  m_isEmptyBlock = true;
1176  return;
1177  }
1178  Block &block = m_field->m_blocks[m_blockId];
1179  int vi, vj, vk;
1180  m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
1181  m_blockStepsTicker = vi;
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  }

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

Member Data Documentation

◆ x

◆ y

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

◆ z

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

◆ 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:
SparseField::m_blocks
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
SparseField::iterator::y
int y
Definition: SparseField.h:1165
SparseField::iterator::m_blockOrder
int m_blockOrder
Block size.
Definition: SparseField.h:1197
SparseField::iterator::m_window
Box3i m_window
Window to traverse.
Definition: SparseField.h:1201
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
Msg::SevWarning
Definition: Log.h:68
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::m_field
class_type * m_field
Reference to field we're traversing.
Definition: SparseField.h:1203
SparseField::lvalue
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
Definition: SparseField.h:1606
SparseField::iterator::m_blockJ
int m_blockJ
Definition: SparseField.h:1199
SparseField::iterator::m_blockId
int m_blockId
Definition: SparseField.h:1199
SparseField::getVoxelInBlock
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:1905
SparseField::m_blockXYSize
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:614
SparseField::iterator::Block
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:1167
SparseField::blockId
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1881
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
SparseField::iterator::m_blockI
int m_blockI
Current block index.
Definition: SparseField.h:1199
SparseField::getBlockCoord
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:1890
SparseField::iterator::m_blockK
int m_blockK
Definition: SparseField.h:1199
SparseField::blockOrder
int blockOrder() const
Returns the block order.
Definition: SparseField.h:1475
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
SparseField::m_blockRes
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
SparseField::applyDataWindowOffset
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:455
SparseField::m_fileManager
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
SparseField::iterator::z
int z
Definition: SparseField.h:1165