MriNiftiIO
Namespace: MRILIB · Library: MRI Library
#include <mri/mri_nifti_io.h>
class MRILIB::MriNiftiIO
Stateless decoder for NIfTI-1 single-file volumes (.nii and .nii.gz).
Parses the 348-byte fixed-size header, expands any voxel-type / endianness combination NIfTI-1 supports into the canonical 16-bit unsigned slice buffer produced by MriMghIO, and resolves voxel→RAS via the sform/qform/pixdim priority chain. The class is a pure namespace of static methods so callers can use it without owning any state; the populated MriVolData carries the result.
MriVolData direct;
MriNiftiIO::read(dataDir + "/gradient.nii.gz", direct);
Static Methods
read(niiFile, volData, verbose)
Reads a NIfTI-1 single-file volume.
For .nii.gz inputs the file is decompressed in memory via zlib (re-using the same MAX_WBITS+16 strategy as MriMghIO).
Parameters:
-
niiFile : const QString & Path to the .nii or .nii.gz file.
-
volData : MriVolData & Volume to populate.
-
verbose : bool Print header geometry on success.
Returns:
- bool — True on success, false on parse / I/O error.
decompress(gzFile, rawData)
Decompresses a .nii.gz file into rawData.
Exposed for direct use by tests; read calls it transparently when the input path ends in .gz.
Parameters:
-
gzFile : const QString & Path to the gzip-compressed input.
-
rawData : QByteArray & Output buffer.
Returns:
- bool — True on success.
Example
- Full source:
src/examples/ex_mri/main.cpp - Build target:
ex_mri(runs under CTest)
Used in examples
ex_mri
MRI library: MGH/MGZ and NIfTI volumes, voxel/RAS transforms, slicing and COR sets.
MriVolData direct;
MriNiftiIO::read(dataDir + "/gradient.nii.gz", direct);
ok &= expect(direct.voxelDataAsFloat() == voxels, "MriNiftiIO::read equals MriVolData::read");
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>