v2.0.0
Loading...
Searching...
No Matches
inv_volume_source_estimate.cpp
Go to the documentation of this file.
1//=============================================================================================================
17
18//=============================================================================================================
19// INCLUDES
20//=============================================================================================================
21
23
24//=============================================================================================================
25// USED NAMESPACES
26//=============================================================================================================
27
28using namespace INVLIB;
29using namespace Eigen;
30
31//=============================================================================================================
32// DEFINE MEMBER METHODS
33//=============================================================================================================
34
40
41//=============================================================================================================
42
44 const VectorXi& p_vertices,
45 float p_tmin, float p_tstep)
46: InvSourceEstimate(p_sol, p_vertices, p_tmin, p_tstep)
47{
49}
50
51//=============================================================================================================
52
54{
55 if (shape.size() == 3)
56 m_shape = shape;
57}
58
59//=============================================================================================================
60
61VectorXd InvVolumeSourceEstimate::toVolume(int timeIdx) const
62{
63 if (!hasShape() || timeIdx < 0 || timeIdx >= static_cast<int>(data.cols()))
64 return VectorXd();
65
66 int nTotal = m_shape[0] * m_shape[1] * m_shape[2];
67 VectorXd vol = VectorXd::Zero(nTotal);
68
69 for (int i = 0; i < vertices.size(); ++i) {
70 int vIdx = vertices[i];
71 if (vIdx >= 0 && vIdx < nTotal)
72 vol[vIdx] = data(i, timeIdx);
73 }
74
75 return vol;
76}
77
78//=============================================================================================================
79
80Vector3d InvVolumeSourceEstimate::centreOfMass(int timeIdx) const
81{
82 if (!hasShape() || timeIdx < 0 || timeIdx >= static_cast<int>(data.cols()))
83 return Vector3d::Zero();
84
85 int ny = m_shape[1];
86 int nz = m_shape[2];
87
88 double totalWeight = 0.0;
89 Vector3d com = Vector3d::Zero();
90
91 for (int i = 0; i < vertices.size(); ++i) {
92 double w = std::abs(data(i, timeIdx));
93 if (w < 1e-15)
94 continue;
95
96 int vIdx = vertices[i];
97 int ix = vIdx / (ny * nz);
98 int iy = (vIdx % (ny * nz)) / nz;
99 int iz = vIdx % nz;
100
101 com += w * Vector3d(ix, iy, iz);
102 totalWeight += w;
103 }
104
105 if (totalWeight > 1e-15)
106 com /= totalWeight;
107
108 return com;
109}
Volume (voxel-grid) source estimate that augments InvSourceEstimate with 3-D grid shape information.
Inverse source estimation (MNE, dSPM, sLORETA, dipole fitting).
Source-space inverse-solution container with dense grid plus optional focal-dipole,...
InvSourceSpaceType sourceSpaceType
void setShape(const QVector< int > &shape)
Eigen::VectorXd toVolume(int timeIdx) const
const QVector< int > & shape() const
Eigen::Vector3d centreOfMass(int timeIdx) const