MNE-CPP  beta 0.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mne.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "mne.h"
42 #include <fiff/fiff.h>
43 #include <iostream>
44 
45 
46 //*************************************************************************************************************
47 //=============================================================================================================
48 // QT INCLUDES
49 //=============================================================================================================
50 
51 #include <QFile>
52 #include <QDebug>
53 
54 
55 //*************************************************************************************************************
56 //=============================================================================================================
57 // USED NAMESPACES
58 //=============================================================================================================
59 
60 using namespace MNELIB;
61 
62 
63 //*************************************************************************************************************
64 //=============================================================================================================
65 // DEFINE MEMBER METHODS
66 //=============================================================================================================
67 
68 bool MNE::read_events(QIODevice &p_IODevice, MatrixXi& eventlist)
69 {
70  //
71  // Open file
72  //
73  FiffStream::SPtr t_pFile(new FiffStream(&p_IODevice));
74  FiffDirTree t_Tree;
75  QList<FiffDirEntry> t_Dir;
76 
77  if(!t_pFile->open(t_Tree, t_Dir))
78  {
79 // if(t_pTree)
80 // delete t_pTree;
81 // if(t_pDir)
82 // delete t_pDir;
83 
84  return false;
85  }
86 
87  //
88  // Find the desired block
89  //
90  QList<FiffDirTree> events = t_Tree.dir_tree_find(FIFFB_MNE_EVENTS);
91 
92  if (events.size() == 0)
93  {
94  printf("Could not find event data\n");
95  return false;
96  }
97 
98  qint32 k, nelem;
99  fiff_int_t kind, pos;
100  FiffTag::SPtr t_pTag;
101  quint32* serial_eventlist = NULL;
102  for(k = 0; k < events[0].nent; ++k)
103  {
104  kind = events[0].dir[k].kind;
105  pos = events[0].dir[k].pos;
106  if (kind == FIFF_MNE_EVENT_LIST)
107  {
108  FiffTag::read_tag(t_pFile.data(),t_pTag,pos);
109  if(t_pTag->type == FIFFT_UINT)
110  {
111  serial_eventlist = t_pTag->toUnsignedInt();
112  nelem = t_pTag->size()/4;
113  }
114  break;
115  }
116  }
117 
118  if(serial_eventlist == NULL)
119  {
120  printf("Could not find any events\n");
121  return false;
122  }
123  else
124  {
125  eventlist.resize(nelem/3,3);
126  for(k = 0; k < nelem/3; ++k)
127  {
128  eventlist(k,0) = serial_eventlist[k*3];
129  eventlist(k,1) = serial_eventlist[k*3+1];
130  eventlist(k,2) = serial_eventlist[k*3+2];
131  }
132  }
133 
134  return true;
135 }
136 
137 
138 //*************************************************************************************************************
QList< FiffDirTree > dir_tree_find(fiff_int_t p_kind) const
QSharedPointer< FiffTag > SPtr
Definition: fiff_tag.h:166
static bool read_tag(FiffStream *p_pStream, FiffTag::SPtr &p_pTag, qint64 pos=-1)
Definition: fiff_tag.cpp:204
static bool read_events(QIODevice &p_IODevice, MatrixXi &eventlist)
Definition: mne.cpp:68
MNE class declaration, which provides static wrapper functions to stay consistent with mne matlab too...
QSharedPointer< FiffStream > SPtr
Definition: fiff_stream.h:132
Directory tree structure.
Definition: fiff_dir_tree.h:80
#define FIFF_MNE_EVENT_LIST
FIFF class declaration, which provides static wrapper functions to stay consistent with mne matlab to...
FIFF File I/O routines.
Definition: fiff_stream.h:129