MNE-CPP  0.1.9
A Framework for Electrophysiology
sensorpositiontreeitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //=============================================================================================================
37 // INCLUDES
38 //=============================================================================================================
39 
40 #include "sensorpositiontreeitem.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_ch_info.h>
47 
48 //=============================================================================================================
49 // QT INCLUDES
50 //=============================================================================================================
51 
52 #include <QMatrix4x4>
53 #include <Qt3DExtras/QCuboidGeometry>
54 #include <Qt3DCore/QEntity>
55 #include <Qt3DExtras/QSphereGeometry>
56 
57 //=============================================================================================================
58 // EIGEN INCLUDES
59 //=============================================================================================================
60 
61 #include <Eigen/Core>
62 
63 //=============================================================================================================
64 // USED NAMESPACES
65 //=============================================================================================================
66 
67 using namespace DISP3DLIB;
68 
69 //=============================================================================================================
70 // DEFINE MEMBER METHODS
71 //=============================================================================================================
72 
73 SensorPositionTreeItem::SensorPositionTreeItem(Qt3DCore::QEntity *p3DEntityParent, int iType, const QString& text)
74 : Abstract3DTreeItem(p3DEntityParent, iType, text)
75 {
76  initItem();
77 }
78 
79 //=============================================================================================================
80 
82 {
83  this->setEditable(false);
84  this->setCheckable(true);
85  this->setCheckState(Qt::Checked);
86  this->setToolTip(this->text());
87 }
88 
89 //=============================================================================================================
90 
91 void SensorPositionTreeItem::addData(const QList<FIFFLIB::FiffChInfo>& lChInfo,
92  const QString& sDataType,
93  const QStringList& bads)
94 {
95  if(sDataType == "MEG") {
96  plotMEGSensors(lChInfo, bads);
97  } else if (sDataType == "EEG") {
98  plotEEGSensors(lChInfo, bads);
99  }
100 }
101 
102 //=============================================================================================================
103 
104 void SensorPositionTreeItem::plotMEGSensors(const QList<FIFFLIB::FiffChInfo>& lChInfo,
105  const QStringList& bads)
106 {
107  if(lChInfo.isEmpty()) {
108  qDebug() << "SensorPositionTreeItem::plotMEGSensors - Channel data is empty. Returning.";
109  return;
110  }
111 
112  if(!m_pMEGSensorEntity) {
113  m_pMEGSensorEntity = new QEntity(this);
114  }
115 
116  //create geometry
117  if(!m_pMEGSensors) {
118  if(!m_pMEGSensorGeometry) {
119  m_pMEGSensorGeometry = QSharedPointer<Qt3DExtras::QCuboidGeometry>::create();
120  m_pMEGSensorGeometry->setXExtent(0.01f);
121  m_pMEGSensorGeometry->setYExtent(0.01f);
122  m_pMEGSensorGeometry->setZExtent(0.001f);
123  }
124 
126 
127  m_pMEGSensorEntity->addComponent(m_pMEGSensors);
128 
129  //Add material
131  pMaterial->setAmbient(QColor(100,100,100));
132  pMaterial->setAlpha(0.75);
133  m_pMEGSensorEntity->addComponent(pMaterial);
134  }
135 
136  //Create transform matrix for each cuboid instance
137  QVector<QMatrix4x4> vTransforms;
138  vTransforms.reserve(lChInfo.size());
139  QVector<QColor> vColorsNodes;
140  QVector3D tempPos;
141 
142  for(int i = 0; i < lChInfo.size(); ++i) {
143  QMatrix4x4 tempTransform;
144 
145  tempPos.setX(lChInfo[i].chpos.r0(0));
146  tempPos.setY(lChInfo[i].chpos.r0(1));
147  tempPos.setZ(lChInfo[i].chpos.r0(2));
148  //Set position
149  tempTransform.translate(tempPos);
150 
151  //Set orientation
152  for(int j = 0; j < 4; ++j) {
153  tempTransform(j, 0) = lChInfo[i].coil_trans.row(j)(0);
154  tempTransform(j, 1) = lChInfo[i].coil_trans.row(j)(1);
155  tempTransform(j, 2) = lChInfo[i].coil_trans.row(j)(2);
156  }
157 
158  if(!vTransforms.contains(tempTransform)) {
159  vTransforms.push_back(tempTransform);
160  }
161 
162  if(bads.contains(lChInfo.at(i).ch_name)) {
163  vColorsNodes.push_back(QColor(255,0,0));
164  } else {
165  vColorsNodes.push_back(QColor(100,100,100));
166  }
167  }
168 
169  //Set instance Transform
170  m_pMEGSensors->setTransforms(vTransforms);
171  m_pMEGSensors->setColors(vColorsNodes);
172 
173  //Update colors in color item
174  QList<QStandardItem*> items = this->findChildren(MetaTreeItemTypes::Color);
175 
176  for(int i = 0; i < items.size(); ++i) {
177  if(MetaTreeItem* item = dynamic_cast<MetaTreeItem*>(items.at(i))) {
178  QVariant data;
179  data.setValue(QColor(100,100,100));
180  item->setData(data, MetaTreeItemRoles::Color);
181  item->setData(data, Qt::DecorationRole);
182  }
183  }
184 }
185 
186 //=============================================================================================================
187 
188 void SensorPositionTreeItem::plotEEGSensors(const QList<FIFFLIB::FiffChInfo>& lChInfo,
189  const QStringList& bads)
190 {
191  if(lChInfo.isEmpty()) {
192  qDebug() << "SensorPositionTreeItem::plotEEGSensors - Channel data is empty. Returning.";
193  return;
194  }
195 
196  if(!m_pEEGSensorEntity) {
197  m_pEEGSensorEntity = new QEntity(this);
198  }
199 
200  //create geometry
201  if(!m_pEEGSensors) {
202  if(!m_pEEGSensorGeometry) {
203  m_pEEGSensorGeometry = QSharedPointer<Qt3DExtras::QSphereGeometry>::create();
204  m_pEEGSensorGeometry->setRadius(0.001f);
205  }
206 
208 
209  m_pEEGSensorEntity->addComponent(m_pEEGSensors);
210 
211  //Add material
213  pMaterial->setAmbient(QColor(100,100,100));
214  pMaterial->setAlpha(0.75);
215  m_pEEGSensorEntity->addComponent(pMaterial);
216  }
217 
218  //Create transform matrix for each cuboid instance
219  QVector<QMatrix4x4> vTransforms;
220  vTransforms.reserve(lChInfo.size());
221  QVector<QColor> vColorsNodes;
222  QVector3D tempPos;
223 
224  for(int i = 0; i < lChInfo.size(); ++i) {
225  QMatrix4x4 tempTransform;
226 
227  tempPos.setX(lChInfo[i].chpos.r0(0));
228  tempPos.setY(lChInfo[i].chpos.r0(1));
229  tempPos.setZ(lChInfo[i].chpos.r0(2));
230  //Set position
231  tempTransform.translate(tempPos);
232 
233  vTransforms.push_back(tempTransform);
234 
235  if(bads.contains(lChInfo.at(i).ch_name)) {
236  vColorsNodes.push_back(Qt::red);
237  } else {
238  vColorsNodes.push_back(Qt::gray);
239  }
240  }
241 
242  //Set instance Transform
243  m_pEEGSensors->setTransforms(vTransforms);
244  m_pEEGSensors->setColors(vColorsNodes);
245 
246  //Update colors in color item
247  QList<QStandardItem*> items = this->findChildren(MetaTreeItemTypes::Color);
248 
249  for(int i = 0; i < items.size(); ++i) {
250  if(MetaTreeItem* item = dynamic_cast<MetaTreeItem*>(items.at(i))) {
251  QVariant data;
252  data.setValue(QColor(100,100,100));
253  item->setData(data, MetaTreeItemRoles::Color);
254  item->setData(data, Qt::DecorationRole);
255  }
256  }
257 }
DISP3DLIB::SensorPositionTreeItem::SensorPositionTreeItem
SensorPositionTreeItem(Qt3DCore::QEntity *p3DEntityParent=0, int iType=Data3DTreeModelItemTypes::SensorPositionItem, const QString &text="Sensor Position")
Definition: sensorpositiontreeitem.cpp:73
DISP3DLIB::AbstractPhongAlphaMaterial::setAlpha
virtual void setAlpha(float fAlpha)
Definition: abstractphongalphamaterial.cpp:101
DISP3DLIB::SensorPositionTreeItem::m_pMEGSensors
QPointer< GeometryMultiplier > m_pMEGSensors
Definition: sensorpositiontreeitem.h:152
DISP3DLIB::Abstract3DTreeItem
Provides the basic tree item.
Definition: abstract3Dtreeitem.h:80
DISP3DLIB::GeometryMultiplierMaterial::setAmbient
void setAmbient(const QColor &ambientColor)
Definition: geometrymultipliermaterial.cpp:100
DISP3DLIB::SensorPositionTreeItem::addData
void addData(const QList< FIFFLIB::FiffChInfo > &lChInfo, const QString &sDataType, const QStringList &bads=QStringList())
Definition: sensorpositiontreeitem.cpp:91
DISP3DLIB::GeometryMultiplier
Instaced based renderer.
Definition: geometrymultiplier.h:99
fiff_ch_info.h
FiffChInfo class declaration.
DISP3DLIB::GeometryMultiplierMaterial
Custom phong alpha material for instanced rendering.
Definition: geometrymultipliermaterial.h:90
DISP3DLIB::SensorPositionTreeItem::m_pEEGSensorGeometry
QSharedPointer< Qt3DExtras::QSphereGeometry > m_pEEGSensorGeometry
Definition: sensorpositiontreeitem.h:157
DISP3DLIB::SensorPositionTreeItem::m_pMEGSensorEntity
QPointer< QEntity > m_pMEGSensorEntity
Definition: sensorpositiontreeitem.h:151
DISP3DLIB::SensorPositionTreeItem::m_pEEGSensors
QPointer< GeometryMultiplier > m_pEEGSensors
Definition: sensorpositiontreeitem.h:156
fiff_constants.h
Fiff constants.
DISP3DLIB::SensorPositionTreeItem::plotEEGSensors
void plotEEGSensors(const QList< FIFFLIB::FiffChInfo > &lChInfo, const QStringList &bads=QStringList())
Definition: sensorpositiontreeitem.cpp:188
DISP3DLIB::MetaTreeItem
Provides a generic brain tree item.
Definition: metatreeitem.h:74
DISP3DLIB::SensorPositionTreeItem::m_pEEGSensorEntity
QPointer< QEntity > m_pEEGSensorEntity
Definition: sensorpositiontreeitem.h:155
DISP3DLIB::Abstract3DTreeItem::findChildren
QList< QStandardItem * > findChildren(int type)
Definition: abstract3Dtreeitem.cpp:190
sensorpositiontreeitem.h
SensorPositionTreeItem class declaration.
DISP3DLIB::SensorPositionTreeItem::plotMEGSensors
void plotMEGSensors(const QList< FIFFLIB::FiffChInfo > &lChInfo, const QStringList &bads=QStringList())
Definition: sensorpositiontreeitem.cpp:104
DISP3DLIB::SensorPositionTreeItem::m_pMEGSensorGeometry
QSharedPointer< Qt3DExtras::QCuboidGeometry > m_pMEGSensorGeometry
Definition: sensorpositiontreeitem.h:153
DISP3DLIB::SensorPositionTreeItem::initItem
void initItem()
Definition: sensorpositiontreeitem.cpp:81