v2.0.0
Loading...
Searching...
No Matches
fs_annotationset.cpp
Go to the documentation of this file.
1//=============================================================================================================
12
13//=============================================================================================================
14// INCLUDES
15//=============================================================================================================
16
17#include "fs_annotationset.h"
18#include "fs_surfaceset.h"
19
20#include <QFile>
21#include <QDebug>
22
23//=============================================================================================================
24// USED NAMESPACES
25//=============================================================================================================
26
27using namespace FSLIB;
28using namespace Eigen;
29
30//=============================================================================================================
31// DEFINE MEMBER METHODS
32//=============================================================================================================
33
37
38//=============================================================================================================
39
40FsAnnotationSet::FsAnnotationSet(const QString& subject_id, qint32 hemi, const QString& atlas, const QString& subjects_dir)
41{
42 FsAnnotation t_Annotation;
43 if (hemi == 0 || hemi == 1) {
44 if (FsAnnotation::read(subject_id, hemi, atlas, subjects_dir, t_Annotation))
45 insert(t_Annotation);
46 } else if (hemi == 2) {
47 if (FsAnnotation::read(subject_id, 0, atlas, subjects_dir, t_Annotation))
48 insert(t_Annotation);
49 if (FsAnnotation::read(subject_id, 1, atlas, subjects_dir, t_Annotation))
50 insert(t_Annotation);
51 }
52}
53
54//=============================================================================================================
55
56FsAnnotationSet::FsAnnotationSet(const QString& path, qint32 hemi, const QString& atlas)
57{
58 FsAnnotation t_Annotation;
59 if (hemi == 0 || hemi == 1) {
60 if (FsAnnotation::read(path, hemi, atlas, t_Annotation))
61 insert(t_Annotation);
62 } else if (hemi == 2) {
63 if (FsAnnotation::read(path, 0, atlas, t_Annotation))
64 insert(t_Annotation);
65 if (FsAnnotation::read(path, 1, atlas, t_Annotation))
66 insert(t_Annotation);
67 }
68}
69
70//=============================================================================================================
71
72FsAnnotationSet::FsAnnotationSet(const FsAnnotation& p_LHAnnotation, const FsAnnotation& p_RHAnnotation)
73{
74 if (p_LHAnnotation.hemi() == 0)
75 m_qMapAnnots.insert(0, p_LHAnnotation);
76 else
77 qWarning("Left hemisphere id is not 0. LH annotation not assigned!");
78
79 if (p_RHAnnotation.hemi() == 1)
80 m_qMapAnnots.insert(1, p_RHAnnotation);
81 else
82 qWarning("Right hemisphere id is not 1. RH annotation not assigned!");
83}
84
85//=============================================================================================================
86
87FsAnnotationSet::FsAnnotationSet(const QString& p_sLHFileName, const QString& p_sRHFileName)
88{
89 FsAnnotationSet t_AnnotationSet;
90 if (FsAnnotationSet::read(p_sLHFileName, p_sRHFileName, t_AnnotationSet))
91 *this = t_AnnotationSet;
92}
93
94//=============================================================================================================
95
97{
98 m_qMapAnnots.clear();
99}
100
101//=============================================================================================================
102
103void FsAnnotationSet::insert(const FsAnnotation& p_Annotation)
104{
105 if (p_Annotation.isEmpty())
106 return;
107
108 qint32 hemi = p_Annotation.hemi();
109 m_qMapAnnots.remove(hemi);
110
111 m_qMapAnnots.insert(hemi, p_Annotation);
112}
113
114//=============================================================================================================
115
116bool FsAnnotationSet::read(const QString& p_sLHFileName, const QString& p_sRHFileName, FsAnnotationSet& p_AnnotationSet)
117{
118 p_AnnotationSet.clear();
119
120 QStringList t_qListFileName;
121 t_qListFileName << p_sLHFileName << p_sRHFileName;
122
123 for (qint32 i = 0; i < t_qListFileName.size(); ++i) {
124 FsAnnotation t_Annotation;
125 if (FsAnnotation::read(t_qListFileName[i], t_Annotation)) {
126 if (t_qListFileName[i].contains("lh."))
127 p_AnnotationSet.m_qMapAnnots.insert(0, t_Annotation);
128 else if (t_qListFileName[i].contains("rh."))
129 p_AnnotationSet.m_qMapAnnots.insert(1, t_Annotation);
130 else
131 return false;
132 }
133 }
134
135 if (p_AnnotationSet.m_qMapAnnots.isEmpty())
136 return false;
137
138 return true;
139}
140
141//=============================================================================================================
142
144 QList<FsLabel>& p_qListLabels,
145 QList<RowVector4i>& p_qListLabelRGBAs,
146 const QStringList& lLabelPicks) const
147{
148 if (!m_qMapAnnots[0].toLabels(p_surfSet[0], p_qListLabels, p_qListLabelRGBAs, lLabelPicks))
149 return false;
150 else if (!m_qMapAnnots[1].toLabels(p_surfSet[1], p_qListLabels, p_qListLabelRGBAs, lLabelPicks))
151 return false;
152
153 return true;
154}
155
156//=============================================================================================================
157
159{
160 if (idx == 0)
161 return m_qMapAnnots[idx];
162 else if (idx == 1)
163 return m_qMapAnnots[idx];
164 else {
165 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
166 return m_qMapAnnots[0];
167 }
168}
169
170//=============================================================================================================
171
173{
174 if (idx == 0)
175 return m_qMapAnnots[idx];
176 else if (idx == 1)
177 return m_qMapAnnots[idx];
178 else {
179 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
180 return m_qMapAnnots[0];
181 }
182}
183
184//=============================================================================================================
185
187{
188 if (idt.compare("lh") == 0)
189 return m_qMapAnnots[0];
190 else if (idt.compare("rh") == 0)
191 return m_qMapAnnots[1];
192 else {
193 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
194 return m_qMapAnnots[0];
195 }
196}
197
198//=============================================================================================================
199
201{
202 if (idt.compare("lh") == 0)
203 return m_qMapAnnots[0];
204 else if (idt.compare("rh") == 0)
205 return m_qMapAnnots[1];
206 else {
207 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
208 return m_qMapAnnots[0];
209 }
210}
Bi-hemispheric pair of FreeSurfer annotations (lh + rh) for one parcellation atlas.
Bi-hemispheric grouping of FreeSurfer surfaces (lh + rh) loaded as a single object.
FreeSurfer surface, annotation and parcellation I/O for mne-cpp.
Single-hemisphere FreeSurfer parcellation: vertex → region label plus embedded colortable.
qint32 hemi() const
static bool read(const QString &subject_id, qint32 hemi, const QString &atlas, const QString &subjects_dir, FsAnnotation &p_Annotation)
bool toLabels(const FsSurfaceSet &p_surfSet, QList< FsLabel > &p_qListLabels, QList< Eigen::RowVector4i > &p_qListLabelRGBAs, const QStringList &lLabelPicks=QStringList()) const
FsAnnotation & operator[](qint32 idx)
static bool read(const QString &p_sLHFileName, const QString &p_sRHFileName, FsAnnotationSet &p_AnnotationSet)
void insert(const FsAnnotation &p_Annotation)
Container holding the lh and/or rh FsSurface for one subject and one surface kind.