121 p_Annotation.
clear();
123 qInfo(
"Reading annotation...\n");
124 QFile t_File(p_sFileName);
125 QFileInfo fileInfo(t_File.fileName());
127 p_Annotation.m_sFileName = fileInfo.fileName();
128 p_Annotation.m_sFilePath = fileInfo.filePath();
130 if (!t_File.open(QIODevice::ReadOnly)) {
131 qWarning(
"\tError: Couldn't open the file");
135 QDataStream t_Stream(&t_File);
136 t_Stream.setByteOrder(QDataStream::BigEndian);
141 p_Annotation.m_Vertices = VectorXi(numEl);
142 p_Annotation.m_LabelIds = VectorXi(numEl);
144 for (qint32 i = 0; i < numEl; ++i) {
145 t_Stream >> p_Annotation.m_Vertices[i];
146 t_Stream >> p_Annotation.m_LabelIds[i];
149 qint32 hasColortable;
150 t_Stream >> hasColortable;
152 p_Annotation.m_Colortable.
clear();
156 t_Stream >> numEntries;
158 if (numEntries > 0) {
159 qInfo(
"\tReading from Original Version\n");
160 p_Annotation.m_Colortable.
numEntries = numEntries;
164 t_Stream.readRawData(tmp.data(), len);
166 if (tmp.endsWith(
'\0'))
168 p_Annotation.m_Colortable.
orig_tab = tmp;
170 for (qint32 i = 0; i < numEntries; ++i)
173 p_Annotation.m_Colortable.
table = MatrixXi(numEntries, 5);
175 for (qint32 i = 0; i < numEntries; ++i) {
178 t_Stream.readRawData(tmp.data(), len);
179 if (tmp.endsWith(
'\0'))
184 for (qint32 j = 0; j < 4; ++j)
185 t_Stream >> p_Annotation.m_Colortable.
table(i, j);
187 p_Annotation.m_Colortable.
table(i, 4) = p_Annotation.m_Colortable.
table(i, 0) + p_Annotation.m_Colortable.
table(i, 1) * 256
188 + p_Annotation.m_Colortable.
table(i, 2) * 65536
189 + p_Annotation.m_Colortable.
table(i, 3) * 16777216;
192 qint32 version = -numEntries;
194 qWarning(
"\tError! Does not handle version %d", version);
196 qInfo(
"\tReading from version %d\n", version);
198 t_Stream >> numEntries;
199 p_Annotation.m_Colortable.
numEntries = numEntries;
204 t_Stream.readRawData(tmp.data(), len);
206 if (tmp.endsWith(
'\0'))
208 p_Annotation.m_Colortable.
orig_tab = tmp;
210 for (qint32 i = 0; i < numEntries; ++i)
213 p_Annotation.m_Colortable.
table = MatrixXi(numEntries, 5);
215 qint32 numEntriesToRead;
216 t_Stream >> numEntriesToRead;
219 for (qint32 i = 0; i < numEntriesToRead; ++i) {
220 t_Stream >> structure;
222 qWarning(
"\tError! Read entry, index %d", structure);
224 if (!p_Annotation.m_Colortable.
struct_names[structure].isEmpty())
225 qWarning(
"Error! Duplicate Structure %d", structure);
229 t_Stream.readRawData(tmp.data(), len);
230 if (tmp.endsWith(
'\0'))
233 p_Annotation.m_Colortable.
struct_names[structure] = tmp;
235 for (qint32 j = 0; j < 4; ++j)
236 t_Stream >> p_Annotation.m_Colortable.
table(structure, j);
238 p_Annotation.m_Colortable.
table(structure, 4) = p_Annotation.m_Colortable.
table(structure, 0) + p_Annotation.m_Colortable.
table(structure, 1) * 256
239 + p_Annotation.m_Colortable.
table(structure, 2) * 65536
240 + p_Annotation.m_Colortable.
table(structure, 3) * 16777216;
243 qInfo(
"\tcolortable with %d entries read\n\t(originally %s)\n", p_Annotation.m_Colortable.
numEntries, p_Annotation.m_Colortable.
orig_tab.toUtf8().constData());
245 qWarning(
"\tError! No colortable stored");
249 if (t_File.fileName().contains(
"lh."))
250 p_Annotation.m_iHemi = 0;
252 p_Annotation.m_iHemi = 1;
264 QList<FsLabel>& p_qListLabels,
265 QList<RowVector4i>& p_qListLabelRGBAs,
266 const QStringList& lLabelPicks)
const
268 if (this->m_iHemi != p_surf.
hemi()) {
269 qWarning(
"FsAnnotation and surface hemisphere (annot = %d; surf = %d) do not match!\n", this->m_iHemi, p_surf.
hemi());
273 if (m_LabelIds.size() == 0) {
274 qWarning(
"FsAnnotation doesn't' contain data!\n");
278 qInfo(
"Converting labels from annotation...");
284 VectorXi label_ids = m_Colortable.getLabelIds();
285 QStringList label_names = m_Colortable.getNames();
286 MatrixX4i label_rgbas = m_Colortable.getRGBAs();
289 MatrixX3f vert_pos = p_surf.
rr();
295 const qsizetype firstNew = p_qListLabels.size();
296 qint32 label_id, count;
297 RowVector4i label_rgba;
302 for (qint32 i = 0; i < label_rgbas.rows(); ++i) {
303 label_id = label_ids[i];
304 label_rgba = label_rgbas.row(i);
306 vertices.resize(m_LabelIds.size());
308 for (qint32 j = 0; j < m_LabelIds.size(); ++j) {
309 if (m_LabelIds[j] == label_id) {
317 vertices.conservativeResize(count);
319 pos.resize(count, 3);
320 for (qint32 j = 0; j < count; ++j)
321 pos.row(j) = vert_pos.row(vertices[j]);
323 values = VectorXd::Ones(count);
324 name = QString(
"%1-%2").arg(label_names[i]).arg(this->m_iHemi == 0 ?
"lh" :
"rh");
327 if (lLabelPicks.isEmpty()) {
329 p_qListLabels.append(
FsLabel(vertices, pos, values, this->m_iHemi, name, label_id));
331 p_qListLabelRGBAs.append(label_rgba);
332 }
else if (lLabelPicks.indexOf(name) != -1) {
334 p_qListLabels.append(
FsLabel(vertices, pos, values, this->m_iHemi, name, label_id));
336 p_qListLabelRGBAs.append(label_rgba);
368 QList<qsizetype> order(p_qListLabels.size() - firstNew);
369 std::iota(order.begin(), order.end(), firstNew);
370 std::sort(order.begin(), order.end(), [&p_qListLabels](qsizetype a, qsizetype b) { return p_qListLabels[a].name < p_qListLabels[b].name; });
371 const QList<FsLabel> labels = p_qListLabels.mid(firstNew);
372 const QList<RowVector4i> rgbas = p_qListLabelRGBAs.mid(firstNew);
373 for (qsizetype k = 0; k < order.size(); ++k) {
374 p_qListLabels[firstNew + k] = labels[order[k] - firstNew];
375 p_qListLabelRGBAs[firstNew + k] = rgbas[order[k] - firstNew];