Field3D
SparseField< Data_T >::const_iterator Class Reference

#include <SparseField.h>

Public Types

typedef SparseField< Data_T > class_type
 

Public Member Functions

 const_iterator (const class_type &field, const Box3i &window, const V3i &currentPos, int blockOrder)
 
template<class Iter_T >
bool operator!= (const Iter_T &rhs) const
 
const Data_T & operator* () const
 
const const_iteratoroperator++ ()
 
const Data_T * operator-> () const
 
template<class Iter_T >
bool operator== (const Iter_T &rhs) const
 
 ~const_iterator ()
 

Public Attributes

int x
 Current x/y/z coord. More...
 
int y
 
int z
 

Private Types

typedef Sparse::SparseBlock< Data_T > Block
 

Private Member Functions

void setupNextBlock (int i, int j, int k)
 

Private Attributes

int m_blockI
 Current block index. More...
 
int m_blockId
 
bool m_blockIsActivated
 Used with delayed-load fields. Check if we've already activated the current blocks. More...
 
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...
 
const 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...
 
SparseFileManagerm_manager
 Pointer to the singleton file manager. More...
 
const 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 >::const_iterator

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

Definition at line 872 of file SparseField.h.

Member Typedef Documentation

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

Definition at line 884 of file SparseField.h.

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

Definition at line 981 of file SparseField.h.

Constructor & Destructor Documentation

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

Definition at line 885 of file SparseField.h.

888  : x(currentPos.x), y(currentPos.y), z(currentPos.z),
889  m_p(NULL), m_blockIsActivated(false),
891  m_blockId(-1), m_window(window), m_field(&field)
892  {
894  setupNextBlock(x, y, z);
895  }
int x
Current x/y/z coord.
Definition: SparseField.h:975
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1028
int m_blockOrder
Block size.
Definition: SparseField.h:1037
Box3i m_window
Window to traverse.
Definition: SparseField.h:1041
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1043
int blockOrder() const
Returns the block order.
Definition: SparseField.h:1445
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:1033
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1045
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1035
void setupNextBlock(int i, int j, int k)
Definition: SparseField.h:985
template<class Data_T>
SparseField< Data_T >::const_iterator::~const_iterator ( )
inline

Definition at line 896 of file SparseField.h.

896  {
897  if (m_manager && m_blockId >= 0 &&
898  m_blockId < static_cast<int>(m_field->m_numBlocks)) {
901  }
902  }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
void decBlockRef(int fileId, int blockIdx)
Decrements the usage reference count on the specified block, after its value is no longer being used ...
Definition: SparseFile.h:1255
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1043
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1045
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616

Member Function Documentation

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

Definition at line 903 of file SparseField.h.

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

904  {
905  bool resetPtr = false;
906  // Check against end of data window
907  if (x == m_window.max.x) {
908  if (y == m_window.max.y) {
909  x = m_window.min.x;
910  y = m_window.min.y;
911  ++z;
912  resetPtr = true;
913  } else {
914  x = m_window.min.x;
915  ++y;
916  resetPtr = true;
917  }
918  } else {
919  ++x;
920  }
921  // These can both safely be incremented here
923  // ... but only step forward if we're in a non-empty block
925  ++m_p;
926  // Check if we've reached the end of this block
927  if (m_blockStepsTicker == (1 << m_blockOrder))
928  resetPtr = true;
929  if (resetPtr) {
930  // If we have, we need to reset the current block, etc.
931  m_blockStepsTicker = 0;
932  setupNextBlock(x, y, z);
933  }
934  return *this;
935  }
int x
Current x/y/z coord.
Definition: SparseField.h:975
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1028
int m_blockOrder
Block size.
Definition: SparseField.h:1037
Box3i m_window
Window to traverse.
Definition: SparseField.h:1041
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1030
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:1033
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1045
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1035
void setupNextBlock(int i, int j, int k)
Definition: SparseField.h:985
template<class Data_T>
template<class Iter_T >
bool SparseField< Data_T >::const_iterator::operator== ( const Iter_T &  rhs) const
inline

Definition at line 937 of file SparseField.h.

938  {
939  return x == rhs.x && y == rhs.y && z == rhs.z;
940  }
int x
Current x/y/z coord.
Definition: SparseField.h:975
template<class Data_T>
template<class Iter_T >
bool SparseField< Data_T >::const_iterator::operator!= ( const Iter_T &  rhs) const
inline

Definition at line 942 of file SparseField.h.

943  {
944  return x != rhs.x || y != rhs.y || z != rhs.z;
945  }
int x
Current x/y/z coord.
Definition: SparseField.h:975
template<class Data_T>
const Data_T& SparseField< Data_T >::const_iterator::operator* ( ) const
inline

Definition at line 946 of file SparseField.h.

References Sparse::SparseBlock< Data_T >::value().

