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