NPL
Neurological Programs and Libraries
npl::Vector3DIter< T > Class Template Reference

This class is used to iterate through an 3D array, where each point then has has multiple higher dimensional variable. This is analogous to Vector3DView, where even if there are multiple higher dimensions they are all alligned into a single vector at each 3D point. This makes them easier to than simple iteration in N-dimensions. More...

#include <iterators.h>

Inherits npl::Slicer.

Public Member Functions

 Vector3DIter ()
 Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Image. More...
 
 Vector3DIter (std::shared_ptr< NDArray > in)
 
void setArray (ptr< NDArray > in)
 
Vector3DIteroperator++ ()
 Prefix increment operator. More...
 
Vector3DIteroperator-- ()
 Prefix decrement operator. More...
 
operator* () const
 Dereference operator. More...
 
get (int64_t i=0) const
 Get value at ith element of vector. More...
 
operator[] (int64_t i) const
 Get value at ith element of vector. More...
 
void set (int64_t i, T v)
 Set the value at the ith element of thevector. More...
 
void set (T v)
 Set the value at the 0th element of the vector. More...
 
void goBegin ()
 Go to beginning of iteration. More...
 
void goEnd ()
 Go to end of iteration. More...
 
bool isEnd () const
 Are we one past the last element? More...
 
bool eof () const
 Are we one past the last element? More...
 
bool isBegin () const
 Are we at the first element. More...
 
bool operator== (const Vector3DIter &other) const
 Whether the position and parent are the same as another. More...
 
bool operator!= (const Vector3DIter &other) const
 Whether the position and parent are different from another. More...
 
bool operator< (const Vector3DIter &other) const
 If the parents are different then false, if they are the same, returns whether this iterator is before the other. More...
 
bool operator> (const Vector3DIter &other) const
 If the parents are different then false, if they are the same, returns whether this iterator is after the other. More...
 
bool operator<= (const Vector3DIter &other) const
 If the parents are different then false, if they are the same, returns whether this iterator is the same or before the other. More...
 
bool operator>= (const Vector3DIter &other) const
 If the parents are different then false, if they are the same, returns whether this iterator is the same or after the other. More...
 
size_t tlen () const
 
void setDim (size_t ndim, const size_t *dim)
 Updates dimensions of target nd array. 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...
 
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 setOrder (const std::vector< size_t > &order, bool revorder=false)
 Sets the order of iteration from increment operators. More...
 
void setOrder (std::initializer_list< size_t > order, bool revorder=false)
 Sets the order of iteration from ++/– operators. More...
 
void setOrder ()
 Sets the order of iteration from ++/– operators. Order will be the default (highest to lowest) 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_linpos
 
size_t m_linfirst
 
std::vector< int64_t > m_pos
 
bool m_end
 
size_t m_ndim
 
std::vector< size_t > m_order
 
std::vector< std::pair< int64_t, int64_t > > m_roi
 
std::vector< size_t > m_dim
 
std::vector< size_t > m_strides
 

Detailed Description

template<typename T = double>
class npl::Vector3DIter< T >

This class is used to iterate through an 3D array, where each point then has has multiple higher dimensional variable. This is analogous to Vector3DView, where even if there are multiple higher dimensions they are all alligned into a single vector at each 3D point. This makes them easier to than simple iteration in N-dimensions.

Template Parameters
T

Definition at line 2149 of file iterators.h.

Constructor & Destructor Documentation

template<typename T = double>
npl::Vector3DIter< T >::Vector3DIter ( )
inline

Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Image.

Definition at line 2157 of file iterators.h.

template<typename T = double>
npl::Vector3DIter< T >::Vector3DIter ( std::shared_ptr< NDArray in)
inline

Definition at line 2159 of file iterators.h.

Member Function Documentation

template<typename T = double>
bool npl::Vector3DIter< T >::eof ( ) const
inline

Are we one past the last element?

Definition at line 2360 of file iterators.h.

template<typename T = double>
T npl::Vector3DIter< T >::get ( int64_t  i = 0) const
inline

Get value at ith element of vector.

Returns
current value

Definition at line 2297 of file iterators.h.

const std::vector<size_t>& npl::Slicer::getOrder ( ) const
inlineinherited

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 334 of file slicer.h.

int64_t npl::Slicer::getStride ( size_t  dd)
inlineinherited

get stride in specified dimension

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

Definition at line 261 of file slicer.h.

template<typename T = double>
void npl::Vector3DIter< T >::goBegin ( )
inline

Go to beginning of iteration.

Definition at line 2345 of file iterators.h.

template<typename T = double>
void npl::Vector3DIter< T >::goEnd ( )
inline

Go to end of iteration.

Definition at line 2350 of file iterators.h.

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

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
newposlocation to move to
void npl::Slicer::goIndex ( std::vector< int64_t >  newpos)
inherited

Jump to the given position.

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

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::Slicer::index ( size_t  len,
int *  index 
) const
inherited

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::Slicer::index ( size_t  len,
double *  index 
) const
inherited

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::Slicer::index ( std::vector< int64_t > &  ind) const
inlineinherited

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 201 of file slicer.h.

void npl::Slicer::index ( std::vector< int > &  ind) const
inlineinherited

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 215 of file slicer.h.

void npl::Slicer::index ( std::vector< double > &  ind) const
inlineinherited

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 230 of file slicer.h.

int64_t npl::Slicer::index ( size_t  dd) const
inlineinherited

Returns the index in the specified dimension.

Parameters
ddDimension of image to sample index of

Definition at line 240 of file slicer.h.

template<typename T = double>
bool npl::Vector3DIter< T >::isBegin ( ) const
inline

Are we at the first element.

