MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
annotationset.cpp
Go to the documentation of this file.
1//=============================================================================================================
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "annotationset.h"
42#include "surfaceset.h"
43
44#include <QFile>
45#include <QDebug>
46
47//=============================================================================================================
48// USED NAMESPACES
49//=============================================================================================================
50
51using namespace FSLIB;
52using namespace Eigen;
53
54//=============================================================================================================
55// DEFINE MEMBER METHODS
56//=============================================================================================================
57
61
62//=============================================================================================================
63
64AnnotationSet::AnnotationSet(const QString &subject_id, qint32 hemi, const QString &atlas, const QString &subjects_dir)
65{
66 Annotation t_Annotation;
67 if(hemi == 0 || hemi == 1)
68 {
69 if(Annotation::read(subject_id, hemi, atlas, subjects_dir, t_Annotation))
70 insert(t_Annotation);
71 }
72 else if(hemi == 2)
73 {
74 if(Annotation::read(subject_id, 0, atlas, subjects_dir, t_Annotation))
75 insert(t_Annotation);
76 if(Annotation::read(subject_id, 1, atlas, subjects_dir, t_Annotation))
77 insert(t_Annotation);
78 }
79}
80
81//=============================================================================================================
82
83AnnotationSet::AnnotationSet(const QString &path, qint32 hemi, const QString &atlas)
84{
85 Annotation t_Annotation;
86 if(hemi == 0 || hemi == 1)
87 {
88 if(Annotation::read(path, hemi, atlas, t_Annotation))
89 insert(t_Annotation);
90 }
91 else if(hemi == 2)
92 {
93 if(Annotation::read(path, 0, atlas, t_Annotation))
94 insert(t_Annotation);
95 if(Annotation::read(path, 1, atlas, t_Annotation))
96 insert(t_Annotation);
97 }
98}
99
100//=============================================================================================================
101
102AnnotationSet::AnnotationSet(const Annotation& p_LHAnnotation, const Annotation& p_RHAnnotation)
103{
104 if(p_LHAnnotation.hemi() == 0)
105 m_qMapAnnots.insert(0, p_LHAnnotation);
106 else
107 qWarning("Left hemisphere id is not 0. LH annotation not assigned!");
108
109 if(p_RHAnnotation.hemi() == 1)
110 m_qMapAnnots.insert(1, p_RHAnnotation);
111 else
112 qWarning("Right hemisphere id is not 1. RH annotation not assigned!");
113}
114
115//=============================================================================================================
116
117AnnotationSet::AnnotationSet(const QString& p_sLHFileName, const QString& p_sRHFileName)
118{
119 AnnotationSet t_AnnotationSet;
120 if(AnnotationSet::read(p_sLHFileName, p_sRHFileName, t_AnnotationSet))
121 *this = t_AnnotationSet;
122}
123
124//=============================================================================================================
125
127{
128 m_qMapAnnots.clear();
129}
130
131//=============================================================================================================
132
133void AnnotationSet::insert(const Annotation& p_Annotation)
134{
135 if(p_Annotation.isEmpty())
136 return;
137
138 qint32 hemi = p_Annotation.hemi();
139 m_qMapAnnots.remove(hemi);
140
141 m_qMapAnnots.insert(hemi, p_Annotation);
142}
143
144//=============================================================================================================
145
146bool AnnotationSet::read(const QString& p_sLHFileName, const QString& p_sRHFileName, AnnotationSet &p_AnnotationSet)
147{
148 p_AnnotationSet.clear();
149
150 QStringList t_qListFileName;
151 t_qListFileName << p_sLHFileName << p_sRHFileName;
152
153 for(qint32 i = 0; i < t_qListFileName.size(); ++i)
154 {
155 Annotation t_Annotation;
156 if(Annotation::read(t_qListFileName[i], t_Annotation))
157 {
158 if(t_qListFileName[i].contains("lh."))
159 p_AnnotationSet.m_qMapAnnots.insert(0, t_Annotation);
160 else if(t_qListFileName[i].contains("rh."))
161 p_AnnotationSet.m_qMapAnnots.insert(1, t_Annotation);
162 else
163 return false;
164 }
165 }
166
167 return true;
168}
169
170//=============================================================================================================
171
173 QList<Label> &p_qListLabels,
174 QList<RowVector4i> &p_qListLabelRGBAs,
175 const QStringList& lLabelPicks) const
176{
177 if(!m_qMapAnnots[0].toLabels(p_surfSet[0], p_qListLabels, p_qListLabelRGBAs, lLabelPicks))
178 return false;
179 else if(!m_qMapAnnots[1].toLabels(p_surfSet[1], p_qListLabels, p_qListLabelRGBAs, lLabelPicks))
180 return false;
181
182 return true;
183}
184
185//=============================================================================================================
186
188{
189 if(idx == 0)
190 return m_qMapAnnots[idx];
191 else if(idx == 1)
192 return m_qMapAnnots[idx];
193 else
194 {
195 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
196 return m_qMapAnnots[0];
197 }
198}
199
200//=============================================================================================================
201
203{
204 if(idx == 0)
205 return m_qMapAnnots[idx];
206 else if(idx == 1)
207 return m_qMapAnnots[idx];
208 else
209 {
210 qWarning("Warning: Index is not '0' or '1'! Returning '0'.");
211 return m_qMapAnnots[0];
212 }
213}
214
215//=============================================================================================================
216
218{
219 if(idt.compare("lh") == 0)
220 return m_qMapAnnots[0];
221 else if(idt.compare("rh") == 0)
222 return m_qMapAnnots[1];
223 else
224 {
225 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
226 return m_qMapAnnots[0];
227 }
228}
229
230//=============================================================================================================
231
233{
234 if(idt.compare("lh") == 0)
235 return m_qMapAnnots[0];
236 else if(idt.compare("rh") == 0)
237 return m_qMapAnnots[1];
238 else
239 {
240 qWarning("Warning: Identifier is not 'lh' or 'rh'! Returning 'lh'.");
241 return m_qMapAnnots[0];
242 }
243}
AnnotationSet class declaration.
SurfaceSet class declaration.
Free surfer annotation.
Definition annotation.h:81
bool isEmpty() const
Definition annotation.h:294
static bool read(const QString &subject_id, qint32 hemi, const QString &atlas, const QString &subjects_dir, Annotation &p_Annotation)
qint32 hemi() const
Definition annotation.h:287
Annotation set.
static bool read(const QString &p_sLHFileName, const QString &p_sRHFileName, AnnotationSet &p_AnnotationSet)
void insert(const Annotation &p_Annotation)
Annotation & operator[](qint32 idx)
bool toLabels(const SurfaceSet &p_surfSet, QList< Label > &p_qListLabels, QList< Eigen::RowVector4i > &p_qListLabelRGBAs, const QStringList &lLabelPicks=QStringList()) const
A hemisphere set of surfaces.
Definition surfaceset.h:72