NPL
Neurological Programs and Libraries
|
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... | |
KSlicer & | operator++ () |
Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder. More... | |
KSlicer & | operator-- () |
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 |
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)
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.
ndim | Number of dimensions |
dim | size of ND array |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
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.
newpos | location 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.
len | size of index |
index | output 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.
kit | Kernel index |
len | size of index |
index | output index variable |
bound | report 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 |
bool npl::KSlicer::insideK | ( | size_t | k | ) |
Returns whether the k'th kernel member is inside the region of interest.
k | Which pixel to return distance from |
|
inline |
|
inline |
|
inline |
|
inline |
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).
kit | Which pixel to return distance from |
dim | dimension to get distance in |
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).
kit | Pixel we are referring to |
len | lenght of dindex array |
dindex | output 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 |
|
inline |
KSlicer& npl::KSlicer::operator++ | ( | ) |
Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder.
KSlicer& npl::KSlicer::operator-- | ( | ) |
Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during construction or by setOrder.
|
inline |
void npl::KSlicer::setDim | ( | size_t | ndim, |
const size_t * | dim | ||
) |
All around intializer. Sets all internal variables.
ndim | Rank (number of dimensions), also length of dim array |
dim | Dimension (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.
order | order 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. |
revorder | Reverse 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).
kradius | vector 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.
kradius | Radius 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.
roi | pair 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
len | length of roi array |
roistart | lower bound of ROI |
roisize | Size 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] ...
krange | Vector of [inf, sup] in each dimension. Unaddressed (missing) values are assumed to be [0,0]. |
|
protected |