MNE-CPP  beta 1.0
layoutloader.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "layoutloader.h"
43 
44 
45 //*************************************************************************************************************
46 //=============================================================================================================
47 // USED NAMESPACES
48 //=============================================================================================================
49 
50 using namespace UTILSLIB;
51 
52 
53 //*************************************************************************************************************
54 //=============================================================================================================
55 // DEFINE MEMBER METHODS
56 //=============================================================================================================
57 
59 {
60 }
61 
62 
63 //*************************************************************************************************************
64 
65 bool LayoutLoader::readAsaElcFile(QString path, QStringList &channelNames, QVector<QVector<double> > &location3D, QVector<QVector<double> > &location2D, QString &unit)
66 {
67  //Open .elc file
68  if(!path.contains(".elc"))
69  return false;
70 
71  QFile file(path);
72  if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
73  qDebug()<<"Error opening elc file";
74  return false;
75  }
76 
77  //Start reading from file
78  double numberElectrodes;
79  QTextStream in(&file);
80  bool read2D = false;
81 
82  while(!in.atEnd())
83  {
84  QString line = in.readLine();
85 
86  QStringList fields = line.split(QRegExp("\\s+"));
87 
88  //Delete last element if it is a blank character
89  if(fields.at(fields.size()-1) == "")
90  fields.removeLast();
91 
92  if(!line.contains("#")) //Skip commented areas in file
93  {
94  //Read number of electrodes
95  if(line.contains("NumberPositions"))
96  numberElectrodes = fields.at(1).toDouble();
97 
98  //Read the unit of the position values
99  if(line.contains("UnitPosition"))
100  unit = fields.at(1);
101 
102  //Read actual electrode positions
103  if(line.contains("Positions2D"))
104  read2D = true;
105 
106  if(line.contains(":") && !read2D) //Read 3D positions
107  {
108  channelNames.push_back(fields.at(0));
109  QVector<double> posTemp;
110 
111  posTemp.push_back(fields.at(fields.size()-3).toDouble()); //x
112  posTemp.push_back(fields.at(fields.size()-2).toDouble()); //y
113  posTemp.push_back(fields.at(fields.size()-1).toDouble()); //z
114 
115  location3D.push_back(posTemp);
116  }
117 
118  if(line.contains(":") && read2D) //Read 2D positions
119  {
120  QVector<double> posTemp;
121  posTemp.push_back(fields.at(fields.size()-2).toDouble()); //x
122  posTemp.push_back(fields.at(fields.size()-1).toDouble()); //y
123  location2D.push_back(posTemp);
124  }
125 
126  //Read channel names
127  if(line.contains("Labels"))
128  {
129  line = in.readLine();
130  fields = line.split(QRegExp("\\s+"));
131 
132  //Delete last element if it is a blank character
133  if(fields.at(fields.size()-1) == "")
134  fields.removeLast();
135 
136  channelNames = fields;
137  }
138  }
139  }
140 
141  Q_UNUSED(numberElectrodes);
142 
143  file.close();
144 
145  return true;
146 }
147 
148 
149 //*************************************************************************************************************
150 
151 bool LayoutLoader::readMNELoutFile(QString path, QMap<QString, QPointF> &channelData)
152 {
153  //Open .elc file
154  if(!path.contains(".lout"))
155  return false;
156 
157  channelData.clear();
158 
159  QFile file(path);
160  if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
161  qDebug()<<"Error opening mne lout file";
162  return false;
163  }
164 
165  //Start reading from file
166  QTextStream in(&file);
167 
168  //skip first line
169  in.readLine();
170 
171  while(!in.atEnd()) {
172  QString line = in.readLine();
173 
174  QStringList fields = line.split(QRegExp("\\s+"));
175 
176  //Delete last element if it is a blank character
177  if(fields.at(fields.size()-1) == "")
178  fields.removeLast();
179 
180  QPointF posTemp;
181  posTemp.setX(fields.at(1).toDouble()); //x
182  posTemp.setY(fields.at(2).toDouble()); //y
183 
184  //Create channel data map entry
185  QString key = QString("%1 %2").arg(fields.at(fields.size()-2)).arg(fields.at(fields.size()-1));
186  channelData.insert(key, posTemp);
187  }
188 
189  file.close();
190 
191  return true;
192 }
static bool readMNELoutFile(QString path, QMap< QString, QPointF > &channelData)
static bool readAsaElcFile(QString path, QStringList &channelNames, QVector< QVector< double > > &location3D, QVector< QVector< double > > &location2D, QString &unit)
LayoutLoader class declaration.