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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/* -*- c++ -*- */
/*
* Copyright 2012,2013 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* GNU Radio is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* GNU Radio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Radio; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef TIMERASTER_GLOBAL_DATA_CPP
#define TIMERASTER_GLOBAL_DATA_CPP
#include <qtgui/timeRasterGlobalData.h>
#include <cstdio>
#include <cmath>
#include <iostream>
TimeRasterData::TimeRasterData(const double rows, const double cols)
#if QWT_VERSION < 0x060000
: QwtRasterData(QwtDoubleRect(0, 0, rows, cols))
#else
: QwtRasterData()
#endif
{
d_nitems = 0;
d_rows = rows;
d_cols = cols;
d_resid = 0;
// We add 1 here so we always have the next row already started
// (helps when d_cols is fractional and we have to slide).
d_totalitems = static_cast<int>((d_rows+1)*floor(d_cols));
d_data_size = d_totalitems + static_cast<int>(floor(d_cols));
d_intensityRange = QwtDoubleInterval(0.0, 10.0);
d_data = new double[d_data_size];
#if QWT_VERSION >= 0x060000
setInterval(Qt::XAxis, QwtInterval(0, cols));
setInterval(Qt::YAxis, QwtInterval(0, rows));
setInterval(Qt::ZAxis, QwtInterval(0.0, 10.0));
#endif
reset();
}
TimeRasterData::~TimeRasterData()
{
delete [] d_data;
}
void TimeRasterData::reset()
{
d_resid = 0;
d_nitems = 0;
memset(d_data, 0x0, d_data_size*sizeof(double));
}
void TimeRasterData::copy(const TimeRasterData* rhs)
{
#if QWT_VERSION < 0x060000
if((d_cols != rhs->getNumCols()) ||
(boundingRect() != rhs->boundingRect()) ){
d_cols = rhs->getNumCols();
d_rows = rhs->getNumRows();
d_totalitems = static_cast<int>((d_rows+1)*floor(d_cols));
d_data_size = d_totalitems + static_cast<int>(floor(d_cols));
setBoundingRect(rhs->boundingRect());
delete [] d_data;
d_data = new double[d_data_size];
}
#else
if((d_cols != rhs->getNumCols()) || (d_rows != rhs->getNumRows())) {
d_cols = rhs->getNumCols();
d_rows = rhs->getNumRows();
d_totalitems = static_cast<int>((d_rows+1)*floor(d_cols));
d_data_size = d_totalitems + static_cast<int>(floor(d_cols));
delete [] d_data;
d_data = new double[d_data_size];
}
#endif
reset();
#if QWT_VERSION < 0x060000
setRange(rhs->range());
#else
setInterval(Qt::XAxis, rhs->interval(Qt::XAxis));
setInterval(Qt::YAxis, rhs->interval(Qt::YAxis));
setInterval(Qt::ZAxis, rhs->interval(Qt::ZAxis));
#endif
}
void TimeRasterData::resizeData(const double rows, const double cols)
{
#if QWT_VERSION < 0x060000
if((cols != getNumCols()) || (boundingRect().width() != cols) ||
(rows != getNumRows()) || (boundingRect().height() != cols)) {
setBoundingRect(QwtDoubleRect(0, 0, cols, rows));
d_cols = cols;
d_rows = rows;
d_totalitems = static_cast<int>((d_rows+1)*floor(d_cols));
d_data_size = d_totalitems + static_cast<int>(floor(d_cols));
delete [] d_data;
d_data = new double[d_data_size];
}
#else
if((cols != getNumCols()) || (interval(Qt::XAxis).width() != cols) ||
(rows != getNumRows()) || (interval(Qt::YAxis).width() != rows)) {
setInterval(Qt::XAxis, QwtInterval(0, cols));
setInterval(Qt::YAxis, QwtInterval(0, rows));
d_cols = cols;
d_rows = rows;
d_totalitems = static_cast<int>((d_rows+1)*floor(d_cols));
d_data_size = d_totalitems + static_cast<int>(floor(d_cols));
delete [] d_data;
d_data = new double[d_data_size];
}
#endif
reset();
}
QwtRasterData *TimeRasterData::copy() const
{
#if QWT_VERSION < 0x060000
TimeRasterData* returnData = \
new TimeRasterData(d_cols, d_rows);
#else
TimeRasterData* returnData = \
new TimeRasterData(d_cols, d_rows);
#endif
returnData->copy(this);
return returnData;
}
#if QWT_VERSION < 0x060000
QwtDoubleInterval TimeRasterData::range() const
{
return d_intensityRange;
}
void TimeRasterData::setRange(const QwtDoubleInterval& newRange)
{
d_intensityRange = newRange;
}
#endif
double
TimeRasterData::value(double x, double y) const
{
double returnValue = 0.0;
#if QWT_VERSION < 0x060000
double top = boundingRect().top();
double bottom = top - boundingRect().height();
double left = boundingRect().left();
double right = left - boundingRect().width();
#else
double top = interval(Qt::YAxis).maxValue();
double bottom = interval(Qt::YAxis).minValue();
double left = interval(Qt::XAxis).minValue();
double right = interval(Qt::XAxis).maxValue();
#endif
if((x < left) || (x > right) || (y < bottom) || (y > top))
return 0.0;
double _y = floor(top - y);
double _loc = _y*(d_cols) + x + d_resid;
int location = static_cast<int>(_loc);
if((location > -1) && (location < d_data_size)) {
returnValue = d_data[location];
}
return returnValue;
}
void
TimeRasterData::incrementResidual()
{
// After a full set of rows are drawn, we want to add up the
// residual due to any fractional value of d_cols to appropriately
// shift the next data in.
double icols = floor(d_cols);
d_resid = fmod(d_resid + (d_cols - icols) * d_rows, icols);
}
double
TimeRasterData::getNumCols() const
{
return d_cols;
}
double
TimeRasterData::getNumRows() const
{
return d_rows;
}
void
TimeRasterData::addData(const double* data,
const int dataSize)
{
int cols = static_cast<int>(d_cols);
if(dataSize == cols) {
if(d_nitems < d_totalitems) {
memcpy(&d_data[d_nitems], data, cols*sizeof(double));
d_nitems += cols;
}
else {
memcpy(&d_data[d_nitems], data, cols*sizeof(double));
memmove(d_data, &d_data[cols], d_totalitems*sizeof(double));
}
}
}
#endif /* TIMERASTER_GLOBAL_DATA_CPP */
|