MNE-CPP  beta 1.0
inverseviewproducer.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "inverseviewproducer.h"
42 
43 #include "inverseview.h"
44 
45 #include <QApplication>
46 
47 
48 //*************************************************************************************************************
49 //=============================================================================================================
50 // USED NAMESPACES
51 //=============================================================================================================
52 
53 using namespace DISP3DLIB;
54 
55 
56 //*************************************************************************************************************
57 //=============================================================================================================
58 // DEFINE MEMBER METHODS
59 //=============================================================================================================
60 
61 InverseViewProducer::InverseViewProducer(qint32 p_iFps, bool p_bLoop, bool p_bSlowMotion)
62 : m_bIsRunning(false)
63 , m_iFps(p_iFps)
64 , m_bLoop(p_bLoop)
65 , m_bSlowMotion(p_bSlowMotion)
66 , m_iT(0)
67 , m_iCurSampleStep(0)
68 , m_dGlobalMaximum(0)
69 , m_bBeep(false)
70 {
71  float t_fT = 1.0 / (float)m_iFps;
72  m_iT = (qint32)(t_fT*1000000);
73 }
74 
75 
76 //*************************************************************************************************************
77 
79 {
80 }
81 
82 
83 //*************************************************************************************************************
84 
86 {
87  mutex.lock();
88 
89  if(p_sourceEstimate.tstep > 0.0f)
90  {
91  m_vecMaxActivation = p_sourceEstimate.data.rowwise().maxCoeff(); //Per Label Source
92 
93  m_dGlobalMaximum = m_vecMaxActivation.maxCoeff();
94 
95  float t_fTstep = p_sourceEstimate.tstep*1000000;
96 
97  if(m_bSlowMotion)
98  {
99  m_iFps = 1/p_sourceEstimate.tstep;
100  float t_fT = 1.0 / (float)m_iFps;
101  m_iT = (qint32)(t_fT*1000000);
102  }
103 
104  //
105  // Adapt skip to buffer size
106  //
107  qint32 t_iSampleStep = (qint32)ceil((float)m_iT)/t_fTstep; //how many samples to skip
108 
109  qint32 t_iBlockSize = p_sourceEstimate.data.cols();
110 
111  if(m_vecStcs.size() > t_iBlockSize*8)
112  t_iSampleStep = t_iBlockSize; //skip block
113  else if(m_vecStcs.size() > t_iBlockSize*4)
114  t_iSampleStep *= 4;
115  else if(m_vecStcs.size() > t_iBlockSize*2)
116  t_iSampleStep *= 2;
117 
118 
119  //
120  // Take first or sample skip of previous push into account
121  //
122  qint32 t_iCurrentSample = m_iCurSampleStep;
123 
124  while(p_sourceEstimate.data.cols() > t_iCurrentSample)
125  {
126  m_vecStcs.append(p_sourceEstimate.data.col(t_iCurrentSample));
127  m_vecTime.append(p_sourceEstimate.times(t_iCurrentSample));
128 
129  t_iCurrentSample += t_iSampleStep;
130  }
131 
132  m_iCurSampleStep = t_iCurrentSample - p_sourceEstimate.data.cols();
133  }
134  else
135  std::cout << "T step not set!" << std::endl;
136  mutex.unlock();
137 }
138 
139 
140 //*************************************************************************************************************
141 
143 {
144  m_bIsRunning = false;
145 
146  // Stop threads
147  QThread::terminate();
148  QThread::wait();
149 }
150 
151 
152 //*************************************************************************************************************
153 
155 {
156  qint32 simCount = 0;
157  qint32 currentSample = 0;
158 
159  float t_fTimeOld = -1.0;
160 
161  m_bIsRunning = true;
162 
163  while(m_bIsRunning)
164  {
165  //LNdT hack
166  mutex.lock();
167  if(m_vecStcs.size() > 0)
168  {
169  //Loop
170  if(m_bLoop)
171  {
172  currentSample = simCount%m_vecStcs.size();
173  if (m_bBeep && ((t_fTimeOld < 0.0) && (m_vecTime[currentSample] >= 0.0)))
174  {
175  QApplication::beep();
176  qDebug("beep");
177  }
178  t_fTimeOld = m_vecTime[currentSample];
179  QSharedPointer<VectorXd> p_qVecCurrentActivation(new VectorXd(m_vecStcs[currentSample]));
180  emit sourceEstimateSample(p_qVecCurrentActivation);
181 
182  ++simCount;
183  }
184  //Single view
185  else
186  {
187  if (m_bBeep && ((t_fTimeOld < 0.0) && (m_vecTime[0] >= 0.0)))
188  {
189  QApplication::beep();
190  qDebug("beep");
191  }
192  t_fTimeOld = m_vecTime[0];
193 
194  QSharedPointer<VectorXd> p_qVecCurrentActivation(new VectorXd(m_vecStcs[0]));
195  emit sourceEstimateSample(p_qVecCurrentActivation);
196  m_vecTime.pop_front();
197  m_vecStcs.pop_front();
198  }
199  }
200 
201  mutex.unlock();
202 
203  if(m_bSlowMotion)
204  msleep(40);
205  else
206  usleep(m_iT);
207  }
208 }
InverseViewProducer class declaration.
void pushSourceEstimate(MNESourceEstimate &p_sourceEstimate)
InverseViewProducer(qint32 p_iFps, bool p_bLoop, bool p_bSlowMotion)
InverseView class declaration.