MNE-CPP  beta 1.0
fiff_info_base.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "fiff_info_base.h"
42 
43 #include <iostream>
44 
45 
46 //*************************************************************************************************************
47 //=============================================================================================================
48 // USED NAMESPACES
49 //=============================================================================================================
50 
51 using namespace FIFFLIB;
52 using namespace Eigen;
53 
54 
55 //*************************************************************************************************************
56 //=============================================================================================================
57 // DEFINE MEMBER METHODS
58 //=============================================================================================================
59 
61 : filename("")
62 , nchan(-1)
63 {
64 }
65 
66 
67 //*************************************************************************************************************
68 
70 : filename(p_FiffInfoBase.filename)
71 , bads(p_FiffInfoBase.bads)
72 , meas_id(FiffId(p_FiffInfoBase.meas_id))
73 , nchan(p_FiffInfoBase.nchan)
74 , ch_names(p_FiffInfoBase.ch_names)
75 , dev_head_t(p_FiffInfoBase.dev_head_t)
76 , ctf_head_t(p_FiffInfoBase.ctf_head_t)
77 {
78  qint32 i;
79  for(i = 0; i < p_FiffInfoBase.chs.size(); ++i)
80  chs.append(p_FiffInfoBase.chs[i]);
81 }
82 
83 
84 //*************************************************************************************************************
85 
87 {
88 
89 }
90 
91 
92 //*************************************************************************************************************
93 
94 QString FiffInfoBase::channel_type(qint32 idx) const
95 {
96  qint32 kind = this->chs[idx].kind;
97  if(kind == FIFFV_MEG_CH)
98  {
99  if(this->chs[idx].unit == FIFF_UNIT_T_M)
100  return "grad";
101  else if(this->chs[idx].unit == FIFF_UNIT_T)
102  return "mag";
103  }
104  else if(kind == FIFFV_REF_MEG_CH)
105  return "ref_meg";
106  else if(kind == FIFFV_EEG_CH)
107  return "eeg";
108  else if(kind == FIFFV_STIM_CH)
109  return "stim";
110  else if(kind == FIFFV_EOG_CH)
111  return "eog";
112  else if(kind == FIFFV_EMG_CH)
113  return "emg";
114  else if(kind == FIFFV_ECG_CH)
115  return "ecg";
116  else if(kind == FIFFV_MISC_CH)
117  return "misc";
118  else if (kind == FIFFV_QUAT_0 || kind == FIFFV_QUAT_1 || kind == FIFFV_QUAT_2
119  || kind == FIFFV_QUAT_3 || kind == FIFFV_QUAT_4 || kind == FIFFV_QUAT_5
120  || kind == FIFFV_QUAT_6 || kind == FIFFV_HPI_G || kind == FIFFV_HPI_ERR || kind == FIFFV_HPI_MOV)
121  return "chpi"; // channels relative to head position monitoring
122  printf("Unknown channel type\n"); //ToDo Throw
123  return "";
124 }
125 
126 
127 //*************************************************************************************************************
128 
130 {
131  filename = "";
132  meas_id.clear();
133  nchan = -1;
134  chs.clear();
135  ch_names.clear();
136  dev_head_t.clear();
137  ctf_head_t.clear();
138  bads.clear();
139 }
140 
141 
142 //*************************************************************************************************************
143 
144 RowVectorXi FiffInfoBase::pick_types(const QString meg, bool eeg, bool stim, const QStringList& include, const QStringList& exclude) const
145 {
146  RowVectorXi pick = RowVectorXi::Zero(this->nchan);
147 
148  fiff_int_t kind;
149  qint32 k;
150  for(k = 0; k < this->nchan; ++k)
151  {
152  kind = this->chs[k].kind;
153 
154  if ((kind == FIFFV_MEG_CH || kind == FIFFV_REF_MEG_CH))
155  {
156  if(meg.compare("all") == 0)
157  pick(k) = 1;
158  else if(meg.compare("grad") == 0 && this->chs[k].unit == FIFF_UNIT_T_M)
159  pick(k) = 1;
160  else if(meg.compare("mag") == 0 && this->chs[k].unit == FIFF_UNIT_T)
161  pick(k) = 1;
162  }
163  else if (kind == FIFFV_EEG_CH && eeg)
164  pick(k) = 1;
165  else if (kind == FIFFV_STIM_CH && stim)
166  pick(k) = 1;
167  }
168 
169  // restrict channels to selection if provided
170  qint32 p = 0;
171  QStringList myinclude;
172  for(k = 0; k < this->nchan; ++k)
173  {
174  if (pick(0, k))
175  {
176  myinclude << this->ch_names[k];
177  ++p;
178  }
179  }
180 
181  if (include.size() > 0)
182  {
183  for (k = 0; k < include.size(); ++k)
184  {
185  myinclude << include[k];
186  ++p;
187  }
188  }
189 
190  RowVectorXi sel;
191  if (p != 0)
192  sel = FiffInfoBase::pick_channels(this->ch_names, myinclude, exclude);
193 
194  return sel;
195 }
196 
197 //*************************************************************************************************************
198 
199 RowVectorXi FiffInfoBase::pick_types(bool meg, bool eeg, bool stim, const QStringList& include, const QStringList& exclude) const
200 {
201  if(meg)
202  return this->pick_types(QString("all"), eeg, stim, include, exclude);
203  else
204  return this->pick_types(QString(""), eeg, stim, include, exclude);
205 }
206 
207 
208 //*************************************************************************************************************
209 
210 RowVectorXi FiffInfoBase::pick_channels(const QStringList& ch_names, const QStringList& include, const QStringList& exclude)
211 {
212  RowVectorXi sel = RowVectorXi::Zero(ch_names.size());
213 
214  QStringList t_includedSelection;
215 
216  qint32 count = 0;
217  for(qint32 k = 0; k < ch_names.size(); ++k)
218  {
219  if( (include.size() == 0 || include.contains(ch_names[k])) && !exclude.contains(ch_names[k]))
220  {
221  //make sure channel is unique
222  if(!t_includedSelection.contains(ch_names[k]))
223  {
224  sel[count] = k;
225  ++count;
226  t_includedSelection << ch_names[k];
227  }
228  }
229  }
230  sel.conservativeResize(count);
231  return sel;
232 }
233 
234 
235 //*************************************************************************************************************
236 
237 FiffInfoBase FiffInfoBase::pick_info(const RowVectorXi* sel) const
238 {
239  FiffInfoBase res = *this;//new FiffInfo(this);
240  if (sel == NULL)
241  return res;
242 
243  //ToDo when pointer List do delation
244  res.chs.clear();
245  res.ch_names.clear();
246 
247  qint32 idx;
248  for(qint32 i = 0; i < sel->size(); ++i)
249  {
250  idx = (*sel)(0,i);
251  res.chs.append(this->chs[idx]);
252  res.ch_names.append(this->ch_names[idx]);
253  }
254  res.nchan = sel->size();
255 
256  return res;
257 }
#define FIFFV_QUAT_0
#define FIFFV_QUAT_4
Universially unique identifier.
Definition: fiff_id.h:78
#define FIFFV_HPI_ERR
FiffCoordTrans ctf_head_t
#define FIFFV_HPI_G
#define FIFFV_QUAT_6
FiffInfoBase class declaration.
#define FIFF_UNIT_T_M
#define FIFFV_HPI_MOV
QList< FiffChInfo > chs
#define FIFFV_QUAT_1
Definition: fiff.h:98
FiffCoordTrans dev_head_t
RowVectorXi pick_types(const QString meg, bool eeg=false, bool stim=false, const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList) const
QString channel_type(qint32 idx) const
#define FIFFV_QUAT_3
FiffInfoBase pick_info(const RowVectorXi *sel=NULL) const
light measurement info
#define FIFFV_QUAT_2
static RowVectorXi pick_channels(const QStringList &ch_names, const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList)
#define FIFFV_QUAT_5
void clear()
Definition: fiff_id.cpp:89