Definition at line 2365 of file iterators.h.

template<typename T = double>
bool npl::Vector3DIter< T >::isEnd ( ) const
inline

Are we one past the last element?

Definition at line 2355 of file iterators.h.

size_t npl::Slicer::linIndex ( ) const
inlineinherited

get linear position of current point

Returns
returns linear index

Definition at line 251 of file slicer.h.

template<typename T = double>
bool npl::Vector3DIter< T >::operator!= ( const Vector3DIter< T > &  other) const
inline

Whether the position and parent are different from another.

Parameters
other
Returns

Definition at line 2386 of file iterators.h.

template<typename T = double>
T npl::Vector3DIter< T >::operator* ( ) const
inline

Dereference operator.

Returns
Value in 0th element of vector

Definition at line 2284 of file iterators.h.

template<typename T = double>
Vector3DIter& npl::Vector3DIter< T >::operator++ ( )
inline

Prefix increment operator.

Returns
new value in 0th element of vector

Definition at line 2262 of file iterators.h.

template<typename T = double>
Vector3DIter& npl::Vector3DIter< T >::operator-- ( )
inline

Prefix decrement operator.

Returns
new value in 0th element of vector

Definition at line 2273 of file iterators.h.

template<typename T = double>
bool npl::Vector3DIter< T >::operator< ( const Vector3DIter< T > &  other) const
inline

If the parents are different then false, if they are the same, returns whether this iterator is before the other.

Parameters
other
Returns

Definition at line 2399 of file iterators.h.

template<typename T = double>
bool npl::Vector3DIter< T >::operator<= ( const Vector3DIter< T > &  other) const
inline

If the parents are different then false, if they are the same, returns whether this iterator is the same or before the other.

Parameters
other
Returns

Definition at line 2441 of file iterators.h.

template<typename T = double>
bool npl::Vector3DIter< T >::operator== ( const Vector3DIter< T > &  other) const
inline

Whether the position and parent are the same as another.

Parameters
other
Returns

Definition at line 2374 of file iterators.h.

template<typename T = double>
bool npl::Vector3DIter< T >::operator> ( const Vector3DIter< T > &  other) const
inline

If the parents are different then false, if they are the same, returns whether this iterator is after the other.

Parameters
other
Returns

Definition at line 2420 of file iterators.h.

template<typename T = double>
bool npl::Vector3DIter< T >::operator>= ( const Vector3DIter< T > &  other) const
inline

If the parents are different then false, if they are the same, returns whether this iterator is the same or after the other.

Parameters
other
Returns

Definition at line 2460 of file iterators.h.

template<typename T = double>
T npl::Vector3DIter< T >::operator[] ( int64_t  i) const
inline

Get value at ith element of vector.

Returns
current value

Definition at line 2310 of file iterators.h.

template<typename T = double>
void npl::Vector3DIter< T >::set ( int64_t  i,
v 
)
inline

Set the value at the ith element of thevector.

Definition at line 2322 of file iterators.h.

template<typename T = double>
void npl::Vector3DIter< T >::set ( v)
inline

Set the value at the 0th element of the vector.

Definition at line 2334 of file iterators.h.

template<typename T = double>
void npl::Vector3DIter< T >::setArray ( ptr< NDArray in)
inline

Definition at line 2164 of file iterators.h.

void npl::Slicer::setDim ( size_t  ndim,
const size_t *  dim 
)
inherited

Updates dimensions of target nd array.

Parameters
ndimRank (dimensionality) of data block, length of dim
dimSize of data block, in each dimension, so dim = {32, 2,54 } would have 32*2*54 members
void npl::Slicer::setOrder ( const std::vector< size_t > &  order,
bool  revorder = false 
)
inherited

Sets the order of iteration from increment 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::Slicer::setOrder ( std::initializer_list< size_t >  order,
bool  revorder = false 
)
inherited

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::Slicer::setOrder ( )
inherited

Sets the order of iteration from ++/– operators. Order will be the default (highest to lowest)

void npl::Slicer::setROI ( size_t  len,
const size_t *  roisize,
const int64_t *  roistart = NULL 
)
inherited

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
roisizeSize of ROI (which runs in the block from: [roistart[0] ... roisize[0]-1, roistart[0] ... roisize[1]-1, etc] or, if roistart is Null then [0 ... roisize[0]-1, 0 ... roisize[1]-1, etc]
roistartLower corner of region-of-interest
void npl::Slicer::setROI ( const std::vector< std::pair< int64_t, int64_t >> &  roi)
inherited

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
template<typename T = double>
size_t npl::Vector3DIter< T >::tlen ( ) const
inline

Definition at line 2471 of file iterators.h.

Member Data Documentation

std::vector<size_t> npl::Slicer::m_dim
protectedinherited

Definition at line 352 of file slicer.h.

bool npl::Slicer::m_end
protectedinherited

Definition at line 347 of file slicer.h.

size_t npl::Slicer::m_linfirst
protectedinherited

Definition at line 345 of file slicer.h.

size_t npl::Slicer::m_linpos
protectedinherited

Definition at line 334 of file slicer.h.

size_t npl::Slicer::m_ndim
protectedinherited

Definition at line 349 of file slicer.h.

std::vector<size_t> npl::Slicer::m_order
protectedinherited

Definition at line 350 of file slicer.h.

std::vector<int64_t> npl::Slicer::m_pos
protectedinherited

Definition at line 346 of file slicer.h.

std::vector<std::pair<int64_t,int64_t> > npl::Slicer::m_roi
protectedinherited

Definition at line 351 of file slicer.h.

std::vector<size_t> npl::Slicer::m_strides
protectedinherited

Definition at line 353 of file slicer.h.


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