v2.0.0
Loading...
Searching...
No Matches
fiff_digitizer_data.cpp
Go to the documentation of this file.
1//=============================================================================================================
15
16//=============================================================================================================
17// INCLUDES
18//=============================================================================================================
19
20#include "fiff_digitizer_data.h"
21#include "fiff_coord_trans.h"
22#include "fiff_stream.h"
23#include "fiff_dig_point.h"
24#include <QDebug>
25
26#include <stdexcept>
27//=============================================================================================================
28// USED NAMESPACES
29//=============================================================================================================
30
31using namespace FIFFLIB;
32
33//=============================================================================================================
34// DEFINE MEMBER METHODS
35//=============================================================================================================
36
45
46//=============================================================================================================
47
49
50//=============================================================================================================
51
53: head_mri_t(p_FiffDigitizerData.head_mri_t ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t) : nullptr)
54, head_mri_t_adj(p_FiffDigitizerData.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t_adj) : nullptr)
55, points(p_FiffDigitizerData.points)
56, coord_frame(p_FiffDigitizerData.coord_frame)
57, active(p_FiffDigitizerData.active)
58, discard(p_FiffDigitizerData.discard)
59, npoint(p_FiffDigitizerData.npoint)
60, mri_fids(p_FiffDigitizerData.mri_fids)
61, show(p_FiffDigitizerData.show)
62, show_minimal(p_FiffDigitizerData.show_minimal)
63, dist(p_FiffDigitizerData.dist)
64, closest(p_FiffDigitizerData.closest)
65, closest_point(p_FiffDigitizerData.closest_point)
66, dist_valid(p_FiffDigitizerData.dist_valid)
67{
68}
69
70//=============================================================================================================
71
73{
74 if (this != &rhs) {
75 head_mri_t = rhs.head_mri_t ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t) : nullptr;
76 head_mri_t_adj = rhs.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t_adj) : nullptr;
77 filename = rhs.filename;
78 points = rhs.points;
80 active = rhs.active;
81 discard = rhs.discard;
82 npoint = rhs.npoint;
83 mri_fids = rhs.mri_fids;
84 show = rhs.show;
86 dist = rhs.dist;
87 closest = rhs.closest;
90 }
91 return *this;
92}
93
94//=============================================================================================================
95
98, npoint(0)
99, show(false)
100, show_minimal(false)
101, dist_valid(false)
102{
103 // Open the io device
104 FiffStream::SPtr t_pStream(new FiffStream(&p_IODevice));
105 bool open_here = false;
106
107 //Open if the device and stream have not been openend already
108 if (!t_pStream->device()->isOpen()) {
109 if (!t_pStream->open()) {
110 throw std::runtime_error("Could not open the digitizer data file");
111 }
112
113 open_here = true;
114 }
115
116 // If device is open read the data
117 if (!t_pStream->read_digitizer_data(t_pStream->dirtree(), *this)) {
118 throw std::runtime_error("Could not read the FiffDigitizerData");
119 }
120
121 // If stream has been opened in this function also close here again
122 if (open_here) {
123 t_pStream->close();
124 }
125}
126
127//=============================================================================================================
128
130{
131 qInfo().noquote().nospace() << "Number of digitizer points: " << points.size();
132
133 switch (coord_frame) {
134 case FIFFV_COORD_MRI:
135 qInfo().noquote().nospace() << "Coord. Frame: FIFFV_COORD_MRI";
136 break;
137 case FIFFV_COORD_HEAD:
138 qInfo().noquote().nospace() << "Coord. Frame: FIFFV_COORD_HEAD";
139 break;
140 }
141
142 for (auto& point : points) {
143 if (point.kind == FIFFV_POINT_HPI) {
144 qInfo().noquote().nospace() << "HPI Point " << point.ident << " - " << point.r[0] << ", " << point.r[1] << ", " << point.r[2];
145 }
146 }
147
148 qInfo().noquote().nospace() << "Number of MRI fiducials: " << nfids();
149
150 if (head_mri_t) {
151 }
152}
153
154//=============================================================================================================
155
157{
158 // Clear any existing MRI fiducials
159 mri_fids.clear();
160
161 if (!head_mri_t_adj) {
162 return;
163 }
164
165 // Extract cardinal points and transform them into MRI coordinates.
166 // This mirrors the original C function update_fids_from_dig_data
167 // from mne_analyze/adjust_alignment.c.
168 for (int k = 0; k < npoint; ++k) {
169 if (points[k].kind == FIFFV_POINT_CARDINAL) {
170 FiffDigPoint fid = points[k];
172 mri_fids.append(fid);
173 }
174 }
175}
constexpr auto FIFFV_COORD_HEAD
constexpr auto FIFFV_POINT_CARDINAL
constexpr auto FIFFV_POINT_HPI
constexpr auto FIFFV_COORD_UNKNOWN
constexpr auto FIFFV_COORD_MRI
FIFF binary tag-stream layer: wraps a QIODevice to read and write FIFF tags, directories,...
4x4 affine FIFF coordinate transform (FIFF_COORD_TRANS) annotated with source/destination coordinate-...
Single digitization point (FIFF_DIG_POINT) with kind (cardinal/HPI/EEG/extra), identifier and 3D coor...
High-level digitization data: dig points plus the device→head transform and fitting metadata that tog...
FIFF file I/O, in-memory data structures and high-level readers/writers.
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
One digitizer point: kind (cardinal/HPI/EEG/extra), ident, 3D position in FIFFV_COORD_HEAD.
QList< FIFFLIB::FiffDigPoint > points
std::unique_ptr< FiffCoordTrans > head_mri_t_adj
Eigen::Matrix< float, Eigen::Dynamic, 3, Eigen::RowMajor > closest_point
std::unique_ptr< FiffCoordTrans > head_mri_t
FiffDigitizerData & operator=(const FiffDigitizerData &rhs)
QList< FIFFLIB::FiffDigPoint > mri_fids
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
QSharedPointer< FiffStream > SPtr