Format-agnostic 3D MRI volume: header geometry, voxel buffer (as a vector of MriSlice), scan parameters and provenance. More...
#include <mri_vol_data.h>
Public Member Functions | |
| MriVolData () | |
| bool | read (const QString &path) |
| bool | isValid () const |
| int | dimX () const |
| int | dimY () const |
| int | dimZ () const |
| QVector< int > | dims () const |
| QVector< float > | voxelDataAsFloat () const |
| Eigen::Matrix4f | computeVox2Ras () const |
| Eigen::Matrix4f | computeVox2RasTkr () const |
Public Attributes | |
| QString | fileName |
| int | version |
| int | width |
| int | height |
| int | depth |
| int | nframes |
| int | type |
| int | dof |
| bool | rasGood |
| float | xsize |
| float | ysize |
| float | zsize |
| Eigen::Vector3f | x_ras |
| Eigen::Vector3f | y_ras |
| Eigen::Vector3f | z_ras |
| Eigen::Vector3f | c_ras |
| FIFFLIB::FiffCoordTrans | voxelSurfRasT |
| float | TR |
| float | flipAngle |
| float | TE |
| float | TI |
| float | FoV |
| QString | talairachXfmPath |
| QVector< MriSlice > | slices |
Format-agnostic 3D MRI volume: header geometry, voxel buffer (as a vector of MriSlice), scan parameters and provenance.
The volume is the single in-memory representation every consumer in mne-cpp operates on, regardless of whether it was loaded from MGH/MGZ, NIfTI-1 or a FreeSurfer COR directory. Storage is decomposed into a vector of MriSlice so the COR.fif writer can serialise without an intermediate copy, while the slice viewer and the BEM coregistration step both index it through the same (column, row, slice) coordinate.
The header captures FreeSurfer's MGH conventions: voxel sizes (spacingX/Y/Z), direction cosines (Mdc, column-major), centre RAS (c_ras) and voxel data type (MRI_UCHAR / MRI_INT / MRI_FLOAT / MRI_SHORT). Optional scan parameters (TR, flip angle, TE, TI, FoV) and tags (Talairach transform path, provenance) round out the structure. The read() entry point dispatches on the file extension so callers do not need to branch on format.
Format reference: https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat
Ported from mneMRIdataRec in MNE C (mne_types_mne-c.h) by Matti Hamalainen.
Definition at line 147 of file mri_vol_data.h.
| MriVolData::MriVolData | ( | ) |
Default constructor.
Definition at line 52 of file mri_vol_data.cpp.
| Matrix4f MriVolData::computeVox2Ras | ( | ) | const |
Builds the voxel-to-surface-RAS (MRI) 4×4 transform matrix.
Following FreeSurfer convention: M = Mdc * diag(xsize, ysize, zsize) P0 = c_ras - M * (dim/2) vox2ras = | M P0 | (in mm, converted to meters for FIFF) | 0 1 |
Definition at line 132 of file mri_vol_data.cpp.
| Matrix4f MriVolData::computeVox2RasTkr | ( | ) | const |
Builds the voxel-to-surface-RAS (tkRAS / tkregister) 4×4 transform.
Identical to computeVox2Ras() but forces c_ras = (0,0,0), producing the coordinate system used by FreeSurfer surfaces (lh.white, etc.).
Definition at line 179 of file mri_vol_data.cpp.
|
inline |
Definition at line 209 of file mri_vol_data.h.
|
inline |
Definition at line 182 of file mri_vol_data.h.
|
inline |
Definition at line 191 of file mri_vol_data.h.
|
inline |
Definition at line 200 of file mri_vol_data.h.
| bool MriVolData::isValid | ( | ) | const |
Returns whether this volume contains valid data.
Definition at line 78 of file mri_vol_data.cpp.
| bool MriVolData::read | ( | const QString & | path | ) |
Convenience loader: reads an MGH/MGZ file and populates this volume.
Wraps MriMghIO::read() so callers don't need to manage a separate additionalTrans vector. Mirrors MNE-Python's nib.load(path) one-liner.
| [in] | path | Path to the .mgh or .mgz file. |
Definition at line 85 of file mri_vol_data.cpp.
| QVector< float > MriVolData::voxelDataAsFloat | ( | ) | const |
Returns all voxel data as a contiguous float array in x-fastest order.
Mirrors MNE-Python's img.get_fdata().ravel(order='F'). Regardless of the on-disk type (UCHAR, SHORT, INT, FLOAT) the output is always float. The array length is width * height * depth.
Definition at line 99 of file mri_vol_data.cpp.
| Eigen::Vector3f MRILIB::MriVolData::c_ras |
Center RAS coordinates (cr, ca, cs). Default: (0, 0, 0).
Definition at line 270 of file mri_vol_data.h.
| int MRILIB::MriVolData::depth |
Third dimension (slowest).
Definition at line 259 of file mri_vol_data.h.
| int MRILIB::MriVolData::dof |
Degrees of freedom.
Definition at line 262 of file mri_vol_data.h.
| QString MRILIB::MriVolData::fileName |
Name of the source file.
Definition at line 255 of file mri_vol_data.h.
| float MRILIB::MriVolData::flipAngle |
Flip angle (radians).
Definition at line 283 of file mri_vol_data.h.
| float MRILIB::MriVolData::FoV |
Field of view (unreliable per FreeSurfer docs).
Definition at line 286 of file mri_vol_data.h.
| int MRILIB::MriVolData::height |
Second dimension.
Definition at line 258 of file mri_vol_data.h.
| int MRILIB::MriVolData::nframes |
Number of frames (scalar components per voxel).
Definition at line 260 of file mri_vol_data.h.
| bool MRILIB::MriVolData::rasGood |
Whether the direction cosines in the header are valid.
Definition at line 263 of file mri_vol_data.h.
| QVector<MriSlice> MRILIB::MriVolData::slices |
Per-slice data (for COR-equivalent representation).
Definition at line 298 of file mri_vol_data.h.
| QString MRILIB::MriVolData::talairachXfmPath |
Path to the Talairach .xfm file (from MGH footer tags).
Definition at line 292 of file mri_vol_data.h.
| float MRILIB::MriVolData::TE |
Echo time (ms).
Definition at line 284 of file mri_vol_data.h.
| float MRILIB::MriVolData::TI |
Inversion time (ms).
Definition at line 285 of file mri_vol_data.h.
| float MRILIB::MriVolData::TR |
Repetition time (ms).
Definition at line 282 of file mri_vol_data.h.
| int MRILIB::MriVolData::type |
Voxel data type (MRI_UCHAR, MRI_INT, MRI_FLOAT, MRI_SHORT).
Definition at line 261 of file mri_vol_data.h.
| int MRILIB::MriVolData::version |
MGH format version (should be 1).
Definition at line 256 of file mri_vol_data.h.
| FIFFLIB::FiffCoordTrans MRILIB::MriVolData::voxelSurfRasT |
Voxel -> surface RAS (MRI) transform.
Definition at line 276 of file mri_vol_data.h.
| int MRILIB::MriVolData::width |
First dimension of the image buffer (fastest).
Definition at line 257 of file mri_vol_data.h.
| Eigen::Vector3f MRILIB::MriVolData::x_ras |
X-direction cosines (xr, xa, xs). Default: (-1, 0, 0).
Definition at line 267 of file mri_vol_data.h.
| float MRILIB::MriVolData::xsize |
Voxel spacing in X direction (mm).
Definition at line 264 of file mri_vol_data.h.
| Eigen::Vector3f MRILIB::MriVolData::y_ras |
Y-direction cosines (yr, ya, ys). Default: (0, 0, -1).
Definition at line 268 of file mri_vol_data.h.
| float MRILIB::MriVolData::ysize |
Voxel spacing in Y direction (mm).
Definition at line 265 of file mri_vol_data.h.
| Eigen::Vector3f MRILIB::MriVolData::z_ras |
Z-direction cosines (zr, za, zs). Default: (0, 1, 0).
Definition at line 269 of file mri_vol_data.h.
| float MRILIB::MriVolData::zsize |
Voxel spacing in Z direction (mm).
Definition at line 266 of file mri_vol_data.h.