NPL
Neurological Programs and Libraries
npl::ChunkSlicer Class Reference

This class is used to step through an ND array in order of dimensions, but unlike Slicer it breaks the NDArray into chunks. Iteration stops at the end of each chunk until nextChunk is called. By default only one chunk is used, equal to the entire image. Use setBreaks() to set the frequency of chunks. The input to setBreaks() is an array of integers, where the next chunk occurs when distbreak == 0, with the special property that break=0 indicates no breaks for the dimension. So for a 3D image, setBreaks({1,0,0}) will stop every time a new x-values is reached. Note that the affects the order of iteration, so x cannot be the fastest iterator. setChunkSize() is an alias for setBreaks. Note that in cases where breaksize != 0, for example image size = 5 and break = 3, chunk sizes will differ during the course of iteration! More...

#include <slicer.h>

Inherited by npl::ChunkConstIter< T >, and npl::ChunkIter< T >.

Public Member Functions

 ChunkSlicer ()
 Default Constructor, max a length 1, dimension 1 slicer. More...
 
 ChunkSlicer (size_t ndim, const size_t *dim)
 Constructor, takses the number of dimensions and the size of the image. More...
 
void setDim (size_t ndim, const size_t *dim)
 Sets the dimensionality of iteration, and the dimensions of the image. More...
 
bool isBegin () const
 Are we at the begining of iteration? More...
 
bool isEnd () const
 Are we at the end of iteration? Note that this will be 1 past the end, as typically is done in c++. More...
 
bool eof () const
 Are we at the end of iteration? Note that this will be 1 past the end, as typically is done in c++. More...
 
bool isChunkBegin () const
 Returns true when we have reached the end of the chunk. More...
 
bool isChunkEnd () const
 Returns true when we have reached the end of the chunk. More...
 
bool eoc () const
 Returns true when we have reached the end of the chunk. More...
 
ChunkSliceroperator++ ()
 Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder. More...
 
ChunkSliceroperator-- ()
 Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder. More...
 
ChunkSlicernextChunk ()
 Proceed to the next chunk (if there is one). More...
 
ChunkSlicerprevChunk ()
 Return to the previous chunk (if there is one). More...
 
void goChunkBegin ()
 Go to the beginning for the current chunk. More...
 
void goChunkEnd ()
 Jump to the end of current chunk. More...
 
void goBegin ()
 Go to the very beginning for the first chunk. More...
 
void goEnd ()
 Jump to the end of the last chunk. More...
 
void goIndex (size_t len, int64_t *newpos)
 Jump to the given position, additional values in newpos beyond dim will be ignored. Any values missing due to ndim > len will be treated as zeros. More...
 
void goIndex (std::vector< int64_t > newpos)
 Jump to the given position. More...
 
int64_t operator* () const
 dereference operator. Returns the linear position in the array given the n-dimensional position. More...
 
void index (size_t len, int64_t *index) const
 Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ. More...
 
void index (size_t len, int *index) const
 Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ. More...
 
void index (size_t len, double *index) const
 Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ. More...
 
void index (std::vector< int64_t > &ind) const
 Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ. More...
 
void index (std::vector< int > &ind) const
 Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ. More...
 
void index (std::vector< double > &ind) const
 Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ. More...
 
int64_t index (size_t dd) const
 Returns the index in the specified dimension. More...
 
size_t linIndex () const
 get linear position of current point More...
 
int64_t getStride (size_t dd)
 get stride in specified dimension More...
 
void setROI (size_t len, const size_t *roisize, const int64_t *roistart=NULL)
 Sets the region of interest, with lower bound of 0. During iteration or any motion the position will not move outside the specified range. Invalidates position. More...
 
void setROI (const std::vector< std::pair< int64_t, int64_t >> &roi)
 Sets the region of interest. During iteration or any motion the position will not move outside the specified range. Extra elements in roi beyond the number of dimensions, are ignored. More...
 
void setChunkSize (size_t len, const int64_t *sizes, bool defunity=false)
 Set the sizes of chunks for each dimension. Chunks will end every N steps in each of the provided dimension, with the caveout that 0 indicates no breaks in the given dimension. So size = {0, 2, 2} will cause chunks to after $\{N_x-1, 1, 1\}$. $\{0,0,0\}$ (the default) indicate * that the entire image will be iterated and only one chunk will be used. Defunity will cause the default to be 1 for non-specified dimensions. More...
 
