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

Iterator for an image, that allows for easy access to the neighbors of the current element/pixel. Neighbors can be accessed through offset(i) which simply provides the value of the i'th neighbor. To get that neighbors index you can use it.offset_index(i). For the center use it.center()/it.center_index(). [] may also be used in place of offset. To get the number of neighbors in the kernel use ksize(), so it.offset(0), it.offset(1), ..., it.offset(ksize()-1) are valid calls. More...

#include <iterators.h>

Inherits npl::KSlicer.

Public Member Functions

 KernelIter ()
 Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Image. More...
 
 KernelIter (std::shared_ptr< const NDArray > in)
 
void setArray (ptr< const NDArray > in)
 
KernelIteroperator++ ()
 Prefix increment operator. More...
 
KernelIteroperator-- ()
 Prefix decrement operator. More...
 
operator* () const
 Dereference operator, get center pixel value. More...
 
getC () const
 Same as dereference operator, get center pixel value. More...
 
getK (int64_t k) const
 Dereference (get) the pixel at the k'th offset position. To figure out WHERE this pixel is in relation to the center use offsetK. More...
 
operator[] (int64_t k) const
 Dereference (get) the pixel at the k'th offset position. To figure out WHERE this pixel is in relation to the center use offsetK. More...
 
bool operator== (const KernelIter &other) const
 Whether the position and parent are the same as another. More...
 
bool operator!= (const KernelIter &other) const
 Whether the position and parent are different from another. More...
 
