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

Member Typedef Documentation

◆ class_type

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

Definition at line 897 of file SparseField.h.

◆ Block

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

Definition at line 994 of file SparseField.h.

Constructor & Destructor Documentation

◆ const_iterator()

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

901  : x(currentPos.x), y(currentPos.y), z(currentPos.z),
902  m_p(NULL), m_blockIsActivated(false),
904  m_blockId(-1), m_window(window), m_field(&field)
905  {
907  setupNextBlock(x, y, z);
908  }

◆ ~const_iterator()

template<class Data_T>
SparseField< Data_T >::const_iterator::~const_iterator ( )
inline

Definition at line 909 of file SparseField.h.

909  {
910  if (m_manager && m_blockId >= 0 &&
911  m_blockId < static_cast<int>(m_field->m_numBlocks)) {
914  }
915  }

Member Function Documentation

◆ operator++()

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

Definition at line 916 of file SparseField.h.

917  {
918  bool resetPtr = false;
919  // Check against end of data window
920  if (x == m_window.max.x) {
921  if (y == m_window.max.y) {
922  x = m_window.min.x;
923  y = m_window.min.y;
924  ++z;
925  resetPtr = true;
926  } else {
927  x = m_window.min.x;
928  ++y;
929  resetPtr = true;
930  }
931  } else {
932  ++x;
933  }
934  // These can both safely be incremented here
936  // ... but only step forward if we're in a non-empty block
938  ++m_p;
939  // Check if we've reached the end of this block
940  if (m_blockStepsTicker == (1 << m_blockOrder))
941  resetPtr = true;
942  if (resetPtr) {
943  // If we have, we need to reset the current block, etc.
944  m_blockStepsTicker = 0;
945  setupNextBlock(x, y, z);
946  }
947  return *this;
948  }

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

◆ operator==()

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

Definition at line 950 of file SparseField.h.

951  {
952  return x == rhs.x && y == rhs.y && z == rhs.z;
953  }

◆ operator!=()

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

Definition at line 955 of file SparseField.h.

956  {
957  return x != rhs.x || y != rhs.y || z != rhs.z;
958  }

◆ operator*()

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

Definition at line 959 of file SparseField.h.

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

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

◆ operator->()

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

Definition at line 971 of file SparseField.h.

972  {
975  manager->activateBlock<Data_T>(m_field->m_fileId, m_blockId);
976  m_blockIsActivated = true;
977  const Block &block = m_field->m_blocks[m_blockId];
978  int vi, vj, vk;
979  m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
980  m_p = &block.value(vi, vj, vk, m_blockOrder);
981  }
982  return m_p;
983  }

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

◆ setupNextBlock()

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

Definition at line 998 of file SparseField.h.

999  {
1000  m_field->applyDataWindowOffset(i, j, k);
1002  int oldBlockId = m_blockId;
1004  if (m_manager && oldBlockId != m_blockId &&
1005  oldBlockId >= 0 &&
1006  oldBlockId < static_cast<int>(m_field->m_numBlocks) &&
1007  m_field->m_blocks[oldBlockId].isAllocated) {
1008  m_manager->decBlockRef<Data_T>(m_field->m_fileId, oldBlockId);
1009  }
1011  m_isEmptyBlock = true;
1012  return;
1013  }
1014 
1015  const Block &block = m_field->m_blocks[m_blockId];
1016  int vi, vj, vk;
1017  m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
1018  m_blockStepsTicker = vi;
1019  if (block.isAllocated) {
1020  if (m_manager && oldBlockId != m_blockId && m_blockId >= 0) {
1022  // this is a managed field, so the block may not be loaded
1023  // yet, so don't bother setting m_p yet (it'll get set in the
1024  // * and -> operators when the block is activated)
1025  } else {
1026  // only set m_p to the voxel's address if this is not a
1027  // managed field, i.e., if the data is already in memory.
1028  m_p = &block.value(vi, vj, vk, m_blockOrder);
1029  }
1030  m_isEmptyBlock = false;
1031  } else {
1032  m_p = &block.emptyValue;
1033  m_isEmptyBlock = true;
1034  }
1035  if (m_field->m_fileManager) {
1036  m_blockIsActivated = false;
1037  }
1038  }

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

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

