48 #include <QDataStream>
49 #include <QSharedPointer>
56 using namespace MNELIB;
57 using namespace FSLIB;
58 using namespace Eigen;
74 , vertices(p_vertices)
84 : data(p_SourceEstimate.data)
85 , vertices(p_SourceEstimate.vertices)
86 , times(p_SourceEstimate.times)
87 , tmin(p_SourceEstimate.tmin)
88 , tstep(p_SourceEstimate.tstep)
98 if(!
read(p_IODevice, *
this))
100 printf(
"\tSource estimation not found.\n");
111 times = RowVectorXf();
122 qint32 rows = this->
data.rows();
124 p_sourceEstimateReduced.
data = MatrixXd::Zero(rows,n);
125 p_sourceEstimateReduced.
data = this->
data.block(0, start, rows, n);
127 p_sourceEstimateReduced.
times = RowVectorXf::Zero(n);
128 p_sourceEstimateReduced.
times = this->
times.block(0,start,1,n);
129 p_sourceEstimateReduced.
tmin = p_sourceEstimateReduced.
times(0);
132 return p_sourceEstimateReduced;
139 QSharedPointer<QDataStream> t_pStream(
new QDataStream(&p_IODevice));
141 t_pStream->setFloatingPointPrecision(QDataStream::SinglePrecision);
142 t_pStream->setByteOrder(QDataStream::BigEndian);
143 t_pStream->setVersion(QDataStream::Qt_5_0);
145 if(!t_pStream->device()->open(QIODevice::ReadOnly))
148 QFile* t_pFile = qobject_cast<QFile*>(&p_IODevice);
150 printf(
"Reading source estimate from %s...", t_pFile->fileName().toUtf8().constData());
152 printf(
"Reading source estimate...");
155 *t_pStream >> p_stc.
tmin;
158 *t_pStream >> p_stc.
tstep;
162 *t_pStream >> t_nVertices;
163 p_stc.
vertices = VectorXi(t_nVertices);
165 for(quint32 i = 0; i < t_nVertices; ++i)
169 *t_pStream >> t_nTimePts;
173 p_stc.
data = MatrixXd(t_nVertices, t_nTimePts);
174 for(qint32 i = 0; i < p_stc.
data.array().size(); ++i)
178 p_stc.
data.array()(i) = value;
182 p_stc.update_times();
185 t_pStream->device()->close();
197 QSharedPointer<QDataStream> t_pStream(
new QDataStream(&p_IODevice));
199 t_pStream->setFloatingPointPrecision(QDataStream::SinglePrecision);
200 t_pStream->setByteOrder(QDataStream::BigEndian);
201 t_pStream->setVersion(QDataStream::Qt_5_0);
203 if(!t_pStream->device()->open(QIODevice::WriteOnly))
205 printf(
"Failed to write source estimate!\n");
209 QFile* t_pFile = qobject_cast<QFile*>(&p_IODevice);
211 printf(
"Write source estimate to %s...", t_pFile->fileName().toUtf8().constData());
213 printf(
"Write source estimate...");
216 *t_pStream << (float)1000*this->
tmin;
218 *t_pStream << (float)1000*this->
tstep;
220 *t_pStream << (quint32)this->
vertices.size();
222 for(qint32 i = 0; i < this->
vertices.size(); ++i)
223 *t_pStream << (quint32)this->
vertices[i];
225 *t_pStream << (quint32)this->
data.cols();
229 for(qint32 i = 0; i < this->
data.array().size(); ++i)
230 *t_pStream << (
float)this->
data.array()(i);
233 t_pStream->device()->close();
241 void MNESourceEstimate::update_times()
247 for(
float i = 1; i < this->
times.size(); ++i)
251 this->
times = RowVectorXf();
281 VectorXi vIndexSourceLabels;
283 if(lPickedLabels.isEmpty()) {
284 qWarning() <<
"MNESourceEstimate::getIndicesByLabel - picked label list is empty. Returning.";
285 return vIndexSourceLabels;
289 for(
int i = 0; i < this->
vertices.rows(); i++) {
290 for(
int k = 0;
k < lPickedLabels.size();
k++) {
291 if(this->
vertices(i) == lPickedLabels.at(
k).label_id) {
292 vIndexSourceLabels.conservativeResize(vIndexSourceLabels.rows()+1,1);
293 vIndexSourceLabels(vIndexSourceLabels.rows()-1) = i;
301 for(
int i = 0; i < this->
vertices.rows(); i++) {
309 for(
int k = 0;
k < lPickedLabels.size();
k++) {
310 for(
int l = 0; l < lPickedLabels.at(
k).
vertices.rows(); l++) {
311 if(this->
vertices(i) == lPickedLabels.at(
k).vertices(l) && lPickedLabels.at(
k).hemi == hemi) {
312 vIndexSourceLabels.conservativeResize(vIndexSourceLabels.rows()+1,1);
313 vIndexSourceLabels(vIndexSourceLabels.rows()-1) = i;
321 return vIndexSourceLabels;