RNifti
Fast R and C++ Access to NIfTI Images
|
Wrapper class encapsulating a NIfTI data blob, with responsibility for handling data scaling and polymorphism. More...
#include <NiftiImage.h>
Classes | |
struct | ConcreteTypeHandler |
Concrete inner class template defining behaviour specific to individual data types. More... | |
struct | ConcreteTypeHandler< rgba32_t, alpha > |
struct | ConcreteTypeHandler< std::complex< ElementType >, false > |
struct | Element |
Inner class representing a single element in the data blob. More... | |
class | Iterator |
Iterator type for NiftiImageData , with Element as its value type. More... | |
struct | TypeHandler |
Abstract inner class defining the type-specific functions required in concrete subclasses. More... | |
Public Member Functions | |
NiftiImageData () | |
Default constructor, creating an empty data object. | |
NiftiImageData (void *data, const size_t length, const int datatype, const double slope=1.0, const double intercept=0.0) | |
Primary constructor. More... | |
NiftiImageData (nifti_image *image) | |
Convenience constructor for a nifti_image . More... | |
NiftiImageData (const NiftiImageData &source, const int datatype=DT_NONE) | |
Copy constructor with optional type conversion. More... | |
template<class InputIterator > | |
NiftiImageData (InputIterator from, InputIterator to, const int datatype) | |
Iterator-based constructor. More... | |
virtual | ~NiftiImageData () |
Destructor which frees the type handler, and the data blob if it is owned by this object. | |
NiftiImageData & | operator= (const NiftiImageData &source) |
Copy assignment operator. More... | |
void * | blob () const |
Return an opaque pointer to the blob. | |
int | datatype () const |
Return stored datatype code. | |
size_t | length () const |
Return the number of elements in the data. | |
size_t | size () const |
Return the number of elements in the data. | |
size_t | bytesPerPixel () const |
Return the number of bytes used per element, or zero if the datatype is undefined or the blob is NULL . | |
size_t | totalBytes () const |
Return the total size of the data blob, in bytes. | |
bool | isEmpty () const |
Determine whether or not the object is empty. More... | |
bool | isScaled () const |
Determine whether the object uses data scaling. More... | |
bool | isComplex () const |
Determine whether the datatype is complex. More... | |
bool | isFloatingPoint () const |
Determine whether the datatype is floating point. More... | |
bool | isInteger () const |
Determine whether the datatype is an integer type. More... | |
bool | isRgb () const |
Determine whether the datatype corresponds to an RGB type. More... | |
NiftiImageData | unscaled () const |
Return a similar object to the callee, but with the slope and intercept values reset. More... | |
NiftiImageData & | disown () |
Disown the data blob, removing responsibility for freeing it upon destruction. More... | |
const Iterator | begin () const |
Obtain a constant iterator corresponding to the start of the blob. | |
const Iterator | end () const |
Obtain a constant iterator corresponding to the end of the blob. | |
Iterator | begin () |
Obtain a mutable iterator corresponding to the start of the blob. | |
Iterator | end () |
Obtain a mutable iterator corresponding to the end of the blob. | |
const Element | operator[] (const size_t i) const |
Indexing operator, returning a constant element. More... | |
Element | operator[] (const size_t i) |
Indexing operator, returning a mutable element. More... | |
void | minmax (double *min, double *max) const |
Calculate the minimum and maximum values in the blob, as doubles. More... | |
Public Attributes | |
double | slope |
The slope term used to scale data values. More... | |
double | intercept |
The intercept term used to scale data values. | |
Protected Member Functions | |
TypeHandler * | createHandler () |
Create a concrete type handler appropriate to the datatype code stored with the data. More... | |
void | init (void *data, const size_t length, const int datatype, const double slope, const double intercept, const bool alloc=true) |
Initialiser method, used by constructors. More... | |
void | calibrateFrom (const NiftiImageData &data) |
Update the slope and intercept to cover the range of another data object. More... | |
Protected Attributes | |
void * | dataPtr |
Opaque pointer to the underlying data blob. | |
int | _datatype |
Datatype code indicating the actual type of the elements. | |
TypeHandler * | handler |
Type handler, which is created to match the datatype. | |
size_t | _length |
The number of data elements in the blob. | |
bool | owner |
An indicator of whether this object is responsible for cleaning up the data. | |
Wrapper class encapsulating a NIfTI data blob, with responsibility for handling data scaling and polymorphism.
This class provides read/write data access, iterators, etc., which internally handle conversion to and from the data's native type. It can be linked to the data in a nifti_image
or used independently.
|
inline |
Primary constructor.
data | A pointer to a pre-allocated data blob, or NULL . In the latter case, memory will be allocated by the object, and cleaned up at destruction unless it is disowned |
length | The number of elements in the blob |
datatype | The NIfTI datatype code corresponding to the type of the data elements |
slope | The slope parameter to use for data scaling, if any |
intercept | The intercept parameter to use for data scaling, if any |
|
inline |
Convenience constructor for a nifti_image
.
image | The image struct whose data the object will wrap |
|
inline |
Copy constructor with optional type conversion.
source | Another NiftiImageData object to copy data from |
datatype | The datatype to convert to, or DT_NONE , the default, for no conversion. If the range of the source data cannot be represented by the chosen type, the slope and intercept parameters will be set to adjust the range |
|
inline |
|
inlineprotected |
Update the slope and intercept to cover the range of another data object.
If the current object's datatype can capture the required range without scaling, the slope and intercept are simply reset
data | Another data object |
|
inlineprotected |
Create a concrete type handler appropriate to the datatype code stored with the data.
NULL
runtime_error | If the current datatype is unsupported |
|
inline |
Disown the data blob, removing responsibility for freeing it upon destruction.
|
inlineprotected |
Initialiser method, used by constructors.
data | Pointer to a preallocated data blob, or NULL |
length | Number of elements in the blob |
datatype | NIfTI datatype code appropriate to the blob |
slope | Slope parameter for scaling values |
intercept | Intercept parameter for scaling values |
alloc | If true , the default, and data is NULL , memory will be allocated for the blob. If false , the blob will be NULL in this case |
|
inline |
Determine whether the datatype is complex.
true
if the data represents complex floating point values; false
otherwise
|
inline |
Determine whether or not the object is empty.
true
if the data pointer is NULL
; false
otherwise
|
inline |
Determine whether the datatype is floating point.
true
if the data represents 32-bit or 64-bit floating point values; false
otherwise
|
inline |
Determine whether the datatype is an integer type.
true
if the data represents integers; false
otherwise
|
inline |
Determine whether the datatype corresponds to an RGB type.
true
if the data represents RGB colour values; false
otherwise
|
inline |
Determine whether the object uses data scaling.
true
if the slope and intercept parameters are set to nontrivial values; false
otherwise
|
inline |
Calculate the minimum and maximum values in the blob, as doubles.
min | Pointer to the minimum value (output parameter). Will be set to zero if the datatype is unknown or the data is empty |
max | Pointer to the maximum value (output parameter). Will be set to zero if the datatype is unknown or the data is empty |
|
inline |
Copy assignment operator.
source | Another NiftiImageData object, from which the data and metadata are copied |
|
inline |
Indexing operator, returning a mutable element.
i | Index value, where the first dimension moves fastest |
|
inline |
Indexing operator, returning a constant element.
i | Index value, where the first dimension moves fastest |
|
inline |
Return a similar object to the callee, but with the slope and intercept values reset.
NiftiImageData
object, pointing to the same memory as the callee double RNifti::NiftiImageData::slope |
The slope term used to scale data values.
Ignored if zero.