|
template<class HeaderType > |
List | get (const HeaderType &header) |
| return the strides of header as a vector<ssize_t> More...
|
|
template<class HeaderType > |
void | set (HeaderType &header, const List &stride) |
| set the strides of header from a vector<ssize_t> More...
|
|
template<class HeaderType , class FromHeaderType > |
void | set (HeaderType &header, const FromHeaderType &from) |
| set the strides of header from another HeaderType More...
|
|
template<class HeaderType > |
vector< size_t > | order (const HeaderType &header, size_t from_axis=0, size_t to_axis=std::numeric_limits< size_t >::max()) |
| sort range of axes with respect to their absolute stride. More...
|
|
template<> |
vector< size_t > | order< List > (const List &strides, size_t from_axis, size_t to_axis) |
| sort axes with respect to their absolute stride. More...
|
|
template<class HeaderType > |
void | sanitise (HeaderType &header) |
| remove duplicate and invalid strides. More...
|
|
template<class HeaderType > |
void | sanitise (List &strides, const HeaderType &header) |
| remove duplicate and invalid strides. More...
|
|
List & | sanitise (List ¤t, const List &desired, const vector< ssize_t > &header) |
| remove duplicate and invalid strides. More...
|
|
template<class HeaderType > |
void | actualise (HeaderType &header) |
| convert strides from symbolic to actual strides More...
|
|
template<class HeaderType > |
void | actualise (List &strides, const HeaderType &header) |
| convert strides from symbolic to actual strides More...
|
|
template<class HeaderType > |
List | get_actual (HeaderType &header) |
| get actual strides: More...
|
|
template<class HeaderType > |
List | get_actual (const List &strides, const HeaderType &header) |
| get actual strides: More...
|
|
template<class HeaderType > |
void | symbolise (HeaderType &header) |
| convert strides from actual to symbolic strides More...
|
|
template<> |
void | symbolise (List &strides) |
| convert strides from actual to symbolic strides More...
|
|
template<class HeaderType > |
List | get_symbolic (const HeaderType &header) |
| get symbolic strides: More...
|
|
template<> |
List | get_symbolic (const List &list) |
| get symbolic strides: More...
|
|
template<class HeaderType > |
size_t | offset (const HeaderType &header) |
| calculate offset to start of data More...
|
|
template<class HeaderType > |
size_t | offset (List &strides, const HeaderType &header) |
| calculate offset to start of data More...
|
|
template<class HeaderType > |
List | get_nearest_match (const HeaderType ¤t, const List &desired) |
| produce strides from current that match those specified in desired More...
|
|
List | contiguous_along_axis (size_t axis) |
| convenience function to get volume-contiguous strides More...
|
|
template<class HeaderType > |
List | contiguous_along_axis (size_t axis, const HeaderType &header) |
| convenience function to get volume-contiguous strides More...
|
|
template<class HeaderType > |
List | contiguous_along_spatial_axes (const HeaderType &header) |
| convenience function to get spatially contiguous strides More...
|
|
List | __from_command_line (const List ¤t) |
|
template<class HeaderType > |
void | set_from_command_line (HeaderType &header, const List &default_strides=List()) |
|
Functions to handle the memory layout of images.
Strides are typically supplied as a symbolic list of increments, representing the layout of the data in memory. In this symbolic representation, the actual magnitude of the strides is only important in that it defines the ordering of the various axes.
For example, the vector of strides [ 3 -1 -2 ] is valid as a symbolic representation of a image stored as a stack of sagittal slices. Each sagittal slice is stored as rows of voxels ordered from anterior to posterior (i.e. negative y: -1), then stacked superior to inferior (i.e. negative z: -2). These slices are then stacked from left to right (i.e. positive x: 3).
This representation is symbolic since it does not take into account the size of the Image along each dimension. To be used in practice, these strides must correspond to the number of intensity values to skip between adjacent voxels along the respective axis. For the example above, the image might consists of 128 sagittal slices, each with dimensions 256x256. The dimensions of the image (as returned by size()) are therefore [ 128 256 256 ]. The actual strides needed to navigate through the image, given the symbolic strides above, should therefore be [ 65536 -256 -1 ] (since 256x256 = 65532).
Note that a stride of zero is treated as undefined or invalid. This can be used in the symbolic representation to specify that the ordering of the corresponding axis is not important. A suitable stride will be allocated to that axis when the image is initialised (this is done with a call to sanitise()).
The functions defined in this namespace provide an interface to manipulate the strides and convert symbolic into actual strides.
template<class HeaderType >
List MR::Stride::get_nearest_match |
( |
const HeaderType & |
current, |
|
|
const List & |
desired |
|
) |
| |
produce strides from current
that match those specified in desired
The strides in desired
should be specified as symbolic strides, and any zero strides will be ignored and replaced with sensible values if needed. Essentially, this function checks whether the symbolic strides in current
already match those specified in desired
. If so, these will be used as-is, otherwise a new set of strides based on desired
will be produced, as follows. First, non-zero strides in desired
are used as-is, then the remaining strides are taken from current
where specified and used with higher values, followed by those strides not specified in either.
Note that strides are considered matching even if the differ in their sign - this purpose of this function is to ensure contiguity in RAM along the desired axes, and a reversal in the direction of traversal is not considered to affect this.
Examples:
current:
[ 1 2 3 4 ], desired:
[ 0 0 0 1 ] => [ 2 3 4 1 ]
current:
[ 3 -2 4 1 ], desired:
[ 0 0 0 1 ] => [ 3 -2 4 1 ]
current:
[ -2 4 -3 1 ], desired:
[ 1 2 3 0 ] => [ 1 2 3 4 ]
current:
[ -1 2 -3 4 ], desired:
[ 1 2 3 0 ] => [ -1 2 -3 4 ]
Definition at line 364 of file stride.h.