53 #include <QDataStream>
60 using namespace FSLIB;
61 using namespace Eigen;
77 : m_sFileName(p_sFileName)
114 m_sFileName = QString(
"");
115 m_Vertices = VectorXi::Zero(0);
116 m_LabelIds = VectorXi::Zero(0);
117 m_Colortable.
clear();
127 QString p_sFile = QString(
"%1/%2/label/%3.%4.annot").arg(subjects_dir).arg(subject_id).arg(
hemi == 0 ?
"lh" :
"rh").arg(atlas);
129 return read(p_sFile, p_Annotation);
139 QString p_sFile = QString(
"%1/%2.%3.annot").arg(path).arg(
hemi == 0 ?
"lh" :
"rh").arg(atlas);
141 return read(p_sFile, p_Annotation);
148 p_Annotation.
clear();
150 printf(
"Reading annotation...\n");
151 QFile t_File(p_sFileName);
152 QFileInfo fileInfo(t_File.fileName());
154 p_Annotation.m_sFileName = fileInfo.fileName();
155 p_Annotation.m_sFilePath = fileInfo.filePath();
157 if (!t_File.open(QIODevice::ReadOnly))
159 printf(
"\tError: Couldn't open the file\n");
163 QDataStream t_Stream(&t_File);
164 t_Stream.setByteOrder(QDataStream::BigEndian);
169 p_Annotation.m_Vertices = VectorXi(numEl);
170 p_Annotation.m_LabelIds = VectorXi(numEl);
172 for(qint32 i = 0; i < numEl; ++i)
174 t_Stream >> p_Annotation.m_Vertices[i];
175 t_Stream >> p_Annotation.m_LabelIds[i];
178 qint32 hasColortable;
179 t_Stream >> hasColortable;
182 p_Annotation.m_Colortable.
clear();
186 t_Stream >> numEntries;
191 printf(
"\tReading from Original Version\n");
192 p_Annotation.m_Colortable.
numEntries = numEntries;
196 t_Stream.readRawData(tmp.data(),len);
197 p_Annotation.m_Colortable.
orig_tab = tmp;
199 for(qint32 i = 0; i < numEntries; ++i)
202 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
204 for(qint32 i = 0; i < numEntries; ++i)
208 t_Stream.readRawData(tmp.data(),len);
212 for(qint32 j = 0; j < 4; ++j)
213 t_Stream >> p_Annotation.m_Colortable.
table(i,j);
215 p_Annotation.m_Colortable.
table(i,4) = p_Annotation.m_Colortable.
table(i,0)
216 + p_Annotation.m_Colortable.
table(i,1) * 256
217 + p_Annotation.m_Colortable.
table(i,2) * 65536
218 + p_Annotation.m_Colortable.
table(i,3) * 16777216;
223 qint32 version = -numEntries;
225 printf(
"\tError! Does not handle version %d\n", version);
227 printf(
"\tReading from version %d\n", version);
229 t_Stream >> numEntries;
230 p_Annotation.m_Colortable.
numEntries = numEntries;
235 t_Stream.readRawData(tmp.data(),len);
236 p_Annotation.m_Colortable.
orig_tab = tmp;
238 for(qint32 i = 0; i < numEntries; ++i)
241 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
243 qint32 numEntriesToRead;
244 t_Stream >> numEntriesToRead;
247 for(qint32 i = 0; i < numEntriesToRead; ++i)
250 t_Stream >> structure;
252 printf(
"\tError! Read entry, index %d\n", structure);
254 if(!p_Annotation.m_Colortable.
struct_names[structure].isEmpty())
255 printf(
"Error! Duplicate Structure %d", structure);
259 t_Stream.readRawData(tmp.data(),len);
263 for(qint32 j = 0; j < 4; ++j)
264 t_Stream >> p_Annotation.m_Colortable.
table(structure,j);
266 p_Annotation.m_Colortable.
table(structure,4) = p_Annotation.m_Colortable.
table(structure,0)
267 + p_Annotation.m_Colortable.
table(structure,1) * 256
268 + p_Annotation.m_Colortable.
table(structure,2) * 65536
269 + p_Annotation.m_Colortable.
table(structure,3) * 16777216;
272 printf(
"\tcolortable with %d entries read\n\t(originally %s)\n", p_Annotation.m_Colortable.
numEntries, p_Annotation.m_Colortable.
orig_tab.toUtf8().constData());
276 printf(
"\tError! No colortable stored\n");
280 if(t_File.fileName().contains(
"lh."))
281 p_Annotation.m_iHemi = 0;
283 p_Annotation.m_iHemi = 1;
295 QList<Label> &p_qListLabels,
296 QList<RowVector4i> &p_qListLabelRGBAs,
297 const QStringList& lLabelPicks)
const
299 if(this->m_iHemi != p_surf.
hemi())
301 qWarning(
"Annotation and surface hemisphere (annot = %d; surf = %d) do not match!\n", this->m_iHemi, p_surf.
hemi());
305 if(m_LabelIds.size() == 0)
307 qWarning(
"Annotation doesn't' contain data!\n");
311 printf(
"Converting labels from annotation...");
318 QStringList label_names = m_Colortable.
getNames();
319 MatrixX4i label_rgbas = m_Colortable.
getRGBAs();
322 MatrixX3f vert_pos = p_surf.
rr();
328 qint32 label_id, count;
329 RowVector4i label_rgba;
334 for(qint32 i = 0; i < label_rgbas.rows(); ++i)
336 label_id = label_ids[i];
337 label_rgba = label_rgbas.row(i);
339 vertices.resize(m_LabelIds.size());
341 for(qint32 j = 0; j < m_LabelIds.size(); ++j)
343 if(m_LabelIds[j] == label_id)
352 vertices.conservativeResize(count);
354 pos.resize(count, 3);
355 for(qint32 j = 0; j < count; ++j)
356 pos.row(j) = vert_pos.row(vertices[j]);
358 values = VectorXd::Zero(count);
359 name = QString(
"%1-%2").arg(label_names[i]).arg(this->m_iHemi == 0 ?
"lh" :
"rh");
362 if(lLabelPicks.isEmpty()) {
364 p_qListLabels.append(
Label(vertices, pos, values, this->m_iHemi, name, label_id));
366 p_qListLabelRGBAs.append(label_rgba);
367 }
else if (lLabelPicks.indexOf(name) != -1) {
369 p_qListLabels.append(
Label(vertices, pos, values, this->m_iHemi, name, label_id));
371 p_qListLabelRGBAs.append(label_rgba);