comparison layer/TimeInstantLayer.cpp @ 1552:045063dcd2bc

Merge
author Chris Cannam
date Thu, 21 Nov 2019 14:03:19 +0000
parents 9a5eede01869
children
comparison
equal deleted inserted replaced
1551:e79731086b0f 1552:045063dcd2bc
319 auto model = ModelById::getAs<SparseOneDimensionalModel>(m_model); 319 auto model = ModelById::getAs<SparseOneDimensionalModel>(m_model);
320 if (!model || !model->isOK()) return; 320 if (!model || !model->isOK()) return;
321 321
322 // Profiler profiler("TimeInstantLayer::paint", true); 322 // Profiler profiler("TimeInstantLayer::paint", true);
323 323
324 int x0 = rect.left(), x1 = rect.right(); 324 int x0 = rect.left();
325 325 int x1 = x0 + rect.width();
326 sv_frame_t frame0 = v->getFrameForX(x0); 326
327 sv_frame_t resolution = model->getResolution();
328
329 sv_frame_t frame0 = v->getFrameForX(x0) - resolution;
327 sv_frame_t frame1 = v->getFrameForX(x1); 330 sv_frame_t frame1 = v->getFrameForX(x1);
328 331
332 #ifdef DEBUG_TIME_INSTANT_LAYER
333 SVCERR << "TimeInstantLayer[" << this << "]::paint: x0 = "
334 << x0 << ", x1 = " << x1 << ", frame0 = " << frame0
335 << ", frame1 = " << frame1 << endl;
336 #endif
337
329 int overspill = 0; 338 int overspill = 0;
330 if (m_plotStyle == PlotSegmentation) { 339 if (m_plotStyle == PlotSegmentation) {
331 // We need to start painting at the prior point, so we can 340 // We need to start painting at the prior point, so we can
332 // fill in the visible part of its segmentation area 341 // fill in the visible part of its segmentation area
333 overspill = 1; 342 overspill = 1;
334 } 343 }
335 344
336 EventVector points(model->getEventsWithin(frame0, frame1 - frame0, 345 EventVector points(model->getEventsWithin(frame0, frame1 - frame0,
337 overspill)); 346 overspill));
347
348 #ifdef DEBUG_TIME_INSTANT_LAYER
349 SVCERR << "TimeInstantLayer[" << this << "]::paint: have " << points.size()
350 << " point(s) with overspill = " << overspill << " from model "
351 << getModel() << endl;
352 #endif
338 353
339 bool odd = false; 354 bool odd = false;
340 if (m_plotStyle == PlotSegmentation && !points.empty()) { 355 if (m_plotStyle == PlotSegmentation && !points.empty()) {
341 int index = model->getRowForFrame(points.begin()->getFrame()); 356 int index = model->getRowForFrame(points.begin()->getFrame());
342 odd = ((index % 2) == 1); 357 odd = ((index % 2) == 1);
362 oddBrushColour = oddBrushColour.lighter(150); 377 oddBrushColour = oddBrushColour.lighter(150);
363 } 378 }
364 oddBrushColour.setAlpha(100); 379 oddBrushColour.setAlpha(100);
365 } 380 }
366 381
367 // SVDEBUG << "TimeInstantLayer::paint: resolution is "
368 // << model->getResolution() << " frames" << endl;
369
370 QPoint localPos; 382 QPoint localPos;
371 sv_frame_t illuminateFrame = -1; 383 sv_frame_t illuminateFrame = -1;
372 384
373 if (v->shouldIlluminateLocalFeatures(this, localPos)) { 385 if (v->shouldIlluminateLocalFeatures(this, localPos)) {
374 EventVector localPoints = getLocalPoints(v, localPos.x()); 386 EventVector localPoints = getLocalPoints(v, localPos.x());
386 Event p(*i); 398 Event p(*i);
387 EventVector::const_iterator j = i; 399 EventVector::const_iterator j = i;
388 ++j; 400 ++j;
389 401
390 int x = v->getXForFrame(p.getFrame()); 402 int x = v->getXForFrame(p.getFrame());
403
404 #ifdef DEBUG_TIME_INSTANT_LAYER
405 SVCERR << "point frame = " << p.getFrame() << " -> x = " << x << endl;
406 #endif
407
391 if (x == prevX && m_plotStyle == PlotInstants && 408 if (x == prevX && m_plotStyle == PlotInstants &&
392 p.getFrame() != illuminateFrame) continue; 409 p.getFrame() != illuminateFrame) {
410 #ifdef DEBUG_TIME_INSTANT_LAYER
411 SVCERR << "(skipping)" << endl;
412 #endif
413 continue;
414 }
393 415
394 int iw = v->getXForFrame(p.getFrame() + model->getResolution()) - x; 416 int iw = v->getXForFrame(p.getFrame() + model->getResolution()) - x;
395 if (iw < 2) { 417 if (iw < 2) {
396 if (iw < 1) { 418 if (iw < 1) {
397 iw = 2; 419 iw = 2;
408 paint.setPen(getForegroundQColor(v->getView())); 430 paint.setPen(getForegroundQColor(v->getView()));
409 } else { 431 } else {
410 paint.setPen(brushColour); 432 paint.setPen(brushColour);
411 } 433 }
412 434
435 #ifdef DEBUG_TIME_INSTANT_LAYER
436 SVCERR << "m_plotStyle = " << m_plotStyle << ", iw = " << iw << endl;
437 #endif
438
413 if (m_plotStyle == PlotInstants) { 439 if (m_plotStyle == PlotInstants) {
414 if (iw > 1) { 440 if (iw > 1) {
415 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1); 441 paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1);
416 } else { 442 } else {
417 paint.drawLine(x, 0, x, v->getPaintHeight() - 1); 443 paint.drawLine(x, 0, x, v->getPaintHeight() - 1);
514 m_editingPoint = m_editingPoint.withFrame(frame); 540 m_editingPoint = m_editingPoint.withFrame(frame);
515 m_editingCommand->add(m_editingPoint); 541 m_editingCommand->add(m_editingPoint);
516 } 542 }
517 543
518 void 544 void
519 TimeInstantLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) 545 TimeInstantLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *
546 #ifdef DEBUG_TIME_INSTANT_LAYER
547 e
548 #endif
549 )
520 { 550 {
521 #ifdef DEBUG_TIME_INSTANT_LAYER 551 #ifdef DEBUG_TIME_INSTANT_LAYER
522 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl; 552 cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl;
523 #endif 553 #endif
524 auto model = ModelById::getAs<SparseOneDimensionalModel>(m_model); 554 auto model = ModelById::getAs<SparseOneDimensionalModel>(m_model);
621 m_editingPoint = m_editingPoint.withFrame(frame); 651 m_editingPoint = m_editingPoint.withFrame(frame);
622 m_editingCommand->add(m_editingPoint); 652 m_editingCommand->add(m_editingPoint);
623 } 653 }
624 654
625 void 655 void
626 TimeInstantLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) 656 TimeInstantLayer::editEnd(LayerGeometryProvider *, QMouseEvent *
657 #ifdef DEBUG_TIME_INSTANT_LAYER
658 e
659 #endif
660 )
627 { 661 {
628 #ifdef DEBUG_TIME_INSTANT_LAYER 662 #ifdef DEBUG_TIME_INSTANT_LAYER
629 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl; 663 cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl;
630 #endif 664 #endif
631 auto model = ModelById::getAs<SparseOneDimensionalModel>(m_model); 665 auto model = ModelById::getAs<SparseOneDimensionalModel>(m_model);