annotate layer/Colour3DPlotLayer.cpp @ 1415:89d124ac9bfa

Avoid compiler warning
author Chris Cannam
date Mon, 21 Jan 2019 10:07:36 +0000
parents 79032214f79d
children fa986b91d77f
rev   line source
Chris@58 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@59 4 Sonic Visualiser
Chris@59 5 An audio file viewer and annotation editor.
Chris@59 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@0 8
Chris@59 9 This program is free software; you can redistribute it and/or
Chris@59 10 modify it under the terms of the GNU General Public License as
Chris@59 11 published by the Free Software Foundation; either version 2 of the
Chris@59 12 License, or (at your option) any later version. See the file
Chris@59 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #include "Colour3DPlotLayer.h"
Chris@0 17
Chris@0 18 #include "base/Profiler.h"
Chris@197 19 #include "base/LogRange.h"
Chris@444 20 #include "base/RangeMapper.h"
Chris@1077 21
Chris@376 22 #include "ColourMapper.h"
Chris@1077 23 #include "LayerGeometryProvider.h"
Chris@1078 24 #include "PaintAssistant.h"
Chris@1077 25
Chris@1100 26 #include "data/model/Dense3DModelPeakCache.h"
Chris@1100 27
Chris@1077 28 #include "view/ViewManager.h"
Chris@0 29
Chris@0 30 #include <QPainter>
Chris@0 31 #include <QImage>
Chris@0 32 #include <QRect>
Chris@316 33 #include <QTextStream>
Chris@1018 34 #include <QSettings>
Chris@0 35
Chris@0 36 #include <iostream>
Chris@0 37
Chris@0 38 #include <cassert>
Chris@0 39
Chris@903 40 using std::vector;
Chris@903 41
Chris@353 42 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1
Chris@125 43
Chris@0 44
Chris@44 45 Colour3DPlotLayer::Colour3DPlotLayer() :
Chris@0 46 m_model(0),
Chris@1105 47 m_colourScale(ColourScaleType::Linear),
Chris@461 48 m_colourScaleSet(false),
Chris@197 49 m_colourMap(0),
Chris@1362 50 m_colourInverted(false),
Chris@534 51 m_gain(1.0),
Chris@1103 52 m_binScale(BinScale::Linear),
Chris@1104 53 m_normalization(ColumnNormalization::None),
Chris@1104 54 m_normalizeVisibleArea(false),
Chris@444 55 m_invertVertical(false),
Chris@465 56 m_opaque(false),
Chris@535 57 m_smooth(false),
Chris@805 58 m_peakResolution(256),
Chris@444 59 m_miny(0),
Chris@1100 60 m_maxy(0),
Chris@1101 61 m_synchronous(false),
Chris@1100 62 m_peakCache(0),
Chris@1100 63 m_peakCacheDivisor(8)
Chris@0 64 {
Chris@1018 65 QSettings settings;
Chris@1018 66 settings.beginGroup("Preferences");
Chris@1018 67 setColourMap(settings.value("colour-3d-plot-colour", ColourMapper::Green).toInt());
Chris@1018 68 settings.endGroup();
Chris@0 69 }
Chris@0 70
Chris@0 71 Colour3DPlotLayer::~Colour3DPlotLayer()
Chris@0 72 {
Chris@1107 73 invalidateRenderers();
Chris@1242 74 if (m_peakCache) m_peakCache->aboutToDelete();
Chris@1100 75 delete m_peakCache;
Chris@0 76 }
Chris@0 77
Chris@1105 78 ColourScaleType
Chris@1104 79 Colour3DPlotLayer::convertToColourScale(int value)
Chris@1104 80 {
Chris@1104 81 switch (value) {
Chris@1104 82 default:
Chris@1105 83 case 0: return ColourScaleType::Linear;
Chris@1105 84 case 1: return ColourScaleType::Log;
Chris@1105 85 case 2: return ColourScaleType::PlusMinusOne;
Chris@1105 86 case 3: return ColourScaleType::Absolute;
Chris@1104 87 }
Chris@1104 88 }
Chris@1104 89
Chris@1104 90 int
Chris@1105 91 Colour3DPlotLayer::convertFromColourScale(ColourScaleType scale)
Chris@1104 92 {
Chris@1104 93 switch (scale) {
Chris@1105 94 case ColourScaleType::Linear: return 0;
Chris@1105 95 case ColourScaleType::Log: return 1;
Chris@1105 96 case ColourScaleType::PlusMinusOne: return 2;
Chris@1105 97 case ColourScaleType::Absolute: return 3;
Chris@1104 98
Chris@1105 99 case ColourScaleType::Meter:
Chris@1105 100 case ColourScaleType::Phase:
Chris@1104 101 default: return 0;
Chris@1104 102 }
Chris@1104 103 }
Chris@1104 104
Chris@1104 105 std::pair<ColumnNormalization, bool>
Chris@1104 106 Colour3DPlotLayer::convertToColumnNorm(int value)
Chris@1104 107 {
Chris@1104 108 switch (value) {
Chris@1104 109 default:
Chris@1104 110 case 0: return { ColumnNormalization::None, false };
Chris@1245 111 case 1: return { ColumnNormalization::Range01, false };
Chris@1104 112 case 2: return { ColumnNormalization::None, true }; // visible area
Chris@1104 113 case 3: return { ColumnNormalization::Hybrid, false };
Chris@1104 114 }
Chris@1104 115 }
Chris@1104 116
Chris@1104 117 int
Chris@1104 118 Colour3DPlotLayer::convertFromColumnNorm(ColumnNormalization norm, bool visible)
Chris@1104 119 {
Chris@1104 120 if (visible) return 2;
Chris@1104 121 switch (norm) {
Chris@1104 122 case ColumnNormalization::None: return 0;
Chris@1245 123 case ColumnNormalization::Range01: return 1;
Chris@1104 124 case ColumnNormalization::Hybrid: return 3;
Chris@1104 125
Chris@1104 126 case ColumnNormalization::Sum1:
Chris@1245 127 case ColumnNormalization::Max1:
Chris@1104 128 default: return 0;
Chris@1104 129 }
Chris@1104 130 }
Chris@1104 131
Chris@0 132 void
Chris@1101 133 Colour3DPlotLayer::setSynchronousPainting(bool synchronous)
Chris@1101 134 {
Chris@1101 135 m_synchronous = synchronous;
Chris@1101 136 }
Chris@1101 137
Chris@1101 138 void
Chris@0 139 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model)
Chris@0 140 {
Chris@1242 141 SVDEBUG << "Colour3DPlotLayer::setModel(" << model << ")" << endl;
Chris@1242 142
Chris@193 143 if (m_model == model) return;
Chris@193 144 const DenseThreeDimensionalModel *oldModel = m_model;
Chris@0 145 m_model = model;
Chris@0 146 if (!m_model || !m_model->isOK()) return;
Chris@0 147
Chris@320 148 connectSignals(m_model);
Chris@0 149
Chris@461 150 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
Chris@908 151 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
Chris@1266 152 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
Chris@0 153
Chris@474 154 m_peakResolution = 256;
Chris@474 155 if (model->getResolution() > 512) {
Chris@474 156 m_peakResolution = 16;
Chris@474 157 } else if (model->getResolution() > 128) {
Chris@474 158 m_peakResolution = 64;
Chris@474 159 } else if (model->getResolution() > 2) {
Chris@474 160 m_peakResolution = 128;
Chris@474 161 }
Chris@1100 162
Chris@1242 163 if (m_peakCache) m_peakCache->aboutToDelete();
Chris@1100 164 delete m_peakCache;
Chris@1100 165 m_peakCache = 0;
Chris@1100 166
Chris@1107 167 invalidateRenderers();
Chris@1235 168 invalidateMagnitudes();
Chris@474 169
Chris@0 170 emit modelReplaced();
Chris@193 171 emit sliceableModelReplaced(oldModel, model);
Chris@0 172 }
Chris@0 173
Chris@0 174 void
Chris@0 175 Colour3DPlotLayer::cacheInvalid()
Chris@0 176 {
Chris@1107 177 invalidateRenderers();
Chris@1235 178 invalidateMagnitudes();
Chris@1107 179 }
Chris@1102 180
Chris@1107 181 void
Chris@1107 182 Colour3DPlotLayer::cacheInvalid(sv_frame_t /* startFrame */,
Chris@1107 183 sv_frame_t /* endFrame */)
Chris@1107 184 {
Chris@1107 185 //!!! should do this only if the range is visible
Chris@1242 186 if (m_peakCache) m_peakCache->aboutToDelete();
Chris@1107 187 delete m_peakCache;
Chris@1108 188 m_peakCache = 0;
Chris@1108 189
Chris@1107 190 invalidateRenderers();
Chris@1235 191 invalidateMagnitudes();
Chris@1107 192 }
Chris@1107 193
Chris@1107 194 void
Chris@1107 195 Colour3DPlotLayer::invalidateRenderers()
Chris@1107 196 {
Chris@1102 197 for (ViewRendererMap::iterator i = m_renderers.begin();
Chris@1102 198 i != m_renderers.end(); ++i) {
Chris@1102 199 delete i->second;
Chris@1102 200 }
Chris@1102 201 m_renderers.clear();
Chris@0 202 }
Chris@0 203
Chris@1235 204 void
Chris@1235 205 Colour3DPlotLayer::invalidateMagnitudes()
Chris@1235 206 {
Chris@1235 207 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@1412 208 SVDEBUG << "Colour3DPlotLayer::invalidateMagnitudes called" << endl;
Chris@1235 209 #endif
Chris@1235 210 m_viewMags.clear();
Chris@1235 211 }
Chris@1235 212
Chris@1100 213 Dense3DModelPeakCache *
Chris@1100 214 Colour3DPlotLayer::getPeakCache() const
Chris@1100 215 {
Chris@1100 216 if (!m_peakCache) {
Chris@1100 217 m_peakCache = new Dense3DModelPeakCache(m_model, m_peakCacheDivisor);
Chris@1100 218 }
Chris@1100 219 return m_peakCache;
Chris@1100 220 }
Chris@1100 221
Chris@461 222 void
Chris@461 223 Colour3DPlotLayer::modelChanged()
Chris@461 224 {
Chris@1105 225 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
Chris@461 226 if (m_model) {
Chris@461 227 if (m_model->shouldUseLogValueScale()) {
Chris@1105 228 setColourScale(ColourScaleType::Log);
Chris@461 229 } else {
Chris@461 230 m_colourScaleSet = true;
Chris@461 231 }
Chris@461 232 }
Chris@461 233 }
Chris@0 234 cacheInvalid();
Chris@0 235 }
Chris@0 236
Chris@461 237 void
Chris@908 238 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
Chris@461 239 {
Chris@1105 240 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
Chris@461 241 if (m_model && m_model->getWidth() > 50) {
Chris@461 242 if (m_model->shouldUseLogValueScale()) {
Chris@1105 243 setColourScale(ColourScaleType::Log);
Chris@461 244 } else {
Chris@461 245 m_colourScaleSet = true;
Chris@461 246 }
Chris@461 247 }
Chris@461 248 }
Chris@461 249 cacheInvalid(startFrame, endFrame);
Chris@461 250 }
Chris@461 251
Chris@159 252 Layer::PropertyList
Chris@159 253 Colour3DPlotLayer::getProperties() const
Chris@159 254 {
Chris@159 255 PropertyList list;
Chris@197 256 list.push_back("Colour");
Chris@159 257 list.push_back("Colour Scale");
Chris@1104 258 list.push_back("Normalization");
Chris@534 259 list.push_back("Gain");
Chris@531 260 list.push_back("Bin Scale");
Chris@357 261 list.push_back("Invert Vertical Scale");
Chris@465 262 list.push_back("Opaque");
Chris@535 263 list.push_back("Smooth");
Chris@159 264 return list;
Chris@159 265 }
Chris@159 266
Chris@159 267 QString
Chris@159 268 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
Chris@159 269 {
Chris@197 270 if (name == "Colour") return tr("Colour");
Chris@197 271 if (name == "Colour Scale") return tr("Scale");
Chris@1104 272 if (name == "Normalization") return tr("Normalization");
Chris@357 273 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
Chris@534 274 if (name == "Gain") return tr("Gain");
Chris@465 275 if (name == "Opaque") return tr("Always Opaque");
Chris@535 276 if (name == "Smooth") return tr("Smooth");
Chris@531 277 if (name == "Bin Scale") return tr("Bin Scale");
Chris@159 278 return "";
Chris@159 279 }
Chris@159 280
Chris@346 281 QString
Chris@346 282 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
Chris@346 283 {
Chris@357 284 if (name == "Invert Vertical Scale") return "invert-vertical";
Chris@465 285 if (name == "Opaque") return "opaque";
Chris@535 286 if (name == "Smooth") return "smooth";
Chris@346 287 return "";
Chris@346 288 }
Chris@346 289
Chris@159 290 Layer::PropertyType
Chris@159 291 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
Chris@159 292 {
Chris@534 293 if (name == "Gain") return RangeProperty;
Chris@357 294 if (name == "Invert Vertical Scale") return ToggleProperty;
Chris@465 295 if (name == "Opaque") return ToggleProperty;
Chris@535 296 if (name == "Smooth") return ToggleProperty;
Chris@1198 297 if (name == "Colour") return ColourMapProperty;
Chris@159 298 return ValueProperty;
Chris@159 299 }
Chris@159 300
Chris@159 301 QString
Chris@159 302 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
Chris@159 303 {
Chris@1104 304 if (name == "Normalization" ||
Chris@1104 305 name == "Colour Scale" ||
Chris@1365 306 name == "Gain") {
Chris@1365 307 return tr("Scale");
Chris@1365 308 }
Chris@531 309 if (name == "Bin Scale" ||
Chris@1365 310 name == "Invert Vertical Scale") {
Chris@1365 311 return tr("Bins");
Chris@1365 312 }
Chris@465 313 if (name == "Opaque" ||
Chris@535 314 name == "Smooth" ||
Chris@1365 315 name == "Colour") {
Chris@1365 316 return tr("Colour");
Chris@1365 317 }
Chris@159 318 return QString();
Chris@159 319 }
Chris@159 320
Chris@159 321 int
Chris@159 322 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 323 int *min, int *max, int *deflt) const
Chris@159 324 {
Chris@216 325 int val = 0;
Chris@159 326
Chris@216 327 int garbage0, garbage1, garbage2;
Chris@159 328 if (!min) min = &garbage0;
Chris@159 329 if (!max) max = &garbage1;
Chris@216 330 if (!deflt) deflt = &garbage2;
Chris@159 331
Chris@534 332 if (name == "Gain") {
Chris@534 333
Chris@1266 334 *min = -50;
Chris@1266 335 *max = 50;
Chris@534 336
Chris@902 337 *deflt = int(lrint(log10(1.0) * 20.0));
Chris@1266 338 if (*deflt < *min) *deflt = *min;
Chris@1266 339 if (*deflt > *max) *deflt = *max;
Chris@534 340
Chris@1266 341 val = int(lrint(log10(m_gain) * 20.0));
Chris@1266 342 if (val < *min) val = *min;
Chris@1266 343 if (val > *max) val = *max;
Chris@534 344
Chris@534 345 } else if (name == "Colour Scale") {
Chris@159 346
Chris@1099 347 // linear, log, +/-1, abs
Chris@1266 348 *min = 0;
Chris@1266 349 *max = 3;
Chris@1099 350 *deflt = 0;
Chris@159 351
Chris@1266 352 val = convertFromColourScale(m_colourScale);
Chris@159 353
Chris@197 354 } else if (name == "Colour") {
Chris@197 355
Chris@1266 356 *min = 0;
Chris@1266 357 *max = ColourMapper::getColourMapCount() - 1;
Chris@216 358 *deflt = 0;
Chris@197 359
Chris@1266 360 val = m_colourMap;
Chris@197 361
Chris@1099 362 } else if (name == "Normalization") {
Chris@1266 363
Chris@1099 364 *min = 0;
Chris@1099 365 *max = 3;
Chris@1104 366 *deflt = 0;
Chris@1104 367
Chris@1104 368 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea);
Chris@197 369
Chris@357 370 } else if (name == "Invert Vertical Scale") {
Chris@1365 371
Chris@1365 372 *min = 0;
Chris@1365 373 *max = 1;
Chris@357 374 *deflt = 0;
Chris@1266 375 val = (m_invertVertical ? 1 : 0);
Chris@357 376
Chris@531 377 } else if (name == "Bin Scale") {
Chris@531 378
Chris@1266 379 *min = 0;
Chris@1266 380 *max = 1;
Chris@1103 381 *deflt = int(BinScale::Linear);
Chris@1266 382 val = (int)m_binScale;
Chris@531 383
Chris@465 384 } else if (name == "Opaque") {
Chris@1266 385
Chris@1365 386 *min = 0;
Chris@1365 387 *max = 1;
Chris@465 388 *deflt = 0;
Chris@1266 389 val = (m_opaque ? 1 : 0);
Chris@465 390
Chris@535 391 } else if (name == "Smooth") {
Chris@1266 392
Chris@1365 393 *min = 0;
Chris@1365 394 *max = 1;
Chris@535 395 *deflt = 0;
Chris@1266 396 val = (m_smooth ? 1 : 0);
Chris@535 397
Chris@159 398 } else {
Chris@1266 399 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@159 400 }
Chris@159 401
Chris@216 402 return val;
Chris@159 403 }
Chris@159 404
Chris@159 405 QString
Chris@159 406 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
Chris@1266 407 int value) const
Chris@159 408 {
Chris@197 409 if (name == "Colour") {
Chris@1362 410 return ColourMapper::getColourMapLabel(value);
Chris@197 411 }
Chris@159 412 if (name == "Colour Scale") {
Chris@1266 413 switch (value) {
Chris@1266 414 default:
Chris@1266 415 case 0: return tr("Linear");
Chris@1266 416 case 1: return tr("Log");
Chris@1266 417 case 2: return tr("+/-1");
Chris@1266 418 case 3: return tr("Absolute");
Chris@1266 419 }
Chris@159 420 }
Chris@1099 421 if (name == "Normalization") {
Chris@1209 422 switch(value) {
Chris@1209 423 default:
Chris@1209 424 case 0: return tr("None");
Chris@1209 425 case 1: return tr("Col");
Chris@1209 426 case 2: return tr("View");
Chris@1209 427 case 3: return tr("Hybrid");
Chris@1209 428 }
Chris@1209 429 // return ""; // icon only
Chris@1099 430 }
Chris@531 431 if (name == "Bin Scale") {
Chris@1266 432 switch (value) {
Chris@1266 433 default:
Chris@1266 434 case 0: return tr("Linear");
Chris@1266 435 case 1: return tr("Log");
Chris@1266 436 }
Chris@531 437 }
Chris@159 438 return tr("<unknown>");
Chris@159 439 }
Chris@159 440
Chris@1099 441 QString
Chris@1099 442 Colour3DPlotLayer::getPropertyValueIconName(const PropertyName &name,
Chris@1099 443 int value) const
Chris@1099 444 {
Chris@1099 445 if (name == "Normalization") {
Chris@1099 446 switch(value) {
Chris@1099 447 default:
Chris@1099 448 case 0: return "normalise-none";
Chris@1099 449 case 1: return "normalise-columns";
Chris@1099 450 case 2: return "normalise";
Chris@1099 451 case 3: return "normalise-hybrid";
Chris@1099 452 }
Chris@1099 453 }
Chris@1099 454 return "";
Chris@1099 455 }
Chris@1099 456
Chris@534 457 RangeMapper *
Chris@534 458 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const
Chris@534 459 {
Chris@534 460 if (name == "Gain") {
Chris@534 461 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
Chris@534 462 }
Chris@534 463 return 0;
Chris@534 464 }
Chris@534 465
Chris@159 466 void
Chris@159 467 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
Chris@159 468 {
Chris@534 469 if (name == "Gain") {
Chris@1266 470 setGain(float(pow(10, value/20.0)));
Chris@534 471 } else if (name == "Colour Scale") {
Chris@1104 472 setColourScale(convertToColourScale(value));
Chris@197 473 } else if (name == "Colour") {
Chris@197 474 setColourMap(value);
Chris@357 475 } else if (name == "Invert Vertical Scale") {
Chris@1266 476 setInvertVertical(value ? true : false);
Chris@465 477 } else if (name == "Opaque") {
Chris@1266 478 setOpaque(value ? true : false);
Chris@535 479 } else if (name == "Smooth") {
Chris@1266 480 setSmooth(value ? true : false);
Chris@531 481 } else if (name == "Bin Scale") {
Chris@1266 482 switch (value) {
Chris@1266 483 default:
Chris@1266 484 case 0: setBinScale(BinScale::Linear); break;
Chris@1266 485 case 1: setBinScale(BinScale::Log); break;
Chris@1266 486 }
Chris@1099 487 } else if (name == "Normalization") {
Chris@1104 488 auto n = convertToColumnNorm(value);
Chris@1104 489 setNormalization(n.first);
Chris@1104 490 setNormalizeVisibleArea(n.second);
Chris@159 491 }
Chris@159 492 }
Chris@159 493
Chris@159 494 void
Chris@1105 495 Colour3DPlotLayer::setColourScale(ColourScaleType scale)
Chris@159 496 {
Chris@1254 497 m_colourScaleSet = true; // even if setting to the same thing
Chris@159 498 if (m_colourScale == scale) return;
Chris@159 499 m_colourScale = scale;
Chris@1107 500 invalidateRenderers();
Chris@159 501 emit layerParametersChanged();
Chris@159 502 }
Chris@159 503
Chris@197 504 void
Chris@197 505 Colour3DPlotLayer::setColourMap(int map)
Chris@197 506 {
Chris@197 507 if (m_colourMap == map) return;
Chris@197 508 m_colourMap = map;
Chris@1107 509 invalidateRenderers();
Chris@197 510 emit layerParametersChanged();
Chris@197 511 }
Chris@197 512
Chris@197 513 void
Chris@534 514 Colour3DPlotLayer::setGain(float gain)
Chris@534 515 {
Chris@534 516 if (m_gain == gain) return;
Chris@534 517 m_gain = gain;
Chris@1107 518 invalidateRenderers();
Chris@534 519 emit layerParametersChanged();
Chris@534 520 }
Chris@534 521
Chris@534 522 float
Chris@534 523 Colour3DPlotLayer::getGain() const
Chris@534 524 {
Chris@534 525 return m_gain;
Chris@534 526 }
Chris@534 527
Chris@534 528 void
Chris@1103 529 Colour3DPlotLayer::setBinScale(BinScale binScale)
Chris@531 530 {
Chris@531 531 if (m_binScale == binScale) return;
Chris@531 532 m_binScale = binScale;
Chris@1107 533 invalidateRenderers();
Chris@531 534 emit layerParametersChanged();
Chris@531 535 }
Chris@531 536
Chris@1103 537 BinScale
Chris@531 538 Colour3DPlotLayer::getBinScale() const
Chris@531 539 {
Chris@531 540 return m_binScale;
Chris@531 541 }
Chris@531 542
Chris@531 543 void
Chris@1104 544 Colour3DPlotLayer::setNormalization(ColumnNormalization n)
Chris@197 545 {
Chris@1099 546 if (m_normalization == n) return;
Chris@1099 547
Chris@1099 548 m_normalization = n;
Chris@1107 549 invalidateRenderers();
Chris@1099 550
Chris@197 551 emit layerParametersChanged();
Chris@197 552 }
Chris@197 553
Chris@1104 554 ColumnNormalization
Chris@1099 555 Colour3DPlotLayer::getNormalization() const
Chris@197 556 {
Chris@1099 557 return m_normalization;
Chris@197 558 }
Chris@197 559
Chris@357 560 void
Chris@1104 561 Colour3DPlotLayer::setNormalizeVisibleArea(bool n)
Chris@1104 562 {
Chris@1104 563 if (m_normalizeVisibleArea == n) return;
Chris@1104 564
Chris@1235 565 invalidateRenderers();
Chris@1235 566 invalidateMagnitudes();
Chris@1104 567 m_normalizeVisibleArea = n;
Chris@1104 568
Chris@1104 569 emit layerParametersChanged();
Chris@1104 570 }
Chris@1104 571
Chris@1104 572 bool
Chris@1104 573 Colour3DPlotLayer::getNormalizeVisibleArea() const
Chris@1104 574 {
Chris@1104 575 return m_normalizeVisibleArea;
Chris@1104 576 }
Chris@1104 577
Chris@1104 578 void
Chris@357 579 Colour3DPlotLayer::setInvertVertical(bool n)
Chris@357 580 {
Chris@357 581 if (m_invertVertical == n) return;
Chris@357 582 m_invertVertical = n;
Chris@1107 583 invalidateRenderers();
Chris@357 584 emit layerParametersChanged();
Chris@357 585 }
Chris@357 586
Chris@465 587 void
Chris@465 588 Colour3DPlotLayer::setOpaque(bool n)
Chris@465 589 {
Chris@465 590 if (m_opaque == n) return;
Chris@465 591 m_opaque = n;
Chris@1107 592 invalidateRenderers();
Chris@465 593 emit layerParametersChanged();
Chris@465 594 }
Chris@465 595
Chris@535 596 void
Chris@535 597 Colour3DPlotLayer::setSmooth(bool n)
Chris@535 598 {
Chris@535 599 if (m_smooth == n) return;
Chris@535 600 m_smooth = n;
Chris@1107 601 invalidateRenderers();
Chris@535 602 emit layerParametersChanged();
Chris@535 603 }
Chris@535 604
Chris@357 605 bool
Chris@357 606 Colour3DPlotLayer::getInvertVertical() const
Chris@357 607 {
Chris@357 608 return m_invertVertical;
Chris@357 609 }
Chris@357 610
Chris@25 611 bool
Chris@465 612 Colour3DPlotLayer::getOpaque() const
Chris@465 613 {
Chris@465 614 return m_opaque;
Chris@465 615 }
Chris@465 616
Chris@535 617 bool
Chris@535 618 Colour3DPlotLayer::getSmooth() const
Chris@535 619 {
Chris@535 620 return m_smooth;
Chris@535 621 }
Chris@535 622
Chris@475 623 void
Chris@916 624 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
Chris@475 625 {
Chris@475 626 if (dormant) {
Chris@475 627
Chris@475 628 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@1412 629 SVDEBUG << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")"
Chris@585 630 << endl;
Chris@475 631 #endif
Chris@475 632
Chris@475 633 if (isLayerDormant(v)) {
Chris@475 634 return;
Chris@475 635 }
Chris@475 636
Chris@475 637 Layer::setLayerDormant(v, true);
Chris@475 638
Chris@475 639 cacheInvalid();
Chris@1266 640
Chris@475 641 } else {
Chris@475 642
Chris@475 643 Layer::setLayerDormant(v, false);
Chris@475 644 }
Chris@475 645 }
Chris@475 646
Chris@465 647 bool
Chris@1150 648 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider * /* v */) const
Chris@25 649 {
Chris@1121 650 return false;
Chris@25 651 }
Chris@25 652
Chris@444 653 bool
Chris@904 654 Colour3DPlotLayer::getValueExtents(double &min, double &max,
Chris@444 655 bool &logarithmic, QString &unit) const
Chris@444 656 {
Chris@444 657 if (!m_model) return false;
Chris@444 658
Chris@444 659 min = 0;
Chris@904 660 max = double(m_model->getHeight());
Chris@444 661
Chris@1238 662 logarithmic = (m_binScale == BinScale::Log);
Chris@444 663 unit = "";
Chris@444 664
Chris@444 665 return true;
Chris@444 666 }
Chris@444 667
Chris@444 668 bool
Chris@904 669 Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const
Chris@444 670 {
Chris@444 671 if (!m_model) return false;
Chris@444 672
Chris@904 673 double hmax = double(m_model->getHeight());
Chris@902 674
Chris@904 675 min = m_miny;
Chris@904 676 max = m_maxy;
Chris@444 677 if (max <= min) {
Chris@444 678 min = 0;
Chris@902 679 max = hmax;
Chris@444 680 }
Chris@444 681 if (min < 0) min = 0;
Chris@902 682 if (max > hmax) max = hmax;
Chris@444 683
Chris@444 684 return true;
Chris@444 685 }
Chris@444 686
Chris@444 687 bool
Chris@904 688 Colour3DPlotLayer::setDisplayExtents(double min, double max)
Chris@444 689 {
Chris@444 690 if (!m_model) return false;
Chris@444 691
Chris@904 692 m_miny = int(lrint(min));
Chris@904 693 m_maxy = int(lrint(max));
Chris@444 694
Chris@1133 695 invalidateRenderers();
Chris@1133 696
Chris@444 697 emit layerParametersChanged();
Chris@444 698 return true;
Chris@444 699 }
Chris@444 700
Chris@725 701 bool
Chris@916 702 Colour3DPlotLayer::getYScaleValue(const LayerGeometryProvider *, int,
Chris@904 703 double &, QString &) const
Chris@725 704 {
Chris@725 705 return false;//!!!
Chris@725 706 }
Chris@725 707
Chris@444 708 int
Chris@444 709 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
Chris@444 710 {
Chris@444 711 if (!m_model) return 0;
Chris@444 712
Chris@444 713 defaultStep = 0;
Chris@444 714 int h = m_model->getHeight();
Chris@444 715 return h;
Chris@444 716 }
Chris@444 717
Chris@444 718 int
Chris@444 719 Colour3DPlotLayer::getCurrentVerticalZoomStep() const
Chris@444 720 {
Chris@444 721 if (!m_model) return 0;
Chris@444 722
Chris@904 723 double min, max;
Chris@444 724 getDisplayExtents(min, max);
Chris@904 725 return m_model->getHeight() - int(lrint(max - min));
Chris@444 726 }
Chris@444 727
Chris@444 728 void
Chris@444 729 Colour3DPlotLayer::setVerticalZoomStep(int step)
Chris@444 730 {
Chris@444 731 if (!m_model) return;
Chris@444 732
Chris@587 733 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl;
Chris@444 734
Chris@444 735 int dist = m_model->getHeight() - step;
Chris@444 736 if (dist < 1) dist = 1;
Chris@904 737 double centre = m_miny + (m_maxy - m_miny) / 2.0;
Chris@904 738 m_miny = int(lrint(centre - dist/2.0));
Chris@444 739 if (m_miny < 0) m_miny = 0;
Chris@444 740 m_maxy = m_miny + dist;
Chris@444 741 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight();
Chris@444 742
Chris@1133 743 invalidateRenderers();
Chris@1133 744
Chris@587 745 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl;
Chris@444 746
Chris@444 747 emit layerParametersChanged();
Chris@444 748 }
Chris@444 749
Chris@444 750 RangeMapper *
Chris@444 751 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const
Chris@444 752 {
Chris@444 753 if (!m_model) return 0;
Chris@444 754
Chris@444 755 return new LinearRangeMapper(0, m_model->getHeight(),
Chris@444 756 0, m_model->getHeight(), "");
Chris@444 757 }
Chris@444 758
Chris@904 759 double
Chris@1113 760 Colour3DPlotLayer::getYForBin(const LayerGeometryProvider *v, double bin) const
Chris@532 761 {
Chris@904 762 double y = bin;
Chris@532 763 if (!m_model) return y;
Chris@904 764 double mn = 0, mx = m_model->getHeight();
Chris@532 765 getDisplayExtents(mn, mx);
Chris@916 766 double h = v->getPaintHeight();
Chris@1103 767 if (m_binScale == BinScale::Linear) {
Chris@532 768 y = h - (((bin - mn) * h) / (mx - mn));
Chris@532 769 } else {
Chris@904 770 double logmin = mn + 1, logmax = mx + 1;
Chris@532 771 LogRange::mapRange(logmin, logmax);
Chris@532 772 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin));
Chris@532 773 }
Chris@532 774 return y;
Chris@532 775 }
Chris@532 776
Chris@904 777 double
Chris@1113 778 Colour3DPlotLayer::getBinForY(const LayerGeometryProvider *v, double y) const
Chris@532 779 {
Chris@904 780 double bin = y;
Chris@532 781 if (!m_model) return bin;
Chris@904 782 double mn = 0, mx = m_model->getHeight();
Chris@532 783 getDisplayExtents(mn, mx);
Chris@916 784 double h = v->getPaintHeight();
Chris@1103 785 if (m_binScale == BinScale::Linear) {
Chris@1220 786 // Arrange that the first bin (mn) appears as the exact result
Chris@1220 787 // for the first pixel (which is pixel h-1) and the first
Chris@1220 788 // out-of-range bin (mx) would appear as the exact result for
Chris@1220 789 // the first out-of-range pixel (which would be pixel -1)
Chris@1220 790 bin = mn + ((h - y - 1) * (mx - mn)) / h;
Chris@532 791 } else {
Chris@904 792 double logmin = mn + 1, logmax = mx + 1;
Chris@532 793 LogRange::mapRange(logmin, logmax);
Chris@1220 794 bin = LogRange::unmap(logmin + ((h - y - 1) * (logmax - logmin)) / h) - 1;
Chris@532 795 }
Chris@532 796 return bin;
Chris@532 797 }
Chris@532 798
Chris@25 799 QString
Chris@916 800 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
Chris@25 801 {
Chris@25 802 if (!m_model) return "";
Chris@25 803
Chris@25 804 int x = pos.x();
Chris@25 805 int y = pos.y();
Chris@25 806
Chris@902 807 sv_frame_t modelStart = m_model->getStartFrame();
Chris@805 808 int modelResolution = m_model->getResolution();
Chris@25 809
Chris@902 810 double srRatio =
Chris@902 811 v->getViewManager()->getMainModelSampleRate() /
Chris@902 812 m_model->getSampleRate();
Chris@159 813
Chris@902 814 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) /
Chris@812 815 modelResolution);
Chris@25 816
Chris@160 817 int f0 = sx0 * modelResolution;
Chris@160 818 int f1 = f0 + modelResolution;
Chris@160 819
Chris@447 820 int sh = m_model->getHeight();
Chris@447 821
Chris@447 822 int symin = m_miny;
Chris@447 823 int symax = m_maxy;
Chris@447 824 if (symax <= symin) {
Chris@447 825 symin = 0;
Chris@447 826 symax = sh;
Chris@447 827 }
Chris@447 828 if (symin < 0) symin = 0;
Chris@447 829 if (symax > sh) symax = sh;
Chris@447 830
Chris@916 831 // double binHeight = double(v->getPaintHeight()) / (symax - symin);
Chris@916 832 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin;
Chris@534 833
Chris@903 834 int sy = getIBinForY(v, y);
Chris@25 835
Chris@812 836 if (sy < 0 || sy >= m_model->getHeight()) {
Chris@812 837 return "";
Chris@812 838 }
Chris@812 839
Chris@1362 840 if (m_invertVertical) {
Chris@1362 841 sy = m_model->getHeight() - sy - 1;
Chris@1362 842 }
Chris@357 843
Chris@160 844 float value = m_model->getValueAt(sx0, sy);
Chris@159 845
Chris@682 846 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl;
Chris@25 847
Chris@25 848 QString binName = m_model->getBinName(sy);
Chris@25 849 if (binName == "") binName = QString("[%1]").arg(sy + 1);
Chris@25 850 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
Chris@25 851
Chris@25 852 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
Chris@1266 853 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate())
Chris@1266 854 .toText(true).c_str())
Chris@1266 855 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate())
Chris@1266 856 .toText(true).c_str())
Chris@1266 857 .arg(binName)
Chris@1266 858 .arg(value);
Chris@25 859
Chris@25 860 return text;
Chris@25 861 }
Chris@25 862
Chris@25 863 int
Chris@969 864 Colour3DPlotLayer::getColourScaleWidth(QPainter &p) const
Chris@159 865 {
Chris@969 866 // Font is rotated
Chris@969 867 int cw = p.fontMetrics().height();
Chris@159 868 return cw;
Chris@159 869 }
Chris@159 870
Chris@159 871 int
Chris@916 872 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
Chris@25 873 {
Chris@25 874 if (!m_model) return 0;
Chris@25 875
Chris@160 876 QString sampleText = QString("[%1]").arg(m_model->getHeight());
Chris@25 877 int tw = paint.fontMetrics().width(sampleText);
Chris@98 878 bool another = false;
Chris@25 879
Chris@805 880 for (int i = 0; i < m_model->getHeight(); ++i) {
Chris@1266 881 if (m_model->getBinName(i).length() > sampleText.length()) {
Chris@1266 882 sampleText = m_model->getBinName(i);
Chris@98 883 another = true;
Chris@1266 884 }
Chris@25 885 }
Chris@98 886 if (another) {
Chris@1266 887 tw = std::max(tw, paint.fontMetrics().width(sampleText));
Chris@25 888 }
Chris@25 889
Chris@159 890 return tw + 13 + getColourScaleWidth(paint);
Chris@25 891 }
Chris@25 892
Chris@25 893 void
Chris@916 894 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
Chris@25 895 {
Chris@25 896 if (!m_model) return;
Chris@25 897
Chris@25 898 int h = rect.height(), w = rect.width();
Chris@25 899
Chris@159 900 int cw = getColourScaleWidth(paint);
Chris@159 901
Chris@159 902 int ch = h - 20;
Chris@1107 903 if (ch > 20) {
Chris@159 904
Chris@1131 905 double min = m_viewMags[v->getId()].getMin();
Chris@1131 906 double max = m_viewMags[v->getId()].getMax();
Chris@447 907
Chris@1131 908 if (max <= min) max = min + 0.1;
Chris@447 909
Chris@287 910 paint.setPen(v->getForeground());
Chris@447 911 paint.drawRect(4, 10, cw - 8, ch+1);
Chris@159 912
Chris@446 913 for (int y = 0; y < ch; ++y) {
Chris@904 914 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min;
Chris@1131 915 paint.setPen(getRenderer(v)->getColour(value));
Chris@1131 916 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
Chris@159 917 }
Chris@446 918
Chris@446 919 QString minstr = QString("%1").arg(min);
Chris@446 920 QString maxstr = QString("%1").arg(max);
Chris@446 921
Chris@446 922 paint.save();
Chris@446 923
Chris@446 924 QFont font = paint.font();
Chris@1053 925 if (font.pixelSize() > 0) {
Chris@1053 926 int newSize = int(font.pixelSize() * 0.65);
Chris@1053 927 if (newSize < 6) newSize = 6;
Chris@1053 928 font.setPixelSize(newSize);
Chris@1053 929 paint.setFont(font);
Chris@1053 930 }
Chris@446 931
Chris@446 932 int msw = paint.fontMetrics().width(maxstr);
Chris@446 933
Chris@446 934 QMatrix m;
Chris@446 935 m.translate(cw - 6, ch + 10);
Chris@446 936 m.rotate(-90);
Chris@446 937
Chris@446 938 paint.setWorldMatrix(m);
Chris@446 939
Chris@1078 940 PaintAssistant::drawVisibleText(v, paint, 2, 0, minstr, PaintAssistant::OutlinedText);
Chris@446 941
Chris@446 942 m.translate(ch - msw - 2, 0);
Chris@446 943 paint.setWorldMatrix(m);
Chris@446 944
Chris@1078 945 PaintAssistant::drawVisibleText(v, paint, 0, 0, maxstr, PaintAssistant::OutlinedText);
Chris@446 946
Chris@446 947 paint.restore();
Chris@159 948 }
Chris@159 949
Chris@287 950 paint.setPen(v->getForeground());
Chris@159 951
Chris@445 952 int sh = m_model->getHeight();
Chris@445 953
Chris@445 954 int symin = m_miny;
Chris@445 955 int symax = m_maxy;
Chris@445 956 if (symax <= symin) {
Chris@445 957 symin = 0;
Chris@445 958 symax = sh;
Chris@445 959 }
Chris@445 960 if (symin < 0) symin = 0;
Chris@445 961 if (symax > sh) symax = sh;
Chris@445 962
Chris@532 963 paint.save();
Chris@456 964
Chris@533 965 int py = h;
Chris@25 966
Chris@969 967 int defaultFontHeight = paint.fontMetrics().height();
Chris@969 968
Chris@805 969 for (int i = symin; i <= symax; ++i) {
Chris@98 970
Chris@532 971 int y0;
Chris@534 972
Chris@903 973 y0 = getIYForBin(v, i);
Chris@532 974 int h = py - y0;
Chris@532 975
Chris@532 976 if (i > symin) {
Chris@532 977 if (paint.fontMetrics().height() >= h) {
Chris@969 978 if (h >= defaultFontHeight * 0.8) {
Chris@532 979 QFont tf = paint.font();
Chris@973 980 tf.setPixelSize(int(h * 0.8));
Chris@532 981 paint.setFont(tf);
Chris@532 982 } else {
Chris@532 983 continue;
Chris@532 984 }
Chris@532 985 }
Chris@532 986 }
Chris@1266 987
Chris@532 988 py = y0;
Chris@532 989
Chris@534 990 if (i < symax) {
Chris@534 991 paint.drawLine(cw, y0, w, y0);
Chris@534 992 }
Chris@25 993
Chris@532 994 if (i > symin) {
Chris@534 995
Chris@805 996 int idx = i - 1;
Chris@1362 997 if (m_invertVertical) {
Chris@1362 998 idx = m_model->getHeight() - idx - 1;
Chris@1362 999 }
Chris@534 1000
Chris@534 1001 QString text = m_model->getBinName(idx);
Chris@534 1002 if (text == "") text = QString("[%1]").arg(idx + 1);
Chris@534 1003
Chris@534 1004 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) +
Chris@534 1005 paint.fontMetrics().ascent() + 1;
Chris@534 1006
Chris@534 1007 paint.drawText(cw + 5, ty, text);
Chris@457 1008 }
Chris@25 1009 }
Chris@456 1010
Chris@456 1011 paint.restore();
Chris@25 1012 }
Chris@25 1013
Chris@1100 1014 Colour3DPlotRenderer *
Chris@1113 1015 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const
Chris@1100 1016 {
Chris@1235 1017 int viewId = v->getId();
Chris@1235 1018
Chris@1235 1019 if (m_renderers.find(viewId) == m_renderers.end()) {
Chris@1100 1020
Chris@1100 1021 Colour3DPlotRenderer::Sources sources;
Chris@1100 1022 sources.verticalBinLayer = this;
Chris@1100 1023 sources.fft = 0;
Chris@1100 1024 sources.source = m_model;
Chris@1212 1025 sources.peakCaches.push_back(getPeakCache());
Chris@1100 1026
Chris@1100 1027 ColourScale::Parameters cparams;
Chris@1100 1028 cparams.colourMap = m_colourMap;
Chris@1362 1029 cparams.inverted = m_colourInverted;
Chris@1137 1030 cparams.scaleType = m_colourScale;
Chris@1100 1031 cparams.gain = m_gain;
Chris@1100 1032
Chris@1235 1033 double minValue = 0.0;
Chris@1235 1034 double maxValue = 1.0;
Chris@1235 1035
Chris@1235 1036 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) {
Chris@1235 1037 minValue = m_viewMags[viewId].getMin();
Chris@1235 1038 maxValue = m_viewMags[viewId].getMax();
Chris@1245 1039 } else if (m_normalization == ColumnNormalization::Hybrid) {
Chris@1245 1040 minValue = 0;
Chris@1245 1041 maxValue = log10(m_model->getMaximumLevel() + 1.0);
Chris@1235 1042 } else if (m_normalization == ColumnNormalization::None) {
Chris@1235 1043 minValue = m_model->getMinimumLevel();
Chris@1235 1044 maxValue = m_model->getMaximumLevel();
Chris@1131 1045 }
Chris@1131 1046
Chris@1244 1047 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is "
Chris@1362 1048 << minValue << " -> " << maxValue
Chris@1362 1049 << " (model min = " << m_model->getMinimumLevel()
Chris@1362 1050 << ", max = " << m_model->getMaximumLevel() << ")"
Chris@1362 1051 << endl;
Chris@1378 1052
Chris@1235 1053 if (maxValue <= minValue) {
Chris@1235 1054 maxValue = minValue + 0.1f;
Chris@1378 1055
Chris@1378 1056 if (!(maxValue > minValue)) { // one of them must be NaN or Inf
Chris@1378 1057 SVCERR << "WARNING: Colour3DPlotLayer::getRenderer: resetting "
Chris@1378 1058 << "minValue and maxValue to zero and one" << endl;
Chris@1378 1059 minValue = 0.f;
Chris@1378 1060 maxValue = 1.f;
Chris@1378 1061 }
Chris@1131 1062 }
Chris@1235 1063
Chris@1247 1064 cparams.threshold = minValue;
Chris@1235 1065 cparams.minValue = minValue;
Chris@1235 1066 cparams.maxValue = maxValue;
Chris@1131 1067
Chris@1235 1068 m_lastRenderedMags[viewId] = MagnitudeRange(float(minValue),
Chris@1235 1069 float(maxValue));
Chris@1235 1070
Chris@1100 1071 Colour3DPlotRenderer::Parameters params;
Chris@1100 1072 params.colourScale = ColourScale(cparams);
Chris@1100 1073 params.normalization = m_normalization;
Chris@1100 1074 params.binScale = m_binScale;
Chris@1100 1075 params.alwaysOpaque = m_opaque;
Chris@1100 1076 params.invertVertical = m_invertVertical;
Chris@1100 1077 params.interpolate = m_smooth;
Chris@1100 1078
Chris@1235 1079 m_renderers[viewId] = new Colour3DPlotRenderer(sources, params);
Chris@1100 1080 }
Chris@1100 1081
Chris@1235 1082 return m_renderers[viewId];
Chris@1100 1083 }
Chris@1100 1084
Chris@197 1085 void
Chris@1107 1086 Colour3DPlotLayer::paintWithRenderer(LayerGeometryProvider *v,
Chris@1107 1087 QPainter &paint, QRect rect) const
Chris@1101 1088 {
Chris@1101 1089 Colour3DPlotRenderer *renderer = getRenderer(v);
Chris@1101 1090
Chris@1121 1091 Colour3DPlotRenderer::RenderResult result;
Chris@1123 1092 MagnitudeRange magRange;
Chris@1123 1093 int viewId = v->getId();
Chris@1123 1094
Chris@1235 1095 bool continuingPaint = !renderer->geometryChanged(v);
Chris@1235 1096
Chris@1235 1097 if (continuingPaint) {
Chris@1123 1098 magRange = m_viewMags[viewId];
Chris@1123 1099 }
Chris@1121 1100
Chris@1101 1101 if (m_synchronous) {
Chris@1121 1102
Chris@1121 1103 result = renderer->render(v, paint, rect);
Chris@1121 1104
Chris@1121 1105 } else {
Chris@1121 1106
Chris@1121 1107 result = renderer->renderTimeConstrained(v, paint, rect);
Chris@1121 1108
Chris@1121 1109 QRect uncached = renderer->getLargestUncachedRect(v);
Chris@1121 1110 if (uncached.width() > 0) {
Chris@1121 1111 v->updatePaintRect(uncached);
Chris@1121 1112 }
Chris@1101 1113 }
Chris@1121 1114
Chris@1123 1115 magRange.sample(result.range);
Chris@1101 1116
Chris@1123 1117 if (magRange.isSet()) {
Chris@1235 1118 if (m_viewMags[viewId] != magRange) {
Chris@1123 1119 m_viewMags[viewId] = magRange;
Chris@1235 1120 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@1412 1121 SVDEBUG << "mag range in this view has changed: "
Chris@1412 1122 << magRange.getMin() << " -> "
Chris@1412 1123 << magRange.getMax() << endl;
Chris@1235 1124 #endif
Chris@1123 1125 }
Chris@1123 1126 }
Chris@1101 1127
Chris@1235 1128 if (!continuingPaint && m_normalizeVisibleArea &&
Chris@1235 1129 m_viewMags[viewId] != m_lastRenderedMags[viewId]) {
Chris@1235 1130 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@1412 1131 SVDEBUG << "mag range has changed from last rendered range: re-rendering"
Chris@1235 1132 << endl;
Chris@1235 1133 #endif
Chris@1235 1134 delete m_renderers[viewId];
Chris@1235 1135 m_renderers.erase(viewId);
Chris@1235 1136 v->updatePaintRect(v->getPaintRect());
Chris@1235 1137 }
Chris@1101 1138 }
Chris@1101 1139
Chris@1101 1140 void
Chris@916 1141 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
Chris@0 1142 {
Chris@514 1143 /*
Chris@443 1144 if (m_model) {
Chris@587 1145 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl;
Chris@443 1146 }
Chris@514 1147 */
Chris@466 1148 Profiler profiler("Colour3DPlotLayer::paint");
Chris@125 1149 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@1412 1150 SVDEBUG << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl;
Chris@125 1151 #endif
Chris@0 1152
Chris@0 1153 int completion = 0;
Chris@0 1154 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
Chris@1266 1155 if (completion > 0) {
Chris@1266 1156 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100,
Chris@1266 1157 10, QColor(120, 120, 120));
Chris@1266 1158 }
Chris@1266 1159 return;
Chris@0 1160 }
Chris@0 1161
Chris@1053 1162 if (m_model->getWidth() == 0) {
Chris@1053 1163 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@1412 1164 SVDEBUG << "Colour3DPlotLayer::paint(): model width == 0, "
Chris@1053 1165 << "nothing to paint (yet)" << endl;
Chris@1053 1166 #endif
Chris@1053 1167 return;
Chris@1053 1168 }
Chris@1101 1169
Chris@1107 1170 paintWithRenderer(v, paint, rect);
Chris@1107 1171 }
Chris@1107 1172
Chris@28 1173 bool
Chris@916 1174 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
Chris@1266 1175 int &resolution,
Chris@1266 1176 SnapType snap) const
Chris@24 1177 {
Chris@24 1178 if (!m_model) {
Chris@1266 1179 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
Chris@24 1180 }
Chris@24 1181
Chris@130 1182 resolution = m_model->getResolution();
Chris@904 1183 sv_frame_t left = (frame / resolution) * resolution;
Chris@904 1184 sv_frame_t right = left + resolution;
Chris@28 1185
Chris@28 1186 switch (snap) {
Chris@28 1187 case SnapLeft: frame = left; break;
Chris@28 1188 case SnapRight: frame = right; break;
Chris@28 1189 case SnapNearest:
Chris@28 1190 case SnapNeighbouring:
Chris@1266 1191 if (frame - left > right - frame) frame = right;
Chris@1266 1192 else frame = left;
Chris@1266 1193 break;
Chris@28 1194 }
Chris@24 1195
Chris@28 1196 return true;
Chris@24 1197 }
Chris@24 1198
Chris@316 1199 void
Chris@316 1200 Colour3DPlotLayer::toXml(QTextStream &stream,
Chris@316 1201 QString indent, QString extraAttributes) const
Chris@197 1202 {
Chris@316 1203 QString s = QString("scale=\"%1\" "
Chris@1362 1204 "minY=\"%2\" "
Chris@1362 1205 "maxY=\"%3\" "
Chris@1362 1206 "invertVertical=\"%4\" "
Chris@1362 1207 "opaque=\"%5\" %6")
Chris@1266 1208 .arg(convertFromColourScale(m_colourScale))
Chris@445 1209 .arg(m_miny)
Chris@465 1210 .arg(m_maxy)
Chris@465 1211 .arg(m_invertVertical ? "true" : "false")
Chris@534 1212 .arg(m_opaque ? "true" : "false")
Chris@536 1213 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ")
Chris@1103 1214 .arg(int(m_binScale))
Chris@536 1215 .arg(m_smooth ? "true" : "false")
Chris@536 1216 .arg(m_gain));
Chris@1362 1217
Chris@1362 1218 // New-style colour map attribute, by string id rather than by
Chris@1362 1219 // number
Chris@1362 1220
Chris@1362 1221 s += QString("colourMap=\"%1\" ")
Chris@1362 1222 .arg(ColourMapper::getColourMapId(m_colourMap));
Chris@1362 1223
Chris@1362 1224 // Old-style colour map attribute
Chris@1362 1225
Chris@1362 1226 s += QString("colourScheme=\"%1\" ")
Chris@1362 1227 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
Chris@535 1228
Chris@1099 1229 // New-style normalization attributes, allowing for more types of
Chris@1099 1230 // normalization in future: write out the column normalization
Chris@1099 1231 // type separately, and then whether we are normalizing visible
Chris@1099 1232 // area as well afterwards
Chris@1099 1233
Chris@1099 1234 s += QString("columnNormalization=\"%1\" ")
Chris@1245 1235 .arg(m_normalization == ColumnNormalization::Range01 ? "peak" :
Chris@1104 1236 m_normalization == ColumnNormalization::Hybrid ? "hybrid" : "none");
Chris@1099 1237
Chris@1099 1238 // Old-style normalization attribute, for backward compatibility
Chris@1099 1239
Chris@1099 1240 s += QString("normalizeColumns=\"%1\" ")
Chris@1266 1241 .arg(m_normalization == ColumnNormalization::Range01 ? "true" : "false");
Chris@1099 1242
Chris@1099 1243 // And this applies to both old- and new-style attributes
Chris@1099 1244
Chris@1099 1245 s += QString("normalizeVisibleArea=\"%1\" ")
Chris@1104 1246 .arg(m_normalizeVisibleArea ? "true" : "false");
Chris@1099 1247
Chris@316 1248 Layer::toXml(stream, indent, extraAttributes + " " + s);
Chris@197 1249 }
Chris@197 1250
Chris@197 1251 void
Chris@197 1252 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
Chris@197 1253 {
Chris@445 1254 bool ok = false, alsoOk = false;
Chris@197 1255
Chris@1105 1256 ColourScaleType colourScale = convertToColourScale
Chris@1252 1257 (attributes.value("scale").toInt(&ok));
Chris@1099 1258 if (ok) setColourScale(colourScale);
Chris@197 1259
Chris@1362 1260 QString colourMapId = attributes.value("colourMap");
Chris@1362 1261 int colourMap = ColourMapper::getColourMapById(colourMapId);
Chris@1362 1262 if (colourMap >= 0) {
Chris@1362 1263 setColourMap(colourMap);
Chris@1362 1264 } else {
Chris@1362 1265 colourMap = attributes.value("colourScheme").toInt(&ok);
Chris@1362 1266 if (ok && colourMap < ColourMapper::getColourMapCount()) {
Chris@1362 1267 setColourMap(colourMap);
Chris@1362 1268 }
Chris@1362 1269 }
Chris@197 1270
Chris@1103 1271 BinScale binScale = (BinScale)
Chris@1266 1272 attributes.value("binScale").toInt(&ok);
Chris@1099 1273 if (ok) setBinScale(binScale);
Chris@445 1274
Chris@465 1275 bool invertVertical =
Chris@465 1276 (attributes.value("invertVertical").trimmed() == "true");
Chris@465 1277 setInvertVertical(invertVertical);
Chris@465 1278
Chris@465 1279 bool opaque =
Chris@465 1280 (attributes.value("opaque").trimmed() == "true");
Chris@535 1281 setOpaque(opaque);
Chris@535 1282
Chris@535 1283 bool smooth =
Chris@535 1284 (attributes.value("smooth").trimmed() == "true");
Chris@535 1285 setSmooth(smooth);
Chris@465 1286
Chris@536 1287 float gain = attributes.value("gain").toFloat(&ok);
Chris@536 1288 if (ok) setGain(gain);
Chris@536 1289
Chris@445 1290 float min = attributes.value("minY").toFloat(&ok);
Chris@445 1291 float max = attributes.value("maxY").toFloat(&alsoOk);
Chris@445 1292 if (ok && alsoOk) setDisplayExtents(min, max);
Chris@1099 1293
Chris@1099 1294 bool haveNewStyleNormalization = false;
Chris@1099 1295
Chris@1099 1296 QString columnNormalization = attributes.value("columnNormalization");
Chris@1099 1297
Chris@1099 1298 if (columnNormalization != "") {
Chris@1099 1299
Chris@1099 1300 haveNewStyleNormalization = true;
Chris@1099 1301
Chris@1099 1302 if (columnNormalization == "peak") {
Chris@1245 1303 setNormalization(ColumnNormalization::Range01);
Chris@1099 1304 } else if (columnNormalization == "hybrid") {
Chris@1104 1305 setNormalization(ColumnNormalization::Hybrid);
Chris@1099 1306 } else if (columnNormalization == "none") {
Chris@1104 1307 setNormalization(ColumnNormalization::None);
Chris@1099 1308 } else {
Chris@1412 1309 SVCERR << "NOTE: Unknown or unsupported columnNormalization attribute \""
Chris@1412 1310 << columnNormalization << "\"" << endl;
Chris@1099 1311 }
Chris@1099 1312 }
Chris@1099 1313
Chris@1099 1314 if (!haveNewStyleNormalization) {
Chris@1099 1315
Chris@1104 1316 setNormalization(ColumnNormalization::None);
Chris@1104 1317
Chris@1099 1318 bool normalizeColumns =
Chris@1099 1319 (attributes.value("normalizeColumns").trimmed() == "true");
Chris@1099 1320 if (normalizeColumns) {
Chris@1245 1321 setNormalization(ColumnNormalization::Range01);
Chris@1099 1322 }
Chris@1099 1323
Chris@1099 1324 bool normalizeHybrid =
Chris@1099 1325 (attributes.value("normalizeHybrid").trimmed() == "true");
Chris@1099 1326 if (normalizeHybrid) {
Chris@1104 1327 setNormalization(ColumnNormalization::Hybrid);
Chris@1099 1328 }
Chris@1099 1329 }
Chris@1099 1330
Chris@1099 1331 bool normalizeVisibleArea =
Chris@1099 1332 (attributes.value("normalizeVisibleArea").trimmed() == "true");
Chris@1104 1333 setNormalizeVisibleArea(normalizeVisibleArea);
Chris@1099 1334
Chris@1099 1335 //!!! todo: check save/reload scaling, compare with
Chris@1099 1336 //!!! SpectrogramLayer, compare with prior SV versions, compare
Chris@1099 1337 //!!! with Tony v1 and v2 and their save files
Chris@197 1338 }
Chris@197 1339