v2.0.0
Loading...
Searching...
No Matches
fiff_coord_trans.h
Go to the documentation of this file.
1//=============================================================================================================
36
37#ifndef FIFF_COORD_TRANS_H
38#define FIFF_COORD_TRANS_H
39
40//=============================================================================================================
41// INCLUDES
42//=============================================================================================================
43
44#include "fiff_global.h"
45#include "fiff_types.h"
46#include "fiff_stream.h"
47#include "fiff_dir_node.h"
48
49//=============================================================================================================
50// QT INCLUDES
51//=============================================================================================================
52
53#include <QIODevice>
54#include <QSharedPointer>
55
56#include <memory>
57
58//=============================================================================================================
59// EIGEN INCLUDES
60//=============================================================================================================
61
62#include <Eigen/Core>
63
64//=============================================================================================================
65// DEFINE NAMESPACE FIFFLIB
66//=============================================================================================================
67
68namespace FIFFLIB
69{
70
71// Forward declaration
72class FiffTag;
73
74//=============================================================================================================
81{
82public:
83 typedef QSharedPointer<FiffCoordTrans> SPtr;
84 typedef QSharedPointer<const FiffCoordTrans> ConstSPtr;
85 typedef std::unique_ptr<FiffCoordTrans> UPtr;
86 typedef std::unique_ptr<const FiffCoordTrans> ConstUPtr;
87
88 //=========================================================================================================
93
94 //=========================================================================================================
100 FiffCoordTrans(QIODevice &p_IODevice);
101
102 //=========================================================================================================
108 FiffCoordTrans(const FiffCoordTrans &p_FiffCoordTrans);
109
110 //=========================================================================================================
119 FiffCoordTrans(int from, int to, const Eigen::Matrix3f& rot, const Eigen::Vector3f& move);
120
121 //=========================================================================================================
130 FiffCoordTrans(int from, int to, const Eigen::Matrix4f& matTrans, bool bStandard = false);
131
132 //=========================================================================================================
137
138 //=========================================================================================================
142 void clear();
143
144 //=========================================================================================================
151 bool invert_transform();
152
153 //=========================================================================================================
159 inline bool isEmpty() const
160 {
161 return this->from < 0;
162 }
163
164 //=========================================================================================================
172
174 auto rot() { return trans.block<3,3>(0,0); }
176 auto rot() const { return trans.block<3,3>(0,0); }
177
179 auto move() { return trans.block<3,1>(0,3); }
181 auto move() const { return trans.block<3,1>(0,3); }
182
184 auto invrot() { return invtrans.block<3,3>(0,0); }
186 auto invrot() const { return invtrans.block<3,3>(0,0); }
187
189 auto invmove() { return invtrans.block<3,1>(0,3); }
191 auto invmove() const { return invtrans.block<3,1>(0,3); }
193
194 //=========================================================================================================
203 static bool read(QIODevice& p_IODevice, FiffCoordTrans& p_Trans);
204
205 //=========================================================================================================
215 static FiffCoordTrans readTransform(const QString& name, int from, int to);
216
217 //=========================================================================================================
225 static FiffCoordTrans readMriTransform(const QString& name);
226
227 //=========================================================================================================
235 static FiffCoordTrans readMeasTransform(const QString& name);
236
237 //=========================================================================================================
247 static FiffCoordTrans readTransformAscii(const QString& name, int from, int to);
248
249 //=========================================================================================================
257 static FiffCoordTrans readFShead2mriTransform(const QString& name);
258
259 //=========================================================================================================
270 Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f& rr, bool do_move = true) const;
271
272 //=========================================================================================================
281 Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f& rr, bool do_move = true) const;
282
283 //=========================================================================================================
291 static void apply_trans(float r[3], const FiffCoordTrans& t, bool do_move);
292
293 //=========================================================================================================
301 static void apply_inverse_trans(float r[3], const FiffCoordTrans& t, bool do_move);
302
303 //=========================================================================================================
311 static QString frame_name (int frame);
312
313 //=========================================================================================================
322 static FiffCoordTrans identity(int from, int to);
323
324 //=========================================================================================================
330 FiffCoordTrans inverted() const;
331
332 //=========================================================================================================
344 static FiffCoordTrans combine(int from, int to, const FiffCoordTrans& t1, const FiffCoordTrans& t2);
345
346 //=========================================================================================================
358 static FiffCoordTrans fromCardinalPoints(int from, int to, const float* rL, const float* rN, const float* rR);
359
360 //=========================================================================================================
366 static bool addInverse(FiffCoordTrans& t);
367
368 //=========================================================================================================
372 void print() const;
373
374 //=========================================================================================================
380 void write(QIODevice &p_IODevice);
381
382 //=========================================================================================================
388 void writeToStream(FiffStream* p_pStream);
389
390 //=========================================================================================================
396 inline static qint32 storageSize();
397
398 //========================================================================================================
406 friend bool operator== (const FiffCoordTrans &a, const FiffCoordTrans &b);
407
408 //========================================================================================================
416 float angleTo(Eigen::MatrixX4f mTransDest);
417
418 //========================================================================================================
426 float translationTo(Eigen::MatrixX4f mTransDest);
427
428 //========================================================================================================
436 static FiffCoordTrans readFromTag(const QSharedPointer<FiffTag>& tag);
437
438 //========================================================================================================
450 const FiffDirNode::SPtr& node,
451 int from, int to);
452
453 //========================================================================================================
467 static FiffCoordTrans procrustesAlign(int from_frame, int to_frame,
468 float **fromp, float **top,
469 float *w, int np,
470 float max_diff);
471
472public:
475 Eigen::Matrix<float, 4,4, Eigen::DontAlign> trans;
476 Eigen::Matrix<float, 4,4, Eigen::DontAlign> invtrans;
477
478};
479
480//=============================================================================================================
481// INLINE DEFINITIONS
482//=============================================================================================================
483
485{
486 // On-disk layout: from, to, rot[3][3], move[3], invrot[3][3], invmove[3]
487 // (C++ class uses Matrix4f but on-disk stores 3x3 rot + 3-vec separately)
488 return 2 * sizeof(fiff_int_t) + 2 * 12 * sizeof(fiff_float_t);
489}
490
491//=============================================================================================================
492
493inline bool operator== (const FiffCoordTrans &a, const FiffCoordTrans &b)
494{
495 return (a.from == b.from &&
496 a.to == b.to &&
497 a.trans.isApprox(b.trans, 0.0001f) &&
498 a.invtrans.isApprox(b.invtrans, 0.0001f));
499}
500} // NAMESPACE
501
502#ifndef metatype_fiffcoordtrans
503#define metatype_fiffcoordtrans
505#endif
506
507#ifndef metatype_fiffcoordtrans_sptr
508#define metatype_fiffcoordtrans_sptr
510#endif
511
512#endif // FIFF_COORD_TRANS_H
Fiff library export/import macros.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:52
FiffStream class declaration.
FiffDirNode class declaration, which provides fiff dir tree processing methods.
Old fiff_type declarations - replace them.
Q_DECLARE_METATYPE(FIFFLIB::FiffCoordTrans)
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
qint32 fiff_int_t
Definition fiff_types.h:89
float fiff_float_t
Definition fiff_types.h:93
bool operator==(const FiffChInfo &a, const FiffChInfo &b)
Coordinate transformation description.
std::unique_ptr< const FiffCoordTrans > ConstUPtr
static FiffCoordTrans readTransformFromNode(FiffStream::SPtr &stream, const FiffDirNode::SPtr &node, int from, int to)
static FiffCoordTrans combine(int from, int to, const FiffCoordTrans &t1, const FiffCoordTrans &t2)
static FiffCoordTrans identity(int from, int to)
FiffCoordTrans(int from, int to, const Eigen::Matrix3f &rot, const Eigen::Vector3f &move)
QSharedPointer< FiffCoordTrans > SPtr
FiffCoordTrans inverted() const
void write(QIODevice &p_IODevice)
Writes the transformation to file.
FiffCoordTrans(int from, int to, const Eigen::Matrix4f &matTrans, bool bStandard=false)
static FiffCoordTrans procrustesAlign(int from_frame, int to_frame, float **fromp, float **top, float *w, int np, float max_diff)
float translationTo(Eigen::MatrixX4f mTransDest)
std::unique_ptr< FiffCoordTrans > UPtr
static FiffCoordTrans fromCardinalPoints(int from, int to, const float *rL, const float *rN, const float *rR)
QSharedPointer< const FiffCoordTrans > ConstSPtr
Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
float angleTo(Eigen::MatrixX4f mTransDest)
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > trans
static FiffCoordTrans readFromTag(const QSharedPointer< FiffTag > &tag)
void writeToStream(FiffStream *p_pStream)
Writes the transformation to a FIFF stream.
static QString frame_name(int frame)
static bool addInverse(FiffCoordTrans &t)
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > invtrans
QSharedPointer< FiffDirNode > SPtr
FIFF File I/O routines.
QSharedPointer< FiffStream > SPtr
FIFF data tag.
Definition fiff_tag.h:152