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 {
45 if(FsAnnotation::read(subject_id, hemi, atlas, subjects_dir, t_Annotation))
46 insert(t_Annotation);
47 }
48 else if(hemi == 2)
49 {
50 if(FsAnnotation::read(subject_id, 0, atlas, subjects_dir, t_Annotation))
51 insert(t_Annotation);
52 if(FsAnnotation::read(subject_id, 1, atlas, subjects_dir, t_Annotation))
53 insert(t_Annotation);
54 }
55}
56
57//=============================================================================================================
58
59FsAnnotationSet::FsAnnotationSet(const QString &path, qint32 hemi, const QString &atlas)
60{
61 FsAnnotation t_Annotation;
62 if(hemi == 0 || hemi == 1)
63 {
64 if(FsAnnotation::read(path, hemi, atlas, t_Annotation))
65 insert(t_Annotation);
66 }
67 else if(hemi == 2)
68 {
69 if(FsAnnotation::read(path, 0, atlas, t_Annotation))
70 insert(t_Annotation);
71 if(FsAnnotation::read(path, 1, atlas, t_Annotation))
72 insert(t_Annotation);
73 }
74}
75
76//=============================================================================================================
77
78FsAnnotationSet::FsAnnotationSet(const FsAnnotation& p_LHAnnotation, const FsAnnotation& p_RHAnnotation)
79{
80 if(p_LHAnnotation.hemi() == 0)
81 m_qMapAnnots.insert(0, p_LHAnnotation);
82 else
83 qWarning("Left hemisphere id is not 0. LH annotation not assigned!");
84
85 if(p_RHAnnotation.hemi() == 1)
86 m_qMapAnnots.insert(1, p_RHAnnotation);
87 else
88 qWarning("Right hemisphere id is not 1. RH annotation not assigned!");
89}
90
91//=============================================================================================================
92
93FsAnnotationSet::FsAnnotationSet(const QString& p_sLHFileName, const QString& p_sRHFileName)
94{
95 FsAnnotationSet t_AnnotationSet;
96 if(FsAnnotationSet::read(p_sLHFileName, p_sRHFileName, t_AnnotationSet))
97 *this = t_AnnotationSet;
98}
99
100//=============================================================================================================
101
103{
104 m_qMapAnnots.clear();
105}
106
107//=============================================================================================================
108
109void FsAnnotationSet::insert(const FsAnnotation& p_Annotation)
110{
111 if(p_Annotation.isEmpty())
112 return;
113
114 qint32 hemi = p_Annotation.hemi();
115 m_qMapAnnots.remove(hemi);
116
117 m_qMapAnnots.insert(hemi, p_Annotation);
118}
119
120//=============================================================================================================
121
122bool FsAnnotationSet::read(const QString& p_sLHFileName, const QString& p_sRHFileName, FsAnnotationSet &p_AnnotationSet)
123{
124 p_AnnotationSet.clear();
125
126 QStringList t_qListFileName;
127 t_qListFileName << p_sLHFileName << p_sRHFileName;
128
129 for(qint32 i = 0; i < t_qListFileName.size(); ++i)
130 {
131 FsAnnotation t_Annotation;
132 if(FsAnnotation::read(t_qListFileName[i], t_Annotation))
133 {
134 if(t_qListFileName[i].contains("lh."))
135 p_AnnotationSet.m_qMapAnnots.insert(0, t_Annotation);
136 else if(t_qListFileName[i].contains("rh."))
137 p_AnnotationSet.m_qMapAnnots.insert(1, t_Annotation);
138 else
139 return false;
140 }
141 }
142
143 if(p_AnnotationSet.m_qMapAnnots.isEmpty())
144 return false;
145
146 return true;
147}
148
149//=============================================================================================================
150
152 QList<FsLabel> &p_qListLabels,
153 QList<RowVector4i> &p_qListLabelRGBAs,
154 const QStringList& lLabelPicks) const
155{
156 if(!m_qMapAnnots[0].toLabels(p_surfSet[0], p_qListLabels, p_qListLabelRGBAs, lLabelPicks))
157 return false;
158 else if(!m_qMapAnnots[1].toLabels(p_surfSet[1], p_qListLabels, p_qListLabelRGBAs, lLabelPicks))
159 return false;
160
161 return true;
162}
163
164//=============================================================================================================
165
167{
168 if(idx == 0)
169 return m_qMapAnnots[idx];
170 else if(idx == 1)
171 return m_qMapAnnots[idx];
172 else
173 {
174 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
175 return m_qMapAnnots[0];
176 }
177}
178
179//=============================================================================================================
180
182{
183 if(idx == 0)
184 return m_qMapAnnots[idx];
185 else if(idx == 1)
186 return m_qMapAnnots[idx];
187 else
188 {
189 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
190 return m_qMapAnnots[0];
191 }
192}
193
194//=============================================================================================================
195
197{
198 if(idt.compare("lh") == 0)
199 return m_qMapAnnots[0];
200 else if(idt.compare("rh") == 0)
201 return m_qMapAnnots[1];
202 else
203 {
204 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
205 return m_qMapAnnots[0];
206 }
207}
208
209//=============================================================================================================
210
212{
213 if(idt.compare("lh") == 0)
214 return m_qMapAnnots[0];
215 else if(idt.compare("rh") == 0)
216 return m_qMapAnnots[1];
217 else
218 {
219 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
220 return m_qMapAnnots[0];
221 }
222}
Bi-hemispheric grouping of FreeSurfer surfaces (lh + rh) loaded as a single object.
Bi-hemispheric pair of FreeSurfer annotations (lh + rh) for one parcellation atlas.
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.