Chris@133
|
1
|
Chris@133
|
2 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@133
|
3
|
Chris@133
|
4 /*
|
Chris@133
|
5 Sonic Visualiser
|
Chris@133
|
6 An audio file viewer and annotation editor.
|
Chris@133
|
7 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
8 This file copyright 2006 QMUL.
|
Chris@133
|
9
|
Chris@133
|
10 This program is free software; you can redistribute it and/or
|
Chris@133
|
11 modify it under the terms of the GNU General Public License as
|
Chris@133
|
12 published by the Free Software Foundation; either version 2 of the
|
Chris@133
|
13 License, or (at your option) any later version. See the file
|
Chris@133
|
14 COPYING included with this distribution for more information.
|
Chris@133
|
15 */
|
Chris@133
|
16
|
Chris@193
|
17 #include "SliceLayer.h"
|
Chris@133
|
18
|
Chris@133
|
19 #include "view/View.h"
|
Chris@153
|
20 #include "base/AudioLevel.h"
|
Chris@167
|
21 #include "base/RangeMapper.h"
|
Chris@133
|
22
|
Chris@133
|
23 #include <QPainter>
|
Chris@133
|
24 #include <QPainterPath>
|
Chris@133
|
25
|
Chris@193
|
26 SliceLayer::SliceLayer() :
|
Chris@193
|
27 m_sliceableModel(0),
|
Chris@153
|
28 m_colour(Qt::darkBlue),
|
Chris@153
|
29 m_energyScale(dBScale),
|
Chris@193
|
30 m_samplingMode(SamplePeak),
|
Chris@193
|
31 m_plotStyle(PlotLines),
|
Chris@193
|
32 m_binScale(LinearBins),
|
Chris@153
|
33 m_normalize(false),
|
Chris@193
|
34 m_bias(false);
|
Chris@193
|
35 m_gain(1.0)
|
Chris@133
|
36 {
|
Chris@133
|
37 }
|
Chris@133
|
38
|
Chris@193
|
39 SliceLayer::~SliceLayer()
|
Chris@133
|
40 {
|
Chris@193
|
41
|
Chris@133
|
42 }
|
Chris@133
|
43
|
Chris@133
|
44 void
|
Chris@193
|
45 SliceLayer::setSliceableModel(const Model *model)
|
Chris@133
|
46 {
|
Chris@193
|
47 const DenseThreeDimensionalModel *sliceable =
|
Chris@193
|
48 dynamic_cast<const DenseThreeDimensionalModel *>(model);
|
Chris@193
|
49
|
Chris@193
|
50 if (model && !sliceable) {
|
Chris@193
|
51 std::cerr << "WARNING: SliceLayer::setSliceableModel(" << model
|
Chris@193
|
52 << "): model is not a DenseThreeDimensionalModel" << std::endl;
|
Chris@193
|
53 }
|
Chris@193
|
54
|
Chris@193
|
55 if (m_sliceableModel == sliceable) return;
|
Chris@193
|
56
|
Chris@193
|
57 m_sliceableModel = sliceable;
|
Chris@193
|
58
|
Chris@193
|
59 connect(m_sliceableModel, SIGNAL(modelChanged()),
|
Chris@193
|
60 this, SIGNAL(modelChanged()));
|
Chris@193
|
61
|
Chris@193
|
62 connect(m_sliceableModel, SIGNAL(modelChanged(size_t, size_t)),
|
Chris@193
|
63 this, SIGNAL(modelChanged(size_t, size_t)));
|
Chris@193
|
64
|
Chris@193
|
65 connect(m_sliceableModel, SIGNAL(completionChanged()),
|
Chris@193
|
66 this, SIGNAL(modelCompletionChanged()));
|
Chris@193
|
67
|
Chris@193
|
68 emit modelReplaced();
|
Chris@153
|
69 }
|
Chris@153
|
70
|
Chris@153
|
71 void
|
Chris@193
|
72 SliceLayer::sliceableModelReplaced(const Model *orig, const Model *replacement)
|
Chris@153
|
73 {
|
Chris@193
|
74 std::cerr << "SliceLayer::sliceableModelReplaced(" << orig << ", " << replacement << ")" << std::endl;
|
Chris@153
|
75
|
Chris@193
|
76 if (orig == m_sliceableModel) {
|
Chris@193
|
77 setSliceableModel
|
Chris@193
|
78 (dynamic_cast<const DenseThreeDimensionalModel *>(replacement));
|
Chris@153
|
79 }
|
Chris@153
|
80 }
|
Chris@153
|
81
|
Chris@153
|
82 void
|
Chris@193
|
83 SliceLayer::modelAboutToBeDeleted(Model *m)
|
Chris@153
|
84 {
|
Chris@193
|
85 std::cerr << "SliceLayer::modelAboutToBeDeleted(" << m << ")" << std::endl;
|
Chris@153
|
86
|
Chris@193
|
87 if (m == m_sliceableModel) {
|
Chris@193
|
88 setSliceableModel(0);
|
Chris@153
|
89 }
|
Chris@133
|
90 }
|
Chris@133
|
91
|
Chris@133
|
92 void
|
Chris@193
|
93 SliceLayer::paint(View *v, QPainter &paint, QRect rect) const
|
Chris@133
|
94 {
|
Chris@193
|
95 if (!m_sliceableModel) return;
|
Chris@133
|
96
|
Chris@133
|
97 int w = (v->width() * 2) / 3;
|
Chris@133
|
98 int xorigin = (v->width() / 2) - (w / 2);
|
Chris@133
|
99
|
Chris@133
|
100 int h = (v->height() * 2) / 3;
|
Chris@133
|
101 int yorigin = (v->height() / 2) + (h / 2);
|
Chris@133
|
102
|
Chris@133
|
103 paint.save();
|
Chris@133
|
104 paint.setPen(m_colour);
|
Chris@133
|
105 paint.setRenderHint(QPainter::Antialiasing, false);
|
Chris@133
|
106
|
Chris@133
|
107 QPainterPath path;
|
Chris@133
|
108 float thresh = -80.f;
|
Chris@133
|
109
|
Chris@193
|
110 int mh = m_sliceableModel->getHeight();
|
Chris@133
|
111
|
Chris@193
|
112 float *values = new float[mh];
|
Chris@193
|
113 int divisor = 0;
|
Chris@193
|
114
|
Chris@193
|
115 for (size_t bin = 0; bin < mh; ++bin) {
|
Chris@193
|
116 values[bin] = 0.f;
|
Chris@193
|
117 }
|
Chris@193
|
118
|
Chris@193
|
119 size_t f0 = v->getCentreFrame();
|
Chris@193
|
120 int f0x = v->getXForFrame(f0);
|
Chris@193
|
121 size_t f1 = v->getFrameForX(f0x + 1);
|
Chris@193
|
122
|
Chris@193
|
123 size_t col0 = f0 / m_sliceableModel->getResolution();
|
Chris@193
|
124 size_t col1 = col0;
|
Chris@193
|
125 if (m_samplingMode != NearestSample) {
|
Chris@193
|
126 col1 = f1 / m_sliceableModel->getResolution();
|
Chris@193
|
127 }
|
Chris@193
|
128 if (col1 <= col0) col1 = col0 + 1;
|
Chris@193
|
129
|
Chris@193
|
130 for (size_t col = col0; col < col1; ++col) {
|
Chris@193
|
131 for (size_t bin = 0; bin < mh; ++bin) {
|
Chris@193
|
132 float value = m_sliceableModel->getValueAt(col, bin);
|
Chris@193
|
133 if (m_bias) value *= bin + 1;
|
Chris@193
|
134 if (m_samplingMode == SamplePeak) {
|
Chris@193
|
135 if (value > values[bin]) values[bin] = value;
|
Chris@193
|
136 } else {
|
Chris@193
|
137 values[bin] += value;
|
Chris@193
|
138 }
|
Chris@153
|
139 }
|
Chris@193
|
140 ++divisor;
|
Chris@193
|
141 }
|
Chris@193
|
142
|
Chris@193
|
143 float max = 0.f;
|
Chris@193
|
144 for (size_t bin = 0; bin < mh; ++bin) {
|
Chris@193
|
145 if (m_samplingMode == SampleMean) values[bin] /= divisor;
|
Chris@193
|
146 if (values[bin] > max) max = values[bin];
|
Chris@193
|
147 }
|
Chris@193
|
148 if (max != 0.f && m_normalize) {
|
Chris@193
|
149 for (size_t bin = 0; bin < mh; ++bin) {
|
Chris@193
|
150 values[bin] /= max;
|
Chris@193
|
151 }
|
Chris@193
|
152 }
|
Chris@193
|
153
|
Chris@193
|
154 float py = 0;
|
Chris@193
|
155 float nx = xorigin;
|
Chris@193
|
156
|
Chris@193
|
157 for (size_t bin = 0; bin < mh; ++bin) {
|
Chris@193
|
158
|
Chris@193
|
159 float x;
|
Chris@193
|
160
|
Chris@193
|
161 switch (m_binScale) {
|
Chris@193
|
162
|
Chris@193
|
163 case LinearBins:
|
Chris@193
|
164 x = nx;
|
Chris@193
|
165 nx = xorigin + (float(w) * (bin + 1)) / mh;
|
Chris@193
|
166 break;
|
Chris@193
|
167
|
Chris@193
|
168 case LogBins:
|
Chris@193
|
169 x = nx;
|
Chris@193
|
170 nx = xorigin + (float(w) * (log10f(bin + 2) - log10f(1))) /
|
Chris@193
|
171 (log10f(mh + 1) - log10f(1));
|
Chris@193
|
172 break;
|
Chris@193
|
173
|
Chris@193
|
174 case InvertedLogBins:
|
Chris@193
|
175 x = nx;
|
Chris@193
|
176 nx = xorigin + w - (float(w) * (log10f(mh - bin) - log10f(1))) /
|
Chris@193
|
177 (log10f(mh) - log10f(1));
|
Chris@193
|
178 break;
|
Chris@193
|
179 }
|
Chris@193
|
180
|
Chris@193
|
181 float value = values[bin];
|
Chris@193
|
182
|
Chris@193
|
183 value *= m_gain;
|
Chris@153
|
184 float y = 0.f;
|
Chris@153
|
185
|
Chris@153
|
186 switch (m_energyScale) {
|
Chris@153
|
187
|
Chris@153
|
188 case dBScale:
|
Chris@153
|
189 {
|
Chris@153
|
190 float db = thresh;
|
Chris@193
|
191 if (value > 0.f) db = 10.f * log10f(value);
|
Chris@153
|
192 if (db < thresh) db = thresh;
|
Chris@153
|
193 float val = (db - thresh) / -thresh;
|
Chris@153
|
194 y = yorigin - (float(h) * val);
|
Chris@153
|
195 break;
|
Chris@153
|
196 }
|
Chris@153
|
197
|
Chris@153
|
198 case MeterScale:
|
Chris@193
|
199 y = yorigin - AudioLevel::multiplier_to_preview(value, h);
|
Chris@153
|
200 break;
|
Chris@153
|
201
|
Chris@153
|
202 default:
|
Chris@193
|
203 y = yorigin - (float(h) * value);
|
Chris@153
|
204 break;
|
Chris@153
|
205 }
|
Chris@133
|
206
|
Chris@193
|
207 if (m_plotStyle == PlotLines) {
|
Chris@193
|
208
|
Chris@193
|
209 if (bin == 0) {
|
Chris@193
|
210 path.moveTo(x, y);
|
Chris@193
|
211 } else {
|
Chris@193
|
212 path.lineTo(x, y);
|
Chris@193
|
213 }
|
Chris@193
|
214
|
Chris@193
|
215 } else if (m_plotStyle == PlotSteps) {
|
Chris@193
|
216
|
Chris@193
|
217 if (bin == 0) {
|
Chris@193
|
218 path.moveTo(x, y);
|
Chris@193
|
219 } else {
|
Chris@193
|
220 path.lineTo(x, y);
|
Chris@193
|
221 }
|
Chris@193
|
222 path.lineTo(nx, y);
|
Chris@193
|
223
|
Chris@193
|
224 } else if (m_plotStyle == PlotBlocks) {
|
Chris@193
|
225
|
Chris@193
|
226 path.moveTo(x, yorigin);
|
Chris@133
|
227 path.lineTo(x, y);
|
Chris@193
|
228 path.lineTo(nx, y);
|
Chris@193
|
229 path.lineTo(nx, yorigin);
|
Chris@193
|
230 path.lineTo(x, yorigin);
|
Chris@133
|
231 }
|
Chris@193
|
232
|
Chris@193
|
233 py = y;
|
Chris@133
|
234 }
|
Chris@133
|
235
|
Chris@133
|
236 paint.drawPath(path);
|
Chris@133
|
237 paint.restore();
|
Chris@133
|
238
|
Chris@133
|
239 }
|
Chris@133
|
240
|
Chris@153
|
241 Layer::PropertyList
|
Chris@193
|
242 SliceLayer::getProperties() const
|
Chris@153
|
243 {
|
Chris@153
|
244 PropertyList list;
|
Chris@153
|
245 list.push_back("Colour");
|
Chris@193
|
246 list.push_back("Plot Type");
|
Chris@193
|
247 list.push_back("Sampling Mode");
|
Chris@153
|
248 list.push_back("Scale");
|
Chris@153
|
249 list.push_back("Normalize");
|
Chris@153
|
250 list.push_back("Gain");
|
Chris@193
|
251 list.push_back("Bin Scale");
|
Chris@153
|
252
|
Chris@153
|
253 return list;
|
Chris@153
|
254 }
|
Chris@153
|
255
|
Chris@153
|
256 QString
|
Chris@193
|
257 SliceLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@153
|
258 {
|
Chris@153
|
259 if (name == "Colour") return tr("Colour");
|
Chris@193
|
260 if (name == "Plot Type") return tr("Plot Type");
|
Chris@153
|
261 if (name == "Energy Scale") return tr("Scale");
|
Chris@153
|
262 if (name == "Normalize") return tr("Normalize");
|
Chris@153
|
263 if (name == "Gain") return tr("Gain");
|
Chris@193
|
264 if (name == "Sampling Mode") return tr("Sampling Mode");
|
Chris@193
|
265 if (name == "Bin Scale") return tr("Plot X Scale");
|
Chris@153
|
266 return "";
|
Chris@153
|
267 }
|
Chris@153
|
268
|
Chris@153
|
269 Layer::PropertyType
|
Chris@193
|
270 SliceLayer::getPropertyType(const PropertyName &name) const
|
Chris@153
|
271 {
|
Chris@153
|
272 if (name == "Gain") return RangeProperty;
|
Chris@153
|
273 if (name == "Normalize") return ToggleProperty;
|
Chris@153
|
274 return ValueProperty;
|
Chris@153
|
275 }
|
Chris@153
|
276
|
Chris@153
|
277 QString
|
Chris@193
|
278 SliceLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@153
|
279 {
|
Chris@153
|
280 if (name == "Scale" ||
|
Chris@153
|
281 name == "Normalize" ||
|
Chris@193
|
282 name == "Sampling Mode" ||
|
Chris@193
|
283 name == "Gain") return tr("Scale");
|
Chris@193
|
284 if (name == "Plot Type" ||
|
Chris@193
|
285 name == "Bin Scale") return tr("Plot Type");
|
Chris@153
|
286 return QString();
|
Chris@153
|
287 }
|
Chris@153
|
288
|
Chris@153
|
289 int
|
Chris@193
|
290 SliceLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@153
|
291 int *min, int *max) const
|
Chris@153
|
292 {
|
Chris@153
|
293 int deft = 0;
|
Chris@153
|
294
|
Chris@153
|
295 int garbage0, garbage1;
|
Chris@153
|
296 if (!min) min = &garbage0;
|
Chris@153
|
297 if (!max) max = &garbage1;
|
Chris@153
|
298
|
Chris@153
|
299 if (name == "Gain") {
|
Chris@153
|
300
|
Chris@153
|
301 *min = -50;
|
Chris@153
|
302 *max = 50;
|
Chris@153
|
303
|
Chris@193
|
304 std::cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << std::endl;
|
Chris@193
|
305
|
Chris@153
|
306 deft = lrint(log10(m_gain) * 20.0);
|
Chris@153
|
307 if (deft < *min) deft = *min;
|
Chris@153
|
308 if (deft > *max) deft = *max;
|
Chris@153
|
309
|
Chris@153
|
310 } else if (name == "Normalize") {
|
Chris@153
|
311
|
Chris@153
|
312 deft = (m_normalize ? 1 : 0);
|
Chris@153
|
313
|
Chris@153
|
314 } else if (name == "Colour") {
|
Chris@153
|
315
|
Chris@153
|
316 *min = 0;
|
Chris@153
|
317 *max = 5;
|
Chris@153
|
318
|
Chris@153
|
319 if (m_colour == Qt::black) deft = 0;
|
Chris@153
|
320 else if (m_colour == Qt::darkRed) deft = 1;
|
Chris@153
|
321 else if (m_colour == Qt::darkBlue) deft = 2;
|
Chris@153
|
322 else if (m_colour == Qt::darkGreen) deft = 3;
|
Chris@153
|
323 else if (m_colour == QColor(200, 50, 255)) deft = 4;
|
Chris@153
|
324 else if (m_colour == QColor(255, 150, 50)) deft = 5;
|
Chris@153
|
325
|
Chris@153
|
326 } else if (name == "Scale") {
|
Chris@153
|
327
|
Chris@153
|
328 *min = 0;
|
Chris@153
|
329 *max = 2;
|
Chris@153
|
330
|
Chris@153
|
331 deft = (int)m_energyScale;
|
Chris@153
|
332
|
Chris@193
|
333 } else if (name == "Sampling Mode") {
|
Chris@153
|
334
|
Chris@153
|
335 *min = 0;
|
Chris@193
|
336 *max = 2;
|
Chris@193
|
337
|
Chris@193
|
338 deft = (int)m_samplingMode;
|
Chris@153
|
339
|
Chris@193
|
340 } else if (name == "Plot Type") {
|
Chris@193
|
341
|
Chris@193
|
342 *min = 0;
|
Chris@193
|
343 *max = 2;
|
Chris@193
|
344
|
Chris@193
|
345 deft = (int)m_plotStyle;
|
Chris@193
|
346
|
Chris@193
|
347 } else if (name == "Bin Scale") {
|
Chris@193
|
348
|
Chris@193
|
349 *min = 0;
|
Chris@193
|
350 *max = 2;
|
Chris@193
|
351
|
Chris@193
|
352 deft = (int)m_binScale;
|
Chris@193
|
353
|
Chris@153
|
354 } else {
|
Chris@153
|
355 deft = Layer::getPropertyRangeAndValue(name, min, max);
|
Chris@153
|
356 }
|
Chris@153
|
357
|
Chris@153
|
358 return deft;
|
Chris@153
|
359 }
|
Chris@153
|
360
|
Chris@153
|
361 QString
|
Chris@193
|
362 SliceLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@153
|
363 int value) const
|
Chris@153
|
364 {
|
Chris@153
|
365 if (name == "Colour") {
|
Chris@153
|
366 switch (value) {
|
Chris@153
|
367 default:
|
Chris@153
|
368 case 0: return tr("Black");
|
Chris@153
|
369 case 1: return tr("Red");
|
Chris@153
|
370 case 2: return tr("Blue");
|
Chris@153
|
371 case 3: return tr("Green");
|
Chris@153
|
372 case 4: return tr("Purple");
|
Chris@153
|
373 case 5: return tr("Orange");
|
Chris@153
|
374 }
|
Chris@153
|
375 }
|
Chris@153
|
376 if (name == "Scale") {
|
Chris@153
|
377 switch (value) {
|
Chris@153
|
378 default:
|
Chris@153
|
379 case 0: return tr("Linear");
|
Chris@153
|
380 case 1: return tr("Meter");
|
Chris@153
|
381 case 2: return tr("dB");
|
Chris@153
|
382 }
|
Chris@153
|
383 }
|
Chris@193
|
384 if (name == "Sampling Mode") {
|
Chris@153
|
385 switch (value) {
|
Chris@153
|
386 default:
|
Chris@193
|
387 case 0: return tr("Any");
|
Chris@193
|
388 case 1: return tr("Mean");
|
Chris@193
|
389 case 2: return tr("Peak");
|
Chris@193
|
390 }
|
Chris@193
|
391 }
|
Chris@193
|
392 if (name == "Plot Type") {
|
Chris@193
|
393 switch (value) {
|
Chris@193
|
394 default:
|
Chris@193
|
395 case 0: return tr("Lines");
|
Chris@193
|
396 case 1: return tr("Steps");
|
Chris@193
|
397 case 2: return tr("Blocks");
|
Chris@193
|
398 }
|
Chris@193
|
399 }
|
Chris@193
|
400 if (name == "Bin Scale") {
|
Chris@193
|
401 switch (value) {
|
Chris@193
|
402 default:
|
Chris@193
|
403 case 0: return tr("Linear");
|
Chris@193
|
404 case 1: return tr("Log");
|
Chris@193
|
405 case 2: return tr("Rev Log");
|
Chris@153
|
406 }
|
Chris@153
|
407 }
|
Chris@153
|
408 return tr("<unknown>");
|
Chris@153
|
409 }
|
Chris@153
|
410
|
Chris@167
|
411 RangeMapper *
|
Chris@193
|
412 SliceLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@167
|
413 {
|
Chris@167
|
414 if (name == "Gain") {
|
Chris@167
|
415 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@167
|
416 }
|
Chris@167
|
417 return 0;
|
Chris@167
|
418 }
|
Chris@167
|
419
|
Chris@133
|
420 void
|
Chris@193
|
421 SliceLayer::setProperty(const PropertyName &name, int value)
|
Chris@133
|
422 {
|
Chris@153
|
423 if (name == "Gain") {
|
Chris@153
|
424 setGain(pow(10, float(value)/20.0));
|
Chris@153
|
425 } else if (name == "Colour") {
|
Chris@153
|
426 switch (value) {
|
Chris@153
|
427 default:
|
Chris@153
|
428 case 0: setBaseColour(Qt::black); break;
|
Chris@153
|
429 case 1: setBaseColour(Qt::darkRed); break;
|
Chris@153
|
430 case 2: setBaseColour(Qt::darkBlue); break;
|
Chris@153
|
431 case 3: setBaseColour(Qt::darkGreen); break;
|
Chris@153
|
432 case 4: setBaseColour(QColor(200, 50, 255)); break;
|
Chris@153
|
433 case 5: setBaseColour(QColor(255, 150, 50)); break;
|
Chris@153
|
434 }
|
Chris@153
|
435 } else if (name == "Scale") {
|
Chris@153
|
436 switch (value) {
|
Chris@153
|
437 default:
|
Chris@153
|
438 case 0: setEnergyScale(LinearScale); break;
|
Chris@153
|
439 case 1: setEnergyScale(MeterScale); break;
|
Chris@153
|
440 case 2: setEnergyScale(dBScale); break;
|
Chris@153
|
441 }
|
Chris@193
|
442 } else if (name == "Plot Type") {
|
Chris@193
|
443 setPlotStyle(PlotStyle(value));
|
Chris@193
|
444 } else if (name == "Sampling Mode") {
|
Chris@193
|
445 switch (value) {
|
Chris@193
|
446 default:
|
Chris@193
|
447 case 0: setSamplingMode(NearestSample); break;
|
Chris@193
|
448 case 1: setSamplingMode(SampleMean); break;
|
Chris@193
|
449 case 2: setSamplingMode(SamplePeak); break;
|
Chris@193
|
450 }
|
Chris@193
|
451 } else if (name == "Bin Scale") {
|
Chris@193
|
452 switch (value) {
|
Chris@193
|
453 default:
|
Chris@193
|
454 case 0: setBinScale(LinearBins); break;
|
Chris@193
|
455 case 1: setBinScale(LogBins); break;
|
Chris@193
|
456 case 2: setBinScale(InvertedLogBins); break;
|
Chris@193
|
457 }
|
Chris@153
|
458 } else if (name == "Normalize") {
|
Chris@153
|
459 setNormalize(value ? true : false);
|
Chris@153
|
460 }
|
Chris@153
|
461 }
|
Chris@153
|
462
|
Chris@153
|
463 void
|
Chris@193
|
464 SliceLayer::setBaseColour(QColor colour)
|
Chris@153
|
465 {
|
Chris@153
|
466 if (m_colour == colour) return;
|
Chris@153
|
467 m_colour = colour;
|
Chris@153
|
468 emit layerParametersChanged();
|
Chris@153
|
469 }
|
Chris@153
|
470
|
Chris@153
|
471 void
|
Chris@193
|
472 SliceLayer::setEnergyScale(EnergyScale scale)
|
Chris@153
|
473 {
|
Chris@153
|
474 if (m_energyScale == scale) return;
|
Chris@153
|
475 m_energyScale = scale;
|
Chris@153
|
476 emit layerParametersChanged();
|
Chris@153
|
477 }
|
Chris@153
|
478
|
Chris@153
|
479 void
|
Chris@193
|
480 SliceLayer::setSamplingMode(SamplingMode mode)
|
Chris@153
|
481 {
|
Chris@193
|
482 if (m_samplingMode == mode) return;
|
Chris@193
|
483 m_samplingMode = mode;
|
Chris@153
|
484 emit layerParametersChanged();
|
Chris@153
|
485 }
|
Chris@153
|
486
|
Chris@153
|
487 void
|
Chris@193
|
488 SliceLayer::setPlotStyle(PlotStyle style)
|
Chris@153
|
489 {
|
Chris@193
|
490 if (m_plotStyle == style) return;
|
Chris@193
|
491 m_plotStyle = style;
|
Chris@153
|
492 emit layerParametersChanged();
|
Chris@153
|
493 }
|
Chris@153
|
494
|
Chris@153
|
495 void
|
Chris@193
|
496 SliceLayer::setBinScale(BinScale scale)
|
Chris@153
|
497 {
|
Chris@193
|
498 if (m_binScale == scale) return;
|
Chris@193
|
499 m_binScale = scale;
|
Chris@153
|
500 emit layerParametersChanged();
|
Chris@153
|
501 }
|
Chris@153
|
502
|
Chris@153
|
503 void
|
Chris@193
|
504 SliceLayer::setNormalize(bool n)
|
Chris@153
|
505 {
|
Chris@153
|
506 if (m_normalize == n) return;
|
Chris@153
|
507 m_normalize = n;
|
Chris@153
|
508 emit layerParametersChanged();
|
Chris@153
|
509 }
|
Chris@153
|
510
|
Chris@153
|
511 void
|
Chris@193
|
512 SliceLayer::setGain(float gain)
|
Chris@153
|
513 {
|
Chris@153
|
514 if (m_gain == gain) return;
|
Chris@153
|
515 m_gain = gain;
|
Chris@153
|
516 emit layerParametersChanged();
|
Chris@153
|
517 }
|
Chris@153
|
518
|
Chris@153
|
519 QString
|
Chris@193
|
520 SliceLayer::toXmlString(QString indent, QString extraAttributes) const
|
Chris@153
|
521 {
|
Chris@153
|
522 QString s;
|
Chris@153
|
523
|
Chris@153
|
524 s += QString("colour=\"%1\" "
|
Chris@193
|
525 "energyScale=\"%2\" "
|
Chris@193
|
526 "samplingMode=\"%3\" "
|
Chris@193
|
527 "gain=\"%4\" "
|
Chris@193
|
528 "normalize=\"%5\"")
|
Chris@153
|
529 .arg(encodeColour(m_colour))
|
Chris@153
|
530 .arg(m_energyScale)
|
Chris@193
|
531 .arg(m_samplingMode)
|
Chris@153
|
532 .arg(m_gain)
|
Chris@153
|
533 .arg(m_normalize ? "true" : "false");
|
Chris@153
|
534
|
Chris@153
|
535 return Layer::toXmlString(indent, extraAttributes + " " + s);
|
Chris@153
|
536 }
|
Chris@153
|
537
|
Chris@153
|
538 void
|
Chris@193
|
539 SliceLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@153
|
540 {
|
Chris@153
|
541 bool ok = false;
|
Chris@153
|
542
|
Chris@153
|
543 QString colourSpec = attributes.value("colour");
|
Chris@153
|
544 if (colourSpec != "") {
|
Chris@153
|
545 QColor colour(colourSpec);
|
Chris@153
|
546 if (colour.isValid()) {
|
Chris@153
|
547 setBaseColour(QColor(colourSpec));
|
Chris@153
|
548 }
|
Chris@153
|
549 }
|
Chris@153
|
550
|
Chris@153
|
551 EnergyScale scale = (EnergyScale)
|
Chris@153
|
552 attributes.value("energyScale").toInt(&ok);
|
Chris@153
|
553 if (ok) setEnergyScale(scale);
|
Chris@153
|
554
|
Chris@193
|
555 SamplingMode mode = (SamplingMode)
|
Chris@193
|
556 attributes.value("samplingMode").toInt(&ok);
|
Chris@193
|
557 if (ok) setSamplingMode(mode);
|
Chris@153
|
558
|
Chris@153
|
559 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@153
|
560 if (ok) setGain(gain);
|
Chris@153
|
561
|
Chris@153
|
562 bool normalize = (attributes.value("normalize").trimmed() == "true");
|
Chris@153
|
563 setNormalize(normalize);
|
Chris@133
|
564 }
|
Chris@133
|
565
|
Chris@133
|
566 bool
|
Chris@193
|
567 SliceLayer::getValueExtents(float &min, float &max, bool &logarithmic,
|
Chris@133
|
568 QString &units) const
|
Chris@133
|
569 {
|
Chris@133
|
570 return false;
|
Chris@133
|
571 }
|
Chris@133
|
572
|