947  {
950  m_blockIsActivated = true;
951  const Block &block = m_field->m_blocks[m_blockId];
952  int vi, vj, vk;
953  m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
954  m_p = &block.value(vi, vj, vk, m_blockOrder);
955  }
956  return *m_p;
957  }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
void activateBlock(int fileId, int blockIdx)
Called by SparseField when it&#39;s about to read from a block. This should not be called by the user...
Definition: SparseFile.h:1206
int x
Current x/y/z coord.
Definition: SparseField.h:975
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1028
int m_blockOrder
Block size.
Definition: SparseField.h:1037
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
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1043
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1030
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:1033
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:981
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1045
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T>
const Data_T* SparseField< Data_T >::const_iterator::operator-> ( ) const
inline

Definition at line 958 of file SparseField.h.

References SparseFileManager::activateBlock(), and Sparse::SparseBlock< Data_T >::value().

959  {
962  manager->activateBlock<Data_T>(m_field->m_fileId, m_blockId);
963  m_blockIsActivated = true;
964  const Block &block = m_field->m_blocks[m_blockId];
965  int vi, vj, vk;
966  m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
967  m_p = &block.value(vi, vj, vk, m_blockOrder);
968  }
969  return m_p;
970  }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
void activateBlock(int fileId, int blockIdx)
Called by SparseField when it&#39;s about to read from a block. This should not be called by the user...
Definition: SparseFile.h:1206
int x
Current x/y/z coord.
Definition: SparseField.h:975
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1028
int m_blockOrder
Block size.
Definition: SparseField.h:1037
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
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1043
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1030
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:1033
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:981
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1045
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
template<class Data_T>
void SparseField< Data_T >::const_iterator::setupNextBlock ( int  i,
int  j,
int  k 
)
inlineprivate

Definition at line 985 of file SparseField.h.

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

986  {
987  m_field->applyDataWindowOffset(i, j, k);
989  int oldBlockId = m_blockId;
991  if (m_manager && oldBlockId != m_blockId &&
992  oldBlockId >= 0 &&
993  oldBlockId < static_cast<int>(m_field->m_numBlocks) &&
994  m_field->m_blocks[oldBlockId].isAllocated) {
995  m_manager->decBlockRef<Data_T>(m_field->m_fileId, oldBlockId);
996  }
998  m_isEmptyBlock = true;
999  return;
1000  }
1001 
1002  const Block &block = m_field->m_blocks[m_blockId];
1003  int vi, vj, vk;
1004  m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
1005  m_blockStepsTicker = vi;
1006  if (block.isAllocated) {
1007  if (m_manager && oldBlockId != m_blockId && m_blockId >= 0) {
1009  // this is a managed field, so the block may not be loaded
1010  // yet, so don't bother setting m_p yet (it'll get set in the
1011  // * and -> operators when the block is activated)
1012  } else {
1013  // only set m_p to the voxel's address if this is not a
1014  // managed field, i.e., if the data is already in memory.
1015  m_p = &block.value(vi, vj, vk, m_blockOrder);
1016  }
1017  m_isEmptyBlock = false;
1018  } else {
1019  m_p = &block.emptyValue;
1020  m_isEmptyBlock = true;
1021  }
1022  if (m_field->m_fileManager) {
1023  m_blockIsActivated = false;
1024  }
1025  }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:612
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:455
void incBlockRef(int fileId, int blockIdx)
Increments the usage reference count on the specified block, to prevent it from getting unloaded whil...
Definition: SparseFile.h:1242
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
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1028
int m_blockOrder
Block size.
Definition: SparseField.h:1037
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
void decBlockRef(int fileId, int blockIdx)
Decrements the usage reference count on the specified block, after its value is no longer being used ...
Definition: SparseFile.h:1255
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
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:1043
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:1030
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:1033
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:981
int m_blockI
Current block index.
Definition: SparseField.h:1039
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1045
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1035
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616

Member Data Documentation

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

Current x/y/z coord.

Definition at line 975 of file SparseField.h.

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

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

Definition at line 975 of file SparseField.h.

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

Definition at line 975 of file SparseField.h.

template<class Data_T>
const Data_T* SparseField< Data_T >::const_iterator::m_p
mutableprivate

Current pointed-to element.

Definition at line 1028 of file SparseField.h.

template<class Data_T>
bool SparseField< Data_T >::const_iterator::m_isEmptyBlock
private

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

Definition at line 1030 of file SparseField.h.

template<class Data_T>
bool SparseField< Data_T >::const_iterator::m_blockIsActivated
mutableprivate

Used with delayed-load fields. Check if we've already activated the current blocks.

Definition at line 1033 of file SparseField.h.

template<class Data_T>
int SparseField< Data_T >::const_iterator::m_blockStepsTicker
private

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

Definition at line 1035 of file SparseField.h.

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

Block size.

Definition at line 1037 of file SparseField.h.

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

Current block index.

Definition at line 1039 of file SparseField.h.

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

Definition at line 1039 of file SparseField.h.

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

Definition at line 1039 of file SparseField.h.

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

Definition at line 1039 of file SparseField.h.

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

Window to traverse.

Definition at line 1041 of file SparseField.h.

template<class Data_T>
const class_type* SparseField< Data_T >::const_iterator::m_field
private

Reference to field we're traversing.

Definition at line 1043 of file SparseField.h.

template<class Data_T>
SparseFileManager* SparseField< Data_T >::const_iterator::m_manager
private

Pointer to the singleton file manager.

Definition at line 1045 of file SparseField.h.


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