MNE-CPP  beta 0.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
asaelc.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //*************************************************************************************************************
38 //=============================================================================================================
39 // INCLUDES
40 //=============================================================================================================
41 
42 #include "asaelc.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 AsAElc::readElcFile(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  file.open(QIODevice::ReadOnly | QIODevice::Text);
73 
74  //Start reading from file
75  double numberElectrodes;
76  QTextStream in(&file);
77  bool read2D = false;
78 
79  while(!in.atEnd())
80  {
81  QString line = in.readLine();
82 
83  QStringList fields = line.split(QRegExp("\\s+"));
84 
85  //Delete last element if it is a blank character
86  if(fields.at(fields.size()-1) == "")
87  fields.removeLast();
88 
89  if(!line.contains("#")) //Skip commented areas in file
90  {
91  //Read number of electrodes
92  if(line.contains("NumberPositions"))
93  numberElectrodes = fields.at(1).toDouble();
94 
95  //Read the unit of the position values
96  if(line.contains("UnitPosition"))
97  unit = fields.at(1);
98 
99  //Read actual electrode positions
100  if(line.contains("Positions2D"))
101  read2D = true;
102 
103  if(line.contains(":") && !read2D) //Read 3D positions
104  {
105  channelNames.push_back(fields.at(0));
106  QVector<double> posTemp;
107 
108  posTemp.push_back(fields.at(fields.size()-3).toDouble()); //x
109  posTemp.push_back(fields.at(fields.size()-2).toDouble()); //y
110  posTemp.push_back(fields.at(fields.size()-1).toDouble()); //z
111 
112  location3D.push_back(posTemp);
113  }
114 
115  if(line.contains(":") && read2D) //Read 2D positions
116  {
117  QVector<double> posTemp;
118  posTemp.push_back(fields.at(fields.size()-2).toDouble()); //x
119  posTemp.push_back(fields.at(fields.size()-1).toDouble()); //y
120  location2D.push_back(posTemp);
121  }
122 
123  //Read channel names
124  if(line.contains("Labels"))
125  {
126  line = in.readLine();
127  fields = line.split(QRegExp("\\s+"));
128 
129  //Delete last element if it is a blank character
130  if(fields.at(fields.size()-1) == "")
131  fields.removeLast();
132 
133  channelNames = fields;
134  }
135  }
136  }
137 
138  Q_UNUSED(numberElectrodes);
139 
140  file.close();
141 
142  return true;
143 }
bool readElcFile(QString path, QStringList &channelNames, QVector< QVector< double > > &location3D, QVector< QVector< double > > &location2D, QString &unit)
Definition: asaelc.cpp:65
AsAElc class declaration.