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

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

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

637  : x(currentPos.x), y(currentPos.y), z(currentPos.z),
638  m_p(NULL), m_blockIsActivated(false),
640  m_blockId(-1), m_window(window), m_field(&field)
641  {
643  setupNextBlock(x, y, z);
644  }
int x
Current x/y/z coord.
Definition: SparseField.h:724
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:777
int m_blockOrder
Block size.
Definition: SparseField.h:786
Box3i m_window
Window to traverse.
Definition: SparseField.h:790
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:792
int blockOrder() const
Returns the block order.
Definition: SparseField.h:1182
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:782
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:794
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:784
void setupNextBlock(int i, int j, int k)
Definition: SparseField.h:734
template<class Data_T>
SparseField< Data_T >::const_iterator::~const_iterator ( )
inline

Definition at line 645 of file SparseField.h.

645  {
646  if (m_manager && m_blockId >= 0 &&
647  m_blockId < static_cast<int>(m_field->m_blocks.size())) {
648  if (m_field->m_blocks[m_blockId].isAllocated)
650  }
651  }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
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:1069
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:792
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:794

Member Function Documentation

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

Definition at line 652 of file SparseField.h.

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

653  {
654  bool resetPtr = false;
655  // Check against end of data window
656  if (x == m_window.max.x) {
657  if (y == m_window.max.y) {
658  x = m_window.min.x;
659  y = m_window.min.y;
660  ++z;
661  resetPtr = true;
662  } else {
663  x = m_window.min.x;
664  ++y;
665  resetPtr = true;
666  }
667  } else {
668  ++x;
669  }
670  // These can both safely be incremented here
672  // ... but only step forward if we're in a non-empty block
674  ++m_p;
675  // Check if we've reached the end of this block
676  if (m_blockStepsTicker == (1 << m_blockOrder))
677  resetPtr = true;
678  if (resetPtr) {
679  // If we have, we need to reset the current block, etc.
680  m_blockStepsTicker = 0;
681  setupNextBlock(x, y, z);
682  }
683  return *this;
684  }
int x
Current x/y/z coord.
Definition: SparseField.h:724
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:777
int m_blockOrder
Block size.
Definition: SparseField.h:786
Box3i m_window
Window to traverse.
Definition: SparseField.h:790
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:779
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:782
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:794
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:784
void setupNextBlock(int i, int j, int k)
Definition: SparseField.h:734
template<class Data_T>
template<class Iter_T >
bool SparseField< Data_T >::const_iterator::operator== ( const Iter_T &  rhs) const
inline

Definition at line 686 of file SparseField.h.

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

Definition at line 691 of file SparseField.h.

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

Definition at line 695 of file SparseField.h.

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

696  {
699  m_blockIsActivated = true;
700  const Block &block = m_field->m_blocks[m_blockId];
701  int vi, vj, vk;
702  m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
703  m_p = &block.value(vi, vj, vk, m_blockOrder);
704  }
705  return *m_p;
706  }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
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:1020
int x
Current x/y/z coord.
Definition: SparseField.h:724
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:777
int m_blockOrder
Block size.
Definition: SparseField.h:786
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
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:792
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:779
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:782
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:730
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:794
template<class Data_T>
const Data_T* SparseField< Data_T >::const_iterator::operator-> ( ) const
inline

Definition at line 707 of file SparseField.h.

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

708  {
711  manager->activateBlock<Data_T>(m_field->m_fileId, m_blockId);
712  m_blockIsActivated = true;
713  const Block &block = m_field->m_blocks[m_blockId];
714  int vi, vj, vk;
715  m_field->getVoxelInBlock(x, y, z, vi, vj, vk);
716  m_p = &block.value(vi, vj, vk, m_blockOrder);
717  }
718  return m_p;
719  }
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
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:1020
int x
Current x/y/z coord.
Definition: SparseField.h:724
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:777
int m_blockOrder
Block size.
Definition: SparseField.h:786
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
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:792
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:779
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:782
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:730
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:794
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
template<class Data_T>
void SparseField< Data_T >::const_iterator::setupNextBlock ( int  i,
int  j,
int  k 
)
inlineprivate

Definition at line 734 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().

735  {
736  m_field->applyDataWindowOffset(i, j, k);
738  int oldBlockId = m_blockId;
740  if (m_manager && oldBlockId != m_blockId &&
741  oldBlockId >= 0 &&
742  oldBlockId < static_cast<int>(m_field->m_blocks.size()) &&
743  m_field->m_blocks[oldBlockId].isAllocated) {
744  m_manager->decBlockRef<Data_T>(m_field->m_fileId, oldBlockId);
745  }
747  m_isEmptyBlock = true;
748  return;
749  }
750 
751  const Block &block = m_field->m_blocks[m_blockId];
752  int vi, vj, vk;
753  m_field->getVoxelInBlock(i, j, k, vi, vj, vk);
754  m_blockStepsTicker = vi;
755  if (block.isAllocated) {
756  if (m_manager && oldBlockId != m_blockId && m_blockId >= 0) {
758  // this is a managed field, so the block may not be loaded
759  // yet, so don't bother setting m_p yet (it'll get set in the
760  // * and -> operators when the block is activated)
761  } else {
762  // only set m_p to the voxel's address if this is not a
763  // managed field, i.e., if the data is already in memory.
764  m_p = &block.value(vi, vj, vk, m_blockOrder);
765  }
766  m_isEmptyBlock = false;
767  } else {
768  m_p = &block.emptyValue;
769  m_isEmptyBlock = true;
770  }
771  if (m_field->m_fileManager) {
772  m_blockIsActivated = false;
773  }
774  }
V3i m_blockRes
Block array resolution.
Definition: SparseField.h:396
int m_fileId
File id. Used with m_fileManager if active. Otherwise -1.
Definition: SparseField.h:406
void applyDataWindowOffset(int &i, int &j, int &k) const
Applies data window offset.
Definition: SparseField.h:265
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:1056
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
std::vector< Block > m_blocks
Information for all blocks in the field.
Definition: SparseField.h:400
const Data_T * m_p
Current pointed-to element.
Definition: SparseField.h:777
int m_blockOrder
Block size.
Definition: SparseField.h:786
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:1069
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
const class_type * m_field
Reference to field we&#39;re traversing.
Definition: SparseField.h:792
bool m_isEmptyBlock
Whether we&#39;re at an empty block and we don&#39;t increment m_p.
Definition: SparseField.h:779
bool m_blockIsActivated
Used with delayed-load fields. Check if we&#39;ve already activated the current blocks.
Definition: SparseField.h:782
Sparse::SparseBlock< Data_T > Block
Definition: SparseField.h:730
int m_blockI
Current block index.
Definition: SparseField.h:788
SparseFileManager * m_manager
Pointer to the singleton file manager.
Definition: SparseField.h:794
SparseFileManager * m_fileManager
Pointer to SparseFileManager. Used when doing dynamic reading. NULL if not in use.
Definition: SparseField.h:404
int m_blockStepsTicker
Ticker for how many more steps to take before resetting the pointer.
Definition: SparseField.h:784

Member Data Documentation

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

Current x/y/z coord.

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

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

Definition at line 724 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 777 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 779 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 782 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 784 of file SparseField.h.

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

Block size.

Definition at line 786 of file SparseField.h.

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

Current block index.

Definition at line 788 of file SparseField.h.

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

Definition at line 788 of file SparseField.h.

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

Definition at line 788 of file SparseField.h.

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

Definition at line 788 of file SparseField.h.

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

Window to traverse.

Definition at line 790 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 792 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 794 of file SparseField.h.


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