118 p_Annotation.
clear();
120 qInfo(
"Reading annotation...\n");
121 QFile t_File(p_sFileName);
122 QFileInfo fileInfo(t_File.fileName());
124 p_Annotation.m_sFileName = fileInfo.fileName();
125 p_Annotation.m_sFilePath = fileInfo.filePath();
127 if (!t_File.open(QIODevice::ReadOnly))
129 qWarning(
"\tError: Couldn't open the file");
133 QDataStream t_Stream(&t_File);
134 t_Stream.setByteOrder(QDataStream::BigEndian);
139 p_Annotation.m_Vertices = VectorXi(numEl);
140 p_Annotation.m_LabelIds = VectorXi(numEl);
142 for(qint32 i = 0; i < numEl; ++i)
144 t_Stream >> p_Annotation.m_Vertices[i];
145 t_Stream >> p_Annotation.m_LabelIds[i];
148 qint32 hasColortable;
149 t_Stream >> hasColortable;
152 p_Annotation.m_Colortable.
clear();
156 t_Stream >> numEntries;
161 qInfo(
"\tReading from Original Version\n");
162 p_Annotation.m_Colortable.
numEntries = numEntries;
166 t_Stream.readRawData(tmp.data(),len);
168 if (tmp.endsWith(
'\0'))
170 p_Annotation.m_Colortable.
orig_tab = tmp;
172 for(qint32 i = 0; i < numEntries; ++i)
175 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
177 for(qint32 i = 0; i < numEntries; ++i)
181 t_Stream.readRawData(tmp.data(),len);
182 if (tmp.endsWith(
'\0'))
187 for(qint32 j = 0; j < 4; ++j)
188 t_Stream >> p_Annotation.m_Colortable.
table(i,j);
190 p_Annotation.m_Colortable.
table(i,4) = p_Annotation.m_Colortable.
table(i,0)
191 + p_Annotation.m_Colortable.
table(i,1) * 256
192 + p_Annotation.m_Colortable.
table(i,2) * 65536
193 + p_Annotation.m_Colortable.
table(i,3) * 16777216;
198 qint32 version = -numEntries;
200 qWarning(
"\tError! Does not handle version %d", version);
202 qInfo(
"\tReading from version %d\n", version);
204 t_Stream >> numEntries;
205 p_Annotation.m_Colortable.
numEntries = numEntries;
210 t_Stream.readRawData(tmp.data(),len);
212 if (tmp.endsWith(
'\0'))
214 p_Annotation.m_Colortable.
orig_tab = tmp;
216 for(qint32 i = 0; i < numEntries; ++i)
219 p_Annotation.m_Colortable.
table = MatrixXi(numEntries,5);
221 qint32 numEntriesToRead;
222 t_Stream >> numEntriesToRead;
225 for(qint32 i = 0; i < numEntriesToRead; ++i)
228 t_Stream >> structure;
230 qWarning(
"\tError! Read entry, index %d", structure);
232 if(!p_Annotation.m_Colortable.
struct_names[structure].isEmpty())
233 qWarning(
"Error! Duplicate Structure %d", structure);
237 t_Stream.readRawData(tmp.data(),len);
238 if (tmp.endsWith(
'\0'))
243 for(qint32 j = 0; j < 4; ++j)
244 t_Stream >> p_Annotation.m_Colortable.
table(structure,j);
246 p_Annotation.m_Colortable.
table(structure,4) = p_Annotation.m_Colortable.
table(structure,0)
247 + p_Annotation.m_Colortable.
table(structure,1) * 256
248 + p_Annotation.m_Colortable.
table(structure,2) * 65536
249 + p_Annotation.m_Colortable.
table(structure,3) * 16777216;
252 qInfo(
"\tcolortable with %d entries read\n\t(originally %s)\n", p_Annotation.m_Colortable.
numEntries, p_Annotation.m_Colortable.
orig_tab.toUtf8().constData());
256 qWarning(
"\tError! No colortable stored");
260 if(t_File.fileName().contains(
"lh."))
261 p_Annotation.m_iHemi = 0;
263 p_Annotation.m_iHemi = 1;
275 QList<FsLabel> &p_qListLabels,
276 QList<RowVector4i> &p_qListLabelRGBAs,
277 const QStringList& lLabelPicks)
const
279 if(this->m_iHemi != p_surf.
hemi())
281 qWarning(
"FsAnnotation and surface hemisphere (annot = %d; surf = %d) do not match!\n", this->m_iHemi, p_surf.
hemi());
285 if(m_LabelIds.size() == 0)
287 qWarning(
"FsAnnotation doesn't' contain data!\n");
291 qInfo(
"Converting labels from annotation...");
297 VectorXi label_ids = m_Colortable.getLabelIds();
298 QStringList label_names = m_Colortable.getNames();
299 MatrixX4i label_rgbas = m_Colortable.getRGBAs();
302 MatrixX3f vert_pos = p_surf.
rr();
308 qint32 label_id, count;
309 RowVector4i label_rgba;
314 for(qint32 i = 0; i < label_rgbas.rows(); ++i)
316 label_id = label_ids[i];
317 label_rgba = label_rgbas.row(i);
319 vertices.resize(m_LabelIds.size());
321 for(qint32 j = 0; j < m_LabelIds.size(); ++j)
323 if(m_LabelIds[j] == label_id)
332 vertices.conservativeResize(count);
334 pos.resize(count, 3);
335 for(qint32 j = 0; j < count; ++j)
336 pos.row(j) = vert_pos.row(vertices[j]);
338 values = VectorXd::Zero(count);
339 name = QString(
"%1-%2").arg(label_names[i]).arg(this->m_iHemi == 0 ?
"lh" :
"rh");
342 if(lLabelPicks.isEmpty()) {
344 p_qListLabels.append(
FsLabel(vertices, pos, values, this->m_iHemi, name, label_id));
346 p_qListLabelRGBAs.append(label_rgba);
347 }
else if (lLabelPicks.indexOf(name) != -1) {
349 p_qListLabels.append(
FsLabel(vertices, pos, values, this->m_iHemi, name, label_id));
351 p_qListLabelRGBAs.append(label_rgba);