v2.0.0
Loading...
Searching...
No Matches
src
libraries
mri
mri_vol_data.cpp
Go to the documentation of this file.
1
//=============================================================================================================
34
35
//=============================================================================================================
36
// INCLUDES
37
//=============================================================================================================
38
39
#include "
mri_vol_data.h
"
40
41
//=============================================================================================================
42
// USED NAMESPACES
43
//=============================================================================================================
44
45
using namespace
MRILIB
;
46
using namespace
Eigen;
47
48
//=============================================================================================================
49
// DEFINE MEMBER METHODS
50
//=============================================================================================================
51
52
MriVolData::MriVolData
()
53
:
version
(0)
54
,
width
(0)
55
,
height
(0)
56
,
depth
(0)
57
,
nframes
(0)
58
,
type
(
MRI_UCHAR
)
59
,
dof
(0)
60
,
rasGood
(false)
61
,
xsize
(1.0f)
62
,
ysize
(1.0f)
63
,
zsize
(1.0f)
64
,
x_ras
(-1.0f, 0.0f, 0.0f)
// FreeSurfer defaults when goodRASflag is false
65
,
y_ras
( 0.0f, 0.0f, -1.0f)
// See: https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat
66
,
z_ras
( 0.0f, 1.0f, 0.0f)
67
,
c_ras
( 0.0f, 0.0f, 0.0f)
68
,
TR
(0.0f)
69
,
flipAngle
(0.0f)
70
,
TE
(0.0f)
71
,
TI
(0.0f)
72
,
FoV
(0.0f)
73
{
74
}
75
76
//=============================================================================================================
77
78
bool
MriVolData::isValid
()
const
79
{
80
return
(
version
==
MRI_MGH_VERSION
&&
width
> 0 &&
height
> 0 &&
depth
> 0);
81
}
82
83
//=============================================================================================================
84
85
Matrix4f
MriVolData::computeVox2Ras
()
const
86
{
87
//
88
// Build voxel-to-surface-RAS transform (FreeSurfer convention).
89
//
90
// The direction cosine matrix Mdc stores the orientation of each voxel axis
91
// (columns are x, y, z directions). Scaling by voxel size gives the actual
92
// spacing matrix M:
93
//
94
// M = Mdc * diag(xsize, ysize, zsize)
95
//
96
// The origin P0 in RAS coordinates is:
97
//
98
// P0 = c_ras - M * (dim/2)
99
//
100
// The full 4x4 vox2ras matrix is:
101
//
102
// | M P0 | (in mm, then converted to meters for FIFF)
103
// | 0 1 |
104
//
105
// Reference: https://surfer.nmr.mgh.harvard.edu/fswiki/FsTutorial/MghFormat
106
//
107
108
// Construct M = Mdc * D (scale direction cosines by voxel sizes)
109
Matrix3f M;
110
M.col(0) =
x_ras
*
xsize
;
111
M.col(1) =
y_ras
*
ysize
;
112
M.col(2) =
z_ras
*
zsize
;
113
114
// Compute center voxel
115
Vector3f center(
static_cast<
float
>
(
width
) / 2.0f,
116
static_cast<
float
>
(
height
) / 2.0f,
117
static_cast<
float
>
(
depth
) / 2.0f);
118
119
// Compute P0 = c_ras - M * center
120
Vector3f P0 =
c_ras
- M * center;
121
122
// Build 4x4 matrix in meters (FreeSurfer uses mm, FIFF uses meters)
123
Matrix4f vox2ras = Matrix4f::Identity();
124
vox2ras.block<3, 3>(0, 0) = M / 1000.0f;
125
vox2ras.block<3, 1>(0, 3) = P0 / 1000.0f;
126
127
return
vox2ras;
128
}
mri_vol_data.h
MriVolData class declaration.
MRILIB
MRI volume and coordinate-system I/O (volumes, voxel geometry, transforms).
Definition
mri_cor_fif_io.h:83
MRILIB::MRI_MGH_VERSION
constexpr int MRI_MGH_VERSION
Definition
mri_types.h:57
MRILIB::MRI_UCHAR
constexpr int MRI_UCHAR
Definition
mri_types.h:75
MRILIB::MriVolData::zsize
float zsize
Definition
mri_vol_data.h:194
MRILIB::MriVolData::TR
float TR
Definition
mri_vol_data.h:210
MRILIB::MriVolData::type
int type
Definition
mri_vol_data.h:189
MRILIB::MriVolData::y_ras
Eigen::Vector3f y_ras
Definition
mri_vol_data.h:196
MRILIB::MriVolData::rasGood
bool rasGood
Definition
mri_vol_data.h:191
MRILIB::MriVolData::isValid
bool isValid() const
Definition
mri_vol_data.cpp:78
MRILIB::MriVolData::nframes
int nframes
Definition
mri_vol_data.h:188
MRILIB::MriVolData::x_ras
Eigen::Vector3f x_ras
Definition
mri_vol_data.h:195
MRILIB::MriVolData::MriVolData
MriVolData()
Definition
mri_vol_data.cpp:52
MRILIB::MriVolData::width
int width
Definition
mri_vol_data.h:185
MRILIB::MriVolData::flipAngle
float flipAngle
Definition
mri_vol_data.h:211
MRILIB::MriVolData::height
int height
Definition
mri_vol_data.h:186
MRILIB::MriVolData::ysize
float ysize
Definition
mri_vol_data.h:193
MRILIB::MriVolData::xsize
float xsize
Definition
mri_vol_data.h:192
MRILIB::MriVolData::computeVox2Ras
Eigen::Matrix4f computeVox2Ras() const
Definition
mri_vol_data.cpp:85
MRILIB::MriVolData::TI
float TI
Definition
mri_vol_data.h:213
MRILIB::MriVolData::z_ras
Eigen::Vector3f z_ras
Definition
mri_vol_data.h:197
MRILIB::MriVolData::FoV
float FoV
Definition
mri_vol_data.h:214
MRILIB::MriVolData::c_ras
Eigen::Vector3f c_ras
Definition
mri_vol_data.h:198
MRILIB::MriVolData::depth
int depth
Definition
mri_vol_data.h:187
MRILIB::MriVolData::version
int version
Definition
mri_vol_data.h:184
MRILIB::MriVolData::TE
float TE
Definition
mri_vol_data.h:212
MRILIB::MriVolData::dof
int dof
Definition
mri_vol_data.h:190
Generated on
for MNE-CPP by
1.16.1