Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1237:2cc9e0e5df51
More tweaks to when to render from the middle
author | Chris Cannam |
---|---|
date | Fri, 27 Jan 2017 13:19:21 +0000 |
parents | 784c92f93fb6 |
children | 6e724c81f18f |
comparison
equal
deleted
inserted
replaced
1236:784c92f93fb6 | 1237:2cc9e0e5df51 |
---|---|
206 | 206 |
207 int reqx0 = x0; | 207 int reqx0 = x0; |
208 int reqx1 = x1; | 208 int reqx1 = x1; |
209 | 209 |
210 if (!m_cache.isValid() && timeConstrained) { | 210 if (!m_cache.isValid() && timeConstrained) { |
211 // When rendering the whole area, in a context where we might | |
212 // not be able to complete the work, start from somewhere near | |
213 // the middle so that the region of interest appears | |
214 // first. But only if we aren't using a peak cache, as | |
215 // rendering from peak cache is usually (not always) quick and | |
216 // looks odd if we make a habit of jumping back after reaching | |
217 // the end. | |
218 if (x0 == 0 && x1 == v->getPaintWidth()) { | 211 if (x0 == 0 && x1 == v->getPaintWidth()) { |
219 int peakCacheIndex = -1, binsPerPeak = -1; | 212 |
220 getPreferredPeakCache(v, peakCacheIndex, binsPerPeak); | 213 // When rendering the whole area, in a context where we |
221 if (peakCacheIndex == -1) { // no peak cache | 214 // might not be able to complete the work, start from |
215 // somewhere near the middle so that the region of | |
216 // interest appears first. | |
217 // | |
218 // This is very useful if we actually are slow to render, | |
219 // but if we're not sure how fast we'll be, we should | |
220 // prefer not to because it can be distracting to render | |
221 // fast from the middle and then jump back to fill in the | |
222 // start. That is: | |
223 // | |
224 // - if our seconds-per-x-pixel count is invalid, then we | |
225 // don't do this: we've probably only just been created | |
226 // and don't know how fast we'll be yet (this happens | |
227 // often while zooming rapidly in and out). The exception | |
228 // to the exception is if we're displaying peak | |
229 // frequencies; this we can assume to be slow. (Note that | |
230 // if the seconds-per-x-pixel is valid and we know we're | |
231 // fast, then we've already set timeConstrained false | |
232 // above so this doesn't apply) | |
233 // | |
234 // - if we're using a peak cache, we don't do this; | |
235 // drawing from peak cache is often (even if not always) | |
236 // fast. | |
237 | |
238 bool drawFromTheMiddle = true; | |
239 | |
240 if (!m_secondsPerXPixelValid && | |
241 (m_params.binDisplay != BinDisplay::PeakFrequencies)) { | |
242 drawFromTheMiddle = false; | |
243 } else { | |
244 int peakCacheIndex = -1, binsPerPeak = -1; | |
245 getPreferredPeakCache(v, peakCacheIndex, binsPerPeak); | |
246 if (peakCacheIndex >= 0) { // have a peak cache | |
247 drawFromTheMiddle = false; | |
248 } | |
249 } | |
250 | |
251 if (drawFromTheMiddle) { | |
222 double offset = 0.5 * (double(rand()) / double(RAND_MAX)); | 252 double offset = 0.5 * (double(rand()) / double(RAND_MAX)); |
223 x0 = int(x1 * offset); | 253 x0 = int(x1 * offset); |
224 } | 254 } |
225 } | 255 } |
226 } | 256 } |
1174 } | 1204 } |
1175 | 1205 |
1176 void | 1206 void |
1177 Colour3DPlotRenderer::updateTimings(const RenderTimer &timer, int xPixelCount) | 1207 Colour3DPlotRenderer::updateTimings(const RenderTimer &timer, int xPixelCount) |
1178 { | 1208 { |
1179 m_secondsPerXPixel = timer.secondsPerItem(xPixelCount); | 1209 double secondsPerXPixel = timer.secondsPerItem(xPixelCount); |
1180 m_secondsPerXPixelValid = (xPixelCount > 10); | 1210 |
1181 | 1211 // valid if we have enough data points, or if the overall time is |
1212 // massively slow anyway (as we definitely need to warn about that) | |
1213 bool valid = (xPixelCount > 20 || secondsPerXPixel > 0.01); | |
1214 | |
1215 if (valid) { | |
1216 m_secondsPerXPixel = secondsPerXPixel; | |
1217 m_secondsPerXPixelValid = true; | |
1218 | |
1182 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 1219 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
1183 SVDEBUG << "across " << xPixelCount << " x-pixels, seconds per x-pixel = " | 1220 SVDEBUG << "across " << xPixelCount << " x-pixels, seconds per x-pixel = " |
1184 << m_secondsPerXPixel | 1221 << m_secondsPerXPixel << endl; |
1185 << " (enough data? " << (m_secondsPerXPixelValid ? "yes" : "no") | 1222 #endif |
1186 << ")" << endl; | 1223 } |
1187 #endif | |
1188 | |
1189 } | 1224 } |
1190 | 1225 |
1191 void | 1226 void |
1192 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h) | 1227 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h) |
1193 { | 1228 { |