bool BrainAnnotationTreeItem::addData(const Surface& tSurface, const Annotation& tAnnotation) { //Create color from annotation data if annotation is not empty if(!tAnnotation.isEmpty()) { QByteArray arrayColorsAnnot; arrayColorsAnnot.resize(tAnnotation.getVertices().rows() * 3 * (int)sizeof(float)); float *rawArrayColors = reinterpret_cast<float *>(arrayColorsAnnot.data()); QList<FSLIB::Label> qListLabels; QList<RowVector4i> qListLabelRGBAs; tAnnotation.toLabels(tSurface, qListLabels, qListLabelRGBAs); for(int i = 0; i<qListLabels.size(); i++) { FSLIB::Label label = qListLabels.at(i); for(int j = 0; j<label.vertices.rows(); j++) { rawArrayColors[label.vertices(j)*3+0] = qListLabelRGBAs.at(i)(0)/255.0; rawArrayColors[label.vertices(j)*3+1] = qListLabelRGBAs.at(i)(1)/255.0; rawArrayColors[label.vertices(j)*3+2] = qListLabelRGBAs.at(i)(2)/255.0; } } //Add data which is held by this BrainAnnotationTreeItem QVariant data; data.setValue(arrayColorsAnnot); this->setData(data, BrainAnnotationTreeItemRoles::AnnotColors); data.setValue(qListLabels); this->setData(data, BrainAnnotationTreeItemRoles::LabeList); data.setValue(tAnnotation.getLabelIds()); this->setData(data, BrainAnnotationTreeItemRoles::LabeIds); //Add annotation meta information as item children BrainTreeMetaItem *itemAnnotFileName = new BrainTreeMetaItem(BrainTreeMetaItemTypes::AnnotFileName, tAnnotation.fileName()); itemAnnotFileName->setEditable(false); *this<<itemAnnotFileName; data.setValue(tAnnotation.fileName()); itemAnnotFileName->setData(data, BrainAnnotationTreeItemRoles::AnnotFileName); BrainTreeMetaItem *itemAnnotPath = new BrainTreeMetaItem(BrainTreeMetaItemTypes::AnnotFilePath, tAnnotation.filePath()); itemAnnotPath->setEditable(false); *this<<itemAnnotPath; data.setValue(tAnnotation.filePath()); itemAnnotFileName->setData(data, BrainAnnotationTreeItemRoles::AnnotFilePath); } return true; }
BrainObject::BrainObject(const Surface &tSurface, const Annotation &tAnnotation, Qt3DCore::QEntity *parent) : Renderable3DEntity(tSurface.rr(), tSurface.nn(), tSurface.tris(), -tSurface.offset(), parent) , m_sFilePath(tSurface.filePath()) , m_sSurfFileName(tSurface.fileName()) , m_iHemi(tSurface.hemi()) , m_sSurf(tSurface.surf()) , m_vecCurv(tSurface.curv()) , m_vecOffset(tSurface.offset()) , m_ColorGyri(QColor(125,125,125)) , m_ColorSulci(QColor(50,50,50)) , m_matVert(tSurface.rr()) , m_matTris(tSurface.tris()) , m_matNorm(tSurface.nn()) , m_sAnnotFilePath(tAnnotation.fileName()) { //Create color from curvature information m_matColorsOrig.resize(m_matVert.rows(), m_matVert.cols()); for(int i = 0; i<m_matVert.rows() ; i++) { if(m_vecCurv[i] >= 0) { m_matColorsOrig(i, 0) = m_ColorSulci.redF(); m_matColorsOrig(i, 1) = m_ColorSulci.greenF(); m_matColorsOrig(i, 2) = m_ColorSulci.blueF(); } else { m_matColorsOrig(i, 0) = m_ColorGyri.redF(); m_matColorsOrig(i, 1) = m_ColorGyri.greenF(); m_matColorsOrig(i, 2) = m_ColorGyri.blueF(); } } //Create color from annotation data if annotation is not empty if(tAnnotation.getVertices().rows() != 0) { tAnnotation.toLabels(tSurface, m_qListLabels, m_qListLabelRGBAs); m_matColorsAnnot.resize(m_matVert.rows(), m_matVert.cols()); for(int i = 0; i<m_qListLabels.size(); i++) { FSLIB::Label label = m_qListLabels.at(i); for(int j = 0; j<label.vertices.rows(); j++) { m_matColorsAnnot(label.vertices(j), 0) = m_qListLabelRGBAs.at(i)(0)/255.0; m_matColorsAnnot(label.vertices(j), 1) = m_qListLabelRGBAs.at(i)(1)/255.0; m_matColorsAnnot(label.vertices(j), 2) = m_qListLabelRGBAs.at(i)(2)/255.0; } } } }
QPair<QByteArray, QByteArray> RtSourceLocDataWorker::performVisualizationTypeCalculation(const VectorXd& sourceColorSamples) { QPair<QByteArray, QByteArray> colorPair; colorPair.first = m_arraySurfaceVertColorLeftHemi; colorPair.second = m_arraySurfaceVertColorRightHemi; //NOTE: This function is called for every new sample point and therefore must be kept highly efficient! if(sourceColorSamples.rows() != m_vecVertNoLeftHemi.rows() + m_vecVertNoRightHemi.rows()) { qDebug() << "RtSourceLocDataWorker::performVisualizationTypeCalculation - number of rows in sample (" << sourceColorSamples.rows() << ") do not not match with idx/no number of rows in vertex (" << m_vecVertNoLeftHemi.rows() + m_vecVertNoRightHemi.rows() << "). Returning..."; return colorPair; } //Cut out left and right hemisphere from source data VectorXd sourceColorSamplesLeftHemi = sourceColorSamples.segment(0,m_vecVertNoLeftHemi.rows()); VectorXd sourceColorSamplesRightHemi = sourceColorSamples.segment(m_vecVertNoLeftHemi.rows()+1,m_vecVertNoRightHemi.rows()); //Generate color data for vertices switch(m_iVisualizationType) { case Data3DTreeModelItemRoles::VertexBased: { if(!m_bSurfaceDataIsInit) { qDebug() << "RtSourceLocDataWorker::performVisualizationTypeCalculation - Surface data was not initialized. Returning ..."; return colorPair; } //Left hemisphere QByteArray arrayCurrentVertColorLeftHemi = m_arraySurfaceVertColorLeftHemi; float *rawArrayCurrentVertColorLeftHemi = reinterpret_cast<float *>(arrayCurrentVertColorLeftHemi.data()); //Create final QByteArray with colors based on the current anatomical information for(int i = 0; i < m_vecVertNoLeftHemi.rows(); ++i) { VectorXd vecActivationLeftHemi(1); vecActivationLeftHemi(0) = sourceColorSamplesLeftHemi(i); if(vecActivationLeftHemi(0) >= m_vecThresholds.x()) { QByteArray sourceColorSamplesColorLeftHemi = transformDataToColor(vecActivationLeftHemi); const float *rawSourceColorSamplesColorLeftHemi = reinterpret_cast<const float *>(sourceColorSamplesColorLeftHemi.data()); rawArrayCurrentVertColorLeftHemi[m_vecVertNoLeftHemi(i)*3+0] = rawSourceColorSamplesColorLeftHemi[0]; rawArrayCurrentVertColorLeftHemi[m_vecVertNoLeftHemi(i)*3+1] = rawSourceColorSamplesColorLeftHemi[1]; rawArrayCurrentVertColorLeftHemi[m_vecVertNoLeftHemi(i)*3+2] = rawSourceColorSamplesColorLeftHemi[2]; } } colorPair.first = arrayCurrentVertColorLeftHemi; //Right hemisphere QByteArray arrayCurrentVertColorRightHemi = m_arraySurfaceVertColorRightHemi; float *rawArrayCurrentVertColorRightHemi = reinterpret_cast<float *>(arrayCurrentVertColorRightHemi.data()); //Create final QByteArray with colors based on the current anatomical information for(int i = 0; i < m_vecVertNoRightHemi.rows(); ++i) { VectorXd vecActivationRightHemi(1); vecActivationRightHemi(0) = sourceColorSamplesRightHemi(i); if(vecActivationRightHemi(0) >= m_vecThresholds.x()) { QByteArray sourceColorSamplesColorRightHemi = transformDataToColor(vecActivationRightHemi); const float *rawSourceColorSamplesColorRightHemi = reinterpret_cast<const float *>(sourceColorSamplesColorRightHemi.data()); rawArrayCurrentVertColorRightHemi[m_vecVertNoRightHemi(i)*3+0] = rawSourceColorSamplesColorRightHemi[0]; rawArrayCurrentVertColorRightHemi[m_vecVertNoRightHemi(i)*3+1] = rawSourceColorSamplesColorRightHemi[1]; rawArrayCurrentVertColorRightHemi[m_vecVertNoRightHemi(i)*3+2] = rawSourceColorSamplesColorRightHemi[2]; } } colorPair.second = arrayCurrentVertColorRightHemi; return colorPair; } case Data3DTreeModelItemRoles::AnnotationBased: { if(!m_bAnnotationDataIsInit) { qDebug() << "RtSourceLocDataWorker::performVisualizationTypeCalculation - Annotation data was not initialized. Returning ..."; return colorPair; } //Find maximum actiavtion for each label QMap<qint32, double> vecLabelActivationLeftHemi; for(int i = 0; i < m_vecVertNoLeftHemi.rows(); ++i) { //Find out label for source qint32 labelIdxLeftHemi = m_mapLabelIdSourcesLeftHemi[m_vecVertNoLeftHemi(i)]; if(abs(sourceColorSamplesLeftHemi(i)) > abs(vecLabelActivationLeftHemi[labelIdxLeftHemi])) vecLabelActivationLeftHemi.insert(labelIdxLeftHemi, sourceColorSamplesLeftHemi(i)); } QMap<qint32, double> vecLabelActivationRightHemi; for(int i = 0; i < m_vecVertNoRightHemi.rows(); ++i) { //Find out label for source qint32 labelIdxRightHemi = m_mapLabelIdSourcesRightHemi[m_vecVertNoRightHemi(i)]; if(abs(sourceColorSamplesRightHemi(i)) > abs(vecLabelActivationRightHemi[labelIdxRightHemi])) vecLabelActivationRightHemi.insert(labelIdxRightHemi, sourceColorSamplesRightHemi(i)); } //Color all labels respectivley to their activation //Left hemisphere QByteArray arrayCurrentVertColorLeftHemi; //arrayCurrentVertColor.resize(m_arraySurfaceVertColor.size()); arrayCurrentVertColorLeftHemi = m_arraySurfaceVertColorLeftHemi; float *rawArrayCurrentVertColorLeftHemi = reinterpret_cast<float *>(arrayCurrentVertColorLeftHemi.data()); for(int i = 0; i<m_lLabelsLeftHemi.size(); i++) { FSLIB::Label labelLeftHemi = m_lLabelsLeftHemi.at(i); //Transform label activations to rgb colors VectorXd vecActivationLeftHemi(1); vecActivationLeftHemi(0) = vecLabelActivationLeftHemi[labelLeftHemi.label_id]; //Check if value is bigger than lower threshold. If not, don't plot activation if(vecActivationLeftHemi(0) >= m_vecThresholds.x()) { QByteArray arrayLabelColorsLeftHemi = transformDataToColor(vecActivationLeftHemi); float *rawArrayLabelColorsLeftHemi = reinterpret_cast<float *>(arrayLabelColorsLeftHemi.data()); for(int j = 0; j<labelLeftHemi.vertices.rows(); j++) { rawArrayCurrentVertColorLeftHemi[labelLeftHemi.vertices(j)*3+0] = rawArrayLabelColorsLeftHemi[0]; rawArrayCurrentVertColorLeftHemi[labelLeftHemi.vertices(j)*3+1] = rawArrayLabelColorsLeftHemi[1]; rawArrayCurrentVertColorLeftHemi[labelLeftHemi.vertices(j)*3+2] = rawArrayLabelColorsLeftHemi[2]; } } } colorPair.first = arrayCurrentVertColorLeftHemi; //Right hemisphere QByteArray arrayCurrentVertColorRightHemi; //arrayCurrentVertColor.resize(m_arraySurfaceVertColor.size()); arrayCurrentVertColorRightHemi = m_arraySurfaceVertColorRightHemi; float *rawArrayCurrentVertColorRightHemi = reinterpret_cast<float *>(arrayCurrentVertColorRightHemi.data()); for(int i = 0; i<m_lLabelsRightHemi.size(); i++) { FSLIB::Label labelRightHemi = m_lLabelsRightHemi.at(i); //Transform label activations to rgb colors VectorXd vecActivationRightHemi(1); vecActivationRightHemi(0) = vecLabelActivationRightHemi[labelRightHemi.label_id]; //Check if value is bigger than lower threshold. If not, don't plot activation if(vecActivationRightHemi(0) >= m_vecThresholds.x()) { QByteArray arrayLabelColorsRightHemi = transformDataToColor(vecActivationRightHemi); float *rawArrayLabelColorsRightHemi = reinterpret_cast<float *>(arrayLabelColorsRightHemi.data()); for(int j = 0; j<labelRightHemi.vertices.rows(); j++) { rawArrayCurrentVertColorRightHemi[labelRightHemi.vertices(j)*3+0] = rawArrayLabelColorsRightHemi[0]; rawArrayCurrentVertColorRightHemi[labelRightHemi.vertices(j)*3+1] = rawArrayLabelColorsRightHemi[1]; rawArrayCurrentVertColorRightHemi[labelRightHemi.vertices(j)*3+2] = rawArrayLabelColorsRightHemi[2]; } } } colorPair.second = arrayCurrentVertColorRightHemi; return colorPair; } case Data3DTreeModelItemRoles::SmoothingBased: { //TODO: Smooth here! break; } } return colorPair; }