Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 160:f4be20ebdfa4
* Some dull work to continue unifying the fft model and editable dense 3d model
interfaces
author | Chris Cannam |
---|---|
date | Mon, 09 Oct 2006 10:49:46 +0000 |
parents | c1fb771b7646 |
children | 42118892f428 |
comparison
equal
deleted
inserted
replaced
159:c1fb771b7646 | 160:f4be20ebdfa4 |
---|---|
185 | 185 |
186 float srRatio = | 186 float srRatio = |
187 float(v->getViewManager()->getMainModelSampleRate()) / | 187 float(v->getViewManager()->getMainModelSampleRate()) / |
188 float(m_model->getSampleRate()); | 188 float(m_model->getSampleRate()); |
189 | 189 |
190 int sx0 = modelResolution * | 190 int sx0 = int((v->getFrameForX(x) / srRatio - long(modelStart)) / |
191 int((v->getFrameForX(x) / srRatio - long(modelStart)) / long(modelResolution)); | 191 long(modelResolution)); |
192 int sx1 = sx0 + modelResolution; | 192 |
193 | 193 int f0 = sx0 * modelResolution; |
194 float binHeight = float(v->height()) / m_model->getYBinCount(); | 194 int f1 = f0 + modelResolution; |
195 | |
196 float binHeight = float(v->height()) / m_model->getHeight(); | |
195 int sy = (v->height() - y) / binHeight; | 197 int sy = (v->height() - y) / binHeight; |
196 | 198 |
197 float value = m_model->getBinValue(sx0, sy); | 199 float value = m_model->getValueAt(sx0, sy); |
198 | 200 |
199 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl; | 201 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl; |
200 | 202 |
201 QString binName = m_model->getBinName(sy); | 203 QString binName = m_model->getBinName(sy); |
202 if (binName == "") binName = QString("[%1]").arg(sy + 1); | 204 if (binName == "") binName = QString("[%1]").arg(sy + 1); |
203 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1); | 205 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1); |
204 | 206 |
205 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4") | 207 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4") |
206 .arg(RealTime::frame2RealTime(sx0, m_model->getSampleRate()) | 208 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate()) |
207 .toText(true).c_str()) | 209 .toText(true).c_str()) |
208 .arg(RealTime::frame2RealTime(sx1, m_model->getSampleRate()) | 210 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate()) |
209 .toText(true).c_str()) | 211 .toText(true).c_str()) |
210 .arg(binName) | 212 .arg(binName) |
211 .arg(value); | 213 .arg(value); |
212 | 214 |
213 return text; | 215 return text; |
223 int | 225 int |
224 Colour3DPlotLayer::getVerticalScaleWidth(View *v, QPainter &paint) const | 226 Colour3DPlotLayer::getVerticalScaleWidth(View *v, QPainter &paint) const |
225 { | 227 { |
226 if (!m_model) return 0; | 228 if (!m_model) return 0; |
227 | 229 |
228 QString sampleText = QString("[%1]").arg(m_model->getYBinCount()); | 230 QString sampleText = QString("[%1]").arg(m_model->getHeight()); |
229 int tw = paint.fontMetrics().width(sampleText); | 231 int tw = paint.fontMetrics().width(sampleText); |
230 bool another = false; | 232 bool another = false; |
231 | 233 |
232 for (size_t i = 0; i < m_model->getYBinCount(); ++i) { | 234 for (size_t i = 0; i < m_model->getHeight(); ++i) { |
233 if (m_model->getBinName(i).length() > sampleText.length()) { | 235 if (m_model->getBinName(i).length() > sampleText.length()) { |
234 sampleText = m_model->getBinName(i); | 236 sampleText = m_model->getBinName(i); |
235 another = true; | 237 another = true; |
236 } | 238 } |
237 } | 239 } |
246 Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const | 248 Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const |
247 { | 249 { |
248 if (!m_model) return; | 250 if (!m_model) return; |
249 | 251 |
250 int h = rect.height(), w = rect.width(); | 252 int h = rect.height(), w = rect.width(); |
251 float binHeight = float(v->height()) / m_model->getYBinCount(); | 253 float binHeight = float(v->height()) / m_model->getHeight(); |
252 | 254 |
253 int cw = getColourScaleWidth(paint); | 255 int cw = getColourScaleWidth(paint); |
254 | 256 |
255 int ch = h - 20; | 257 int ch = h - 20; |
256 if (ch > 20 && m_cache) { | 258 if (ch > 20 && m_cache) { |
267 } | 269 } |
268 | 270 |
269 paint.setPen(Qt::black); | 271 paint.setPen(Qt::black); |
270 | 272 |
271 int count = v->height() / paint.fontMetrics().height(); | 273 int count = v->height() / paint.fontMetrics().height(); |
272 int step = m_model->getYBinCount() / count; | 274 int step = m_model->getHeight() / count; |
273 if (step == 0) step = 1; | 275 if (step == 0) step = 1; |
274 | 276 |
275 for (size_t i = 0; i < m_model->getYBinCount(); ++i) { | 277 for (size_t i = 0; i < m_model->getHeight(); ++i) { |
276 | 278 |
277 if ((i % step) != 0) continue; | 279 if ((i % step) != 0) continue; |
278 | 280 |
279 int y0 = v->height() - (i * binHeight) - 1; | 281 int y0 = v->height() - (i * binHeight) - 1; |
280 | 282 |
310 size_t modelStart = m_model->getStartFrame(); | 312 size_t modelStart = m_model->getStartFrame(); |
311 size_t modelEnd = m_model->getEndFrame(); | 313 size_t modelEnd = m_model->getEndFrame(); |
312 size_t modelResolution = m_model->getResolution(); | 314 size_t modelResolution = m_model->getResolution(); |
313 | 315 |
314 size_t cacheWidth = (modelEnd - modelStart) / modelResolution + 1; | 316 size_t cacheWidth = (modelEnd - modelStart) / modelResolution + 1; |
315 size_t cacheHeight = m_model->getYBinCount(); | 317 size_t cacheHeight = m_model->getHeight(); |
316 | 318 |
317 if (m_cache && | 319 if (m_cache && |
318 (m_cache->width() != cacheWidth || | 320 (m_cache->width() != cacheWidth || |
319 m_cache->height() != cacheHeight)) { | 321 m_cache->height() != cacheHeight)) { |
320 | 322 |
327 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); | 329 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8); |
328 | 330 |
329 std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << std::endl; | 331 std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << std::endl; |
330 | 332 |
331 m_cache->setNumColors(256); | 333 m_cache->setNumColors(256); |
332 DenseThreeDimensionalModel::BinValueSet values; | 334 DenseThreeDimensionalModel::Column values; |
333 | 335 |
334 float min = m_model->getMinimumLevel(); | 336 float min = m_model->getMinimumLevel(); |
335 float max = m_model->getMaximumLevel(); | 337 float max = m_model->getMaximumLevel(); |
336 | 338 |
337 if (max == min) max = min + 1.0; | 339 if (max == min) max = min + 1.0; |
375 m_cache->fill(zeroIndex); | 377 m_cache->fill(zeroIndex); |
376 | 378 |
377 for (size_t f = modelStart; f <= modelEnd; f += modelResolution) { | 379 for (size_t f = modelStart; f <= modelEnd; f += modelResolution) { |
378 | 380 |
379 values.clear(); | 381 values.clear(); |
380 m_model->getBinValues(f, values); | 382 m_model->getColumn(f / modelResolution, values); |
381 | 383 |
382 for (size_t y = 0; y < m_model->getYBinCount(); ++y) { | 384 for (size_t y = 0; y < m_model->getHeight(); ++y) { |
383 | 385 |
384 float value = min; | 386 float value = min; |
385 if (y < values.size()) { | 387 if (y < values.size()) { |
386 value = values[y]; | 388 value = values[y]; |
387 if (m_colourScale != LinearScale) { | 389 if (m_colourScale != LinearScale) { |
396 m_cache->setPixel(f / modelResolution, y, pixel); | 398 m_cache->setPixel(f / modelResolution, y, pixel); |
397 } | 399 } |
398 } | 400 } |
399 } | 401 } |
400 | 402 |
401 if (m_model->getYBinCount() >= v->height() || | 403 if (m_model->getHeight() >= v->height() || |
402 modelResolution < v->getZoomLevel() / 2) { | 404 modelResolution < v->getZoomLevel() / 2) { |
403 paintDense(v, paint, rect); | 405 paintDense(v, paint, rect); |
404 return; | 406 return; |
405 } | 407 } |
406 | 408 |
423 float(v->getViewManager()->getMainModelSampleRate()) / | 425 float(v->getViewManager()->getMainModelSampleRate()) / |
424 float(m_model->getSampleRate()); | 426 float(m_model->getSampleRate()); |
425 | 427 |
426 int sx0 = int((v->getFrameForX(x0) / srRatio - long(modelStart)) / long(modelResolution)); | 428 int sx0 = int((v->getFrameForX(x0) / srRatio - long(modelStart)) / long(modelResolution)); |
427 int sx1 = int((v->getFrameForX(x1) / srRatio - long(modelStart)) / long(modelResolution)); | 429 int sx1 = int((v->getFrameForX(x1) / srRatio - long(modelStart)) / long(modelResolution)); |
428 int sh = m_model->getYBinCount(); | 430 int sh = m_model->getHeight(); |
429 | 431 |
430 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 432 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT |
431 std::cerr << "Colour3DPlotLayer::paint: w " << w << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sw << ", sh " << sh << std::endl; | 433 std::cerr << "Colour3DPlotLayer::paint: w " << w << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sw << ", sh " << sh << std::endl; |
432 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << std::endl; | 434 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << std::endl; |
433 #endif | 435 #endif |
495 paint.drawRect(r); | 497 paint.drawRect(r); |
496 | 498 |
497 if (showLabel) { | 499 if (showLabel) { |
498 if (sx >= 0 && sx < m_cache->width() && | 500 if (sx >= 0 && sx < m_cache->width() && |
499 sy >= 0 && sy < m_cache->height()) { | 501 sy >= 0 && sy < m_cache->height()) { |
500 float value = m_model->getBinValue(fx, sy); | 502 float value = m_model->getValueAt(sx, sy); |
501 sprintf(labelbuf, "%06f", value); | 503 sprintf(labelbuf, "%06f", value); |
502 QString text(labelbuf); | 504 QString text(labelbuf); |
503 paint.setPen(Qt::white); | 505 paint.setPen(Qt::white); |
504 paint.drawText(rx0 + 2, | 506 paint.drawText(rx0 + 2, |
505 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), | 507 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(), |
527 int x0 = rect.left(); | 529 int x0 = rect.left(); |
528 int x1 = rect.right() + 1; | 530 int x1 = rect.right() + 1; |
529 | 531 |
530 int w = x1 - x0; | 532 int w = x1 - x0; |
531 int h = v->height(); | 533 int h = v->height(); |
532 int sh = m_model->getYBinCount(); | 534 int sh = m_model->getHeight(); |
533 | 535 |
534 QImage img(w, h, QImage::Format_RGB32); | 536 QImage img(w, h, QImage::Format_RGB32); |
535 | 537 |
536 for (int x = x0; x < x1; ++x) { | 538 for (int x = x0; x < x1; ++x) { |
537 | 539 |