154 QSharedPointer<QDataStream> t_pStream(
new QDataStream(&p_IODevice));
156 t_pStream->setFloatingPointPrecision(QDataStream::SinglePrecision);
157 t_pStream->setByteOrder(QDataStream::BigEndian);
158 t_pStream->setVersion(QDataStream::Qt_5_0);
160 if(!t_pStream->device()->open(QIODevice::ReadOnly))
163 QFile* t_pFile = qobject_cast<QFile*>(&p_IODevice);
165 qInfo(
"Reading source estimate from %s...", t_pFile->fileName().toUtf8().constData());
167 qInfo(
"Reading source estimate...");
170 *t_pStream >> p_stc.
tmin;
173 *t_pStream >> p_stc.
tstep;
177 *t_pStream >> t_nVertices;
178 p_stc.
vertices = VectorXi(t_nVertices);
180 for(quint32 i = 0; i < t_nVertices; ++i)
184 *t_pStream >> t_nTimePts;
188 p_stc.
data = MatrixXd(t_nVertices, t_nTimePts);
189 for(qint32 i = 0; i < p_stc.
data.array().size(); ++i)
193 p_stc.
data.array()(i) = value;
197 p_stc.update_times();
200 t_pStream->device()->close();
212 QSharedPointer<QDataStream> t_pStream(
new QDataStream(&p_IODevice));
214 t_pStream->setFloatingPointPrecision(QDataStream::SinglePrecision);
215 t_pStream->setByteOrder(QDataStream::BigEndian);
216 t_pStream->setVersion(QDataStream::Qt_5_0);
218 if(!t_pStream->device()->open(QIODevice::WriteOnly))
220 qWarning(
"Failed to write source estimate!");
224 QFile* t_pFile = qobject_cast<QFile*>(&p_IODevice);
226 qInfo(
"Write source estimate to %s...", t_pFile->fileName().toUtf8().constData());
228 qInfo(
"Write source estimate...");
231 *t_pStream << static_cast<float>(1000*this->
tmin);
233 *t_pStream << static_cast<float>(1000*this->
tstep);
235 *t_pStream << static_cast<quint32>(this->
vertices.size());
237 for(qint32 i = 0; i < this->
vertices.size(); ++i)
238 *t_pStream <<
static_cast<quint32
>(this->
vertices[i]);
240 *t_pStream << static_cast<quint32>(this->
data.cols());
244 for(qint32 i = 0; i < this->
data.array().size(); ++i)
245 *t_pStream <<
static_cast<float>(this->
data.array()(i));
248 t_pStream->device()->close();
259 if (!file.open(QIODevice::ReadOnly)) {
260 qWarning(
"InvSourceEstimate::read_w - Cannot open file %s", path.toUtf8().constData());
264 QDataStream stream(&file);
265 stream.setByteOrder(QDataStream::BigEndian);
266 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
274 stream >> b0 >> b1 >> b2;
275 qint32 nVertices = (
static_cast<qint32
>(b0) << 16)
276 | (
static_cast<qint32
>(b1) << 8)
277 |
static_cast<qint32
>(b2);
280 MatrixXd
data(nVertices, 1);
282 for (qint32 i = 0; i < nVertices; ++i) {
284 stream >> b0 >> b1 >> b2;
285 vertices[i] = (
static_cast<qint32
>(b0) << 16)
286 | (
static_cast<qint32
>(b1) << 8)
287 |
static_cast<qint32
>(b2);
292 data(i, 0) =
static_cast<double>(val);
306 qWarning(
"InvSourceEstimate::write_w - Source estimate is empty");
311 if (!file.open(QIODevice::WriteOnly)) {
312 qWarning(
"InvSourceEstimate::write_w - Cannot open file %s for writing", path.toUtf8().constData());
316 QDataStream stream(&file);
317 stream.setByteOrder(QDataStream::BigEndian);
318 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
321 stream << static_cast<quint8>(0) <<
static_cast<quint8
>(0);
324 qint32 nVertices =
static_cast<qint32
>(
vertices.size());
325 stream << static_cast<quint8>((nVertices >> 16) & 0xFF)
326 <<
static_cast<quint8
>((nVertices >> 8) & 0xFF)
327 <<
static_cast<quint8
>(nVertices & 0xFF);
330 for (qint32 i = 0; i < nVertices; ++i) {
332 stream << static_cast<quint8>((idx >> 16) & 0xFF)
333 <<
static_cast<quint8
>((idx >> 8) & 0xFF)
334 <<
static_cast<quint8
>(idx & 0xFF);
336 stream << static_cast<float>(
data(i, 0));
391 VectorXi vIndexSourceLabels;
393 if(lPickedLabels.isEmpty()) {
394 qWarning() <<
"InvSourceEstimate::getIndicesByLabel - picked label list is empty. Returning.";
395 return vIndexSourceLabels;
399 for(
int i = 0; i < this->
vertices.rows(); i++) {
400 for(
int k = 0; k < lPickedLabels.size(); k++) {
401 if(this->
vertices(i) == lPickedLabels.at(k).label_id) {
402 vIndexSourceLabels.conservativeResize(vIndexSourceLabels.rows()+1,1);
403 vIndexSourceLabels(vIndexSourceLabels.rows()-1) = i;
411 for(
int i = 0; i < this->
vertices.rows(); i++) {
419 for(
int k = 0; k < lPickedLabels.size(); k++) {
420 for(
int l = 0; l < lPickedLabels.at(k).
vertices.rows(); l++) {
421 if(this->
vertices(i) == lPickedLabels.at(k).vertices(l) && lPickedLabels.at(k).hemi == hemi) {
422 vIndexSourceLabels.conservativeResize(vIndexSourceLabels.rows()+1,1);
423 vIndexSourceLabels(vIndexSourceLabels.rows()-1) = i;
431 return vIndexSourceLabels;