40 QMutexLocker locker(&m_mutex);
41 m_sInterpolationFunction = sInterpolationFunction;
48 QMutexLocker locker(&m_mutex);
49 m_dCancelDist = dCancelDist;
55 const Eigen::MatrixX3f &matVertices,
56 const std::vector<Eigen::VectorXi> &vecNeighborVertices,
57 const Eigen::VectorXi &vecSourceVertices)
59 QMutexLocker locker(&m_mutex);
60 m_matVerticesLh = matVertices;
61 m_vecNeighborsLh = vecNeighborVertices;
62 m_vecSourceVerticesLh = vecSourceVertices;
63 m_hasLh = (!matVertices.isZero(0) && matVertices.rows() > 0 && vecSourceVertices.size() > 0);
69 const Eigen::MatrixX3f &matVertices,
70 const std::vector<Eigen::VectorXi> &vecNeighborVertices,
71 const Eigen::VectorXi &vecSourceVertices)
73 QMutexLocker locker(&m_mutex);
74 m_matVerticesRh = matVertices;
75 m_vecNeighborsRh = vecNeighborVertices;
76 m_vecSourceVerticesRh = vecSourceVertices;
77 m_hasRh = (!matVertices.isZero(0) && matVertices.rows() > 0 && vecSourceVertices.size() > 0);
84 QMutexLocker locker(&m_mutex);
85 m_iVisualizationType = iVisType;
91 const QList<FSLIB::FsLabel> &lLabels,
92 const Eigen::VectorXi &vecVertNo)
94 if (vecLabelIds.rows() == 0 || lLabels.isEmpty()) {
95 qDebug() <<
"RtSourceInterpolationMatWorker::setAnnotationInfoLeft - FsAnnotation data is empty.";
99 QMutexLocker locker(&m_mutex);
100 m_lLabelsLh = lLabels;
101 m_mapLabelIdSourcesLh.clear();
104 for (qint32 i = 0; i < vecVertNo.rows(); ++i) {
105 m_mapLabelIdSourcesLh.insert(vecVertNo(i), vecLabelIds(vecVertNo(i)));
106 m_vertNosLh.append(vecVertNo(i));
109 m_bAnnotationLhInit =
true;
115 const QList<FSLIB::FsLabel> &lLabels,
116 const Eigen::VectorXi &vecVertNo)
118 if (vecLabelIds.rows() == 0 || lLabels.isEmpty()) {
119 qDebug() <<
"RtSourceInterpolationMatWorker::setAnnotationInfoRight - FsAnnotation data is empty.";
123 QMutexLocker locker(&m_mutex);
124 m_lLabelsRh = lLabels;
125 m_mapLabelIdSourcesRh.clear();
128 for (qint32 i = 0; i < vecVertNo.rows(); ++i) {
129 m_mapLabelIdSourcesRh.insert(vecVertNo(i), vecLabelIds(vecVertNo(i)));
130 m_vertNosRh.append(vecVertNo(i));
133 m_bAnnotationRhInit =
true;
138double (*RtSourceInterpolationMatWorker::resolveInterpolationFunction(
const QString &name))(double)
151QSharedPointer<Eigen::SparseMatrix<float>> RtSourceInterpolationMatWorker::computeHemi(
152 const Eigen::MatrixX3f &matVertices,
153 const std::vector<Eigen::VectorXi> &vecNeighborVertices,
154 Eigen::VectorXi vecSourceVertices,
156 double (*interpFunc)(
double))
158 if (matVertices.rows() == 0 || vecSourceVertices.size() == 0) {
159 return QSharedPointer<Eigen::SparseMatrix<float>>();
170 if (!distTable || distTable->rows() == 0) {
171 qWarning() <<
"RtSourceInterpolationMatWorker: SCDC computation failed.";
172 return QSharedPointer<Eigen::SparseMatrix<float>>();
191 Eigen::MatrixX3f vertsLh, vertsRh;
192 std::vector<Eigen::VectorXi> neighborsLh, neighborsRh;
193 Eigen::VectorXi srcVertsLh, srcVertsRh;
196 QString interpFuncName;
200 QList<FSLIB::FsLabel> labelsLh, labelsRh;
201 QMap<qint32, qint32> mapLabelIdSrcLh, mapLabelIdSrcRh;
202 QList<int> vertNosLh, vertNosRh;
203 bool annotLhInit, annotRhInit;
206 QMutexLocker locker(&m_mutex);
207 vertsLh = m_matVerticesLh;
208 vertsRh = m_matVerticesRh;
209 neighborsLh = m_vecNeighborsLh;
210 neighborsRh = m_vecNeighborsRh;
211 srcVertsLh = m_vecSourceVerticesLh;
212 srcVertsRh = m_vecSourceVerticesRh;
215 cancelDist = m_dCancelDist;
216 interpFuncName = m_sInterpolationFunction;
217 visType = m_iVisualizationType;
219 labelsLh = m_lLabelsLh;
220 labelsRh = m_lLabelsRh;
221 mapLabelIdSrcLh = m_mapLabelIdSourcesLh;
222 mapLabelIdSrcRh = m_mapLabelIdSourcesRh;
223 vertNosLh = m_vertNosLh;
224 vertNosRh = m_vertNosRh;
225 annotLhInit = m_bAnnotationLhInit;
226 annotRhInit = m_bAnnotationRhInit;
231 qDebug() <<
"RtSourceInterpolationMatWorker: Computing annotation matrices...";
234 auto mat = computeAnnotationOperator(labelsLh, mapLabelIdSrcLh, vertNosLh);
235 if (mat && mat->rows() > 0) {
236 qDebug() <<
"RtSourceInterpolationMatWorker: LH annotation matrix:"
237 << mat->rows() <<
"x" << mat->cols();
243 auto mat = computeAnnotationOperator(labelsRh, mapLabelIdSrcRh, vertNosRh);
244 if (mat && mat->rows() > 0) {
245 qDebug() <<
"RtSourceInterpolationMatWorker: RH annotation matrix:"
246 << mat->rows() <<
"x" << mat->cols();
251 qDebug() <<
"RtSourceInterpolationMatWorker: FsAnnotation matrix computation complete.";
256 if (!hasLh && !hasRh) {
257 qDebug() <<
"RtSourceInterpolationMatWorker: No hemisphere data set, skipping.";
261 auto interpFunc = resolveInterpolationFunction(interpFuncName);
263 qDebug() <<
"RtSourceInterpolationMatWorker: Computing interpolation matrices"
264 <<
"(cancelDist=" << cancelDist <<
", func=" << interpFuncName <<
")...";
268 qDebug() <<
"RtSourceInterpolationMatWorker: Computing LH matrix ("
269 << vertsLh.rows() <<
"verts," << srcVertsLh.size() <<
"sources)...";
271 auto mat = computeHemi(vertsLh, neighborsLh, srcVertsLh, cancelDist, interpFunc);
273 if (mat && mat->rows() > 0) {
274 qDebug() <<
"RtSourceInterpolationMatWorker: LH matrix computed:"
275 << mat->rows() <<
"x" << mat->cols();
278 qWarning() <<
"RtSourceInterpolationMatWorker: LH interpolation matrix computation failed.";
284 qDebug() <<
"RtSourceInterpolationMatWorker: Computing RH matrix ("
285 << vertsRh.rows() <<
"verts," << srcVertsRh.size() <<
"sources)...";
287 auto mat = computeHemi(vertsRh, neighborsRh, srcVertsRh, cancelDist, interpFunc);
289 if (mat && mat->rows() > 0) {
290 qDebug() <<
"RtSourceInterpolationMatWorker: RH matrix computed:"
291 << mat->rows() <<
"x" << mat->cols();
294 qWarning() <<
"RtSourceInterpolationMatWorker: RH interpolation matrix computation failed.";
298 qDebug() <<
"RtSourceInterpolationMatWorker: Interpolation matrix computation complete.";
303QSharedPointer<Eigen::SparseMatrix<float>> RtSourceInterpolationMatWorker::computeAnnotationOperator(
304 const QList<FSLIB::FsLabel> &lLabels,
305 const QMap<qint32, qint32> &mapLabelIdSrc,
306 const QList<int> &vertNos)
308 if (lLabels.isEmpty() || vertNos.isEmpty()) {
309 return QSharedPointer<Eigen::SparseMatrix<float>>();
314 for (
int i = 0; i < lLabels.size(); ++i) {
315 iNumVert += lLabels.at(i).vertices.rows();
318 auto mat = QSharedPointer<Eigen::SparseMatrix<float>>(
319 new Eigen::SparseMatrix<float>(iNumVert, vertNos.size()));
322 for (
int i = 0; i < lLabels.size(); ++i) {
323 const FSLIB::FsLabel &label = lLabels.at(i);
324 QList<qint32> listSourcesVertNoLabel = mapLabelIdSrc.keys(label.
label_id);
326 for (
int j = 0; j < label.
vertices.rows(); ++j) {
327 for (
int k = 0; k < listSourcesVertNoLabel.size(); ++k) {
328 int colIdx = vertNos.indexOf(listSourcesVertNoLabel.at(k));
329 if (colIdx >= 0 && label.
vertices(j) < iNumVert) {
330 mat->coeffRef(label.
vertices(j), colIdx) = 1.0f / listSourcesVertNoLabel.size();
Background worker that builds the sparse source-to-vertex interpolation matrix for one hemisphere.
Distance-based sparse interpolation weights and per-frame signal smoothing on triangulated meshes.
Surface-constrained geodesic distance and sensor-to-mesh projection helpers.
Reader and in-memory representation of a FreeSurfer/MNE surface label (.label).
3-D brain visualisation using the Qt RHI rendering backend.
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 gaussian(const double dIn)
gaussian Gaussian interpolation function (sigma=1).
static double linear(const double dIn)
linear Identity interpolation function.
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.
static double square(const double dIn)
square Negative parabola interpolation function with y-offset of 1.
void setInterpolationFunction(const QString &sInterpolationFunction)
void computeInterpolationMatrix()
void setInterpolationInfoLeft(const Eigen::MatrixX3f &matVertices, const std::vector< Eigen::VectorXi > &vecNeighborVertices, const Eigen::VectorXi &vecSourceVertices)
void setCancelDistance(double dCancelDist)
void setAnnotationInfoLeft(const Eigen::VectorXi &vecLabelIds, const QList< FSLIB::FsLabel > &lLabels, const Eigen::VectorXi &vecVertNo)
RtSourceInterpolationMatWorker(QObject *parent=nullptr)
void newInterpolationMatrixRightAvailable(QSharedPointer< Eigen::SparseMatrix< float > > interpMat)
void setInterpolationInfoRight(const Eigen::MatrixX3f &matVertices, const std::vector< Eigen::VectorXi > &vecNeighborVertices, const Eigen::VectorXi &vecSourceVertices)
void newInterpolationMatrixLeftAvailable(QSharedPointer< Eigen::SparseMatrix< float > > interpMat)
void setVisualizationType(int iVisType)
void setAnnotationInfoRight(const Eigen::VectorXi &vecLabelIds, const QList< FSLIB::FsLabel > &lLabels, const Eigen::VectorXi &vecVertNo)