void setChunkSize (size_t len, const size_t *sizes, bool defunity=false)
 Set the sizes of chunks for each dimension. Chunks will end every N steps in each of the provided dimension, with the caveout that 0 indicates no breaks in the given dimension. So size = {0, 2, 2} will cause chunks to after $\{N_x-1, 1, 1\}$. $\{0,0,0\}$ (the default) indicate * that the entire image will be iterated and only one chunk will be used. Defunity will cause the default to be 1 for non-specified dimensions. More...
 
void setLineChunk (size_t dir)
 Sets the chunk sizes so that each chunk is a line in the given dimension. This would be analogous to itk's linear iterator. Usage: More...
 
void setOrder (const std::vector< size_t > &order, bool revorder=false)
 Sets the order of iteration from ++/– operators. More...
 
void setOrder (std::initializer_list< size_t > order, bool revorder=false)
 Sets the order of iteration from ++/– operators. More...
 
const std::vector< size_t > & getOrder () const
 Returns the array giving the order of dimension being traversed. So 3,2,1,0 would mean that the next point in dimension 3 will be next, when wrapping the next point in 2 is visited, when that wraps the next in one and so on. More...
 

Protected Attributes

size_t m_linfirst
 
size_t m_chunkfirst
 
bool m_end
 
bool m_chunkend
 
size_t m_linpos
 
std::vector< int64_t > m_pos
 
std::vector< std::pair< int64_t, int64_t > > m_chunk
 
std::vector< size_t > m_order
 
std::vector< std::pair< int64_t, int64_t > > m_roi
 
std::vector< int64_t > m_chunksizes
 
size_t m_ndim
 
std::vector< size_t > m_dim
 
std::vector< size_t > m_strides
 

Detailed Description

This class is used to step through an ND array in order of dimensions, but unlike Slicer it breaks the NDArray into chunks. Iteration stops at the end of each chunk until nextChunk is called. By default only one chunk is used, equal to the entire image. Use setBreaks() to set the frequency of chunks. The input to setBreaks() is an array of integers, where the next chunk occurs when distbreak == 0, with the special property that break=0 indicates no breaks for the dimension. So for a 3D image, setBreaks({1,0,0}) will stop every time a new x-values is reached. Note that the affects the order of iteration, so x cannot be the fastest iterator. setChunkSize() is an alias for setBreaks. Note that in cases where breaksize != 0, for example image size = 5 and break = 3, chunk sizes will differ during the course of iteration!

Order may still be set to decide the order of iteration. The first member of setOrder will be the fastest moving, and the last will be the slowest. Any dimensions not included in the order vector will be slower than the last member of order. Note that order will not necessarily be strictly obeyed when more than one chunk size is > 0. For isntance if setBreaks({1,1,0}), setOrder({0,1,2}) are used, then all of 2 will visited before we iterate in 0 or 1, because otherwise we would be stepping across chunks.

Definition at line 378 of file slicer.h.

Constructor & Destructor Documentation

npl::ChunkSlicer::ChunkSlicer ( )

Default Constructor, max a length 1, dimension 1 slicer.

npl::ChunkSlicer::ChunkSlicer ( size_t  ndim,
const size_t *  dim 
)

Constructor, takses the number of dimensions and the size of the image.

Parameters
ndimsize of ND array
dimarray providing the size in each dimension

Member Function Documentation

bool npl::ChunkSlicer::eoc ( ) const
inline

Returns true when we have reached the end of the chunk.

Returns
Are we ready for the next chunk?

Definition at line 460 of file slicer.h.

bool npl::ChunkSlicer::eof ( ) const
inline

Are we at the end of iteration? Note that this will be 1 past the end, as typically is done in c++.

Returns
true if we are at the end

Definition at line 439 of file slicer.h.

const std::vector<size_t>& npl::ChunkSlicer::getOrder ( ) const
inline

Returns the array giving the order of dimension being traversed. So 3,2,1,0 would mean that the next point in dimension 3 will be next, when wrapping the next point in 2 is visited, when that wraps the next in one and so on.

Returns
Order of dimensions

Definition at line 784 of file slicer.h.

int64_t npl::ChunkSlicer::getStride ( size_t  dd)
inline

get stride in specified dimension

Returns
returns stride (change in linear index given a position)

Definition at line 655 of file slicer.h.

void npl::ChunkSlicer::goBegin ( )

Go to the very beginning for the first chunk.

void npl::ChunkSlicer::goChunkBegin ( )

Go to the beginning for the current chunk.

void npl::ChunkSlicer::goChunkEnd ( )

Jump to the end of current chunk.

void npl::ChunkSlicer::goEnd ( )

Jump to the end of the last chunk.

void npl::ChunkSlicer::goIndex ( size_t  len,
int64_t *  newpos 
)

Jump to the given position, additional values in newpos beyond dim will be ignored. Any values missing due to ndim > len will be treated as zeros.

