comparison layer/Colour3DPlotRenderer.cpp @ 1083:7122aae95a88 spectrogram-minor-refactor

Start introducing render code
author Chris Cannam
date Fri, 01 Jul 2016 11:21:09 +0100
parents 5b4fe7bb9430
children db976e9f385a
comparison
equal deleted inserted replaced
1082:5b4fe7bb9430 1083:7122aae95a88
271 for (int y = 0; y < h; ++y) { 271 for (int y = 0; y < h; ++y) {
272 binfory[y] = 272 binfory[y] =
273 m_sources.verticalBinLayer->getBinForY(m_sources.geometryProvider, y); 273 m_sources.verticalBinLayer->getBinForY(m_sources.geometryProvider, y);
274 } 274 }
275 275
276 /* 276 int attainedWidth = renderDrawBuffer(repaintWidth,
277 int attainedWidth = renderDrawBuffer(v,
278 repaintWidth,
279 h, 277 h,
280 binforx, 278 binforx,
281 binfory, 279 binfory,
282 usePeaksCache, 280 usePeaksCache,
283 rightToLeft, 281 rightToLeft,
284 timeConstrained); 282 timeConstrained);
285 */ 283
286 } 284 //!!! now scale-copy to cache
287 285 }
286
287
288 int
289 Colour3DPlotRenderer::renderDrawBuffer(int w, int h,
290 const vector<int> &binforx,
291 const vector<double> &binfory,
292 bool usePeaksCache,
293 bool rightToLeft,
294 bool timeConstrained)
295 {
296 // Callers must have checked that the appropriate subset of
297 // Sources data members are set for the supplied flags (e.g. that
298 // peaks model exists if usePeaksCache)
299
300 RenderTimer timer(timeConstrained ?
301 RenderTimer::FastRender :
302 RenderTimer::NoTimeout);
303
304 int minbin = int(binfory[0] + 0.0001);
305 int maxbin = int(binfory[h-1]);
306 if (minbin < 0) minbin = 0;
307 if (maxbin < 0) maxbin = minbin+1;
308
309 int divisor = 1;
310 DenseThreeDimensionalModel *sourceModel = m_sources.source;
311 if (usePeaksCache) {
312 divisor = m_sources.peaks->getColumnsPerPeak();
313 sourceModel = m_sources.peaks;
314 }
315
316 int psx = -1;
317
318 int start = 0;
319 int finish = w;
320 int step = 1;
321
322 if (rightToLeft) {
323 start = w-1;
324 finish = -1;
325 step = -1;
326 }
327
328 int columnCount = 0;
329
330 vector<float> preparedColumn;
331
332 for (int x = start; x != finish; x += step) {
333
334 // x is the on-canvas pixel coord; sx (later) will be the
335 // source column index
336
337 ++columnCount;
338
339 if (binforx[x] < 0) continue;
340
341 int sx0 = binforx[x] / divisor;
342 int sx1 = sx0;
343 if (x+1 < w) sx1 = binforx[x+1] / divisor;
344 if (sx0 < 0) sx0 = sx1 - 1;
345 if (sx0 < 0) continue;
346 if (sx1 <= sx0) sx1 = sx0 + 1;
347
348 vector<float> pixelPeakColumn;
349
350 for (int sx = sx0; sx < sx1; ++sx) {
351
352 #ifdef DEBUG_SPECTROGRAM_REPAINT
353 // cerr << "sx = " << sx << endl;
354 #endif
355
356 if (sx < 0 || sx >= sourceModel->getWidth()) {
357 continue;
358 }
359
360 if (sx != psx) {
361
362 // order:
363 // get column -> scale -> record extents ->
364 // normalise -> peak pick -> apply display gain ->
365 // distribute/interpolate
366
367 ColumnOp::Column fullColumn = sourceModel->getColumn(sx);
368 ColumnOp::Column column =
369 vector<float>(fullColumn.data() + minbin,
370 fullColumn.data() + maxbin + 1);
371
372 //!!! fft scale if (m_colourScale != PhaseColourScale) {
373 // column = ColumnOp::fftScale(column, m_fftSize);
374 // }
375
376 //!!! extents recordColumnExtents(column,
377 // sx,
378 // overallMag,
379 // overallMagChanged);
380
381 // if (m_colourScale != PhaseColourScale) {
382 column = ColumnOp::normalize(column, m_params.normalization);
383 // }
384
385 if (m_params.binDisplay == PeakBins) {
386 column = ColumnOp::peakPick(column);
387 }
388
389 preparedColumn =
390 ColumnOp::distribute(column, //!!! gain? ColumnOp::applyGain(column, m_gain),
391 h,
392 binfory,
393 minbin,
394 m_params.interpolate);
395
396 psx = sx;
397 }
398
399 if (sx == sx0) {
400 pixelPeakColumn = preparedColumn;
401 } else {
402 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) {
403 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
404 preparedColumn[i]);
405 }
406 }
407 }
408
409 if (!pixelPeakColumn.empty()) {
410 for (int y = 0; y < h; ++y) {
411 m_drawBuffer.setPixel
412 (x,
413 h-y-1,
414 m_params.colourScale.getPixel(pixelPeakColumn[y]));
415 }
416 }
417
418 double fractionComplete = double(columnCount) / double(w);
419 if (timer.outOfTime(fractionComplete)) {
420 return columnCount;
421 }
422 }
423
424 return columnCount;
425 }
426
288 void 427 void
289 Colour3DPlotRenderer::clearDrawBuffer(int w, int h) 428 Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
290 { 429 {
291 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) { 430 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) {
292 431