v2.0.0
Loading...
Searching...
No Matches
fiff_coord_trans.h
Go to the documentation of this file.
1//=============================================================================================================
32
33#ifndef FIFF_COORD_TRANS_H
34#define FIFF_COORD_TRANS_H
35
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "fiff_global.h"
41#include "fiff_types.h"
42#include "fiff_stream.h"
43#include "fiff_dir_node.h"
44
45//=============================================================================================================
46// QT INCLUDES
47//=============================================================================================================
48
49#include <QIODevice>
50#include <QSharedPointer>
51
52#include <memory>
53
54//=============================================================================================================
55// EIGEN INCLUDES
56//=============================================================================================================
57
58#include <Eigen/Core>
59
60//=============================================================================================================
61// DEFINE NAMESPACE FIFFLIB
62//=============================================================================================================
63
64namespace FIFFLIB
65{
66
67// Forward declaration
68class FiffTag;
69
70//=============================================================================================================
82{
83public:
84 using SPtr = QSharedPointer<FiffCoordTrans>;
85 using ConstSPtr = QSharedPointer<const FiffCoordTrans>;
86 using UPtr = std::unique_ptr<FiffCoordTrans>;
87 using ConstUPtr = std::unique_ptr<const FiffCoordTrans>;
88
89 //=========================================================================================================
94
95 //=========================================================================================================
101 FiffCoordTrans(QIODevice &p_IODevice);
102
103 //=========================================================================================================
109 FiffCoordTrans(const FiffCoordTrans &p_FiffCoordTrans);
110
111 //=========================================================================================================
120 FiffCoordTrans(int from, int to, const Eigen::Matrix3f& rot, const Eigen::Vector3f& move);
121
122 //=========================================================================================================
131 FiffCoordTrans(int from, int to, const Eigen::Matrix4f& matTrans, bool bStandard = false);
132
133 //=========================================================================================================
138
139 //=========================================================================================================
143 void clear();
144
145 //=========================================================================================================
153
154 //=========================================================================================================
160 inline bool isEmpty() const
161 {
162 return this->from < 0;
163 }
164
165 //=========================================================================================================
173
175 auto rot() { return trans.block<3,3>(0,0); }
177 auto rot() const { return trans.block<3,3>(0,0); }
178
180 auto move() { return trans.block<3,1>(0,3); }
182 auto move() const { return trans.block<3,1>(0,3); }
183
185 auto invrot() { return invtrans.block<3,3>(0,0); }
187 auto invrot() const { return invtrans.block<3,3>(0,0); }
188
190 auto invmove() { return invtrans.block<3,1>(0,3); }
192 auto invmove() const { return invtrans.block<3,1>(0,3); }
194
195 //=========================================================================================================
204 static bool read(QIODevice& p_IODevice, FiffCoordTrans& p_Trans);
205
206 //=========================================================================================================
216 static FiffCoordTrans readTransform(const QString& name, int from, int to);
217
218 //=========================================================================================================
226 static FiffCoordTrans readMriTransform(const QString& name);
227
228 //=========================================================================================================
236 static FiffCoordTrans readMeasTransform(const QString& name);
237
238 //=========================================================================================================
248 static FiffCoordTrans readTransformAscii(const QString& name, int from, int to);
249
250 //=========================================================================================================
258 static FiffCoordTrans readFShead2mriTransform(const QString& name);
259
260 //=========================================================================================================
271 Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f& rr, bool do_move = true) const;
272
273 //=========================================================================================================
282 Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f& rr, bool do_move = true) const;
283
284 //=========================================================================================================
292 static void apply_trans(float r[3], const FiffCoordTrans& t, bool do_move);
293
294 //=========================================================================================================
302 static void apply_inverse_trans(float r[3], const FiffCoordTrans& t, bool do_move);
303
304 //=========================================================================================================
312 static QString frame_name (int frame);
313
314 //=========================================================================================================
323 static FiffCoordTrans identity(int from, int to);
324
325 //=========================================================================================================
332
333 //=========================================================================================================
345 static FiffCoordTrans combine(int from, int to, const FiffCoordTrans& t1, const FiffCoordTrans& t2);
346
347 //=========================================================================================================
359 static FiffCoordTrans fromCardinalPoints(int from, int to, const float* rL, const float* rN, const float* rR);
360
361 //=========================================================================================================
367 static bool addInverse(FiffCoordTrans& t);
368
369 //=========================================================================================================
373 void print() const;
374
375 //=========================================================================================================
381 void write(QIODevice &p_IODevice);
382
383 //=========================================================================================================
389 void writeToStream(FiffStream* p_pStream);
390
391 //=========================================================================================================
397 inline static qint32 storageSize();
398
399 //========================================================================================================
407 friend bool operator== (const FiffCoordTrans &a, const FiffCoordTrans &b);
408
409 //========================================================================================================
417 float angleTo(Eigen::MatrixX4f mTransDest);
418
419 //========================================================================================================
427 float translationTo(Eigen::MatrixX4f mTransDest);
428
429 //========================================================================================================
437 static FiffCoordTrans readFromTag(const std::unique_ptr<FiffTag>& tag);
438
439 //========================================================================================================
451 const FiffDirNode::SPtr& node,
452 int from, int to);
453
454 //========================================================================================================
467 static FiffCoordTrans procrustesAlign(int from_frame, int to_frame,
468 const Eigen::MatrixXf& fromp,
469 const Eigen::MatrixXf& top,
470 const Eigen::VectorXf& w,
471 float max_diff);
472
473public:
474 fiff_int_t from;
475 fiff_int_t to;
476 Eigen::Matrix<float, 4,4, Eigen::DontAlign> trans;
477 Eigen::Matrix<float, 4,4, Eigen::DontAlign> invtrans;
478
479};
480
481//=============================================================================================================
482// INLINE DEFINITIONS
483//=============================================================================================================
484
486{
487 // On-disk layout: from, to, rot[3][3], move[3], invrot[3][3], invmove[3]
488 // (C++ class uses Matrix4f but on-disk stores 3x3 rot + 3-vec separately)
489 return 2 * sizeof(fiff_int_t) + 2 * 12 * sizeof(fiff_float_t);
490}
491
492//=============================================================================================================
493
494inline bool operator== (const FiffCoordTrans &a, const FiffCoordTrans &b)
495{
496 return (a.from == b.from &&
497 a.to == b.to &&
498 a.trans.isApprox(b.trans, 0.0001f) &&
499 a.invtrans.isApprox(b.invtrans, 0.0001f));
500}
501} // NAMESPACE
502
503#ifndef metatype_fiffcoordtrans
504#define metatype_fiffcoordtrans
506#endif
507
508#ifndef metatype_fiffcoordtrans_sptr
509#define metatype_fiffcoordtrans_sptr
511#endif
512
513#endif // FIFF_COORD_TRANS_H
bool operator==(const BIDSPath &a, const BIDSPath &b)
Recursive node of the parsed FIFF block tree (FIFFB_* hierarchy with directory entries and children).
Export/import macros and build-info accessors for the FIFFLIB shared library.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:44
Q_DECLARE_METATYPE(FIFFLIB::FiffCoordTrans)
FIFF binary tag-stream layer: wraps a QIODevice to read and write FIFF tags, directories,...
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
FIFF file I/O, in-memory data structures and high-level readers/writers.
bool operator==(const FiffChInfo &a, const FiffChInfo &b)
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
static FiffCoordTrans procrustesAlign(int from_frame, int to_frame, const Eigen::MatrixXf &fromp, const Eigen::MatrixXf &top, const Eigen::VectorXf &w, float max_diff)
static FiffCoordTrans combine(int from, int to, const FiffCoordTrans &t1, const FiffCoordTrans &t2)
static QString frame_name(int frame)
static FiffCoordTrans readTransformFromNode(FiffStream::SPtr &stream, const FiffDirNode::SPtr &node, int from, int to)
QSharedPointer< FiffCoordTrans > SPtr
FiffCoordTrans(int from, int to, const Eigen::Matrix3f &rot, const Eigen::Vector3f &move)
void writeToStream(FiffStream *p_pStream)
Writes the transformation to a FIFF stream.
static FiffCoordTrans readMeasTransform(const QString &name)
static FiffCoordTrans readFShead2mriTransform(const QString &name)
static void apply_inverse_trans(float r[3], const FiffCoordTrans &t, bool do_move)
FiffCoordTrans(int from, int to, const Eigen::Matrix4f &matTrans, bool bStandard=false)
FiffCoordTrans(QIODevice &p_IODevice)
QSharedPointer< const FiffCoordTrans > ConstSPtr
std::unique_ptr< FiffCoordTrans > UPtr
Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
static FiffCoordTrans readMriTransform(const QString &name)
static FiffCoordTrans readTransformAscii(const QString &name, int from, int to)
static bool read(QIODevice &p_IODevice, FiffCoordTrans &p_Trans)
FiffCoordTrans inverted() const
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
float angleTo(Eigen::MatrixX4f mTransDest)
static FiffCoordTrans identity(int from, int to)
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > trans
static FiffCoordTrans fromCardinalPoints(int from, int to, const float *rL, const float *rN, const float *rR)
FiffCoordTrans(const FiffCoordTrans &p_FiffCoordTrans)
std::unique_ptr< const FiffCoordTrans > ConstUPtr
float translationTo(Eigen::MatrixX4f mTransDest)
void write(QIODevice &p_IODevice)
Writes the transformation to file.
static void apply_trans(float r[3], const FiffCoordTrans &t, bool do_move)
static FiffCoordTrans readTransform(const QString &name, int from, int to)
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > invtrans
static bool addInverse(FiffCoordTrans &t)
static FiffCoordTrans readFromTag(const std::unique_ptr< FiffTag > &tag)
QSharedPointer< FiffDirNode > SPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
QSharedPointer< FiffStream > SPtr
FIFF tag: 16-byte header (kind, type, size, next) plus payload, with typed decoders for every FIFFT_*...
Definition fiff_tag.h:159