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

Member Typedef Documentation

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

Definition at line 806 of file SparseField.h.

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

Definition at line 894 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 807 of file SparseField.h.

810  : x(currentPos.x), y(currentPos.y), z(currentPos.z),
812  m_blockId(-1), m_window(window), m_field(&field)
813  {
814  setupNextBlock(x, y, z);
815  }
int m_blockOrder
Block size.
Definition: SparseField.h:924
Box3i m_window
Window to traverse.
Definition: SparseField.h:928
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:918
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:922
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:896
int blockOrder() const
Returns the block order.
Definition: SparseField.h:1182
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:930

Member Function Documentation

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

Definition at line 816 of file SparseField.h.

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

817  {
818  bool resetPtr = false;
819  // Check against end of data window
820  if (x == m_window.max.x) {
821  if (y == m_window.max.y) {
822  x = m_window.min.x;
823  y = m_window.min.y;
824  ++z;
825  resetPtr = true;
826  } else {
827  x = m_window.min.x;
828  ++y;
829  resetPtr = true;
830  }
831  } else {
832  ++x;
833  }
834  // These can both safely be incremented here
836  // ... but only step forward if we're in a non-empty block
837  if (!m_isEmptyBlock)
838  ++m_p;
839  // Check if we've reached the end of this block
840  if (m_blockStepsTicker == (1 << m_blockOrder))
841  resetPtr = true;
842  if (resetPtr) {
843  // If we have, we need to reset the current block, etc.
844  m_blockStepsTicker = 0;
845  setupNextBlock(x, y, z);
846  }
847  return *this;
848  }
int m_blockOrder
Block size.
Definition: SparseField.h:924
Box3i m_window
Window to traverse.
Definition: SparseField.h:928
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:918
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:922
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:896
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:920
template<class Data_T>
bool SparseField< Data_T >::iterator::operator== ( const iterator rhs) const
inline

Definition at line 849 of file SparseField.h.

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

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

Definition at line 853 of file SparseField.h.

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

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

Definition at line 857 of file SparseField.h.

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

858  {
859  if (m_field->m_fileManager) {
860  assert(false && "Dereferencing iterator on a dynamic-read sparse field");
861  Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
862  "sparse field");
863  return *m_p;
864  }
865  // If the block is currently empty, we must allocate it
866  if (m_isEmptyBlock) {
867  // Touch the voxel to allocate the block
868  m_field->lvalue(x, y, z);
869  // Set up the block again
870  setupNextBlock(x, y, z);
871  }
872  return *m_p;
873  }
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:918
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:896
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
Definition: SparseField.h:1314
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:920
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:930
template<class Data_T>
Data_T* SparseField< Data_T >::iterator::operator-> ( )
inline

Definition at line 874 of file SparseField.h.

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

875  {
876  if (m_field->m_fileManager) {
877  assert(false && "Dereferencing iterator on a dynamic-read sparse field");
878  Msg::print(Msg::SevWarning, "Dereferencing iterator on a dynamic-read "
879  "sparse field");
880  return m_p;
881  }
882  // If the block is currently empty, we must allocate it
883  if (m_isEmptyBlock) {
884  // Touch the voxel to allocate the block
885  m_field->lvalue(x, y, z);
886  // Set up the block again
887  setupNextBlock(x, y, z);
888  }
889  return m_p;
890  }
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:918
void print(Severity severity, const std::string &message)
Sends the string to the assigned output, prefixing the message with the severity. ...
Definition: Log.cpp:62
void setupNextBlock(int i, int j, int k)
Convenience.
Definition: SparseField.h:896
virtual Data_T & lvalue(int i, int j, int k)
Write access to a voxel. The coordinates are global coordinates.
Definition: SparseField.h:1314
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:920
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:930
template<class Data_T>
void SparseField< Data_T >::iterator::setupNextBlock ( int  i,
int  j,
int  k 
)
inlineprivate

Convenience.

Definition at line 896 of file SparseField.h.

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

897  {
898  m_field->applyDataWindowOffset(i, j, k);
902  m_isEmptyBlock = true;
903  return;
904  }
905  Block &block = m_field->m_blocks[m_blockId];
906  int vi, vj, vk;
907  m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
908  m_blockStepsTicker = vi;
909  if (block.isAllocated) {
910  m_p = &block.value(vi, vj, vk, m_blockOrder);
911  m_isEmptyBlock = false;
912  } else {
913  m_p = &block.emptyValue;
914  m_isEmptyBlock = true;
915  }
916  }
int m_blockOrder
Block size.
Definition: SparseField.h:924
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:265
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:398
int blockId(int blockI, int blockJ, int blockK) const
Calculates the block number based on a block i,j,k index.
Definition: SparseField.h:1558
Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:918
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:922
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:894
int m_blockI
Current block index.
Definition: SparseField.h:926
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:1582
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:1567
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:920
class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:930

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 918 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 920 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 922 of file SparseField.h.

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

Block size.

Definition at line 924 of file SparseField.h.

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

Current block index.

Definition at line 926 of file SparseField.h.

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

Definition at line 926 of file SparseField.h.

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

Definition at line 926 of file SparseField.h.

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

Definition at line 926 of file SparseField.h.

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

Window to traverse.

Definition at line 928 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 930 of file SparseField.h.


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