170 QSharedPointer<QDataStream> t_pStream(
new QDataStream(&p_IODevice));
172 t_pStream->setFloatingPointPrecision(QDataStream::SinglePrecision);
173 t_pStream->setByteOrder(QDataStream::BigEndian);
174 t_pStream->setVersion(QDataStream::Qt_5_0);
176 if(!t_pStream->device()->open(QIODevice::ReadOnly))
179 QFile* t_pFile = qobject_cast<QFile*>(&p_IODevice);
181 qInfo(
"Reading source estimate from %s...", t_pFile->fileName().toUtf8().constData());
183 qInfo(
"Reading source estimate...");
186 *t_pStream >> p_stc.
tmin;
189 *t_pStream >> p_stc.
tstep;
193 *t_pStream >> t_nVertices;
194 p_stc.
vertices = VectorXi(t_nVertices);
196 for(quint32 i = 0; i < t_nVertices; ++i)
200 *t_pStream >> t_nTimePts;
204 p_stc.
data = MatrixXd(t_nVertices, t_nTimePts);
205 for(qint32 i = 0; i < p_stc.
data.array().size(); ++i)
209 p_stc.
data.array()(i) = value;
213 p_stc.update_times();
216 t_pStream->device()->close();
228 QSharedPointer<QDataStream> t_pStream(
new QDataStream(&p_IODevice));
230 t_pStream->setFloatingPointPrecision(QDataStream::SinglePrecision);
231 t_pStream->setByteOrder(QDataStream::BigEndian);
232 t_pStream->setVersion(QDataStream::Qt_5_0);
234 if(!t_pStream->device()->open(QIODevice::WriteOnly))
236 qWarning(
"Failed to write source estimate!");
240 QFile* t_pFile = qobject_cast<QFile*>(&p_IODevice);
242 qInfo(
"Write source estimate to %s...", t_pFile->fileName().toUtf8().constData());
244 qInfo(
"Write source estimate...");
247 *t_pStream << static_cast<float>(1000*this->
tmin);
249 *t_pStream << static_cast<float>(1000*this->
tstep);
251 *t_pStream << static_cast<quint32>(this->
vertices.size());
253 for(qint32 i = 0; i < this->
vertices.size(); ++i)
254 *t_pStream <<
static_cast<quint32
>(this->
vertices[i]);
256 *t_pStream << static_cast<quint32>(this->
data.cols());
260 for(qint32 i = 0; i < this->
data.array().size(); ++i)
261 *t_pStream <<
static_cast<float>(this->
data.array()(i));
264 t_pStream->device()->close();
275 if (!file.open(QIODevice::ReadOnly)) {
276 qWarning(
"InvSourceEstimate::read_w - Cannot open file %s", path.toUtf8().constData());
280 QDataStream stream(&file);
281 stream.setByteOrder(QDataStream::BigEndian);
282 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
290 stream >> b0 >> b1 >> b2;
291 qint32 nVertices = (
static_cast<qint32
>(b0) << 16)
292 | (
static_cast<qint32
>(b1) << 8)
293 |
static_cast<qint32
>(b2);
296 MatrixXd
data(nVertices, 1);
298 for (qint32 i = 0; i < nVertices; ++i) {
300 stream >> b0 >> b1 >> b2;
301 vertices[i] = (
static_cast<qint32
>(b0) << 16)
302 | (
static_cast<qint32
>(b1) << 8)
303 |
static_cast<qint32
>(b2);
308 data(i, 0) =
static_cast<double>(val);
322 qWarning(
"InvSourceEstimate::write_w - Source estimate is empty");
327 if (!file.open(QIODevice::WriteOnly)) {
328 qWarning(
"InvSourceEstimate::write_w - Cannot open file %s for writing", path.toUtf8().constData());
332 QDataStream stream(&file);
333 stream.setByteOrder(QDataStream::BigEndian);
334 stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
337 stream << static_cast<quint8>(0) <<
static_cast<quint8
>(0);
340 qint32 nVertices =
static_cast<qint32
>(
vertices.size());
341 stream << static_cast<quint8>((nVertices >> 16) & 0xFF)
342 <<
static_cast<quint8
>((nVertices >> 8) & 0xFF)
343 <<
static_cast<quint8
>(nVertices & 0xFF);
346 for (qint32 i = 0; i < nVertices; ++i) {
348 stream << static_cast<quint8>((idx >> 16) & 0xFF)
349 <<
static_cast<quint8
>((idx >> 8) & 0xFF)
350 <<
static_cast<quint8
>(idx & 0xFF);
352 stream << static_cast<float>(
data(i, 0));
407 VectorXi vIndexSourceLabels;
409 if(lPickedLabels.isEmpty()) {
410 qWarning() <<
"InvSourceEstimate::getIndicesByLabel - picked label list is empty. Returning.";
411 return vIndexSourceLabels;
415 for(
int i = 0; i < this->
vertices.rows(); i++) {
416 for(
int k = 0; k < lPickedLabels.size(); k++) {
417 if(this->
vertices(i) == lPickedLabels.at(k).label_id) {
418 vIndexSourceLabels.conservativeResize(vIndexSourceLabels.rows()+1,1);
419 vIndexSourceLabels(vIndexSourceLabels.rows()-1) = i;
427 for(
int i = 0; i < this->
vertices.rows(); i++) {
435 for(
int k = 0; k < lPickedLabels.size(); k++) {
436 for(
int l = 0; l < lPickedLabels.at(k).
vertices.rows(); l++) {
437 if(this->
vertices(i) == lPickedLabels.at(k).vertices(l) && lPickedLabels.at(k).hemi == hemi) {
438 vIndexSourceLabels.conservativeResize(vIndexSourceLabels.rows()+1,1);
439 vIndexSourceLabels(vIndexSourceLabels.rows()-1) = i;
447 return vIndexSourceLabels;