Current x/y/z coord.

Definition at line 988 of file SparseField.h.

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

◆ y

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

Definition at line 988 of file SparseField.h.

◆ z

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

Definition at line 988 of file SparseField.h.

◆ m_p

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

Current pointed-to element.

Definition at line 1041 of file SparseField.h.

◆ m_isEmptyBlock

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

◆ m_blockIsActivated

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

◆ m_blockStepsTicker

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

◆ m_blockOrder

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

Block size.

Definition at line 1050 of file SparseField.h.

◆ m_blockI

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

Current block index.

Definition at line 1052 of file SparseField.h.

◆ m_blockJ

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

Definition at line 1052 of file SparseField.h.

◆ m_blockK

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

Definition at line 1052 of file SparseField.h.

◆ m_blockId

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

Definition at line 1052 of file SparseField.h.

◆ m_window

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

Window to traverse.

Definition at line 1054 of file SparseField.h.

◆ m_field

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

Reference to field we're traversing.

Definition at line 1056 of file SparseField.h.

◆ m_manager

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

Pointer to the singleton file manager.

Definition at line 1058 of file SparseField.h.


The documentation for this class was generated from the following file:
SparseField::const_iterator::m_blockIsActivated
bool m_blockIsActivated
Used with delayed-load fields. Check if we've already activated the current blocks.
Definition: SparseField.h:1046
SparseField::const_iterator::setupNextBlock
void setupNextBlock(int i, int j, int k)
Definition: SparseField.h:998
SparseField::m_blocks
Block * m_blocks
Array of blocks. Not using std::vector since SparseBlock is noncopyable.
Definition: SparseField.h:616
SparseField::const_iterator::m_blockId
int m_blockId
Definition: SparseField.h:1052
SparseField::const_iterator::m_blockJ
int m_blockJ
Definition: SparseField.h:1052
SparseField::const_iterator::m_blockStepsTicker
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:1048
SparseFileManager::activateBlock
void activateBlock(int fileId, int blockIdx)
Called by SparseField when it's about to read from a block. This should not be called by the user,...
Definition: SparseFile.h:1256
SparseFileManager::incBlockRef
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:1297
SparseField::const_iterator::m_field
const class_type * m_field
Reference to field we're traversing.
Definition: SparseField.h:1056
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::const_iterator::z
int z
Definition: SparseField.h:988
SparseField::const_iterator::m_blockK
int m_blockK
Definition: SparseField.h:1052
SparseField::m_blockXYSize
int m_blockXYSize
Block array res.x * res.y.
Definition: SparseField.h:614
SparseField::const_iterator::m_blockI
int m_blockI
Current block index.
Definition: SparseField.h:1052
SparseField::const_iterator::y
int y
Definition: SparseField.h:988
SparseField::const_iterator::m_blockOrder
int m_blockOrder
Block size.
Definition: SparseField.h:1050
SparseField::const_iterator::m_p
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:1041
SparseField::const_iterator::m_manager
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:1058
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::const_iterator::x
int x
Current x/y/z coord.
Definition: SparseField.h:988
SparseFileManager
Definition: SparseFile.h:396
Sparse::SparseBlock::isAllocated
bool isAllocated
Whether the block is allocated or not.
Definition: SparseField.h:303
SparseField::const_iterator::Block
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:994
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
SparseFileManager::decBlockRef
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:1310
SparseField::blockOrder
int blockOrder() const
Returns the block order.
Definition: SparseField.h:1475
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_fileId
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:624
SparseField::m_numBlocks
size_t m_numBlocks
Number of blocks in field.
Definition: SparseField.h:618
SparseField::m_fileManager
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:622
SparseField::const_iterator::m_window
Box3i m_window
Window to traverse.
Definition: SparseField.h:1054
SparseField::const_iterator::m_isEmptyBlock
bool m_isEmptyBlock
Whether we're at an empty block and we don't increment m_p.
Definition: SparseField.h:1043