v2.0.0
Loading...
Searching...
No Matches
mne_hemisphere.h
Go to the documentation of this file.
1//=============================================================================================================
24
25#ifndef MNE_HEMISPHERE_H
26#define MNE_HEMISPHERE_H
27
28//=============================================================================================================
29// INCLUDES
30//=============================================================================================================
31
32#include "mne_global.h"
33#include "mne_source_space.h"
34#include "mne_cluster_info.h"
35
36#include <fiff/fiff_types.h>
37#include <fiff/fiff.h>
38
39//=============================================================================================================
40// EIGEN INCLUDES
41//=============================================================================================================
42
43#include <Eigen/Core>
44#include <Eigen/SparseCore>
45
46//=============================================================================================================
47// QT INCLUDES
48//=============================================================================================================
49
50#include <QList>
51#include <vector>
52
53//=============================================================================================================
54// DEFINE NAMESPACE MNELIB
55//=============================================================================================================
56
57namespace MNELIB
58{
59
60//=============================================================================================================
61// FORWARD DECLARATIONS
62//=============================================================================================================
63
64//=============================================================================================================
71{
72public:
73 using SPtr = std::shared_ptr<MNEHemisphere>;
74 using ConstSPtr = std::shared_ptr<const MNEHemisphere>;
75
76 //=========================================================================================================
81
82 //=========================================================================================================
88 MNEHemisphere(const MNEHemisphere& p_MNEHemisphere);
89
90 //=========================================================================================================
94 ~MNEHemisphere() override;
95
96 //=========================================================================================================
102 MNESourceSpace::SPtr clone() const override;
103
104 //=========================================================================================================
112 bool add_geometry_info();
113
114 //=========================================================================================================
122
123 //=========================================================================================================
130 bool compute_patch_info();
131
132 //=========================================================================================================
136 void clear();
137
138 //=========================================================================================================
146 Eigen::MatrixXf& getTriCoords(float p_fScaling = 1.0f);
147
148 //=========================================================================================================
154 inline bool isClustered() const;
155
156 //=========================================================================================================
170 bool transform_hemisphere_to(FIFFLIB::fiff_int_t dest, const FIFFLIB::FiffCoordTrans &p_Trans);
171
172 //=========================================================================================================
182 void writeToStream(FIFFLIB::FiffStream* p_pStream);
183
184 //=========================================================================================================
193
194 //ToDo write(IODevice &)
195
203 friend bool operator== (const MNEHemisphere &a, const MNEHemisphere &b);
204
205public:
206 // --- Fields inherited from MNESurfaceOrVolume via MNESourceSpace ---
207 // type, id, np, ntri, coord_frame, rr, nn, nuse, inuse, vertno,
208 // nuse_tri, dist_limit, dist, nearest, neighbor_tri, neighbor_vert
209 // are all available through the base class.
210 // Use nearestVertIdx() / nearestDistVec() accessors for VectorXi/VectorXd views.
211
212 // --- Shadowing fields (different type from base — TODO: unify in Phase 2) ---
213 // tris / use_tris removed: now use inherited itris / use_itris (TrianglesT, row-major)
214 // nearest / nearest_dist removed: now use inherited vector<MNENearest> nearest
215 // + nearestVertIdx() / nearestDistVec() accessors
216 // dist removed: now use inherited FiffSparseMatrix dist + toEigenSparse() / fromEigenSparse()
217 QList<Eigen::VectorXi> pinfo;
218 Eigen::VectorXi patch_inds;
219
220 // --- MNEHemisphere-specific fields ---
221 Eigen::MatrixX3d tri_cent;
222 Eigen::MatrixX3d tri_nn;
223 Eigen::VectorXd tri_area;
224 Eigen::MatrixX3d use_tri_cent;
225 Eigen::MatrixX3d use_tri_nn;
226 Eigen::VectorXd use_tri_area;
227
229private:
230 // Newly added
231 Eigen::MatrixXf m_TriCoords;
232};
233
234//=============================================================================================================
235// INLINE DEFINITIONS
236//=============================================================================================================
237
238inline bool MNEHemisphere::isClustered() const
239{
240 return !cluster_info.isEmpty();
241}
242
243//=============================================================================================================
244
245inline bool operator== (const MNEHemisphere &a, const MNEHemisphere &b)
246{
247 if(a.pinfo.size() == b.pinfo.size()) {
248 for(int i = 0; i < a.pinfo.size(); ++i) {
249 if(!a.pinfo.at(i).isApprox(b.pinfo.at(i))) {
250 return false;
251 }
252 }
253 } else {
254 return false;
255 }
256
257 return (a.type == b.type &&
258 a.id == b.id &&
259 a.np == b.np &&
260 a.ntri == b.ntri &&
261 a.coord_frame == b.coord_frame &&
262 a.rr.isApprox(b.rr, 0.0001f) &&
263 a.nn.isApprox(b.nn, 0.0001f) &&
264 a.itris.isApprox(b.itris) &&
265 a.nuse == b.nuse &&
266 a.inuse.isApprox(b.inuse) &&
267 a.vertno.isApprox(b.vertno) &&
268 a.nuse_tri == b.nuse_tri &&
269 a.use_itris.isApprox(b.use_itris) &&
270 a.nearestVertIdx().isApprox(b.nearestVertIdx()) &&
271 a.nearestDistVec().isApprox(b.nearestDistVec(), 0.0001) &&
272 a.patch_inds.isApprox(b.patch_inds) &&
273 //a.dist_limit == b.dist_limit && //TODO: We still not sure if dist_limit can also be a matrix. This needs to be debugged
274 [&a, &b]() {
275 const auto& sa = a.dist.eigen();
276 const auto& sb = b.dist.eigen();
277 if (sa.rows() == 0 && sb.rows() == 0 && sa.cols() == 0 && sb.cols() == 0)
278 return true;
279 return sa.toDense().isApprox(sb.toDense(), 0.0001f);
280 }() &&
281 a.tri_cent.isApprox(b.tri_cent, 0.0001) &&
282 a.tri_nn.isApprox(b.tri_nn, 0.0001) &&
283 a.tri_area.isApprox(b.tri_area, 0.0001) &&
284 a.use_tri_cent.isApprox(b.use_tri_cent, 0.0001) &&
285 a.use_tri_nn.isApprox(b.use_tri_nn, 0.0001) &&
286 a.use_tri_area.isApprox(b.use_tri_area, 0.0001) &&
287 [&a, &b]() {
288 if (a.neighbor_tri.size() != b.neighbor_tri.size()) return false;
289 for (size_t i = 0; i < a.neighbor_tri.size(); ++i) {
290 if (a.neighbor_tri[i].size() != b.neighbor_tri[i].size()) return false;
291 if (a.neighbor_tri[i].size() > 0 && !(a.neighbor_tri[i].array() == b.neighbor_tri[i].array()).all()) return false;
292 }
293 return true;
294 }() &&
295 [&a, &b]() {
296 if (a.neighbor_vert.size() != b.neighbor_vert.size()) return false;
297 for (size_t i = 0; i < a.neighbor_vert.size(); ++i) {
298 if (a.neighbor_vert[i].size() != b.neighbor_vert[i].size()) return false;
299 if (a.neighbor_vert[i].size() > 0 && !(a.neighbor_vert[i].array() == b.neighbor_vert[i].array()).all()) return false;
300 }
301 return true;
302 }() &&
303 a.cluster_info == b.cluster_info &&
304 a.m_TriCoords.isApprox(b.m_TriCoords, 0.0001f));
305}
306} // NAMESPACE
307
308#endif // MNE_HEMISPHERE_H
bool operator==(const BIDSPath &a, const BIDSPath &b)
MNELIB shared-library export/import macros and library build metadata.
#define MNESHARED_EXPORT
Definition mne_global.h:40
Single-hemisphere source space (cortical surface or volume grid) loaded from FIFF.
Bookkeeping for a label-restricted clustering of source-space leadfield columns.
Static MATLAB-style FIFF facade: thin wrapper functions kept for parity with the historical mne-matla...
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
Core MNE data structures (source spaces, source estimates, hemispheres).
bool operator==(const MNEClusterInfo &a, const MNEClusterInfo &b)
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
Cluster table used to compress and reconstruct a clustered leadfield.
void writeToStream(FIFFLIB::FiffStream *p_pStream)
Eigen::MatrixX3d tri_cent
Eigen::VectorXd use_tri_area
Eigen::MatrixX3d use_tri_cent
Eigen::MatrixXf & getTriCoords(float p_fScaling=1.0f)
Eigen::MatrixX3d tri_nn
MNEHemisphere & operator=(const MNEHemisphere &other)
MNESourceSpace::SPtr clone() const override
bool transform_hemisphere_to(FIFFLIB::fiff_int_t dest, const FIFFLIB::FiffCoordTrans &p_Trans)
MNEClusterInfo cluster_info
Eigen::MatrixX3d use_tri_nn
Eigen::VectorXd tri_area
std::shared_ptr< const MNEHemisphere > ConstSPtr
QList< Eigen::VectorXi > pinfo
std::shared_ptr< MNEHemisphere > SPtr
Eigen::VectorXi patch_inds
std::shared_ptr< MNESourceSpace > SPtr
Eigen::VectorXd nearestDistVec() const
Eigen::VectorXi nearestVertIdx() const