NPL
Neurological Programs and Libraries
npl::KSlicer Class Reference

This class is used to slice an image in along a dimension, and to step an arbitrary direction in an image. Order may be any size from 0 to the number of dimensions. The first member of order will be the fastest moving, and the last will be the slowest. Any not dimensions not included in the order vector will be slower than the last member of order. More...

#include <slicer.h>

Inherited by npl::KernelIter< T >.

Public Member Functions

 KSlicer ()
 Default Constructor, size 1, dimension 1 slicer, krange = 0. More...
 
 KSlicer (size_t ndim, const size_t *dim)
 Constructs a iterator with the given dimensions. 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...
 
KSliceroperator++ ()
 Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder. More...
 
KSliceroperator-- ()
 Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder. 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...
 
int64_t getC () const
 Get image linear index of center. More...
 
int64_t operator* () const
 Get image linear index of center. Identitcal to center() just more confusing. 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...
 
int64_t getK (int64_t kit) const
 Get index of i'th kernel (center-offset) element. Note that values outside the image will not be returned, the nearest inside position will be. More...
 
int64_t operator[] (int64_t kit) const
 Same as offset(int64_t kit). Note that values outside the image will not be returned, the nearest inside position will be. 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...
 
bool insideK (size_t k)
 Returns whether the k'th kernel member is inside the region of interest. 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...
 
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

This class is used to slice an image in along a dimension, and to step an arbitrary direction in an image. Order may be any size from 0 to the number of dimensions. The first member of order will be the fastest moving, and the last will be the slowest. Any not dimensions not included in the order vector will be slower than the last member of order.

TODO: Change API to be more intuitive.

Key variables are

dim Dimension (size) of memory block. krange Range of offset values. Each pair indicats a min and max in the i'th dimension. So {{-3,0}, {-3,3},{0,3}} would indicate a kernel from (X-3,Y-3,Z+0) to (X+0,Y+3,Z+3). Ranges must include zero. roi Range of region of interest. Pairs indicates the range in i'th dimension, so krange = {{1,5},{0,9},{32,100}} would cause the iterator to range from (1,0,32) to (5,9,100)

Definition at line 836 of file slicer.h.

Constructor & Destructor Documentation

npl::KSlicer::KSlicer ( )

Default Constructor, size 1, dimension 1 slicer, krange = 0.

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

Constructs a iterator with the given dimensions.

Parameters
ndimNumber of dimensions
dimsize of ND array

Member Function Documentation

bool npl::KSlicer::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 981 of file slicer.h.

int64_t npl::KSlicer::getC ( ) const
inline

Get image linear index of center.

Returns
Linear index

Definition at line 1054 of file slicer.h.

int64_t npl::KSlicer::getK ( int64_t  kit) const
inline

Get index of i'th kernel (center-offset) element. Note that values outside the image will not be returned, the nearest inside position will be.

Returns
linear position

Definition at line 1093 of file slicer.h.

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

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

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 ( )

Go to the beginning.

void npl::KSlicer::goEnd ( )

Jump to the end of iteration.

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

Jump to the given position.

Parameters
newposlocation to move to
void npl::KSlicer::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.

Parameters
lensize of index
indexoutput index variable
void npl::KSlicer::indexK ( size_t  kit,
size_t  len,
int64_t *  index,
bool  bound = true 
) const

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)

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
inline

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

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

Get linear position.

Returns
linear position

Definition at line 1174 of file slicer.h.

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

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 
)

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

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
int64_t npl::KSlicer::operator* ( ) const
inline

Get image linear index of center. Identitcal to center() just more confusing.

Returns
Linear index

Definition at line 1066 of file slicer.h.

KSlicer& npl::KSlicer::operator++ ( )

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

Returns
new value of linear position
KSlicer& npl::KSlicer::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
int64_t npl::KSlicer::operator[] ( int64_t  kit) const
inline

Same as offset(int64_t kit). Note that values outside the image will not be returned, the nearest inside position will be.

Returns
linear position

Definition at line 1108 of file slicer.h.

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

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 
)

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 = {})

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)

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 = {})

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 
)

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)

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
protected

Definition at line 1210 of file slicer.h.

size_t npl::KSlicer::m_center
protected

Definition at line 1204 of file slicer.h.

bool npl::KSlicer::m_end
protected

Definition at line 1213 of file slicer.h.

int64_t npl::KSlicer::m_fradius
protected

Definition at line 1205 of file slicer.h.

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

Definition at line 1216 of file slicer.h.

size_t npl::KSlicer::m_ndim
protected

Definition at line 1190 of file slicer.h.

size_t npl::KSlicer::m_numoffs
protected

Definition at line 1199 of file slicer.h.

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

Definition at line 1202 of file slicer.h.

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

Definition at line 1203 of file slicer.h.

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

Definition at line 1195 of file slicer.h.

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

Definition at line 1214 of file slicer.h.

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

Definition at line 1215 of file slicer.h.

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

Definition at line 1209 of file slicer.h.

int64_t npl::KSlicer::m_rradius
protected

Definition at line 1206 of file slicer.h.

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

Definition at line 1191 of file slicer.h.

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

Definition at line 1192 of file slicer.h.


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