annotate layer/Colour3DPlotRenderer.h @ 1088:c520f90bbf2e spectrogram-minor-refactor

One FFT model per spectrogram (again!) - but we do still need a magnitude range per view, as views could be showing different regions
author Chris Cannam
date Tue, 05 Jul 2016 08:58:28 +0100
parents 7122aae95a88
children c8683d94442a
rev   line source
Chris@1071 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1071 2
Chris@1071 3 /*
Chris@1071 4 Sonic Visualiser
Chris@1071 5 An audio file viewer and annotation editor.
Chris@1071 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1071 7 This file copyright 2006-2016 Chris Cannam and QMUL.
Chris@1071 8
Chris@1071 9 This program is free software; you can redistribute it and/or
Chris@1071 10 modify it under the terms of the GNU General Public License as
Chris@1071 11 published by the Free Software Foundation; either version 2 of the
Chris@1071 12 License, or (at your option) any later version. See the file
Chris@1071 13 COPYING included with this distribution for more information.
Chris@1071 14 */
Chris@1071 15
Chris@1071 16 #ifndef COLOUR_3D_PLOT_RENDERER_H
Chris@1071 17 #define COLOUR_3D_PLOT_RENDERER_H
Chris@1071 18
Chris@1071 19 #include "ColourScale.h"
Chris@1073 20 #include "ScrollableImageCache.h"
Chris@1071 21
Chris@1071 22 #include "base/ColumnOp.h"
Chris@1073 23 #include "base/MagnitudeRange.h"
Chris@1071 24
Chris@1073 25 #include <QRect>
Chris@1073 26 #include <QPainter>
Chris@1073 27 #include <QImage>
Chris@1073 28
Chris@1073 29 class LayerGeometryProvider;
Chris@1082 30 class VerticalBinLayer;
Chris@1071 31 class DenseThreeDimensionalModel;
Chris@1071 32 class Dense3DModelPeakCache;
Chris@1071 33 class FFTModel;
Chris@1071 34
Chris@1071 35 class Colour3DPlotRenderer
Chris@1071 36 {
Chris@1071 37 public:
Chris@1071 38 enum BinDisplay {
Chris@1071 39 AllBins,
Chris@1071 40 PeakBins,
Chris@1071 41 PeakFrequencies
Chris@1071 42 };
Chris@1071 43
Chris@1071 44 enum BinScale {
Chris@1071 45 LinearBinScale,
Chris@1071 46 LogBinScale
Chris@1071 47 };
Chris@1073 48
Chris@1073 49 struct Sources {
Chris@1082 50 Sources() : geometryProvider(0), verticalBinLayer(0),
Chris@1082 51 source(0), peaks(0), fft(0) { }
Chris@1073 52
Chris@1073 53 // These must all outlive this class
Chris@1073 54 LayerGeometryProvider *geometryProvider; // always
Chris@1082 55 VerticalBinLayer *verticalBinLayer; // always
Chris@1073 56 DenseThreeDimensionalModel *source; // always
Chris@1073 57 Dense3DModelPeakCache *peaks; // optionally
Chris@1073 58 FFTModel *fft; // optionally
Chris@1073 59 };
Chris@1073 60
Chris@1071 61 struct Parameters {
Chris@1071 62 Parameters() :
Chris@1071 63 colourScale(ColourScale::Parameters()),
Chris@1071 64 normalization(ColumnOp::NoNormalization),
Chris@1073 65 binDisplay(AllBins),
Chris@1073 66 binScale(LinearBinScale),
Chris@1073 67 alwaysOpaque(false),
Chris@1073 68 interpolate(false),
Chris@1073 69 invertVertical(false) { }
Chris@1071 70
Chris@1071 71 ColourScale colourScale; // complete ColourScale object by value
Chris@1071 72 ColumnOp::Normalization normalization;
Chris@1071 73 BinDisplay binDisplay;
Chris@1071 74 BinScale binScale;
Chris@1071 75 bool alwaysOpaque;
Chris@1071 76 bool interpolate;
Chris@1071 77 bool invertVertical;
Chris@1071 78 };
Chris@1073 79
Chris@1073 80 Colour3DPlotRenderer(Sources sources, Parameters parameters) :
Chris@1073 81 m_sources(sources),
Chris@1079 82 m_params(parameters)
Chris@1071 83 { }
Chris@1071 84
Chris@1073 85 struct RenderResult {
Chris@1073 86 /**
Chris@1073 87 * The rect that was actually rendered. May be equal to the
Chris@1073 88 * rect that was requested to render, or may be smaller if
Chris@1073 89 * time ran out and the complete flag was not set.
Chris@1073 90 */
Chris@1073 91 QRect rendered;
Chris@1073 92
Chris@1073 93 /**
Chris@1073 94 * The magnitude range of the data in the rendered area.
Chris@1073 95 */
Chris@1073 96 MagnitudeRange range;
Chris@1073 97 };
Chris@1073 98
Chris@1073 99 /**
Chris@1073 100 * Render the requested area using the given painter, obtaining
Chris@1073 101 * geometry (e.g. start frame) from the stored
Chris@1073 102 * LayerGeometryProvider.
Chris@1073 103 *
Chris@1076 104 * The whole rect will be rendered and the returned QRect will be
Chris@1076 105 * equal to the passed QRect. (See renderTimeConstrained for an
Chris@1076 106 * alternative that may render only part of the rect in cases
Chris@1076 107 * where obtaining source data is slow and retaining
Chris@1076 108 * responsiveness is important.)
Chris@1075 109 *
Chris@1075 110 * If the model to render from is not ready, this will throw a
Chris@1075 111 * std::logic_error exception. The model must be ready and the
Chris@1075 112 * layer requesting the render must not be dormant in its view, so
Chris@1075 113 * that the LayerGeometryProvider returns valid results; it is the
Chris@1075 114 * caller's responsibility to ensure these.
Chris@1073 115 */
Chris@1076 116 RenderResult render(QPainter &paint, QRect rect);
Chris@1076 117
Chris@1076 118 /**
Chris@1076 119 * Render the requested area using the given painter, obtaining
Chris@1076 120 * geometry (e.g. start frame) from the stored
Chris@1076 121 * LayerGeometryProvider.
Chris@1076 122 *
Chris@1076 123 * As much of the rect will be rendered as can be managed given
Chris@1076 124 * internal time constraints (using a RenderTimer object
Chris@1076 125 * internally). The returned QRect (the rendered field in the
Chris@1076 126 * RenderResult struct) will contain the area that was
Chris@1076 127 * rendered. Note that we always render the full requested height,
Chris@1076 128 * it's only width that is time-constrained.
Chris@1076 129 *
Chris@1076 130 * If the model to render from is not ready, this will throw a
Chris@1076 131 * std::logic_error exception. The model must be ready and the
Chris@1076 132 * layer requesting the render must not be dormant in its view, so
Chris@1076 133 * that the LayerGeometryProvider returns valid results; it is the
Chris@1076 134 * caller's responsibility to ensure these.
Chris@1076 135 */
Chris@1076 136 RenderResult renderTimeConstrained(QPainter &paint, QRect rect);
Chris@1073 137
Chris@1071 138 private:
Chris@1073 139 Sources m_sources;
Chris@1071 140 Parameters m_params;
Chris@1072 141
Chris@1073 142 // Draw buffer is the target of each partial repaint. It is always
Chris@1073 143 // at view height (not model height) and is cleared and repainted
Chris@1073 144 // on each fragment render. The only reason it's stored as a data
Chris@1073 145 // member is to avoid reallocation.
Chris@1073 146 QImage m_drawBuffer;
Chris@1072 147
Chris@1073 148 // Image cache is our persistent record of the visible area. It is
Chris@1073 149 // always the same size as the view (i.e. the paint size reported
Chris@1073 150 // by the LayerGeometryProvider) and is scrolled and partially
Chris@1073 151 // repainted internally as appropriate. A render request is
Chris@1073 152 // carried out by repainting to cache (via the draw buffer) any
Chris@1073 153 // area that is being requested but is not valid in the cache, and
Chris@1073 154 // then repainting from cache to the requested painter.
Chris@1073 155 ScrollableImageCache m_cache;
Chris@1073 156
Chris@1076 157 RenderResult render(QPainter &paint, QRect rect, bool timeConstrained);
Chris@1080 158 void renderToCache(int x0, int repaintWidth,
Chris@1080 159 bool rightToLeft, bool timeConstrained);
Chris@1083 160 int renderDrawBuffer(int w, int h,
Chris@1083 161 const std::vector<int> &binforx,
Chris@1083 162 const std::vector<double> &binfory,
Chris@1083 163 bool usePeaksCache,
Chris@1083 164 bool rightToLeft,
Chris@1083 165 bool timeConstrained);
Chris@1079 166 void clearDrawBuffer(int w, int h);
Chris@1071 167 };
Chris@1071 168
Chris@1071 169 #endif
Chris@1071 170