v2.0.0
Loading...
Searching...
No Matches
mne_source_spaces.h
Go to the documentation of this file.
1//=============================================================================================================
21
22#ifndef MNE_SOURCE_SPACES_H
23#define MNE_SOURCE_SPACES_H
24
25//=============================================================================================================
26// INCLUDES
27//=============================================================================================================
28
29#include "mne_global.h"
30#include "mne_hemisphere.h"
31
32#include <fiff/fiff_types.h>
33#include <fiff/fiff_dir_node.h>
34#include <fiff/fiff.h>
35
36#include <algorithm>
37#include <vector>
38#include <memory>
39
40//=============================================================================================================
41// EIGEN INCLUDES
42//=============================================================================================================
43
44#include <Eigen/Core>
45
46//=============================================================================================================
47// QT INCLUDES
48//=============================================================================================================
49
50#include <QList>
51
52//=============================================================================================================
53// FORWARD DECLARATIONS
54//=============================================================================================================
55
56namespace FSLIB
57{
58class FsLabel;
59}
60
61//=============================================================================================================
62// DEFINE NAMESPACE MNELIB
63//=============================================================================================================
64
65namespace MNELIB
66{
67
68//=============================================================================================================
69// MNELIB FORWARD DECLARATIONS
70//=============================================================================================================
71
72//=============================================================================================================
83{
84public:
85 using SPtr = std::shared_ptr<MNESourceSpaces>;
86 using ConstSPtr = std::shared_ptr<const MNESourceSpaces>;
87
88 //=========================================================================================================
93
94 //=========================================================================================================
100 MNESourceSpaces(const MNESourceSpaces& p_MNESourceSpaces);
101
102 //=========================================================================================================
113 MNESourceSpaces& operator=(const MNESourceSpaces& other) = default;
114
115 //=========================================================================================================
120
121 //=========================================================================================================
125 void clear();
126
127 //=========================================================================================================
133 inline bool isEmpty() const;
134
135 //=========================================================================================================
145 static qint32 find_source_space_hemi(MNESourceSpace& p_SourceSpace);
146
147 //=========================================================================================================
153 QList<Eigen::VectorXi> get_vertno() const;
154
155 //=========================================================================================================
165 QList<Eigen::VectorXi> label_src_vertno_sel(const FSLIB::FsLabel& p_label, Eigen::VectorXi& src_sel) const;
166
167 //=========================================================================================================
178 static bool patch_info(MNEHemisphere& p_Hemisphere); //VectorXi& nearest, QList<VectorXi>& pinfo);@param[in] nearest The nearest vector of the source space.@param[in, out] pinfo The requested patch information.
179
180 //=========================================================================================================
188 MNESourceSpaces pick_regions(const QList<FSLIB::FsLabel>& p_qListLabels) const;
189
190 //=========================================================================================================
202 static bool readFromStream(FIFFLIB::FiffStream::SPtr& p_pStream,
203 bool add_geom,
204 MNESourceSpaces& p_SourceSpace);
205
206 //=========================================================================================================
212 inline qint32 size() const;
213
214 //=========================================================================================================
231
232 //=========================================================================================================
240 void writeToStream(FIFFLIB::FiffStream* p_pStream);
241
242 //=========================================================================================================
248 void append(const MNESourceSpace& space);
249
250 //=========================================================================================================
258 MNESourceSpace& operator[](qint32 idx);
259
260 //=========================================================================================================
268 const MNESourceSpace& operator[](qint32 idx) const;
269
270 //=========================================================================================================
278 MNESourceSpace& operator[](QString idt);
279
280 //=========================================================================================================
288 const MNESourceSpace& operator[](QString idt) const;
289
290 //=========================================================================================================
298 MNEHemisphere* hemisphereAt(qint32 idx);
299
300 //=========================================================================================================
308 const MNEHemisphere* hemisphereAt(qint32 idx) const;
309
310 //=========================================================================================================
318 std::shared_ptr<MNESourceSpace>& at(qint32 idx);
319
320 //=========================================================================================================
328 const std::shared_ptr<MNESourceSpace>& at(qint32 idx) const;
329
338 friend bool operator==(const MNESourceSpaces& a, const MNESourceSpaces& b);
339
340private:
341 //=========================================================================================================
351 static bool complete_source_space_info(MNEHemisphere& p_Hemisphere);
352
353 //=========================================================================================================
365 static bool read_source_space(FIFFLIB::FiffStream::SPtr& p_pStream,
366 const FIFFLIB::FiffDirNode::SPtr& p_Tree,
367 MNEHemisphere& p_Hemisphere);
368
369private:
370 std::vector<std::shared_ptr<MNESourceSpace>> m_sourceSpaces;
371};
372
373//=============================================================================================================
374// INLINE DEFINITIONS
375//=============================================================================================================
376
377inline bool MNESourceSpaces::isEmpty() const
378{
379 return m_sourceSpaces.empty();
380}
381
382//=============================================================================================================
383
384inline qint32 MNESourceSpaces::size() const
385{
386 return static_cast<qint32>(m_sourceSpaces.size());
387}
388
389//=============================================================================================================
390
391inline bool operator==(const MNESourceSpaces& a, const MNESourceSpaces& b)
392{
393 if (a.size() != b.size())
394 return false;
395 for (qint32 i = 0; i < a.size(); ++i) {
396 // Compare as hemispheres if both elements are hemispheres
397 auto* ha = dynamic_cast<const MNEHemisphere*>(&a[i]);
398 auto* hb = dynamic_cast<const MNEHemisphere*>(&b[i]);
399 if (ha && hb) {
400 if (!(*ha == *hb))
401 return false;
402 } else {
403 // Fallback: compare base-class identity (pointer equality or basic fields)
404 // For now, require both to be hemispheres for equality
405 return false;
406 }
407 }
408 return true;
409}
410
411} // NAMESPACE
412
413#endif // MNE_SOURCE_SPACES_H
Static MATLAB-style FIFF facade: thin wrapper functions kept for parity with the historical mne-matla...
Recursive node of the parsed FIFF block tree (FIFFB_* hierarchy with directory entries and children).
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
Per-hemisphere cortical surface bundle with decimation, patch info and rendering buffers.
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)
FreeSurfer surface, annotation and parcellation I/O for mne-cpp.
qint32 fiff_int_t
Definition fiff_types.h:86
Labelled 4x4 FIFF affine: source frame, destination frame, rotation, translation and cached inverse.
QSharedPointer< FiffDirNode > SPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
QSharedPointer< FiffStream > SPtr
A FreeSurfer/MNE surface label: per-vertex indices, Tk-RAS positions and scalar values for one hemisp...
Definition fs_label.h:81
Hemisphere provides geometry information.
This defines a source space.
friend bool operator==(const MNESourceSpaces &a, const MNESourceSpaces &b)
MNESourceSpaces & operator=(const MNESourceSpaces &other)=default
void writeToStream(FIFFLIB::FiffStream *p_pStream)
MNESourceSpaces pick_regions(const QList< FSLIB::FsLabel > &p_qListLabels) const
std::shared_ptr< const MNESourceSpaces > ConstSPtr
bool transform_source_space_to(FIFFLIB::fiff_int_t dest, FIFFLIB::FiffCoordTrans &trans)
MNEHemisphere * hemisphereAt(qint32 idx)
std::shared_ptr< MNESourceSpaces > SPtr
void append(const MNESourceSpace &space)
static bool patch_info(MNEHemisphere &p_Hemisphere)
static qint32 find_source_space_hemi(MNESourceSpace &p_SourceSpace)
QList< Eigen::VectorXi > label_src_vertno_sel(const FSLIB::FsLabel &p_label, Eigen::VectorXi &src_sel) const
MNESourceSpace & operator[](qint32 idx)
static bool readFromStream(FIFFLIB::FiffStream::SPtr &p_pStream, bool add_geom, MNESourceSpaces &p_SourceSpace)
std::shared_ptr< MNESourceSpace > & at(qint32 idx)
QList< Eigen::VectorXi > get_vertno() const