v2.0.0
Loading...
Searching...
No Matches
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
45using namespace MRILIB;
46using namespace Eigen;
47
48//=============================================================================================================
49// DEFINE MEMBER METHODS
50//=============================================================================================================
51
53: version(0)
54, width(0)
55, height(0)
56, depth(0)
57, nframes(0)
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
79{
80 return (version == MRI_MGH_VERSION && width > 0 && height > 0 && depth > 0);
81}
82
83//=============================================================================================================
84
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}
MriVolData class declaration.
MRI volume and coordinate-system I/O (volumes, voxel geometry, transforms).
constexpr int MRI_MGH_VERSION
Definition mri_types.h:57
constexpr int MRI_UCHAR
Definition mri_types.h:75
Eigen::Vector3f y_ras
bool isValid() const
Eigen::Vector3f x_ras
Eigen::Matrix4f computeVox2Ras() const
Eigen::Vector3f z_ras
Eigen::Vector3f c_ras