MNE-CPP  0.1.9
A Framework for Electrophysiology
digitizertreeitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "digitizertreeitem.h"
41 #include "../common/metatreeitem.h"
42 #include "../../3dhelpers/geometrymultiplier.h"
43 #include "../../materials/geometrymultipliermaterial.h"
44 
45 #include <fiff/fiff_constants.h>
46 #include <fiff/fiff_dig_point.h>
47 
48 //=============================================================================================================
49 // QT INCLUDES
50 //=============================================================================================================
51 
52 #include <Qt3DExtras/QSphereGeometry>
53 #include <QMatrix4x4>
54 #include <Qt3DCore/QTransform>
55 
56 //=============================================================================================================
57 // EIGEN INCLUDES
58 //============================================================================= ================================
59 
60 //=============================================================================================================
61 // USED NAMESPACES
62 //=============================================================================================================
63 
64 using namespace DISP3DLIB;
65 
66 //=============================================================================================================
67 // DEFINE MEMBER METHODS
68 //=============================================================================================================
69 
70 DigitizerTreeItem::DigitizerTreeItem(Qt3DCore::QEntity *p3DEntityParent, int iType, const QString& text)
71 : Abstract3DTreeItem(p3DEntityParent, iType, text)
72 {
73  initItem();
74 }
75 
76 //=============================================================================================================
77 
79 {
80  this->setEditable(false);
81  this->setCheckable(true);
82  this->setCheckState(Qt::Checked);
83  this->setToolTip(this->text());
84 }
85 
86 //=============================================================================================================
87 
88 void DigitizerTreeItem::addData(const QList<FIFFLIB::FiffDigPoint>& tDigitizer, const float tSphereRadius, const QColor &tSphereColor)
89 {
90  //create instanced renderer if there is none
91  if(!m_pSphereMesh && !tDigitizer.isEmpty())
92  {
93  QSharedPointer<Qt3DExtras::QSphereGeometry> pSourceSphereGeometry = QSharedPointer<Qt3DExtras::QSphereGeometry>::create();
94  pSourceSphereGeometry->setRadius(tSphereRadius);
95 
96  m_pSphereMesh = new GeometryMultiplier(pSourceSphereGeometry);
97 
98  //Set sphere positions
99  this->addComponent(m_pSphereMesh);
100 
101  //Add material
103  pMaterial->setAmbient(tSphereColor);
104  this->addComponent(pMaterial);
105  }
106 
107  //Set transforms
108  if(!tDigitizer.isEmpty())
109  {
110  QVector<QColor> vColorsEdges;
111 
112  QVector<QMatrix4x4> vTransforms;
113  vTransforms.reserve(tDigitizer.size());
114 
115  QVector3D tempPos;
116 
117  for(int i = 0; i < tDigitizer.size(); ++i) {
118  QMatrix4x4 tempTransform;
119 
120  tempPos.setX(tDigitizer[i].r[0]);
121  tempPos.setY(tDigitizer[i].r[1]);
122  tempPos.setZ(tDigitizer[i].r[2]);
123 
124  tempTransform.translate(tempPos);
125  vTransforms.push_back(tempTransform);
126 
127  vColorsEdges.push_back(tSphereColor);
128  }
129 
130  //Set instance Transform
131  m_pSphereMesh->setTransforms(vTransforms);
132  m_pSphereMesh->setColors(vColorsEdges);
133  }
134 
135  //Update alpha
136  float alpha = 1.0;
137 
138  QList<QStandardItem*> items = m_pItemAppearanceOptions->findChildren(MetaTreeItemTypes::AlphaValue);
139 
140  for(int i = 0; i < items.size(); ++i) {
141  if(MetaTreeItem* item = dynamic_cast<MetaTreeItem*>(items.at(i))) {
142  QVariant data;
143  data.setValue(alpha);
144  item->setData(data, MetaTreeItemRoles::AlphaValue);
145  item->setData(data, Qt::DecorationRole);
146  }
147  }
148 
149  //Update colors in color item
150  items = m_pItemAppearanceOptions->findChildren(MetaTreeItemTypes::Color);
151 
152  for(int i = 0; i < items.size(); ++i) {
153  if(MetaTreeItem* item = dynamic_cast<MetaTreeItem*>(items.at(i))) {
154  QVariant data;
155  data.setValue(tSphereColor);
156  item->setData(data, MetaTreeItemRoles::Color);
157  item->setData(data, Qt::DecorationRole);
158  }
159  }
160 }
DISP3DLIB::DigitizerTreeItem::initItem
void initItem()
Definition: digitizertreeitem.cpp:78
DISP3DLIB::Abstract3DTreeItem::m_pItemAppearanceOptions
QPointer< MetaTreeItem > m_pItemAppearanceOptions
Definition: abstract3Dtreeitem.h:225
DISP3DLIB::Abstract3DTreeItem
Provides the basic tree item.
Definition: abstract3Dtreeitem.h:80
digitizertreeitem.h
DigitizerTreeItem class declaration.
DISP3DLIB::GeometryMultiplierMaterial::setAmbient
void setAmbient(const QColor &ambientColor)
Definition: geometrymultipliermaterial.cpp:100
DISP3DLIB::GeometryMultiplier
Instaced based renderer.
Definition: geometrymultiplier.h:99
DISP3DLIB::GeometryMultiplierMaterial
Custom phong alpha material for instanced rendering.
Definition: geometrymultipliermaterial.h:90
fiff_constants.h
Fiff constants.
fiff_dig_point.h
FiffDigPoint class declaration.
DISP3DLIB::MetaTreeItem
Provides a generic brain tree item.
Definition: metatreeitem.h:74
DISP3DLIB::DigitizerTreeItem::addData
void addData(const QList< FIFFLIB::FiffDigPoint > &tDigitizer, const float tSphereRadius, const QColor &tSphereColor)
Definition: digitizertreeitem.cpp:88
DISP3DLIB::DigitizerTreeItem::DigitizerTreeItem
DigitizerTreeItem(Qt3DCore::QEntity *p3DEntityParent=0, int iType=Data3DTreeModelItemTypes::DigitizerItem, const QString &text="Digitizer")
Definition: digitizertreeitem.cpp:70