comparison layer/Colour3DPlotRenderer.h @ 1090:c8c747783110 spectrogram-minor-refactor

Cut over to using the renderer (though it's very incomplete) and fix some cache problems and pointer lifetime misunderstandings
author Chris Cannam
date Tue, 05 Jul 2016 17:48:26 +0100
parents c8683d94442a
children 8a815776151c
comparison
equal deleted inserted replaced
1089:c8683d94442a 1090:c8c747783110
45 LinearBinScale, 45 LinearBinScale,
46 LogBinScale 46 LogBinScale
47 }; 47 };
48 48
49 struct Sources { 49 struct Sources {
50 Sources() : geometryProvider(0), verticalBinLayer(0), 50 Sources() : verticalBinLayer(0), source(0), peaks(0), fft(0) { }
51 source(0), peaks(0), fft(0) { }
52 51
53 // These must all outlive this class 52 // These must all outlive this class
54 LayerGeometryProvider *geometryProvider; // always
55 const VerticalBinLayer *verticalBinLayer; // always 53 const VerticalBinLayer *verticalBinLayer; // always
56 DenseThreeDimensionalModel *source; // always 54 DenseThreeDimensionalModel *source; // always
57 Dense3DModelPeakCache *peaks; // optionally 55 Dense3DModelPeakCache *peaks; // optionally
58 FFTModel *fft; // optionally 56 FFTModel *fft; // optionally
59 }; 57 };
96 MagnitudeRange range; 94 MagnitudeRange range;
97 }; 95 };
98 96
99 /** 97 /**
100 * Render the requested area using the given painter, obtaining 98 * Render the requested area using the given painter, obtaining
101 * geometry (e.g. start frame) from the stored 99 * geometry (e.g. start frame) from the given
102 * LayerGeometryProvider. 100 * LayerGeometryProvider.
103 * 101 *
104 * The whole rect will be rendered and the returned QRect will be 102 * The whole of the supplied rect will be rendered and the
105 * equal to the passed QRect. (See renderTimeConstrained for an 103 * returned QRect will be equal to the supplied QRect. (See
106 * alternative that may render only part of the rect in cases 104 * renderTimeConstrained for an alternative that may render only
107 * where obtaining source data is slow and retaining 105 * part of the rect in cases where obtaining source data is slow
108 * responsiveness is important.) 106 * and retaining responsiveness is important.)
107 *
108 * Note that Colour3DPlotRenderer retains internal cache state
109 * related to the size and position of the supplied
110 * LayerGeometryProvider. Although it is valid to call render()
111 * successively on the same Colour3DPlotRenderer with different
112 * LayerGeometryProviders, it will be much faster to use a
113 * dedicated Colour3DPlotRenderer for each LayerGeometryProvider.
109 * 114 *
110 * If the model to render from is not ready, this will throw a 115 * If the model to render from is not ready, this will throw a
111 * std::logic_error exception. The model must be ready and the 116 * std::logic_error exception. The model must be ready and the
112 * layer requesting the render must not be dormant in its view, so 117 * layer requesting the render must not be dormant in its view, so
113 * that the LayerGeometryProvider returns valid results; it is the 118 * that the LayerGeometryProvider returns valid results; it is the
114 * caller's responsibility to ensure these. 119 * caller's responsibility to ensure these.
115 */ 120 */
116 RenderResult render(QPainter &paint, QRect rect); 121 RenderResult render(LayerGeometryProvider *v, QPainter &paint, QRect rect);
117 122
118 /** 123 /**
119 * Render the requested area using the given painter, obtaining 124 * Render the requested area using the given painter, obtaining
120 * geometry (e.g. start frame) from the stored 125 * geometry (e.g. start frame) from the stored
121 * LayerGeometryProvider. 126 * LayerGeometryProvider.
125 * internally). The returned QRect (the rendered field in the 130 * internally). The returned QRect (the rendered field in the
126 * RenderResult struct) will contain the area that was 131 * RenderResult struct) will contain the area that was
127 * rendered. Note that we always render the full requested height, 132 * rendered. Note that we always render the full requested height,
128 * it's only width that is time-constrained. 133 * it's only width that is time-constrained.
129 * 134 *
135 * Note that Colour3DPlotRenderer retains internal cache state
136 * related to the size and position of the supplied
137 * LayerGeometryProvider. Although it is valid to call render()
138 * successively on the same Colour3DPlotRenderer with different
139 * LayerGeometryProviders, it will be much faster to use a
140 * dedicated Colour3DPlotRenderer for each LayerGeometryProvider.
141 *
130 * If the model to render from is not ready, this will throw a 142 * If the model to render from is not ready, this will throw a
131 * std::logic_error exception. The model must be ready and the 143 * std::logic_error exception. The model must be ready and the
132 * layer requesting the render must not be dormant in its view, so 144 * layer requesting the render must not be dormant in its view, so
133 * that the LayerGeometryProvider returns valid results; it is the 145 * that the LayerGeometryProvider returns valid results; it is the
134 * caller's responsibility to ensure these. 146 * caller's responsibility to ensure these.
135 */ 147 */
136 RenderResult renderTimeConstrained(QPainter &paint, QRect rect); 148 RenderResult renderTimeConstrained(LayerGeometryProvider *v,
149 QPainter &paint, QRect rect);
137 150
138 private: 151 private:
139 Sources m_sources; 152 Sources m_sources;
140 Parameters m_params; 153 Parameters m_params;
141 154
152 // carried out by repainting to cache (via the draw buffer) any 165 // carried out by repainting to cache (via the draw buffer) any
153 // area that is being requested but is not valid in the cache, and 166 // area that is being requested but is not valid in the cache, and
154 // then repainting from cache to the requested painter. 167 // then repainting from cache to the requested painter.
155 ScrollableImageCache m_cache; 168 ScrollableImageCache m_cache;
156 169
157 RenderResult render(QPainter &paint, QRect rect, bool timeConstrained); 170 RenderResult render(LayerGeometryProvider *v,
158 void renderToCache(int x0, int repaintWidth, 171 QPainter &paint, QRect rect, bool timeConstrained);
172 void renderToCache(LayerGeometryProvider *v, int x0, int repaintWidth,
159 bool rightToLeft, bool timeConstrained); 173 bool rightToLeft, bool timeConstrained);
160 int renderDrawBuffer(int w, int h, 174 int renderDrawBuffer(int w, int h,
161 const std::vector<int> &binforx, 175 const std::vector<int> &binforx,
162 const std::vector<double> &binfory, 176 const std::vector<double> &binfory,
163 bool usePeaksCache, 177 bool usePeaksCache,