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#include <QDebug>
47
48#include <stdexcept>
49//=============================================================================================================
50// USED NAMESPACES
51//=============================================================================================================
52
53using namespace FIFFLIB;
54
55//=============================================================================================================
56// DEFINE MEMBER METHODS
57//=============================================================================================================
58
67
68//=============================================================================================================
69
71
72//=============================================================================================================
73
75: head_mri_t(p_FiffDigitizerData.head_mri_t ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t) : nullptr)
76, head_mri_t_adj(p_FiffDigitizerData.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t_adj) : nullptr)
77, points(p_FiffDigitizerData.points)
78, coord_frame(p_FiffDigitizerData.coord_frame)
79, active(p_FiffDigitizerData.active)
80, discard(p_FiffDigitizerData.discard)
81, npoint(p_FiffDigitizerData.npoint)
82, mri_fids(p_FiffDigitizerData.mri_fids)
83, show(p_FiffDigitizerData.show)
84, show_minimal(p_FiffDigitizerData.show_minimal)
85, dist(p_FiffDigitizerData.dist)
86, closest(p_FiffDigitizerData.closest)
87, closest_point(p_FiffDigitizerData.closest_point)
88, dist_valid(p_FiffDigitizerData.dist_valid)
89{
90}
91
92//=============================================================================================================
93
95{
96 if (this != &rhs) {
97 head_mri_t = rhs.head_mri_t ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t) : nullptr;
98 head_mri_t_adj = rhs.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t_adj) : nullptr;
99 filename = rhs.filename;
100 points = rhs.points;
102 active = rhs.active;
103 discard = rhs.discard;
104 npoint = rhs.npoint;
105 mri_fids = rhs.mri_fids;
106 show = rhs.show;
108 dist = rhs.dist;
109 closest = rhs.closest;
112 }
113 return *this;
114}
115
116//=============================================================================================================
117
120, npoint(0)
121, show(false)
122, show_minimal(false)
123, dist_valid(false)
124{
125 // Open the io device
126 FiffStream::SPtr t_pStream(new FiffStream(&p_IODevice));
127 bool open_here = false;
128
129 //Open if the device and stream have not been openend already
130 if (!t_pStream->device()->isOpen()) {
131 if(!t_pStream->open()) {
132 throw std::runtime_error("Could not open the digitizer data file");
133 }
134
135 open_here = true;
136 }
137
138 // If device is open read the data
139 if(!t_pStream->read_digitizer_data(t_pStream->dirtree(), *this)) {
140 throw std::runtime_error("Could not read the FiffDigitizerData");
141 }
142
143 // If stream has been opened in this function also close here again
144 if(open_here) {
145 t_pStream->close();
146 }
147}
148
149//=============================================================================================================
150
152{
153 std::cout << "Number of digitizer points: " << points.size() << "\n";
154
155 switch(coord_frame){
156 case FIFFV_COORD_MRI:
157 std::cout << "Coord. Frame: FIFFV_COORD_MRI \n";
158 break;
159 case FIFFV_COORD_HEAD:
160 std::cout << "Coord. Frame: FIFFV_COORD_HEAD \n";
161 break;
162 }
163
164 for (auto& point : points){
165 if (point.kind == FIFFV_POINT_HPI){
166 std::cout << "HPI Point " << point.ident << " - " << point.r[0] << ", " << point.r[1] << ", " << point.r[2] << "\n";
167 }
168 }
169
170 std::cout << "Number of MRI fiducials: " << nfids() << "\n";
171
172 if (head_mri_t){
173
174 }
175}
176
177//=============================================================================================================
178
180{
181 // Clear any existing MRI fiducials
182 mri_fids.clear();
183
184 if (!head_mri_t_adj) {
185 return;
186 }
187
188 // Extract cardinal points and transform them into MRI coordinates.
189 // This mirrors the original C function update_fids_from_dig_data
190 // from mne_analyze/adjust_alignment.c.
191 for (int k = 0; k < npoint; ++k) {
192 if (points[k].kind == FIFFV_POINT_CARDINAL) {
193 FiffDigPoint fid = points[k];
195 mri_fids.append(fid);
196 }
197 }
198}
FiffDigitizerData class declaration.
FiffCoordTrans class declaration.
FiffStream class declaration.
#define FIFFV_POINT_CARDINAL
#define FIFFV_COORD_HEAD
#define FIFFV_COORD_MRI
#define FIFFV_COORD_UNKNOWN
#define FIFFV_POINT_HPI
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