From 95418e25c07a2dde5fb2c7032959a0108167b02c Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 28 Mar 2016 17:46:19 -0700 Subject: [PATCH 1/4] Try to fix the iinclude for the PerfPlot/qml --- examples/utilities/tools/render/stats.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/utilities/tools/render/stats.qml b/examples/utilities/tools/render/stats.qml index 142b5e25e2..7e7684800b 100644 --- a/examples/utilities/tools/render/stats.qml +++ b/examples/utilities/tools/render/stats.qml @@ -10,7 +10,7 @@ // import QtQuick 2.5 import QtQuick.Controls 1.4 - +import "." Item { id: statsUI From 807698f0bbec99602221b6a2d086d0d8690a4592 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 28 Mar 2016 17:39:43 -0700 Subject: [PATCH 2/4] Make svo loading use ResourceManager --- interface/src/Application.cpp | 9 +------ libraries/octree/src/Octree.cpp | 44 +++++++++++++-------------------- 2 files changed, 18 insertions(+), 35 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7eb19557e5..c6669303a8 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2893,14 +2893,7 @@ void Application::saveSettings() { bool Application::importEntities(const QString& urlOrFilename) { _entityClipboard->eraseAllOctreeElements(); - QUrl url(urlOrFilename); - - // if the URL appears to be invalid or relative, then it is probably a local file - if (!url.isValid() || url.isRelative()) { - url = QUrl::fromLocalFile(urlOrFilename); - } - - bool success = _entityClipboard->readFromURL(url.toString()); + bool success = _entityClipboard->readFromURL(urlOrFilename); if (success) { _entityClipboard->remapIDs(); _entityClipboard->reaverageOctreeElements(); diff --git a/libraries/octree/src/Octree.cpp b/libraries/octree/src/Octree.cpp index 4d89464460..ffbc2e6709 100644 --- a/libraries/octree/src/Octree.cpp +++ b/libraries/octree/src/Octree.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1674,35 +1675,24 @@ bool Octree::readJSONFromGzippedFile(QString qFileName) { } bool Octree::readFromURL(const QString& urlString) { - bool readOk = false; + auto request = std::unique_ptr(ResourceManager::createResourceRequest(this, urlString)); - // determine if this is a local file or a network resource - QUrl url(urlString); - - if (url.isLocalFile()) { - readOk = readFromFile(qPrintable(url.toLocalFile())); - } else { - QNetworkRequest request; - request.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT); - request.setUrl(url); - - QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); - QNetworkReply* reply = networkAccessManager.get(request); - - qCDebug(octree) << "Downloading svo at" << qPrintable(urlString); - - QEventLoop loop; - QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); - loop.exec(); - - if (reply->error() == QNetworkReply::NoError) { - int resourceSize = reply->bytesAvailable(); - QDataStream inputStream(reply); - readOk = readFromStream(resourceSize, inputStream); - } - delete reply; + if (!request) { + return false; } - return readOk; + + QEventLoop loop; + connect(request.get(), &ResourceRequest::finished, &loop, &QEventLoop::quit); + request->send(); + loop.exec(); + + if (request->getResult() != ResourceRequest::Success) { + return false; + } + + auto data = request->getData(); + QDataStream inputStream(data); + return readFromStream(data.size(), inputStream); } From a815c50fcacfcdd951761667ceb0071d1c9d3b56 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 28 Mar 2016 18:36:17 -0700 Subject: [PATCH 3/4] fixing the qml component --- .../tools/render/plotperf/PlotPerf.qml | 186 ++++++++++++++++++ .../utilities/tools/render/plotperf/qmldir | 1 + examples/utilities/tools/render/stats.qml | 2 +- 3 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 examples/utilities/tools/render/plotperf/PlotPerf.qml create mode 100644 examples/utilities/tools/render/plotperf/qmldir diff --git a/examples/utilities/tools/render/plotperf/PlotPerf.qml b/examples/utilities/tools/render/plotperf/PlotPerf.qml new file mode 100644 index 0000000000..0e100e4e72 --- /dev/null +++ b/examples/utilities/tools/render/plotperf/PlotPerf.qml @@ -0,0 +1,186 @@ +// +// PlotPerf.qml +// examples/utilities/tools/render +// +// Created by Sam Gateau on 3//2016 +// Copyright 2016 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html +// +import QtQuick 2.5 +import QtQuick.Controls 1.4 + +Item { + id: root + width: parent.width + height: 100 + property string title + property var config + property string parameters + + // THis is my hack to get the name of the first property and assign it to a trigger var in order to get + // a signal called whenever the value changed + property var trigger: config[parameters.split(":")[3].split("-")[0]] + + property var inputs: parameters.split(":") + property var valueScale: +inputs[0] + property var valueUnit: inputs[1] + property var valueNumDigits: inputs[2] + property var input_VALUE_OFFSET: 3 + property var valueMax : 1 + + property var _values : new Array() + property var tick : 0 + + function createValues() { + if (inputs.length > input_VALUE_OFFSET) { + for (var i = input_VALUE_OFFSET; i < inputs.length; i++) { + var varProps = inputs[i].split("-") + _values.push( { + value: varProps[0], + valueMax: 1, + numSamplesConstantMax: 0, + valueHistory: new Array(), + label: varProps[1], + color: varProps[2], + scale: (varProps.length > 3 ? varProps[3] : 1), + unit: (varProps.length > 4 ? varProps[4] : valueUnit) + }) + } + } + print("in creator" + JSON.stringify(_values)); + + } + + Component.onCompleted: { + createValues(); + print(JSON.stringify(_values)); + + } + + function pullFreshValues() { + //print("pullFreshValues"); + var VALUE_HISTORY_SIZE = 100; + var UPDATE_CANVAS_RATE = 20; + tick++; + + + var currentValueMax = 0 + for (var i = 0; i < _values.length; i++) { + + var currentVal = config[_values[i].value] * _values[i].scale; + _values[i].valueHistory.push(currentVal) + _values[i].numSamplesConstantMax++; + + if (_values[i].valueHistory.length > VALUE_HISTORY_SIZE) { + var lostValue = _values[i].valueHistory.shift(); + if (lostValue >= _values[i].valueMax) { + _values[i].valueMax *= 0.99 + _values[i].numSamplesConstantMax = 0 + } + } + + if (_values[i].valueMax < currentVal) { + _values[i].valueMax = currentVal; + _values[i].numSamplesConstantMax = 0 + } + + if (_values[i].numSamplesConstantMax > VALUE_HISTORY_SIZE) { + _values[i].numSamplesConstantMax = 0 + _values[i].valueMax *= 0.95 // lower slowly the current max if no new above max since a while + } + + if (currentValueMax < _values[i].valueMax) { + currentValueMax = _values[i].valueMax + } + } + + if ((valueMax < currentValueMax) || (tick % VALUE_HISTORY_SIZE == 0)) { + valueMax = currentValueMax; + } + + if (tick % UPDATE_CANVAS_RATE == 0) { + mycanvas.requestPaint() + } + } + onTriggerChanged: pullFreshValues() + + Canvas { + id: mycanvas + anchors.fill:parent + onPaint: { + var lineHeight = 12; + + function displayValue(val, unit) { + return (val / root.valueScale).toFixed(root.valueNumDigits) + " " + unit + } + + function pixelFromVal(val, valScale) { + return lineHeight + (height - lineHeight) * (1 - (0.9) * val / valueMax); + } + function valueFromPixel(pixY) { + return ((pixY - lineHeight) / (height - lineHeight) - 1) * valueMax / (-0.9); + } + function plotValueHistory(ctx, valHistory, color) { + var widthStep= width / (valHistory.length - 1); + + ctx.beginPath(); + ctx.strokeStyle= color; // Green path + ctx.lineWidth="2"; + ctx.moveTo(0, pixelFromVal(valHistory[0])); + + for (var i = 1; i < valHistory.length; i++) { + ctx.lineTo(i * widthStep, pixelFromVal(valHistory[i])); + } + + ctx.stroke(); + } + function displayValueLegend(ctx, val, num) { + ctx.fillStyle = val.color; + var bestValue = val.valueHistory[val.valueHistory.length -1]; + ctx.textAlign = "right"; + ctx.fillText(displayValue(bestValue, val.unit), width, (num + 2) * lineHeight * 1.5); + ctx.textAlign = "left"; + ctx.fillText(val.label, 0, (num + 2) * lineHeight * 1.5); + } + + function displayTitle(ctx, text, maxVal) { + ctx.fillStyle = "grey"; + ctx.textAlign = "right"; + ctx.fillText(displayValue(valueFromPixel(lineHeight), root.valueUnit), width, lineHeight); + + ctx.fillStyle = "white"; + ctx.textAlign = "left"; + ctx.fillText(text, 0, lineHeight); + } + function displayBackground(ctx) { + ctx.fillStyle = Qt.rgba(0, 0, 0, 0.6); + ctx.fillRect(0, 0, width, height); + + ctx.strokeStyle= "grey"; + ctx.lineWidth="2"; + + ctx.beginPath(); + ctx.moveTo(0, lineHeight + 1); + ctx.lineTo(width, lineHeight + 1); + ctx.moveTo(0, height); + ctx.lineTo(width, height); + ctx.stroke(); + } + + var ctx = getContext("2d"); + ctx.clearRect(0, 0, width, height); + ctx.font="12px Verdana"; + + displayBackground(ctx); + + for (var i = 0; i < _values.length; i++) { + plotValueHistory(ctx, _values[i].valueHistory, _values[i].color) + displayValueLegend(ctx, _values[i], i) + } + + displayTitle(ctx, title, valueMax) + } + } +} diff --git a/examples/utilities/tools/render/plotperf/qmldir b/examples/utilities/tools/render/plotperf/qmldir new file mode 100644 index 0000000000..5668f5034c --- /dev/null +++ b/examples/utilities/tools/render/plotperf/qmldir @@ -0,0 +1 @@ +PlotPerf 1.0 PlotPerf.qml \ No newline at end of file diff --git a/examples/utilities/tools/render/stats.qml b/examples/utilities/tools/render/stats.qml index 7e7684800b..aacc896444 100644 --- a/examples/utilities/tools/render/stats.qml +++ b/examples/utilities/tools/render/stats.qml @@ -10,7 +10,7 @@ // import QtQuick 2.5 import QtQuick.Controls 1.4 -import "." +import "plotperf" Item { id: statsUI From 884a3e691d0ac7e7d79ee8981b7c8ac3bcca1639 Mon Sep 17 00:00:00 2001 From: samcake Date: Mon, 28 Mar 2016 18:38:34 -0700 Subject: [PATCH 4/4] Cleaning up moved files --- examples/utilities/tools/render/PlotPerf.qml | 186 ------------------- 1 file changed, 186 deletions(-) delete mode 100644 examples/utilities/tools/render/PlotPerf.qml diff --git a/examples/utilities/tools/render/PlotPerf.qml b/examples/utilities/tools/render/PlotPerf.qml deleted file mode 100644 index 0e100e4e72..0000000000 --- a/examples/utilities/tools/render/PlotPerf.qml +++ /dev/null @@ -1,186 +0,0 @@ -// -// PlotPerf.qml -// examples/utilities/tools/render -// -// Created by Sam Gateau on 3//2016 -// Copyright 2016 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html -// -import QtQuick 2.5 -import QtQuick.Controls 1.4 - -Item { - id: root - width: parent.width - height: 100 - property string title - property var config - property string parameters - - // THis is my hack to get the name of the first property and assign it to a trigger var in order to get - // a signal called whenever the value changed - property var trigger: config[parameters.split(":")[3].split("-")[0]] - - property var inputs: parameters.split(":") - property var valueScale: +inputs[0] - property var valueUnit: inputs[1] - property var valueNumDigits: inputs[2] - property var input_VALUE_OFFSET: 3 - property var valueMax : 1 - - property var _values : new Array() - property var tick : 0 - - function createValues() { - if (inputs.length > input_VALUE_OFFSET) { - for (var i = input_VALUE_OFFSET; i < inputs.length; i++) { - var varProps = inputs[i].split("-") - _values.push( { - value: varProps[0], - valueMax: 1, - numSamplesConstantMax: 0, - valueHistory: new Array(), - label: varProps[1], - color: varProps[2], - scale: (varProps.length > 3 ? varProps[3] : 1), - unit: (varProps.length > 4 ? varProps[4] : valueUnit) - }) - } - } - print("in creator" + JSON.stringify(_values)); - - } - - Component.onCompleted: { - createValues(); - print(JSON.stringify(_values)); - - } - - function pullFreshValues() { - //print("pullFreshValues"); - var VALUE_HISTORY_SIZE = 100; - var UPDATE_CANVAS_RATE = 20; - tick++; - - - var currentValueMax = 0 - for (var i = 0; i < _values.length; i++) { - - var currentVal = config[_values[i].value] * _values[i].scale; - _values[i].valueHistory.push(currentVal) - _values[i].numSamplesConstantMax++; - - if (_values[i].valueHistory.length > VALUE_HISTORY_SIZE) { - var lostValue = _values[i].valueHistory.shift(); - if (lostValue >= _values[i].valueMax) { - _values[i].valueMax *= 0.99 - _values[i].numSamplesConstantMax = 0 - } - } - - if (_values[i].valueMax < currentVal) { - _values[i].valueMax = currentVal; - _values[i].numSamplesConstantMax = 0 - } - - if (_values[i].numSamplesConstantMax > VALUE_HISTORY_SIZE) { - _values[i].numSamplesConstantMax = 0 - _values[i].valueMax *= 0.95 // lower slowly the current max if no new above max since a while - } - - if (currentValueMax < _values[i].valueMax) { - currentValueMax = _values[i].valueMax - } - } - - if ((valueMax < currentValueMax) || (tick % VALUE_HISTORY_SIZE == 0)) { - valueMax = currentValueMax; - } - - if (tick % UPDATE_CANVAS_RATE == 0) { - mycanvas.requestPaint() - } - } - onTriggerChanged: pullFreshValues() - - Canvas { - id: mycanvas - anchors.fill:parent - onPaint: { - var lineHeight = 12; - - function displayValue(val, unit) { - return (val / root.valueScale).toFixed(root.valueNumDigits) + " " + unit - } - - function pixelFromVal(val, valScale) { - return lineHeight + (height - lineHeight) * (1 - (0.9) * val / valueMax); - } - function valueFromPixel(pixY) { - return ((pixY - lineHeight) / (height - lineHeight) - 1) * valueMax / (-0.9); - } - function plotValueHistory(ctx, valHistory, color) { - var widthStep= width / (valHistory.length - 1); - - ctx.beginPath(); - ctx.strokeStyle= color; // Green path - ctx.lineWidth="2"; - ctx.moveTo(0, pixelFromVal(valHistory[0])); - - for (var i = 1; i < valHistory.length; i++) { - ctx.lineTo(i * widthStep, pixelFromVal(valHistory[i])); - } - - ctx.stroke(); - } - function displayValueLegend(ctx, val, num) { - ctx.fillStyle = val.color; - var bestValue = val.valueHistory[val.valueHistory.length -1]; - ctx.textAlign = "right"; - ctx.fillText(displayValue(bestValue, val.unit), width, (num + 2) * lineHeight * 1.5); - ctx.textAlign = "left"; - ctx.fillText(val.label, 0, (num + 2) * lineHeight * 1.5); - } - - function displayTitle(ctx, text, maxVal) { - ctx.fillStyle = "grey"; - ctx.textAlign = "right"; - ctx.fillText(displayValue(valueFromPixel(lineHeight), root.valueUnit), width, lineHeight); - - ctx.fillStyle = "white"; - ctx.textAlign = "left"; - ctx.fillText(text, 0, lineHeight); - } - function displayBackground(ctx) { - ctx.fillStyle = Qt.rgba(0, 0, 0, 0.6); - ctx.fillRect(0, 0, width, height); - - ctx.strokeStyle= "grey"; - ctx.lineWidth="2"; - - ctx.beginPath(); - ctx.moveTo(0, lineHeight + 1); - ctx.lineTo(width, lineHeight + 1); - ctx.moveTo(0, height); - ctx.lineTo(width, height); - ctx.stroke(); - } - - var ctx = getContext("2d"); - ctx.clearRect(0, 0, width, height); - ctx.font="12px Verdana"; - - displayBackground(ctx); - - for (var i = 0; i < _values.length; i++) { - plotValueHistory(ctx, _values[i].valueHistory, _values[i].color) - displayValueLegend(ctx, _values[i], i) - } - - displayTitle(ctx, title, valueMax) - } - } -}