annotate layer/Colour3DPlotExporter.h @ 1605:ae2d5f8ff005

When asked to render the whole view width, we need to wait for the layers to be ready before we can determine what the width is
author Chris Cannam
date Thu, 30 Apr 2020 14:47:13 +0100
parents 32171776fcc9
children
rev   line source
Chris@1554 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1554 2
Chris@1554 3 /*
Chris@1554 4 Sonic Visualiser
Chris@1554 5 An audio file viewer and annotation editor.
Chris@1554 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1554 7
Chris@1554 8 This program is free software; you can redistribute it and/or
Chris@1554 9 modify it under the terms of the GNU General Public License as
Chris@1554 10 published by the Free Software Foundation; either version 2 of the
Chris@1554 11 License, or (at your option) any later version. See the file
Chris@1554 12 COPYING included with this distribution for more information.
Chris@1554 13 */
Chris@1554 14
Chris@1554 15 #ifndef COLOUR_3D_PLOT_EXPORTER_H
Chris@1554 16 #define COLOUR_3D_PLOT_EXPORTER_H
Chris@1554 17
Chris@1554 18 #include "Colour3DPlotRenderer.h"
Chris@1554 19
Chris@1554 20 class Colour3DPlotExporter : public Model
Chris@1554 21 {
Chris@1554 22 Q_OBJECT
Chris@1554 23
Chris@1554 24 public:
Chris@1554 25 struct Sources {
Chris@1554 26 // These must all outlive this class, or else discardSources()
Chris@1554 27 // must be called
Chris@1554 28 const VerticalBinLayer *verticalBinLayer; // always
Chris@1554 29 ModelId source; // always; a DenseThreeDimensionalModel
Chris@1554 30 ModelId fft; // optionally; an FFTModel; used for phase/peak-freq modes
Chris@1554 31 const LayerGeometryProvider *provider; // optionally
Chris@1554 32 };
Chris@1554 33
Chris@1554 34 struct Parameters {
Chris@1554 35 Parameters() :
Chris@1561 36 binDisplay(BinDisplay::AllBins),
Chris@1561 37 scaleFactor(1.0),
Chris@1561 38 threshold(0.0),
Chris@1561 39 gain(1.0),
Chris@1568 40 normalization(ColumnNormalization::None) { }
Chris@1554 41
Chris@1570 42 /** Selection of bins to include in the export. If a
Chris@1570 43 * LayerGeometryProvider is also included in Sources, then
Chris@1570 44 * the set of bins will also be constrained to the vertical
Chris@1570 45 * range of that. */
Chris@1554 46 BinDisplay binDisplay;
Chris@1561 47
Chris@1561 48 /** Initial scale factor (e.g. for FFT scaling). This factor
Chris@1561 49 * is actually applied to exported values, in contrast to the
Chris@1561 50 * gain value below based on the ColourScale parameter. */
Chris@1561 51 double scaleFactor;
Chris@1561 52
Chris@1561 53 /** Threshold below which every value is mapped to background
Chris@1561 54 * pixel 0 in the display, matching the ColourScale object
Chris@1561 55 * parameters. This is used for thresholding in
Chris@1561 56 * peak-frequency output only. */
Chris@1561 57 double threshold;
Chris@1561 58
Chris@1561 59 /** Gain that is applied before thresholding, in the display,
Chris@1561 60 * matching the ColourScale object parameters. This is used
Chris@1561 61 * only to determined the thresholding level. The exported
Chris@1561 62 * values have the scaleFactor applied, but not this gain. */
Chris@1561 63 double gain;
Chris@1561 64
Chris@1561 65 /** Type of column normalization. Again, this is only used to
Chris@1561 66 * calculate thresholding level. The exported values are
Chris@1561 67 * un-normalized. */
Chris@1561 68 ColumnNormalization normalization;
Chris@1554 69 };
Chris@1554 70
Chris@1556 71 Colour3DPlotExporter(Sources sources, Parameters parameters);
Chris@1556 72 ~Colour3DPlotExporter();
Chris@1554 73
Chris@1556 74 void discardSources();
Chris@1565 75
Chris@1593 76 QVector<QString>
Chris@1593 77 getStringExportHeaders(DataExportOptions options) const override;
Chris@1565 78
Chris@1593 79 QVector<QVector<QString>>
Chris@1593 80 toStringExportRows(DataExportOptions options,
Chris@1593 81 sv_frame_t startFrame,
Chris@1593 82 sv_frame_t duration) const override;
Chris@1556 83
Chris@1556 84 // Further Model methods that we just delegate
Chris@1556 85
Chris@1556 86 bool isOK() const override {
Chris@1556 87 if (auto model = ModelById::get(m_sources.source)) {
Chris@1556 88 return model->isOK();
Chris@1556 89 }
Chris@1556 90 return false;
Chris@1556 91 }
Chris@1556 92
Chris@1556 93 sv_frame_t getStartFrame() const override {
Chris@1556 94 if (auto model = ModelById::get(m_sources.source)) {
Chris@1556 95 return model->getStartFrame();
Chris@1556 96 }
Chris@1556 97 return 0;
Chris@1556 98 }
Chris@1556 99
Chris@1556 100 sv_frame_t getTrueEndFrame() const override {
Chris@1556 101 if (auto model = ModelById::get(m_sources.source)) {
Chris@1556 102 return model->getTrueEndFrame();
Chris@1556 103 }
Chris@1556 104 return 0;
Chris@1556 105 }
Chris@1556 106
Chris@1556 107 sv_samplerate_t getSampleRate() const override {
Chris@1556 108 if (auto model = ModelById::get(m_sources.source)) {
Chris@1556 109 return model->getSampleRate();
Chris@1556 110 }
Chris@1556 111 return 0;
Chris@1556 112 }
Chris@1556 113
Chris@1556 114 QString getTypeName() const override {
Chris@1556 115 if (auto model = ModelById::get(m_sources.source)) {
Chris@1556 116 return model->getTypeName();
Chris@1556 117 }
Chris@1556 118 return "(exporter)"; // internal fallback, no translation needed
Chris@1556 119 }
Chris@1556 120
Chris@1556 121 int getCompletion() const override {
Chris@1556 122 if (auto model = ModelById::get(m_sources.source)) {
Chris@1556 123 return model->getCompletion();
Chris@1556 124 }
Chris@1556 125 return 0;
Chris@1556 126 }
Chris@1556 127
Chris@1554 128 private:
Chris@1554 129 Sources m_sources;
Chris@1554 130 Parameters m_params;
Chris@1554 131 };
Chris@1554 132
Chris@1554 133 #endif