| 1 | /* |
| 2 | * Copyright (C) 2016, Mike Walters <[email protected]> |
| 3 | * |
| 4 | * This file is part of inspectrum. |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #include <QPixmapCache> |
| 21 | #include <QTextStream> |
| 22 | #include <QtConcurrent> |
| 23 | #include <QPainterPath> |
| 24 | #include "samplesource.h"cxx . . $ `<file>/src/samplesource.h`/ |
| 25 | #include "traceplot.h"cxx . . $ `<file>/src/traceplot.h`/ |
| 26 | |
| 27 | TracePlotcxx . . $ TracePlot#::TracePlotcxx . . $ TracePlot#TracePlot(22d84a47a7b53cf1).(stdcxx . . $ std/::shared_ptrcxx . . $ std/shared_ptr#<AbstractSampleSourcecxx . . $ AbstractSampleSource#> source) : Plotcxx . . $ Plot#(sourcecxx . . $ std/shared_ptr#shared_ptr(c44ffe56f5110b84).) { |
| 28 | connectcxx . . $ QObject#connect(835f87066c895669).(this, &TracePlotcxx . . $ TracePlot#::imageReadycxx . . $ TracePlot#imageReady(2fc6005f4c39585c)., this, &TracePlotcxx . . $ TracePlot#::handleImagecxx . . $ TracePlot#handleImage(2fc6005f4c39585c).); |
| 29 | } |
| 30 | |
| 31 | void TracePlotcxx . . $ TracePlot#::paintMidcxx . . $ TracePlot#paintMid(dba2c6533854c69f).(QPaintercxx . . $ QPainter# &painter, QRectcxx . . $ QRect# &rect, range_tcxx . . $ range_t#<size_t> sampleRange) |
| 32 | { |
| 33 | if (sampleRange.lengthcxx . . $ range_t#length(f448638088200dcb).() == 0) return; |
| 34 | |
| 35 | int samplesPerColumn = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a).(1UL, sampleRange.lengthcxx . . $ range_t#length(f448638088200dcb).() / rect.widthcxx . . $ QRect#width(455f465bc33b4cdf).()); |
| 36 | int samplesPerTile = tileWidthcxx . . $ TracePlot#tileWidth. * samplesPerColumn; |
| 37 | size_t tileID = sampleRange.minimumcxx . . $ range_t#minimum. / samplesPerTile; |
| 38 | size_t tileOffset = sampleRange.minimumcxx . . $ range_t#minimum. % samplesPerTile; // Number of samples to skip from first image tile |
| 39 | int xOffset = tileOffset / samplesPerColumn; // Number of columns to skip from first image tile |
| 40 | |
| 41 | // Paint first (possibly partial) tile |
| 42 | painter.drawPixmapcxx . . $ QPainter#drawPixmap(583800ea2588537e).( |
| 43 | QRectcxx . . $ QRect#QRect(748afa4755bc9595).(rect.xcxx . . $ QRect#x(455f465bc33b4cdf).(), rect.ycxx . . $ QRect#y(455f465bc33b4cdf).(), tileWidthcxx . . $ TracePlot#tileWidth. - xOffset, heightcxx . . $ Plot#height(455f465bc33b4cdf).()), |
| 44 | getTilecxx . . $ TracePlot#getTile(487b0baefcfe71df).(tileID++, samplesPerTile), |
| 45 | QRectcxx . . $ QRect#QRect(748afa4755bc9595).(xOffset, 0, tileWidthcxx . . $ TracePlot#tileWidth. - xOffset, heightcxx . . $ Plot#height(455f465bc33b4cdf).()) |
| 46 | ); |
| 47 | |
| 48 | // Paint remaining tiles |
| 49 | for (int x = tileWidthcxx . . $ TracePlot#tileWidth. - xOffset; x < rect.rightcxx . . $ QRect#right(455f465bc33b4cdf).(); x += tileWidthcxx . . $ TracePlot#tileWidth.) { |
| 50 | painter.drawPixmapcxx . . $ QPainter#drawPixmap(579b881b2368aa78).( |
| 51 | QRectcxx . . $ QRect#QRect(748afa4755bc9595).(x, rect.ycxx . . $ QRect#y(455f465bc33b4cdf).(), tileWidthcxx . . $ TracePlot#tileWidth., heightcxx . . $ Plot#height(455f465bc33b4cdf).()), |
| 52 | getTilecxx . . $ TracePlot#getTile(487b0baefcfe71df).(tileID++, samplesPerTile) |
| 53 | ); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | QPixmapcxx . . $ QPixmap# TracePlotcxx . . $ TracePlot#::getTilecxx . . $ TracePlot#getTile(487b0baefcfe71df).(size_t tileID, size_t sampleCount) |
| 58 | { |
| 59 | QPixmapcxx . . $ QPixmap# pixmapcxx . . $ QPixmap#QPixmap(3e454b8ccf442868).(tileWidthcxx . . $ TracePlot#tileWidth., heightcxx . . $ Plot#height(455f465bc33b4cdf).()); |
| 60 | QStringcxx . . $ QString# keycxx . . $ QString#QString(49f6e7a06ebc5aa8).; |
| 61 | QTextStreamcxx . . $ QTextStream#QTextStream(16e3d097052a73db).(&key) <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). "traceplot_" <<cxx . . $ QTextStream#`operator<<`(e641e3d92a38a901). this <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). "_" <<cxx . . $ QTextStream#`operator<<`(e258565795f3a3bc). tileID <<cxx . . $ QTextStream#`operator<<`(a8e98279dde0dccf). "_" <<cxx . . $ QTextStream#`operator<<`(e258565795f3a3bc). sampleCount; |
| 62 | if (QPixmapCachecxx . . $ QPixmapCache#::findcxx . . $ QPixmapCache#find(505d75979a078a48).(key, &pixmap)) |
| 63 | return pixmapcxx . . $ QPixmap#QPixmap(8887f7d25b86c3f4).; |
| 64 | |
| 65 | if (!taskscxx . . $ TracePlot#tasks..containscxx . . $ QSet#contains(8877ebe272b9620d).(key)) { |
| 66 | range_tcxx . . $ range_t#<size_t> sampleRange{tileID * sampleCount, (tileID + 1) * sampleCount}; |
| 67 | #if QT_VERSIONcxx . . $ `<external>/15045578679651060896/qglobal.h:57:9`! >= QT_VERSION_CHECKcxx . . $ `<external>/15045578679651060896/qglobal.h:61:9`!(6, 0, 0) |
| 68 | QtConcurrent::run(&TracePlot::drawTile, this, key, QRect(0, 0, tileWidth, height()), sampleRange); |
| 69 | #else |
| 70 | QtConcurrentcxx . . $ QtConcurrent/::runcxx . . $ QtConcurrent/run(9a12e62f9833f48f).(this, &TracePlotcxx . . $ TracePlot#::drawTilecxx . . $ TracePlot#drawTile(446f64e73cd7f568)., key, QRectcxx . . $ QRect#QRect(748afa4755bc9595).(0, 0, tileWidthcxx . . $ TracePlot#tileWidth., heightcxx . . $ Plot#height(455f465bc33b4cdf).()), sampleRange); |
| 71 | #endif |
| 72 | taskscxx . . $ TracePlot#tasks..insertcxx . . $ QSet#insert(b1720532d625d779).(key); |
| 73 | } |
| 74 | pixmap.fillcxx . . $ QPixmap#fill(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(cd98eb3c6d110ca7).::transparentcxx . . $ Qt/transparent.); |
| 75 | return pixmapcxx . . $ QPixmap#QPixmap(8887f7d25b86c3f4).; |
| 76 | } |
| 77 | |
| 78 | void TracePlotcxx . . $ TracePlot#::drawTilecxx . . $ TracePlot#drawTile(446f64e73cd7f568).(QStringcxx . . $ QString# key, const QRectcxx . . $ QRect# &rect, range_tcxx . . $ range_t#<size_t> sampleRange) |
| 79 | { |
| 80 | QImagecxx . . $ QImage# imagecxx . . $ QImage#QImage(fe815e29ae3e37c9).(rect.sizecxx . . $ QRect#size(4b3b776e5ee2b367).(), QImagecxx . . $ QImage#::Format_ARGB32cxx . . $ QImage#Format_ARGB32.); |
| 81 | image.fillcxx . . $ QImage#fill(cd98eb3c6d110ca7).(Qtcxx . . $ Qt/::transparentcxx . . $ Qt/transparent.); |
| 82 | |
| 83 | QPaintercxx . . $ QPainter# paintercxx . . $ QPainter#QPainter(dd2eedc069b0ab5f).(&image); |
| 84 | painter.setRenderHintcxx . . $ QPainter#setRenderHint(df747a77a7bbbce1).(QPaintercxx . . $ QPainter#::Antialiasingcxx . . $ QPainter#Antialiasing., true); |
| 85 | |
| 86 | auto firstSample = sampleRange.minimumcxx . . $ range_t#minimum.; |
| 87 | auto length = sampleRange.lengthcxx . . $ range_t#length(f448638088200dcb).(); |
| 88 | |
| 89 | // Is it a 2-channel (complex) trace? |
| 90 | if (auto src = dynamic_cast<SampleSourcecxx . . $ SampleSource#<stdcxx . . $ std/::complexcxx . . $ std/complex#<float>>*>(sampleSourcecxx . . $ Plot#sampleSource..getcxx . . $ std/__shared_ptr#get(8bad9e61ec1ad29c).())) { |
| 91 | auto samples = srccxx . . $ std/unique_ptr#unique_ptr(c72f3246697f2f97).->getSamplescxx . . $ SampleSource#getSamples(beb84398f18d5b52).(firstSample, length); |
| 92 | if (samples ==cxx . . $ std/`operator==`(5e0825b51b28ca0b). nullptr) |
| 93 | return; |
| 94 | |
| 95 | painter.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(cd98eb3c6d110ca7).::redcxx . . $ Qt/red.); |
| 96 | plotTracecxx . . $ TracePlot#plotTrace(c1eb76396d5548a1).(painter, rect, reinterpret_cast<float*>(samples.getcxx . . $ std/unique_ptr#get(ca399b2b6292c808).()), length, 2); |
| 97 | painter.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(cd98eb3c6d110ca7).::bluecxx . . $ Qt/blue.); |
| 98 | plotTracecxx . . $ TracePlot#plotTrace(c1eb76396d5548a1).(painter, rect, reinterpret_cast<float*>(samples.getcxx . . $ std/unique_ptr#get(ca399b2b6292c808).())+1, length, 2); |
| 99 | |
| 100 | // Otherwise is it single channel? |
| 101 | } else if (auto src = dynamic_cast<SampleSourcecxx . . $ SampleSource#<float>*>(sampleSourcecxx . . $ Plot#sampleSource..getcxx . . $ std/__shared_ptr#get(8bad9e61ec1ad29c).())) { |
| 102 | auto samples = srccxx . . $ std/unique_ptr#unique_ptr(c72f3246697f2f97).->getSamplescxx . . $ SampleSource#getSamples(beb84398f18d5b52).(firstSample, length); |
| 103 | if (samples ==cxx . . $ std/`operator==`(5e0825b51b28ca0b). nullptr) |
| 104 | return; |
| 105 | |
| 106 | painter.setPencxx . . $ QPainter#setPen(129a55e114526ad3).(Qtcxx . . $ QColor#QColor(cd98eb3c6d110ca7).::greencxx . . $ Qt/green.); |
| 107 | plotTracecxx . . $ TracePlot#plotTrace(c1eb76396d5548a1).(painter, rect, samples.getcxx . . $ std/unique_ptr#get(ca399b2b6292c808).(), length, 1); |
| 108 | } else { |
| 109 | throw stdcxx . . $ std/runtime_error#runtime_error(6be18eeaba0abf21).::runtime_errorcxx . . $ std/runtime_error#("TracePlot::paintMid: Unsupported source type"); |
| 110 | } |
| 111 | |
| 112 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! imageReadycxx . . $ TracePlot#imageReady(2fc6005f4c39585c).(keycxx . . $ QString#QString(3520e46b33348bf6)., imagecxx . . $ QImage#QImage(9ff1334af0ec69dd).); |
| 113 | } |
| 114 | |
| 115 | void TracePlotcxx . . $ TracePlot#::handleImagecxx . . $ TracePlot#handleImage(2fc6005f4c39585c).(QStringcxx . . $ QString# key, QImagecxx . . $ QImage# image) |
| 116 | { |
| 117 | auto pixmap = QPixmapcxx . . $ QPixmap#QPixmap(8887f7d25b86c3f4).::fromImagecxx . . $ QPixmap#fromImage(e89e6101063912f).(image); |
| 118 | QPixmapCachecxx . . $ QPixmapCache#::insertcxx . . $ QPixmapCache#insert(ea4708518c20dff9).(key, pixmap); |
| 119 | taskscxx . . $ TracePlot#tasks..removecxx . . $ QSet#remove(fe1ba53999e710f3).(key); |
| 120 | emitcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:97:10`! repaintcxx . . $ Plot#repaint(49f6e7a06ebc5aa8).(); |
| 121 | } |
| 122 | |
| 123 | void TracePlotcxx . . $ TracePlot#::plotTracecxx . . $ TracePlot#plotTrace(c1eb76396d5548a1).(QPaintercxx . . $ QPainter# &painter, const QRectcxx . . $ QRect# &rect, float *samples, size_t count, int step = 1) |
| 124 | { |
| 125 | QPainterPathcxx . . $ QPainterPath# pathcxx . . $ QPainterPath#QPainterPath(49f6e7a06ebc5aa8).; |
| 126 | range_tcxx . . $ range_t#<float> xRange{0, rect.widthcxx . . $ QRect#width(455f465bc33b4cdf).() - 2.f}; |
| 127 | range_tcxx . . $ range_t#<float> yRange{0, rect.heightcxx . . $ QRect#height(455f465bc33b4cdf).() - 2.f}; |
| 128 | const float xStep = 1.0 / count * rect.widthcxx . . $ QRect#width(455f465bc33b4cdf).(); |
| 129 | for (size_t i = 0; i < count; i++) { |
| 130 | float sample = samples[i*step]; |
| 131 | float x = i * xStep; |
| 132 | float y = (1 - sample) * (rect.heightcxx . . $ QRect#height(455f465bc33b4cdf).() / 2); |
| 133 | |
| 134 | x = xRange.clipcxx . . $ range_t#clip(2e044cb6e7a82418).(x) + rect.xcxx . . $ QRect#x(455f465bc33b4cdf).(); |
| 135 | y = yRange.clipcxx . . $ range_t#clip(2e044cb6e7a82418).(y) + rect.ycxx . . $ QRect#y(455f465bc33b4cdf).(); |
| 136 | |
| 137 | if (i == 0) |
| 138 | path.moveTocxx . . $ QPainterPath#moveTo(bc12c9ec15586e6a).(x, y); |
| 139 | else |
| 140 | path.lineTocxx . . $ QPainterPath#lineTo(bc12c9ec15586e6a).(x, y); |
| 141 | } |
| 142 | painter.drawPathcxx . . $ QPainter#drawPath(30c23ba204361e3b).(path); |
| 143 | } |