libfs
Header-only C++11 library for accessing FreeSurfer neuroimaging data
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
fs::MghHeader Struct Reference

Models the header of an MGH file. More...

#include <libfs.h>

Collaboration diagram for fs::MghHeader:
Collaboration graph
[legend]

Public Member Functions

 MghHeader ()
 Empty default constuctor.
 
 MghHeader (Curv curv)
 
 MghHeader (std::vector< float > curv_data)
 
size_t num_values () const
 Compute the number of values based on the dim*length header fields.
 
std::vector< float > compute_vox2ras () const
 Compute the 4x4 voxel-to-RAS (vox2ras) matrix from the RAS header fields, if available.
 

Public Attributes

int32_t dim1length = 0
 size of data along 1st dimension
 
int32_t dim2length = 0
 size of data along 2nd dimension
 
int32_t dim3length = 0
 size of data along 3rd dimension
 
int32_t dim4length = 0
 size of data along 4th dimension
 
int32_t dtype = 0
 the MRI data type
 
int32_t dof = 0
 typically ignored
 
int16_t ras_good_flag = 0
 flag indicating whether the data in the RAS fields (Mdc, Pxyz_c) are valid. 1 means valid, everything else means invalid.
 
float xsize = 0.0
 size of voxels along 1st axis (x or r)
 
float ysize = 0.0
 size of voxels along 2nd axis (y or a)
 
float zsize = 0.0
 size of voxels along 3rd axis (z or s)
 
std::vector< float > Mdc
 matrix
 
std::vector< float > Pxyz_c
 x,y,z coordinates of central vertex
 

Detailed Description

Models the header of an MGH file.

Constructor & Destructor Documentation

◆ MghHeader() [1/2]

fs::MghHeader::MghHeader ( Curv  curv)
inline

< Constuctor to fill header from a Curv instance.

◆ MghHeader() [2/2]

fs::MghHeader::MghHeader ( std::vector< float >  curv_data)
inline

< Constuctor to fill header from a 1D float array (curv data).

Member Function Documentation

◆ compute_vox2ras()

std::vector< float > fs::MghHeader::compute_vox2ras ( ) const
inline

Compute the 4x4 voxel-to-RAS (vox2ras) matrix from the RAS header fields, if available.

The vox2ras matrix maps voxel indices to world (RAS) coordinates: the world coordinate of a voxel (i, j, k) is vox2ras * [i, j, k, 1]. The linear part (upper left 3x3 block) maps a unit step along voxel axis j to a world displacement of size_j * Mdc_row_j, i.e. column j is scaled by the voxel size of axis j. This is the FreeSurfer convention (vox2ras = Mdc^T * diag(size), with the rows of the MGH Mdc matrix being the unit direction cosines of the 3 volume axes). The translation is the RAS coordinate of voxel (0,0,0), derived from the center voxel Pxyz_c stored in the header (center index uses integer division dim/2).

Returns
the vox2ras matrix as 16 floats in row-major order (entry [i*4+j] = row i, col j), or an empty vector if the header does not carry valid RAS information.

The documentation for this struct was generated from the following file: