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

WIP: Move polarplot and waterfallplot to use material and shaders #874

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pingviewer.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RESOURCES += \

# Warning as error
*-g++ | *-clang {
QMAKE_CXXFLAGS += -Werror
#QMAKE_CXXFLAGS += -Werror
tcanabrava marked this conversation as resolved.
Show resolved Hide resolved
}
*msvc {
QMAKE_CXXFLAGS += /WX \
Expand Down
16 changes: 16 additions & 0 deletions qml/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import PingEnumNamespace 1.0
import SettingsManager 1.0
import StyleManager 1.0

import QQuickOpenGL 1.0

Item {
id: root
visible: true
Expand Down Expand Up @@ -260,6 +262,20 @@ Item {
radialGradient : sensorVisualizer.toString().includes("Ping360") ? radialGradient : linearGradient
}

QQuickOpenGL {
id: potato
//width: 200
//height: 200
anchors.centerIn: parent
//anchors.fill: parent
width: Math.min(parent.height, parent.width)
height: width
//width: 200
//height: 200
visible: true
z: 10000000
}

PingStatus {
// We need to be over the mainvisualizer
z: sensorVisualizer ? sensorVisualizer.z + 1 : 0
Expand Down
17 changes: 15 additions & 2 deletions qml/Ping1DVisualizer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@ Item {
orientation: Qt.Horizontal
anchors.fill: parent

WaterfallPlot {
id: waterfall
ShaderEffect {
id: shader

WaterfallPlot {
id: waterfall
visible: false
anchors.fill: parent
}

property variant src: waterfall
property variant horizontalRatio: waterfall.drawHorizontalRatio
property variant verticalRatio: waterfall.drawVerticalRatio
vertexShader: "qrc:/opengl/waterfallplot/vertex.glsl"
fragmentShader: "qrc:/opengl/waterfallplot/fragment.glsl"

Layout.fillHeight: true
Layout.fillWidth: true
Layout.preferredWidth: 350
Expand Down
48 changes: 21 additions & 27 deletions qml/Ping360Visualizer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Item {

onWidthChanged: {
if(chart.Layout.minimumWidth === chart.width) {
shader.parent.width = width - chart.width
waterfall.parent.width = width - chart.width
}
}

Expand All @@ -73,25 +73,25 @@ Item {
Layout.fillHeight: true
Layout.fillWidth: true

/** TODO: The shader logic should be inside done inside of PolarPlot c++ Object
* Or better encapsulated
*/
ShaderEffect {
id: shader
PolarPlot {
id: waterfall
/*
height: Math.min(ping.sectorSize > 180 ? parent.height : parent.height*2, parent.width*scale)
width: height
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: ping.sectorSize > 180 ? parent.verticalCenter : parent.bottom
*/
anchors.fill: parent

property var scale: ping.sectorSize >= 180 ? 1 : 0.8/Math.sin(ping.sectorSize*Math.PI/360)
property variant src: waterfall
//property variant src: waterfall
property var angle: 1

property bool verticalFlip: false
property bool horizontalFlip: false

vertexShader: "qrc:/opengl/polarplot/vertex.glsl"
fragmentShader: "qrc:/opengl/polarplot/fragment.glsl"
//vertexShader: "qrc:/opengl/polarplot/vertex.glsl"
//fragmentShader: "qrc:/opengl/polarplot/fragment.glsl"

Text {
id: northText
Expand Down Expand Up @@ -158,7 +158,7 @@ Item {
}

Shape {
visible: waterfall.containsMouse
//visible: waterfall.containsMouse
anchors.centerIn: parent
opacity: 0.5
ShapePath {
Expand All @@ -168,30 +168,24 @@ Item {
startY: 0
//TODO: This need to be updated in sensor integration
PathLine {
property real angle: -Math.atan2(waterfall.mousePos.x - waterfall.width/2, waterfall.mousePos.y - waterfall.height/2) + Math.PI/2
property real angle: 0//-Math.atan2(waterfall.mousePos.x - waterfall.width/2, waterfall.mousePos.y - waterfall.height/2) + Math.PI/2
x: waterfall.width*Math.cos(angle)/2
y: waterfall.height*Math.sin(angle)/2
}
}
}

transform: Rotation {
origin.x: shader.width/2
origin.y: shader.height/2
axis { x: shader.verticalFlip; y: shader.horizontalFlip; z: ping.sectorSize > 180}
origin.x: waterfall.width/2
origin.y: waterfall.height/2
axis { x: waterfall.verticalFlip; y: waterfall.horizontalFlip; z: ping.sectorSize > 180}
angle: -ping.heading*180/200
}
}

PolarPlot {
id: waterfall
anchors.fill: shader
visible: false
}

Text {
id: mouseReadout
visible: waterfall.containsMouse
//visible: waterfall.containsMouse
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 5
Expand All @@ -214,17 +208,17 @@ Item {

function calcAngleFromFlips(angle) {
var value = waterfall.mouseSampleAngle
if(shader.verticalFlip && shader.horizontalFlip) {
if(waterfall.verticalFlip && waterfall.horizontalFlip) {
value = (360 + 270 - value) % 360
return transformValue(value)
}

if(shader.verticalFlip) {
if(waterfall.verticalFlip) {
value = (360 + 180 - value) % 360
return transformValue(value)
}

if(shader.horizontalFlip) {
if(waterfall.horizontalFlip) {
value = 360 - value
return transformValue(value)
}
Expand All @@ -236,7 +230,7 @@ Item {

PolarGrid {
id: polarGrid
anchors.fill: shader
anchors.fill: waterfall
angle: ping.sectorSize
maxDistance: waterfall.maxDistance
}
Expand All @@ -246,7 +240,7 @@ Item {
height: 10
anchors.bottom: parent.bottom
anchors.right: parent.right
waterfallGradient: waterfall.waterfallGradient
//waterfallGradient: waterfall.waterfallGradient
}
}

Expand Down Expand Up @@ -311,7 +305,7 @@ Item {
Layout.columnSpan: 5
Layout.fillWidth: true
onCheckStateChanged: {
shader.horizontalFlip = checkState
waterfall.horizontalFlip = checkState
}
}

Expand Down
1 change: 1 addition & 0 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ApplicationWindow {
width: parent.width/2
height: parent.height*0.9
anchors.centerIn: parent
visible: false
}
}

Expand Down
8 changes: 5 additions & 3 deletions qml/opengl/polarplot/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* Tilman Schmidt [KeyMaster-] example
*/
uniform sampler2D src;
uniform float angle;
varying vec2 coord;

void main() {
gl_FragColor = vec4(0, coord.x, coord.y, 1.0);
return;

vec2 sizeOverRadius = vec2(2.0, 2.0);
float sampleOffset = 0.0;
float polarFactor = 1.0;
Expand All @@ -25,8 +27,8 @@ void main() {
polar.y = sqrt(relPos.x * relPos.x + relPos.y * relPos.y);

//Any radius over 1 would go beyond the source texture size, this simply outputs black for those fragments
if(polar.y > 1.0){
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
if(polar.y > 0.5){
gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0);
return;
}

Expand Down
10 changes: 4 additions & 6 deletions qml/opengl/polarplot/vertex.glsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
uniform highp mat4 qt_Matrix;
attribute highp vec4 qt_Vertex;
attribute highp vec2 qt_MultiTexCoord0;
varying highp vec2 coord;
attribute vec4 vertices;
varying vec2 coords;
void main() {
coord = qt_MultiTexCoord0;
gl_Position = qt_Matrix * qt_Vertex;
gl_Position = vertices;
coords = vertices.xy;
}
10 changes: 10 additions & 0 deletions qml/opengl/qquickopengl/fragment.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
varying highp vec2 coord;
uniform lowp float qt_Opacity;
void main() {
float d = distance(coord, vec2(0.5, 0.5));
if ( d > 0.5) {
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0) * qt_Opacity;
return;
}
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0) * qt_Opacity;
}
11 changes: 11 additions & 0 deletions qml/opengl/qquickopengl/vertex.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
uniform highp mat4 qt_Matrix;

attribute highp vec4 qt_Vertex;
attribute highp vec2 qt_MultiTexCoord0;

varying highp vec2 coord;

void main() {
gl_Position = qt_Matrix * qt_Vertex;
coord = qt_MultiTexCoord0;// + vec2(1.0, 1.0)) / 2.0;
}
11 changes: 11 additions & 0 deletions qml/opengl/waterfallplot/fragment.glsl
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);
}
8 changes: 8 additions & 0 deletions qml/opengl/waterfallplot/vertex.glsl
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;
}
4 changes: 4 additions & 0 deletions resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,9 @@
<qresource prefix="/opengl">
<file alias="polarplot/fragment.glsl">qml/opengl/polarplot/fragment.glsl</file>
<file alias="polarplot/vertex.glsl">qml/opengl/polarplot/vertex.glsl</file>
<file alias="qquickopengl/fragment.glsl">qml/opengl/qquickopengl/fragment.glsl</file>
<file alias="qquickopengl/vertex.glsl">qml/opengl/qquickopengl/vertex.glsl</file>
<file alias="waterfallplot/fragment.glsl">qml/opengl/waterfallplot/fragment.glsl</file>
<file alias="waterfallplot/vertex.glsl">qml/opengl/waterfallplot/vertex.glsl</file>
</qresource>
</RCC>
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(INCLUDE_DIRS
mavlink
network
notification
qquickcomponents
sensor
settings
style
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
#include "ping.h"
#include "ping360.h"
#include "polarplot.h"
#include "qquickopengl.h"
#include "settingsmanager.h"
#include "stylemanager.h"
#include "util.h"
#include "waterfallplot.h"

#include "qquickopengl.h"

Q_DECLARE_LOGGING_CATEGORY(mainCategory)

PING_LOGGING_CATEGORY(mainCategory, "ping.main")
Expand Down Expand Up @@ -68,6 +71,7 @@ int main(int argc, char *argv[])
qmlRegisterType<Ping>("Ping", 1, 0, "Ping");
qmlRegisterType<Ping360>("Ping360", 1, 0, "Ping360");
qmlRegisterType<PolarPlot>("PolarPlot", 1, 0, "PolarPlot");
qmlRegisterType<QQuickOpenGL>("QQuickOpenGL", 1, 0, "QQuickOpenGL");
qmlRegisterType<WaterfallPlot>("WaterfallPlot", 1, 0, "WaterfallPlot");

qmlRegisterUncreatableMetaObject(
Expand Down
11 changes: 11 additions & 0 deletions src/qquickcomponents/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_library(
qquickcomponents
STATIC
qquickopengl.cpp
)

target_link_libraries(qquickcomponents
PRIVATE
Qt5::Core
Qt5::Quick
)
7 changes: 7 additions & 0 deletions src/qquickcomponents/qquickcomponents.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INCLUDEPATH += $$PWD

HEADERS += \
$$PWD/*.h

SOURCES += \
$$PWD/*.cpp
Loading