53 #include <QDataStream>
60 using namespace FSLIB;
61 using namespace Eigen;
75 : m_sFileName(p_sFileName)
108 m_sFileName = QString(
"");
109 m_Vertices = VectorXi::Zero(0);
110 m_LabelIds = VectorXi::Zero(0);
111 m_Colortable.
clear();
121 QString p_sFile = QString(
"%1/%2/label/%3.%4.annot").arg(subjects_dir).arg(subject_id).arg(
hemi == 0 ?
"lh" :
"rh").arg(atlas);
123 return read(p_sFile, p_Annotation);
133 QString p_sFile = QString(
"%1/%2.%3.annot").arg(path).arg(
hemi == 0 ?
"lh" :
"rh").arg(atlas);
135 return read(p_sFile, p_Annotation);
142 p_Annotation.
clear();
144 printf(
"Reading annotation...\n");
145 QFile t_File(p_sFileName);
146 QFileInfo fileInfo(t_File.fileName());
148 p_Annotation.m_sFileName = fileInfo.fileName();
149 p_Annotation.m_sFilePath = fileInfo.filePath();
151 if (!t_File.open(QIODevice::ReadOnly))
153 printf(
"\tError: Couldn't open the file\n");
157 QDataStream t_Stream(&t_File);
158 t_Stream.setByteOrder(QDataStream::BigEndian);
163 p_Annotation.m_Vertices = VectorXi(numEl);
164 p_Annotation.m_LabelIds = VectorXi(numEl);
166 for(qint32 i = 0; i < numEl; ++i)
168 t_Stream >> p_Annotation.m_Vertices[i];
169 t_Stream >> p_Annotation.m_LabelIds[i];
172 qint32 hasColortable;
173 t_Stream >> hasColortable;
176 p_Annotation.m_Colortable.
clear();
180 t_Stream >> numEntries;
185 printf(
"\tReading from Original Version\n");
186 p_Annotation.m_Colortable.
numEntries = numEntries;
190 t_Stream.readRawData(tmp.data(),len);
191 p_Annotation.m_Colortable.
orig_tab = tmp;
193 for(qint32 i = 0; i < numEntries; ++i)
196 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
198 for(qint32 i = 0; i < numEntries; ++i)
202 t_Stream.readRawData(tmp.data(),len);
206 for(qint32 j = 0; j < 4; ++j)
207 t_Stream >> p_Annotation.m_Colortable.
table(i,j);
209 p_Annotation.m_Colortable.
table(i,4) = p_Annotation.m_Colortable.
table(i,0)
210 + p_Annotation.m_Colortable.
table(i,1) * 256
211 + p_Annotation.m_Colortable.
table(i,2) * 65536
212 + p_Annotation.m_Colortable.
table(i,3) * 16777216;
217 qint32 version = -numEntries;
219 printf(
"\tError! Does not handle version %d\n", version);
221 printf(
"\tReading from version %d\n", version);
223 t_Stream >> numEntries;
224 p_Annotation.m_Colortable.
numEntries = numEntries;
229 t_Stream.readRawData(tmp.data(),len);
230 p_Annotation.m_Colortable.
orig_tab = tmp;
232 for(qint32 i = 0; i < numEntries; ++i)
235 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
237 qint32 numEntriesToRead;
238 t_Stream >> numEntriesToRead;
241 for(qint32 i = 0; i < numEntriesToRead; ++i)
244 t_Stream >> structure;
246 printf(
"\tError! Read entry, index %d\n", structure);
248 if(!p_Annotation.m_Colortable.
struct_names[structure].isEmpty())
249 printf(
"Error! Duplicate Structure %d", structure);
253 t_Stream.readRawData(tmp.data(),len);
257 for(qint32 j = 0; j < 4; ++j)
258 t_Stream >> p_Annotation.m_Colortable.
table(structure,j);
260 p_Annotation.m_Colortable.
table(structure,4) = p_Annotation.m_Colortable.
table(structure,0)
261 + p_Annotation.m_Colortable.
table(structure,1) * 256
262 + p_Annotation.m_Colortable.
table(structure,2) * 65536
263 + p_Annotation.m_Colortable.
table(structure,3) * 16777216;
266 printf(
"\tcolortable with %d entries read\n\t(originally %s)\n", p_Annotation.m_Colortable.
numEntries, p_Annotation.m_Colortable.
orig_tab.toUtf8().constData());
270 printf(
"\tError! No colortable stored\n");
274 if(t_File.fileName().contains(
"lh."))
275 p_Annotation.m_iHemi = 0;
277 p_Annotation.m_iHemi = 1;
289 QList<Label> &p_qListLabels,
290 QList<RowVector4i> &p_qListLabelRGBAs,
291 const QStringList& lLabelPicks)
const
293 if(this->m_iHemi != p_surf.
hemi())
295 qWarning(
"Annotation and surface hemisphere (annot = %d; surf = %d) do not match!\n", this->m_iHemi, p_surf.
hemi());
299 if(m_LabelIds.size() == 0)
301 qWarning(
"Annotation doesn't' contain data!\n");
305 printf(
"Converting labels from annotation...");
312 QStringList label_names = m_Colortable.
getNames();
313 MatrixX4i label_rgbas = m_Colortable.
getRGBAs();
316 MatrixX3f vert_pos = p_surf.
rr();
322 qint32 label_id, count;
323 RowVector4i label_rgba;
328 for(qint32 i = 0; i < label_rgbas.rows(); ++i)
330 label_id = label_ids[i];
331 label_rgba = label_rgbas.row(i);
333 vertices.resize(m_LabelIds.size());
335 for(qint32 j = 0; j < m_LabelIds.size(); ++j)
337 if(m_LabelIds[j] == label_id)
346 vertices.conservativeResize(count);
348 pos.resize(count, 3);
349 for(qint32 j = 0; j < count; ++j)
350 pos.row(j) = vert_pos.row(vertices[j]);
352 values = VectorXd::Zero(count);
353 name = QString(
"%1-%2").arg(label_names[i]).arg(this->m_iHemi == 0 ?
"lh" :
"rh");
356 if(lLabelPicks.isEmpty()) {
358 p_qListLabels.append(
Label(vertices, pos, values, this->m_iHemi, name, label_id));
360 p_qListLabelRGBAs.append(label_rgba);
361 }
else if (lLabelPicks.indexOf(name) != -1) {
363 p_qListLabels.append(
Label(vertices, pos, values, this->m_iHemi, name, label_id));
365 p_qListLabelRGBAs.append(label_rgba);