-
Notifications
You must be signed in to change notification settings - Fork 40
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
waterfallplot: Use OpenGL #861
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
varying vec2 coord; | ||
uniform float horizontalRatio; | ||
uniform float verticalRatio; | ||
uniform sampler2D src; | ||
|
||
void main() { | ||
// Mod is used to wrap around the 0-1 scaled x axis | ||
vec2 shiftedCoord = mod(coord + vec2(horizontalRatio, 0), 1.0); | ||
shiftedCoord.y = shiftedCoord.y * verticalRatio; | ||
gl_FragColor = texture2D(src, shiftedCoord); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
uniform highp mat4 qt_Matrix; | ||
attribute highp vec4 qt_Vertex; | ||
attribute highp vec2 qt_MultiTexCoord0; | ||
varying highp vec2 coord; | ||
void main() { | ||
coord = qt_MultiTexCoord0; | ||
gl_Position = qt_Matrix * qt_Vertex; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ uint16_t WaterfallPlot::_displayWidth = 500; | |
|
||
WaterfallPlot::WaterfallPlot(QQuickItem* parent) | ||
: Waterfall(parent) | ||
, _currentDrawIndex(_displayWidth) | ||
, _image(2048, 2500, QImage::Format_RGBA8888) | ||
, _currentDrawIndex(0) | ||
, _image(_displayWidth, 2000, QImage::Format_RGBA8888) | ||
, _maxDepthToDrawInPixels(0) | ||
, _minDepthToDrawInPixels(0) | ||
, _mouseDepth(0) | ||
|
@@ -50,20 +50,13 @@ void WaterfallPlot::paint(QPainter* painter) | |
_painter = painter; | ||
} | ||
|
||
static uint16_t first; | ||
|
||
if (_currentDrawIndex < _displayWidth) { | ||
first = 0; | ||
} else { | ||
first = _currentDrawIndex - _displayWidth; | ||
} | ||
|
||
// http://blog.qt.io/blog/2006/05/13/fast-transformed-pixmapimage-drawing/ | ||
pix = QPixmap::fromImage(_image, Qt::NoFormatConversion); | ||
// Code for debug, draw the entire waterfall | ||
//_painter->drawPixmap(_painter->viewport(), pix, QRect(0, 0, _image.width(), _image.height())); | ||
_painter->drawPixmap(QRect(0, 0, width(), height()), pix, | ||
QRect(first, _minDepthToDrawInPixels, _displayWidth, _maxDepthToDrawInPixels)); | ||
_painter->drawPixmap(_painter->viewport(), pix, QRect(0, 0, _image.width(), _image.height())); | ||
|
||
emit drawHorizontalRatioChanged(); | ||
emit drawVerticalRatioChanged(); | ||
} | ||
|
||
void WaterfallPlot::setImage(const QImage& image) | ||
|
@@ -137,6 +130,10 @@ void WaterfallPlot::draw(const QVector<double>& points, float confidence, float | |
// This ring vector will store variables of the last n samples for user access | ||
_DCRing.append({initPoint, length, confidence, distance}); | ||
|
||
// Limit currentDrawIndex to be inside our image max width | ||
_currentDrawIndex++; | ||
_currentDrawIndex %= _displayWidth; | ||
|
||
/** | ||
* @brief Get lastMaxDepth from the last n samples | ||
*/ | ||
|
@@ -183,7 +180,6 @@ void WaterfallPlot::draw(const QVector<double>& points, float confidence, float | |
QPainter painter(&_image); | ||
// Clean everything and start from zero | ||
painter.fillRect(_image.rect(), Qt::transparent); | ||
// QRect(0, 0, _image.width(), _image.height()*dynamicPixelsPerMeterScalar), old | ||
painter.drawImage(dst, old, src); | ||
painter.end(); | ||
}; | ||
|
@@ -217,16 +213,6 @@ void WaterfallPlot::draw(const QVector<double>& points, float confidence, float | |
int virtualFloor = initPoint * _minPixelsPerMeter; | ||
int virtualHeight = length * _minPixelsPerMeter * dynamicPixelsPerMeterScalar; | ||
|
||
// Copy tail to head | ||
// TODO: can we get even better and allocate just once at initialization? ie circular buffering | ||
if (_currentDrawIndex >= _image.width()) { | ||
redrawImage(QRect(0, 0, _displayWidth, _image.height()), | ||
QRect(old.width() - _displayWidth, 0, _displayWidth, old.height())); | ||
|
||
// Start painting from the beginning | ||
_currentDrawIndex = _displayWidth; | ||
} | ||
|
||
// Do up/downsampling | ||
float factor = points.length() / ((float)(virtualHeight)); | ||
|
||
|
@@ -273,7 +259,10 @@ void WaterfallPlot::draw(const QVector<double>& points, float confidence, float | |
_image.setPixelColor(_currentDrawIndex, i + virtualFloor, valueToRGB(points[factor * i])); | ||
} | ||
} | ||
_currentDrawIndex++; // This can get to be an issue at very fast update rates from ping | ||
|
||
for (int i = virtualHeight; i < _image.height(); i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how fast is this but perhaps this is something that could be improved by QConcurrent? |
||
_image.setPixelColor(_currentDrawIndex, i, Qt::transparent); | ||
} | ||
|
||
// Fix max update in 20Hz at max | ||
if (!_updateTimer->isActive()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,28 @@ class WaterfallPlot : public Waterfall { | |
Q_INVOKABLE float getMinDepthToDraw() { return _minDepthToDraw; } | ||
Q_PROPERTY(float minDepthToDraw READ getMinDepthToDraw NOTIFY minDepthToDrawChanged) | ||
|
||
/** | ||
* @brief Return the necessary horizontal ratio value to perform the correct waterfall draw | ||
* | ||
* @return double | ||
*/ | ||
Q_INVOKABLE double drawHorizontalRatio() { return static_cast<double>(_currentDrawIndex + 1) / _image.width(); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const. |
||
Q_PROPERTY(double drawHorizontalRatio READ drawHorizontalRatio NOTIFY drawHorizontalRatioChanged) | ||
|
||
/** | ||
* @brief Return the necessary vertical ratio value to perform the correct waterfall draw | ||
* | ||
* @return double | ||
*/ | ||
Q_INVOKABLE double drawVerticalRatio() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. const. |
||
{ | ||
return (_maxDepthToDraw - _minDepthToDraw) * _minPixelsPerMeter / _image.height(); | ||
} | ||
Q_PROPERTY(double drawVerticalRatio READ drawVerticalRatio NOTIFY drawVerticalRatioChanged) | ||
|
||
signals: | ||
void drawHorizontalRatioChanged(); | ||
void drawVerticalRatioChanged(); | ||
void imageChanged(); | ||
void maxDepthToDrawChanged(); | ||
void minDepthToDrawChanged(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about merging those two emits into one? if the horizontal and vertical changes at the same time probably there will be one less redraw