53 #include <QPainterPath>
55 #include <QSvgGenerator>
56 #include <QSurfaceFormat>
63 using namespace DISPLIB;
73 #if !defined(NO_QOPENGLWIDGET)
74 QOpenGLWidget(parent, f)
78 , m_sSettingsPath(sSettingsPath)
79 , m_pEvokedSetModel(NULL)
86 , m_colCurrentBackgroundColor(Qt::white)
87 , m_qMapAverageActivation(QSharedPointer<QMap<QString, bool> >::create())
88 , m_qMapAverageColor(QSharedPointer<QMap<QString, QColor> >::create())
109 #if !defined(NO_QOPENGLWIDGET)
195 if(fileName.contains(
".svg", Qt::CaseInsensitive)) {
197 QSvgGenerator svgGen;
198 svgGen.setFileName(fileName);
199 svgGen.setSize(this->size());
200 svgGen.setViewBox(this->rect());
202 this->render(&svgGen);
205 if(fileName.contains(
".png", Qt::CaseInsensitive)) {
206 QImage image(this->size(), QImage::Format_ARGB32);
207 image.fill(Qt::transparent);
209 QPainter painter(&image);
210 this->render(&painter);
211 image.save(fileName);
265 qDebug() <<
"ButterflyView::showSelectedChannelsOnly - m_pChannelInfoModel is NULL. Returning. ";
269 QList<int> selectedChannelsIndexes;
271 for(
int i = 0; i<selectedChannels.size(); i++)
272 selectedChannelsIndexes<<
m_pChannelInfoModel->getIndexFromOrigChName(selectedChannels.at(i));
289 QList<int> lAllChannels;
291 lAllChannels.append(i);
306 QSettings settings(
"MNECPP");
318 QSettings settings(
"MNECPP");
323 #if !defined(NO_QOPENGLWIDGET)
326 void ButterflyView::paintEvent(QPaintEvent *event)
329 QPainter painter(
this);
332 painter.setBrush(QBrush(m_colCurrentBackgroundColor));
333 painter.drawRect(QRect(-1,-1,this->width()+2,this->height()+2));
336 painter.setRenderHint(QPainter::Antialiasing,
true);
338 if(m_bIsInit && m_pEvokedSetModel)
341 if(m_pEvokedSetModel->getBaselineInfo().first.toString() !=
"None" &&
342 m_pEvokedSetModel->getBaselineInfo().second.toString() !=
"None") {
343 float from = m_pEvokedSetModel->getBaselineInfo().first.toFloat();
344 float to = m_pEvokedSetModel->getBaselineInfo().second.toFloat();
347 painter.setPen(QPen(Qt::red, 1, Qt::DashLine));
348 painter.setBrush(Qt::red);
349 painter.setOpacity(0.1);
351 if(m_pEvokedSetModel->getNumSamples() == 0){
352 qDebug() <<
"Unable to get data. Returning early.";
356 float fDx = (float)(this->width()) / ((
float)m_pEvokedSetModel->getNumSamples());
358 float fromSamp = ((from)*m_pEvokedSetModel->getSamplingFrequency())+m_pEvokedSetModel->getNumPreStimSamples();
359 float posX = fDx*(fromSamp);
360 float toSamp = ((to)*m_pEvokedSetModel->getSamplingFrequency())+m_pEvokedSetModel->getNumPreStimSamples();
361 float width = fDx*(toSamp-fromSamp);
363 QRect rect(posX,0,width,this->height());
365 painter.drawRect(rect);
371 if(m_pEvokedSetModel->getNumSamples() > 0) {
373 painter.setPen(QPen(Qt::red, 1, Qt::DashLine));
375 float fDx = (float)(this->width()) / ((
float)m_pEvokedSetModel->getNumSamples());
376 float posX = fDx * ((float)m_pEvokedSetModel->getNumPreStimSamples());
377 painter.drawLine(posX, 1, posX, this->height());
379 painter.drawText(QPointF(posX+5,this->rect().bottomRight().y()-5), QString(
"0ms / Stimulus"));
385 if(m_pEvokedSetModel->getNumberOfTimeSpacers() > 0)
388 QColor colorTimeSpacer = Qt::black;
389 colorTimeSpacer.setAlphaF(0.5);
390 painter.setPen(QPen(colorTimeSpacer, 1, Qt::DashLine));
392 float yStart = this->rect().topLeft().y();
393 float yEnd = this->rect().bottomRight().y();
396 if(m_pEvokedSetModel->getNumSamples() != 0) {
397 fDx = (float)(this->width()) / ((
float)m_pEvokedSetModel->getNumSamples());
400 float sampleCounter = m_pEvokedSetModel->getNumPreStimSamples();
402 float timeDistanceMSec = 50.0;
403 float timeDistanceSamples = (timeDistanceMSec/1000.0)*m_pEvokedSetModel->getSamplingFrequency();
406 while(sampleCounter-timeDistanceSamples>0) {
407 sampleCounter-=timeDistanceSamples;
408 float x = fDx*sampleCounter;
409 painter.drawLine(x, yStart, x, yEnd);
410 painter.drawText(QPointF(x+5,yEnd-5), QString(
"-%1ms").arg(timeDistanceMSec*counter));
416 sampleCounter = m_pEvokedSetModel->getNumPreStimSamples();
417 while(sampleCounter+timeDistanceSamples<m_pEvokedSetModel->getNumSamples()) {
418 sampleCounter+=timeDistanceSamples;
419 float x = fDx*sampleCounter;
420 painter.drawLine(x, yStart, x, yEnd);
421 painter.drawText(QPointF(x+5,yEnd-5), QString(
"%1ms").arg(timeDistanceMSec*counter));
429 if(m_pEvokedSetModel->getNumSamples() > 0) {
431 painter.setPen(QPen(Qt::black, 1, Qt::DashLine));
433 painter.drawLine(0, this->height()/2, this->width(), this->height()/2);
438 painter.translate(0,this->height()/2);
441 for(qint32 r = 0; r < m_pEvokedSetModel->rowCount(); ++r) {
442 if(m_lSelectedChannels.contains(r)) {
443 qint32 kind = m_pEvokedSetModel->getKind(r);
448 qint32 unit = m_pEvokedSetModel->getUnit(r);
449 if(unit == FIFF_UNIT_T_M) {
450 if(m_modalityMap[
"GRAD"])
455 else if(unit == FIFF_UNIT_T)
457 if(m_modalityMap[
"MAG"])
465 if(m_modalityMap[
"EEG"])
471 if(m_modalityMap[
"EOG"])
476 case FIFFV_MISC_CH: {
477 if(m_modalityMap[
"MISC"])
488 createPlotPath(r, painter);
495 #if !defined(NO_QOPENGLWIDGET)
496 return QOpenGLWidget::paintGL();
498 return QWidget::paintEvent(event);
512 painter.setOpacity(0.20);
514 painter.setOpacity(0.75);
518 float fScaleY = this->height()/(2*fMaxValue);
521 float fWinMaxVal = ((float)this->height()-2)/2.0f;
527 QPointF qSamplePosition;
529 float fDx = (float)(this->width()-2) / ((
float)
m_pEvokedSetModel->getNumSamples()-1.0f);
531 QList<DISPLIB::AvrTypeRowVector> rowVec =
m_pEvokedSetModel->data(row,1).value<QList<DISPLIB::AvrTypeRowVector> >();
534 for(
int j = 0; j < rowVec.size(); ++j) {
535 QString sAvrComment = rowVec.at(j).first;
540 freezeColor.setAlphaF(0.5);
541 painter.setPen(QPen(freezeColor, 1));
549 rowVec.at(j).second.cols() / this->width() < 1 ? dsFactor = 1 : dsFactor = rowVec.at(j).second.cols() / this->width();
554 QPainterPath path(QPointF(1,0));
555 float y_base = path.currentPosition().y();
558 if(rowVec.at(j).second.cols() > 0)
560 float val = rowVec.at(j).second[0];
561 fValue = (val)*fScaleY;
563 float newY = y_base+fValue;
565 qSamplePosition.setY(-newY);
566 qSamplePosition.setX(path.currentPosition().x());
568 path.moveTo(qSamplePosition);
573 for(i = 1; i < rowVec.at(j).second.cols() && path.elementCount() <= this->width(); i += dsFactor) {
574 float val = rowVec.at(j).second[i];
575 fValue = val*fScaleY;
578 fValue = fValue > fWinMaxVal ? fWinMaxVal : fValue < -fWinMaxVal ? -fWinMaxVal : fValue;
580 float newY = y_base+fValue;
582 qSamplePosition.setY(-newY);
584 qSamplePosition.setX(path.currentPosition().x()+fDx);
586 path.lineTo(qSamplePosition);
606 painter.drawPath(path);