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//=============================================================================================================
73{
74public:
75 using SPtr = std::shared_ptr<MNEHemisphere>;
76 using ConstSPtr = std::shared_ptr<const MNEHemisphere>;
77
78 //=========================================================================================================
83
84 //=========================================================================================================
90 MNEHemisphere(const MNEHemisphere& p_MNEHemisphere);
91
92 //=========================================================================================================
96 ~MNEHemisphere() override;
97
98 //=========================================================================================================
104 MNESourceSpace::SPtr clone() const override;
105
106 //=========================================================================================================
112 bool add_geometry_info();
113
114 //=========================================================================================================
122
123 //=========================================================================================================
130 bool compute_patch_info();
131
132 //=========================================================================================================
136 void clear();
137
138 //=========================================================================================================
144 inline bool isClustered() const;
145
146 //=========================================================================================================
161
162 //=========================================================================================================
172 void writeToStream(FIFFLIB::FiffStream* p_pStream);
173
174 //=========================================================================================================
183
184 //ToDo write(IODevice &)
185
194 friend bool operator==(const MNEHemisphere& a, const MNEHemisphere& b);
195
196public:
197 // --- Fields inherited from MNESurfaceOrVolume via MNESourceSpace ---
198 // type, id, np, ntri, coord_frame, rr, nn, nuse, inuse, vertno,
199 // nuse_tri, dist_limit, dist, nearest, neighbor_tri, neighbor_vert
200 // are all available through the base class.
201 // Use nearestVertIdx() / nearestDistVec() accessors for VectorXi/VectorXd views.
202
203 // --- Shadowing fields (different type from base — TODO: unify in Phase 2) ---
204 // tris / use_tris removed: now use inherited itris / use_itris (TrianglesT, row-major)
205 // nearest / nearest_dist removed: now use inherited vector<MNENearest> nearest
206 // + nearestVertIdx() / nearestDistVec() accessors
207 // dist removed: now use inherited FiffSparseMatrix dist + toEigenSparse() / fromEigenSparse()
208 QList<Eigen::VectorXi> pinfo;
209 Eigen::VectorXi patch_inds;
210
211 // --- MNEHemisphere-specific fields ---
212 Eigen::MatrixX3d tri_cent;
213 Eigen::MatrixX3d tri_nn;
214 Eigen::VectorXd tri_area;
215 Eigen::MatrixX3d use_tri_cent;
216 Eigen::MatrixX3d use_tri_nn;
217 Eigen::VectorXd use_tri_area;
218
220};
221
222//=============================================================================================================
223// INLINE DEFINITIONS
224//=============================================================================================================
225
226inline bool MNEHemisphere::isClustered() const
227{
228 return !cluster_info.isEmpty();
229}
230
231//=============================================================================================================
232
233inline bool operator==(const MNEHemisphere& a, const MNEHemisphere& b)
234{
235 if (a.pinfo.size() == b.pinfo.size()) {
236 for (int i = 0; i < a.pinfo.size(); ++i) {
237 if (!a.pinfo.at(i).isApprox(b.pinfo.at(i))) {
238 return false;
239 }
240 }
241 } else {
242 return false;
243 }
244
245 return (a.type == b.type && a.id == b.id && a.np == b.np && a.ntri == b.ntri && a.coord_frame == b.coord_frame && a.rr.isApprox(b.rr, 0.0001f) && a.nn.isApprox(b.nn, 0.0001f) && a.itris.isApprox(b.itris) && a.nuse == b.nuse && a.inuse.isApprox(b.inuse) && a.vertno.isApprox(b.vertno) && a.nuse_tri == b.nuse_tri && a.use_itris.isApprox(b.use_itris) && a.nearestVertIdx().isApprox(b.nearestVertIdx()) && a.nearestDistVec().isApprox(b.nearestDistVec(), 0.0001) && a.patch_inds.isApprox(b.patch_inds) &&
246 //a.dist_limit == b.dist_limit && //TODO: We still not sure if dist_limit can also be a matrix. This needs to be debugged
247 [&a, &b]() {
248 const auto& sa = a.dist.eigen();
249 const auto& sb = b.dist.eigen();
250 if (sa.rows() == 0 && sb.rows() == 0 && sa.cols() == 0 && sb.cols() == 0)
251 return true;
252 return sa.toDense().isApprox(sb.toDense(), 0.0001f);
253 }() &&
254 a.tri_cent.isApprox(b.tri_cent, 0.0001) && a.tri_nn.isApprox(b.tri_nn, 0.0001) && a.tri_area.isApprox(b.tri_area, 0.0001) && a.use_tri_cent.isApprox(b.use_tri_cent, 0.0001) && a.use_tri_nn.isApprox(b.use_tri_nn, 0.0001) && a.use_tri_area.isApprox(b.use_tri_area, 0.0001) && [&a, &b]() {
255 if (a.neighbor_tri.size() != b.neighbor_tri.size())
256 return false;
257 for (size_t i = 0; i < a.neighbor_tri.size(); ++i) {
258 if (a.neighbor_tri[i].size() != b.neighbor_tri[i].size())
259 return false;
260 if (a.neighbor_tri[i].size() > 0 && !(a.neighbor_tri[i].array() == b.neighbor_tri[i].array()).all())
261 return false;
262 }
263 return true;
264 }() &&
265 [&a, &b]() {
266 if (a.neighbor_vert.size() != b.neighbor_vert.size())
267 return false;
268 for (size_t i = 0; i < a.neighbor_vert.size(); ++i) {
269 if (a.neighbor_vert[i].size() != b.neighbor_vert[i].size())
270 return false;
271 if (a.neighbor_vert[i].size() > 0 && !(a.neighbor_vert[i].array() == b.neighbor_vert[i].array()).all())
272 return false;
273 }
274 return true;
275 }() &&
276 a.cluster_info == b.cluster_info);
277}
278} // NAMESPACE
279
280#endif // MNE_HEMISPHERE_H
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.
Bookkeeping for a label-restricted clustering of source-space leadfield columns.
Single-hemisphere source space (cortical surface or volume grid) loaded from FIFF.
MNELIB shared-library export/import macros and library build metadata.
#define MNESHARED_EXPORT
Definition mne_global.h:40
Core MNE data structures (source spaces, source estimates, hemispheres).
bool operator==(const MNEClusterInfo &a, const MNEClusterInfo &b)
qint32 fiff_int_t
Definition fiff_types.h:86
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
friend bool operator==(const MNEHemisphere &a, const MNEHemisphere &b)
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