v2.0.0
Loading...
Searching...
No Matches
mne_cluster_info.cpp
Go to the documentation of this file.
1//=============================================================================================================
18
19//=============================================================================================================
20// INCLUDES
21//=============================================================================================================
22
23#include "mne_cluster_info.h"
24
25//=============================================================================================================
26// QT INCLUDES
27//=============================================================================================================
28
29#include <QDir>
30#include <QFile>
31#include <QFileInfo>
32#include <QTextStream>
33
34//=============================================================================================================
35// USED NAMESPACES
36//=============================================================================================================
37
38using namespace MNELIB;
39
40//=============================================================================================================
41// DEFINE MEMBER METHODS
42//=============================================================================================================
43
47
48//=============================================================================================================
49
51{
52 clusterLabelNames.clear();
53 clusterLabelIds.clear();
54 centroidVertno.clear();
55 centroidSource_rr.clear();
56 clusterVertnos.clear();
57 clusterSource_rr.clear();
58 clusterDistances.clear();
59}
60
61//=============================================================================================================
62
63void MNEClusterInfo::write(QString p_sFileName) const
64{
65 QFile file(p_sFileName);
66 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
67 qDebug("Unable to open file.");
68 return;
69 }
70 QTextStream out(&file);
71 out << "MNE Cluster Info\n";
72
73 for (qint32 i = 0; i < clusterLabelIds.size(); ++i) {
74 out << "\nLabel : " << clusterLabelNames[i] << "\n";
75 out << "FsLabel ID : " << clusterLabelIds[i] << "\n";
76 out << "Centroid Vertno : " << centroidVertno[i] << "\n";
77 out << "Centroid rr : " << centroidSource_rr[i](0) << ", " << centroidSource_rr[i](1) << ", " << centroidSource_rr[i](2) << "\n";
78 out << "Vertnos :\n";
79 for (qint32 j = 0; j < clusterVertnos[i].size(); ++j)
80 out << clusterVertnos[i][j] << ", ";
81 out << "\nDistances :\n";
82 for (qint32 j = 0; j < clusterDistances[i].size(); ++j)
83 out << clusterDistances[i][j] << ", ";
84 out << "\nrr :\n";
85 for (qint32 j = 0; j < clusterSource_rr[i].rows(); ++j)
86 out << clusterSource_rr[i](j, 0) << ", " << clusterSource_rr[i](j, 1) << ", " << clusterSource_rr[i](j, 2) << "\n";
87
88 out << "\n";
89 }
90
91 // optional, as QFile destructor will already do it:
92 file.close();
93
94 // Next to the main file: <dir>/centroids_<name>
95 const QFileInfo info(p_sFileName);
96 QFile file_centroids(info.dir().filePath("centroids_" + info.fileName()));
97
98 if (file_centroids.open(QIODevice::WriteOnly | QIODevice::Text)) {
99 QTextStream out_centroids(&file_centroids);
100
101 for (qint32 i = 0; i < clusterLabelIds.size(); ++i)
102 out_centroids << centroidVertno[i] << ", ";
103
104 // optional, as QFile destructor will already do it:
105 file_centroids.close();
106 }
107}
Bookkeeping for a label-restricted clustering of source-space leadfield columns.
Core MNE data structures (source spaces, source estimates, hemispheres).
QList< Eigen::VectorXd > clusterDistances
QList< QString > clusterLabelNames
QList< qint32 > clusterLabelIds
QList< Eigen::MatrixX3f > clusterSource_rr
QList< Eigen::VectorXi > clusterVertnos
void write(QString p_sFileName) const
QList< qint32 > centroidVertno
QList< Eigen::Vector3f > centroidSource_rr