50 #include <QTextStream>
53 #include <QRegularExpression>
59 using namespace UTILSLIB;
66 QStringList &channelNames,
67 QList<QVector<float> > &location3D,
68 QList<QVector<float> > &location2D,
72 if(!path.contains(
".elc"))
76 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
77 qDebug()<<
"Error opening elc file";
82 double numberElectrodes;
83 QTextStream in(&file);
88 QString line = in.readLine();
90 QStringList fields = line.split(QRegularExpression(
"\\s+"));
93 if(fields.at(fields.size()-1) ==
"")
96 if(!line.contains(
"#"))
99 if(line.contains(
"NumberPositions"))
100 numberElectrodes = fields.at(1).toDouble();
103 if(line.contains(
"UnitPosition"))
107 if(line.contains(
"Positions2D"))
110 if(line.contains(
":") && !read2D)
112 channelNames.push_back(fields.at(0));
113 QVector<float> posTemp;
115 posTemp.push_back(fields.at(fields.size()-3).toDouble());
116 posTemp.push_back(fields.at(fields.size()-2).toDouble());
117 posTemp.push_back(fields.at(fields.size()-1).toDouble());
119 location3D.append(posTemp);
122 if(line.contains(
":") && read2D)
124 QVector<float> posTemp;
125 posTemp.push_back(fields.at(fields.size()-2).toDouble());
126 posTemp.push_back(fields.at(fields.size()-1).toDouble());
127 location2D.append(posTemp);
131 if(line.contains(
"Labels"))
133 line = in.readLine();
134 fields = line.split(QRegularExpression(
"\\s+"));
137 if(fields.at(fields.size()-1) ==
"")
140 channelNames = fields;
145 Q_UNUSED(numberElectrodes);
155 std::vector<std::string> &channelNames,
156 std::vector<std::vector<float> > &location3D,
157 std::vector<std::vector<float> > &location2D,
161 if(path.find(
".elc") == std::string::npos){
165 std::ifstream inFile(path);
167 if(!inFile.is_open()){
168 qDebug()<<
"Error opening elc file";
173 double numberElectrodes;
178 while(std::getline(inFile, line)){
179 if(line.find(
'#') == std::string::npos){
180 std::vector<std::string> elements;
181 std::stringstream stream{line};
185 while(stream >> element){
186 elements.push_back(std::move(element));
191 if(line.find(
"NumberPositions") != std::string::npos)
192 numberElectrodes = std::stod(elements.at(1));
195 if(line.find(
"UnitPosition") != std::string::npos)
196 unit = elements.at(1);
199 if(line.find(
"Positions2D") != std::string::npos)
202 if(line.find(
':') != std::string::npos && !read2D)
204 channelNames.push_back(elements.at(0));
205 std::vector<float> posTemp;
207 posTemp.push_back(std::stod(elements.at(elements.size()-3)));
208 posTemp.push_back(std::stod(elements.at(elements.size()-2)));
209 posTemp.push_back(std::stod(elements.at(elements.size()-1)));
211 location3D.push_back(std::move(posTemp));
214 if(line.find(
":") != std::string::npos && read2D)
216 std::vector<float> posTemp;
217 posTemp.push_back(std::stod(elements.at(elements.size()-2)));
218 posTemp.push_back(std::stod(elements.at(elements.size()-1)));
219 location2D.push_back(std::move(posTemp));
223 if(line.find(
"Labels") != std::string::npos)
225 std::getline(inFile, line);
226 std::stringstream channels{line};
227 std::vector<std::string> listOfNames;
229 std::string channelName;
232 while(channels >> channelName){
233 listOfNames.push_back(std::move(channelName));
237 channelNames = std::move(listOfNames);
242 Q_UNUSED(numberElectrodes);
252 if(!path.contains(
".lout"))
258 if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
259 qDebug()<<
"Error opening mne lout file";
264 QTextStream in(&file);
270 QString line = in.readLine();
272 QStringList fields = line.split(QRegularExpression(
"\\s+"));
275 if(fields.at(fields.size()-1) ==
"")
279 posTemp.setX(fields.at(1).toDouble());
280 posTemp.setY(fields.at(2).toDouble());
283 QString key = QString(
"%1 %2").arg(fields.at(fields.size()-2)).arg(fields.at(fields.size()-1));
284 channelData.insert(key, posTemp);
297 if(path.find(
".lout") == std::string::npos){
302 std::ifstream inFile(path);
304 if(!inFile.is_open()){
305 qDebug()<<
"Error opening mne lout file";
311 while(std::getline(inFile, line)){
312 if(line.find(
'#') != std::string::npos){
313 std::vector<std::string> elements;
314 std::stringstream stream{line};
318 while(stream >> element){
319 elements.push_back(std::move(element));
324 posTemp.setX(std::stod(elements.at(1)));
325 posTemp.setY(std::stod(elements.at(2)));
328 std::string key{elements.at(elements.size() - 2) +
" " + elements.at(elements.size() - 1)};
329 channelData.insert(key, posTemp);