v2.0.0
Loading...
Searching...
No Matches
stcloadingworker.cpp
Go to the documentation of this file.
1//=============================================================================================================
34
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "stcloadingworker.h"
41
44
45#include <QFile>
46#include <QDebug>
47
48//=============================================================================================================
49// DEFINE MEMBER METHODS
50//=============================================================================================================
51
53 const QString &rhPath,
54 BrainSurface *lhSurface,
55 BrainSurface *rhSurface,
56 double cancelDist,
57 QObject *parent)
58 : QObject(parent)
59 , m_lhPath(lhPath)
60 , m_rhPath(rhPath)
61 , m_lhSurface(lhSurface)
62 , m_rhSurface(rhSurface)
63 , m_cancelDist(cancelDist)
64{
65}
66
67//=============================================================================================================
68
72
73//=============================================================================================================
74
76{
77 emit progress(0, "Loading STC files...");
78
79 // Load LH STC file
80 if (!m_lhPath.isEmpty()) {
81 QFile file(m_lhPath);
83 if (MNELIB::MNESourceEstimate::read(file, stc)) {
84 m_stcLh = stc;
85 m_hasLh = true;
86 qDebug() << "StcLoadingWorker: Loaded LH with" << stc.data.rows() << "vertices,"
87 << stc.data.cols() << "time points";
88 } else {
89 emit error(QString("Failed to read LH STC file: %1").arg(m_lhPath));
90 }
91 }
92
93 emit progress(5, "Loading RH STC file...");
94
95 // Load RH STC file
96 if (!m_rhPath.isEmpty()) {
97 QFile file(m_rhPath);
99 if (MNELIB::MNESourceEstimate::read(file, stc)) {
100 m_stcRh = stc;
101 m_hasRh = true;
102 qDebug() << "StcLoadingWorker: Loaded RH with" << stc.data.rows() << "vertices,"
103 << stc.data.cols() << "time points";
104 } else {
105 emit error(QString("Failed to read RH STC file: %1").arg(m_rhPath));
106 }
107 }
108
109 if (!m_hasLh && !m_hasRh) {
110 emit error("No STC data could be loaded.");
111 emit finished(false);
112 return;
113 }
114
115 // Compute LH interpolation matrix
116 if (m_hasLh && m_lhSurface) {
117 emit progress(10, "Computing LH interpolation matrix...");
118
119 Eigen::MatrixX3f matVertices = m_lhSurface->verticesAsMatrix();
120 std::vector<Eigen::VectorXi> vecNeighbors = m_lhSurface->computeNeighbors();
121
122 Eigen::VectorXi vecSourceVertices = m_stcLh.vertices;
123
124 qDebug() << "StcLoadingWorker: LH surface has" << matVertices.rows() << "vertices,"
125 << vecSourceVertices.size() << "sources";
126
127 if (vecSourceVertices.size() > 0) {
128 // Compute distance table (SCDC - geodesic distance)
129 emit progress(15, "Computing LH geodesic distances (SCDC)...");
130 QSharedPointer<Eigen::MatrixXd> distTable = DISP3DRHILIB::GeometryInfo::scdc(
131 matVertices,
132 vecNeighbors,
133 vecSourceVertices,
134 m_cancelDist
135 );
136
137 if (distTable && distTable->rows() > 0) {
138 emit progress(35, "Creating LH interpolation matrix...");
140 vecSourceVertices,
141 distTable,
143 m_cancelDist
144 );
145
146 if (m_interpMatLh && m_interpMatLh->rows() > 0) {
147 qDebug() << "StcLoadingWorker: LH interpolation matrix created:"
148 << m_interpMatLh->rows() << "x" << m_interpMatLh->cols();
149 }
150 }
151 }
152 }
153
154 // Compute RH interpolation matrix
155 if (m_hasRh && m_rhSurface) {
156 emit progress(50, "Computing RH interpolation matrix...");
157
158 Eigen::MatrixX3f matVertices = m_rhSurface->verticesAsMatrix();
159 std::vector<Eigen::VectorXi> vecNeighbors = m_rhSurface->computeNeighbors();
160
161 Eigen::VectorXi vecSourceVertices = m_stcRh.vertices;
162
163 qDebug() << "StcLoadingWorker: RH surface has" << matVertices.rows() << "vertices,"
164 << vecSourceVertices.size() << "sources";
165
166 if (vecSourceVertices.size() > 0) {
167 // Compute distance table (SCDC - geodesic distance)
168 emit progress(55, "Computing RH geodesic distances (SCDC)...");
169 QSharedPointer<Eigen::MatrixXd> distTable = DISP3DRHILIB::GeometryInfo::scdc(
170 matVertices,
171 vecNeighbors,
172 vecSourceVertices,
173 m_cancelDist
174 );
175
176 if (distTable && distTable->rows() > 0) {
177 emit progress(75, "Creating RH interpolation matrix...");
179 vecSourceVertices,
180 distTable,
182 m_cancelDist
183 );
184
185 if (m_interpMatRh && m_interpMatRh->rows() > 0) {
186 qDebug() << "StcLoadingWorker: RH interpolation matrix created:"
187 << m_interpMatRh->rows() << "x" << m_interpMatRh->cols();
188 }
189 }
190 }
191 }
192
193 emit progress(95, "Finalizing...");
194 emit progress(100, "Complete");
195 emit finished(true);
196}
StcLoadingWorker class declaration.
BrainSurface class declaration.
GeometryInfo class declaration.
Interpolation class declaration.
static QSharedPointer< Eigen::MatrixXd > scdc(const Eigen::MatrixX3f &matVertices, const std::vector< Eigen::VectorXi > &vecNeighborVertices, Eigen::VectorXi &vecVertSubset, double dCancelDist=FLOAT_INFINITY)
scdc Calculates surface constrained distances on a mesh.
static double cubic(const double dIn)
cubic Cubic hyperbola interpolation function.
static QSharedPointer< Eigen::SparseMatrix< float > > createInterpolationMat(const Eigen::VectorXi &vecProjectedSensors, const QSharedPointer< Eigen::MatrixXd > matDistanceTable, double(*interpolationFunction)(double), const double dCancelDist=FLOAT_INFINITY, const Eigen::VectorXi &vecExcludeIndex=Eigen::VectorXi())
createInterpolationMat Calculates the weight matrix for interpolation.
Renderable cortical surface mesh with per-vertex color, curvature data, and GPU buffer management.
void error(const QString &message)
void progress(int percent, const QString &message)
void finished(bool success)
StcLoadingWorker(const QString &lhPath, const QString &rhPath, BrainSurface *lhSurface, BrainSurface *rhSurface, double cancelDist=0.05, QObject *parent=nullptr)
static bool read(QIODevice &p_IODevice, MNESourceEstimate &p_stc)