MNE-CPP  0.1.9
A Framework for Electrophysiology
fiff_info_base.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "fiff_info_base.h"
42 
43 #include <iostream>
44 
45 //=============================================================================================================
46 // USED NAMESPACES
47 //=============================================================================================================
48 
49 using namespace FIFFLIB;
50 using namespace Eigen;
51 
52 //=============================================================================================================
53 // DEFINE MEMBER METHODS
54 //=============================================================================================================
55 
57 : filename("")
58 , nchan(-1)
59 {
60 }
61 
62 //=============================================================================================================
63 
65 : filename(p_FiffInfoBase.filename)
66 , bads(p_FiffInfoBase.bads)
67 , meas_id(FiffId(p_FiffInfoBase.meas_id))
68 , nchan(p_FiffInfoBase.nchan)
69 , chs(p_FiffInfoBase.chs)
70 , ch_names(p_FiffInfoBase.ch_names)
71 , dev_head_t(p_FiffInfoBase.dev_head_t)
72 , ctf_head_t(p_FiffInfoBase.ctf_head_t)
73 {
74 }
75 
76 //=============================================================================================================
77 
79 {
80 }
81 
82 //=============================================================================================================
83 
84 QString FiffInfoBase::channel_type(qint32 idx) const
85 {
86  qint32 kind = this->chs[idx].kind;
87  if(kind == FIFFV_MEG_CH)
88  {
89  if(this->chs[idx].unit == FIFF_UNIT_T_M)
90  return "grad";
91  else if(this->chs[idx].unit == FIFF_UNIT_T)
92  return "mag";
93  }
94  else if(kind == FIFFV_REF_MEG_CH)
95  return "ref_meg";
96  else if(kind == FIFFV_EEG_CH)
97  return "eeg";
98  else if(kind == FIFFV_STIM_CH)
99  return "stim";
100  else if(kind == FIFFV_EOG_CH)
101  return "eog";
102  else if(kind == FIFFV_EMG_CH)
103  return "emg";
104  else if(kind == FIFFV_ECG_CH)
105  return "ecg";
106  else if(kind == FIFFV_MISC_CH)
107  return "misc";
108  else if (kind == FIFFV_QUAT_0 || kind == FIFFV_QUAT_1 || kind == FIFFV_QUAT_2
109  || kind == FIFFV_QUAT_3 || kind == FIFFV_QUAT_4 || kind == FIFFV_QUAT_5
110  || kind == FIFFV_QUAT_6 || kind == FIFFV_HPI_G || kind == FIFFV_HPI_ERR || kind == FIFFV_HPI_MOV)
111  return "chpi"; // channels relative to head position monitoring
112  printf("Unknown channel type\n"); //ToDo Throw
113  return "";
114 }
115 
116 //=============================================================================================================
117 
119 {
120  filename = "";
121  meas_id.clear();
122  nchan = -1;
123  chs.clear();
124  ch_names.clear();
125  dev_head_t.clear();
126  ctf_head_t.clear();
127  bads.clear();
128 }
129 
130 //=============================================================================================================
131 
132 RowVectorXi FiffInfoBase::pick_types(const QString meg, bool eeg, bool stim, const QStringList& include, const QStringList& exclude) const
133 {
134  RowVectorXi pick = RowVectorXi::Zero(this->nchan);
135 
136  fiff_int_t kind;
137  qint32 k;
138  for(k = 0; k < this->nchan; ++k)
139  {
140  kind = this->chs[k].kind;
141 
142  if ((kind == FIFFV_MEG_CH || kind == FIFFV_REF_MEG_CH))
143  {
144  if(meg.compare("all") == 0) {
145  pick(k) = 1;
146  } else if(meg.compare("grad") == 0 && this->chs[k].unit == FIFF_UNIT_T_M) {
147  pick(k) = 1;
148  } else if(meg.compare("mag") == 0 && this->chs[k].unit == FIFF_UNIT_T) {
149  pick(k) = 1;
150  }
151  }
152  else if (kind == FIFFV_EEG_CH && eeg)
153  pick(k) = 1;
154  else if (kind == FIFFV_STIM_CH && stim)
155  pick(k) = 1;
156  }
157 
158  // restrict channels to selection if provided
159  qint32 p = 0;
160  QStringList myinclude;
161  for(k = 0; k < this->nchan; ++k)
162  {
163  if (pick(0, k))
164  {
165  myinclude << this->ch_names[k];
166  ++p;
167  }
168  }
169 
170  if (include.size() > 0)
171  {
172  for (k = 0; k < include.size(); ++k)
173  {
174  myinclude << include[k];
175  ++p;
176  }
177  }
178 
179  RowVectorXi sel;
180  if (p != 0)
181  sel = FiffInfoBase::pick_channels(this->ch_names, myinclude, exclude);
182 
183  return sel;
184 }
185 
186 //=============================================================================================================
187 
188 RowVectorXi FiffInfoBase::pick_types(bool meg, bool eeg, bool stim, const QStringList& include, const QStringList& exclude) const
189 {
190  if(meg)
191  return this->pick_types(QString("all"), eeg, stim, include, exclude);
192  else
193  return this->pick_types(QString(""), eeg, stim, include, exclude);
194 }
195 
196 //=============================================================================================================
197 
198 RowVectorXi FiffInfoBase::pick_channels(const QStringList& ch_names, const QStringList& include, const QStringList& exclude)
199 {
200  RowVectorXi sel = RowVectorXi::Zero(ch_names.size());
201 
202  QStringList t_includedSelection;
203 
204  qint32 count = 0;
205  for(qint32 k = 0; k < ch_names.size(); ++k)
206  {
207  if( (include.size() == 0 || include.contains(ch_names[k])) && !exclude.contains(ch_names[k]))
208  {
209  //make sure channel is unique
210  if(!t_includedSelection.contains(ch_names[k]))
211  {
212  sel[count] = k;
213  ++count;
214  t_includedSelection << ch_names[k];
215  }
216  }
217  }
218  sel.conservativeResize(count);
219  return sel;
220 }
221 
222 //=============================================================================================================
223 
224 FiffInfoBase FiffInfoBase::pick_info(const RowVectorXi* sel) const
225 {
226  FiffInfoBase res = *this;//new FiffInfo(this);
227  if (sel == NULL)
228  return res;
229 
230  //ToDo when pointer List do deletion
231  res.chs.clear();
232  res.ch_names.clear();
233 
234  qint32 idx;
235  for(qint32 i = 0; i < sel->size(); ++i)
236  {
237  idx = (*sel)(0,i);
238  res.chs.append(this->chs[idx]);
239  res.ch_names.append(this->ch_names[idx]);
240  }
241  res.nchan = sel->size();
242 
243  return res;
244 }
245 //=============================================================================================================
246 
248 {
249  QStringList lChannelTypes;
250 
251  for(int i = 0; i < chs.size(); ++i)
252  {
253  switch(chs.at(i).kind) {
254  case FIFFV_MEG_CH: {
255  if( chs.at(i).unit == FIFF_UNIT_T_M ) { //Gradiometers
256  if(!lChannelTypes.contains("grad")) {
257  lChannelTypes << "grad";
258  }
259  } else if( chs.at(i).unit == FIFF_UNIT_T ) { //Magnetometers
260  if(!lChannelTypes.contains("mag")) {
261  lChannelTypes << "mag";
262  }
263  }
264  break;
265  }
266 
267  case FIFFV_REF_MEG_CH: {
268  if(!lChannelTypes.contains("ref_meg")) {
269  lChannelTypes << "ref_meg";
270  }
271  break;
272  }
273 
274  case FIFFV_EEG_CH: { //EEG Channels
275  if(!lChannelTypes.contains("eeg")) {
276  lChannelTypes << "eeg";
277  }
278  break;
279  }
280 
281  case FIFFV_ECG_CH: { //ECG Channels
282  if(!lChannelTypes.contains("ecg")) {
283  lChannelTypes << "ecg";
284  }
285  break;
286  }
287  case FIFFV_EMG_CH: { //EMG Channels
288  if(!lChannelTypes.contains("emg")) {
289  lChannelTypes << "emg";
290  }
291  break;
292  }
293  case FIFFV_EOG_CH: { //EOG Channels
294  if(!lChannelTypes.contains("eog")) {
295  lChannelTypes << "eog";
296  }
297  break;
298  }
299 
300  case FIFFV_STIM_CH: { //STIM Channels
301  if(!lChannelTypes.contains("stim")) {
302  lChannelTypes << "stim";
303  }
304  break;
305  }
306 
307  case FIFFV_MISC_CH: { //MISC Channels
308  if(!lChannelTypes.contains("misc")) {
309  lChannelTypes << "misc";
310  }
311  break;
312  }
313  }
314  }
315 
316  return lChannelTypes;
317 }
318 
FIFFV_QUAT_4
#define FIFFV_QUAT_4
Definition: fiff_constants.h:73
FIFFLIB::FiffInfoBase::pick_info
FiffInfoBase pick_info(const Eigen::RowVectorXi *sel=Q_NULLPTR) const
Definition: fiff_info_base.cpp:224
FIFFLIB::FiffInfoBase::ctf_head_t
FiffCoordTrans ctf_head_t
Definition: fiff_info_base.h:226
fiff_info_base.h
FiffInfoBase class declaration.
FIFFLIB::FiffInfoBase::clear
void clear()
Definition: fiff_info_base.cpp:118
FIFFV_HPI_MOV
#define FIFFV_HPI_MOV
Definition: fiff_constants.h:78
FIFFLIB::FiffInfoBase::get_channel_types
QStringList get_channel_types()
Definition: fiff_info_base.cpp:247
FIFFV_HPI_ERR
#define FIFFV_HPI_ERR
Definition: fiff_constants.h:77
FIFFLIB::FiffInfoBase::pick_types
Eigen::RowVectorXi pick_types(const QString meg, bool eeg=false, bool stim=false, const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList) const
Definition: fiff_info_base.cpp:132
FIFFLIB::FiffInfoBase::~FiffInfoBase
virtual ~FiffInfoBase()
Definition: fiff_info_base.cpp:78
FIFFLIB::FiffId
Universially unique identifier.
Definition: fiff_id.h:68
FIFFLIB::FiffInfoBase::pick_channels
static Eigen::RowVectorXi pick_channels(const QStringList &ch_names, const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList)
Definition: fiff_info_base.cpp:198
k
int k
Definition: fiff_tag.cpp:322
FIFFV_QUAT_6
#define FIFFV_QUAT_6
Definition: fiff_constants.h:75
FIFFLIB::FiffInfoBase::bads
QStringList bads
Definition: fiff_info_base.h:220
FIFFV_QUAT_1
#define FIFFV_QUAT_1
Definition: fiff_constants.h:70
FIFFV_REF_MEG_CH
#define FIFFV_REF_MEG_CH
Definition: fiff_constants.h:270
FIFFV_HPI_G
#define FIFFV_HPI_G
Definition: fiff_constants.h:76
FIFFV_QUAT_2
#define FIFFV_QUAT_2
Definition: fiff_constants.h:71
FIFFV_QUAT_3
#define FIFFV_QUAT_3
Definition: fiff_constants.h:72
FIFFV_QUAT_0
#define FIFFV_QUAT_0
Definition: fiff_constants.h:69
FIFFLIB::FiffInfoBase::chs
QList< FiffChInfo > chs
Definition: fiff_info_base.h:223
FIFFLIB::FiffInfoBase
light measurement info
Definition: fiff_info_base.h:74
FIFFLIB::FiffInfoBase::channel_type
QString channel_type(qint32 idx) const
Definition: fiff_info_base.cpp:84
FIFFLIB::FiffInfoBase::ch_names
QStringList ch_names
Definition: fiff_info_base.h:224
FIFFLIB::FiffInfoBase::nchan
fiff_int_t nchan
Definition: fiff_info_base.h:222
FIFFV_QUAT_5
#define FIFFV_QUAT_5
Definition: fiff_constants.h:74
FIFFLIB::FiffInfoBase::dev_head_t
FiffCoordTrans dev_head_t
Definition: fiff_info_base.h:225
FIFFLIB::FiffInfoBase::filename
QString filename
Definition: fiff_info_base.h:219
FIFFLIB::FiffCoordTrans::clear
void clear()
Definition: fiff_coord_trans.cpp:110
FIFFLIB::FiffId::clear
void clear()
Definition: fiff_id.cpp:115
FIFFLIB::FiffInfoBase::meas_id
FiffId meas_id
Definition: fiff_info_base.h:221
FIFFLIB::FiffInfoBase::FiffInfoBase
FiffInfoBase()
Definition: fiff_info_base.cpp:56