annotate layer/Colour3DPlotLayer.cpp @ 535:78f9436195b1

* Add smoothing option to colour 3d plot
author Chris Cannam
date Fri, 22 May 2009 13:54:45 +0000
parents 7a560380b6e2
children aca01b3af29f
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@128 18 #include "view/View.h"
Chris@0 19 #include "base/Profiler.h"
Chris@197 20 #include "base/LogRange.h"
Chris@444 21 #include "base/RangeMapper.h"
Chris@376 22 #include "ColourMapper.h"
Chris@0 23
Chris@0 24 #include <QPainter>
Chris@0 25 #include <QImage>
Chris@0 26 #include <QRect>
Chris@316 27 #include <QTextStream>
Chris@0 28
Chris@0 29 #include <iostream>
Chris@0 30
Chris@0 31 #include <cassert>
Chris@0 32
Chris@353 33 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1
Chris@125 34
Chris@0 35
Chris@44 36 Colour3DPlotLayer::Colour3DPlotLayer() :
Chris@0 37 m_model(0),
Chris@159 38 m_cache(0),
Chris@469 39 m_peaksCache(0),
Chris@474 40 m_peakResolution(256),
Chris@461 41 m_cacheValidStart(0),
Chris@461 42 m_cacheValidEnd(0),
Chris@197 43 m_colourScale(LinearScale),
Chris@461 44 m_colourScaleSet(false),
Chris@197 45 m_colourMap(0),
Chris@534 46 m_gain(1.0),
Chris@531 47 m_binScale(LinearBinScale),
Chris@197 48 m_normalizeColumns(false),
Chris@357 49 m_normalizeVisibleArea(false),
Chris@444 50 m_invertVertical(false),
Chris@465 51 m_opaque(false),
Chris@535 52 m_smooth(false),
Chris@444 53 m_miny(0),
Chris@444 54 m_maxy(0)
Chris@0 55 {
Chris@44 56
Chris@0 57 }
Chris@0 58
Chris@0 59 Colour3DPlotLayer::~Colour3DPlotLayer()
Chris@0 60 {
Chris@461 61 delete m_cache;
Chris@469 62 delete m_peaksCache;
Chris@0 63 }
Chris@0 64
Chris@0 65 void
Chris@0 66 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model)
Chris@0 67 {
Chris@193 68 if (m_model == model) return;
Chris@193 69 const DenseThreeDimensionalModel *oldModel = m_model;
Chris@0 70 m_model = model;
Chris@0 71 if (!m_model || !m_model->isOK()) return;
Chris@0 72
Chris@320 73 connectSignals(m_model);
Chris@0 74
Chris@461 75 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
Chris@0 76 connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
Chris@461 77 this, SLOT(modelChanged(size_t, size_t)));
Chris@0 78
Chris@474 79 m_peakResolution = 256;
Chris@474 80 if (model->getResolution() > 512) {
Chris@474 81 m_peakResolution = 16;
Chris@474 82 } else if (model->getResolution() > 128) {
Chris@474 83 m_peakResolution = 64;
Chris@474 84 } else if (model->getResolution() > 2) {
Chris@474 85 m_peakResolution = 128;
Chris@474 86 }
Chris@474 87 cacheInvalid();
Chris@474 88
Chris@0 89 emit modelReplaced();
Chris@193 90 emit sliceableModelReplaced(oldModel, model);
Chris@0 91 }
Chris@0 92
Chris@0 93 void
Chris@0 94 Colour3DPlotLayer::cacheInvalid()
Chris@0 95 {
Chris@469 96 delete m_cache;
Chris@469 97 delete m_peaksCache;
Chris@0 98 m_cache = 0;
Chris@469 99 m_peaksCache = 0;
Chris@461 100 m_cacheValidStart = 0;
Chris@461 101 m_cacheValidEnd = 0;
Chris@0 102 }
Chris@0 103
Chris@0 104 void
Chris@461 105 Colour3DPlotLayer::cacheInvalid(size_t startFrame, size_t endFrame)
Chris@0 106 {
Chris@461 107 if (!m_cache) return;
Chris@461 108
Chris@461 109 size_t modelResolution = m_model->getResolution();
Chris@461 110 size_t start = startFrame / modelResolution;
Chris@461 111 size_t end = endFrame / modelResolution + 1;
Chris@461 112 if (m_cacheValidStart < end) m_cacheValidStart = end;
Chris@461 113 if (m_cacheValidEnd > start) m_cacheValidEnd = start;
Chris@461 114 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart;
Chris@461 115 }
Chris@461 116
Chris@461 117 void
Chris@461 118 Colour3DPlotLayer::modelChanged()
Chris@461 119 {
Chris@461 120 if (!m_colourScaleSet && m_colourScale == LinearScale) {
Chris@461 121 if (m_model) {
Chris@461 122 if (m_model->shouldUseLogValueScale()) {
Chris@461 123 setColourScale(LogScale);
Chris@461 124 } else {
Chris@461 125 m_colourScaleSet = true;
Chris@461 126 }
Chris@461 127 }
Chris@461 128 }
Chris@0 129 cacheInvalid();
Chris@0 130 }
Chris@0 131
Chris@461 132 void
Chris@461 133 Colour3DPlotLayer::modelChanged(size_t startFrame, size_t endFrame)
Chris@461 134 {
Chris@461 135 if (!m_colourScaleSet && m_colourScale == LinearScale) {
Chris@461 136 if (m_model && m_model->getWidth() > 50) {
Chris@461 137 if (m_model->shouldUseLogValueScale()) {
Chris@461 138 setColourScale(LogScale);
Chris@461 139 } else {
Chris@461 140 m_colourScaleSet = true;
Chris@461 141 }
Chris@461 142 }
Chris@461 143 }
Chris@461 144 cacheInvalid(startFrame, endFrame);
Chris@461 145 }
Chris@461 146
Chris@159 147 Layer::PropertyList
Chris@159 148 Colour3DPlotLayer::getProperties() const
Chris@159 149 {
Chris@159 150 PropertyList list;
Chris@197 151 list.push_back("Colour");
Chris@159 152 list.push_back("Colour Scale");
Chris@197 153 list.push_back("Normalize Columns");
Chris@197 154 list.push_back("Normalize Visible Area");
Chris@534 155 list.push_back("Gain");
Chris@531 156 list.push_back("Bin Scale");
Chris@357 157 list.push_back("Invert Vertical Scale");
Chris@465 158 list.push_back("Opaque");
Chris@535 159 list.push_back("Smooth");
Chris@159 160 return list;
Chris@159 161 }
Chris@159 162
Chris@159 163 QString
Chris@159 164 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
Chris@159 165 {
Chris@197 166 if (name == "Colour") return tr("Colour");
Chris@197 167 if (name == "Colour Scale") return tr("Scale");
Chris@197 168 if (name == "Normalize Columns") return tr("Normalize Columns");
Chris@197 169 if (name == "Normalize Visible Area") return tr("Normalize Visible Area");
Chris@357 170 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
Chris@534 171 if (name == "Gain") return tr("Gain");
Chris@465 172 if (name == "Opaque") return tr("Always Opaque");
Chris@535 173 if (name == "Smooth") return tr("Smooth");
Chris@531 174 if (name == "Bin Scale") return tr("Bin Scale");
Chris@159 175 return "";
Chris@159 176 }
Chris@159 177
Chris@346 178 QString
Chris@346 179 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
Chris@346 180 {
Chris@346 181 if (name == "Normalize Columns") return "normalise-columns";
Chris@346 182 if (name == "Normalize Visible Area") return "normalise";
Chris@357 183 if (name == "Invert Vertical Scale") return "invert-vertical";
Chris@465 184 if (name == "Opaque") return "opaque";
Chris@535 185 if (name == "Smooth") return "smooth";
Chris@346 186 return "";
Chris@346 187 }
Chris@346 188
Chris@159 189 Layer::PropertyType
Chris@159 190 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
Chris@159 191 {
Chris@534 192 if (name == "Gain") return RangeProperty;
Chris@197 193 if (name == "Normalize Columns") return ToggleProperty;
Chris@197 194 if (name == "Normalize Visible Area") return ToggleProperty;
Chris@357 195 if (name == "Invert Vertical Scale") return ToggleProperty;
Chris@465 196 if (name == "Opaque") return ToggleProperty;
Chris@535 197 if (name == "Smooth") return ToggleProperty;
Chris@159 198 return ValueProperty;
Chris@159 199 }
Chris@159 200
Chris@159 201 QString
Chris@159 202 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
Chris@159 203 {
Chris@197 204 if (name == "Normalize Columns" ||
Chris@197 205 name == "Normalize Visible Area" ||
Chris@534 206 name == "Colour Scale" ||
Chris@534 207 name == "Gain") return tr("Scale");
Chris@531 208 if (name == "Bin Scale" ||
Chris@531 209 name == "Invert Vertical Scale") return tr("Bins");
Chris@465 210 if (name == "Opaque" ||
Chris@535 211 name == "Smooth" ||
Chris@465 212 name == "Colour") return tr("Colour");
Chris@159 213 return QString();
Chris@159 214 }
Chris@159 215
Chris@159 216 int
Chris@159 217 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
Chris@216 218 int *min, int *max, int *deflt) const
Chris@159 219 {
Chris@216 220 int val = 0;
Chris@159 221
Chris@216 222 int garbage0, garbage1, garbage2;
Chris@159 223 if (!min) min = &garbage0;
Chris@159 224 if (!max) max = &garbage1;
Chris@216 225 if (!deflt) deflt = &garbage2;
Chris@159 226
Chris@534 227 if (name == "Gain") {
Chris@534 228
Chris@534 229 *min = -50;
Chris@534 230 *max = 50;
Chris@534 231
Chris@534 232 *deflt = lrintf(log10(1.f) * 20.0);;
Chris@534 233 if (*deflt < *min) *deflt = *min;
Chris@534 234 if (*deflt > *max) *deflt = *max;
Chris@534 235
Chris@534 236 val = lrintf(log10(m_gain) * 20.0);
Chris@534 237 if (val < *min) val = *min;
Chris@534 238 if (val > *max) val = *max;
Chris@534 239
Chris@534 240 } else if (name == "Colour Scale") {
Chris@159 241
Chris@159 242 *min = 0;
Chris@509 243 *max = 3;
Chris@216 244 *deflt = (int)LinearScale;
Chris@159 245
Chris@216 246 val = (int)m_colourScale;
Chris@159 247
Chris@197 248 } else if (name == "Colour") {
Chris@197 249
Chris@197 250 *min = 0;
Chris@197 251 *max = ColourMapper::getColourMapCount() - 1;
Chris@216 252 *deflt = 0;
Chris@197 253
Chris@216 254 val = m_colourMap;
Chris@197 255
Chris@197 256 } else if (name == "Normalize Columns") {
Chris@197 257
Chris@216 258 *deflt = 0;
Chris@216 259 val = (m_normalizeColumns ? 1 : 0);
Chris@197 260
Chris@197 261 } else if (name == "Normalize Visible Area") {
Chris@197 262
Chris@216 263 *deflt = 0;
Chris@216 264 val = (m_normalizeVisibleArea ? 1 : 0);
Chris@197 265
Chris@357 266 } else if (name == "Invert Vertical Scale") {
Chris@357 267
Chris@357 268 *deflt = 0;
Chris@357 269 val = (m_invertVertical ? 1 : 0);
Chris@357 270
Chris@531 271 } else if (name == "Bin Scale") {
Chris@531 272
Chris@531 273 *min = 0;
Chris@531 274 *max = 1;
Chris@531 275 *deflt = int(LinearBinScale);
Chris@531 276 val = (int)m_binScale;
Chris@531 277
Chris@465 278 } else if (name == "Opaque") {
Chris@465 279
Chris@465 280 *deflt = 0;
Chris@465 281 val = (m_opaque ? 1 : 0);
Chris@465 282
Chris@535 283 } else if (name == "Smooth") {
Chris@535 284
Chris@535 285 *deflt = 0;
Chris@535 286 val = (m_smooth ? 1 : 0);
Chris@535 287
Chris@159 288 } else {
Chris@216 289 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
Chris@159 290 }
Chris@159 291
Chris@216 292 return val;
Chris@159 293 }
Chris@159 294
Chris@159 295 QString
Chris@159 296 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
Chris@159 297 int value) const
Chris@159 298 {
Chris@197 299 if (name == "Colour") {
Chris@197 300 return ColourMapper::getColourMapName(value);
Chris@197 301 }
Chris@159 302 if (name == "Colour Scale") {
Chris@159 303 switch (value) {
Chris@159 304 default:
Chris@198 305 case 0: return tr("Linear");
Chris@198 306 case 1: return tr("Log");
Chris@198 307 case 2: return tr("+/-1");
Chris@509 308 case 3: return tr("Absolute");
Chris@159 309 }
Chris@159 310 }
Chris@531 311 if (name == "Bin Scale") {
Chris@531 312 switch (value) {
Chris@531 313 default:
Chris@531 314 case 0: return tr("Linear");
Chris@531 315 case 1: return tr("Log");
Chris@531 316 }
Chris@531 317 }
Chris@159 318 return tr("<unknown>");
Chris@159 319 }
Chris@159 320
Chris@534 321 RangeMapper *
Chris@534 322 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const
Chris@534 323 {
Chris@534 324 if (name == "Gain") {
Chris@534 325 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
Chris@534 326 }
Chris@534 327 return 0;
Chris@534 328 }
Chris@534 329
Chris@159 330 void
Chris@159 331 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
Chris@159 332 {
Chris@534 333 if (name == "Gain") {
Chris@534 334 setGain(pow(10, float(value)/20.0));
Chris@534 335 } else if (name == "Colour Scale") {
Chris@159 336 switch (value) {
Chris@159 337 default:
Chris@159 338 case 0: setColourScale(LinearScale); break;
Chris@197 339 case 1: setColourScale(LogScale); break;
Chris@197 340 case 2: setColourScale(PlusMinusOneScale); break;
Chris@509 341 case 3: setColourScale(AbsoluteScale); break;
Chris@159 342 }
Chris@197 343 } else if (name == "Colour") {
Chris@197 344 setColourMap(value);
Chris@197 345 } else if (name == "Normalize Columns") {
Chris@197 346 setNormalizeColumns(value ? true : false);
Chris@197 347 } else if (name == "Normalize Visible Area") {
Chris@197 348 setNormalizeVisibleArea(value ? true : false);
Chris@357 349 } else if (name == "Invert Vertical Scale") {
Chris@357 350 setInvertVertical(value ? true : false);
Chris@465 351 } else if (name == "Opaque") {
Chris@465 352 setOpaque(value ? true : false);
Chris@535 353 } else if (name == "Smooth") {
Chris@535 354 setSmooth(value ? true : false);
Chris@531 355 } else if (name == "Bin Scale") {
Chris@531 356 switch (value) {
Chris@531 357 default:
Chris@531 358 case 0: setBinScale(LinearBinScale); break;
Chris@531 359 case 1: setBinScale(LogBinScale); break;
Chris@531 360 }
Chris@159 361 }
Chris@159 362 }
Chris@159 363
Chris@159 364 void
Chris@159 365 Colour3DPlotLayer::setColourScale(ColourScale scale)
Chris@159 366 {
Chris@159 367 if (m_colourScale == scale) return;
Chris@159 368 m_colourScale = scale;
Chris@461 369 m_colourScaleSet = true;
Chris@159 370 cacheInvalid();
Chris@159 371 emit layerParametersChanged();
Chris@159 372 }
Chris@159 373
Chris@197 374 void
Chris@197 375 Colour3DPlotLayer::setColourMap(int map)
Chris@197 376 {
Chris@197 377 if (m_colourMap == map) return;
Chris@197 378 m_colourMap = map;
Chris@197 379 cacheInvalid();
Chris@197 380 emit layerParametersChanged();
Chris@197 381 }
Chris@197 382
Chris@197 383 void
Chris@534 384 Colour3DPlotLayer::setGain(float gain)
Chris@534 385 {
Chris@534 386 if (m_gain == gain) return;
Chris@534 387 m_gain = gain;
Chris@534 388 cacheInvalid();
Chris@534 389 emit layerParametersChanged();
Chris@534 390 }
Chris@534 391
Chris@534 392 float
Chris@534 393 Colour3DPlotLayer::getGain() const
Chris@534 394 {
Chris@534 395 return m_gain;
Chris@534 396 }
Chris@534 397
Chris@534 398 void
Chris@531 399 Colour3DPlotLayer::setBinScale(BinScale binScale)
Chris@531 400 {
Chris@531 401 if (m_binScale == binScale) return;
Chris@531 402 m_binScale = binScale;
Chris@531 403 cacheInvalid();
Chris@531 404 emit layerParametersChanged();
Chris@531 405 }
Chris@531 406
Chris@531 407 Colour3DPlotLayer::BinScale
Chris@531 408 Colour3DPlotLayer::getBinScale() const
Chris@531 409 {
Chris@531 410 return m_binScale;
Chris@531 411 }
Chris@531 412
Chris@531 413 void
Chris@197 414 Colour3DPlotLayer::setNormalizeColumns(bool n)
Chris@197 415 {
Chris@197 416 if (m_normalizeColumns == n) return;
Chris@197 417 m_normalizeColumns = n;
Chris@197 418 cacheInvalid();
Chris@197 419 emit layerParametersChanged();
Chris@197 420 }
Chris@197 421
Chris@197 422 bool
Chris@197 423 Colour3DPlotLayer::getNormalizeColumns() const
Chris@197 424 {
Chris@197 425 return m_normalizeColumns;
Chris@197 426 }
Chris@197 427
Chris@197 428 void
Chris@197 429 Colour3DPlotLayer::setNormalizeVisibleArea(bool n)
Chris@197 430 {
Chris@197 431 if (m_normalizeVisibleArea == n) return;
Chris@197 432 m_normalizeVisibleArea = n;
Chris@197 433 cacheInvalid();
Chris@197 434 emit layerParametersChanged();
Chris@197 435 }
Chris@197 436
Chris@197 437 bool
Chris@197 438 Colour3DPlotLayer::getNormalizeVisibleArea() const
Chris@197 439 {
Chris@197 440 return m_normalizeVisibleArea;
Chris@197 441 }
Chris@197 442
Chris@357 443 void
Chris@357 444 Colour3DPlotLayer::setInvertVertical(bool n)
Chris@357 445 {
Chris@357 446 if (m_invertVertical == n) return;
Chris@357 447 m_invertVertical = n;
Chris@357 448 cacheInvalid();
Chris@357 449 emit layerParametersChanged();
Chris@357 450 }
Chris@357 451
Chris@465 452 void
Chris@465 453 Colour3DPlotLayer::setOpaque(bool n)
Chris@465 454 {
Chris@465 455 if (m_opaque == n) return;
Chris@465 456 m_opaque = n;
Chris@465 457 emit layerParametersChanged();
Chris@465 458 }
Chris@465 459
Chris@535 460 void
Chris@535 461 Colour3DPlotLayer::setSmooth(bool n)
Chris@535 462 {
Chris@535 463 if (m_smooth == n) return;
Chris@535 464 m_smooth = n;
Chris@535 465 emit layerParametersChanged();
Chris@535 466 }
Chris@535 467
Chris@357 468 bool
Chris@357 469 Colour3DPlotLayer::getInvertVertical() const
Chris@357 470 {
Chris@357 471 return m_invertVertical;
Chris@357 472 }
Chris@357 473
Chris@25 474 bool
Chris@465 475 Colour3DPlotLayer::getOpaque() const
Chris@465 476 {
Chris@465 477 return m_opaque;
Chris@465 478 }
Chris@465 479
Chris@535 480 bool
Chris@535 481 Colour3DPlotLayer::getSmooth() const
Chris@535 482 {
Chris@535 483 return m_smooth;
Chris@535 484 }
Chris@535 485
Chris@475 486 void
Chris@475 487 Colour3DPlotLayer::setLayerDormant(const View *v, bool dormant)
Chris@475 488 {
Chris@475 489 if (dormant) {
Chris@475 490
Chris@475 491 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@475 492 std::cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")"
Chris@475 493 << std::endl;
Chris@475 494 #endif
Chris@475 495
Chris@475 496 if (isLayerDormant(v)) {
Chris@475 497 return;
Chris@475 498 }
Chris@475 499
Chris@475 500 Layer::setLayerDormant(v, true);
Chris@475 501
Chris@475 502 cacheInvalid();
Chris@475 503
Chris@475 504 } else {
Chris@475 505
Chris@475 506 Layer::setLayerDormant(v, false);
Chris@475 507 }
Chris@475 508 }
Chris@475 509
Chris@465 510 bool
Chris@44 511 Colour3DPlotLayer::isLayerScrollable(const View *v) const
Chris@25 512 {
Chris@197 513 if (m_normalizeVisibleArea) return false;
Chris@25 514 QPoint discard;
Chris@44 515 return !v->shouldIlluminateLocalFeatures(this, discard);
Chris@25 516 }
Chris@25 517
Chris@444 518 bool
Chris@444 519 Colour3DPlotLayer::getValueExtents(float &min, float &max,
Chris@444 520 bool &logarithmic, QString &unit) const
Chris@444 521 {
Chris@444 522 if (!m_model) return false;
Chris@444 523
Chris@444 524 min = 0;
Chris@444 525 max = m_model->getHeight();
Chris@444 526
Chris@444 527 logarithmic = false;
Chris@444 528 unit = "";
Chris@444 529
Chris@444 530 return true;
Chris@444 531 }
Chris@444 532
Chris@444 533 bool
Chris@444 534 Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const
Chris@444 535 {
Chris@444 536 if (!m_model) return false;
Chris@444 537
Chris@444 538 min = m_miny;
Chris@444 539 max = m_maxy;
Chris@444 540 if (max <= min) {
Chris@444 541 min = 0;
Chris@444 542 max = m_model->getHeight();
Chris@444 543 }
Chris@444 544 if (min < 0) min = 0;
Chris@444 545 if (max > m_model->getHeight()) max = m_model->getHeight();
Chris@444 546
Chris@444 547 return true;
Chris@444 548 }
Chris@444 549
Chris@444 550 bool
Chris@444 551 Colour3DPlotLayer::setDisplayExtents(float min, float max)
Chris@444 552 {
Chris@444 553 if (!m_model) return false;
Chris@444 554
Chris@444 555 m_miny = lrintf(min);
Chris@444 556 m_maxy = lrintf(max);
Chris@444 557
Chris@444 558 emit layerParametersChanged();
Chris@444 559 return true;
Chris@444 560 }
Chris@444 561
Chris@444 562 int
Chris@444 563 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
Chris@444 564 {
Chris@444 565 if (!m_model) return 0;
Chris@444 566
Chris@444 567 defaultStep = 0;
Chris@444 568 int h = m_model->getHeight();
Chris@444 569 return h;
Chris@444 570 }
Chris@444 571
Chris@444 572 int
Chris@444 573 Colour3DPlotLayer::getCurrentVerticalZoomStep() const
Chris@444 574 {
Chris@444 575 if (!m_model) return 0;
Chris@444 576
Chris@444 577 float min, max;
Chris@444 578 getDisplayExtents(min, max);
Chris@444 579 return m_model->getHeight() - lrintf(max - min);
Chris@444 580 }
Chris@444 581
Chris@444 582 void
Chris@444 583 Colour3DPlotLayer::setVerticalZoomStep(int step)
Chris@444 584 {
Chris@444 585 if (!m_model) return;
Chris@444 586
Chris@445 587 // std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << std::endl;
Chris@444 588
Chris@444 589 int dist = m_model->getHeight() - step;
Chris@444 590 if (dist < 1) dist = 1;
Chris@444 591 float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f;
Chris@444 592 m_miny = lrintf(centre - float(dist)/2);
Chris@444 593 if (m_miny < 0) m_miny = 0;
Chris@444 594 m_maxy = m_miny + dist;
Chris@444 595 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight();
Chris@444 596
Chris@445 597 // std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << std::endl;
Chris@444 598
Chris@444 599 emit layerParametersChanged();
Chris@444 600 }
Chris@444 601
Chris@444 602 RangeMapper *
Chris@444 603 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const
Chris@444 604 {
Chris@444 605 if (!m_model) return 0;
Chris@444 606
Chris@444 607 return new LinearRangeMapper(0, m_model->getHeight(),
Chris@444 608 0, m_model->getHeight(), "");
Chris@444 609 }
Chris@444 610
Chris@532 611 float
Chris@532 612 Colour3DPlotLayer::getYForBin(View *v, float bin) const
Chris@532 613 {
Chris@532 614 float y = bin;
Chris@532 615 if (!m_model) return y;
Chris@532 616 float mn = 0, mx = m_model->getHeight();
Chris@532 617 getDisplayExtents(mn, mx);
Chris@532 618 float h = v->height();
Chris@532 619 if (m_binScale == LinearBinScale) {
Chris@532 620 y = h - (((bin - mn) * h) / (mx - mn));
Chris@532 621 } else {
Chris@532 622 float logmin = mn + 1, logmax = mx + 1;
Chris@532 623 LogRange::mapRange(logmin, logmax);
Chris@532 624 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin));
Chris@532 625 }
Chris@532 626 return y;
Chris@532 627 }
Chris@532 628
Chris@532 629 float
Chris@532 630 Colour3DPlotLayer::getBinForY(View *v, float y) const
Chris@532 631 {
Chris@532 632 float bin = y;
Chris@532 633 if (!m_model) return bin;
Chris@532 634 float mn = 0, mx = m_model->getHeight();
Chris@532 635 getDisplayExtents(mn, mx);
Chris@532 636 float h = v->height();
Chris@532 637 if (m_binScale == LinearBinScale) {
Chris@532 638 bin = mn + ((h - y) * (mx - mn)) / h;
Chris@532 639 } else {
Chris@532 640 float logmin = mn + 1, logmax = mx + 1;
Chris@532 641 LogRange::mapRange(logmin, logmax);
Chris@532 642 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1;
Chris@532 643 }
Chris@532 644 return bin;
Chris@532 645 }
Chris@532 646
Chris@25 647 QString
Chris@44 648 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const
Chris@25 649 {
Chris@25 650 if (!m_model) return "";
Chris@25 651
Chris@25 652 int x = pos.x();
Chris@25 653 int y = pos.y();
Chris@25 654
Chris@25 655 size_t modelStart = m_model->getStartFrame();
Chris@130 656 size_t modelResolution = m_model->getResolution();
Chris@25 657
Chris@159 658 float srRatio =
Chris@159 659 float(v->getViewManager()->getMainModelSampleRate()) /
Chris@159 660 float(m_model->getSampleRate());
Chris@159 661
Chris@160 662 int sx0 = int((v->getFrameForX(x) / srRatio - long(modelStart)) /
Chris@160 663 long(modelResolution));
Chris@25 664
Chris@160 665 int f0 = sx0 * modelResolution;
Chris@160 666 int f1 = f0 + modelResolution;
Chris@160 667
Chris@447 668 int sh = m_model->getHeight();
Chris@447 669
Chris@447 670 int symin = m_miny;
Chris@447 671 int symax = m_maxy;
Chris@447 672 if (symax <= symin) {
Chris@447 673 symin = 0;
Chris@447 674 symax = sh;
Chris@447 675 }
Chris@447 676 if (symin < 0) symin = 0;
Chris@447 677 if (symax > sh) symax = sh;
Chris@447 678
Chris@534 679 // float binHeight = float(v->height()) / (symax - symin);
Chris@534 680 // int sy = int((v->height() - y) / binHeight) + symin;
Chris@534 681
Chris@534 682 int sy = getBinForY(v, y);
Chris@25 683
Chris@357 684 if (m_invertVertical) sy = m_model->getHeight() - sy - 1;
Chris@357 685
Chris@160 686 float value = m_model->getValueAt(sx0, sy);
Chris@159 687
Chris@159 688 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl;
Chris@25 689
Chris@25 690 QString binName = m_model->getBinName(sy);
Chris@25 691 if (binName == "") binName = QString("[%1]").arg(sy + 1);
Chris@25 692 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
Chris@25 693
Chris@25 694 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
Chris@160 695 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate())
Chris@25 696 .toText(true).c_str())
Chris@160 697 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate())
Chris@25 698 .toText(true).c_str())
Chris@25 699 .arg(binName)
Chris@25 700 .arg(value);
Chris@25 701
Chris@25 702 return text;
Chris@25 703 }
Chris@25 704
Chris@25 705 int
Chris@248 706 Colour3DPlotLayer::getColourScaleWidth(QPainter &) const
Chris@159 707 {
Chris@159 708 int cw = 20;
Chris@159 709 return cw;
Chris@159 710 }
Chris@159 711
Chris@159 712 int
Chris@248 713 Colour3DPlotLayer::getVerticalScaleWidth(View *, QPainter &paint) const
Chris@25 714 {
Chris@25 715 if (!m_model) return 0;
Chris@25 716
Chris@160 717 QString sampleText = QString("[%1]").arg(m_model->getHeight());
Chris@25 718 int tw = paint.fontMetrics().width(sampleText);
Chris@98 719 bool another = false;
Chris@25 720
Chris@160 721 for (size_t i = 0; i < m_model->getHeight(); ++i) {
Chris@25 722 if (m_model->getBinName(i).length() > sampleText.length()) {
Chris@25 723 sampleText = m_model->getBinName(i);
Chris@98 724 another = true;
Chris@25 725 }
Chris@25 726 }
Chris@98 727 if (another) {
Chris@25 728 tw = std::max(tw, paint.fontMetrics().width(sampleText));
Chris@25 729 }
Chris@25 730
Chris@159 731 return tw + 13 + getColourScaleWidth(paint);
Chris@25 732 }
Chris@25 733
Chris@25 734 void
Chris@44 735 Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const
Chris@25 736 {
Chris@25 737 if (!m_model) return;
Chris@25 738
Chris@25 739 int h = rect.height(), w = rect.width();
Chris@25 740
Chris@159 741 int cw = getColourScaleWidth(paint);
Chris@159 742
Chris@159 743 int ch = h - 20;
Chris@159 744 if (ch > 20 && m_cache) {
Chris@159 745
Chris@447 746 float min = m_model->getMinimumLevel();
Chris@447 747 float max = m_model->getMaximumLevel();
Chris@447 748
Chris@447 749 float mmin = min;
Chris@447 750 float mmax = max;
Chris@447 751
Chris@447 752 if (m_colourScale == LogScale) {
Chris@447 753 LogRange::mapRange(mmin, mmax);
Chris@447 754 } else if (m_colourScale == PlusMinusOneScale) {
Chris@447 755 mmin = -1.f;
Chris@447 756 mmax = 1.f;
Chris@509 757 } else if (m_colourScale == AbsoluteScale) {
Chris@509 758 if (mmin < 0) {
Chris@509 759 if (fabsf(mmin) > fabsf(mmax)) mmax = fabsf(mmin);
Chris@509 760 else mmax = fabsf(mmax);
Chris@509 761 mmin = 0;
Chris@509 762 } else {
Chris@509 763 mmin = fabsf(mmin);
Chris@509 764 mmax = fabsf(mmax);
Chris@509 765 }
Chris@447 766 }
Chris@447 767
Chris@447 768 if (max == min) max = min + 1.0;
Chris@465 769 if (mmax == mmin) mmax = mmin + 1.0;
Chris@447 770
Chris@287 771 paint.setPen(v->getForeground());
Chris@447 772 paint.drawRect(4, 10, cw - 8, ch+1);
Chris@159 773
Chris@446 774 for (int y = 0; y < ch; ++y) {
Chris@447 775 float value = ((max - min) * (ch - y - 1)) / ch + min;
Chris@447 776 if (m_colourScale == LogScale) {
Chris@447 777 value = LogRange::map(value);
Chris@447 778 }
Chris@447 779 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
Chris@465 780 if (pixel >= 0 && pixel < 256) {
Chris@465 781 QRgb c = m_cache->color(pixel);
Chris@465 782 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c)));
Chris@465 783 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
Chris@465 784 } else {
Chris@465 785 std::cerr << "WARNING: Colour3DPlotLayer::paintVerticalScale: value " << value << ", mmin " << mmin << ", mmax " << mmax << " leads to invalid pixel " << pixel << std::endl;
Chris@465 786 }
Chris@159 787 }
Chris@446 788
Chris@446 789 QString minstr = QString("%1").arg(min);
Chris@446 790 QString maxstr = QString("%1").arg(max);
Chris@446 791
Chris@446 792 paint.save();
Chris@446 793
Chris@446 794 QFont font = paint.font();
Chris@446 795 font.setPixelSize(10);
Chris@446 796 paint.setFont(font);
Chris@446 797
Chris@446 798 int msw = paint.fontMetrics().width(maxstr);
Chris@446 799
Chris@446 800 QMatrix m;
Chris@446 801 m.translate(cw - 6, ch + 10);
Chris@446 802 m.rotate(-90);
Chris@446 803
Chris@446 804 paint.setWorldMatrix(m);
Chris@446 805
Chris@446 806 v->drawVisibleText(paint, 2, 0, minstr, View::OutlinedText);
Chris@446 807
Chris@446 808 m.translate(ch - msw - 2, 0);
Chris@446 809 paint.setWorldMatrix(m);
Chris@446 810
Chris@446 811 v->drawVisibleText(paint, 0, 0, maxstr, View::OutlinedText);
Chris@446 812
Chris@446 813 paint.restore();
Chris@159 814 }
Chris@159 815
Chris@287 816 paint.setPen(v->getForeground());
Chris@159 817
Chris@445 818 int sh = m_model->getHeight();
Chris@445 819
Chris@445 820 int symin = m_miny;
Chris@445 821 int symax = m_maxy;
Chris@445 822 if (symax <= symin) {
Chris@445 823 symin = 0;
Chris@445 824 symax = sh;
Chris@445 825 }
Chris@445 826 if (symin < 0) symin = 0;
Chris@445 827 if (symax > sh) symax = sh;
Chris@445 828
Chris@532 829 paint.save();
Chris@456 830
Chris@533 831 int py = h;
Chris@25 832
Chris@534 833 for (size_t i = symin; i <= symax; ++i) {
Chris@98 834
Chris@532 835 int y0;
Chris@534 836
Chris@532 837 y0 = lrintf(getYForBin(v, i));
Chris@532 838 int h = py - y0;
Chris@532 839
Chris@532 840 if (i > symin) {
Chris@532 841 if (paint.fontMetrics().height() >= h) {
Chris@533 842 if (h >= 8) {
Chris@532 843 QFont tf = paint.font();
Chris@533 844 tf.setPixelSize(h-2);
Chris@532 845 paint.setFont(tf);
Chris@532 846 } else {
Chris@532 847 continue;
Chris@532 848 }
Chris@532 849 }
Chris@532 850 }
Chris@25 851
Chris@532 852 py = y0;
Chris@532 853
Chris@534 854 if (i < symax) {
Chris@534 855 paint.drawLine(cw, y0, w, y0);
Chris@534 856 }
Chris@25 857
Chris@532 858 if (i > symin) {
Chris@534 859
Chris@534 860 size_t idx = i - 1;
Chris@534 861 if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
Chris@534 862
Chris@534 863 QString text = m_model->getBinName(idx);
Chris@534 864 if (text == "") text = QString("[%1]").arg(idx + 1);
Chris@534 865
Chris@534 866 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) +
Chris@534 867 paint.fontMetrics().ascent() + 1;
Chris@534 868
Chris@534 869 paint.drawText(cw + 5, ty, text);
Chris@457 870 }
Chris@25 871 }
Chris@456 872
Chris@456 873 paint.restore();
Chris@25 874 }
Chris@25 875
Chris@467 876 DenseThreeDimensionalModel::Column
Chris@467 877 Colour3DPlotLayer::getColumn(size_t col) const
Chris@197 878 {
Chris@467 879 DenseThreeDimensionalModel::Column values = m_model->getColumn(col);
Chris@468 880 while (values.size() < m_model->getHeight()) values.push_back(0.f);
Chris@467 881 if (!m_normalizeColumns) return values;
Chris@461 882
Chris@224 883 float colMax = 0.f, colMin = 0.f;
Chris@461 884 float min = 0.f, max = 0.f;
Chris@197 885
Chris@461 886 min = m_model->getMinimumLevel();
Chris@461 887 max = m_model->getMaximumLevel();
Chris@461 888
Chris@461 889 for (size_t y = 0; y < values.size(); ++y) {
Chris@467 890 if (y == 0 || values.at(y) > colMax) colMax = values.at(y);
Chris@467 891 if (y == 0 || values.at(y) < colMin) colMin = values.at(y);
Chris@197 892 }
Chris@461 893 if (colMin == colMax) colMax = colMin + 1;
Chris@197 894
Chris@197 895 for (size_t y = 0; y < values.size(); ++y) {
Chris@461 896
Chris@467 897 float value = values.at(y);
Chris@461 898 float norm = (value - colMin) / (colMax - colMin);
Chris@467 899 float newvalue = min + (max - min) * norm;
Chris@197 900
Chris@467 901 if (value != newvalue) values[y] = newvalue;
Chris@468 902 }
Chris@468 903
Chris@468 904 return values;
Chris@197 905 }
Chris@197 906
Chris@197 907 void
Chris@197 908 Colour3DPlotLayer::fillCache(size_t firstBin, size_t lastBin) const
Chris@197 909 {
Chris@466 910 Profiler profiler("Colour3DPlotLayer::fillCache");
Chris@476 911
Chris@197 912 size_t modelStart = m_model->getStartFrame();
Chris@197 913 size_t modelEnd = m_model->getEndFrame();
Chris@197 914 size_t modelResolution = m_model->getResolution();
Chris@197 915
Chris@519 916 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@519 917 std::cerr << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << std::endl;
Chris@519 918 #endif
Chris@197 919
Chris@461 920 size_t modelStartBin = modelStart / modelResolution;
Chris@461 921 size_t modelEndBin = modelEnd / modelResolution;
Chris@461 922
Chris@461 923 size_t cacheWidth = modelEndBin - modelStartBin + 1;
Chris@471 924 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1;
Chris@461 925 size_t cacheHeight = m_model->getHeight();
Chris@461 926
Chris@461 927 if (m_cache && (m_cache->height() != int(cacheHeight))) {
Chris@461 928 delete m_cache;
Chris@469 929 delete m_peaksCache;
Chris@461 930 m_cache = 0;
Chris@469 931 m_peaksCache = 0;
Chris@461 932 }
Chris@461 933
Chris@461 934 if (m_cache && (m_cache->width() != int(cacheWidth))) {
Chris@469 935 QImage *newCache =
Chris@469 936 new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight));
Chris@461 937 delete m_cache;
Chris@461 938 m_cache = newCache;
Chris@469 939 if (m_peaksCache) {
Chris@469 940 QImage *newPeaksCache =
Chris@469 941 new QImage(m_peaksCache->copy
Chris@469 942 (0, 0, cacheWidth / m_peakResolution, cacheHeight));
Chris@469 943 delete m_peaksCache;
Chris@469 944 m_peaksCache = newPeaksCache;
Chris@469 945 }
Chris@197 946 }
Chris@197 947
Chris@461 948 if (!m_cache) {
Chris@469 949 m_cache = new QImage
Chris@469 950 (cacheWidth, cacheHeight, QImage::Format_Indexed8);
Chris@461 951 m_cache->setNumColors(256);
Chris@514 952 m_cache->fill(0);
Chris@474 953 if (!m_normalizeVisibleArea) {
Chris@469 954 m_peaksCache = new QImage
Chris@469 955 (cacheWidth / m_peakResolution + 1, cacheHeight,
Chris@469 956 QImage::Format_Indexed8);
Chris@469 957 m_peaksCache->setNumColors(256);
Chris@514 958 m_peaksCache->fill(0);
Chris@469 959 } else if (m_peaksCache) {
Chris@469 960 delete m_peaksCache;
Chris@469 961 m_peaksCache = 0;
Chris@469 962 }
Chris@461 963 m_cacheValidStart = 0;
Chris@461 964 m_cacheValidEnd = 0;
Chris@197 965 }
Chris@197 966
Chris@461 967 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) {
Chris@519 968 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@519 969 std::cerr << "Cache is valid in this region already" << std::endl;
Chris@519 970 #endif
Chris@461 971 return;
Chris@461 972 }
Chris@461 973
Chris@461 974 size_t fillStart = firstBin;
Chris@461 975 size_t fillEnd = lastBin;
Chris@197 976
Chris@461 977 if (fillStart < modelStartBin) fillStart = modelStartBin;
Chris@461 978 if (fillStart > modelEndBin) fillStart = modelEndBin;
Chris@461 979 if (fillEnd < modelStartBin) fillEnd = modelStartBin;
Chris@461 980 if (fillEnd > modelEndBin) fillEnd = modelEndBin;
Chris@197 981
Chris@461 982 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns);
Chris@197 983
Chris@461 984 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) {
Chris@461 985
Chris@461 986 if (m_cacheValidEnd < fillStart) {
Chris@461 987 fillStart = m_cacheValidEnd + 1;
Chris@461 988 }
Chris@461 989 if (m_cacheValidStart > fillEnd) {
Chris@461 990 fillEnd = m_cacheValidStart - 1;
Chris@461 991 }
Chris@461 992
Chris@461 993 m_cacheValidStart = std::min(fillStart, m_cacheValidStart);
Chris@461 994 m_cacheValidEnd = std::max(fillEnd, m_cacheValidEnd);
Chris@461 995
Chris@461 996 } else {
Chris@461 997
Chris@461 998 // the only valid area, ever, is the currently visible one
Chris@461 999
Chris@461 1000 m_cacheValidStart = fillStart;
Chris@461 1001 m_cacheValidEnd = fillEnd;
Chris@461 1002 }
Chris@461 1003
Chris@519 1004 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@519 1005 std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " will be valid from " << m_cacheValidStart << " to " << m_cacheValidEnd << std::endl;
Chris@519 1006 #endif
Chris@461 1007
Chris@197 1008 DenseThreeDimensionalModel::Column values;
Chris@197 1009
Chris@197 1010 float min = m_model->getMinimumLevel();
Chris@197 1011 float max = m_model->getMaximumLevel();
Chris@197 1012
Chris@197 1013 if (m_colourScale == LogScale) {
Chris@197 1014 LogRange::mapRange(min, max);
Chris@197 1015 } else if (m_colourScale == PlusMinusOneScale) {
Chris@197 1016 min = -1.f;
Chris@197 1017 max = 1.f;
Chris@509 1018 } else if (m_colourScale == AbsoluteScale) {
Chris@509 1019 if (min < 0) {
Chris@509 1020 if (fabsf(min) > fabsf(max)) max = fabsf(min);
Chris@509 1021 else max = fabsf(max);
Chris@509 1022 min = 0;
Chris@509 1023 } else {
Chris@509 1024 min = fabsf(min);
Chris@509 1025 max = fabsf(max);
Chris@509 1026 }
Chris@197 1027 }
Chris@197 1028
Chris@197 1029 if (max == min) max = min + 1.0;
Chris@197 1030
Chris@197 1031 ColourMapper mapper(m_colourMap, 0.f, 255.f);
Chris@197 1032
Chris@197 1033 for (int index = 0; index < 256; ++index) {
Chris@197 1034 QColor colour = mapper.map(index);
Chris@469 1035 m_cache->setColor
Chris@469 1036 (index, qRgb(colour.red(), colour.green(), colour.blue()));
Chris@469 1037 if (m_peaksCache) {
Chris@469 1038 m_peaksCache->setColor
Chris@469 1039 (index, qRgb(colour.red(), colour.green(), colour.blue()));
Chris@469 1040 }
Chris@197 1041 }
Chris@197 1042
Chris@224 1043 float visibleMax = 0.f, visibleMin = 0.f;
Chris@197 1044
Chris@461 1045 if (normalizeVisible) {
Chris@197 1046
Chris@461 1047 for (size_t c = fillStart; c <= fillEnd; ++c) {
Chris@197 1048
Chris@467 1049 values = getColumn(c);
Chris@197 1050
Chris@224 1051 float colMax = 0.f, colMin = 0.f;
Chris@197 1052
Chris@461 1053 for (size_t y = 0; y < cacheHeight; ++y) {
Chris@197 1054 if (y >= values.size()) break;
Chris@197 1055 if (y == 0 || values[y] > colMax) colMax = values[y];
Chris@224 1056 if (y == 0 || values[y] < colMin) colMin = values[y];
Chris@197 1057 }
Chris@197 1058
Chris@461 1059 if (c == fillStart || colMax > visibleMax) visibleMax = colMax;
Chris@461 1060 if (c == fillStart || colMin < visibleMin) visibleMin = colMin;
Chris@461 1061 }
Chris@461 1062
Chris@461 1063 if (m_colourScale == LogScale) {
Chris@461 1064 visibleMin = LogRange::map(visibleMin);
Chris@461 1065 visibleMax = LogRange::map(visibleMax);
Chris@461 1066 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax);
Chris@509 1067 } else if (m_colourScale == AbsoluteScale) {
Chris@509 1068 if (visibleMin < 0) {
Chris@509 1069 if (fabsf(visibleMin) > fabsf(visibleMax)) visibleMax = fabsf(visibleMin);
Chris@509 1070 else visibleMax = fabsf(visibleMax);
Chris@509 1071 visibleMin = 0;
Chris@509 1072 } else {
Chris@509 1073 visibleMin = fabsf(visibleMin);
Chris@509 1074 visibleMax = fabsf(visibleMax);
Chris@509 1075 }
Chris@197 1076 }
Chris@197 1077 }
Chris@197 1078
Chris@224 1079 if (visibleMin == visibleMax) visibleMax = visibleMin + 1;
Chris@224 1080
Chris@469 1081 int *peaks = 0;
Chris@469 1082 if (m_peaksCache) {
Chris@469 1083 peaks = new int[cacheHeight];
Chris@469 1084 for (int y = 0; y < cacheHeight; ++y) {
Chris@469 1085 peaks[y] = 0;
Chris@469 1086 }
Chris@469 1087 }
Chris@469 1088
Chris@461 1089 for (size_t c = fillStart; c <= fillEnd; ++c) {
Chris@197 1090
Chris@467 1091 values = getColumn(c);
Chris@197 1092
Chris@461 1093 for (size_t y = 0; y < cacheHeight; ++y) {
Chris@197 1094
Chris@197 1095 float value = min;
Chris@197 1096 if (y < values.size()) {
Chris@469 1097 value = values.at(y);
Chris@197 1098 }
Chris@224 1099
Chris@534 1100 value = value * m_gain;
Chris@534 1101
Chris@224 1102 if (m_colourScale == LogScale) {
Chris@224 1103 value = LogRange::map(value);
Chris@509 1104 } else if (m_colourScale == AbsoluteScale) {
Chris@509 1105 value = fabsf(value);
Chris@197 1106 }
Chris@461 1107
Chris@461 1108 if (normalizeVisible) {
Chris@461 1109 float norm = (value - visibleMin) / (visibleMax - visibleMin);
Chris@461 1110 value = min + (max - min) * norm;
Chris@461 1111 }
Chris@197 1112
Chris@197 1113 int pixel = int(((value - min) * 256) / (max - min));
Chris@197 1114 if (pixel < 0) pixel = 0;
Chris@197 1115 if (pixel > 255) pixel = 255;
Chris@469 1116 if (peaks && (pixel > peaks[y])) peaks[y] = pixel;
Chris@197 1117
Chris@357 1118 if (m_invertVertical) {
Chris@461 1119 m_cache->setPixel(c, cacheHeight - y - 1, pixel);
Chris@357 1120 } else {
Chris@461 1121 m_cache->setPixel(c, y, pixel);
Chris@357 1122 }
Chris@197 1123 }
Chris@469 1124
Chris@469 1125 if (peaks) {
Chris@469 1126 size_t notch = (c % m_peakResolution);
Chris@469 1127 if (notch == m_peakResolution-1 || c == fillEnd) {
Chris@469 1128 size_t pc = c / m_peakResolution;
Chris@469 1129 for (size_t y = 0; y < cacheHeight; ++y) {
Chris@469 1130 if (m_invertVertical) {
Chris@469 1131 m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]);
Chris@469 1132 } else {
Chris@469 1133 m_peaksCache->setPixel(pc, y, peaks[y]);
Chris@469 1134 }
Chris@469 1135 }
Chris@469 1136 for (int y = 0; y < cacheHeight; ++y) {
Chris@469 1137 peaks[y] = 0;
Chris@469 1138 }
Chris@469 1139 }
Chris@469 1140 }
Chris@197 1141 }
Chris@469 1142
Chris@469 1143 delete[] peaks;
Chris@197 1144 }
Chris@197 1145
Chris@197 1146 void
Chris@44 1147 Colour3DPlotLayer::paint(View *v, QPainter &paint, QRect rect) const
Chris@0 1148 {
Chris@514 1149 /*
Chris@443 1150 if (m_model) {
Chris@443 1151 std::cerr << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << std::endl;
Chris@443 1152 }
Chris@514 1153 */
Chris@466 1154 Profiler profiler("Colour3DPlotLayer::paint");
Chris@125 1155 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@125 1156 std::cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << std::endl;
Chris@125 1157 #endif
Chris@0 1158
Chris@0 1159 int completion = 0;
Chris@0 1160 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
Chris@0 1161 if (completion > 0) {
Chris@44 1162 paint.fillRect(0, 10, v->width() * completion / 100,
Chris@0 1163 10, QColor(120, 120, 120));
Chris@0 1164 }
Chris@0 1165 return;
Chris@0 1166 }
Chris@0 1167
Chris@197 1168 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect();
Chris@197 1169
Chris@0 1170 size_t modelStart = m_model->getStartFrame();
Chris@0 1171 size_t modelEnd = m_model->getEndFrame();
Chris@130 1172 size_t modelResolution = m_model->getResolution();
Chris@0 1173
Chris@197 1174 // The cache is from the model's start frame to the model's end
Chris@197 1175 // frame at the model's window increment frames per pixel. We
Chris@197 1176 // want to draw from our start frame + x0 * zoomLevel to our start
Chris@197 1177 // frame + x1 * zoomLevel at zoomLevel frames per pixel.
Chris@12 1178
Chris@197 1179 // We have quite different paint mechanisms for rendering "large"
Chris@197 1180 // bins (more than one bin per pixel in both directions) and
Chris@197 1181 // "small". This is "large"; see paintDense below for "small".
Chris@12 1182
Chris@197 1183 int x0 = rect.left();
Chris@197 1184 int x1 = rect.right() + 1;
Chris@12 1185
Chris@197 1186 int h = v->height();
Chris@0 1187
Chris@197 1188 float srRatio =
Chris@197 1189 float(v->getViewManager()->getMainModelSampleRate()) /
Chris@197 1190 float(m_model->getSampleRate());
Chris@0 1191
Chris@197 1192 int sx0 = int((v->getFrameForX(x0) / srRatio - long(modelStart))
Chris@197 1193 / long(modelResolution));
Chris@197 1194 int sx1 = int((v->getFrameForX(x1) / srRatio - long(modelStart))
Chris@197 1195 / long(modelResolution));
Chris@197 1196 int sh = m_model->getHeight();
Chris@159 1197
Chris@444 1198 int symin = m_miny;
Chris@444 1199 int symax = m_maxy;
Chris@444 1200 if (symax <= symin) {
Chris@444 1201 symin = 0;
Chris@444 1202 symax = sh;
Chris@444 1203 }
Chris@444 1204 if (symin < 0) symin = 0;
Chris@444 1205 if (symax > sh) symax = sh;
Chris@444 1206
Chris@197 1207 if (sx0 > 0) --sx0;
Chris@197 1208 fillCache(sx0 < 0 ? 0 : sx0,
Chris@197 1209 sx1 < 0 ? 0 : sx1);
Chris@0 1210
Chris@351 1211 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@466 1212 std::cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << " (zoom level = " << v->getZoomLevel() << ", srRatio = " << srRatio << ")" << std::endl;
Chris@351 1213 #endif
Chris@351 1214
Chris@465 1215 if (m_opaque ||
Chris@535 1216 m_smooth ||
Chris@465 1217 int(m_model->getHeight()) >= v->height() ||
Chris@466 1218 ((modelResolution * srRatio) / v->getZoomLevel()) < 2) {
Chris@347 1219 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@351 1220 std::cerr << "calling paintDense" << std::endl;
Chris@347 1221 #endif
Chris@98 1222 paintDense(v, paint, rect);
Chris@98 1223 return;
Chris@98 1224 }
Chris@98 1225
Chris@125 1226 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@347 1227 std::cerr << "Colour3DPlotLayer::paint: w " << x1-x0 << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sx1-sx0 << ", sh " << sh << std::endl;
Chris@130 1228 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << std::endl;
Chris@125 1229 #endif
Chris@0 1230
Chris@25 1231 QPoint illuminatePos;
Chris@44 1232 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
Chris@54 1233 char labelbuf[10];
Chris@25 1234
Chris@197 1235 for (int sx = sx0; sx <= sx1; ++sx) {
Chris@0 1236
Chris@130 1237 int fx = sx * int(modelResolution);
Chris@0 1238
Chris@351 1239 if (fx + int(modelResolution) <= int(modelStart) ||
Chris@0 1240 fx > int(modelEnd)) continue;
Chris@0 1241
Chris@248 1242 int rx0 = v->getXForFrame(int((fx + int(modelStart)) * srRatio));
Chris@248 1243 int rx1 = v->getXForFrame(int((fx + int(modelStart) + int(modelResolution) + 1) * srRatio));
Chris@54 1244
Chris@159 1245 int rw = rx1 - rx0;
Chris@159 1246 if (rw < 1) rw = 1;
Chris@54 1247
Chris@159 1248 bool showLabel = (rw > 10 &&
Chris@159 1249 paint.fontMetrics().width("0.000000") < rw - 3 &&
Chris@54 1250 paint.fontMetrics().height() < (h / sh));
Chris@98 1251
Chris@444 1252 for (int sy = symin; sy < symax; ++sy) {
Chris@0 1253
Chris@534 1254 int ry0 = getYForBin(v, sy);
Chris@534 1255 int ry1 = getYForBin(v, sy + 1);
Chris@534 1256 QRect r(rx0, ry1, rw, ry0 - ry1);
Chris@534 1257
Chris@0 1258 QRgb pixel = qRgb(255, 255, 255);
Chris@461 1259 if (sx >= 0 && sx < m_cache->width() &&
Chris@0 1260 sy >= 0 && sy < m_cache->height()) {
Chris@461 1261 pixel = m_cache->pixel(sx, sy);
Chris@0 1262 }
Chris@0 1263
Chris@159 1264 if (rw == 1) {
Chris@159 1265 paint.setPen(pixel);
Chris@159 1266 paint.setBrush(Qt::NoBrush);
Chris@159 1267 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1);
Chris@159 1268 continue;
Chris@159 1269 }
Chris@159 1270
Chris@0 1271 QColor pen(255, 255, 255, 80);
Chris@0 1272 QColor brush(pixel);
Chris@159 1273
Chris@159 1274 if (rw > 3 && r.height() > 3) {
Chris@159 1275 brush.setAlpha(160);
Chris@159 1276 }
Chris@159 1277
Chris@0 1278 paint.setPen(Qt::NoPen);
Chris@0 1279 paint.setBrush(brush);
Chris@0 1280
Chris@25 1281 if (illuminate) {
Chris@25 1282 if (r.contains(illuminatePos)) {
Chris@287 1283 paint.setPen(v->getForeground());
Chris@25 1284 }
Chris@25 1285 }
Chris@76 1286
Chris@125 1287 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
Chris@519 1288 // std::cerr << "rect " << r.x() << "," << r.y() << " "
Chris@519 1289 // << r.width() << "x" << r.height() << std::endl;
Chris@125 1290 #endif
Chris@25 1291
Chris@25 1292 paint.drawRect(r);
Chris@0 1293
Chris@54 1294 if (showLabel) {
Chris@461 1295 if (sx >= 0 && sx < m_cache->width() &&
Chris@54 1296 sy >= 0 && sy < m_cache->height()) {
Chris@461 1297 float value = m_model->getValueAt(sx, sy);
Chris@54 1298 sprintf(labelbuf, "%06f", value);
Chris@54 1299 QString text(labelbuf);
Chris@287 1300 paint.setPen(v->getBackground());
Chris@54 1301 paint.drawText(rx0 + 2,
Chris@54 1302 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
Chris@54 1303 text);
Chris@0 1304 }
Chris@0 1305 }
Chris@0 1306 }
Chris@0 1307 }
Chris@98 1308 }
Chris@0 1309
Chris@98 1310 void
Chris@98 1311 Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const
Chris@98 1312 {
Chris@466 1313 Profiler profiler("Colour3DPlotLayer::paintDense");
Chris@463 1314 if (!m_cache) return;
Chris@463 1315
Chris@466 1316 float modelStart = m_model->getStartFrame();
Chris@466 1317 float modelResolution = m_model->getResolution();
Chris@0 1318
Chris@469 1319 int mmsr = v->getViewManager()->getMainModelSampleRate();
Chris@469 1320 int msr = m_model->getSampleRate();
Chris@469 1321 float srRatio = float(mmsr) / float(msr);
Chris@159 1322
Chris@98 1323 int x0 = rect.left();
Chris@98 1324 int x1 = rect.right() + 1;
Chris@0 1325
Chris@470 1326 const int w = x1 - x0; // const so it can be used as array size below
Chris@471 1327 int h = v->height(); // we always paint full height
Chris@160 1328 int sh = m_model->getHeight();
Chris@98 1329
Chris@444 1330 int symin = m_miny;
Chris@444 1331 int symax = m_maxy;
Chris@444 1332 if (symax <= symin) {
Chris@444 1333 symin = 0;
Chris@444 1334 symax = sh;
Chris@444 1335 }
Chris@444 1336 if (symin < 0) symin = 0;
Chris@444 1337 if (symax > sh) symax = sh;
Chris@444 1338
Chris@466 1339 QImage img(w, h, QImage::Format_Indexed8);
Chris@466 1340 img.setColorTable(m_cache->colorTable());
Chris@98 1341
Chris@466 1342 uchar *peaks = new uchar[w];
Chris@466 1343 memset(peaks, 0, w);
Chris@98 1344
Chris@469 1345 int zoomLevel = v->getZoomLevel();
Chris@469 1346
Chris@469 1347 QImage *source = m_cache;
Chris@474 1348
Chris@474 1349 std::cerr << "modelResolution " << modelResolution << ", srRatio "
Chris@474 1350 << srRatio << ", m_peakResolution " << m_peakResolution
Chris@474 1351 << ", zoomLevel " << zoomLevel << ", result "
Chris@474 1352 << ((modelResolution * srRatio * m_peakResolution) / zoomLevel)
Chris@474 1353 << std::endl;
Chris@474 1354
Chris@474 1355 if (m_peaksCache) {
Chris@474 1356 if (((modelResolution * srRatio * m_peakResolution) / zoomLevel) < 1) {
Chris@474 1357 std::cerr << "using peaks cache" << std::endl;
Chris@474 1358 source = m_peaksCache;
Chris@474 1359 modelResolution *= m_peakResolution;
Chris@474 1360 } else {
Chris@474 1361 std::cerr << "not using peaks cache" << std::endl;
Chris@474 1362 }
Chris@469 1363 } else {
Chris@474 1364 std::cerr << "have no peaks cache" << std::endl;
Chris@469 1365 }
Chris@469 1366
Chris@466 1367 int psy1i = -1;
Chris@469 1368 int sw = source->width();
Chris@470 1369
Chris@470 1370 long xf = -1;
Chris@470 1371 long nxf = v->getFrameForX(x0);
Chris@470 1372
Chris@535 1373 float epsilon = 0.000001;
Chris@535 1374
Chris@535 1375 float sxa[w * 2];
Chris@470 1376 for (int x = 0; x < w; ++x) {
Chris@470 1377
Chris@470 1378 xf = nxf;
Chris@470 1379 nxf = xf + zoomLevel;
Chris@470 1380
Chris@470 1381 float sx0 = (float(xf) / srRatio - modelStart) / modelResolution;
Chris@470 1382 float sx1 = (float(nxf) / srRatio - modelStart) / modelResolution;
Chris@470 1383
Chris@535 1384 sxa[x*2] = sx0;
Chris@535 1385 sxa[x*2 + 1] = sx1;
Chris@470 1386 }
Chris@466 1387
Chris@532 1388 float logmin = symin+1, logmax = symax+1;
Chris@532 1389 LogRange::mapRange(logmin, logmax);
Chris@532 1390
Chris@535 1391 if (m_smooth) {
Chris@535 1392
Chris@535 1393 for (int y = 0; y < h; ++y) {
Chris@466 1394
Chris@535 1395 float sy = getBinForY(v, y) - 0.5;
Chris@535 1396 int syi = int(sy + epsilon);
Chris@535 1397 if (syi < 0 || syi >= source->height()) continue;
Chris@531 1398
Chris@535 1399 uchar *targetLine = img.scanLine(y);
Chris@535 1400 uchar *sourceLine = source->scanLine(syi);
Chris@535 1401 uchar *nextSource;
Chris@535 1402 if (syi + 1 < source->height()) {
Chris@535 1403 nextSource = source->scanLine(syi + 1);
Chris@535 1404 } else {
Chris@535 1405 nextSource = sourceLine;
Chris@535 1406 }
Chris@466 1407
Chris@466 1408 for (int x = 0; x < w; ++x) {
Chris@98 1409
Chris@535 1410 targetLine[x] = 0;
Chris@474 1411
Chris@535 1412 float sx0 = sxa[x*2];
Chris@535 1413 int sx0i = int(sx0 + epsilon);
Chris@474 1414 if (sx0i >= sw) break;
Chris@535 1415 if (sx0i < 0) continue;
Chris@98 1416
Chris@535 1417 float a, b, value;
Chris@535 1418
Chris@535 1419 float sx1 = sxa[x*2+1];
Chris@535 1420 if (sx1 > sx0 + 1.f) {
Chris@535 1421 int sx1i = int(sx1);
Chris@535 1422 bool have = false;
Chris@535 1423 for (int sx = sx0i; sx <= sx1i; ++sx) {
Chris@535 1424 if (sx < 0 || sx >= sw) continue;
Chris@535 1425 if (!have) {
Chris@535 1426 a = float(sourceLine[sx]);
Chris@535 1427 b = float(nextSource[sx]);
Chris@535 1428 have = true;
Chris@535 1429 } else {
Chris@535 1430 a = std::max(a, float(sourceLine[sx]));
Chris@535 1431 b = std::max(b, float(nextSource[sx]));
Chris@535 1432 }
Chris@535 1433 }
Chris@535 1434 float yprop = sy - syi;
Chris@535 1435 value = (a * (1.f - yprop) + b * yprop);
Chris@535 1436 } else {
Chris@535 1437 a = float(sourceLine[sx0i]);
Chris@535 1438 b = float(nextSource[sx0i]);
Chris@535 1439 float yprop = sy - syi;
Chris@535 1440 value = (a * (1.f - yprop) + b * yprop);
Chris@535 1441 int oi = sx0i + 1;
Chris@535 1442 float xprop = sx0 - sx0i;
Chris@535 1443 xprop -= 0.5;
Chris@535 1444 if (xprop < 0) {
Chris@535 1445 oi = sx0i - 1;
Chris@535 1446 xprop = -xprop;
Chris@535 1447 }
Chris@535 1448 if (oi < 0 || oi >= sw) oi = sx0i;
Chris@535 1449 a = float(sourceLine[oi]);
Chris@535 1450 b = float(nextSource[oi]);
Chris@535 1451 value = (value * (1.f - xprop) +
Chris@535 1452 (a * (1.f - yprop) + b * yprop) * xprop);
Chris@98 1453 }
Chris@535 1454
Chris@535 1455 int vi = lrintf(value);
Chris@535 1456 if (vi > 255) vi = 255;
Chris@535 1457 if (vi < 0) vi = 0;
Chris@535 1458 targetLine[x] = uchar(vi);
Chris@98 1459 }
Chris@466 1460 }
Chris@535 1461 } else {
Chris@535 1462
Chris@535 1463 for (int y = 0; y < h; ++y) {
Chris@535 1464
Chris@535 1465 float sy0, sy1;
Chris@535 1466
Chris@535 1467 sy0 = getBinForY(v, y + 1);
Chris@535 1468 sy1 = getBinForY(v, y);
Chris@535 1469
Chris@535 1470 int sy0i = int(sy0 + epsilon);
Chris@535 1471 int sy1i = int(sy1);
Chris@535 1472
Chris@535 1473 uchar *targetLine = img.scanLine(y);
Chris@535 1474
Chris@535 1475 if (sy0i == sy1i && sy0i == psy1i) { // same source scan line as just computed
Chris@535 1476 goto copy;
Chris@535 1477 }
Chris@535 1478
Chris@535 1479 for (int x = 0; x < w; ++x) {
Chris@535 1480 peaks[x] = 0;
Chris@535 1481 }
Chris@466 1482
Chris@535 1483 for (int sy = sy0i; sy <= sy1i; ++sy) {
Chris@535 1484
Chris@535 1485 if (sy < 0 || sy >= source->height()) continue;
Chris@535 1486
Chris@535 1487 uchar *sourceLine = source->scanLine(sy);
Chris@535 1488
Chris@535 1489 for (int x = 0; x < w; ++x) {
Chris@535 1490
Chris@535 1491 int sx1i = int(sxa[x*2 + 1]);
Chris@535 1492 if (sx1i < 0) continue;
Chris@535 1493
Chris@535 1494 int sx0i = int(sxa[x*2] + epsilon);
Chris@535 1495 if (sx0i >= sw) break;
Chris@535 1496
Chris@535 1497 uchar peak = 0;
Chris@535 1498 for (int sx = sx0i; sx <= sx1i; ++sx) {
Chris@535 1499 if (sx < 0 || sx >= sw) continue;
Chris@535 1500 if (sourceLine[sx] > peak) peak = sourceLine[sx];
Chris@535 1501 }
Chris@535 1502 peaks[x] = peak;
Chris@535 1503 }
Chris@535 1504 }
Chris@535 1505
Chris@535 1506 copy:
Chris@535 1507 for (int x = 0; x < w; ++x) {
Chris@535 1508 targetLine[x] = peaks[x];
Chris@535 1509 }
Chris@98 1510 }
Chris@0 1511 }
Chris@0 1512
Chris@469 1513 delete[] peaks;
Chris@469 1514
Chris@98 1515 paint.drawImage(x0, 0, img);
Chris@0 1516 }
Chris@0 1517
Chris@28 1518 bool
Chris@44 1519 Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame,
Chris@28 1520 size_t &resolution,
Chris@28 1521 SnapType snap) const
Chris@24 1522 {
Chris@24 1523 if (!m_model) {
Chris@44 1524 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
Chris@24 1525 }
Chris@24 1526
Chris@130 1527 resolution = m_model->getResolution();
Chris@28 1528 int left = (frame / resolution) * resolution;
Chris@28 1529 int right = left + resolution;
Chris@28 1530
Chris@28 1531 switch (snap) {
Chris@28 1532 case SnapLeft: frame = left; break;
Chris@28 1533 case SnapRight: frame = right; break;
Chris@28 1534 case SnapNearest:
Chris@28 1535 case SnapNeighbouring:
Chris@28 1536 if (frame - left > right - frame) frame = right;
Chris@28 1537 else frame = left;
Chris@28 1538 break;
Chris@28 1539 }
Chris@24 1540
Chris@28 1541 return true;
Chris@24 1542 }
Chris@24 1543
Chris@316 1544 void
Chris@316 1545 Colour3DPlotLayer::toXml(QTextStream &stream,
Chris@316 1546 QString indent, QString extraAttributes) const
Chris@197 1547 {
Chris@316 1548 QString s = QString("scale=\"%1\" "
Chris@316 1549 "colourScheme=\"%2\" "
Chris@316 1550 "normalizeColumns=\"%3\" "
Chris@445 1551 "normalizeVisibleArea=\"%4\" "
Chris@445 1552 "minY=\"%5\" "
Chris@465 1553 "maxY=\"%6\" "
Chris@465 1554 "invertVertical=\"%7\" "
Chris@535 1555 "opaque=\"%8\" %9")
Chris@197 1556 .arg((int)m_colourScale)
Chris@197 1557 .arg(m_colourMap)
Chris@197 1558 .arg(m_normalizeColumns ? "true" : "false")
Chris@445 1559 .arg(m_normalizeVisibleArea ? "true" : "false")
Chris@445 1560 .arg(m_miny)
Chris@465 1561 .arg(m_maxy)
Chris@465 1562 .arg(m_invertVertical ? "true" : "false")
Chris@534 1563 .arg(m_opaque ? "true" : "false")
Chris@535 1564 .arg(QString("binScale=\"%1\" smooth=\"%2\" ")
Chris@535 1565 .arg((int)m_binScale)
Chris@535 1566 .arg(m_smooth ? "true" : "false"));
Chris@535 1567
Chris@316 1568 Layer::toXml(stream, indent, extraAttributes + " " + s);
Chris@197 1569 }
Chris@197 1570
Chris@197 1571 void
Chris@197 1572 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
Chris@197 1573 {
Chris@445 1574 bool ok = false, alsoOk = false;
Chris@197 1575
Chris@197 1576 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok);
Chris@197 1577 if (ok) setColourScale(scale);
Chris@197 1578
Chris@197 1579 int colourMap = attributes.value("colourScheme").toInt(&ok);
Chris@197 1580 if (ok) setColourMap(colourMap);
Chris@197 1581
Chris@534 1582 BinScale binscale = (BinScale)attributes.value("binScale").toInt(&ok);
Chris@534 1583 if (ok) setBinScale(binscale);
Chris@534 1584
Chris@197 1585 bool normalizeColumns =
Chris@197 1586 (attributes.value("normalizeColumns").trimmed() == "true");
Chris@197 1587 setNormalizeColumns(normalizeColumns);
Chris@197 1588
Chris@197 1589 bool normalizeVisibleArea =
Chris@197 1590 (attributes.value("normalizeVisibleArea").trimmed() == "true");
Chris@197 1591 setNormalizeVisibleArea(normalizeVisibleArea);
Chris@445 1592
Chris@465 1593 bool invertVertical =
Chris@465 1594 (attributes.value("invertVertical").trimmed() == "true");
Chris@465 1595 setInvertVertical(invertVertical);
Chris@465 1596
Chris@465 1597 bool opaque =
Chris@465 1598 (attributes.value("opaque").trimmed() == "true");
Chris@535 1599 setOpaque(opaque);
Chris@535 1600
Chris@535 1601 bool smooth =
Chris@535 1602 (attributes.value("smooth").trimmed() == "true");
Chris@535 1603 setSmooth(smooth);
Chris@465 1604
Chris@445 1605 float min = attributes.value("minY").toFloat(&ok);
Chris@445 1606 float max = attributes.value("maxY").toFloat(&alsoOk);
Chris@445 1607 if (ok && alsoOk) setDisplayExtents(min, max);
Chris@197 1608 }
Chris@197 1609