MNE-CPP  beta 0.1
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stcmodel.cpp
1 #include "stcmodel.h"
2 
4 
5 #include <QDebug>
6 
7 #include <iostream>
8 
9 
10 
11 using namespace MNELIB;
12 
13 
14 StcModel::StcModel(QObject *parent)
15 : QAbstractTableModel(parent)
16 , m_pThread(new QThread)
17 , m_pWorker(new StcWorker)
18 , m_bRTMode(true)
19 , m_iDownsampling(20)
20 , m_iCurrentSample(0)
21 {
22  qRegisterMetaType<MatrixXd>("MatrixXd");
23 
24  m_pWorker->moveToThread(m_pThread.data());
25  connect(m_pThread.data(), &QThread::started, m_pWorker.data(), &StcWorker::process);
26  m_pThread->start();
27 
28 }
29 
30 
31 //*************************************************************************************************************
32 //virtual functions
33 int StcModel::rowCount(const QModelIndex & /*parent*/) const
34 {
35 // if(!m_qMapIdxRowSelection.empty())
36 // return m_qMapIdxRowSelection.size();
37 // else
38  return 0;
39 }
40 
41 
42 //*************************************************************************************************************
43 
44 int StcModel::columnCount(const QModelIndex & /*parent*/) const
45 {
46  return 2;
47 }
48 
49 
50 //*************************************************************************************************************
51 
52 QVariant StcModel::data(const QModelIndex &index, int role) const
53 {
54 // if(role != Qt::DisplayRole && role != Qt::BackgroundRole)
55 // return QVariant();
56 
57 // if (index.isValid()) {
58 // qint32 row = m_qMapIdxRowSelection[index.row()];
59 
60 // //******** first column (chname) ********
61 // if(index.column() == 0 && role == Qt::DisplayRole)
62 // return QVariant(m_qListChInfo[row].getChannelName());
63 
64 // //******** second column (data plot) ********
65 // if(index.column()==1) {
66 // QVariant v;
67 
68 // switch(role) {
69 // case Qt::DisplayRole: {
70 // //pack all adjacent (after reload) RowVectorPairs into a QList
71 // QList< QVector<float> > qListVector;
72 
73 // // data
74 // QVector<float> data;
75 // for(qint32 i = 0; i < m_dataCurrent.size(); ++i)
76 // data.append(m_dataCurrent[i](row));
77 // qListVector.append(data);
78 
79 // // last data
80 // QVector<float> lastData;
81 // for(qint32 i=0; i < m_dataLast.size(); ++i)
82 // lastData.append(m_dataLast[i](row));
83 // qListVector.append(lastData);
84 
85 // v.setValue(qListVector);
86 // return v;
87 // break;
88 // }
89 // case Qt::BackgroundRole: {
98 // return QVariant();
99 
100 // break;
101 // }
102 // } // end role switch
103 // } // end column check
104 
105 // } // end index.valid() check
106 
107  return QVariant();
108 }
109 
110 
111 //*************************************************************************************************************
112 
113 QVariant StcModel::headerData(int section, Qt::Orientation orientation, int role) const
114 {
115 // if(role != Qt::DisplayRole && role != Qt::TextAlignmentRole)
116 // return QVariant();
117 
118 // if(orientation == Qt::Horizontal) {
119 // switch(section) {
120 // case 0: //chname column
121 // return QVariant();
122 // case 1: //data plot column
123 // return QVariant("data plot");
124 // switch(role) {
125 // case Qt::DisplayRole:
126 // return QVariant("data plot");
127 // case Qt::TextAlignmentRole:
128 // return QVariant(Qt::AlignLeft);
129 // }
130 // }
131 // }
132 // else if(orientation == Qt::Vertical) {
133 // QModelIndex chname = createIndex(section,0);
134 // switch(role) {
135 // case Qt::DisplayRole:
136 // return QVariant(data(chname).toString());
137 // }
138 // }
139 
140  return QVariant();
141 }
142 
143 
144 //*************************************************************************************************************
145 
146 void StcModel::addData(const MNESourceEstimate &stc)
147 {
148 // qDebug() << "m_vertices.size()" << m_vertices.size();
149 
150  if(m_vertices.size() < stc.data.rows())
151  setVertices(stc.vertices);
152 
153  //Downsampling ->ToDo make this more accurate
154  qint32 i;
155  for(i = m_iCurrentSample; i < stc.data.cols(); i += m_iDownsampling)
156  m_data.append(stc.data.col(i));
157 
158 // qDebug() << "StcModel::addData" << stc.data.rows();
159 // qDebug() << "MNESourceEstimate" << stc.vertices.size();
160 // qDebug() << "m_vertices.size()" << m_vertices.size();
161 // std::cout << "Vertices\n" << stc.vertices << std::endl;
162 
163  //store for next buffer
164  m_iCurrentSample = i - stc.data.cols();
165 
166 // //ToDo separate worker thread? ToDo 2000 -> size of screen
167 // if(m_dataCurrent.size() > m_iMaxSamples)
168 // {
169 // m_dataLast = m_dataCurrent.mid(0,m_iMaxSamples); // Store last data to keep as background in the display
170 // m_dataCurrent.remove(0, m_iMaxSamples);
171 // }
172 
173 // //Update data content
174 // QModelIndex topLeft = this->index(0,1);
175 // QModelIndex bottomRight = this->index(m_qListChInfo.size()-1,1);
176 // QVector<int> roles; roles << Qt::DisplayRole;
177 // emit dataChanged(topLeft, bottomRight, roles);
178 }
179 
180 
181 //*************************************************************************************************************
182 
183 void StcModel::setVertices(const VectorXi &vertnos)
184 {
185  m_vertices = vertnos;
186 }
187 
MNESourceEstimate class declaration.