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@1103
|
35 enum class BinDisplay {
|
Chris@1103
|
36 AllBins,
|
Chris@1103
|
37 PeakBins,
|
Chris@1103
|
38 PeakFrequencies
|
Chris@1103
|
39 };
|
Chris@1103
|
40
|
Chris@1103
|
41 enum class BinScale {
|
Chris@1103
|
42 Linear,
|
Chris@1103
|
43 Log
|
Chris@1103
|
44 };
|
Chris@1103
|
45
|
Chris@1071
|
46 class Colour3DPlotRenderer
|
Chris@1071
|
47 {
|
Chris@1071
|
48 public:
|
Chris@1073
|
49 struct Sources {
|
Chris@1090
|
50 Sources() : verticalBinLayer(0), source(0), peaks(0), fft(0) { }
|
Chris@1073
|
51
|
Chris@1073
|
52 // These must all outlive this class
|
Chris@1089
|
53 const VerticalBinLayer *verticalBinLayer; // always
|
Chris@1100
|
54 const DenseThreeDimensionalModel *source; // always
|
Chris@1100
|
55 const Dense3DModelPeakCache *peaks; // optionally
|
Chris@1100
|
56 const FFTModel *fft; // optionally
|
Chris@1073
|
57 };
|
Chris@1073
|
58
|
Chris@1071
|
59 struct Parameters {
|
Chris@1071
|
60 Parameters() :
|
Chris@1071
|
61 colourScale(ColourScale::Parameters()),
|
Chris@1104
|
62 normalization(ColumnNormalization::None),
|
Chris@1103
|
63 binDisplay(BinDisplay::AllBins),
|
Chris@1103
|
64 binScale(BinScale::Linear),
|
Chris@1073
|
65 alwaysOpaque(false),
|
Chris@1094
|
66 interpolate(false), //!!! separate out x-interpolate and y-interpolate? the spectrogram actually does (or used to)
|
Chris@1112
|
67 invertVertical(false),
|
Chris@1112
|
68 colourRotation(0) { }
|
Chris@1071
|
69
|
Chris@1071
|
70 ColourScale colourScale; // complete ColourScale object by value
|
Chris@1104
|
71 ColumnNormalization normalization;
|
Chris@1071
|
72 BinDisplay binDisplay;
|
Chris@1071
|
73 BinScale binScale;
|
Chris@1071
|
74 bool alwaysOpaque;
|
Chris@1071
|
75 bool interpolate;
|
Chris@1071
|
76 bool invertVertical;
|
Chris@1112
|
77 int colourRotation;
|
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@1090
|
101 * geometry (e.g. start frame) from the given
|
Chris@1073
|
102 * LayerGeometryProvider.
|
Chris@1073
|
103 *
|
Chris@1090
|
104 * The whole of the supplied rect will be rendered and the
|
Chris@1090
|
105 * returned QRect will be equal to the supplied QRect. (See
|
Chris@1090
|
106 * renderTimeConstrained for an alternative that may render only
|
Chris@1090
|
107 * part of the rect in cases where obtaining source data is slow
|
Chris@1090
|
108 * and retaining responsiveness is important.)
|
Chris@1090
|
109 *
|
Chris@1090
|
110 * Note that Colour3DPlotRenderer retains internal cache state
|
Chris@1090
|
111 * related to the size and position of the supplied
|
Chris@1090
|
112 * LayerGeometryProvider. Although it is valid to call render()
|
Chris@1090
|
113 * successively on the same Colour3DPlotRenderer with different
|
Chris@1090
|
114 * LayerGeometryProviders, it will be much faster to use a
|
Chris@1090
|
115 * dedicated Colour3DPlotRenderer for each LayerGeometryProvider.
|
Chris@1075
|
116 *
|
Chris@1075
|
117 * If the model to render from is not ready, this will throw a
|
Chris@1075
|
118 * std::logic_error exception. The model must be ready and the
|
Chris@1075
|
119 * layer requesting the render must not be dormant in its view, so
|
Chris@1075
|
120 * that the LayerGeometryProvider returns valid results; it is the
|
Chris@1075
|
121 * caller's responsibility to ensure these.
|
Chris@1073
|
122 */
|
Chris@1090
|
123 RenderResult render(LayerGeometryProvider *v, QPainter &paint, QRect rect);
|
Chris@1076
|
124
|
Chris@1076
|
125 /**
|
Chris@1076
|
126 * Render the requested area using the given painter, obtaining
|
Chris@1076
|
127 * geometry (e.g. start frame) from the stored
|
Chris@1076
|
128 * LayerGeometryProvider.
|
Chris@1076
|
129 *
|
Chris@1076
|
130 * As much of the rect will be rendered as can be managed given
|
Chris@1076
|
131 * internal time constraints (using a RenderTimer object
|
Chris@1076
|
132 * internally). The returned QRect (the rendered field in the
|
Chris@1076
|
133 * RenderResult struct) will contain the area that was
|
Chris@1076
|
134 * rendered. Note that we always render the full requested height,
|
Chris@1076
|
135 * it's only width that is time-constrained.
|
Chris@1076
|
136 *
|
Chris@1090
|
137 * Note that Colour3DPlotRenderer retains internal cache state
|
Chris@1090
|
138 * related to the size and position of the supplied
|
Chris@1090
|
139 * LayerGeometryProvider. Although it is valid to call render()
|
Chris@1090
|
140 * successively on the same Colour3DPlotRenderer with different
|
Chris@1090
|
141 * LayerGeometryProviders, it will be much faster to use a
|
Chris@1090
|
142 * dedicated Colour3DPlotRenderer for each LayerGeometryProvider.
|
Chris@1090
|
143 *
|
Chris@1076
|
144 * If the model to render from is not ready, this will throw a
|
Chris@1076
|
145 * std::logic_error exception. The model must be ready and the
|
Chris@1076
|
146 * layer requesting the render must not be dormant in its view, so
|
Chris@1076
|
147 * that the LayerGeometryProvider returns valid results; it is the
|
Chris@1076
|
148 * caller's responsibility to ensure these.
|
Chris@1076
|
149 */
|
Chris@1090
|
150 RenderResult renderTimeConstrained(LayerGeometryProvider *v,
|
Chris@1090
|
151 QPainter &paint, QRect rect);
|
Chris@1096
|
152
|
Chris@1096
|
153 /**
|
Chris@1096
|
154 * Return the area of the largest rectangle within the entire area
|
Chris@1096
|
155 * of the cache that is unavailable in the cache. This is only
|
Chris@1096
|
156 * valid in relation to a preceding render() call which is
|
Chris@1096
|
157 * presumed to have set the area, start frame, and zoom level for
|
Chris@1096
|
158 * the cache. It could be used to establish a suitable region for
|
Chris@1096
|
159 * a subsequent paint request (because if an area is not in the
|
Chris@1096
|
160 * cache, it cannot have been rendered since the cache was
|
Chris@1096
|
161 * cleared).
|
Chris@1096
|
162 *
|
Chris@1096
|
163 * Returns an empty QRect if the cache is entirely valid.
|
Chris@1096
|
164 */
|
Chris@1096
|
165 QRect getLargestUncachedRect();
|
Chris@1073
|
166
|
Chris@1071
|
167 private:
|
Chris@1073
|
168 Sources m_sources;
|
Chris@1071
|
169 Parameters m_params;
|
Chris@1072
|
170
|
Chris@1073
|
171 // Draw buffer is the target of each partial repaint. It is always
|
Chris@1073
|
172 // at view height (not model height) and is cleared and repainted
|
Chris@1073
|
173 // on each fragment render. The only reason it's stored as a data
|
Chris@1073
|
174 // member is to avoid reallocation.
|
Chris@1073
|
175 QImage m_drawBuffer;
|
Chris@1072
|
176
|
Chris@1073
|
177 // Image cache is our persistent record of the visible area. It is
|
Chris@1073
|
178 // always the same size as the view (i.e. the paint size reported
|
Chris@1073
|
179 // by the LayerGeometryProvider) and is scrolled and partially
|
Chris@1073
|
180 // repainted internally as appropriate. A render request is
|
Chris@1073
|
181 // carried out by repainting to cache (via the draw buffer) any
|
Chris@1073
|
182 // area that is being requested but is not valid in the cache, and
|
Chris@1073
|
183 // then repainting from cache to the requested painter.
|
Chris@1073
|
184 ScrollableImageCache m_cache;
|
Chris@1073
|
185
|
Chris@1090
|
186 RenderResult render(LayerGeometryProvider *v,
|
Chris@1090
|
187 QPainter &paint, QRect rect, bool timeConstrained);
|
Chris@1109
|
188
|
Chris@1109
|
189 void renderDirectTranslucent(LayerGeometryProvider *v,
|
Chris@1109
|
190 QPainter &paint, QRect rect);
|
Chris@1109
|
191
|
Chris@1094
|
192 void renderToCachePixelResolution(LayerGeometryProvider *v, int x0,
|
Chris@1094
|
193 int repaintWidth, bool rightToLeft,
|
Chris@1094
|
194 bool timeConstrained);
|
Chris@1109
|
195
|
Chris@1094
|
196 void renderToCacheBinResolution(LayerGeometryProvider *v, int x0,
|
Chris@1094
|
197 int repaintWidth);
|
Chris@1097
|
198
|
Chris@1083
|
199 int renderDrawBuffer(int w, int h,
|
Chris@1083
|
200 const std::vector<int> &binforx,
|
Chris@1083
|
201 const std::vector<double> &binfory,
|
Chris@1083
|
202 bool usePeaksCache,
|
Chris@1083
|
203 bool rightToLeft,
|
Chris@1083
|
204 bool timeConstrained);
|
Chris@1097
|
205
|
Chris@1097
|
206 int renderDrawBufferPeakFrequencies(LayerGeometryProvider *v,
|
Chris@1097
|
207 int w, int h,
|
Chris@1097
|
208 const std::vector<int> &binforx,
|
Chris@1097
|
209 const std::vector<double> &binfory,
|
Chris@1097
|
210 bool rightToLeft,
|
Chris@1097
|
211 bool timeConstrained);
|
Chris@1097
|
212
|
Chris@1095
|
213 void recreateDrawBuffer(int w, int h);
|
Chris@1079
|
214 void clearDrawBuffer(int w, int h);
|
Chris@1109
|
215
|
Chris@1109
|
216 enum RenderType {
|
Chris@1109
|
217 DrawBufferPixelResolution,
|
Chris@1109
|
218 DrawBufferBinResolution,
|
Chris@1109
|
219 DirectTranslucent
|
Chris@1109
|
220 };
|
Chris@1109
|
221
|
Chris@1109
|
222 RenderType decideRenderType(LayerGeometryProvider *) const;
|
Chris@1071
|
223 };
|
Chris@1071
|
224
|
Chris@1071
|
225 #endif
|
Chris@1071
|
226
|