MNE-CPP  0.1.9
A Framework for Electrophysiology
ecddatatreeitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "ecddatatreeitem.h"
42 #include "../common/metatreeitem.h"
43 
45 #include "../../3dhelpers/geometrymultiplier.h"
46 #include "../../materials/geometrymultipliermaterial.h"
47 
48 //=============================================================================================================
49 // QT INCLUDES
50 //=============================================================================================================
51 
52 #include <QList>
53 #include <QVariant>
54 #include <QStringList>
55 #include <QColor>
56 #include <QVector3D>
57 #include <QStandardItem>
58 #include <QStandardItemModel>
59 #include <Qt3DRender/qshaderprogram.h>
60 #include <QQuaternion>
61 #include <Qt3DExtras/QConeGeometry>
62 #include <QMatrix4x4>
63 #include <QRandomGenerator>
64 
65 //=============================================================================================================
66 // EIGEN INCLUDES
67 //=============================================================================================================
68 
69 #include <Eigen/Core>
70 
71 //=============================================================================================================
72 // USED NAMESPACES
73 //=============================================================================================================
74 
75 using namespace Eigen;
76 using namespace INVERSELIB;
77 using namespace DISP3DLIB;
78 
79 //=============================================================================================================
80 // DEFINE MEMBER METHODS
81 //=============================================================================================================
82 
83 EcdDataTreeItem::EcdDataTreeItem(Qt3DCore::QEntity *p3DEntityParent, int iType, const QString &text)
84 : Abstract3DTreeItem(p3DEntityParent, iType, text)
85 {
86  initItem();
87 }
88 
89 //=============================================================================================================
90 
92 {
93  this->setEditable(false);
94  this->setCheckable(true);
95  this->setCheckState(Qt::Checked);
96  this->setToolTip("Dipole fit data");
97 }
98 
99 //=============================================================================================================
100 
101 void EcdDataTreeItem::addData(const ECDSet& pECDSet)
102 {
103  if(!m_pItemNumDipoles){
104  //Add further infos as children
105  QList<QStandardItem*> list;
106  m_pItemNumDipoles = new MetaTreeItem(MetaTreeItemTypes::NumberDipoles, QString::number(pECDSet.size()));
107  m_pItemNumDipoles->setEditable(false);
108  list.clear();
109  list << m_pItemNumDipoles;
110  list << new QStandardItem(m_pItemNumDipoles->toolTip());
111  this->appendRow(list);
112  } else {
113  m_pItemNumDipoles->setText(QString::number(pECDSet.size()));
114  }
115  //Plot dipole moment
116  plotDipoles(pECDSet);
117 }
118 
119 //=============================================================================================================
120 
122 {
123  //Plot dipoles
124 
125  QVector3D pos, to, from;
126 
127  //The Qt3D default cone orientation and the top of the cone lies in line with the positive y-axis.
128  from = QVector3D(0.0, 1.0, 0.0);
129  double norm;
130 
131  QVector<QColor> vColors;
132  vColors.reserve(tECDSet.size());
133  QVector<QMatrix4x4> vTransforms;
134  vTransforms.reserve(tECDSet.size());
135 
136  for(int i = 0; i < tECDSet.size(); ++i) {
137  pos.setX(tECDSet[i].rd(0));
138  pos.setY(tECDSet[i].rd(1));
139  pos.setZ(tECDSet[i].rd(2));
140 
141  norm = sqrt(pow(tECDSet[i].Q(0),2)+pow(tECDSet[i].Q(1),2)+pow(tECDSet[i].Q(2),2));
142 
143  to.setX(tECDSet[i].Q(0)/norm);
144  to.setY(tECDSet[i].Q(1)/norm);
145  to.setZ(tECDSet[i].Q(2)/norm);
146 
147 // qDebug()<<"EcdDataTreeItem::plotDipoles - from" << from;
148 // qDebug()<<"EcdDataTreeItem::plotDipoles - to" << to;
149 
150  QQuaternion final = QQuaternion::rotationTo(from, to);
151 
152  //Set dipole position and orientation
153  QMatrix4x4 m;
154  m.translate(pos);
155  m.rotate(final);
156  vTransforms.push_back(m);
157 
158  //add random color;
159  vColors.push_back(QColor(QRandomGenerator::global()->bounded(0 , 255),
160  QRandomGenerator::global()->bounded(0 , 255),
161  QRandomGenerator::global()->bounded(0 , 255)));
162  }
163 
164  //create geometry
165  if(!m_pDipolMesh){
166  QSharedPointer<Qt3DExtras::QConeGeometry> pDipolGeometry = QSharedPointer<Qt3DExtras::QConeGeometry>::create();
167  pDipolGeometry->setBottomRadius(0.001f);
168  pDipolGeometry->setLength(0.003f);
169  //create instanced renderer
170  m_pDipolMesh = new GeometryMultiplier(pDipolGeometry);
171 
172  //Set instance Transform
173  m_pDipolMesh->setTransforms(vTransforms);
174  //Set instance colors
175  m_pDipolMesh->setColors(vColors);
176 
177  this->addComponent(m_pDipolMesh);
178 
179  //Add material
181  pMaterial->setAmbient(QColor(0,0,0));
182  pMaterial->setAlpha(1.0f);
183  this->addComponent(pMaterial);
184  } else {
185  //Set instance Transform
186  m_pDipolMesh->setTransforms(vTransforms);
187  //Set instance colors
188  m_pDipolMesh->setColors(vColors);
189  }
190 }
191 
DISP3DLIB::AbstractPhongAlphaMaterial::setAlpha
virtual void setAlpha(float fAlpha)
Definition: abstractphongalphamaterial.cpp:101
ecd_set.h
FiffDigPointSet class declaration.
DISP3DLIB::Abstract3DTreeItem
Provides the basic tree item.
Definition: abstract3Dtreeitem.h:80
DISP3DLIB::GeometryMultiplierMaterial::setAmbient
void setAmbient(const QColor &ambientColor)
Definition: geometrymultipliermaterial.cpp:100
DISP3DLIB::GeometryMultiplier
Instaced based renderer.
Definition: geometrymultiplier.h:99
INVERSELIB::ECDSet
Holds a set of Electric Current Dipoles.
Definition: ecd_set.h:80
INVERSELIB::ECDSet::size
qint32 size() const
Definition: ecd_set.h:193
DISP3DLIB::GeometryMultiplierMaterial
Custom phong alpha material for instanced rendering.
Definition: geometrymultipliermaterial.h:90
DISP3DLIB::EcdDataTreeItem::plotDipoles
void plotDipoles(const INVERSELIB::ECDSet &tECDSet)
Definition: ecddatatreeitem.cpp:121
ecddatatreeitem.h
EcdDataTreeItem class declaration.
DISP3DLIB::MetaTreeItem
Provides a generic brain tree item.
Definition: metatreeitem.h:74
DISP3DLIB::EcdDataTreeItem::initItem
void initItem()
Definition: ecddatatreeitem.cpp:91
DISP3DLIB::EcdDataTreeItem::addData
void addData(const INVERSELIB::ECDSet &pECDSet)
Definition: ecddatatreeitem.cpp:101