Parameters
lenlength of newpos array
newposPosition to move to
void npl::ChunkSlicer::goIndex ( std::vector< int64_t >  newpos)

Jump to the given position.

Parameters
newposlocation to move to
void npl::ChunkSlicer::index ( size_t  len,
int64_t *  index 
) const

Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ.

Parameters
lensize of index array
indexoutput index variable
void npl::ChunkSlicer::index ( size_t  len,
int *  index 
) const

Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ.

Parameters
lensize of index
indexoutput index variable
void npl::ChunkSlicer::index ( size_t  len,
double *  index 
) const

Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ.

Parameters
lensize of index
indexoutput index variable
void npl::ChunkSlicer::index ( std::vector< int64_t > &  ind) const
inline

Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ.

Parameters
indoutput index variable

Definition at line 596 of file slicer.h.

void npl::ChunkSlicer::index ( std::vector< int > &  ind) const
inline

Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ.

Parameters
indoutput index variable

Definition at line 610 of file slicer.h.

void npl::ChunkSlicer::index ( std::vector< double > &  ind) const
inline

Places the first len dimension in the given array. If the number of dimensions exceed the len then the additional dimensions will be ignored, if len exceeds the dimensionality then index[dim...len-1] = 0. In other words index will be completely overwritten in the most sane way possible if the internal dimensions and size index differ.

Parameters
indoutput index variable

Definition at line 624 of file slicer.h.

int64_t npl::ChunkSlicer::index ( size_t  dd) const
inline

Returns the index in the specified dimension.

Parameters
ddDimension of image to sample index of

Definition at line 634 of file slicer.h.

bool npl::ChunkSlicer::isBegin ( ) const
inline

Are we at the begining of iteration?

Returns
true if we are at the begining

Definition at line 423 of file slicer.h.

bool npl::ChunkSlicer::isChunkBegin ( ) const
inline

Returns true when we have reached the end of the chunk.

Returns
Are we ready for the next chunk?

Definition at line 446 of file slicer.h.

bool npl::ChunkSlicer::isChunkEnd ( ) const
inline

Returns true when we have reached the end of the chunk.

Returns
Are we ready for the next chunk?

Definition at line 453 of file slicer.h.

bool npl::ChunkSlicer::isEnd ( ) const
inline

Are we at the end of iteration? Note that this will be 1 past the end, as typically is done in c++.

Returns
true if we are at the end

Definition at line 431 of file slicer.h.

size_t npl::ChunkSlicer::linIndex ( ) const
inline

get linear position of current point

Returns
returns linear index

Definition at line 645 of file slicer.h.

ChunkSlicer& npl::ChunkSlicer::nextChunk ( )

Proceed to the next chunk (if there is one).

Returns
int64_t npl::ChunkSlicer::operator* ( ) const
inline

dereference operator. Returns the linear position in the array given the n-dimensional position.

Returns

Definition at line 549 of file slicer.h.

ChunkSlicer& npl::ChunkSlicer::operator++ ( )

Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder.

Returns
new value of linear position
ChunkSlicer& npl::ChunkSlicer::operator-- ( )

Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder.

Returns
new value of linear position
ChunkSlicer& npl::ChunkSlicer::prevChunk ( )

Return to the previous chunk (if there is one).

Returns
new value of linear position
void npl::ChunkSlicer::setChunkSize ( size_t  len,
const int64_t *  sizes,
bool  defunity = false 
)

Set the sizes of chunks for each dimension. Chunks will end every N steps in each of the provided dimension, with the caveout that 0 indicates no breaks in the given dimension. So size = {0, 2, 2} will cause chunks to after $\{N_x-1, 1, 1\}$. $\{0,0,0\}$ (the default) indicate * that the entire image will be iterated and only one chunk will be used. Defunity will cause the default to be 1 for non-specified dimensions.

Parameters
lenLength of sizes array
sizesSize of chunk in each dimension. If you multiply together the elements of sizes that is the MAXIMUM number of iterations between chunks. Note however that there could be less if we are at the edge.
defunitySets the default to unity rather than 0. Thus unreferenced dimensions will be broken up at each step; so {0,1} for a 4D image will be effectively {0,1,1,1} instead of {0,1,0,0}. This is convenient, for instance, if you want to split up based on volumes, {0,0,0} would stop at the end of each volume, whereas the default would be to treat the entire ND-image as a chunk.
void npl::ChunkSlicer::setChunkSize ( size_t  len,
const size_t *  sizes,
bool  defunity = false 
)

