MNE-CPP  beta 1.0
brainview.cpp
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "brainview.h"
42 
43 
44 //*************************************************************************************************************
45 //=============================================================================================================
46 // QT INCLUDES
47 //=============================================================================================================
48 
49 #include <QMouseEvent>
50 
51 
52 //*************************************************************************************************************
53 //=============================================================================================================
54 // USED NAMESPACES
55 //=============================================================================================================
56 
57 using namespace DISP3DNEWLIB;
58 
59 
60 //*************************************************************************************************************
61 //=============================================================================================================
62 // DEFINE MEMBER METHODS
63 //=============================================================================================================
64 
66 : Qt3D::Window()
67 , m_pStcDataModel(QSharedPointer<StcDataModel>(new StcDataModel(this)))
68 {
69  init(QString(), QString(), -1, QString(), QString(), QString());
70 }
71 
72 
73 //*************************************************************************************************************
74 
75 BrainView::BrainView(const QString &subject_id, qint32 hemi, const QString &surf, const QString &subjects_dir)
76 : Qt3D::Window()
77 , m_pStcDataModel(QSharedPointer<StcDataModel>(new StcDataModel(this)))
78 {
79  init(QString(), subject_id, hemi, surf, QString(), subjects_dir);
80 }
81 
82 
83 //*************************************************************************************************************
84 
85 BrainView::BrainView(const QString &subject_id, qint32 hemi, const QString &surf, const QString &atlas, const QString &subjects_dir)
86 : Qt3D::Window()
87 , m_pStcDataModel(QSharedPointer<StcDataModel>(new StcDataModel(this)))
88 {
89  init(QString(), subject_id, hemi, surf, atlas, subjects_dir);
90 }
91 
92 
93 //*************************************************************************************************************
94 
95 BrainView::BrainView(const QString& p_sFile)
96 : Qt3D::Window()
97 , m_pStcDataModel(QSharedPointer<StcDataModel>(new StcDataModel(this)))
98 {
99  init(p_sFile, QString(), -1, QString(), QString(), QString());
100 }
101 
102 
103 //*************************************************************************************************************
104 
106 {
107 }
108 
109 
110 //*************************************************************************************************************
111 
113 {
114  std::cout<<"BrainView::addSourceEstimate()"<<std::endl;
115 
116  m_pStcDataModel->addData(p_sourceEstimate);
117 }
118 
119 
120 //*************************************************************************************************************
121 
122 void BrainView::initStcDataModel(const QString &subject_id, qint32 hemi, const QString &surf, const QString &subjects_dir, const QString &atlas, const MNEForwardSolution &forwardSolution)
123 {
124  // Init stc data model
125  m_pStcDataModel->init(subject_id, hemi, surf, subjects_dir, atlas, forwardSolution);
126 
127  //Set stc models to views
128  m_pBrainSurfaceEntity->setModel(m_pStcDataModel);
129 }
130 
131 
132 //*************************************************************************************************************
133 
134 void BrainView::init(const QString& p_sFile, const QString &subject_id, qint32 hemi, const QString &surf, const QString &atlas, const QString &subjects_dir)
135 {
136  Q_UNUSED(atlas)
137  Q_UNUSED(p_sFile)
138 
139  m_Engine.registerAspect(new Qt3D::QRenderAspect());
140  Qt3D::QInputAspect *m_pAspectInput = new Qt3D::QInputAspect;
141  m_Engine.registerAspect(m_pAspectInput);
142  m_Engine.initialize();
143 
144  m_data.insert(QStringLiteral("surface"), QVariant::fromValue(static_cast<QSurface *>(this)));
145  m_data.insert(QStringLiteral("eventSource"), QVariant::fromValue(this));
146  m_Engine.setData(m_data);
147 
148  // Root entity
149  m_pRootEntity = new Qt3D::QEntity();
150  m_pRootEntity->setObjectName(QStringLiteral("m_pRootEntity"));
151 
152  // Surface
153  m_pBrainSurfaceEntity = QSharedPointer<BrainSurface>(new BrainSurface(subject_id, hemi, surf, subjects_dir, m_pRootEntity));
154  m_pBrainSurfaceEntity->setObjectName(QStringLiteral("m_pBrainSurfaceEntity"));
155 
156  // Light source
157  Qt3D::QPointLight *light1 = new Qt3D::QPointLight();
158  light1->setColor(Qt::white);
159  light1->setIntensity(0.1f);
160  m_pRootEntity->addComponent(light1);
161 
162  // Build Coordinate System
163  //createCoordSystem(m_pRootEntity);
164 
165  // Camera
166  Qt3D::QCamera *cameraEntity = new Qt3D::QCamera(m_pRootEntity);
167  cameraEntity->setObjectName(QStringLiteral("cameraEntity"));
168 
169  cameraEntity->lens()->setPerspectiveProjection(60.0f, 16.0f/9.0f, 0.1f, 1000.0f);
170  cameraEntity->setPosition(QVector3D(-0, 0, -1.0f));
171  cameraEntity->setViewCenter(QVector3D(0, 0, 0));
172  cameraEntity->setUpVector(QVector3D(0, 1, 0));
173  m_pAspectInput->setCamera(cameraEntity);
174 
175  // FrameGraph
176  Qt3D::QFrameGraph *frameGraph = new Qt3D::QFrameGraph();
177  Qt3D::QForwardRenderer *forwardRenderer = new Qt3D::QForwardRenderer();
178  forwardRenderer->setClearColor(QColor::fromRgbF(1.0, 1.0, 1.0, 1.0));
179  forwardRenderer->setCamera(cameraEntity);
180  frameGraph->setActiveFrameGraph(forwardRenderer);
181 
182  // Setting the FrameGraph
183  m_pRootEntity->addComponent(frameGraph);
184 
185  // Set root object of the scene
186  m_Engine.setRootEntity(m_pRootEntity);
187 }
188 
189 
190 //*************************************************************************************************************
191 
192 void BrainView::createCoordSystem(QEntity *rootEntity)
193 {
194  // X
195  Qt3D::QCylinderMesh *XAxis = new Qt3D::QCylinderMesh();
196  XAxis->setRadius(0.1f);
197  XAxis->setLength(3);
198  XAxis->setRings(100);
199  XAxis->setSlices(20);
200 
201  m_XAxisEntity = QSharedPointer<Qt3D::QEntity>(new Qt3D::QEntity(rootEntity));
202  m_XAxisEntity->addComponent(XAxis);
203 
204  QPhongMaterial *phongMaterialX = new QPhongMaterial();
205  phongMaterialX->setDiffuse(QColor(255, 0, 0));
206  phongMaterialX->setAmbient(Qt::gray);
207  phongMaterialX->setSpecular(Qt::white);
208  phongMaterialX->setShininess(50.0f);
209  m_XAxisEntity->addComponent(phongMaterialX);
210 
211  // Y
212  Qt3D::QCylinderMesh *YAxis = new Qt3D::QCylinderMesh();
213  YAxis->setRadius(0.1f);
214  YAxis->setLength(3);
215  YAxis->setRings(100);
216  YAxis->setSlices(20);
217 
218  Qt3D::QRotateTransform *rotationY = new Qt3D::QRotateTransform();
219  Qt3D::QTransform *transformY = new Qt3D::QTransform();
220 
221  rotationY->setAngleDeg(90.0f);
222  rotationY->setAxis(QVector3D(1, 0, 0));
223  transformY->addTransform(rotationY);
224 
225  m_YAxisEntity = QSharedPointer<Qt3D::QEntity>(new Qt3D::QEntity(rootEntity));
226  m_YAxisEntity->addComponent(YAxis);
227  m_YAxisEntity->addComponent(transformY);
228 
229  QPhongMaterial *phongMaterialY = new QPhongMaterial();
230  phongMaterialY->setDiffuse(QColor(0, 0, 255));
231  phongMaterialY->setAmbient(Qt::gray);
232  phongMaterialY->setSpecular(Qt::white);
233  phongMaterialY->setShininess(50.0f);
234  m_YAxisEntity->addComponent(phongMaterialY);
235 
236  // Z
237  Qt3D::QCylinderMesh *ZAxis = new Qt3D::QCylinderMesh();
238  ZAxis->setRadius(0.1f);
239  ZAxis->setLength(3);
240  ZAxis->setRings(100);
241  ZAxis->setSlices(20);
242 
243  Qt3D::QRotateTransform *rotationZ = new Qt3D::QRotateTransform();
244  Qt3D::QTransform *transformZ = new Qt3D::QTransform();
245 
246  rotationZ->setAngleDeg(90.0f);
247  rotationZ->setAxis(QVector3D(0, 0, 1));
248  transformZ->addTransform(rotationZ);
249 
250  m_ZAxisEntity = QSharedPointer<Qt3D::QEntity>(new Qt3D::QEntity(rootEntity));
251  m_ZAxisEntity->addComponent(ZAxis);
252  m_ZAxisEntity->addComponent(transformZ);
253 
254  QPhongMaterial *phongMaterialZ = new QPhongMaterial();
255  phongMaterialZ->setDiffuse(QColor(0, 255, 0));
256  phongMaterialZ->setAmbient(Qt::gray);
257  phongMaterialZ->setSpecular(Qt::white);
258  phongMaterialZ->setShininess(50.0f);
259  m_ZAxisEntity->addComponent(phongMaterialZ);
260 }
261 
262 void BrainView::mousePressEvent(QMouseEvent *e)
263 {
264  std::cout<<"mouse click"<<std::endl;
265  if(e->buttons() & Qt::RightButton)
266  {
267  std::cout<<"mouse click"<<std::endl;
268  }
269 }
Table model which prepares source estimate information.
Definition: stcdatamodel.h:127
void mousePressEvent(QMouseEvent *e)
Definition: brainview.cpp:262
void addSourceEstimate(MNESourceEstimate &p_sourceEstimate)
Definition: brainview.cpp:112
void init(const QString &p_sFile, const QString &subject_id, qint32 hemi, const QString &surf, const QString &atlas, const QString &subjects_dir)
Definition: brainview.cpp:134
Holds the data of one hemisphere in form of a mesh.
Definition: brainsurface.h:110