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 <iostream>
25#include <QDebug>
26
27#include <stdexcept>
28//=============================================================================================================
29// USED NAMESPACES
30//=============================================================================================================
31
32using namespace FIFFLIB;
33
34//=============================================================================================================
35// DEFINE MEMBER METHODS
36//=============================================================================================================
37
46
47//=============================================================================================================
48
50
51//=============================================================================================================
52
54: head_mri_t(p_FiffDigitizerData.head_mri_t ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t) : nullptr)
55, head_mri_t_adj(p_FiffDigitizerData.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t_adj) : nullptr)
56, points(p_FiffDigitizerData.points)
57, coord_frame(p_FiffDigitizerData.coord_frame)
58, active(p_FiffDigitizerData.active)
59, discard(p_FiffDigitizerData.discard)
60, npoint(p_FiffDigitizerData.npoint)
61, mri_fids(p_FiffDigitizerData.mri_fids)
62, show(p_FiffDigitizerData.show)
63, show_minimal(p_FiffDigitizerData.show_minimal)
64, dist(p_FiffDigitizerData.dist)
65, closest(p_FiffDigitizerData.closest)
66, closest_point(p_FiffDigitizerData.closest_point)
67, dist_valid(p_FiffDigitizerData.dist_valid)
68{
69}
70
71//=============================================================================================================
72
74{
75 if (this != &rhs) {
76 head_mri_t = rhs.head_mri_t ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t) : nullptr;
77 head_mri_t_adj = rhs.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t_adj) : nullptr;
78 filename = rhs.filename;
79 points = rhs.points;
81 active = rhs.active;
82 discard = rhs.discard;
83 npoint = rhs.npoint;
84 mri_fids = rhs.mri_fids;
85 show = rhs.show;
87 dist = rhs.dist;
88 closest = rhs.closest;
91 }
92 return *this;
93}
94
95//=============================================================================================================
96
99, npoint(0)
100, show(false)
101, show_minimal(false)
102, dist_valid(false)
103{
104 // Open the io device
105 FiffStream::SPtr t_pStream(new FiffStream(&p_IODevice));
106 bool open_here = false;
107
108 //Open if the device and stream have not been openend already
109 if (!t_pStream->device()->isOpen()) {
110 if(!t_pStream->open()) {
111 throw std::runtime_error("Could not open the digitizer data file");
112 }
113
114 open_here = true;
115 }
116
117 // If device is open read the data
118 if(!t_pStream->read_digitizer_data(t_pStream->dirtree(), *this)) {
119 throw std::runtime_error("Could not read the FiffDigitizerData");
120 }
121
122 // If stream has been opened in this function also close here again
123 if(open_here) {
124 t_pStream->close();
125 }
126}
127
128//=============================================================================================================
129
131{
132 std::cout << "Number of digitizer points: " << points.size() << "\n";
133
134 switch(coord_frame){
135 case FIFFV_COORD_MRI:
136 std::cout << "Coord. Frame: FIFFV_COORD_MRI \n";
137 break;
138 case FIFFV_COORD_HEAD:
139 std::cout << "Coord. Frame: FIFFV_COORD_HEAD \n";
140 break;
141 }
142
143 for (auto& point : points){
144 if (point.kind == FIFFV_POINT_HPI){
145 std::cout << "HPI Point " << point.ident << " - " << point.r[0] << ", " << point.r[1] << ", " << point.r[2] << "\n";
146 }
147 }
148
149 std::cout << "Number of MRI fiducials: " << nfids() << "\n";
150
151 if (head_mri_t){
152
153 }
154}
155
156//=============================================================================================================
157
159{
160 // Clear any existing MRI fiducials
161 mri_fids.clear();
162
163 if (!head_mri_t_adj) {
164 return;
165 }
166
167 // Extract cardinal points and transform them into MRI coordinates.
168 // This mirrors the original C function update_fids_from_dig_data
169 // from mne_analyze/adjust_alignment.c.
170 for (int k = 0; k < npoint; ++k) {
171 if (points[k].kind == FIFFV_POINT_CARDINAL) {
172 FiffDigPoint fid = points[k];
174 mri_fids.append(fid);
175 }
176 }
177}
#define FIFFV_POINT_CARDINAL
#define FIFFV_COORD_HEAD
#define FIFFV_COORD_MRI
#define FIFFV_COORD_UNKNOWN
#define FIFFV_POINT_HPI
High-level digitization data: dig points plus the device→head transform and fitting metadata that tog...
4x4 affine FIFF coordinate transform (FIFF_COORD_TRANS) annotated with source/destination coordinate-...
FIFF binary tag-stream layer: wraps a QIODevice to read and write FIFF tags, directories,...
Single digitization point (FIFF_DIG_POINT) with kind (cardinal/HPI/EEG/extra), identifier and 3D coor...
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