Set the sizes of chunks for each dimension. Chunks will end every N steps in each of the provided dimension, with the caveout that 0 indicates no breaks in the given dimension. So size = {0, 2, 2} will cause chunks to after $\{N_x-1, 1, 1\}$. $\{0,0,0\}$ (the default) indicate * that the entire image will be iterated and only one chunk will be used. Defunity will cause the default to be 1 for non-specified dimensions.

Parameters
lenLength of sizes array
sizesSize of chunk in each dimension. If you multiply together the elements of sizes that is the MAXIMUM number of iterations between chunks. Note however that there could be less if we are at the edge.
defunitySets the default to unity rather than 0. Thus unreferenced dimensions will be broken up at each step; so {0,1} for a 4D image will be effectively {0,1,1,1} instead of {0,1,0,0}. This is convenient, for instance, if you want to split up based on volumes, {0,0,0} would stop at the end of each volume, whereas the default would be to treat the entire ND-image as a chunk.
void npl::ChunkSlicer::setDim ( size_t  ndim,
const size_t *  dim 
)

Sets the dimensionality of iteration, and the dimensions of the image.

Invalidates position and ROI.

Parameters
ndimNumber of dimension
dimDimensions (size)
void npl::ChunkSlicer::setLineChunk ( size_t  dir)

Sets the chunk sizes so that each chunk is a line in the given dimension. This would be analogous to itk's linear iterator. Usage:

it.setLineChunk(0); while(!it.isEnd()) { while(!it.isChunkEnd()) {

++it; } it.nextChunk(); }

Parameters
dirDimension to travel linearly along
void npl::ChunkSlicer::setOrder ( const std::vector< size_t > &  order,
bool  revorder = false 
)

Sets the order of iteration from ++/– operators.

Parameters
ordervector of priorities, with first element being the fastest iteration and last the slowest. All other dimensions not used will be slower than the last
revorderReverse order, in which case the first element of order will have the slowest iteration, and dimensions not specified in order will be faster than those included.
void npl::ChunkSlicer::setOrder ( std::initializer_list< size_t >  order,
bool  revorder = false 
)

Sets the order of iteration from ++/– operators.

Parameters
ordervector of priorities, with first element being the fastest iteration and last the slowest. All other dimensions not used will be slower than the last
revorderReverse order, in which case the first element of order will have the slowest iteration, and dimensions not specified in order will be faster than those included.
void npl::ChunkSlicer::setROI ( size_t  len,
const size_t *  roisize,
const int64_t *  roistart = NULL 
)

Sets the region of interest, with lower bound of 0. During iteration or any motion the position will not move outside the specified range. Invalidates position.

Invalidates position

Parameters
lenlength of roi array
roistartlower bound of ROI
roisizeSize of ROI (which runs in the block from: [0 to roisize[0]-1,0. to roisize[1]-1, etc]
void npl::ChunkSlicer::setROI ( const std::vector< std::pair< int64_t, int64_t >> &  roi)

Sets the region of interest. During iteration or any motion the position will not move outside the specified range. Extra elements in roi beyond the number of dimensions, are ignored.

Parameters
roipair of [min,max] values in the desired hypercube

Member Data Documentation

std::vector<std::pair<int64_t,int64_t> > npl::ChunkSlicer::m_chunk
protected

Definition at line 803 of file slicer.h.

bool npl::ChunkSlicer::m_chunkend
protected

Definition at line 798 of file slicer.h.

size_t npl::ChunkSlicer::m_chunkfirst
protected

Definition at line 796 of file slicer.h.

std::vector<int64_t> npl::ChunkSlicer::m_chunksizes
protected

Definition at line 808 of file slicer.h.

std::vector<size_t> npl::ChunkSlicer::m_dim
protected

Definition at line 811 of file slicer.h.

bool npl::ChunkSlicer::m_end
protected

Definition at line 797 of file slicer.h.

size_t npl::ChunkSlicer::m_linfirst
protected

Definition at line 784 of file slicer.h.

size_t npl::ChunkSlicer::m_linpos
protected

Definition at line 801 of file slicer.h.

size_t npl::ChunkSlicer::m_ndim
protected

Definition at line 810 of file slicer.h.

std::vector<size_t> npl::ChunkSlicer::m_order
protected

Definition at line 806 of file slicer.h.

std::vector<int64_t> npl::ChunkSlicer::m_pos
protected

Definition at line 802 of file slicer.h.

std::vector<std::pair<int64_t,int64_t> > npl::ChunkSlicer::m_roi
protected

Definition at line 807 of file slicer.h.

std::vector<size_t> npl::ChunkSlicer::m_strides
protected

Definition at line 812 of file slicer.h.


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