MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
fiff_dig_point_set.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "fiff_dig_point_set.h"
41
42//=============================================================================================================
43// INCLUDES
44//=============================================================================================================
45
46#include "fiff_dig_point.h"
47#include "fiff_dir_node.h"
48#include "fiff_tag.h"
49#include "fiff_types.h"
50
51//=============================================================================================================
52// QT INCLUDES
53//=============================================================================================================
54
55//=============================================================================================================
56// EIGEN INCLUDES
57//=============================================================================================================
58
59//=============================================================================================================
60// USED NAMESPACES
61//=============================================================================================================
62
63using namespace FIFFLIB;
64using namespace Eigen;
65
66//=============================================================================================================
67// DEFINE GLOBAL METHODS
68//=============================================================================================================
69
70//=============================================================================================================
71// DEFINE MEMBER METHODS
72//=============================================================================================================
73
75 :m_qListDigPoint()
76{
77}
78
79//=============================================================================================================
80
82: m_qListDigPoint(p_FiffDigPointSet.m_qListDigPoint)
83{
84}
85
86//=============================================================================================================
87
88FiffDigPointSet::FiffDigPointSet(QList<FIFFLIB::FiffDigPoint> pointList)
89: m_qListDigPoint(pointList)
90{
91}
92
93//=============================================================================================================
94
95FiffDigPointSet::FiffDigPointSet(QIODevice &p_IODevice) //const FiffDigPointSet &p_FiffDigPointSet
96{
97 //
98 // Open the file
99 //
100 FiffStream::SPtr t_pStream(new FiffStream(&p_IODevice));
101
102 if(!FiffDigPointSet::readFromStream(t_pStream, *this)) {
103 t_pStream->close();
104 qInfo() << "[FiffDigPointSet::FiffDigPointSet] Could not read the FiffDigPointSet"; // ToDo throw error
105 }
106
107 qInfo("[FiffDigPointSet::FiffDigPointSet] %i digitizer Points read from file.", this->size());
108}
109
110//=============================================================================================================
111
115
116//=============================================================================================================
117
119{
120 //
121 // Open the file, create directory
122 //
123 bool open_here = false;
124
125 if (!p_pStream->device()->isOpen()) {
126 QString t_sFileName = p_pStream->streamName();
127
128 if(!p_pStream->open())
129 return false;
130
131 printf("Opening header data %s...\n",t_sFileName.toUtf8().constData());
132
133 open_here = true;
134 }
135
136 //
137 // Read the measurement info
138 //
139 //read_hpi_info(p_pStream,p_Tree, info);
140 fiff_int_t kind = -1;
141 fiff_int_t pos = -1;
142 FiffTag::SPtr t_pTag;
143
144 //
145 // Locate the Electrodes
146 //
147 QList<FiffDirNode::SPtr> isotrak = p_pStream->dirtree()->dir_tree_find(FIFFB_ISOTRAK);
148
149 fiff_int_t coord_frame = FIFFV_COORD_HEAD;
150 FiffCoordTrans dig_trans;
151 qint32 k = 0;
152
153 if (isotrak.size() == 1)
154 {
155 for (k = 0; k < isotrak[0]->nent(); ++k)
156 {
157 kind = isotrak[0]->dir[k]->kind;
158 pos = isotrak[0]->dir[k]->pos;
159 if (kind == FIFF_DIG_POINT)
160 {
161 p_pStream->read_tag(t_pTag, pos);
162 p_Dig.m_qListDigPoint.append(t_pTag->toDigPoint());
163 }
164 else
165 {
166 if (kind == FIFF_MNE_COORD_FRAME)
167 {
168 p_pStream->read_tag(t_pTag, pos);
169 qDebug() << "NEEDS To BE DEBBUGED: FIFF_MNE_COORD_FRAME" << t_pTag->getType();
170 coord_frame = *t_pTag->toInt();
171 }
172 else if (kind == FIFF_COORD_TRANS)
173 {
174 p_pStream->read_tag(t_pTag, pos);
175 qDebug() << "NEEDS To BE DEBBUGED: FIFF_COORD_TRANS" << t_pTag->getType();
176 dig_trans = t_pTag->toCoordTrans();
177 }
178 }
179 }
180 }
181 for(k = 0; k < p_Dig.size(); ++k)
182 {
183 p_Dig[k].coord_frame = coord_frame;
184 }
185
186 //
187 // All kinds of auxliary stuff
188 //
189 if(open_here)
190 {
191 p_pStream->close();
192 }
193 return true;
194}
195
196//=============================================================================================================
197
198void FiffDigPointSet::write(QIODevice &p_IODevice)
199{
200 //
201 // Open the file, create directory
202 //
203
204 // Create the file and save the essentials
205 FiffStream::SPtr t_pStream = FiffStream::start_file(p_IODevice);
206 printf("Write Digitizer Points in %s...\n", t_pStream->streamName().toUtf8().constData());
207 this->writeToStream(t_pStream.data());
208 t_pStream->end_file();
209}
210
211//=============================================================================================================
212
214{
215 p_pStream->start_block(FIFFB_MEAS);
216 p_pStream->start_block(FIFFB_MEAS_INFO);
217 p_pStream->start_block(FIFFB_ISOTRAK);
218
219 for(qint32 h = 0; h < m_qListDigPoint.size(); ++h)
220 {
221 p_pStream->write_dig_point(m_qListDigPoint[h]);
222 }
223
224 printf("\t%lld digitizer points written\n", m_qListDigPoint.size());
225 p_pStream->end_block(FIFFB_ISOTRAK);
226 p_pStream->end_block(FIFFB_MEAS_INFO);
227 p_pStream->end_block(FIFFB_MEAS);
228}
229
230//=============================================================================================================
231
233{
234 if (idx>=m_qListDigPoint.length())
235 {
236 qWarning("Warning: Required DigPoint doesn't exist! Returning DigPoint '0'.");
237 idx=0;
238 }
239 return m_qListDigPoint[idx];
240}
241
242//=============================================================================================================
243
245{
246 if (idx >= m_qListDigPoint.length())
247 {
248 qWarning("Warning: Required DigPoint doesn't exist! Returning DigPoint '0'.");
249 idx = 0;
250 }
251 return m_qListDigPoint[idx];
252}
253
254//=============================================================================================================
255
256FiffDigPointSet FiffDigPointSet::pickTypes(QList<int> includeTypes) const
257{
258 FiffDigPointSet pickedSet;
259
260 for(int i = 0; i < m_qListDigPoint.size(); ++i) {
261 if(includeTypes.contains(m_qListDigPoint[i].kind)) {
262 pickedSet << m_qListDigPoint[i];
263 }
264 }
265
266 return pickedSet;
267}
268
269//=============================================================================================================
270
272{
273 this->m_qListDigPoint.append(dig);
274 return *this;
275}
276
277//=============================================================================================================
278
280{
281 this->m_qListDigPoint.append(*dig);
282 return *this;
283}
284
285//=============================================================================================================
286
287void FiffDigPointSet::applyTransform(const FiffCoordTrans& coordTrans, bool bApplyInverse)
288{
289 Vector4f tempvec;
290 for(int i = 0; i < m_qListDigPoint.size(); ++i) {
291 tempvec(0) = m_qListDigPoint.at(i).r[0];
292 tempvec(1) = m_qListDigPoint.at(i).r[1];
293 tempvec(2) = m_qListDigPoint.at(i).r[2];
294 tempvec(3) = 1.0f;
295 if(bApplyInverse) {
296 tempvec = coordTrans.invtrans * tempvec;
297 } else {
298 tempvec = coordTrans.trans * tempvec;
299 }
300 m_qListDigPoint[i].r[0] = tempvec(0);
301 m_qListDigPoint[i].r[1] = tempvec(1);
302 m_qListDigPoint[i].r[2] = tempvec(2);
303 }
304}
305
306//=============================================================================================================
307
308QList<FiffDigPoint> FiffDigPointSet::getList()
309{
310 return m_qListDigPoint;
311}
FiffTag class declaration, which provides fiff tag I/O and processing methods.
#define FIFF_MNE_COORD_FRAME
FiffDigPointSet class declaration.
FiffDirNode class declaration, which provides fiff dir tree processing methods.
int k
Definition fiff_tag.cpp:324
#define FIFF_COORD_TRANS
Definition fiff_file.h:475
#define FIFF_DIG_POINT
Definition fiff_file.h:466
Definitions for describing the objects in a FIFF file.
FiffDigPoint class declaration.
Coordinate transformation description.
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > trans
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > invtrans
Digitization point description.
Holds a set of digitizer points.
const FiffDigPoint & operator[](qint32 idx) const
FiffDigPointSet & operator<<(const FiffDigPoint &dig)
FiffDigPointSet pickTypes(QList< int > includeTypes) const
void applyTransform(const FiffCoordTrans &coordTrans, bool bApplyInverse=false)
void write(QIODevice &p_IODevice)
write
void writeToStream(FiffStream *p_pStream)
writeToStream
static bool readFromStream(FiffStream::SPtr &p_Stream, FiffDigPointSet &p_Dig)
QList< FiffDigPoint > getList()
FIFF File I/O routines.
fiff_long_t start_block(fiff_int_t kind)
fiff_long_t write_dig_point(const FiffDigPoint &dig)
static FiffStream::SPtr start_file(QIODevice &p_IODevice)
fiff_long_t end_block(fiff_int_t kind, fiff_int_t next=FIFFV_NEXT_SEQ)
QSharedPointer< FiffStream > SPtr
QSharedPointer< FiffTag > SPtr
Definition fiff_tag.h:152