Chris@133
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@133
|
2
|
Chris@133
|
3 /*
|
Chris@133
|
4 Sonic Visualiser
|
Chris@133
|
5 An audio file viewer and annotation editor.
|
Chris@133
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@195
|
7 This file copyright 2006-2007 QMUL.
|
Chris@133
|
8
|
Chris@133
|
9 This program is free software; you can redistribute it and/or
|
Chris@133
|
10 modify it under the terms of the GNU General Public License as
|
Chris@133
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@133
|
12 License, or (at your option) any later version. See the file
|
Chris@133
|
13 COPYING included with this distribution for more information.
|
Chris@133
|
14 */
|
Chris@133
|
15
|
Chris@193
|
16 #include "SliceLayer.h"
|
Chris@133
|
17
|
Chris@133
|
18 #include "view/View.h"
|
Chris@153
|
19 #include "base/AudioLevel.h"
|
Chris@167
|
20 #include "base/RangeMapper.h"
|
Chris@195
|
21 #include "base/RealTime.h"
|
Chris@376
|
22 #include "ColourMapper.h"
|
Chris@376
|
23 #include "ColourDatabase.h"
|
Chris@195
|
24
|
Chris@195
|
25 #include "PaintAssistant.h"
|
Chris@133
|
26
|
Chris@133
|
27 #include <QPainter>
|
Chris@133
|
28 #include <QPainterPath>
|
Chris@316
|
29 #include <QTextStream>
|
Chris@316
|
30
|
Chris@133
|
31
|
Chris@193
|
32 SliceLayer::SliceLayer() :
|
Chris@193
|
33 m_sliceableModel(0),
|
Chris@197
|
34 m_colourMap(0),
|
Chris@153
|
35 m_energyScale(dBScale),
|
Chris@198
|
36 m_samplingMode(SampleMean),
|
Chris@1233
|
37 m_plotStyle(PlotLines),
|
Chris@193
|
38 m_binScale(LinearBins),
|
Chris@153
|
39 m_normalize(false),
|
Chris@284
|
40 m_threshold(0.0),
|
Chris@284
|
41 m_initialThreshold(0.0),
|
Chris@198
|
42 m_gain(1.0),
|
Chris@1238
|
43 m_minbin(0),
|
Chris@1238
|
44 m_maxbin(0),
|
Chris@198
|
45 m_currentf0(0),
|
Chris@198
|
46 m_currentf1(0)
|
Chris@133
|
47 {
|
Chris@133
|
48 }
|
Chris@133
|
49
|
Chris@193
|
50 SliceLayer::~SliceLayer()
|
Chris@133
|
51 {
|
Chris@193
|
52
|
Chris@133
|
53 }
|
Chris@133
|
54
|
Chris@133
|
55 void
|
Chris@193
|
56 SliceLayer::setSliceableModel(const Model *model)
|
Chris@133
|
57 {
|
Chris@193
|
58 const DenseThreeDimensionalModel *sliceable =
|
Chris@193
|
59 dynamic_cast<const DenseThreeDimensionalModel *>(model);
|
Chris@193
|
60
|
Chris@193
|
61 if (model && !sliceable) {
|
Chris@682
|
62 cerr << "WARNING: SliceLayer::setSliceableModel(" << model
|
Chris@682
|
63 << "): model is not a DenseThreeDimensionalModel" << endl;
|
Chris@193
|
64 }
|
Chris@193
|
65
|
Chris@193
|
66 if (m_sliceableModel == sliceable) return;
|
Chris@193
|
67
|
Chris@193
|
68 m_sliceableModel = sliceable;
|
Chris@193
|
69
|
Chris@320
|
70 connectSignals(m_sliceableModel);
|
Chris@193
|
71
|
Chris@1238
|
72 m_minbin = 0;
|
Chris@1238
|
73 m_maxbin = m_sliceableModel->getHeight();
|
Chris@1238
|
74
|
Chris@193
|
75 emit modelReplaced();
|
Chris@1238
|
76 emit layerParametersChanged();
|
Chris@153
|
77 }
|
Chris@153
|
78
|
Chris@153
|
79 void
|
Chris@193
|
80 SliceLayer::sliceableModelReplaced(const Model *orig, const Model *replacement)
|
Chris@153
|
81 {
|
Chris@587
|
82 SVDEBUG << "SliceLayer::sliceableModelReplaced(" << orig << ", " << replacement << ")" << endl;
|
Chris@153
|
83
|
Chris@193
|
84 if (orig == m_sliceableModel) {
|
Chris@193
|
85 setSliceableModel
|
Chris@193
|
86 (dynamic_cast<const DenseThreeDimensionalModel *>(replacement));
|
Chris@153
|
87 }
|
Chris@153
|
88 }
|
Chris@153
|
89
|
Chris@153
|
90 void
|
Chris@193
|
91 SliceLayer::modelAboutToBeDeleted(Model *m)
|
Chris@153
|
92 {
|
Chris@587
|
93 SVDEBUG << "SliceLayer::modelAboutToBeDeleted(" << m << ")" << endl;
|
Chris@153
|
94
|
Chris@193
|
95 if (m == m_sliceableModel) {
|
Chris@193
|
96 setSliceableModel(0);
|
Chris@153
|
97 }
|
Chris@133
|
98 }
|
Chris@133
|
99
|
Chris@198
|
100 QString
|
Chris@918
|
101 SliceLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const
|
Chris@198
|
102 {
|
Chris@199
|
103 int minbin, maxbin, range;
|
Chris@805
|
104 return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range);
|
Chris@199
|
105 }
|
Chris@199
|
106
|
Chris@199
|
107 QString
|
Chris@918
|
108 SliceLayer::getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &p,
|
Chris@805
|
109 bool includeBinDescription,
|
Chris@805
|
110 int &minbin, int &maxbin, int &range) const
|
Chris@199
|
111 {
|
Chris@199
|
112 minbin = 0;
|
Chris@199
|
113 maxbin = 0;
|
Chris@198
|
114 if (!m_sliceableModel) return "";
|
Chris@198
|
115
|
Chris@1238
|
116 minbin = int(round(getBinForX(v, p.x())));
|
Chris@1238
|
117 maxbin = int(round(getBinForX(v, p.x() + 1)));
|
Chris@1238
|
118
|
Chris@198
|
119 int mh = m_sliceableModel->getHeight();
|
Chris@199
|
120 if (minbin >= mh) minbin = mh - 1;
|
Chris@199
|
121 if (maxbin >= mh) maxbin = mh - 1;
|
Chris@199
|
122 if (minbin < 0) minbin = 0;
|
Chris@199
|
123 if (maxbin < 0) maxbin = 0;
|
Chris@198
|
124
|
Chris@906
|
125 sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate();
|
Chris@198
|
126
|
Chris@906
|
127 sv_frame_t f0 = m_currentf0;
|
Chris@906
|
128 sv_frame_t f1 = m_currentf1;
|
Chris@198
|
129
|
Chris@198
|
130 RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate);
|
Chris@198
|
131 RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate);
|
Chris@198
|
132
|
Chris@906
|
133 range = int(f1 - f0 + 1);
|
Chris@198
|
134
|
Chris@280
|
135 QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str());
|
Chris@280
|
136
|
Chris@199
|
137 if (includeBinDescription) {
|
Chris@198
|
138
|
Chris@1238
|
139 int i0 = minbin - m_minbin;
|
Chris@1238
|
140 int i1 = maxbin - m_minbin;
|
Chris@1238
|
141
|
Chris@906
|
142 float minvalue = 0.0;
|
Chris@1238
|
143 if (in_range_for(m_values, i0)) minvalue = m_values[i0];
|
Chris@198
|
144
|
Chris@199
|
145 float maxvalue = minvalue;
|
Chris@1238
|
146 if (in_range_for(m_values, i1)) maxvalue = m_values[i1];
|
Chris@1238
|
147
|
Chris@199
|
148 if (minvalue > maxvalue) std::swap(minvalue, maxvalue);
|
Chris@199
|
149
|
Chris@199
|
150 QString binstr;
|
Chris@199
|
151 if (maxbin != minbin) {
|
Chris@199
|
152 binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1);
|
Chris@199
|
153 } else {
|
Chris@199
|
154 binstr = QString("%1").arg(minbin+1);
|
Chris@199
|
155 }
|
Chris@199
|
156
|
Chris@199
|
157 QString valuestr;
|
Chris@199
|
158 if (maxvalue != minvalue) {
|
Chris@199
|
159 valuestr = tr("%1 - %2").arg(minvalue).arg(maxvalue);
|
Chris@199
|
160 } else {
|
Chris@199
|
161 valuestr = QString("%1").arg(minvalue);
|
Chris@199
|
162 }
|
Chris@199
|
163
|
Chris@280
|
164 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples (%4)\nBin:\t%5\n%6 value:\t%7")
|
Chris@199
|
165 .arg(QString::fromStdString(rt0.toText(true)))
|
Chris@199
|
166 .arg(QString::fromStdString(rt1.toText(true)))
|
Chris@199
|
167 .arg(range)
|
Chris@280
|
168 .arg(rtrangestr)
|
Chris@199
|
169 .arg(binstr)
|
Chris@199
|
170 .arg(m_samplingMode == NearestSample ? tr("First") :
|
Chris@199
|
171 m_samplingMode == SampleMean ? tr("Mean") : tr("Peak"))
|
Chris@199
|
172 .arg(valuestr);
|
Chris@199
|
173
|
Chris@199
|
174 return description;
|
Chris@199
|
175
|
Chris@199
|
176 } else {
|
Chris@199
|
177
|
Chris@280
|
178 QString description = tr("Time:\t%1 - %2\nRange:\t%3 samples (%4)")
|
Chris@199
|
179 .arg(QString::fromStdString(rt0.toText(true)))
|
Chris@199
|
180 .arg(QString::fromStdString(rt1.toText(true)))
|
Chris@280
|
181 .arg(range)
|
Chris@280
|
182 .arg(rtrangestr);
|
Chris@199
|
183
|
Chris@199
|
184 return description;
|
Chris@199
|
185 }
|
Chris@198
|
186 }
|
Chris@198
|
187
|
Chris@906
|
188 double
|
Chris@1238
|
189 SliceLayer::getXForBin(const LayerGeometryProvider *v, double bin) const
|
Chris@198
|
190 {
|
Chris@906
|
191 double x = 0;
|
Chris@198
|
192
|
Chris@1238
|
193 bin -= m_minbin;
|
Chris@1238
|
194 if (bin < 0) bin = 0;
|
Chris@1238
|
195
|
Chris@1238
|
196 double count = m_maxbin - m_minbin;
|
Chris@1238
|
197 if (count < 0) count = 0;
|
Chris@1238
|
198
|
Chris@1238
|
199 int pw = v->getPaintWidth();
|
Chris@1238
|
200 int origin = m_xorigins[v->getId()];
|
Chris@1238
|
201 int w = pw - origin;
|
Chris@1238
|
202 if (w < 1) w = 1;
|
Chris@1238
|
203
|
Chris@198
|
204 switch (m_binScale) {
|
Chris@198
|
205
|
Chris@198
|
206 case LinearBins:
|
Chris@906
|
207 x = (w * bin) / count;
|
Chris@198
|
208 break;
|
Chris@198
|
209
|
Chris@198
|
210 case LogBins:
|
Chris@906
|
211 x = (w * log10(bin + 1)) / log10(count + 1);
|
Chris@198
|
212 break;
|
Chris@198
|
213
|
Chris@198
|
214 case InvertedLogBins:
|
Chris@906
|
215 x = w - (w * log10(count - bin - 1)) / log10(count);
|
Chris@198
|
216 break;
|
Chris@198
|
217 }
|
Chris@1238
|
218
|
Chris@1238
|
219 return x + origin;
|
Chris@198
|
220 }
|
Chris@198
|
221
|
Chris@1238
|
222 double
|
Chris@1238
|
223 SliceLayer::getBinForX(const LayerGeometryProvider *v, double x) const
|
Chris@198
|
224 {
|
Chris@1238
|
225 double bin = 0;
|
Chris@198
|
226
|
Chris@1238
|
227 double count = m_maxbin - m_minbin;
|
Chris@1238
|
228 if (count < 0) count = 0;
|
Chris@1238
|
229
|
Chris@1238
|
230 int pw = v->getPaintWidth();
|
Chris@1238
|
231 int origin = m_xorigins[v->getId()];
|
Chris@1238
|
232
|
Chris@1238
|
233 int w = pw - origin;
|
Chris@1238
|
234 if (w < 1) w = 1;
|
Chris@1238
|
235
|
Chris@1238
|
236 x = x - origin;
|
Chris@1238
|
237 if (x < 0) x = 0;
|
Chris@1238
|
238
|
Chris@198
|
239 switch (m_binScale) {
|
Chris@198
|
240
|
Chris@198
|
241 case LinearBins:
|
Chris@198
|
242 bin = int((x * count) / w + 0.0001);
|
Chris@198
|
243 break;
|
Chris@198
|
244
|
Chris@198
|
245 case LogBins:
|
Chris@906
|
246 bin = int(pow(10.0, (x * log10(count + 1)) / w) - 1 + 0.0001);
|
Chris@198
|
247 break;
|
Chris@198
|
248
|
Chris@198
|
249 case InvertedLogBins:
|
Chris@906
|
250 bin = count + 1 - int(pow(10.0, (log10(count) * (w - x)) / double(w)) + 0.0001);
|
Chris@198
|
251 break;
|
Chris@198
|
252 }
|
Chris@198
|
253
|
Chris@1238
|
254 return bin + m_minbin;
|
Chris@198
|
255 }
|
Chris@198
|
256
|
Chris@906
|
257 double
|
Chris@1238
|
258 SliceLayer::getYForValue(const LayerGeometryProvider *v, double value, double &norm) const
|
Chris@274
|
259 {
|
Chris@906
|
260 norm = 0.0;
|
Chris@274
|
261
|
Chris@1238
|
262 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return 0;
|
Chris@274
|
263
|
Chris@274
|
264 value *= m_gain;
|
Chris@274
|
265
|
Chris@1238
|
266 int yorigin = m_yorigins[v->getId()];
|
Chris@1238
|
267 int h = m_heights[v->getId()];
|
Chris@906
|
268 double thresh = getThresholdDb();
|
Chris@274
|
269
|
Chris@906
|
270 double y = 0.0;
|
Chris@274
|
271
|
Chris@274
|
272 if (h <= 0) return y;
|
Chris@274
|
273
|
Chris@274
|
274 switch (m_energyScale) {
|
Chris@274
|
275
|
Chris@274
|
276 case dBScale:
|
Chris@274
|
277 {
|
Chris@906
|
278 double db = thresh;
|
Chris@906
|
279 if (value > 0.0) db = 10.0 * log10(fabs(value));
|
Chris@274
|
280 if (db < thresh) db = thresh;
|
Chris@274
|
281 norm = (db - thresh) / -thresh;
|
Chris@906
|
282 y = yorigin - (double(h) * norm);
|
Chris@274
|
283 break;
|
Chris@274
|
284 }
|
Chris@274
|
285
|
Chris@274
|
286 case MeterScale:
|
Chris@274
|
287 y = AudioLevel::multiplier_to_preview(value, h);
|
Chris@906
|
288 norm = double(y) / double(h);
|
Chris@274
|
289 y = yorigin - y;
|
Chris@274
|
290 break;
|
Chris@274
|
291
|
Chris@538
|
292 case AbsoluteScale:
|
Chris@906
|
293 value = fabs(value);
|
Chris@538
|
294 // and fall through
|
Chris@538
|
295
|
Chris@805
|
296 case LinearScale:
|
Chris@274
|
297 default:
|
Chris@538
|
298 norm = (value - m_threshold);
|
Chris@284
|
299 if (norm < 0) norm = 0;
|
Chris@906
|
300 y = yorigin - (double(h) * norm);
|
Chris@274
|
301 break;
|
Chris@274
|
302 }
|
Chris@274
|
303
|
Chris@274
|
304 return y;
|
Chris@274
|
305 }
|
Chris@274
|
306
|
Chris@906
|
307 double
|
Chris@1238
|
308 SliceLayer::getValueForY(const LayerGeometryProvider *v, double y) const
|
Chris@274
|
309 {
|
Chris@906
|
310 double value = 0.0;
|
Chris@274
|
311
|
Chris@1238
|
312 if (m_yorigins.find(v->getId()) == m_yorigins.end()) return value;
|
Chris@274
|
313
|
Chris@1238
|
314 int yorigin = m_yorigins[v->getId()];
|
Chris@1238
|
315 int h = m_heights[v->getId()];
|
Chris@906
|
316 double thresh = getThresholdDb();
|
Chris@274
|
317
|
Chris@274
|
318 if (h <= 0) return value;
|
Chris@274
|
319
|
Chris@274
|
320 y = yorigin - y;
|
Chris@274
|
321
|
Chris@274
|
322 switch (m_energyScale) {
|
Chris@274
|
323
|
Chris@274
|
324 case dBScale:
|
Chris@274
|
325 {
|
Chris@906
|
326 double db = ((y / h) * -thresh) + thresh;
|
Chris@906
|
327 value = pow(10.0, db/10.0);
|
Chris@274
|
328 break;
|
Chris@274
|
329 }
|
Chris@274
|
330
|
Chris@274
|
331 case MeterScale:
|
Chris@906
|
332 value = AudioLevel::preview_to_multiplier(int(lrint(y)), h);
|
Chris@274
|
333 break;
|
Chris@805
|
334
|
Chris@805
|
335 case LinearScale:
|
Chris@805
|
336 case AbsoluteScale:
|
Chris@274
|
337 default:
|
Chris@284
|
338 value = y / h + m_threshold;
|
Chris@274
|
339 }
|
Chris@274
|
340
|
Chris@274
|
341 return value / m_gain;
|
Chris@274
|
342 }
|
Chris@274
|
343
|
Chris@133
|
344 void
|
Chris@916
|
345 SliceLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@133
|
346 {
|
Chris@254
|
347 if (!m_sliceableModel || !m_sliceableModel->isOK() ||
|
Chris@254
|
348 !m_sliceableModel->isReady()) return;
|
Chris@133
|
349
|
Chris@195
|
350 paint.save();
|
Chris@195
|
351 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@538
|
352 paint.setBrush(Qt::NoBrush);
|
Chris@195
|
353
|
Chris@195
|
354 if (v->getViewManager() && v->getViewManager()->shouldShowScaleGuides()) {
|
Chris@195
|
355 if (!m_scalePoints.empty()) {
|
Chris@195
|
356 paint.setPen(QColor(240, 240, 240)); //!!! and dark background?
|
Chris@805
|
357 for (int i = 0; i < (int)m_scalePoints.size(); ++i) {
|
Chris@195
|
358 paint.drawLine(0, m_scalePoints[i], rect.width(), m_scalePoints[i]);
|
Chris@195
|
359 }
|
Chris@195
|
360 }
|
Chris@195
|
361 }
|
Chris@195
|
362
|
Chris@1233
|
363 if (m_plotStyle == PlotBlocks) {
|
Chris@1233
|
364 // Must use actual zero-width pen, too slow otherwise
|
Chris@1233
|
365 paint.setPen(QPen(getBaseQColor(), 0));
|
Chris@1233
|
366 } else {
|
Chris@1233
|
367 paint.setPen(PaintAssistant::scalePen(getBaseQColor()));
|
Chris@1233
|
368 }
|
Chris@195
|
369
|
Chris@607
|
370 int xorigin = getVerticalScaleWidth(v, true, paint) + 1;
|
Chris@1238
|
371 m_xorigins[v->getId()] = xorigin; // for use in getFeatureDescription
|
Chris@133
|
372
|
Chris@918
|
373 int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 7;
|
Chris@195
|
374 int h = yorigin - paint.fontMetrics().height() - 8;
|
Chris@133
|
375
|
Chris@1238
|
376 m_yorigins[v->getId()] = yorigin; // for getYForValue etc
|
Chris@1238
|
377 m_heights[v->getId()] = h;
|
Chris@274
|
378
|
Chris@274
|
379 if (h <= 0) return;
|
Chris@274
|
380
|
Chris@133
|
381 QPainterPath path;
|
Chris@133
|
382
|
Chris@805
|
383 int mh = m_sliceableModel->getHeight();
|
Chris@1238
|
384 int bin0 = 0;
|
Chris@133
|
385
|
Chris@1238
|
386 if (m_maxbin > m_minbin) {
|
Chris@1238
|
387 mh = m_maxbin - m_minbin;
|
Chris@1238
|
388 bin0 = m_minbin;
|
Chris@1238
|
389 }
|
Chris@1238
|
390
|
Chris@193
|
391 int divisor = 0;
|
Chris@193
|
392
|
Chris@198
|
393 m_values.clear();
|
Chris@805
|
394 for (int bin = 0; bin < mh; ++bin) {
|
Chris@906
|
395 m_values.push_back(0.0);
|
Chris@193
|
396 }
|
Chris@193
|
397
|
Chris@906
|
398 sv_frame_t f0 = v->getCentreFrame();
|
Chris@193
|
399 int f0x = v->getXForFrame(f0);
|
Chris@195
|
400 f0 = v->getFrameForX(f0x);
|
Chris@906
|
401 sv_frame_t f1 = v->getFrameForX(f0x + 1);
|
Chris@195
|
402 if (f1 > f0) --f1;
|
Chris@193
|
403
|
Chris@682
|
404 // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl;
|
Chris@274
|
405
|
Chris@805
|
406 int res = m_sliceableModel->getResolution();
|
Chris@906
|
407 int col0 = int(f0 / res);
|
Chris@805
|
408 int col1 = col0;
|
Chris@906
|
409 if (m_samplingMode != NearestSample) col1 = int(f1 / res);
|
Chris@274
|
410 f0 = col0 * res;
|
Chris@274
|
411 f1 = (col1 + 1) * res - 1;
|
Chris@274
|
412
|
Chris@682
|
413 // cerr << "resolution " << res << ", col0 " << col0 << ", col1 " << col1 << ", f0 " << f0 << ", f1 " << f1 << endl;
|
Chris@193
|
414
|
Chris@198
|
415 m_currentf0 = f0;
|
Chris@198
|
416 m_currentf1 = f1;
|
Chris@198
|
417
|
Chris@254
|
418 BiasCurve curve;
|
Chris@254
|
419 getBiasCurve(curve);
|
Chris@906
|
420 int cs = int(curve.size());
|
Chris@254
|
421
|
Chris@805
|
422 for (int col = col0; col <= col1; ++col) {
|
Chris@805
|
423 for (int bin = 0; bin < mh; ++bin) {
|
Chris@1238
|
424 float value = m_sliceableModel->getValueAt(col, bin0 + bin);
|
Chris@254
|
425 if (bin < cs) value *= curve[bin];
|
Chris@193
|
426 if (m_samplingMode == SamplePeak) {
|
Chris@198
|
427 if (value > m_values[bin]) m_values[bin] = value;
|
Chris@193
|
428 } else {
|
Chris@198
|
429 m_values[bin] += value;
|
Chris@193
|
430 }
|
Chris@153
|
431 }
|
Chris@193
|
432 ++divisor;
|
Chris@193
|
433 }
|
Chris@193
|
434
|
Chris@906
|
435 float max = 0.0;
|
Chris@805
|
436 for (int bin = 0; bin < mh; ++bin) {
|
Chris@847
|
437 if (m_samplingMode == SampleMean && divisor > 0) {
|
Chris@906
|
438 m_values[bin] /= float(divisor);
|
Chris@847
|
439 }
|
Chris@198
|
440 if (m_values[bin] > max) max = m_values[bin];
|
Chris@193
|
441 }
|
Chris@906
|
442 if (max != 0.0 && m_normalize) {
|
Chris@805
|
443 for (int bin = 0; bin < mh; ++bin) {
|
Chris@198
|
444 m_values[bin] /= max;
|
Chris@193
|
445 }
|
Chris@193
|
446 }
|
Chris@193
|
447
|
Chris@1238
|
448 double nx = getXForBin(v, bin0);
|
Chris@193
|
449
|
Chris@197
|
450 ColourMapper mapper(m_colourMap, 0, 1);
|
Chris@197
|
451
|
Chris@805
|
452 for (int bin = 0; bin < mh; ++bin) {
|
Chris@193
|
453
|
Chris@906
|
454 double x = nx;
|
Chris@1238
|
455 nx = getXForBin(v, bin + bin0 + 1);
|
Chris@193
|
456
|
Chris@906
|
457 double value = m_values[bin];
|
Chris@906
|
458 double norm = 0.0;
|
Chris@1238
|
459 double y = getYForValue(v, value, norm);
|
Chris@133
|
460
|
Chris@193
|
461 if (m_plotStyle == PlotLines) {
|
Chris@193
|
462
|
Chris@193
|
463 if (bin == 0) {
|
Chris@1233
|
464 path.moveTo((x + nx) / 2, y);
|
Chris@193
|
465 } else {
|
Chris@1233
|
466 path.lineTo((x + nx) / 2, y);
|
Chris@193
|
467 }
|
Chris@193
|
468
|
Chris@193
|
469 } else if (m_plotStyle == PlotSteps) {
|
Chris@193
|
470
|
Chris@193
|
471 if (bin == 0) {
|
Chris@193
|
472 path.moveTo(x, y);
|
Chris@193
|
473 } else {
|
Chris@193
|
474 path.lineTo(x, y);
|
Chris@193
|
475 }
|
Chris@193
|
476 path.lineTo(nx, y);
|
Chris@193
|
477
|
Chris@193
|
478 } else if (m_plotStyle == PlotBlocks) {
|
Chris@193
|
479
|
Chris@193
|
480 path.moveTo(x, yorigin);
|
Chris@133
|
481 path.lineTo(x, y);
|
Chris@193
|
482 path.lineTo(nx, y);
|
Chris@193
|
483 path.lineTo(nx, yorigin);
|
Chris@193
|
484 path.lineTo(x, yorigin);
|
Chris@197
|
485
|
Chris@197
|
486 } else if (m_plotStyle == PlotFilledBlocks) {
|
Chris@197
|
487
|
Chris@197
|
488 paint.fillRect(QRectF(x, y, nx - x, yorigin - y), mapper.map(norm));
|
Chris@133
|
489 }
|
Chris@193
|
490
|
Chris@133
|
491 }
|
Chris@133
|
492
|
Chris@197
|
493 if (m_plotStyle != PlotFilledBlocks) {
|
Chris@197
|
494 paint.drawPath(path);
|
Chris@197
|
495 }
|
Chris@133
|
496 paint.restore();
|
Chris@195
|
497 }
|
Chris@195
|
498
|
Chris@195
|
499 int
|
Chris@918
|
500 SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
|
Chris@195
|
501 {
|
Chris@1238
|
502 int width;
|
Chris@538
|
503 if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) {
|
Chris@1238
|
504 width = std::max(paint.fontMetrics().width("0.0") + 13,
|
Chris@1238
|
505 paint.fontMetrics().width("x10-10"));
|
Chris@195
|
506 } else {
|
Chris@1238
|
507 width = std::max(paint.fontMetrics().width(tr("0dB")),
|
Chris@1238
|
508 paint.fontMetrics().width(tr("-Inf"))) + 13;
|
Chris@195
|
509 }
|
Chris@1238
|
510 return width;
|
Chris@195
|
511 }
|
Chris@195
|
512
|
Chris@195
|
513 void
|
Chris@918
|
514 SliceLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
|
Chris@195
|
515 {
|
Chris@906
|
516 double thresh = m_threshold;
|
Chris@538
|
517 if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) {
|
Chris@284
|
518 thresh = AudioLevel::dB_to_multiplier(getThresholdDb());
|
Chris@195
|
519 }
|
Chris@195
|
520
|
Chris@195
|
521 // int h = (rect.height() * 3) / 4;
|
Chris@195
|
522 // int y = (rect.height() / 2) - (h / 2);
|
Chris@195
|
523
|
Chris@918
|
524 int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 6;
|
Chris@195
|
525 int h = yorigin - paint.fontMetrics().height() - 8;
|
Chris@195
|
526 if (h < 0) return;
|
Chris@195
|
527
|
Chris@195
|
528 QRect actual(rect.x(), rect.y() + yorigin - h, rect.width(), h);
|
Chris@195
|
529
|
Chris@220
|
530 int mult = 1;
|
Chris@220
|
531
|
Chris@195
|
532 PaintAssistant::paintVerticalLevelScale
|
Chris@195
|
533 (paint, actual, thresh, 1.0 / m_gain,
|
Chris@195
|
534 PaintAssistant::Scale(m_energyScale),
|
Chris@220
|
535 mult,
|
Chris@195
|
536 const_cast<std::vector<int> *>(&m_scalePoints));
|
Chris@220
|
537
|
Chris@220
|
538 if (mult != 1 && mult != 0) {
|
Chris@906
|
539 int log = int(lrint(log10(mult)));
|
Chris@220
|
540 QString a = tr("x10");
|
Chris@220
|
541 QString b = QString("%1").arg(-log);
|
Chris@220
|
542 paint.drawText(3, 8 + paint.fontMetrics().ascent(), a);
|
Chris@220
|
543 paint.drawText(3 + paint.fontMetrics().width(a),
|
Chris@220
|
544 3 + paint.fontMetrics().ascent(), b);
|
Chris@220
|
545 }
|
Chris@133
|
546 }
|
Chris@133
|
547
|
Chris@153
|
548 Layer::PropertyList
|
Chris@193
|
549 SliceLayer::getProperties() const
|
Chris@153
|
550 {
|
Chris@287
|
551 PropertyList list = SingleColourLayer::getProperties();
|
Chris@538
|
552 list.push_back("Bin Scale");
|
Chris@193
|
553 list.push_back("Plot Type");
|
Chris@153
|
554 list.push_back("Scale");
|
Chris@153
|
555 list.push_back("Normalize");
|
Chris@284
|
556 list.push_back("Threshold");
|
Chris@153
|
557 list.push_back("Gain");
|
Chris@153
|
558
|
Chris@153
|
559 return list;
|
Chris@153
|
560 }
|
Chris@153
|
561
|
Chris@153
|
562 QString
|
Chris@193
|
563 SliceLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@153
|
564 {
|
Chris@193
|
565 if (name == "Plot Type") return tr("Plot Type");
|
Chris@290
|
566 if (name == "Scale") return tr("Scale");
|
Chris@153
|
567 if (name == "Normalize") return tr("Normalize");
|
Chris@284
|
568 if (name == "Threshold") return tr("Threshold");
|
Chris@153
|
569 if (name == "Gain") return tr("Gain");
|
Chris@193
|
570 if (name == "Sampling Mode") return tr("Sampling Mode");
|
Chris@538
|
571 if (name == "Bin Scale") return tr("Bin Scale");
|
Chris@287
|
572 return SingleColourLayer::getPropertyLabel(name);
|
Chris@153
|
573 }
|
Chris@153
|
574
|
Chris@335
|
575 QString
|
Chris@335
|
576 SliceLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@335
|
577 {
|
Chris@335
|
578 if (name == "Normalize") return "normalise";
|
Chris@335
|
579 return "";
|
Chris@335
|
580 }
|
Chris@335
|
581
|
Chris@153
|
582 Layer::PropertyType
|
Chris@193
|
583 SliceLayer::getPropertyType(const PropertyName &name) const
|
Chris@153
|
584 {
|
Chris@153
|
585 if (name == "Gain") return RangeProperty;
|
Chris@153
|
586 if (name == "Normalize") return ToggleProperty;
|
Chris@284
|
587 if (name == "Threshold") return RangeProperty;
|
Chris@287
|
588 if (name == "Plot Type") return ValueProperty;
|
Chris@290
|
589 if (name == "Scale") return ValueProperty;
|
Chris@287
|
590 if (name == "Sampling Mode") return ValueProperty;
|
Chris@287
|
591 if (name == "Bin Scale") return ValueProperty;
|
Chris@287
|
592 if (name == "Colour" && m_plotStyle == PlotFilledBlocks) return ValueProperty;
|
Chris@287
|
593 return SingleColourLayer::getPropertyType(name);
|
Chris@153
|
594 }
|
Chris@153
|
595
|
Chris@153
|
596 QString
|
Chris@193
|
597 SliceLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@153
|
598 {
|
Chris@153
|
599 if (name == "Scale" ||
|
Chris@153
|
600 name == "Normalize" ||
|
Chris@193
|
601 name == "Sampling Mode" ||
|
Chris@284
|
602 name == "Threshold" ||
|
Chris@193
|
603 name == "Gain") return tr("Scale");
|
Chris@193
|
604 if (name == "Plot Type" ||
|
Chris@538
|
605 name == "Bin Scale") return tr("Bins");
|
Chris@287
|
606 return SingleColourLayer::getPropertyGroupName(name);
|
Chris@153
|
607 }
|
Chris@153
|
608
|
Chris@153
|
609 int
|
Chris@193
|
610 SliceLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
611 int *min, int *max, int *deflt) const
|
Chris@153
|
612 {
|
Chris@216
|
613 int val = 0;
|
Chris@153
|
614
|
Chris@216
|
615 int garbage0, garbage1, garbage2;
|
Chris@153
|
616 if (!min) min = &garbage0;
|
Chris@153
|
617 if (!max) max = &garbage1;
|
Chris@248
|
618 if (!deflt) deflt = &garbage2;
|
Chris@153
|
619
|
Chris@153
|
620 if (name == "Gain") {
|
Chris@153
|
621
|
Chris@153
|
622 *min = -50;
|
Chris@153
|
623 *max = 50;
|
Chris@216
|
624 *deflt = 0;
|
Chris@153
|
625
|
Chris@1238
|
626 // cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl;
|
Chris@193
|
627
|
Chris@906
|
628 val = int(lrint(log10(m_gain) * 20.0));
|
Chris@216
|
629 if (val < *min) val = *min;
|
Chris@216
|
630 if (val > *max) val = *max;
|
Chris@153
|
631
|
Chris@284
|
632 } else if (name == "Threshold") {
|
Chris@284
|
633
|
Chris@284
|
634 *min = -80;
|
Chris@284
|
635 *max = 0;
|
Chris@284
|
636
|
Chris@906
|
637 *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold)));
|
Chris@284
|
638 if (*deflt < *min) *deflt = *min;
|
Chris@284
|
639 if (*deflt > *max) *deflt = *max;
|
Chris@284
|
640
|
Chris@906
|
641 val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold)));
|
Chris@284
|
642 if (val < *min) val = *min;
|
Chris@284
|
643 if (val > *max) val = *max;
|
Chris@284
|
644
|
Chris@153
|
645 } else if (name == "Normalize") {
|
Chris@153
|
646
|
Chris@216
|
647 val = (m_normalize ? 1 : 0);
|
Chris@216
|
648 *deflt = 0;
|
Chris@153
|
649
|
Chris@287
|
650 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
|
Chris@197
|
651
|
Chris@287
|
652 *min = 0;
|
Chris@287
|
653 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@287
|
654 *deflt = 0;
|
Chris@287
|
655
|
Chris@287
|
656 val = m_colourMap;
|
Chris@153
|
657
|
Chris@153
|
658 } else if (name == "Scale") {
|
Chris@153
|
659
|
Chris@153
|
660 *min = 0;
|
Chris@538
|
661 *max = 3;
|
Chris@216
|
662 *deflt = (int)dBScale;
|
Chris@153
|
663
|
Chris@216
|
664 val = (int)m_energyScale;
|
Chris@153
|
665
|
Chris@193
|
666 } else if (name == "Sampling Mode") {
|
Chris@153
|
667
|
Chris@153
|
668 *min = 0;
|
Chris@193
|
669 *max = 2;
|
Chris@216
|
670 *deflt = (int)SampleMean;
|
Chris@193
|
671
|
Chris@216
|
672 val = (int)m_samplingMode;
|
Chris@153
|
673
|
Chris@193
|
674 } else if (name == "Plot Type") {
|
Chris@193
|
675
|
Chris@193
|
676 *min = 0;
|
Chris@197
|
677 *max = 3;
|
Chris@216
|
678 *deflt = (int)PlotSteps;
|
Chris@193
|
679
|
Chris@216
|
680 val = (int)m_plotStyle;
|
Chris@193
|
681
|
Chris@193
|
682 } else if (name == "Bin Scale") {
|
Chris@193
|
683
|
Chris@193
|
684 *min = 0;
|
Chris@198
|
685 *max = 2;
|
Chris@216
|
686 *deflt = (int)LinearBins;
|
Chris@198
|
687 // *max = 1; // I don't think we really do want to offer inverted log
|
Chris@193
|
688
|
Chris@216
|
689 val = (int)m_binScale;
|
Chris@193
|
690
|
Chris@153
|
691 } else {
|
Chris@287
|
692 val = SingleColourLayer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@153
|
693 }
|
Chris@153
|
694
|
Chris@216
|
695 return val;
|
Chris@153
|
696 }
|
Chris@153
|
697
|
Chris@153
|
698 QString
|
Chris@193
|
699 SliceLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@153
|
700 int value) const
|
Chris@153
|
701 {
|
Chris@287
|
702 if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
|
Chris@287
|
703 return ColourMapper::getColourMapName(value);
|
Chris@153
|
704 }
|
Chris@153
|
705 if (name == "Scale") {
|
Chris@153
|
706 switch (value) {
|
Chris@153
|
707 default:
|
Chris@153
|
708 case 0: return tr("Linear");
|
Chris@153
|
709 case 1: return tr("Meter");
|
Chris@538
|
710 case 2: return tr("Log");
|
Chris@538
|
711 case 3: return tr("Absolute");
|
Chris@153
|
712 }
|
Chris@153
|
713 }
|
Chris@193
|
714 if (name == "Sampling Mode") {
|
Chris@153
|
715 switch (value) {
|
Chris@153
|
716 default:
|
Chris@193
|
717 case 0: return tr("Any");
|
Chris@193
|
718 case 1: return tr("Mean");
|
Chris@193
|
719 case 2: return tr("Peak");
|
Chris@193
|
720 }
|
Chris@193
|
721 }
|
Chris@193
|
722 if (name == "Plot Type") {
|
Chris@193
|
723 switch (value) {
|
Chris@193
|
724 default:
|
Chris@193
|
725 case 0: return tr("Lines");
|
Chris@193
|
726 case 1: return tr("Steps");
|
Chris@193
|
727 case 2: return tr("Blocks");
|
Chris@197
|
728 case 3: return tr("Colours");
|
Chris@193
|
729 }
|
Chris@193
|
730 }
|
Chris@193
|
731 if (name == "Bin Scale") {
|
Chris@193
|
732 switch (value) {
|
Chris@193
|
733 default:
|
Chris@538
|
734 case 0: return tr("Linear");
|
Chris@538
|
735 case 1: return tr("Log");
|
Chris@538
|
736 case 2: return tr("Rev Log");
|
Chris@153
|
737 }
|
Chris@153
|
738 }
|
Chris@287
|
739 return SingleColourLayer::getPropertyValueLabel(name, value);
|
Chris@153
|
740 }
|
Chris@153
|
741
|
Chris@167
|
742 RangeMapper *
|
Chris@193
|
743 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@167
|
744 {
|
Chris@167
|
745 if (name == "Gain") {
|
Chris@167
|
746 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@167
|
747 }
|
Chris@284
|
748 if (name == "Threshold") {
|
Chris@284
|
749 return new LinearRangeMapper(-80, 0, -80, 0, tr("dB"));
|
Chris@284
|
750 }
|
Chris@287
|
751 return SingleColourLayer::getNewPropertyRangeMapper(name);
|
Chris@167
|
752 }
|
Chris@167
|
753
|
Chris@133
|
754 void
|
Chris@193
|
755 SliceLayer::setProperty(const PropertyName &name, int value)
|
Chris@133
|
756 {
|
Chris@153
|
757 if (name == "Gain") {
|
Chris@906
|
758 setGain(powf(10, float(value)/20.0f));
|
Chris@284
|
759 } else if (name == "Threshold") {
|
Chris@906
|
760 if (value == -80) setThreshold(0.0f);
|
Chris@906
|
761 else setThreshold(float(AudioLevel::dB_to_multiplier(value)));
|
Chris@287
|
762 } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) {
|
Chris@287
|
763 setFillColourMap(value);
|
Chris@153
|
764 } else if (name == "Scale") {
|
Chris@153
|
765 switch (value) {
|
Chris@153
|
766 default:
|
Chris@153
|
767 case 0: setEnergyScale(LinearScale); break;
|
Chris@153
|
768 case 1: setEnergyScale(MeterScale); break;
|
Chris@153
|
769 case 2: setEnergyScale(dBScale); break;
|
Chris@538
|
770 case 3: setEnergyScale(AbsoluteScale); break;
|
Chris@153
|
771 }
|
Chris@193
|
772 } else if (name == "Plot Type") {
|
Chris@193
|
773 setPlotStyle(PlotStyle(value));
|
Chris@193
|
774 } else if (name == "Sampling Mode") {
|
Chris@193
|
775 switch (value) {
|
Chris@193
|
776 default:
|
Chris@193
|
777 case 0: setSamplingMode(NearestSample); break;
|
Chris@193
|
778 case 1: setSamplingMode(SampleMean); break;
|
Chris@193
|
779 case 2: setSamplingMode(SamplePeak); break;
|
Chris@193
|
780 }
|
Chris@193
|
781 } else if (name == "Bin Scale") {
|
Chris@193
|
782 switch (value) {
|
Chris@193
|
783 default:
|
Chris@193
|
784 case 0: setBinScale(LinearBins); break;
|
Chris@193
|
785 case 1: setBinScale(LogBins); break;
|
Chris@193
|
786 case 2: setBinScale(InvertedLogBins); break;
|
Chris@193
|
787 }
|
Chris@153
|
788 } else if (name == "Normalize") {
|
Chris@153
|
789 setNormalize(value ? true : false);
|
Chris@287
|
790 } else {
|
Chris@287
|
791 SingleColourLayer::setProperty(name, value);
|
Chris@153
|
792 }
|
Chris@153
|
793 }
|
Chris@153
|
794
|
Chris@153
|
795 void
|
Chris@197
|
796 SliceLayer::setFillColourMap(int map)
|
Chris@197
|
797 {
|
Chris@197
|
798 if (m_colourMap == map) return;
|
Chris@197
|
799 m_colourMap = map;
|
Chris@197
|
800 emit layerParametersChanged();
|
Chris@197
|
801 }
|
Chris@197
|
802
|
Chris@197
|
803 void
|
Chris@193
|
804 SliceLayer::setEnergyScale(EnergyScale scale)
|
Chris@153
|
805 {
|
Chris@153
|
806 if (m_energyScale == scale) return;
|
Chris@153
|
807 m_energyScale = scale;
|
Chris@153
|
808 emit layerParametersChanged();
|
Chris@153
|
809 }
|
Chris@153
|
810
|
Chris@153
|
811 void
|
Chris@193
|
812 SliceLayer::setSamplingMode(SamplingMode mode)
|
Chris@153
|
813 {
|
Chris@193
|
814 if (m_samplingMode == mode) return;
|
Chris@193
|
815 m_samplingMode = mode;
|
Chris@153
|
816 emit layerParametersChanged();
|
Chris@153
|
817 }
|
Chris@153
|
818
|
Chris@153
|
819 void
|
Chris@193
|
820 SliceLayer::setPlotStyle(PlotStyle style)
|
Chris@153
|
821 {
|
Chris@193
|
822 if (m_plotStyle == style) return;
|
Chris@197
|
823 bool colourTypeChanged = (style == PlotFilledBlocks ||
|
Chris@197
|
824 m_plotStyle == PlotFilledBlocks);
|
Chris@193
|
825 m_plotStyle = style;
|
Chris@197
|
826 if (colourTypeChanged) {
|
Chris@197
|
827 emit layerParameterRangesChanged();
|
Chris@197
|
828 }
|
Chris@153
|
829 emit layerParametersChanged();
|
Chris@153
|
830 }
|
Chris@153
|
831
|
Chris@153
|
832 void
|
Chris@193
|
833 SliceLayer::setBinScale(BinScale scale)
|
Chris@153
|
834 {
|
Chris@193
|
835 if (m_binScale == scale) return;
|
Chris@193
|
836 m_binScale = scale;
|
Chris@153
|
837 emit layerParametersChanged();
|
Chris@153
|
838 }
|
Chris@153
|
839
|
Chris@153
|
840 void
|
Chris@193
|
841 SliceLayer::setNormalize(bool n)
|
Chris@153
|
842 {
|
Chris@153
|
843 if (m_normalize == n) return;
|
Chris@153
|
844 m_normalize = n;
|
Chris@153
|
845 emit layerParametersChanged();
|
Chris@153
|
846 }
|
Chris@153
|
847
|
Chris@153
|
848 void
|
Chris@284
|
849 SliceLayer::setThreshold(float thresh)
|
Chris@284
|
850 {
|
Chris@284
|
851 if (m_threshold == thresh) return;
|
Chris@284
|
852 m_threshold = thresh;
|
Chris@284
|
853 emit layerParametersChanged();
|
Chris@284
|
854 }
|
Chris@284
|
855
|
Chris@284
|
856 void
|
Chris@193
|
857 SliceLayer::setGain(float gain)
|
Chris@153
|
858 {
|
Chris@153
|
859 if (m_gain == gain) return;
|
Chris@153
|
860 m_gain = gain;
|
Chris@153
|
861 emit layerParametersChanged();
|
Chris@153
|
862 }
|
Chris@153
|
863
|
Chris@284
|
864 float
|
Chris@284
|
865 SliceLayer::getThresholdDb() const
|
Chris@284
|
866 {
|
Chris@284
|
867 if (m_threshold == 0.0) return -80.f;
|
Chris@906
|
868 float db = float(AudioLevel::multiplier_to_dB(m_threshold));
|
Chris@284
|
869 return db;
|
Chris@284
|
870 }
|
Chris@284
|
871
|
Chris@287
|
872 int
|
Chris@287
|
873 SliceLayer::getDefaultColourHint(bool darkbg, bool &impose)
|
Chris@287
|
874 {
|
Chris@287
|
875 impose = false;
|
Chris@287
|
876 return ColourDatabase::getInstance()->getColourIndex
|
Chris@287
|
877 (QString(darkbg ? "Bright Blue" : "Blue"));
|
Chris@287
|
878 }
|
Chris@287
|
879
|
Chris@316
|
880 void
|
Chris@316
|
881 SliceLayer::toXml(QTextStream &stream,
|
Chris@316
|
882 QString indent, QString extraAttributes) const
|
Chris@153
|
883 {
|
Chris@153
|
884 QString s;
|
Chris@153
|
885
|
Chris@287
|
886 s += QString("colourScheme=\"%1\" "
|
Chris@287
|
887 "energyScale=\"%2\" "
|
Chris@287
|
888 "samplingMode=\"%3\" "
|
Chris@598
|
889 "plotStyle=\"%4\" "
|
Chris@598
|
890 "binScale=\"%5\" "
|
Chris@598
|
891 "gain=\"%6\" "
|
Chris@598
|
892 "threshold=\"%7\" "
|
Chris@1238
|
893 "normalize=\"%8\" %9")
|
Chris@197
|
894 .arg(m_colourMap)
|
Chris@153
|
895 .arg(m_energyScale)
|
Chris@193
|
896 .arg(m_samplingMode)
|
Chris@598
|
897 .arg(m_plotStyle)
|
Chris@598
|
898 .arg(m_binScale)
|
Chris@153
|
899 .arg(m_gain)
|
Chris@598
|
900 .arg(m_threshold)
|
Chris@1238
|
901 .arg(m_normalize ? "true" : "false")
|
Chris@1238
|
902 .arg(QString("minbin=\"%1\" "
|
Chris@1238
|
903 "maxbin=\"%2\"")
|
Chris@1238
|
904 .arg(m_minbin)
|
Chris@1238
|
905 .arg(m_maxbin));
|
Chris@153
|
906
|
Chris@316
|
907 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@153
|
908 }
|
Chris@153
|
909
|
Chris@153
|
910 void
|
Chris@193
|
911 SliceLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@153
|
912 {
|
Chris@153
|
913 bool ok = false;
|
Chris@153
|
914
|
Chris@287
|
915 SingleColourLayer::setProperties(attributes);
|
Chris@153
|
916
|
Chris@153
|
917 EnergyScale scale = (EnergyScale)
|
Chris@153
|
918 attributes.value("energyScale").toInt(&ok);
|
Chris@153
|
919 if (ok) setEnergyScale(scale);
|
Chris@153
|
920
|
Chris@193
|
921 SamplingMode mode = (SamplingMode)
|
Chris@193
|
922 attributes.value("samplingMode").toInt(&ok);
|
Chris@193
|
923 if (ok) setSamplingMode(mode);
|
Chris@153
|
924
|
Chris@197
|
925 int colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@197
|
926 if (ok) setFillColourMap(colourMap);
|
Chris@197
|
927
|
Chris@598
|
928 PlotStyle s = (PlotStyle)
|
Chris@598
|
929 attributes.value("plotStyle").toInt(&ok);
|
Chris@598
|
930 if (ok) setPlotStyle(s);
|
Chris@598
|
931
|
Chris@598
|
932 BinScale b = (BinScale)
|
Chris@598
|
933 attributes.value("binScale").toInt(&ok);
|
Chris@598
|
934 if (ok) setBinScale(b);
|
Chris@598
|
935
|
Chris@153
|
936 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@153
|
937 if (ok) setGain(gain);
|
Chris@153
|
938
|
Chris@598
|
939 float threshold = attributes.value("threshold").toFloat(&ok);
|
Chris@598
|
940 if (ok) setThreshold(threshold);
|
Chris@598
|
941
|
Chris@153
|
942 bool normalize = (attributes.value("normalize").trimmed() == "true");
|
Chris@153
|
943 setNormalize(normalize);
|
Chris@1238
|
944
|
Chris@1238
|
945 bool alsoOk = false;
|
Chris@1238
|
946
|
Chris@1238
|
947 float min = attributes.value("minbin").toFloat(&ok);
|
Chris@1238
|
948 float max = attributes.value("maxbin").toFloat(&alsoOk);
|
Chris@1238
|
949 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@133
|
950 }
|
Chris@133
|
951
|
Chris@133
|
952 bool
|
Chris@1238
|
953 SliceLayer::getValueExtents(double &min, double &max, bool &logarithmic,
|
Chris@1238
|
954 QString &unit) const
|
Chris@133
|
955 {
|
Chris@1238
|
956 if (!m_sliceableModel) return false;
|
Chris@1238
|
957
|
Chris@1238
|
958 min = 0;
|
Chris@1238
|
959 max = double(m_sliceableModel->getHeight());
|
Chris@1238
|
960
|
Chris@1238
|
961 logarithmic = (m_binScale == BinScale::LogBins);
|
Chris@1238
|
962 unit = "";
|
Chris@1238
|
963
|
Chris@1238
|
964 return true;
|
Chris@133
|
965 }
|
Chris@133
|
966
|
Chris@1238
|
967 bool
|
Chris@1238
|
968 SliceLayer::getDisplayExtents(double &min, double &max) const
|
Chris@1238
|
969 {
|
Chris@1238
|
970 if (!m_sliceableModel) return false;
|
Chris@1238
|
971
|
Chris@1238
|
972 double hmax = double(m_sliceableModel->getHeight());
|
Chris@1238
|
973
|
Chris@1238
|
974 min = m_minbin;
|
Chris@1238
|
975 max = m_maxbin;
|
Chris@1238
|
976 if (max <= min) {
|
Chris@1238
|
977 min = 0;
|
Chris@1238
|
978 max = hmax;
|
Chris@1238
|
979 }
|
Chris@1238
|
980 if (min < 0) min = 0;
|
Chris@1238
|
981 if (max > hmax) max = hmax;
|
Chris@1238
|
982
|
Chris@1238
|
983 return true;
|
Chris@1238
|
984 }
|
Chris@1238
|
985
|
Chris@1238
|
986 bool
|
Chris@1238
|
987 SliceLayer::setDisplayExtents(double min, double max)
|
Chris@1238
|
988 {
|
Chris@1238
|
989 if (!m_sliceableModel) return false;
|
Chris@1238
|
990
|
Chris@1238
|
991 m_minbin = int(lrint(min));
|
Chris@1238
|
992 m_maxbin = int(lrint(max));
|
Chris@1238
|
993
|
Chris@1238
|
994 emit layerParametersChanged();
|
Chris@1238
|
995 return true;
|
Chris@1238
|
996 }
|
Chris@1238
|
997
|
Chris@1238
|
998 int
|
Chris@1238
|
999 SliceLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@1238
|
1000 {
|
Chris@1238
|
1001 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1002
|
Chris@1238
|
1003 defaultStep = 0;
|
Chris@1238
|
1004 int h = m_sliceableModel->getHeight();
|
Chris@1238
|
1005 return h;
|
Chris@1238
|
1006 }
|
Chris@1238
|
1007
|
Chris@1238
|
1008 int
|
Chris@1238
|
1009 SliceLayer::getCurrentVerticalZoomStep() const
|
Chris@1238
|
1010 {
|
Chris@1238
|
1011 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1012
|
Chris@1238
|
1013 double min, max;
|
Chris@1238
|
1014 getDisplayExtents(min, max);
|
Chris@1238
|
1015 return m_sliceableModel->getHeight() - int(lrint(max - min));
|
Chris@1238
|
1016 }
|
Chris@1238
|
1017
|
Chris@1238
|
1018 void
|
Chris@1238
|
1019 SliceLayer::setVerticalZoomStep(int step)
|
Chris@1238
|
1020 {
|
Chris@1238
|
1021 if (!m_sliceableModel) return;
|
Chris@1238
|
1022
|
Chris@1238
|
1023 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): before: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
|
Chris@1238
|
1024
|
Chris@1238
|
1025 int dist = m_sliceableModel->getHeight() - step;
|
Chris@1238
|
1026 if (dist < 1) dist = 1;
|
Chris@1238
|
1027 double centre = m_minbin + (m_maxbin - m_minbin) / 2.0;
|
Chris@1238
|
1028 m_minbin = int(lrint(centre - dist/2.0));
|
Chris@1238
|
1029 if (m_minbin < 0) m_minbin = 0;
|
Chris@1238
|
1030 m_maxbin = m_minbin + dist;
|
Chris@1238
|
1031 if (m_maxbin > m_sliceableModel->getHeight()) m_maxbin = m_sliceableModel->getHeight();
|
Chris@1238
|
1032
|
Chris@1238
|
1033 // SVDEBUG << "SliceLayer::setVerticalZoomStep(" <<step <<"): after: minbin = " << m_minbin << ", maxbin = " << m_maxbin << endl;
|
Chris@1238
|
1034
|
Chris@1238
|
1035 emit layerParametersChanged();
|
Chris@1238
|
1036 }
|
Chris@1238
|
1037
|
Chris@1238
|
1038 RangeMapper *
|
Chris@1238
|
1039 SliceLayer::getNewVerticalZoomRangeMapper() const
|
Chris@1238
|
1040 {
|
Chris@1238
|
1041 if (!m_sliceableModel) return 0;
|
Chris@1238
|
1042
|
Chris@1238
|
1043 return new LinearRangeMapper(0, m_sliceableModel->getHeight(),
|
Chris@1238
|
1044 0, m_sliceableModel->getHeight(), "");
|
Chris@1238
|
1045 }
|