v2.0.0
Loading...
Searching...
No Matches
fiff_coord_trans.h
Go to the documentation of this file.
1//=============================================================================================================
31
32#ifndef FIFF_COORD_TRANS_H
33#define FIFF_COORD_TRANS_H
34
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "fiff_global.h"
40#include "fiff_types.h"
41#include "fiff_stream.h"
42#include "fiff_dir_node.h"
43
44//=============================================================================================================
45// QT INCLUDES
46//=============================================================================================================
47
48#include <QIODevice>
49#include <QSharedPointer>
50
51#include <memory>
52
53//=============================================================================================================
54// EIGEN INCLUDES
55//=============================================================================================================
56
57#include <Eigen/Core>
58
59//=============================================================================================================
60// DEFINE NAMESPACE FIFFLIB
61//=============================================================================================================
62
63namespace FIFFLIB
64{
65
66// Forward declaration
67class FiffTag;
68
69//=============================================================================================================
83{
84public:
85 using SPtr = QSharedPointer<FiffCoordTrans>;
86 using ConstSPtr = QSharedPointer<const FiffCoordTrans>;
87 using UPtr = std::unique_ptr<FiffCoordTrans>;
88 using ConstUPtr = std::unique_ptr<const FiffCoordTrans>;
89
90 //=========================================================================================================
95
96 //=========================================================================================================
102 FiffCoordTrans(QIODevice& p_IODevice);
103
104 //=========================================================================================================
110 FiffCoordTrans(const FiffCoordTrans& p_FiffCoordTrans);
111
112 //=========================================================================================================
123 FiffCoordTrans& operator=(const FiffCoordTrans& p_FiffCoordTrans) = default;
124
125 //=========================================================================================================
134 FiffCoordTrans(int from, int to, const Eigen::Matrix3f& rot, const Eigen::Vector3f& move);
135
136 //=========================================================================================================
145 FiffCoordTrans(int from, int to, const Eigen::Matrix4f& matTrans, bool bStandard = false);
146
147 //=========================================================================================================
152
153 //=========================================================================================================
157 void clear();
158
159 //=========================================================================================================
167
168 //=========================================================================================================
174 inline bool isEmpty() const
175 {
176 return this->from < 0;
177 }
178
179 //=========================================================================================================
187
193 auto rot()
194 {
195 return trans.block<3, 3>(0, 0);
196 }
197
202 auto rot() const
203 {
204 return trans.block<3, 3>(0, 0);
205 }
206
212 auto move()
213 {
214 return trans.block<3, 1>(0, 3);
215 }
216
221 auto move() const
222 {
223 return trans.block<3, 1>(0, 3);
224 }
225
231 auto invrot()
232 {
233 return invtrans.block<3, 3>(0, 0);
234 }
235
240 auto invrot() const
241 {
242 return invtrans.block<3, 3>(0, 0);
243 }
244
250 auto invmove()
251 {
252 return invtrans.block<3, 1>(0, 3);
253 }
254
259 auto invmove() const
260 {
261 return invtrans.block<3, 1>(0, 3);
262 }
263
264
265 //=========================================================================================================
275 static bool read(QIODevice& p_IODevice, FiffCoordTrans& p_Trans);
276
277 //=========================================================================================================
287 static FiffCoordTrans readTransform(const QString& name, int from, int to);
288
289 //=========================================================================================================
297 static FiffCoordTrans readMriTransform(const QString& name);
298
299 //=========================================================================================================
307 static FiffCoordTrans readMeasTransform(const QString& name);
308
309 //=========================================================================================================
319 static FiffCoordTrans readTransformAscii(const QString& name, int from, int to);
320
321 //=========================================================================================================
329 static FiffCoordTrans readFShead2mriTransform(const QString& name);
330
331 //=========================================================================================================
342 Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f& rr, bool do_move = true) const;
343
344 //=========================================================================================================
353 Eigen::MatrixX3f apply_inverse_trans(const Eigen::MatrixX3f& rr, bool do_move = true) const;
354
355 //=========================================================================================================
363 static void apply_trans(float r[3], const FiffCoordTrans& t, bool do_move);
364
365 //=========================================================================================================
373 static void apply_inverse_trans(float r[3], const FiffCoordTrans& t, bool do_move);
374
375 //=========================================================================================================
383 static QString frame_name(int frame);
384
385 //=========================================================================================================
394 static FiffCoordTrans identity(int from, int to);
395
396 //=========================================================================================================
403
404 //=========================================================================================================
416 static FiffCoordTrans combine(int from, int to, const FiffCoordTrans& t1, const FiffCoordTrans& t2);
417
418 //=========================================================================================================
430 static FiffCoordTrans fromCardinalPoints(int from, int to, const float* rL, const float* rN, const float* rR);
431
432 //=========================================================================================================
438 static bool addInverse(FiffCoordTrans& t);
439
440 //=========================================================================================================
444 void print() const;
445
446 //=========================================================================================================
454 bool write(QIODevice& p_IODevice);
455
456 //=========================================================================================================
462 void writeToStream(FiffStream* p_pStream);
463
464 //=========================================================================================================
470 inline static qint32 storageSize();
471
472 //========================================================================================================
481 friend bool operator==(const FiffCoordTrans& a, const FiffCoordTrans& b);
482
483 //========================================================================================================
491 float angleTo(Eigen::MatrixX4f mTransDest);
492
493 //========================================================================================================
501 float translationTo(Eigen::MatrixX4f mTransDest);
502
503 //========================================================================================================
511 static FiffCoordTrans readFromTag(const std::unique_ptr<FiffTag>& tag);
512
513 //========================================================================================================
525 const FiffDirNode::SPtr& node,
526 int from, int to);
527
528 //========================================================================================================
541 static FiffCoordTrans procrustesAlign(int from_frame, int to_frame,
542 const Eigen::MatrixXf& fromp,
543 const Eigen::MatrixXf& top,
544 const Eigen::VectorXf& w,
545 float max_diff);
546
547public:
550 Eigen::Matrix<float, 4, 4, Eigen::DontAlign> trans;
551 Eigen::Matrix<float, 4, 4, Eigen::DontAlign> invtrans;
552};
553
554//=============================================================================================================
555// INLINE DEFINITIONS
556//=============================================================================================================
557
559{
560 // On-disk layout: from, to, rot[3][3], move[3], invrot[3][3], invmove[3]
561 // (C++ class uses Matrix4f but on-disk stores 3x3 rot + 3-vec separately)
562 return 2 * sizeof(fiff_int_t) + 2 * 12 * sizeof(fiff_float_t);
563}
564
565//=============================================================================================================
566
567inline bool operator==(const FiffCoordTrans& a, const FiffCoordTrans& b)
568{
569 return (a.from == b.from &&
570 a.to == b.to &&
571 a.trans.isApprox(b.trans, 0.0001f) &&
572 a.invtrans.isApprox(b.invtrans, 0.0001f));
573}
574} // NAMESPACE
575
576#ifndef metatype_fiffcoordtrans
577#define metatype_fiffcoordtrans
579#endif
580
581#ifndef metatype_fiffcoordtrans_sptr
582#define metatype_fiffcoordtrans_sptr
584#endif
585
586#endif // FIFF_COORD_TRANS_H
FIFF binary tag-stream layer: wraps a QIODevice to read and write FIFF tags, directories,...
Q_DECLARE_METATYPE(FIFFLIB::FiffCoordTrans)
Export/import macros and build-info accessors for the FIFFLIB shared library.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:44
Recursive node of the parsed FIFF block tree (FIFFB_* hierarchy with directory entries and children).
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.
qint32 fiff_int_t
Definition fiff_types.h:86
float fiff_float_t
Definition fiff_types.h:90
bool operator==(const FiffChInfo &a, const FiffChInfo &b)
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > invtrans
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)
friend bool operator==(const FiffCoordTrans &a, const FiffCoordTrans &b)
QSharedPointer< FiffCoordTrans > SPtr
FiffCoordTrans(int from, int to, const Eigen::Matrix3f &rot, const Eigen::Vector3f &move)
FiffCoordTrans & operator=(const FiffCoordTrans &p_FiffCoordTrans)=default
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
bool write(QIODevice &p_IODevice)
Writes the transformation to file.
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)
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)
Eigen::Matrix< float, 4, 4, Eigen::DontAlign > trans
static void apply_trans(float r[3], const FiffCoordTrans &t, bool do_move)
static FiffCoordTrans readTransform(const QString &name, int from, int to)
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:161