MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
sourcespacetreeitem.cpp
Go to the documentation of this file.
1//=============================================================================================================
36//=============================================================================================================
37// INCLUDES
38//=============================================================================================================
39
40#include "sourcespacetreeitem.h"
41#include "../common/metatreeitem.h"
42#include "../../3dhelpers/renderable3Dentity.h"
43#include "../../3dhelpers/custommesh.h"
44#include "../../3dhelpers/geometrymultiplier.h"
45#include "../../materials/geometrymultipliermaterial.h"
46
47#include <mne/mne_hemisphere.h>
48
49//=============================================================================================================
50// QT INCLUDES
51//=============================================================================================================
52
53#include <Qt3DExtras/QSphereGeometry>
54#include <QMatrix4x4>
55
56//=============================================================================================================
57// EIGEN INCLUDES
58//=============================================================================================================
59
60#include <Eigen/Core>
61
62//=============================================================================================================
63// USED NAMESPACES
64//=============================================================================================================
65
66using namespace Eigen;
67using namespace MNELIB;
68using namespace DISP3DLIB;
69
70//=============================================================================================================
71// DEFINE MEMBER METHODS
72//=============================================================================================================
73
74SourceSpaceTreeItem::SourceSpaceTreeItem(Qt3DCore::QEntity *p3DEntityParent, int iType, const QString& text)
75: AbstractMeshTreeItem(p3DEntityParent, iType, text)
76{
77 initItem();
78}
79
80//=============================================================================================================
81
83{
84 this->setEditable(false);
85 this->setCheckable(true);
86 this->setCheckState(Qt::Checked);
87 this->setToolTip("Source space item");
88}
89
90//=============================================================================================================
91
93{
94 //Create color from curvature information with default gyri and sulcus colors
95 MatrixX4f matVertColor = createVertColor(tHemisphere.rr.rows());
96
97 //Set renderable 3D entity mesh and color data
98 m_pCustomMesh->setMeshData(tHemisphere.rr,
99 tHemisphere.nn,
100 tHemisphere.tris,
101 matVertColor,
102 Qt3DRender::QGeometryRenderer::Triangles);
103
104 //Add data which is held by this SourceSpaceTreeItem
105 QVariant data;
106
107 data.setValue(tHemisphere.rr.rows());
108 this->setData(data, Data3DTreeModelItemRoles::NumberVertices);
109
110 plotSources(tHemisphere);
111
112 this->setAlpha(1.0f);
113}
114
115//=============================================================================================================
116
118{
119 //use QEntity instead of Renderable3DEntity to avoid a double transformation of digitizers
120 //from Abstract3DMeshTree and the child Renderable3DEntity
121 QEntity* pSourceSphereEntity = new QEntity(this);
122
123 //create geometry
124 QSharedPointer<Qt3DExtras::QSphereGeometry> pSourceSphereGeometry = QSharedPointer<Qt3DExtras::QSphereGeometry>::create();
125 pSourceSphereGeometry->setRadius(0.00075f);
126 //create instanced renderer
127 GeometryMultiplier *pSphereMesh = new GeometryMultiplier(pSourceSphereGeometry);
128
129 //Create transform matrix for each sphere instance
130 QVector<QMatrix4x4> vTransforms;
131 QVector3D tempPos;
132
133 if(tHemisphere.isClustered())
134 {
135 vTransforms.reserve(tHemisphere.cluster_info.centroidVertno.size());
136
137 for(int i = 0; i < tHemisphere.cluster_info.centroidVertno.size(); i++)
138 {
139 QMatrix4x4 tempTransform;
140 const RowVector3f& sourcePos = tHemisphere.rr.row(tHemisphere.cluster_info.centroidVertno.at(i));
141
142 tempPos.setX(sourcePos(0));
143 tempPos.setY(sourcePos(1));
144 tempPos.setZ(sourcePos(2));
145
146 //Set position
147 tempTransform.translate(tempPos);
148 vTransforms.push_back(tempTransform);
149 }
150 }
151 else
152 {
153 vTransforms.reserve(tHemisphere.vertno.rows());
154
155 for(int i = 0; i < tHemisphere.vertno.rows(); i++)
156 {
157 QMatrix4x4 tempTransform;
158 const RowVector3f& sourcePos = tHemisphere.rr.row(tHemisphere.vertno(i));
159
160 tempPos.setX(sourcePos(0));
161 tempPos.setY(sourcePos(1));
162 tempPos.setZ(sourcePos(2));
163
164 //Set position
165 tempTransform.translate(tempPos);
166 vTransforms.push_back(tempTransform);
167 }
168 }
169 //Set instance Transform
170 pSphereMesh->setTransforms(vTransforms);
171
172 pSourceSphereEntity->addComponent(pSphereMesh);
173
174 //Add material
176 QColor defaultColor(212, 28, 92);
177 pMaterial->setAmbient(defaultColor);
178 pMaterial->setAlpha(1.0f);
179
180 pSourceSphereEntity->addComponent(pMaterial);
181}
MNEHemisphere class declaration.
SourceSpaceTreeItem class declaration.
void setTransforms(const QVector< QMatrix4x4 > &tInstanceTansform)
static Eigen::MatrixX4f createVertColor(int numVert, const QColor &color=QColor(0, 49, 69))
Provides a generic mesh tree item.
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
SourceSpaceTreeItem(Qt3DCore::QEntity *p3DEntityParent=0, int iType=Data3DTreeModelItemTypes::SourceSpaceItem, const QString &text="Source space")
void addData(const MNELIB::MNEHemisphere &tHemisphere)
void plotSources(const MNELIB::MNEHemisphere &tHemisphere)
Custom phong alpha material for instanced rendering.
QList< qint32 > centroidVertno
Hemisphere provides geometry information.
Eigen::VectorXi vertno
Eigen::MatrixX3i tris
Eigen::MatrixX3f nn
Eigen::MatrixX3f rr
MNEClusterInfo cluster_info