bool operator< (const KernelIter &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 KernelIter &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 KernelIter &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 KernelIter &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...
 
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. 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 setOrder (const std::vector< size_t > order={}, bool revorder=false)
 Set the order of iteration, in terms of which dimensions iterate the fastest and which the slowest. 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...
 
void setRadius (std::vector< size_t > kradius={})
 Set the radius of the kernel window. All directions will have equal distance, with the radius in each dimension set by the magntitude of the kradius vector. So if kradius = {2,1,0} then dimension 0 (x) will have a radius of 2, dimension 1 (y) will have a readius of 1 and dimension 2 will have a radius of 0 (won't step out from the middle at all). More...
 
void setRadius (size_t kradius)
 Set the radius of the kernel window. All directions will have equal distance in all dimensions. So if kradius = 2 then dimension 0 (x) will have a radius of 2, dimension 2 (y) will have a readius of 2 and so on. Warning images may have more dimensions than you know, so if the image has a dimension that is only size 1 it will have a radius of 0, but if you didn't know you had a 10D image all the dimensions about to support the radius will. More...
 
void setWindow (const std::vector< std::pair< int64_t, int64_t >> &krange)
 Set the ROI from the center of the kernel. The first value should be <= 0, the second should be >= 0. The ranges are inclusive. So if kradius = {{-1,1},{0,1},{-1,0}}, in the x dimension values will range from center - 1 to center + 1, y indices will range from center to center + 1, and z indices will range from center-1 to center. Kernel will range from [kRange[0].first, kRange[0].second] [kRange[1].first, kRange[1].second] ... 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...
 
int64_t linIndex () const
 get linear position of current point More...
 
int64_t getStride (size_t dd)
 get stride in specified dimension More...
 
void goBegin ()
 Go to the beginning. More...
 
void goEnd ()
 Jump to the end of iteration. More...
 
void goIndex (const std::vector< int64_t > &newpos)
 Jump to the given position. More...
 
void indexC (size_t len, int64_t *index) const
 Places the first len dimensions of ND-position 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 indexK (size_t kit, size_t len, int64_t *index, bool bound=true) const
 Get the ND position of the specified offset (kernel) element. More...
 
int64_t offsetK (size_t kit, size_t dim)
 Returns the distance from the center projected onto the specified dimension. So center is {0,0,0}, and {1,2,1} would return 1,2,1 for inputs dim=0, dim=1, dim=2. Note that this is the ideal offset (so it doesn't respect image bounds). More...
 
void offsetK (size_t kit, size_t len, int64_t *dindex) const
 Returns offset from center of specified pixel (kit). Note that this is the ideal offset (so it doesn't respect image bounds). More...
 
bool insideK (size_t k)
 Returns whether the k'th kernel member is inside the region of interest. More...
 
size_t ksize () const
 Get linear position. More...
 
void setDim (size_t ndim, const size_t *dim)
 All around intializer. Sets all internal variables. More...
 

Protected Attributes

size_t m_ndim
 
std::vector< size_t > m_size
 
std::vector< size_t > m_strides
 
std::vector< size_t > m_order
 
size_t m_numoffs
 
std::vector< int64_t * > m_offs
 
std::vector< int64_t > m_offs_raw
 
size_t m_center
 
int64_t m_fradius
 
int64_t m_rradius
 
std::vector< std::pair< int64_t, int64_t > > m_roi
 
size_t m_begin
 
bool m_end
 
std::vector< int64_t * > m_pos
 
std::vector< int64_t > m_pos_raw
 
std::vector< int64_t > m_linpos
 

Detailed Description

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

Iterator for an image, that allows for easy access to the neighbors of the current element/pixel. Neighbors can be accessed through offset(i) which simply provides the value of the i'th neighbor. To get that neighbors index you can use it.offset_index(i). For the center use it.center()/it.center_index(). [] may also be used in place of offset. To get the number of neighbors in the kernel use ksize(), so it.offset(0), it.offset(1), ..., it.offset(ksize()-1) are valid calls.

The primary functions are operator[] which allows you to get the k'th offset value, indexK() which returns the index of the k'th offset, and offsetK() which returns the offset of k'th offset, IE where it is in relation to the center.

Note that order is the not the default order. If you use using this iterator with another iterator, be sure to setOrder(it.getOrder()) so that both iterators have the same directions.

There are no 'set' functions so this is const iterator.

Template Parameters
T

Definition at line 1871 of file iterators.h.

Constructor & Destructor Documentation

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

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

Definition at line 1879 of file iterators.h.

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

Definition at line 1881 of file iterators.h.

Member Function Documentation

bool npl::KSlicer::eof ( ) const
inlineinherited

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

template<typename T = double>
T npl::KernelIter< T >::getC ( ) const
inline

Same as dereference operator, get center pixel value.

Returns
current value

Definition at line 1987 of file iterators.h.

template<typename T = double>
T npl::KernelIter< T >::getK ( int64_t  k) const
inline

Dereference (get) the pixel at the k'th offset position. To figure out WHERE this pixel is in relation to the center use offsetK.

Returns
current value at offset k

Definition at line 2001 of file iterators.h.

const std::vector<size_t>& npl::KSlicer::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 909 of file slicer.h.

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

get stride in specified dimension

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

Definition at line 998 of file slicer.h.

void npl::KSlicer::goBegin ( )
inherited

Go to the beginning.

void npl::KSlicer::goEnd ( )
inherited

Jump to the end of iteration.

void npl::KSlicer::goIndex ( const std::vector< int64_t > &  newpos)
inherited

Jump to the given position.

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

Places the first len dimensions of ND-position 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::KSlicer::indexK ( size_t  kit,
size_t  len,
int64_t *  index,
bool  bound = true 
) const
inherited

Get the ND position of the specified offset (kernel) element.

Parameters
kitKernel index
lensize of index
indexoutput index variable
boundreport the actual sampled point (ie point after clamping position to be in the image. Interior points will be the same, but on the boundary if you set bound you will only get indices inside the image ROI, otherwise you would get values like -1, -1 -1 for radius 1 pos 0,0,0
Returns
ND position
bool npl::KSlicer::insideK ( size_t  k)
inherited

Returns whether the k'th kernel member is inside the region of interest.

Parameters
kWhich pixel to return distance from
Returns
True if k'th kernel element is inside the region, false if a clamped value would be returned
bool npl::KSlicer::isBegin ( ) const
inlineinherited

Are we at the begining of iteration?

Returns
true if we are at the begining

Definition at line 965 of file slicer.h.

bool npl::KSlicer::isEnd ( ) const
inlineinherited

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

size_t npl::KSlicer::ksize ( ) const
inlineinherited

Get linear position.

Returns
linear position

Definition at line 1174 of file slicer.h.

int64_t npl::KSlicer::linIndex ( ) const
inlineinherited

get linear position of current point

Returns
returns linear index

Definition at line 988 of file slicer.h.

int64_t npl::KSlicer::offsetK ( size_t  kit,
size_t  dim 
)
inherited

Returns the distance from the center projected onto the specified dimension. So center is {0,0,0}, and {1,2,1} would return 1,2,1 for inputs dim=0, dim=1, dim=2. Note that this is the ideal offset (so it doesn't respect image bounds).

Parameters
kitWhich pixel to return distance from
dimdimension to get distance in
Returns
Offset from center of given pixel (kit)
void npl::KSlicer::offsetK ( size_t  kit,
size_t  len,
int64_t *  dindex 
) const
inherited

Returns offset from center of specified pixel (kit). Note that this is the ideal offset (so it doesn't respect image bounds).

Parameters
kitPixel we are referring to
lenlenght of dindex array
dindexoutput paramter indicating distance of pixel from the center of the kernel in each dimension. If this array is shorter than the iteration dimensions, only the first len will be filled. If it is longer the additional values won't be touched
template<typename T = double>
bool npl::KernelIter< T >::operator!= ( const KernelIter< T > &  other) const
inline

Whether the position and parent are different from another.

Parameters
other
Returns

Definition at line 2042 of file iterators.h.

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

Dereference operator, get center pixel value.

Returns
current value

Definition at line 1974 of file iterators.h.

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

Prefix increment operator.

Returns
new value

Definition at line 1952 of file iterators.h.

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

Prefix decrement operator.

Returns
new value

Definition at line 1963 of file iterators.h.

template<typename T = double>
bool npl::KernelIter< T >::operator< ( const KernelIter< 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 2055 of file iterators.h.

template<typename T = double>
bool npl::KernelIter< T >::operator<= ( const KernelIter< 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 2097 of file iterators.h.

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

Whether the position and parent are the same as another.

Parameters
other
Returns

Definition at line 2030 of file iterators.h.

template<typename T = double>
bool npl::KernelIter< T >::operator> ( const KernelIter< 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 2076 of file iterators.h.

template<typename T = double>
bool npl::KernelIter< T >::operator>= ( const KernelIter< 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 2116 of file iterators.h.

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

Dereference (get) the pixel at the k'th offset position. To figure out WHERE this pixel is in relation to the center use offsetK.

Returns
current value at offset k

Definition at line 2015 of file iterators.h.

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

Definition at line 1886 of file iterators.h.

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

All around intializer. Sets all internal variables.

Parameters
ndimRank (number of dimensions), also length of dim array
dimDimension (size) of memory block.
void npl::KSlicer::setOrder ( const std::vector< size_t >  order = {},
bool  revorder = false 
)
inherited

Set the order of iteration, in terms of which dimensions iterate the fastest and which the slowest.

Parameters
orderorder of iteration. {0,1,2} would mean that dimension 0 (x) would move the fastest and 2 the slowest. If the image is a 5D image then that unmentioned (3,4) would be the slowest.
revorderReverse the speed of iteration. So the first dimension in the order vector would in fact be the slowest and un-referenced dimensions will be the fastest. (in the example for order this would be 4 and 3).
void npl::KSlicer::setRadius ( std::vector< size_t >  kradius = {})
inherited

Set the radius of the kernel window. All directions will have equal distance, with the radius in each dimension set by the magntitude of the kradius vector. So if kradius = {2,1,0} then dimension 0 (x) will have a radius of 2, dimension 1 (y) will have a readius of 1 and dimension 2 will have a radius of 0 (won't step out from the middle at all).

Parameters
kradiusvector of radii in the given dimension. Unset values assumed to be 0. So a 10 dimensional image with 3 values will have non-zero values for x,y,z but 0 values in higher dimensions
void npl::KSlicer::setRadius ( size_t  kradius)
inherited

Set the radius of the kernel window. All directions will have equal distance in all dimensions. So if kradius = 2 then dimension 0 (x) will have a radius of 2, dimension 2 (y) will have a readius of 2 and so on. Warning images may have more dimensions than you know, so if the image has a dimension that is only size 1 it will have a radius of 0, but if you didn't know you had a 10D image all the dimensions about to support the radius will.

Parameters
kradiusRadius in all directions.
void npl::KSlicer::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.

Parameters
roipair of [min,max] values in the desired hypercube
void npl::KSlicer::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
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::KSlicer::setWindow ( const std::vector< std::pair< int64_t, int64_t >> &  krange)
inherited

Set the ROI from the center of the kernel. The first value should be <= 0, the second should be >= 0. The ranges are inclusive. So if kradius = {{-1,1},{0,1},{-1,0}}, in the x dimension values will range from center - 1 to center + 1, y indices will range from center to center + 1, and z indices will range from center-1 to center. Kernel will range from [kRange[0].first, kRange[0].second] [kRange[1].first, kRange[1].second] ...

Parameters
krangeVector of [inf, sup] in each dimension. Unaddressed (missing) values are assumed to be [0,0].

Member Data Documentation

size_t npl::KSlicer::m_begin
protectedinherited

Definition at line 1210 of file slicer.h.

size_t npl::KSlicer::m_center
protectedinherited

Definition at line 1204 of file slicer.h.

bool npl::KSlicer::m_end
protectedinherited

Definition at line 1213 of file slicer.h.

int64_t npl::KSlicer::m_fradius
protectedinherited

Definition at line 1205 of file slicer.h.

std::vector<int64_t> npl::KSlicer::m_linpos
protectedinherited

Definition at line 1216 of file slicer.h.

size_t npl::KSlicer::m_ndim
protectedinherited

Definition at line 1190 of file slicer.h.

size_t npl::KSlicer::m_numoffs
protectedinherited

Definition at line 1199 of file slicer.h.

std::vector<int64_t*> npl::KSlicer::m_offs
protectedinherited

Definition at line 1202 of file slicer.h.

std::vector<int64_t> npl::KSlicer::m_offs_raw
protectedinherited

Definition at line 1203 of file slicer.h.

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

Definition at line 1195 of file slicer.h.

std::vector<int64_t*> npl::KSlicer::m_pos
protectedinherited

Definition at line 1214 of file slicer.h.

std::vector<int64_t> npl::KSlicer::m_pos_raw
protectedinherited

Definition at line 1215 of file slicer.h.

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

Definition at line 1209 of file slicer.h.

int64_t npl::KSlicer::m_rradius
protectedinherited

Definition at line 1206 of file slicer.h.

std::vector<size_t> npl::KSlicer::m_size
protectedinherited

Definition at line 1191 of file slicer.h.

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

Definition at line 1192 of file slicer.h.


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