MNE-CPP  0.1.9
A Framework for Electrophysiology
digitizersettreeitem.cpp
Go to the documentation of this file.
1 //=============================================================================================================
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "digitizersettreeitem.h"
42 
43 //=============================================================================================================
44 // INCLUDES
45 //=============================================================================================================
46 
47 #include "digitizertreeitem.h"
48 #include "../../3dhelpers/renderable3Dentity.h"
49 
50 #include <fiff/fiff_constants.h>
51 #include <fiff/fiff_dig_point.h>
53 #include <fiff/fiff_coord_trans.h>
54 
55 //=============================================================================================================
56 // QT INCLUDES
57 //=============================================================================================================
58 
59 #include <Qt3DCore/QTransform>
60 
61 //=============================================================================================================
62 // EIGEN INCLUDES
63 //=============================================================================================================
64 
65 //=============================================================================================================
66 // USED NAMESPACES
67 //=============================================================================================================
68 
69 using namespace DISP3DLIB;
70 using namespace FIFFLIB;
71 
72 //=============================================================================================================
73 // DEFINE GLOBAL METHODS
74 //=============================================================================================================
75 
76 //=============================================================================================================
77 // DEFINE MEMBER METHODS
78 //=============================================================================================================
79 
80 DigitizerSetTreeItem::DigitizerSetTreeItem(int iType, const QString& text)
81 : AbstractTreeItem(iType, text)
82 {
83  initItem();
84 }
85 
86 //=============================================================================================================
87 
89 {
90  this->setEditable(false);
91  this->setCheckable(true);
92  this->setCheckState(Qt::Checked);
93  this->setToolTip("Digitizer set item");
94 }
95 
96 //=============================================================================================================
97 
98 void DigitizerSetTreeItem::addData(const FIFFLIB::FiffDigPointSet& tDigitizer, Qt3DCore::QEntity* parent)
99 {
100  if(!m_pRenderable3DEntity) {
102  }
103 
104  //Add data
105  //parsing the digitizer List
106  QList<FIFFLIB::FiffDigPoint> tNasion;
107  QList<FIFFLIB::FiffDigPoint> tLAP;
108  QList<FIFFLIB::FiffDigPoint> tRAP;
109  QList<FIFFLIB::FiffDigPoint> tHpi;
110  QList<FIFFLIB::FiffDigPoint> tEeg;
111  QList<FIFFLIB::FiffDigPoint> tExtra;
112 
113  for(int i = 0; i < tDigitizer.size(); ++i){
114 
115  switch (tDigitizer[i].kind) {
116  case FIFFV_POINT_CARDINAL:
117 
118  switch (tDigitizer[i].ident) {
119  case FIFFV_POINT_LPA:
120  tLAP.append(tDigitizer[i]);
121  tLAP.append(tDigitizer[i]);
122  break;
123 
124  case FIFFV_POINT_NASION:
125  tNasion.append(tDigitizer[i]);
126  tNasion.append(tDigitizer[i]);
127  break;
128 
129  case FIFFV_POINT_RPA:
130  tRAP.append(tDigitizer[i]);
131  tRAP.append(tDigitizer[i]);
132  break;
133 
134  default:
135  break;
136  }
137  break;
138 
139  case FIFFV_POINT_HPI:
140  tHpi.append(tDigitizer[i]);
141  break;
142 
143  case FIFFV_POINT_EEG:
144  tEeg.append(tDigitizer[i]);
145  break;
146 
147  case FIFFV_POINT_EXTRA:
148  tExtra.append(tDigitizer[i]);
149  break;
150 
151  default:
152  break;
153  }
154  }
155 
156 // //Create items all new - A bit more inefficient but we do not run into the problem that the QEntity
157 // //is delted with deleteLater() which could let to deletion after the new Qentity has been created
158 // //Delete all childs first. We do this because we always want to start fresh with the newly added digitizer data.
159 // if(this->hasChildren()) {
160 // this->removeRows(0, this->rowCount());
161 // }
162 
163 // QList<QStandardItem*> itemList;
164 
165 // if (!tLAP.empty()){
166 // //Create a LAP digitizer item
167 // DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"LAP");
168 // digitizerItem->addData(tLAP);
169 // itemList << digitizerItem;
170 // itemList << new QStandardItem(digitizerItem->toolTip());
171 // this->appendRow(itemList);
172 // itemList.clear();
173 // }
174 // if (!tNasion.empty()){
175 // //Create a Nasion digitizer item
176 // DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"Nasion");
177 // digitizerItem->addData(tNasion);
178 // itemList << digitizerItem;
179 // itemList << new QStandardItem(digitizerItem->toolTip());
180 // this->appendRow(itemList);
181 // itemList.clear();
182 // }
183 // if (!tRAP.empty()){
184 // //Create a RAO digitizer item
185 // DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"RAP");
186 // digitizerItem->addData(tRAP);
187 // itemList << digitizerItem;
188 // itemList << new QStandardItem(digitizerItem->toolTip());
189 // this->appendRow(itemList);
190 // itemList.clear();
191 // }
192 // if (!tHpi.empty()){
193 // //Create a HPI digitizer item
194 // DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"HPI");
195 // digitizerItem->addData(tHpi);
196 // itemList << digitizerItem;
197 // itemList << new QStandardItem(digitizerItem->toolTip());
198 // this->appendRow(itemList);
199 // itemList.clear();
200 // }
201 // if (!tEeg.empty()){
202 // //Create a EEG digitizer item
203 // DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"EEG/ECG");
204 // digitizerItem->addData(tEeg);
205 // itemList << digitizerItem;
206 // itemList << new QStandardItem(digitizerItem->toolTip());
207 // this->appendRow(itemList);
208 // itemList.clear();
209 // }
210 // if (!tExtra.empty()){
211 // //Create a extra digitizer item
212 // DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"Extra");
213 // digitizerItem->addData(tExtra);
214 // itemList << digitizerItem;
215 // itemList << new QStandardItem(digitizerItem->toolTip());
216 // this->appendRow(itemList);
217 // itemList.clear();
218 // }
219 
220  //Find exiting Digitizer Items and add data respectivley
221  QList<QStandardItem*> itemList = this->findChildren(Data3DTreeModelItemTypes::DigitizerItem);
222  bool bFoundNasionlItem = false;
223  bool bFoundLAPItem = false;
224  bool bFoundRAPItem = false;
225  bool bFoundHPIItem = false;
226  bool bFoundEEGItem = false;
227  bool bFoundExtraItem = false;
228 
229  for(int i = 0; i < itemList.size(); ++i) {
230  DigitizerTreeItem* item = dynamic_cast<DigitizerTreeItem*>(itemList.at(i));
231 
232  if(item == Q_NULLPTR){
233  qDebug() << "Dynamic cast returned null. Returning early.";
234  return;
235  }
236 
237  if(item->text() == "Nasion" && !tNasion.empty()) {
238  item->addData(tNasion, 0.002f, Qt::green);
239  bFoundNasionlItem = true;
240  }
241 
242  if(item->text() == "LAP" && !tLAP.empty()) {
243  item->addData(tLAP, 0.002f, Qt::red);
244  bFoundLAPItem = true;
245  }
246 
247  if(item->text() == "RAP" && !tRAP.empty()) {
248  item->addData(tRAP, 0.002f, Qt::blue);
249  bFoundRAPItem = true;
250  }
251 
252  if(item->text() == "HPI" && !tHpi.empty()) {
253  item->addData(tHpi, 0.001f, Qt::darkRed);
254  bFoundHPIItem = true;
255  }
256 
257  if(item->text() == "EEG/ECG" && !tEeg.empty()) {
258  item->addData(tEeg, 0.001f, Qt::cyan);
259  bFoundEEGItem = true;
260  }
261 
262  if(item->text() == "Extra" && !tExtra.empty()) {
263  item->addData(tExtra, 0.001f, Qt::magenta);
264  bFoundExtraItem = true;
265  }
266  }
267 
268  //If not existent yet create here
269  if (!bFoundNasionlItem && !tNasion.empty()){
270  //Create a cardinal digitizer item
271  QList<QStandardItem*> itemListCardinal;
272  DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"Nasion");
273  digitizerItem->addData(tNasion, 0.002f, Qt::green);
274  itemListCardinal << digitizerItem;
275  itemListCardinal << new QStandardItem(digitizerItem->toolTip());
276  this->appendRow(itemListCardinal);
277  }
278 
279  if (!bFoundLAPItem && !tLAP.empty()){
280  //Create a cardinal digitizer item
281  QList<QStandardItem*> itemListCardinal;
282  DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"LAP");
283  digitizerItem->addData(tLAP, 0.002f, Qt::red);
284  itemListCardinal << digitizerItem;
285  itemListCardinal << new QStandardItem(digitizerItem->toolTip());
286  this->appendRow(itemListCardinal);
287  }
288 
289  if (!bFoundRAPItem && !tRAP.empty()){
290  //Create a cardinal digitizer item
291  QList<QStandardItem*> itemListCardinal;
292  DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"RAP");
293  digitizerItem->addData(tRAP, 0.002f, Qt::blue);
294  itemListCardinal << digitizerItem;
295  itemListCardinal << new QStandardItem(digitizerItem->toolTip());
296  this->appendRow(itemListCardinal);
297  }
298 
299  if (!bFoundHPIItem && !tHpi.empty()){
300  //Create a hpi digitizer item
301  QList<QStandardItem*> itemListHPI;
302  DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"HPI");
303  digitizerItem->addData(tHpi, 0.001f, Qt::darkRed);
304  itemListHPI << digitizerItem;
305  itemListHPI << new QStandardItem(digitizerItem->toolTip());
306  this->appendRow(itemListHPI);
307  }
308 
309  if (!bFoundEEGItem && !tEeg.empty()){
310  //Create a eeg ecg digitizer item
311  QList<QStandardItem*> itemListEEG;
312  DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"EEG/ECG");
313  digitizerItem->addData(tEeg, 0.001f, Qt::cyan);
314  itemListEEG << digitizerItem;
315  itemListEEG << new QStandardItem(digitizerItem->toolTip());
316  this->appendRow(itemListEEG);
317  }
318 
319  if (!bFoundExtraItem && !tExtra.empty()){
320  //Create a extra digitizer item
321  QList<QStandardItem*> itemListExtra;
322  DigitizerTreeItem* digitizerItem = new DigitizerTreeItem(m_pRenderable3DEntity, Data3DTreeModelItemTypes::DigitizerItem,"Extra");
323  digitizerItem->addData(tExtra, 0.001f, Qt::magenta);
324  itemListExtra << digitizerItem;
325  itemListExtra << new QStandardItem(digitizerItem->toolTip());
326  this->appendRow(itemListExtra);
327  }
328 }
329 
330 //=============================================================================================================
331 
332 void DigitizerSetTreeItem::setTransform(const Qt3DCore::QTransform& transform)
333 {
335  m_pRenderable3DEntity->setTransform(transform);
336  }
337 }
338 
339 //=============================================================================================================
340 
342  bool bApplyInverse)
343 {
345  m_pRenderable3DEntity->setTransform(transform, bApplyInverse);
346  }
347 }
348 
349 //=============================================================================================================
350 
351 void DigitizerSetTreeItem::applyTransform(const Qt3DCore::QTransform& transform)
352 {
354  m_pRenderable3DEntity->applyTransform(transform);
355  }
356 }
357 
358 //=============================================================================================================
359 
361  bool bApplyInverse)
362 {
364  m_pRenderable3DEntity->applyTransform(transform, bApplyInverse);
365  }
366 }
DISP3DLIB::DigitizerSetTreeItem::addData
void addData(const FIFFLIB::FiffDigPointSet &tDigitizer, Qt3DCore::QEntity *parent)
Definition: digitizersettreeitem.cpp:98
DISP3DLIB::DigitizerSetTreeItem::applyTransform
virtual void applyTransform(const Qt3DCore::QTransform &transform)
Definition: digitizersettreeitem.cpp:351
digitizertreeitem.h
DigitizerTreeItem class declaration.
DISP3DLIB::AbstractTreeItem
Provides the basic tree item.
Definition: abstracttreeitem.h:76
fiff_coord_trans.h
FiffCoordTrans class declaration.
digitizersettreeitem.h
DigitizerSetTreeItem class declaration.
DISP3DLIB::AbstractTreeItem::findChildren
QList< QStandardItem * > findChildren(int type)
Definition: abstracttreeitem.cpp:112
DISP3DLIB::DigitizerTreeItem
DigitizerTreeItem provides a generic tree item to hold and visualize digitizer data.
Definition: digitizertreeitem.h:85
fiff_constants.h
Fiff constants.
fiff_dig_point.h
FiffDigPoint class declaration.
DISP3DLIB::DigitizerSetTreeItem::setTransform
virtual void setTransform(const Qt3DCore::QTransform &transform)
Definition: digitizersettreeitem.cpp:332
fiff_dig_point_set.h
FiffDigPointSet class declaration.
DISP3DLIB::Renderable3DEntity
Base class for renederable 3D QEntities.
Definition: renderable3Dentity.h:88
FIFFLIB::FiffCoordTrans
Coordinate transformation description.
Definition: fiff_coord_trans.h:74
FIFFLIB::FiffDigPointSet::size
qint32 size() const
Definition: fiff_dig_point_set.h:271
DISP3DLIB::DigitizerSetTreeItem::m_pRenderable3DEntity
QPointer< Renderable3DEntity > m_pRenderable3DEntity
Definition: digitizersettreeitem.h:160
DISP3DLIB::DigitizerSetTreeItem::DigitizerSetTreeItem
DigitizerSetTreeItem(int iType=Data3DTreeModelItemTypes::DigitizerSetItem, const QString &text="Source space")
Definition: digitizersettreeitem.cpp:80
DISP3DLIB::DigitizerSetTreeItem::initItem
void initItem()
Definition: digitizersettreeitem.cpp:88
DISP3DLIB::DigitizerTreeItem::addData
void addData(const QList< FIFFLIB::FiffDigPoint > &tDigitizer, const float tSphereRadius, const QColor &tSphereColor)
Definition: digitizertreeitem.cpp:88
FIFFLIB::FiffDigPointSet
Holds a set of digitizer points.
Definition: fiff_dig_point_set.h:83