142 p_Annotation.
clear();
144 qInfo(
"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 qWarning(
"\tError: Couldn't open the file");
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 qInfo(
"\tReading from Original Version\n");
186 p_Annotation.m_Colortable.
numEntries = numEntries;
190 t_Stream.readRawData(tmp.data(),len);
192 if (tmp.endsWith(
'\0'))
194 p_Annotation.m_Colortable.
orig_tab = tmp;
196 for(qint32 i = 0; i < numEntries; ++i)
199 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
201 for(qint32 i = 0; i < numEntries; ++i)
205 t_Stream.readRawData(tmp.data(),len);
206 if (tmp.endsWith(
'\0'))
211 for(qint32 j = 0; j < 4; ++j)
212 t_Stream >> p_Annotation.m_Colortable.
table(i,j);
214 p_Annotation.m_Colortable.
table(i,4) = p_Annotation.m_Colortable.
table(i,0)
215 + p_Annotation.m_Colortable.
table(i,1) * 256
216 + p_Annotation.m_Colortable.
table(i,2) * 65536
217 + p_Annotation.m_Colortable.
table(i,3) * 16777216;
222 qint32 version = -numEntries;
224 qWarning(
"\tError! Does not handle version %d", version);
226 qInfo(
"\tReading from version %d\n", version);
228 t_Stream >> numEntries;
229 p_Annotation.m_Colortable.
numEntries = numEntries;
234 t_Stream.readRawData(tmp.data(),len);
236 if (tmp.endsWith(
'\0'))
238 p_Annotation.m_Colortable.
orig_tab = tmp;
240 for(qint32 i = 0; i < numEntries; ++i)
243 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
245 qint32 numEntriesToRead;
246 t_Stream >> numEntriesToRead;
249 for(qint32 i = 0; i < numEntriesToRead; ++i)
252 t_Stream >> structure;
254 qWarning(
"\tError! Read entry, index %d", structure);
256 if(!p_Annotation.m_Colortable.
struct_names[structure].isEmpty())
257 qWarning(
"Error! Duplicate Structure %d", structure);
261 t_Stream.readRawData(tmp.data(),len);
262 if (tmp.endsWith(
'\0'))
267 for(qint32 j = 0; j < 4; ++j)
268 t_Stream >> p_Annotation.m_Colortable.
table(structure,j);
270 p_Annotation.m_Colortable.
table(structure,4) = p_Annotation.m_Colortable.
table(structure,0)
271 + p_Annotation.m_Colortable.
table(structure,1) * 256
272 + p_Annotation.m_Colortable.
table(structure,2) * 65536
273 + p_Annotation.m_Colortable.
table(structure,3) * 16777216;
276 qInfo(
"\tcolortable with %d entries read\n\t(originally %s)\n", p_Annotation.m_Colortable.
numEntries, p_Annotation.m_Colortable.
orig_tab.toUtf8().constData());
280 qWarning(
"\tError! No colortable stored");
284 if(t_File.fileName().contains(
"lh."))
285 p_Annotation.m_iHemi = 0;
287 p_Annotation.m_iHemi = 1;
299 QList<FsLabel> &p_qListLabels,
300 QList<RowVector4i> &p_qListLabelRGBAs,
301 const QStringList& lLabelPicks)
const
303 if(this->m_iHemi != p_surf.
hemi())
305 qWarning(
"FsAnnotation and surface hemisphere (annot = %d; surf = %d) do not match!\n", this->m_iHemi, p_surf.
hemi());
309 if(m_LabelIds.size() == 0)
311 qWarning(
"FsAnnotation doesn't' contain data!\n");
315 qInfo(
"Converting labels from annotation...");
321 VectorXi label_ids = m_Colortable.getLabelIds();
322 QStringList label_names = m_Colortable.getNames();
323 MatrixX4i label_rgbas = m_Colortable.getRGBAs();
326 MatrixX3f vert_pos = p_surf.
rr();
332 qint32 label_id, count;
333 RowVector4i label_rgba;
338 for(qint32 i = 0; i < label_rgbas.rows(); ++i)
340 label_id = label_ids[i];
341 label_rgba = label_rgbas.row(i);
343 vertices.resize(m_LabelIds.size());
345 for(qint32 j = 0; j < m_LabelIds.size(); ++j)
347 if(m_LabelIds[j] == label_id)
356 vertices.conservativeResize(count);
358 pos.resize(count, 3);
359 for(qint32 j = 0; j < count; ++j)
360 pos.row(j) = vert_pos.row(vertices[j]);
362 values = VectorXd::Zero(count);
363 name = QString(
"%1-%2").arg(label_names[i]).arg(this->m_iHemi == 0 ?
"lh" :
"rh");
366 if(lLabelPicks.isEmpty()) {
368 p_qListLabels.append(
FsLabel(vertices, pos, values, this->m_iHemi, name, label_id));
370 p_qListLabelRGBAs.append(label_rgba);
371 }
else if (lLabelPicks.indexOf(name) != -1) {
373 p_qListLabels.append(
FsLabel(vertices, pos, values, this->m_iHemi, name, label_id));
375 p_qListLabelRGBAs.append(label_rgba);