Developer documentation
Version 3.0.3-105-gd3941f44
MR::Stride Namespace Reference

Functions to handle the memory layout of images. More...

Typedefs

using List = vector< ssize_t >
 

Functions

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...
 
Listsanitise (List &current, 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 &current, 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 &current)
 
template<class HeaderType >
void set_from_command_line (HeaderType &header, const List &default_strides=List())
 

Variables

const App::OptionGroup Options
 

Detailed Description

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.

Typedef Documentation

◆ List

using MR::Stride::List = typedef vector<ssize_t>

Definition at line 63 of file stride.h.

Function Documentation

◆ __from_command_line()

List MR::Stride::__from_command_line ( const List current)

◆ actualise() [1/2]

template<class HeaderType >
void MR::Stride::actualise ( HeaderType &  header)

convert strides from symbolic to actual strides

Definition at line 239 of file stride.h.

◆ actualise() [2/2]

template<class HeaderType >
void MR::Stride::actualise ( List strides,
const HeaderType &  header 
)
inline

convert strides from symbolic to actual strides

convert strides from symbolic to actual strides, assuming the strides in strides and HeaderType dimensions of header.

Definition at line 253 of file stride.h.

◆ contiguous_along_axis() [1/2]

List MR::Stride::contiguous_along_axis ( size_t  axis)
inline

convenience function to get volume-contiguous strides

Definition at line 386 of file stride.h.

◆ contiguous_along_axis() [2/2]

template<class HeaderType >
List MR::Stride::contiguous_along_axis ( size_t  axis,
const HeaderType &  header 
)
inline

convenience function to get volume-contiguous strides

Definition at line 395 of file stride.h.

◆ contiguous_along_spatial_axes()

template<class HeaderType >
List MR::Stride::contiguous_along_spatial_axes ( const HeaderType &  header)
inline

convenience function to get spatially contiguous strides

Definition at line 402 of file stride.h.

◆ get()

template<class HeaderType >
List MR::Stride::get ( const HeaderType &  header)

return the strides of header as a vector<ssize_t>

Definition at line 125 of file stride.h.

◆ get_actual() [1/2]

template<class HeaderType >
List MR::Stride::get_actual ( const List strides,
const HeaderType &  header 
)
inline

get actual strides:

Definition at line 270 of file stride.h.

◆ get_actual() [2/2]

template<class HeaderType >
List MR::Stride::get_actual ( HeaderType &  header)
inline

get actual strides:

Definition at line 261 of file stride.h.

◆ get_nearest_match()

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.

◆ get_symbolic() [1/2]

template<class HeaderType >
List MR::Stride::get_symbolic ( const HeaderType &  header)
inline

get symbolic strides:

Definition at line 298 of file stride.h.

◆ get_symbolic() [2/2]

template<>
List MR::Stride::get_symbolic ( const List list)
inline

get symbolic strides:

Definition at line 307 of file stride.h.

◆ offset() [1/2]

template<class HeaderType >
size_t MR::Stride::offset ( const HeaderType &  header)

calculate offset to start of data

this function caculate the offset (in number of voxels) from the start of the data region to the first voxel value (i.e. at voxel [ 0 0 0 ... ]).

Definition at line 319 of file stride.h.

◆ offset() [2/2]

template<class HeaderType >
size_t MR::Stride::offset ( List strides,
const HeaderType &  header 
)

calculate offset to start of data

this function caculate the offset (in number of voxels) from the start of the data region to the first voxel value (i.e. at voxel [ 0 0 0 ... ]), assuming the strides in strides and HeaderType dimensions of header.

Definition at line 333 of file stride.h.

◆ order()

template<class HeaderType >
vector< size_t > MR::Stride::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.

Returns
a vector of indices of the axes in order of increasing absolute stride.
Note
all strides should be valid (i.e. non-zero).

Definition at line 159 of file stride.h.

◆ order< List >()

template<>
vector< size_t > MR::Stride::order< List > ( const List strides,
size_t  from_axis,
size_t  to_axis 
)
inline

sort axes with respect to their absolute stride.

Returns
a vector of indices of the axes in order of increasing absolute stride.
Note
all strides should be valid (i.e. non-zero).

Definition at line 159 of file stride.h.

◆ sanitise() [1/3]

template<class HeaderType >
void MR::Stride::sanitise ( HeaderType &  header)

remove duplicate and invalid strides.

sanitise the strides of HeaderType header by identifying invalid (i.e. zero) or duplicate (absolute) strides, and assigning to each a suitable value. The value chosen for each sanitised stride is the lowest number greater than any of the currently valid strides.

Definition at line 191 of file stride.h.

◆ sanitise() [2/3]

List & MR::Stride::sanitise ( List current,
const List desired,
const vector< ssize_t > &  header 
)

remove duplicate and invalid strides.

sanitise the strides in current by identifying invalid (i.e. zero) or duplicate (absolute) strides, and assigning to each a suitable value. The value chosen for each sanitised stride is the lowest number greater than any of the currently valid strides.

◆ sanitise() [3/3]

template<class HeaderType >
void MR::Stride::sanitise ( List strides,
const HeaderType &  header 
)
inline

remove duplicate and invalid strides.

sanitise the strides of HeaderType header by identifying invalid (i.e. zero) or duplicate (absolute) strides, and assigning to each a suitable value. The value chosen for each sanitised stride is the lowest number greater than any of the currently valid strides.

Definition at line 222 of file stride.h.

◆ set() [1/2]

template<class HeaderType , class FromHeaderType >
void MR::Stride::set ( HeaderType &  header,
const FromHeaderType &  from 
)

set the strides of header from another HeaderType

Definition at line 146 of file stride.h.

◆ set() [2/2]

template<class HeaderType >
void MR::Stride::set ( HeaderType &  header,
const List stride 
)

set the strides of header from a vector<ssize_t>

Definition at line 135 of file stride.h.

◆ set_from_command_line()

template<class HeaderType >
void MR::Stride::set_from_command_line ( HeaderType &  header,
const List default_strides = List() 
)
inline

Definition at line 416 of file stride.h.

◆ symbolise() [1/2]

template<class HeaderType >
void MR::Stride::symbolise ( HeaderType &  header)

convert strides from actual to symbolic strides

Definition at line 281 of file stride.h.

◆ symbolise() [2/2]

template<>
void MR::Stride::symbolise ( List strides)
inline

convert strides from actual to symbolic strides

Definition at line 290 of file stride.h.

Variable Documentation

◆ Options

const App::OptionGroup MR::Stride::Options
extern

Definition at line 274 of file app.h.