diff options
Diffstat (limited to 'gr-qtgui/lib/ConstellationDisplayPlot.cc')
-rw-r--r-- | gr-qtgui/lib/ConstellationDisplayPlot.cc | 241 |
1 files changed, 121 insertions, 120 deletions
diff --git a/gr-qtgui/lib/ConstellationDisplayPlot.cc b/gr-qtgui/lib/ConstellationDisplayPlot.cc index 7a595fef45..f3951534a9 100644 --- a/gr-qtgui/lib/ConstellationDisplayPlot.cc +++ b/gr-qtgui/lib/ConstellationDisplayPlot.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2008,2009,2010,2011 Free Software Foundation, Inc. + * Copyright 2008-2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,7 @@ #include <qwt_scale_draw.h> #include <qwt_legend.h> +#include <QColor> #include <iostream> class ConstellationDisplayZoomer: public QwtPlotZoomer @@ -47,65 +48,22 @@ public: protected: using QwtPlotZoomer::trackerText; - virtual QwtText trackerText( const QwtDoublePoint& p ) const + virtual QwtText trackerText( const QPoint& p ) const { - QwtText t(QString("(%1, %2)").arg(p.x(), 0, 'f', 4). - arg(p.y(), 0, 'f', 4)); + QwtDoublePoint dp = QwtPlotZoomer::invTransform(p); + QwtText t(QString("(%1, %2)").arg(dp.x(), 0, 'f', 4). + arg(dp.y(), 0, 'f', 4)); return t; } }; -ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) - : QwtPlot(parent) +ConstellationDisplayPlot::ConstellationDisplayPlot(int nplots, QWidget* parent) + : DisplayPlot(nplots, parent) { - _lastReplot = 0; - resize(parent->width(), parent->height()); _numPoints = 1024; _penSize = 5; - _realDataPoints = new double[_numPoints]; - _imagDataPoints = new double[_numPoints]; - - // Disable polygon clipping -#if QWT_VERSION < 0x060000 - QwtPainter::setDeviceClipping(false); -#else - QwtPainter::setPolylineSplitting(false); -#endif - -#if QWT_VERSION < 0x060000 - // We don't need the cache here - canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false); - canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false); -#endif - - QPalette palette; - palette.setColor(canvas()->backgroundRole(), QColor("white")); - canvas()->setPalette(palette); - - setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine); - set_xaxis(-2.0, 2.0); - setAxisTitle(QwtPlot::xBottom, "In-phase"); - - setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine); - set_yaxis(-2.0, 2.0); - setAxisTitle(QwtPlot::yLeft, "Quadrature"); - - // Automatically deleted when parent is deleted - _plot_curve = new QwtPlotCurve("Constellation Points"); - _plot_curve->attach(this); - _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - _plot_curve->setStyle(QwtPlotCurve::Dots); - -#if QWT_VERSION < 0x060000 - _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints); -#else - _plot_curve->setRawSamples(_realDataPoints, _imagDataPoints, _numPoints); -#endif - - memset(_realDataPoints, 0x0, _numPoints*sizeof(double)); - memset(_imagDataPoints, 0x0, _numPoints*sizeof(double)); _zoomer = new ConstellationDisplayZoomer(canvas()); @@ -118,65 +76,73 @@ ConstellationDisplayPlot::ConstellationDisplayPlot(QWidget* parent) _zoomer->setMousePattern(QwtEventPattern::MouseSelect3, Qt::RightButton); - _panner = new QwtPlotPanner(canvas()); - _panner->setAxisEnabled(QwtPlot::yRight, false); - _panner->setMouseButton(Qt::MidButton); - - // Avoid jumping when labels with more/less digits - // appear/disappear when scrolling vertically - - const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font()); - QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft); - sd->setMinimumExtent( fm.width("100.00") ); - const QColor c(Qt::darkRed); _zoomer->setRubberBandPen(c); _zoomer->setTrackerPen(c); - // emit the position of clicks on widget - _picker = new QwtDblClickPlotPicker(canvas()); + setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine); + set_xaxis(-2.0, 2.0); + setAxisTitle(QwtPlot::xBottom, "In-phase"); + + setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine); + set_yaxis(-2.0, 2.0); + setAxisTitle(QwtPlot::yLeft, "Quadrature"); + updateAxes(); + + QList<QColor> colors; + colors << QColor(Qt::blue) << QColor(Qt::red) << QColor(Qt::green) + << QColor(Qt::black) << QColor(Qt::cyan) << QColor(Qt::magenta) + << QColor(Qt::yellow) << QColor(Qt::gray) << QColor(Qt::darkRed) + << QColor(Qt::darkGreen) << QColor(Qt::darkBlue) << QColor(Qt::darkGray); + + // Setup dataPoints and plot vectors + // Automatically deleted when parent is deleted + for(int i = 0; i < _nplots; i++) { + _realDataPoints.push_back(new double[_numPoints]); + _imagDataPoints.push_back(new double[_numPoints]); + memset(_realDataPoints[i], 0x0, _numPoints*sizeof(double)); + memset(_imagDataPoints[i], 0x0, _numPoints*sizeof(double)); + + _plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i))); + _plot_curve[i]->attach(this); + _plot_curve[i]->setPen(QPen(colors[i])); + + QwtSymbol *symbol = new QwtSymbol(QwtSymbol::NoSymbol, QBrush(colors[i]), QPen(colors[i]), QSize(7,7)); #if QWT_VERSION < 0x060000 - connect(_picker, SIGNAL(selected(const QwtDoublePoint &)), - this, SLOT(OnPickerPointSelected(const QwtDoublePoint &))); + _plot_curve[i]->setRawData(_realDataPoints[i], _imagDataPoints[i], _numPoints); + _plot_curve[i]->setSymbol(*symbol); #else - connect(_picker, SIGNAL(selected(const QPointF &)), - this, SLOT(OnPickerPointSelected6(const QPointF &))); + _plot_curve[i]->setRawSamples(_realDataPoints[i], _imagDataPoints[i], _numPoints); + _plot_curve[i]->setSymbol(symbol); #endif - connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool ) ), - this, SLOT(LegendEntryChecked(QwtPlotItem *, bool ) )); + setLineStyle(i, Qt::NoPen); + setLineMarker(i, QwtSymbol::Ellipse); + } } ConstellationDisplayPlot::~ConstellationDisplayPlot() { - delete[] _realDataPoints; - delete[] _imagDataPoints; + for(int i = 0; i < _nplots; i++) { + delete [] _realDataPoints[i]; + delete [] _imagDataPoints[i]; + } // _fft_plot_curves deleted when parent deleted // _zoomer and _panner deleted when parent deleted } void -ConstellationDisplayPlot::set_pen_size(int size) -{ - if(size > 0 && size < 30){ - _penSize = size; - _plot_curve->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); - } -} - - -void ConstellationDisplayPlot::set_xaxis(double min, double max) { - setAxisScale(QwtPlot::xBottom, min, max); + setXaxis(min, max); } void ConstellationDisplayPlot::set_yaxis(double min, double max) { - setAxisScale(QwtPlot::yLeft, min, max); + setYaxis(min, max); } void @@ -187,69 +153,104 @@ ConstellationDisplayPlot::set_axis(double xmin, double xmax, set_yaxis(ymin, ymax); } -void ConstellationDisplayPlot::replot() +void +ConstellationDisplayPlot::set_pen_size(int size) { - QwtPlot::replot(); + if(size > 0 && size < 30){ + _penSize = size; + for(int i = 0; i < _nplots; i++) { + _plot_curve[i]->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); + } + } } void -ConstellationDisplayPlot::resizeSlot( QSize *s ) +ConstellationDisplayPlot::replot() { - resize(s->width(), s->height()); + QwtPlot::replot(); } -void ConstellationDisplayPlot::PlotNewData(const double* realDataPoints, - const double* imagDataPoints, - const int64_t numDataPoints, - const double timeInterval) -{ - if((numDataPoints > 0) && - (gruel::high_res_timer_now() - _lastReplot > timeInterval*gruel::high_res_timer_tps())) { - - if(numDataPoints != _numPoints){ - _numPoints = numDataPoints; - delete[] _realDataPoints; - delete[] _imagDataPoints; - _realDataPoints = new double[_numPoints]; - _imagDataPoints = new double[_numPoints]; +void +ConstellationDisplayPlot::plotNewData(const std::vector<double*> realDataPoints, + const std::vector<double*> imagDataPoints, + const int64_t numDataPoints, + const double timeInterval) +{ + if(!_stop) { + if((numDataPoints > 0)) { + if(numDataPoints != _numPoints) { + _numPoints = numDataPoints; + + for(int i = 0; i < _nplots; i++) { + delete [] _realDataPoints[i]; + delete [] _imagDataPoints[i]; + _realDataPoints[i] = new double[_numPoints]; + _imagDataPoints[i] = new double[_numPoints]; #if QWT_VERSION < 0x060000 - _plot_curve->setRawData(_realDataPoints, _imagDataPoints, _numPoints); + _plot_curve[i]->setRawData(_realDataPoints[i], _imagDataPoints[i], _numPoints); #else - _plot_curve->setRawSamples(_realDataPoints, _imagDataPoints, _numPoints); + _plot_curve[i]->setRawSamples(_realDataPoints[i], _imagDataPoints[i], _numPoints); #endif - } - - memcpy(_realDataPoints, realDataPoints, numDataPoints*sizeof(double)); - memcpy(_imagDataPoints, imagDataPoints, numDataPoints*sizeof(double)); + } + } + + for(int i = 0; i < _nplots; i++) { + memcpy(_realDataPoints[i], realDataPoints[i], numDataPoints*sizeof(double)); + memcpy(_imagDataPoints[i], imagDataPoints[i], numDataPoints*sizeof(double)); + } + + if(_autoscale_state) { + double bottom=1e20, top=-1e20; + for(int n = 0; n < _nplots; n++) { + for(int64_t point = 0; point < numDataPoints; point++) { + double b = std::min(realDataPoints[n][point], imagDataPoints[n][point]); + double t = std::max(realDataPoints[n][point], imagDataPoints[n][point]); + if(b < bottom) { + bottom = b; + } + if(t > top) { + top = t; + } + } + } + _autoScale(bottom, top); + } + + replot(); - replot(); - - _lastReplot = gruel::high_res_timer_now(); + } } } void -ConstellationDisplayPlot::LegendEntryChecked(QwtPlotItem* plotItem, bool on) +ConstellationDisplayPlot::plotNewData(const double* realDataPoints, + const double* imagDataPoints, + const int64_t numDataPoints, + const double timeInterval) { - plotItem->setVisible(!on); + std::vector<double*> vecRealDataPoints; + std::vector<double*> vecImagDataPoints; + vecRealDataPoints.push_back((double*)realDataPoints); + vecImagDataPoints.push_back((double*)imagDataPoints); + plotNewData(vecRealDataPoints, vecImagDataPoints, + numDataPoints, timeInterval); } void -ConstellationDisplayPlot::OnPickerPointSelected(const QwtDoublePoint & p) +ConstellationDisplayPlot::_autoScale(double bottom, double top) { - QPointF point = p; - //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); - emit plotPointSelected(point); + // Auto scale the x- and y-axis with a margin of 20% + double b = bottom - fabs(bottom)*0.20; + double t = top + fabs(top)*0.20; + set_axis(b, t, b, t); } void -ConstellationDisplayPlot::OnPickerPointSelected6(const QPointF & p) +ConstellationDisplayPlot::setAutoScale(bool state) { - QPointF point = p; - //fprintf(stderr,"OnPickerPointSelected %f %f\n", point.x(), point.y()); - emit plotPointSelected(point); + _autoscale_state = state; } #endif /* CONSTELLATION_DISPLAY_PLOT_C */ |