MNE-CPP  0.1.9
A Framework for Electrophysiology
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 
66 using namespace Eigen;
67 using namespace MNELIB;
68 using namespace DISP3DLIB;
69 
70 //=============================================================================================================
71 // DEFINE MEMBER METHODS
72 //=============================================================================================================
73 
74 SourceSpaceTreeItem::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 }
DISP3DLIB::AbstractMeshTreeItem::setData
virtual void setData(const QVariant &value, int role=Qt::UserRole+1)
Definition: abstractmeshtreeitem.cpp:169
MNELIB::MNEClusterInfo::centroidVertno
QList< qint32 > centroidVertno
Definition: mne_cluster_info.h:126
MNELIB::MNEHemisphere::nn
Eigen::MatrixX3f nn
Definition: mne_hemisphere.h:186
DISP3DLIB::AbstractPhongAlphaMaterial::setAlpha
virtual void setAlpha(float fAlpha)
Definition: abstractphongalphamaterial.cpp:101
DISP3DLIB::SourceSpaceTreeItem::addData
void addData(const MNELIB::MNEHemisphere &tHemisphere)
Definition: sourcespacetreeitem.cpp:92
DISP3DLIB::AbstractMeshTreeItem::m_pCustomMesh
QPointer< CustomMesh > m_pCustomMesh
Definition: abstractmeshtreeitem.h:200
DISP3DLIB::GeometryMultiplier::setTransforms
void setTransforms(const QVector< QMatrix4x4 > &tInstanceTansform)
Definition: geometrymultiplier.cpp:96
sourcespacetreeitem.h
SourceSpaceTreeItem class declaration.
DISP3DLIB::GeometryMultiplierMaterial::setAmbient
void setAmbient(const QColor &ambientColor)
Definition: geometrymultipliermaterial.cpp:100
MNELIB::MNEHemisphere::rr
Eigen::MatrixX3f rr
Definition: mne_hemisphere.h:185
DISP3DLIB::SourceSpaceTreeItem::plotSources
void plotSources(const MNELIB::MNEHemisphere &tHemisphere)
Definition: sourcespacetreeitem.cpp:117
DISP3DLIB::GeometryMultiplier
Instaced based renderer.
Definition: geometrymultiplier.h:99
DISP3DLIB::GeometryMultiplierMaterial
Custom phong alpha material for instanced rendering.
Definition: geometrymultipliermaterial.h:90
DISP3DLIB::SourceSpaceTreeItem::initItem
void initItem()
Definition: sourcespacetreeitem.cpp:82
mne_hemisphere.h
MNEHemisphere class declaration.
MNELIB::MNEHemisphere::vertno
Eigen::VectorXi vertno
Definition: mne_hemisphere.h:190
MNELIB::MNEHemisphere::isClustered
bool isClustered() const
Definition: mne_hemisphere.h:219
MNELIB::MNEHemisphere::cluster_info
MNEClusterInfo cluster_info
Definition: mne_hemisphere.h:209
DISP3DLIB::Abstract3DTreeItem::setAlpha
void setAlpha(float fAlpha)
Definition: abstract3Dtreeitem.cpp:262
DISP3DLIB::AbstractMeshTreeItem
Provides a generic mesh tree item.
Definition: abstractmeshtreeitem.h:90
MNELIB::MNEHemisphere
Hemisphere provides geometry information.
Definition: mne_hemisphere.h:80
DISP3DLIB::Abstract3DTreeItem::createVertColor
static Eigen::MatrixX4f createVertColor(int numVert, const QColor &color=QColor(0, 49, 69))
Definition: abstract3Dtreeitem.cpp:246
MNELIB::MNEHemisphere::tris
Eigen::MatrixX3i tris
Definition: mne_hemisphere.h:187