62 QMutexLocker locker(&m_mutex);
63 m_sInterpolationFunction = sInterpolationFunction;
70 QMutexLocker locker(&m_mutex);
71 m_dCancelDist = dCancelDist;
77 const Eigen::MatrixX3f &matVertices,
78 const std::vector<Eigen::VectorXi> &vecNeighborVertices,
79 const Eigen::VectorXi &vecSourceVertices)
81 QMutexLocker locker(&m_mutex);
82 m_matVerticesLh = matVertices;
83 m_vecNeighborsLh = vecNeighborVertices;
84 m_vecSourceVerticesLh = vecSourceVertices;
85 m_hasLh = (!matVertices.isZero(0) && matVertices.rows() > 0 && vecSourceVertices.size() > 0);
91 const Eigen::MatrixX3f &matVertices,
92 const std::vector<Eigen::VectorXi> &vecNeighborVertices,
93 const Eigen::VectorXi &vecSourceVertices)
95 QMutexLocker locker(&m_mutex);
96 m_matVerticesRh = matVertices;
97 m_vecNeighborsRh = vecNeighborVertices;
98 m_vecSourceVerticesRh = vecSourceVertices;
99 m_hasRh = (!matVertices.isZero(0) && matVertices.rows() > 0 && vecSourceVertices.size() > 0);
106 QMutexLocker locker(&m_mutex);
107 m_iVisualizationType = iVisType;
113 const QList<FSLIB::Label> &lLabels,
114 const Eigen::VectorXi &vecVertNo)
116 if (vecLabelIds.rows() == 0 || lLabels.isEmpty()) {
117 qDebug() <<
"RtSourceInterpolationMatWorker::setAnnotationInfoLeft - Annotation data is empty.";
121 QMutexLocker locker(&m_mutex);
122 m_lLabelsLh = lLabels;
123 m_mapLabelIdSourcesLh.clear();
126 for (qint32 i = 0; i < vecVertNo.rows(); ++i) {
127 m_mapLabelIdSourcesLh.insert(vecVertNo(i), vecLabelIds(vecVertNo(i)));
128 m_vertNosLh.append(vecVertNo(i));
131 m_bAnnotationLhInit =
true;
137 const QList<FSLIB::Label> &lLabels,
138 const Eigen::VectorXi &vecVertNo)
140 if (vecLabelIds.rows() == 0 || lLabels.isEmpty()) {
141 qDebug() <<
"RtSourceInterpolationMatWorker::setAnnotationInfoRight - Annotation data is empty.";
145 QMutexLocker locker(&m_mutex);
146 m_lLabelsRh = lLabels;
147 m_mapLabelIdSourcesRh.clear();
150 for (qint32 i = 0; i < vecVertNo.rows(); ++i) {
151 m_mapLabelIdSourcesRh.insert(vecVertNo(i), vecLabelIds(vecVertNo(i)));
152 m_vertNosRh.append(vecVertNo(i));
155 m_bAnnotationRhInit =
true;
160double (*RtSourceInterpolationMatWorker::resolveInterpolationFunction(
const QString &name))(double)
173QSharedPointer<Eigen::SparseMatrix<float>> RtSourceInterpolationMatWorker::computeHemi(
174 const Eigen::MatrixX3f &matVertices,
175 const std::vector<Eigen::VectorXi> &vecNeighborVertices,
176 Eigen::VectorXi vecSourceVertices,
178 double (*interpFunc)(
double))
180 if (matVertices.rows() == 0 || vecSourceVertices.size() == 0) {
181 return QSharedPointer<Eigen::SparseMatrix<float>>();
192 if (!distTable || distTable->rows() == 0) {
193 qWarning() <<
"RtSourceInterpolationMatWorker: SCDC computation failed.";
194 return QSharedPointer<Eigen::SparseMatrix<float>>();
213 Eigen::MatrixX3f vertsLh, vertsRh;
214 std::vector<Eigen::VectorXi> neighborsLh, neighborsRh;
215 Eigen::VectorXi srcVertsLh, srcVertsRh;
218 QString interpFuncName;
222 QList<FSLIB::Label> labelsLh, labelsRh;
223 QMap<qint32, qint32> mapLabelIdSrcLh, mapLabelIdSrcRh;
224 QList<int> vertNosLh, vertNosRh;
225 bool annotLhInit, annotRhInit;
228 QMutexLocker locker(&m_mutex);
229 vertsLh = m_matVerticesLh;
230 vertsRh = m_matVerticesRh;
231 neighborsLh = m_vecNeighborsLh;
232 neighborsRh = m_vecNeighborsRh;
233 srcVertsLh = m_vecSourceVerticesLh;
234 srcVertsRh = m_vecSourceVerticesRh;
237 cancelDist = m_dCancelDist;
238 interpFuncName = m_sInterpolationFunction;
239 visType = m_iVisualizationType;
241 labelsLh = m_lLabelsLh;
242 labelsRh = m_lLabelsRh;
243 mapLabelIdSrcLh = m_mapLabelIdSourcesLh;
244 mapLabelIdSrcRh = m_mapLabelIdSourcesRh;
245 vertNosLh = m_vertNosLh;
246 vertNosRh = m_vertNosRh;
247 annotLhInit = m_bAnnotationLhInit;
248 annotRhInit = m_bAnnotationRhInit;
253 qDebug() <<
"RtSourceInterpolationMatWorker: Computing annotation matrices...";
256 auto mat = computeAnnotationOperator(labelsLh, mapLabelIdSrcLh, vertNosLh);
257 if (mat && mat->rows() > 0) {
258 qDebug() <<
"RtSourceInterpolationMatWorker: LH annotation matrix:"
259 << mat->rows() <<
"x" << mat->cols();
265 auto mat = computeAnnotationOperator(labelsRh, mapLabelIdSrcRh, vertNosRh);
266 if (mat && mat->rows() > 0) {
267 qDebug() <<
"RtSourceInterpolationMatWorker: RH annotation matrix:"
268 << mat->rows() <<
"x" << mat->cols();
273 qDebug() <<
"RtSourceInterpolationMatWorker: Annotation matrix computation complete.";
278 if (!hasLh && !hasRh) {
279 qDebug() <<
"RtSourceInterpolationMatWorker: No hemisphere data set, skipping.";
283 auto interpFunc = resolveInterpolationFunction(interpFuncName);
285 qDebug() <<
"RtSourceInterpolationMatWorker: Computing interpolation matrices"
286 <<
"(cancelDist=" << cancelDist <<
", func=" << interpFuncName <<
")...";
290 qDebug() <<
"RtSourceInterpolationMatWorker: Computing LH matrix ("
291 << vertsLh.rows() <<
"verts," << srcVertsLh.size() <<
"sources)...";
293 auto mat = computeHemi(vertsLh, neighborsLh, srcVertsLh, cancelDist, interpFunc);
295 if (mat && mat->rows() > 0) {
296 qDebug() <<
"RtSourceInterpolationMatWorker: LH matrix computed:"
297 << mat->rows() <<
"x" << mat->cols();
300 qWarning() <<
"RtSourceInterpolationMatWorker: LH interpolation matrix computation failed.";
306 qDebug() <<
"RtSourceInterpolationMatWorker: Computing RH matrix ("
307 << vertsRh.rows() <<
"verts," << srcVertsRh.size() <<
"sources)...";
309 auto mat = computeHemi(vertsRh, neighborsRh, srcVertsRh, cancelDist, interpFunc);
311 if (mat && mat->rows() > 0) {
312 qDebug() <<
"RtSourceInterpolationMatWorker: RH matrix computed:"
313 << mat->rows() <<
"x" << mat->cols();
316 qWarning() <<
"RtSourceInterpolationMatWorker: RH interpolation matrix computation failed.";
320 qDebug() <<
"RtSourceInterpolationMatWorker: Interpolation matrix computation complete.";
325QSharedPointer<Eigen::SparseMatrix<float>> RtSourceInterpolationMatWorker::computeAnnotationOperator(
326 const QList<FSLIB::Label> &lLabels,
327 const QMap<qint32, qint32> &mapLabelIdSrc,
328 const QList<int> &vertNos)
330 if (lLabels.isEmpty() || vertNos.isEmpty()) {
331 return QSharedPointer<Eigen::SparseMatrix<float>>();
336 for (
int i = 0; i < lLabels.size(); ++i) {
337 iNumVert += lLabels.at(i).vertices.rows();
340 auto mat = QSharedPointer<Eigen::SparseMatrix<float>>(
341 new Eigen::SparseMatrix<float>(iNumVert, vertNos.size()));
344 for (
int i = 0; i < lLabels.size(); ++i) {
345 const FSLIB::Label &label = lLabels.at(i);
346 QList<qint32> listSourcesVertNoLabel = mapLabelIdSrc.keys(label.
label_id);
348 for (
int j = 0; j < label.
vertices.rows(); ++j) {
349 for (
int k = 0; k < listSourcesVertNoLabel.size(); ++k) {
350 int colIdx = vertNos.indexOf(listSourcesVertNoLabel.at(k));
351 if (colIdx >= 0 && label.
vertices(j) < iNumVert) {
352 mat->coeffRef(label.
vertices(j), colIdx) = 1.0f / listSourcesVertNoLabel.size();
RtSourceInterpolationMatWorker class declaration.
GeometryInfo class declaration.
Interpolation class declaration.
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 setAnnotationInfoLeft(const Eigen::VectorXi &vecLabelIds, const QList< FSLIB::Label > &lLabels, const Eigen::VectorXi &vecVertNo)
void newInterpolationMatrixRightAvailable(QSharedPointer< Eigen::SparseMatrix< float > > interpMat)
void setInterpolationInfoLeft(const Eigen::MatrixX3f &matVertices, const std::vector< Eigen::VectorXi > &vecNeighborVertices, const Eigen::VectorXi &vecSourceVertices)
void newInterpolationMatrixLeftAvailable(QSharedPointer< Eigen::SparseMatrix< float > > interpMat)
void setAnnotationInfoRight(const Eigen::VectorXi &vecLabelIds, const QList< FSLIB::Label > &lLabels, const Eigen::VectorXi &vecVertNo)
void setCancelDistance(double dCancelDist)
RtSourceInterpolationMatWorker(QObject *parent=nullptr)
void setInterpolationInfoRight(const Eigen::MatrixX3f &matVertices, const std::vector< Eigen::VectorXi > &vecNeighborVertices, const Eigen::VectorXi &vecSourceVertices)
void setVisualizationType(int iVisType)