v2.0.0
Loading...
Searching...
No Matches
fiff_digitizer_data.cpp
Go to the documentation of this file.
1//=============================================================================================================
36
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "fiff_digitizer_data.h"
42#include "fiff_coord_trans.h"
43#include "fiff_stream.h"
44#include "fiff_dig_point.h"
45#include <iostream>
46
47//=============================================================================================================
48// USED NAMESPACES
49//=============================================================================================================
50
51using namespace FIFFLIB;
52
53//=============================================================================================================
54// DEFINE MEMBER METHODS
55//=============================================================================================================
56
65
66//=============================================================================================================
67
69
70//=============================================================================================================
71
73: head_mri_t(p_FiffDigitizerData.head_mri_t ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t) : nullptr)
74, head_mri_t_adj(p_FiffDigitizerData.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t_adj) : nullptr)
75, points(p_FiffDigitizerData.points)
76, coord_frame(p_FiffDigitizerData.coord_frame)
77, active(p_FiffDigitizerData.active)
78, discard(p_FiffDigitizerData.discard)
79, npoint(p_FiffDigitizerData.npoint)
80, mri_fids(p_FiffDigitizerData.mri_fids)
81, show(p_FiffDigitizerData.show)
82, show_minimal(p_FiffDigitizerData.show_minimal)
83, dist(p_FiffDigitizerData.dist)
84, closest(p_FiffDigitizerData.closest)
85, closest_point(p_FiffDigitizerData.closest_point)
86, dist_valid(p_FiffDigitizerData.dist_valid)
87{
88}
89
90//=============================================================================================================
91
93{
94 if (this != &rhs) {
95 head_mri_t = rhs.head_mri_t ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t) : nullptr;
96 head_mri_t_adj = rhs.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t_adj) : nullptr;
97 filename = rhs.filename;
98 points = rhs.points;
100 active = rhs.active;
101 discard = rhs.discard;
102 npoint = rhs.npoint;
103 mri_fids = rhs.mri_fids;
104 show = rhs.show;
106 dist = rhs.dist;
107 closest = rhs.closest;
110 }
111 return *this;
112}
113
114//=============================================================================================================
115
118, npoint(0)
119, show(false)
120, show_minimal(false)
121, dist_valid(false)
122{
123 // Open the io device
124 FiffStream::SPtr t_pStream(new FiffStream(&p_IODevice));
125 bool open_here = false;
126
127 //Open if the device and stream have not been openend already
128 if (!t_pStream->device()->isOpen()) {
129 if(!t_pStream->open()) {
130 qWarning() << "Warning in FiffDigitizerData::FiffDigitizerData - Could not open the didigitzer data file"; // ToDo throw error
131 return;
132 }
133
134 open_here = true;
135 }
136
137 // If device is open read the data
138 if(!t_pStream->read_digitizer_data(t_pStream->dirtree(), *this)) {
139 qWarning() << "Warning in FiffDigitizerData::FiffDigitizerData - Could not read the FiffDigitizerData"; // ToDo throw error
140 }
141
142 // If stream has been opened in this function also close here again
143 if(open_here) {
144 t_pStream->close();
145 }
146}
147
148//=============================================================================================================
149
151{
152 std::cout << "Number of digitizer points: " << points.size() << "\n";
153
154 switch(coord_frame){
155 case FIFFV_COORD_MRI:
156 std::cout << "Coord. Frame: FIFFV_COORD_MRI \n";
157 break;
158 case FIFFV_COORD_HEAD:
159 std::cout << "Coord. Frame: FIFFV_COORD_HEAD \n";
160 break;
161 }
162
163 for (auto& point : points){
164 if (point.kind == FIFFV_POINT_HPI){
165 std::cout << "HPI Point " << point.ident << " - " << point.r[0] << ", " << point.r[1] << ", " << point.r[2] << "\n";
166 }
167 }
168
169 std::cout << "Number of MRI fiducials: " << nfids() << "\n";
170
171 if (head_mri_t){
172
173 }
174}
175
176//=============================================================================================================
177
179{
180 // Clear any existing MRI fiducials
181 mri_fids.clear();
182
183 if (!head_mri_t_adj) {
184 return;
185 }
186
187 // Extract cardinal points and transform them into MRI coordinates.
188 // This mirrors the original C function update_fids_from_dig_data
189 // from mne_analyze/adjust_alignment.c.
190 for (int k = 0; k < npoint; ++k) {
191 if (points[k].kind == FIFFV_POINT_CARDINAL) {
192 FiffDigPoint fid = points[k];
194 mri_fids.append(fid);
195 }
196 }
197}
#define FIFFV_POINT_CARDINAL
#define FIFFV_COORD_HEAD
#define FIFFV_COORD_MRI
#define FIFFV_COORD_UNKNOWN
#define FIFFV_POINT_HPI
FiffStream class declaration.
FiffDigitizerData class declaration.
FiffCoordTrans class declaration.
FiffDigPoint class declaration.
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
Coordinate transformation description.
Eigen::MatrixX3f apply_trans(const Eigen::MatrixX3f &rr, bool do_move=true) const
Digitization point description.
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 File I/O routines.
QSharedPointer< FiffStream > SPtr