File: incrementalplot.cpp

package info (click to toggle)
libqwt 4.2.0-4.1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,832 kB
  • ctags: 5,512
  • sloc: cpp: 22,973; ansic: 244; makefile: 66
file content (86 lines) | stat: -rw-r--r-- 1,715 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <qwt_plot.h>
#include <qwt_plot_dict.h>
#include "incrementalplot.h"

CurveData::CurveData():
    d_count(0)
{
}

void CurveData::append(double *x, double *y, int count)
{
    int newSize = ( (d_count + count) / 1000 + 1 ) * 1000;
    if ( newSize > size() )
    {
        d_x.resize(newSize);
        d_y.resize(newSize);
    }

    for ( register int i = 0; i < count; i++ )
    {
        d_x[d_count + i] = x[i];
        d_y[d_count + i] = y[i];
    }
    d_count += count;
}

int CurveData::count() const
{
    return d_count;
}

int CurveData::size() const
{
    return d_x.size();
}

double *CurveData::x() const
{
    return d_x.data();
}

double *CurveData::y() const
{
    return d_y.data();
}

IncrementalPlot::IncrementalPlot(QWidget *parent, const char* name): 
    QwtPlot(parent, name)
{
    d_curveDictionary.setAutoDelete(TRUE);
}

IncrementalPlot::~IncrementalPlot()
{
    removeCurves();
}

void IncrementalPlot::appendCurvePoint(long curveId, double x, double y)
{
    appendCurveData(curveId, &x, &y, 1);
}

void IncrementalPlot::appendCurveData(long curveId, 
    double *x, double *y, int size)
{
    QwtPlotCurve *curve = IncrementalPlot::curve(curveId);
    if ( curve == 0 || size <= 0 )
        return;
    
    CurveData *curveData = d_curveDictionary.find(curveId);
    if ( curveData == 0 )
    {
        curveData = new CurveData();
        d_curveDictionary.insert(curveId, curveData);
    }

    curveData->append(x, y, size);
    curve->setRawData(curveData->x(), curveData->y(), curveData->count());

    drawCurve(curveId, curve->dataSize() - size, curve->dataSize() - 1);
}

void IncrementalPlot::removeCurveData(long curveId)
{
    d_curveDictionary.remove(curveId);
}