comparison layer/Colour3DPlotLayer.cpp @ 224:9465b5375235

* Fix #1672407 confused by plugin-named files in cwd (or home?) * Fix #1491848 crash when loading new file while transform plugin runs * Fix #1502287 Background remains black after spectrogram layer deleted * Fix #1604477 Replacing the main audio file silences secondary audio file * Fix failure to initialise property box layout to last preference on startup * Fix resample/wrong-rate display in Pane, ensure that right rate is chosen if all current models have an acceptable rate even if previous main model had a different one * Fix "global zoom" broken in previous commit * Some fixes to spectrogram cache area updating (makes spectrogram appear more quickly, previously it had a tendency to refresh with empty space) * Fixes to colour 3d plot normalization
author Chris Cannam
date Thu, 08 Mar 2007 16:53:08 +0000
parents 34bbbcb3c01f
children 28c8e8e3c537
comparison
equal deleted inserted replaced
223:403bfb88d8d6 224:9465b5375235
382 Colour3DPlotLayer::getColumn(size_t col, 382 Colour3DPlotLayer::getColumn(size_t col,
383 DenseThreeDimensionalModel::Column &values) const 383 DenseThreeDimensionalModel::Column &values) const
384 { 384 {
385 m_model->getColumn(col, values); 385 m_model->getColumn(col, values);
386 386
387 float colMax = 0.f; 387 float colMax = 0.f, colMin = 0.f;
388 388
389 float min = 0.f, max = 0.f; 389 float min = 0.f, max = 0.f;
390 if (m_normalizeColumns) { 390 if (m_normalizeColumns) {
391 min = m_model->getMinimumLevel(); 391 min = m_model->getMinimumLevel();
392 max = m_model->getMaximumLevel(); 392 max = m_model->getMaximumLevel();
393 } 393 }
394 394
395 if (m_normalizeColumns) { 395 if (m_normalizeColumns) {
396 for (size_t y = 0; y < values.size(); ++y) { 396 for (size_t y = 0; y < values.size(); ++y) {
397 if (values[y] > colMax || y == 0) colMax = values[y]; 397 if (y == 0 || values[y] > colMax) colMax = values[y];
398 if (y == 0 || values[y] < colMin) colMin = values[y];
398 } 399 }
399 if (m_colourScale == LogScale) { 400 if (colMin == colMax) colMax = colMin + 1;
400 colMax = LogRange::map(colMax);
401 }
402 } 401 }
403 402
404 for (size_t y = 0; y < values.size(); ++y) { 403 for (size_t y = 0; y < values.size(); ++y) {
405 404
406 float value = min; 405 float value = min;
407 406
408 value = values[y]; 407 value = values[y];
409 if (m_colourScale == LogScale) {
410 value = LogRange::map(value);
411 }
412 408
413 if (m_normalizeColumns) { 409 if (m_normalizeColumns) {
414 if (colMax != 0) { 410 float norm = (value - colMin) / (colMax - colMin);
415 value = max * (value / colMax); 411 value = min + (max - min) * norm;
416 } else {
417 value = 0;
418 }
419 } 412 }
420 413
421 values[y] = value; 414 values[y] = value;
422 } 415 }
423 } 416 }
427 { 420 {
428 size_t modelStart = m_model->getStartFrame(); 421 size_t modelStart = m_model->getStartFrame();
429 size_t modelEnd = m_model->getEndFrame(); 422 size_t modelEnd = m_model->getEndFrame();
430 size_t modelResolution = m_model->getResolution(); 423 size_t modelResolution = m_model->getResolution();
431 424
432 std::cerr << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << std::endl; 425 // std::cerr << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << std::endl;
433 426
434 if (!m_normalizeVisibleArea || m_normalizeColumns) { 427 if (!m_normalizeVisibleArea || m_normalizeColumns) {
435 firstBin = modelStart / modelResolution; 428 firstBin = modelStart / modelResolution;
436 lastBin = modelEnd / modelResolution; 429 lastBin = modelEnd / modelResolution;
437 } 430 }
451 if (m_cache) return; 444 if (m_cache) return;
452 445
453 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); 446 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8);
454 m_cacheStart = firstBin; 447 m_cacheStart = firstBin;
455 448
456 std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " starting " << m_cacheStart << std::endl; 449 // std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " starting " << m_cacheStart << std::endl;
457 450
458 m_cache->setNumColors(256); 451 m_cache->setNumColors(256);
459 DenseThreeDimensionalModel::Column values; 452 DenseThreeDimensionalModel::Column values;
460 453
461 float min = m_model->getMinimumLevel(); 454 float min = m_model->getMinimumLevel();
478 m_cache->setColor(index, qRgb(colour.red(), colour.green(), colour.blue())); 471 m_cache->setColor(index, qRgb(colour.red(), colour.green(), colour.blue()));
479 } 472 }
480 473
481 m_cache->fill(0); 474 m_cache->fill(0);
482 475
483 float visibleMax = 0.f; 476 float visibleMax = 0.f, visibleMin = 0.f;
484 477
485 if (m_normalizeVisibleArea && !m_normalizeColumns) { 478 if (m_normalizeVisibleArea && !m_normalizeColumns) {
486 479
487 for (size_t c = firstBin; c <= lastBin; ++c) { 480 for (size_t c = firstBin; c <= lastBin; ++c) {
488 481
489 values.clear(); 482 values.clear();
490 getColumn(c, values); 483 getColumn(c, values);
491 484
492 float colMax = 0.f; 485 float colMax = 0.f, colMin = 0.f;
493 486
494 for (size_t y = 0; y < m_model->getHeight(); ++y) { 487 for (size_t y = 0; y < m_model->getHeight(); ++y) {
495 if (y >= values.size()) break; 488 if (y >= values.size()) break;
496 if (y == 0 || values[y] > colMax) colMax = values[y]; 489 if (y == 0 || values[y] > colMax) colMax = values[y];
490 if (y == 0 || values[y] < colMin) colMin = values[y];
497 } 491 }
498 492
499 if (c == firstBin || colMax > visibleMax) visibleMax = colMax; 493 if (c == firstBin || colMax > visibleMax) visibleMax = colMax;
494 if (c == firstBin || colMin < visibleMin) visibleMin = colMin;
500 } 495 }
501 } 496 }
502 497
498 if (visibleMin == visibleMax) visibleMax = visibleMin + 1;
499
503 for (size_t c = firstBin; c <= lastBin; ++c) { 500 for (size_t c = firstBin; c <= lastBin; ++c) {
504 501
505 values.clear(); 502 values.clear();
506 getColumn(c, values); 503 getColumn(c, values);
507 504
511 if (y < values.size()) { 508 if (y < values.size()) {
512 value = values[y]; 509 value = values[y];
513 } 510 }
514 511
515 if (m_normalizeVisibleArea && !m_normalizeColumns) { 512 if (m_normalizeVisibleArea && !m_normalizeColumns) {
516 if (visibleMax != 0) { 513 float norm = (value - visibleMin) / (visibleMax - visibleMin);
517 value = max * (value / visibleMax); 514 value = min + (max - min) * norm;
518 } 515 }
516
517 if (m_colourScale == LogScale) {
518 value = LogRange::map(value);
519 } 519 }
520 520
521 int pixel = int(((value - min) * 256) / (max - min)); 521 int pixel = int(((value - min) * 256) / (max - min));
522 if (pixel < 0) pixel = 0; 522 if (pixel < 0) pixel = 0;
523 if (pixel > 255) pixel = 255; 523 if (pixel > 255) pixel = 255;