MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
fssurfacetreeitem.cpp
Go to the documentation of this file.
1//=============================================================================================================
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "fssurfacetreeitem.h"
42#include "../common/metatreeitem.h"
43#include "../../3dhelpers/renderable3Dentity.h"
44#include "../../materials/pervertexphongalphamaterial.h"
45#include "../../materials/shownormalsmaterial.h"
46#include "../../3dhelpers/custommesh.h"
47
48#include <fs/label.h>
49#include <fs/surface.h>
50
51//=============================================================================================================
52// QT INCLUDES
53//=============================================================================================================
54
55//=============================================================================================================
56// EIGEN INCLUDES
57//=============================================================================================================
58
59#include <Eigen/Core>
60
61//=============================================================================================================
62// USED NAMESPACES
63//=============================================================================================================
64
65using namespace DISP3DLIB;
66using namespace Eigen;
67using namespace FSLIB;
68
69//=============================================================================================================
70// DEFINE MEMBER METHODS
71//=============================================================================================================
72
73FsSurfaceTreeItem::FsSurfaceTreeItem(Qt3DCore::QEntity *p3DEntityParent, int iType, const QString& text)
74: AbstractMeshTreeItem(p3DEntityParent, iType, text)
75, m_sColorInfoOrigin("Color from curvature")
76{
77 initItem();
78}
79
80//=============================================================================================================
81
83{
84 this->setToolTip("Brain hemisphere surface item");
85
86 //Use SortPolicy in frame graph
87 this->removeComponent(m_pMaterial);
89 this->addComponent(m_pMaterial);
90
91 //Add surface meta information as item children
92 QList<QStandardItem*> list;
93 QVariant data;
94
96 m_pItemSurfColSulci = new MetaTreeItem(MetaTreeItemTypes::SurfaceColorSulci, "Sulci color");
97 }
98
101 list << m_pItemSurfColSulci;
102 list << new QStandardItem(m_pItemSurfColSulci->toolTip());
103 m_pItemAppearanceOptions->appendRow(list);
104 data.setValue(QColor(50,50,50));
105 m_pItemSurfColSulci->setData(data, MetaTreeItemRoles::SurfaceColorSulci);
106 m_pItemSurfColSulci->setData(data, Qt::DecorationRole);
107
108 if(!m_pItemSurfColGyri) {
109 m_pItemSurfColGyri = new MetaTreeItem(MetaTreeItemTypes::SurfaceColorGyri, "Gyri color");
110 }
111
114 list.clear();
115 list << m_pItemSurfColGyri;
116 list << new QStandardItem(m_pItemSurfColGyri->toolTip());
117 m_pItemAppearanceOptions->appendRow(list);
118 data.setValue(QColor(125,125,125));
119 m_pItemSurfColGyri->setData(data, MetaTreeItemRoles::SurfaceColorGyri);
120 m_pItemSurfColGyri->setData(data, Qt::DecorationRole);
121
122 this->setAlpha(1.0f);
123}
124
125//=============================================================================================================
126
128{
129 //Create color from curvature information with default gyri and sulcus colors
130 MatrixX4f matCurvatureColor = createCurvatureVertColor(tSurface.curv());
131
132 //Set renderable 3D entity mesh and color data
133 m_pCustomMesh->setMeshData(tSurface.rr(),
134 tSurface.nn(),
135 tSurface.tris(),
136 matCurvatureColor,
137 Qt3DRender::QGeometryRenderer::Triangles);
138 this->setPosition(QVector3D(-tSurface.offset()(0), -tSurface.offset()(1), -tSurface.offset()(2)));
139
140 //Add data which is held by this FsSurfaceTreeItem
141 QVariant data;
142
143 data.setValue(matCurvatureColor);
144 this->setData(data, Data3DTreeModelItemRoles::SurfaceCurrentColorVert);
145
146 data.setValue(tSurface.curv());
147 this->setData(data, Data3DTreeModelItemRoles::SurfaceCurv);
148
149 data.setValue(tSurface.rr().rows());
150 this->setData(data, Data3DTreeModelItemRoles::NumberVertices);
151
152 //Add data which is held by this FsSurfaceTreeItem
153 QList<QStandardItem*> list;
154
155 MetaTreeItem *itemSurfFileName = new MetaTreeItem(MetaTreeItemTypes::FileName, tSurface.fileName());
156 itemSurfFileName->setEditable(false);
157 list.clear();
158 list << itemSurfFileName;
159 list << new QStandardItem(itemSurfFileName->toolTip());
160 this->appendRow(list);
161 data.setValue(tSurface.fileName());
162 itemSurfFileName->setData(data, MetaTreeItemRoles::SurfaceFileName);
163
164// MetaTreeItem *itemSurfPath = new MetaTreeItem(MetaTreeItemTypes::FilePath, tSurface.filePath());
165// itemSurfPath->setEditable(false);
166// list.clear();
167// list << itemSurfPath;
168// list << new QStandardItem(itemSurfPath->toolTip());
169// this->appendRow(list);
170// data.setValue(tSurface.filePath());
171// itemSurfPath->setData(data, MetaTreeItemRoles::SurfaceFilePath);
172}
173
174//=============================================================================================================
175
177{
178 if(isVisible) {
179 m_sColorInfoOrigin = "Color from annotation";
180 } else {
181 m_sColorInfoOrigin = "Color from curvature";
182 }
183
185}
186
187//=============================================================================================================
188
189MatrixX4f FsSurfaceTreeItem::createCurvatureVertColor(const VectorXf& curvature,
190 const QColor& colSulci,
191 const QColor& colGyri)
192{
193 MatrixX4f colors(curvature.rows(), 4);
194
195 for(int i = 0; i < colors.rows(); ++i) {
196 //Color (this is the default color and will be used until the updateVertColor function was called)
197 if(curvature(i) >= 0) {
198 colors(i,0) = colSulci.redF();
199 colors(i,1) = colSulci.greenF();
200 colors(i,2) = colSulci.blueF();
201 colors(i,3) = colSulci.alphaF();
202 } else {
203 colors(i,0) = colGyri.redF();
204 colors(i,1) = colGyri.greenF();
205 colors(i,2) = colGyri.blueF();
206 colors(i,3) = colGyri.alphaF();
207 }
208 }
209
210 return colors;
211}
212
213//=============================================================================================================
214
216{
218 QVariant data;
219 MatrixX4f matNewVertColor;
220
221 if(m_sColorInfoOrigin.contains("Color from curvature")) {
222 //Create color from curvature information with default gyri and sulcus colors
223 QColor colorSulci = m_pItemSurfColSulci->data(MetaTreeItemRoles::SurfaceColorSulci).value<QColor>();
224 QColor colorGyri = m_pItemSurfColGyri->data(MetaTreeItemRoles::SurfaceColorGyri).value<QColor>();
225
226 matNewVertColor = createCurvatureVertColor(this->data(Data3DTreeModelItemRoles::SurfaceCurv).value<VectorXf>(), colorSulci, colorGyri);
227
228 data.setValue(matNewVertColor);
229 this->setData(data, Data3DTreeModelItemRoles::SurfaceCurrentColorVert);
230
231 //Return here because the new colors will be set to the renderable entity in the setData() function with the role Data3DTreeModelItemRoles::SurfaceCurrentColorVert
232 return;
233 }
234
235 if(m_sColorInfoOrigin.contains("Color from annotation")) {
236 //Find the FsAnnotationTreeItem
237 for(int i = 0; i < this->QStandardItem::parent()->rowCount(); ++i) {
238 if(this->QStandardItem::parent()->child(i,0)->type() == Data3DTreeModelItemTypes::AnnotationItem) {
239 matNewVertColor = this->QStandardItem::parent()->child(i,0)->data(Data3DTreeModelItemRoles::AnnotColors).value<MatrixX4f>();
240
241 //Set renderable 3D entity mesh and color data
242 data.setValue(matNewVertColor);
243 this->setData(data, Data3DTreeModelItemRoles::SurfaceCurrentColorVert);
244
245 //Return here because the new colors will be set to the renderable entity in the setData() function with the role Data3DTreeModelItemRoles::SurfaceCurrentColorVert
246 return;
247 }
248 }
249 }
250 }
251}
252
Label class declaration.
Surface class declaration.
FsSurfaceTreeItem class declaration.
virtual void setPosition(const QVector3D &position)
QPointer< MetaTreeItem > m_pItemAppearanceOptions
Provides a generic mesh tree item.
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
QPointer< Qt3DRender::QMaterial > m_pMaterial
Provides a generic brain tree item.
void dataChanged(const QVariant &data)
void setData(const QVariant &value, int role=Qt::UserRole+1)
void addData(const FSLIB::Surface &tSurface)
QPointer< MetaTreeItem > m_pItemSurfColGyri
QPointer< MetaTreeItem > m_pItemSurfColSulci
FsSurfaceTreeItem(Qt3DCore::QEntity *p3DEntityParent=0, int iType=Data3DTreeModelItemTypes::SurfaceItem, const QString &text="Surface")
static Eigen::MatrixX4f createCurvatureVertColor(const Eigen::VectorXf &curvature, const QColor &colSulci=QColor(50, 50, 50), const QColor &colGyri=QColor(125, 125, 125))
void onAnnotationVisibilityChanged(bool isVisible)
PerVertexPhongAlphaMaterial is provides a Qt3D material with own shader support.
FreeSurfer surface mesh.
Definition surface.h:76
const Eigen::MatrixX3f & nn() const
Definition surface.h:336
const Eigen::Vector3f & offset() const
Definition surface.h:350
const Eigen::MatrixX3f & rr() const
Definition surface.h:322
const Eigen::VectorXf & curv() const
Definition surface.h:343
QString fileName() const
Definition surface.h:371
const Eigen::MatrixX3i & tris() const
Definition surface.h:329