From 1ecbbd1c431fa6873b835c081002cd3a9abc3d7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Mon, 10 Mar 2014 19:21:16 +0100 Subject: [PATCH] Integrate peaks even when the baseline is drawn from right to left --- gui/graphview.cpp | 3 --- integrator.cpp | 25 +++++++++++++++---------- signalcontroller.cpp | 1 + signaldrawer.cpp | 6 +++--- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gui/graphview.cpp b/gui/graphview.cpp index ee5ee90..329e114 100644 --- a/gui/graphview.cpp +++ b/gui/graphview.cpp @@ -142,9 +142,6 @@ void GraphView::mousePressEvent(QMouseEvent* ev) m_mouseMode = GraphView::MouseMode::CROSSHAIR; break; case GraphView::MouseMode::INTEGRATE: - if (m_integrateStartXPix > m_integrateStopXPix) - std::swap(m_integrateStartXPix, m_integrateStopXPix); - PeakDrawData pdData = m_controller->integratePeak(xPixToRel(m_integrateStartXPix), yPixToRel(m_integrateStartYPix), xPixToRel(m_integrateStopXPix), yPixToRel(m_integrateStopYPix)); eraseIntegrationBaseline(true); diff --git a/integrator.cpp b/integrator.cpp index 5e8365c..6c37612 100644 --- a/integrator.cpp +++ b/integrator.cpp @@ -90,27 +90,32 @@ Integrator::ReturnCode Integrator::integrate(size_t startIdx, size_t stopIdx, do return ReturnCode::E_INVAL; } + if (startIdx > stopIdx) { + std::swap(startIdx, stopIdx); + std::swap(startY, stopY); + } + qDebug() << "INTEG" << startIdx << stopIdx << startY << stopY; - slope = (stopY - startY) / (stopIdx - startIdx); + slope = (stopY - startY) / static_cast(stopIdx - startIdx); /* Try to find first intersection */ if (startY < m_signal->valueAt(startIdx)) { expectDownward = true; - qDebug() << "Expecting downward peak"; + //qDebug() << "Expecting downward peak"; } else { expectDownward = false; - qDebug() << "Expecting upward peak"; + //qDebug() << "Expecting upward peak"; } for (i = startIdx; i <= stopIdx; i++) { double value = m_signal->valueAt(i); - double blY = slope * (i - startIdx) + startY; + double blY = slope * static_cast(i - startIdx) + startY; if (expectDownward && blY > value) { /* Found first intersection */ - startIntersIdx = i-1; + startIntersIdx = i; startYVal = blY; break; } else if (!expectDownward && blY < value) { /* Found first intersection */ - startIntersIdx = i-1; + startIntersIdx = i; startYVal = blY; break; } @@ -123,13 +128,13 @@ Integrator::ReturnCode Integrator::integrate(size_t startIdx, size_t stopIdx, do /* Try to find second intersection */ for (; i <= stopIdx; i++) { double value = m_signal->valueAt(i); - double blY = slope * (i - startIdx) + startY; + double blY = slope * static_cast(i - startIdx) + startY; - if (expectDownward && blY <= value) { + if (expectDownward && blY < value) { stopIntersIdx = i; stopYVal = blY; break; - } else if (!expectDownward && blY >= value) { + } else if (!expectDownward && blY > value) { stopIntersIdx = i; stopYVal = blY; break; @@ -143,7 +148,7 @@ Integrator::ReturnCode Integrator::integrate(size_t startIdx, size_t stopIdx, do /* Integrate */ peakValueIdx = startIntersIdx; for (i = startIntersIdx+1; i < stopIntersIdx; i++) { - double blXA = slope * (i - startIntersIdx - 1) + startY; + double blXA = slope * (i - startIntersIdx) + startY; double blXB = slope * (i - startIntersIdx) + startY; double valA = m_signal->valueAt(i-1); double valB = m_signal->valueAt(i); diff --git a/signalcontroller.cpp b/signalcontroller.cpp index 70e0f78..88f685c 100644 --- a/signalcontroller.cpp +++ b/signalcontroller.cpp @@ -23,6 +23,7 @@ #include "signalcontroller.h" #include "logger.h" #include +#include #include diff --git a/signaldrawer.cpp b/signaldrawer.cpp index b61433a..107f60d 100644 --- a/signaldrawer.cpp +++ b/signaldrawer.cpp @@ -102,7 +102,7 @@ bool SignalDrawer::setDimensions(const int width, const int height) m_gWidth = width - SCALE_MARGIN_VALUE; m_gHeight = height - SCALE_MARGIN_TIME; - qDebug() << __QFUNC__ << width << height << m_width << m_height; + //qDebug() << __QFUNC__ << width << height << m_width << m_height; return draw(m_relXMin, m_relYMin, m_relXMax, m_relYMax); } @@ -305,8 +305,8 @@ bool SignalDrawer::renderGraph(QPixmap* const target) xStep = static_cast(m_gWidth) / m_gdData->ddataLen; yStep = static_cast(m_gHeight) / (m_relYMax - m_relYMin); - Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + " yStep: " + QString::number(yStep) - + " fY " + QString::number(m_relYMin) + " tY " + QString::number(m_relYMax)); + /*Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + " yStep: " + QString::number(yStep) + + " fY " + QString::number(m_relYMin) + " tY " + QString::number(m_relYMax));*/ fromYPix = m_gHeight - yStep * (m_gdData->ddata[0] - m_relYMin); for (size_t i = 1; i < m_gdData->ddataLen; i++) { int toXPix = xStep * i + SCALE_MARGIN_VALUE; -- 2.43.5