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//=============================================================================================================
49// USED NAMESPACES
50//=============================================================================================================
51
52using namespace FIFFLIB;
53
54//=============================================================================================================
55// DEFINE MEMBER METHODS
56//=============================================================================================================
57
66
67//=============================================================================================================
68
70
71//=============================================================================================================
72
74: head_mri_t(p_FiffDigitizerData.head_mri_t ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t) : nullptr)
75, head_mri_t_adj(p_FiffDigitizerData.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*p_FiffDigitizerData.head_mri_t_adj) : nullptr)
76, points(p_FiffDigitizerData.points)
77, coord_frame(p_FiffDigitizerData.coord_frame)
78, active(p_FiffDigitizerData.active)
79, discard(p_FiffDigitizerData.discard)
80, npoint(p_FiffDigitizerData.npoint)
81, mri_fids(p_FiffDigitizerData.mri_fids)
82, show(p_FiffDigitizerData.show)
83, show_minimal(p_FiffDigitizerData.show_minimal)
84, dist(p_FiffDigitizerData.dist)
85, closest(p_FiffDigitizerData.closest)
86, closest_point(p_FiffDigitizerData.closest_point)
87, dist_valid(p_FiffDigitizerData.dist_valid)
88{
89}
90
91//=============================================================================================================
92
94{
95 if (this != &rhs) {
96 head_mri_t = rhs.head_mri_t ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t) : nullptr;
97 head_mri_t_adj = rhs.head_mri_t_adj ? std::make_unique<FiffCoordTrans>(*rhs.head_mri_t_adj) : nullptr;
98 filename = rhs.filename;
99 points = rhs.points;
101 active = rhs.active;
102 discard = rhs.discard;
103 npoint = rhs.npoint;
104 mri_fids = rhs.mri_fids;
105 show = rhs.show;
107 dist = rhs.dist;
108 closest = rhs.closest;
111 }
112 return *this;
113}
114
115//=============================================================================================================
116
119, npoint(0)
120, show(false)
121, show_minimal(false)
122, dist_valid(false)
123{
124 // Open the io device
125 FiffStream::SPtr t_pStream(new FiffStream(&p_IODevice));
126 bool open_here = false;
127
128 //Open if the device and stream have not been openend already
129 if (!t_pStream->device()->isOpen()) {
130 if(!t_pStream->open()) {
131 qWarning() << "Warning in FiffDigitizerData::FiffDigitizerData - Could not open the didigitzer data file"; // ToDo throw error
132 return;
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 qWarning() << "Warning in FiffDigitizerData::FiffDigitizerData - Could not read the FiffDigitizerData"; // ToDo throw error
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}
#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