Changeset - 52f54b71dc6b
[Not reviewed]
snapshots
0 6 0
Hasan Yavuz ÖZDERYA - 10 years ago 2015-09-19 15:46:37
hy@ozderya.net
plot snapshots with color
6 files changed with 38 insertions and 35 deletions:
0 comments (0 inline, 0 general)
mainwindow.cpp
Show inline comments
 
@@ -32,6 +32,7 @@
 
#include <iostream>
 

	
 
#include <snapshotview.h>
 
#include <plot.h>
 

	
 
#include "utils.h"
 
#include "version.h"
 
@@ -157,7 +158,7 @@ MainWindow::MainWindow(QWidget *parent) 
 
        channelBuffers.append(new FrameBuffer(numOfSamples));
 
        curves.append(new QwtPlotCurve());
 
        curves[i]->setSamples(channelBuffers[i]);
 
        curves[i]->setPen(makeColor(i));
 
        curves[i]->setPen(Plot::makeColor(i));
 
        curves[i]->attach(ui->plot);
 
    }
 

	
 
@@ -471,7 +472,7 @@ void MainWindow::onNumOfChannelsChanged(
 
            channelBuffers.append(new FrameBuffer(numOfSamples));
 
            curves.append(new QwtPlotCurve());
 
            curves.last()->setSamples(channelBuffers.last());
 
            curves.last()->setPen(makeColor(curves.length()-1));
 
            curves.last()->setPen(Plot::makeColor(curves.length()-1));
 
            curves.last()->attach(ui->plot);
 
        }
 
    }
 
@@ -653,37 +654,6 @@ void MainWindow::enableDemo(bool enabled
 
    }
 
}
 

	
 
/*
 
  Below crude drawing demostrates how color selection occurs for
 
  given channel index
 

	
 
  0°                     <--Hue Value-->                           360°
 
  |* . o . + . o . * . o . + . o . * . o . + . o . * . o . + . o . |
 

	
 
  * -> 0-3
 
  + -> 4-7
 
  o -> 8-15
 
  . -> 16-31
 

	
 
 */
 

	
 
QColor MainWindow::makeColor(unsigned int channelIndex)
 
{
 
    auto i = channelIndex;
 

	
 
    if (i < 4)
 
    {
 
        return QColor::fromHsv(360*i/4, 255, 230);
 
    }
 
    else
 
    {
 
        double p = floor(log2(i));
 
        double n = pow(2, p);
 
        i = i - n;
 
        return QColor::fromHsv(360*i/n + 360/pow(2,p+1), 255, 230);
 
    }
 
}
 

	
 
void MainWindow::onExportCsv()
 
{
 
    bool wasPaused = ui->actionPause->isChecked();
mainwindow.h
Show inline comments
 
@@ -109,8 +109,6 @@ private:
 
    bool isDemoRunning();
 
    QwtPlotTextLabel demoIndicator;
 

	
 
    QColor makeColor(unsigned int channelIndex);
 

	
 
private slots:
 
    void onPortToggled(bool open);
 
    void onDataReady();      // used with binary number formats
plot.cpp
Show inline comments
 
@@ -110,3 +110,33 @@ void Plot::darkBackground(bool enabled)
 
    }
 
    replot();
 
}
 

	
 
/*
 
  Below crude drawing demostrates how color selection occurs for
 
  given channel index
 

	
 
  0°                     <--Hue Value-->                           360°
 
  |* . o . + . o . * . o . + . o . * . o . + . o . * . o . + . o . |
 

	
 
  * -> 0-3
 
  + -> 4-7
 
  o -> 8-15
 
  . -> 16-31
 

	
 
 */
 
QColor Plot::makeColor(unsigned int channelIndex)
 
{
 
    auto i = channelIndex;
 

	
 
    if (i < 4)
 
    {
 
        return QColor::fromHsv(360*i/4, 255, 230);
 
    }
 
    else
 
    {
 
        double p = floor(log2(i));
 
        double n = pow(2, p);
 
        i = i - n;
 
        return QColor::fromHsv(360*i/n + 360/pow(2,p+1), 255, 230);
 
    }
 
}
plot.h
Show inline comments
 
@@ -20,6 +20,7 @@
 
#ifndef PLOT_H
 
#define PLOT_H
 

	
 
#include <QColor>
 
#include <qwt_plot.h>
 
#include <qwt_plot_grid.h>
 
#include <qwt_plot_shapeitem.h>
 
@@ -34,6 +35,8 @@ public:
 
    Plot(QWidget* parent = 0);
 
    void setAxis(bool autoScaled, double yMin = 0, double yMax = 1);
 

	
 
    static QColor makeColor(unsigned int channelIndex);
 

	
 
private:
 
    bool isAutoScaled;
 
    double yMin, yMax;
snapshotview.cpp
Show inline comments
 
@@ -14,6 +14,7 @@ SnapShotView::SnapShotView(QWidget *pare
 
        QwtPlotCurve* curve = new QwtPlotCurve();
 
        curves.append(curve);
 
        curve->setSamples(snapShot->data[ci]);
 
        curve->setPen(Plot::makeColor(ci));
 
        curve->attach(ui->plot);
 
    }
 

	
snapshotview.h
Show inline comments
 
@@ -4,6 +4,7 @@
 
#include <QMainWindow>
 
#include <QVector>
 
#include <QPointF>
 
#include <QPen>
 
#include <qwt_plot_curve.h>
 
#include "plot.h"
 

	
0 comments (0 inline, 0 general)