MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
rtsourceinterpolationmatworker.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
41
42#include "../../../../helpers/geometryinfo/geometryinfo.h"
43#include "../../../../helpers/interpolation/interpolation.h"
44#include "../../items/common/types.h"
45
46//=============================================================================================================
47// QT INCLUDES
48//=============================================================================================================
49
50//=============================================================================================================
51// EIGEN INCLUDES
52//=============================================================================================================
53
54//=============================================================================================================
55// USED NAMESPACES
56//=============================================================================================================
57
58using namespace DISP3DLIB;
59using namespace MNELIB;
60using namespace Eigen;
61using namespace FSLIB;
62
63//=============================================================================================================
64// DEFINE MEMBER METHODS
65//=============================================================================================================
66
68: m_bInterpolationInfoIsInit(false)
69, m_iVisualizationType(Data3DTreeModelItemRoles::InterpolationBased)
70, m_bAnnotationInfoIsInit(false)
71, m_pMatInterpolationMat(QSharedPointer<SparseMatrix<float> >(new SparseMatrix<float>()))
72, m_pMatAnnotationMat(QSharedPointer<SparseMatrix<float> >(new SparseMatrix<float>()))
73{
76 m_lInterpolationData.matDistanceMatrix = QSharedPointer<MatrixXd>(new MatrixXd());
77}
78
79//=============================================================================================================
80
81void RtSourceInterpolationMatWorker::setInterpolationFunction(const QString &sInterpolationFunction)
82{
83 //Only supported in interpolation mode
84 if(m_iVisualizationType != Data3DTreeModelItemRoles::InterpolationBased) {
85 return;
86 }
87
88 if(sInterpolationFunction == QStringLiteral("Linear")) {
90 }
91 else if(sInterpolationFunction == QStringLiteral("Square")) {
93 }
94 else if(sInterpolationFunction == QStringLiteral("Cubic")) {
96 }
97 else if(sInterpolationFunction == QStringLiteral("Gaussian")) {
99 }
100
101 if(m_bInterpolationInfoIsInit == true){
102 //recalculate Interpolation matrix parameters changed
107
108 emitMatrix();
109 }
110}
111
112//=============================================================================================================
113
115{
116 if(m_iVisualizationType != iVisType) {
117 m_iVisualizationType = iVisType;
118
119 emitMatrix();
120 }
121}
122
123//=============================================================================================================
124
126{
127 //Only supported in interpolation mode
128 if(m_iVisualizationType != Data3DTreeModelItemRoles::InterpolationBased) {
129 return;
130 }
131
133
134 //recalculate everything because parameters changed
136
137 emitMatrix();
138}
139
140//=============================================================================================================
141
142void RtSourceInterpolationMatWorker::setInterpolationInfo(const Eigen::MatrixX3f &matVertices,
143 const QVector<QVector<int> > &vecNeighborVertices,
144 const QVector<int> &vecMappedSubset)
145{
146 if(matVertices.rows() == 0) {
147 qDebug() << "RtSourceInterpolationMatWorker::setInterpolationInfo - Surface data is empty. Returning ...";
148 return;
149 }
150
151 //set members
152 m_lInterpolationData.matVertices = matVertices;
153 m_lInterpolationData.vecNeighborVertices = vecNeighborVertices;
154 m_lInterpolationData.vecMappedSubset = vecMappedSubset;
155
157
159
160 if(m_iVisualizationType == Data3DTreeModelItemRoles::InterpolationBased) {
162 }
163}
164
165//=============================================================================================================
166
167void RtSourceInterpolationMatWorker::setAnnotationInfo(const Eigen::VectorXi &vecLabelIds,
168 const QList<FSLIB::Label> &lLabels,
169 const Eigen::VectorXi &vecVertNo)
170{
171 if(vecLabelIds.rows() == 0 || lLabels.isEmpty()) {
172 qDebug() << "RtSourceInterpolationMatWorker::setAnnotationInfo - Annotation data is empty. Returning ...";
173 return;
174 }
175
178
179 //Generate fast lookup map for each source and corresponding label
180 for(qint32 i = 0; i < vecVertNo.rows(); ++i) {
181 m_lInterpolationData.mapLabelIdSources.insert(vecVertNo(i), vecLabelIds(vecVertNo(i)));
182 m_lInterpolationData.vertNos.append(vecVertNo(i));
183 }
184
186
188
189 if(m_iVisualizationType == Data3DTreeModelItemRoles::AnnotationBased) {
191 }
192}
193
194//=============================================================================================================
195
215
216//=============================================================================================================
217
219{
221 qDebug() << "RtSourceInterpolationMatWorker::calculateAnnotationOperator - Set annotation info first.";
222 return;
223 }
224
225 int iNumVert = 0;
226 for(int i = 0; i < m_lInterpolationData.lLabels.size(); ++i) {
227 iNumVert += m_lInterpolationData.lLabels.at(i).vertices.rows();
228 }
229
230 m_pMatAnnotationMat = QSharedPointer<Eigen::SparseMatrix<float> >(new Eigen::SparseMatrix<float>(iNumVert, m_lInterpolationData.vecMappedSubset.size()));
231
232 //Color all labels respectivley to their activation
233 for(int i = 0; i < m_lInterpolationData.lLabels.size(); ++i) {
235 QList<qint32> listSourcesVertNoLabel = m_lInterpolationData.mapLabelIdSources.keys(label.label_id);
236
237 for(int j = 0; j < label.vertices.rows(); ++j) {
238 for(int k = 0; k < listSourcesVertNoLabel.size(); ++k) {
239 int colIdx = m_lInterpolationData.vertNos.indexOf(listSourcesVertNoLabel.at(k));
240 m_pMatAnnotationMat->coeffRef(label.vertices(j),colIdx) = 1.0f/listSourcesVertNoLabel.size();
241 }
242 }
243 }
244}
245
246//=============================================================================================================
247
249{
250 switch (m_iVisualizationType) {
251 case Data3DTreeModelItemRoles::InterpolationBased:
253 return;
254 }
255
256 if(m_pMatInterpolationMat->size() == 0) {
258 }
259
261 break;
262
263 case Data3DTreeModelItemRoles::AnnotationBased:
265 return;
266 }
267
268 if(m_pMatAnnotationMat->size() == 0) {
269 qDebug() << "RtSourceInterpolationMatWorker::setVisualizationType size == 0 Calculating";
271 }
272
274 break;
275 }
276}
int k
Definition fiff_tag.cpp:324
RtSourceInterpolationMatWorker class declaration.
void setInterpolationFunction(const QString &sInterpolationFunction)
void setAnnotationInfo(const Eigen::VectorXi &vecLabelIds, const QList< FSLIB::Label > &lLabels, const Eigen::VectorXi &vecVertNo)
void newInterpolationMatrixCalculated(QSharedPointer< Eigen::SparseMatrix< float > > pMatInterpolationMatrix)
QSharedPointer< Eigen::SparseMatrix< float > > m_pMatAnnotationMat
void setInterpolationInfo(const Eigen::MatrixX3f &matVertices, const QVector< QVector< int > > &vecNeighborVertices, const QVector< int > &vecMappedSubset)
QSharedPointer< Eigen::SparseMatrix< float > > m_pMatInterpolationMat
struct DISP3DLIB::RtSourceInterpolationMatWorker::InterpolationData m_lInterpolationData
static QSharedPointer< Eigen::MatrixXd > scdc(const Eigen::MatrixX3f &matVertices, const QVector< QVector< int > > &vecNeighborVertices, QVector< int > &pVecVertSubset, double dCancelDist=FLOAT_INFINITY)
scdc Calculates surface constrained distances on a mesh.
static QSharedPointer< Eigen::SparseMatrix< float > > createInterpolationMat(const QVector< int > &vecProjectedSensors, const QSharedPointer< Eigen::MatrixXd > matDistanceTable, double(*interpolationFunction)(double), const double dCancelDist=FLOAT_INFINITY, const QVector< int > &vecExcludeIndex=QVector< int >())
static double gaussian(const double dIn)
static double linear(const double dIn)
static double cubic(const double dIn)
static double square(const double dIn)
Freesurfer/MNE label.
Definition label.h:81
qint32 label_id
Definition label.h:172
Eigen::VectorXi vertices
Definition label.h:166