Statistics
| Branch: | Tag: | Revision:

root / gr-qtgui / lib / ConstellationDisplayPlot.cc @ 11ce14ee

History | View | Annotate | Download (6.2 kB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2008-2012 Free Software Foundation, Inc.
4
 *
5
 * This file is part of GNU Radio
6
 *
7
 * GNU Radio is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3, or (at your option)
10
 * any later version.
11
 *
12
 * GNU Radio is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with GNU Radio; see the file COPYING.  If not, write to
19
 * the Free Software Foundation, Inc., 51 Franklin Street,
20
 * Boston, MA 02110-1301, USA.
21
 */
22
23
#ifndef CONSTELLATION_DISPLAY_PLOT_C
24
#define CONSTELLATION_DISPLAY_PLOT_C
25
26
#include <ConstellationDisplayPlot.h>
27
28
#include <qwt_scale_draw.h>
29
#include <qwt_legend.h>
30
#include <QColor>
31
#include <iostream>
32
33
class ConstellationDisplayZoomer: public QwtPlotZoomer
34
{
35
public:
36
  ConstellationDisplayZoomer(QwtPlotCanvas* canvas):QwtPlotZoomer(canvas)
37
  {
38
    setTrackerMode(QwtPicker::AlwaysOn);
39
  }
40
41
  virtual ~ConstellationDisplayZoomer(){
42
43
  }
44
45
  virtual void updateTrackerText(){
46
    updateDisplay();
47
  }
48
49
protected:
50
  using QwtPlotZoomer::trackerText;
51
  virtual QwtText trackerText( const QPoint& p ) const
52
  {
53
    QwtDoublePoint dp = QwtPlotZoomer::invTransform(p);
54
    QwtText t(QString("(%1, %2)").arg(dp.x(), 0, 'f', 4).
55
              arg(dp.y(), 0, 'f', 4));
56
    return t;
57
  }
58
};
59
60
ConstellationDisplayPlot::ConstellationDisplayPlot(int nplots, QWidget* parent)
61
  : DisplayPlot(nplots, parent)
62
{
63
  resize(parent->width(), parent->height());
64
65
  _numPoints = 1024;
66
  _penSize = 5;
67
68
  setAxisScaleEngine(QwtPlot::xBottom, new QwtLinearScaleEngine);
69
  set_xaxis(-2.0, 2.0);
70
  setAxisTitle(QwtPlot::xBottom, "In-phase");
71
72
  setAxisScaleEngine(QwtPlot::yLeft, new QwtLinearScaleEngine);
73
  set_yaxis(-2.0, 2.0);
74
  setAxisTitle(QwtPlot::yLeft, "Quadrature");
75
76
  _zoomer = new ConstellationDisplayZoomer(canvas());
77
78
#if QWT_VERSION < 0x060000
79
  _zoomer->setSelectionFlags(QwtPicker::RectSelection | QwtPicker::DragSelection);
80
#endif
81
82
  _zoomer->setMousePattern(QwtEventPattern::MouseSelect2,
83
                           Qt::RightButton, Qt::ControlModifier);
84
  _zoomer->setMousePattern(QwtEventPattern::MouseSelect3,
85
                           Qt::RightButton);
86
87
  const QColor c(Qt::darkRed);
88
  _zoomer->setRubberBandPen(c);
89
  _zoomer->setTrackerPen(c);
90
91
  QList<QColor> colors;
92
  colors << QColor(Qt::blue) << QColor(Qt::red) << QColor(Qt::green)
93
         << QColor(Qt::black) << QColor(Qt::cyan) << QColor(Qt::magenta)
94
         << QColor(Qt::yellow) << QColor(Qt::gray) << QColor(Qt::darkRed)
95
         << QColor(Qt::darkGreen) << QColor(Qt::darkBlue) << QColor(Qt::darkGray);
96
97
  // Setup dataPoints and plot vectors
98
  // Automatically deleted when parent is deleted
99
  for(int i = 0; i < _nplots; i++) {
100
    _realDataPoints.push_back(new double[_numPoints]);
101
    _imagDataPoints.push_back(new double[_numPoints]);
102
    memset(_realDataPoints[i], 0x0, _numPoints*sizeof(double));
103
    memset(_imagDataPoints[i], 0x0, _numPoints*sizeof(double));
104
105
    _plot_curve.push_back(new QwtPlotCurve(QString("Data %1").arg(i)));
106
    _plot_curve[i]->attach(this);
107
    _plot_curve[i]->setPen(QPen(colors[i]));
108
    
109
    QwtSymbol *symbol = new QwtSymbol(QwtSymbol::NoSymbol, QBrush(colors[i]), QPen(colors[i]), QSize(7,7));
110
111
    setLineStyle(i, Qt::NoPen);
112
    setLineMarker(i, QwtSymbol::Ellipse);
113
114
#if QWT_VERSION < 0x060000
115
    _plot_curve[i]->setRawData(_realDataPoints[i], _imagDataPoints[i], _numPoints);
116
    _plot_curve[i]->setSymbol(*symbol);
117
#else
118
    _plot_curve[i]->setRawSamples(_realDataPoints[i], _imagDataPoints[i], _numPoints);
119
    _plot_curve[i]->setSymbol(symbol);
120
#endif
121
  }
122
}
123
124
ConstellationDisplayPlot::~ConstellationDisplayPlot()
125
{
126
  for(int i = 0; i < _nplots; i++) {
127
    delete [] _realDataPoints[i];
128
    delete [] _imagDataPoints[i];
129
  }
130
131
  // _fft_plot_curves deleted when parent deleted
132
  // _zoomer and _panner deleted when parent deleted
133
}
134
135
void
136
ConstellationDisplayPlot::set_xaxis(double min, double max)
137
{
138
  setAxisScale(QwtPlot::xBottom, min, max);
139
}
140
141
void
142
ConstellationDisplayPlot::set_yaxis(double min, double max)
143
{
144
  setAxisScale(QwtPlot::yLeft, min, max);
145
}
146
147
void
148
ConstellationDisplayPlot::set_axis(double xmin, double xmax,
149
                                   double ymin, double ymax)
150
{
151
  set_xaxis(xmin, xmax);
152
  set_yaxis(ymin, ymax);
153
}
154
155
void
156
ConstellationDisplayPlot::set_pen_size(int size)
157
{
158
  if(size > 0 && size < 30){
159
    _penSize = size;
160
    for(int i = 0; i < _nplots; i++) {
161
      _plot_curve[i]->setPen(QPen(Qt::blue, _penSize, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
162
    }
163
  }
164
}
165
166
void
167
ConstellationDisplayPlot::replot()
168
{
169
  QwtPlot::replot();
170
}
171
172
173
void
174
ConstellationDisplayPlot::PlotNewData(const std::vector<double*> realDataPoints,
175
                                      const std::vector<double*> imagDataPoints,
176
                                      const int64_t numDataPoints,
177
                                      const double timeInterval)
178
{
179
  if(!_stop) {
180
    if((numDataPoints > 0)) {
181
      if(numDataPoints != _numPoints) {
182
        _numPoints = numDataPoints;
183
      
184
        for(int i = 0; i < _nplots; i++) {
185
          delete [] _realDataPoints[i];
186
          delete [] _imagDataPoints[i];
187
          _realDataPoints[i] = new double[_numPoints];
188
          _imagDataPoints[i] = new double[_numPoints];
189
190
#if QWT_VERSION < 0x060000
191
          _plot_curve[i]->setRawData(_realDataPoints[i], _imagDataPoints[i], _numPoints);
192
#else
193
          _plot_curve[i]->setRawSamples(_realDataPoints[i], _imagDataPoints[i], _numPoints);
194
#endif
195
        }
196
      }
197
198
      for(int i = 0; i < _nplots; i++) {
199
        memcpy(_realDataPoints[i], realDataPoints[i], numDataPoints*sizeof(double));
200
        memcpy(_imagDataPoints[i], imagDataPoints[i], numDataPoints*sizeof(double));
201
      }
202
203
      replot();
204
205
    }
206
  }
207
}
208
209
void
210
ConstellationDisplayPlot::PlotNewData(const double* realDataPoints,
211
                                      const double* imagDataPoints,
212
                                      const int64_t numDataPoints,
213
                                      const double timeInterval)
214
{
215
  std::vector<double*> vecRealDataPoints;
216
  std::vector<double*> vecImagDataPoints;
217
  vecRealDataPoints.push_back((double*)realDataPoints);
218
  vecImagDataPoints.push_back((double*)imagDataPoints);
219
  PlotNewData(vecRealDataPoints, vecImagDataPoints,
220
              numDataPoints, timeInterval);
221
}
222
223
#endif /* CONSTELLATION_DISPLAY_PLOT_C */