Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Plotter Fills #1391

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions src/qtgui/plotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1506,13 +1506,6 @@ void CPlotter::draw(bool newData)
QPainter painter2(&m_2DPixmap);
painter2.translate(QPointF(0.5, 0.5));


// draw the pandapter
QBrush fillBrush = QBrush(m_FftFillCol);

// Fill between max and avg
QBrush maxFillBrush = QBrush(m_FilledModeFillCol);

// Diagonal fill for area between markers. Scale the pattern to DPR.
QColor abFillColor = QColor::fromRgba(PLOTTER_MARKER_COLOR);
abFillColor.setAlpha(128);
Expand Down Expand Up @@ -1547,8 +1540,7 @@ void CPlotter::draw(bool newData)

const float binSizeY = (float)plotHeight / (float)histBinsDisplayed;
QPolygonF abPolygon;
QPolygonF underPolygon;
QPolygonF avgMaxPolygon;
qreal yFillMax = 0;
for (i = 0; i < npts; i++)
{
const int ix = i + xmin;
Expand Down Expand Up @@ -1593,25 +1585,21 @@ void CPlotter::draw(bool newData)

// Fill area between markers, even if they are off screen
qreal yFill = m_PlotMode == PLOT_MODE_MAX ? yMaxD : yAvgD;
yFillMax = std::max(yFillMax, yFill);
if (fillMarkers && (ix) > minMarker && (ix) < maxMarker) {
abPolygon << QPointF(ixPlot, yFill);
}
if (m_FftFill && m_PlotMode != PLOT_MODE_HISTOGRAM)
{
underPolygon << QPointF(ixPlot, yFill);
}
if (m_PlotMode == PLOT_MODE_FILLED)
{
avgMaxPolygon << m_maxLineBuf[i];
}
}

if (!underPolygon.isEmpty())
if (m_FftFill && m_PlotMode != PLOT_MODE_HISTOGRAM)
{
underPolygon << QPointF(underPolygon.last().x(), plotHeight);
underPolygon << QPointF(underPolygon.first().x(), plotHeight);
painter2.setBrush(fillBrush);
painter2.drawPolygon(underPolygon);
for (i = 0; i < npts; i++)
{
const QPointF point = m_PlotMode == PLOT_MODE_MAX ? m_maxLineBuf[i] : m_avgLineBuf[i];
const qreal yFill = point.y();
painter2.fillRect(QRectF(point.x() - 1.0, yFill, 1.0, yFillMax - yFill), m_FftFillCol);
}
painter2.fillRect(QRectF(xmin, yFillMax, npts, plotHeight - yFillMax), m_FftFillCol);
}

if (!abPolygon.isEmpty())
Expand Down Expand Up @@ -1645,7 +1633,7 @@ void CPlotter::draw(bool newData)
// Min hold
if (m_MinHoldActive)
{
// Show min(avg) except when showing only max on scree
// Show min(avg) except when showing only max on screen
for (i = 0; i < npts; i++)
{
const int ix = i + xmin;
Expand All @@ -1662,14 +1650,14 @@ void CPlotter::draw(bool newData)
m_MinHoldValid = true;
}

if (!avgMaxPolygon.isEmpty())
if (m_PlotMode == PLOT_MODE_FILLED)
{
for (i = npts - 1; i >= 0; i--)
for (i = 0; i < npts; i++)
{
avgMaxPolygon << m_avgLineBuf[i];
const QPointF maxPoint = m_maxLineBuf[i];
const qreal yMax = maxPoint.y();
painter2.fillRect(QRectF(maxPoint.x() - 1.0, yMax, 1.0, m_avgLineBuf[i].y() - yMax), m_FilledModeFillCol);
}
painter2.setBrush(maxFillBrush);
painter2.drawPolygon(avgMaxPolygon);
}

if (doMaxLine)
Expand Down
Loading