From 09768054e9db6c321db690bdc86b0f44b66d86d4 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 29 Jan 2021 14:15:37 +0100 Subject: [PATCH] Update to new dictionary --- .../rendering/renderablepointscloud.cpp | 32 +++---- .../softwareintegrationmodule.cpp | 93 +++++++------------ 2 files changed, 47 insertions(+), 78 deletions(-) diff --git a/modules/softwareintegration/rendering/renderablepointscloud.cpp b/modules/softwareintegration/rendering/renderablepointscloud.cpp index 095fbc7049..a705c2ba0b 100644 --- a/modules/softwareintegration/rendering/renderablepointscloud.cpp +++ b/modules/softwareintegration/rendering/renderablepointscloud.cpp @@ -132,7 +132,7 @@ namespace openspace { ); if (dictionary.hasKey(ColorInfo.identifier)) { - _color = dictionary.value(ColorInfo.identifier); + _color = dictionary.value(ColorInfo.identifier); } _color.setViewOption(properties::Property::ViewOptions::Color); addProperty(_color); @@ -143,32 +143,30 @@ namespace openspace { ); for (int i = 0; i < static_cast(pointDataDict.size()); ++i) { _pointData.push_back( - { pointDataDict.value(std::to_string(i + 1)) } + { pointDataDict.value(std::to_string(i + 1)) } ); } _hasPointData = true; } if (dictionary.hasKey(KeyLuminosity)) { - ghoul::Dictionary luminosityDataDict = dictionary.value( - KeyLuminosity - ); - for (int i = 0; i < static_cast(luminosityDataDict.size()); ++i) { - _luminosityData.push_back( - { luminosityDataDict.value(std::to_string(i + 1)) } + ghoul::Dictionary lumDict = dictionary.value(KeyLuminosity); + for (int i = 0; i < static_cast(lumDict.size()); ++i) { + float luminosity = static_cast( + lumDict.value(std::to_string(i + 1)) ); + _luminosityData.push_back(luminosity); } _hasLuminosityData = true; } if (dictionary.hasKey(KeyVelocity)) { - ghoul::Dictionary velocityDataDict = dictionary.value( - KeyVelocity - ); - for (int i = 0; i < static_cast(velocityDataDict.size()); ++i) { - _velocityData.push_back( - { velocityDataDict.value(std::to_string(i + 1)) } + ghoul::Dictionary velDict = dictionary.value(KeyVelocity); + for (int i = 0; i < static_cast(velDict.size()); ++i) { + float velocity = static_cast( + velDict.value(std::to_string(i + 1)) ); + _velocityData.push_back(velocity); } _hasVelocityData = true; } @@ -196,7 +194,7 @@ namespace openspace { return ((_shaderProgram != nullptr) && (!_fullData.empty())); } - void RenderablePointsCloud::initialize() { + void RenderablePointsCloud::initialize() { bool isSuccessful = loadData(); if (!isSuccessful) { throw ghoul::RuntimeError("Error loading data"); @@ -269,7 +267,7 @@ namespace openspace { } } - void RenderablePointsCloud::update(const UpdateData&) { + void RenderablePointsCloud::update(const UpdateData&) { if (!_isDirty) { return; } @@ -311,7 +309,7 @@ namespace openspace { nullptr ); } - + glBindVertexArray(0); _isDirty = false; diff --git a/modules/softwareintegration/softwareintegrationmodule.cpp b/modules/softwareintegration/softwareintegrationmodule.cpp index abde80fa71..d43d54e3fd 100644 --- a/modules/softwareintegration/softwareintegrationmodule.cpp +++ b/modules/softwareintegration/softwareintegrationmodule.cpp @@ -185,9 +185,9 @@ namespace openspace { std::string software(message.begin(), message.end()); LINFO(fmt::format("OpenSpace has connected with {} through socket.", software)); break; - } + } case SoftwareConnection::MessageType::ReadPointData: { - messageOffset = 0; // Resets message offset + messageOffset = 0; // Resets message offset std::vector xCoordinates = readData(message); std::vector yCoordinates = readData(message); @@ -206,14 +206,14 @@ namespace openspace { break; } case SoftwareConnection::MessageType::ReadLuminosityData: { - messageOffset = 0; // Resets message offset + messageOffset = 0; // Resets message offset luminosityData.clear(); luminosityData = readData(message); break; } case SoftwareConnection::MessageType::ReadVelocityData: { - messageOffset = 0; // Resets message offset + messageOffset = 0; // Resets message offset velocityData.clear(); velocityData = readData(message); @@ -230,81 +230,52 @@ namespace openspace { float opacity = readFloatValue(message); float size = readFloatValue(message); std::string guiName = readGUI(message); - + bool hasLuminosityData = !luminosityData.empty(); bool hasVelocityData = !velocityData.empty(); - ghoul::Dictionary renderable; ghoul::Dictionary pointDataDictonary; ghoul::Dictionary luminosityDataDictonary; ghoul::Dictionary velocityDataDictionary; for (int i = 0; i < pointData.size(); ++i) { - pointDataDictonary.setValue(std::to_string(i + 1), pointData[i]); + pointDataDictonary.setValue(std::to_string(i + 1), pointData[i]); } if (hasLuminosityData) { for (int i = 0; i < luminosityData.size(); ++i) { - luminosityDataDictonary.setValue(std::to_string(i + 1), luminosityData[i]); + luminosityDataDictonary.setValue(std::to_string(i + 1), luminosityData[i]); } } if (hasVelocityData) { for (int i = 0; i < velocityData.size(); ++i) { - velocityDataDictionary.setValue(std::to_string(i + 1), velocityData[i]); + velocityDataDictionary.setValue(std::to_string(i + 1), velocityData[i]); } } // Create a renderable depending on what data was received - if (hasLuminosityData && hasVelocityData) { - renderable = { - { "Type", "RenderablePointsCloud"s }, - { "Color", static_cast(color)}, - { "Data", pointDataDictonary }, - { "Luminosity", luminosityDataDictonary }, - { "Opacity", static_cast(opacity) }, - { "Size", static_cast(size)}, - { "Velocity", velocityDataDictionary } - }; - } - else if (hasLuminosityData && !hasVelocityData) { - renderable = { - { "Type", "RenderablePointsCloud"s }, - { "Color", static_cast(color)}, - { "Data", pointDataDictonary }, - { "Luminosity", luminosityDataDictonary }, - { "Opacity", static_cast(opacity) }, - { "Size", static_cast(size)}, - }; - } - else if (!hasLuminosityData && hasVelocityData) { - renderable = { - { "Type", "RenderablePointsCloud"s }, - { "Color", static_cast(color)}, - { "Data", pointDataDictonary }, - { "Opacity", static_cast(opacity) }, - { "Size", static_cast(size)}, - { "Velocity", velocityDataDictionary } - }; - } - else { - renderable = { - { "Type", "RenderablePointsCloud"s }, - { "Color", static_cast(color)}, - { "Data", pointDataDictonary }, - { "Opacity", static_cast(opacity) }, - { "Size", static_cast(size)}, - }; - } - - ghoul::Dictionary gui = { - { "Name", guiName }, - { "Path", "/Examples"s } - }; + ghoul::Dictionary renderable; + renderable.setValue("Type", "RenderablePointsCloud"s); + renderable.setValue("Color", static_cast(color)); + renderable.setValue("Data", pointDataDictonary); + renderable.setValue("Opacity", static_cast(opacity)); + renderable.setValue("Size", static_cast(size)); - ghoul::Dictionary node = { - { "Identifier", identifier }, - { "Renderable", renderable }, - { "GUI", gui } - }; + if (hasLuminosityData) { + renderable.setValue("Luminosity", luminosityDataDictonary); + } + + if (hasVelocityData) { + renderable.setValue("Velocity", velocityDataDictionary); + } + + ghoul::Dictionary gui; + gui.setValue("Name", guiName); + gui.setValue("Path", "/Examples"s); + + ghoul::Dictionary node; + node.setValue("Identifier", identifier); + node.setValue("Renderable", renderable); + node.setValue("GUI", gui); try { SceneGraphNode* sgn = global::renderEngine->scene()->loadNode(node); @@ -340,7 +311,7 @@ namespace openspace { LDEBUG(fmt::format("Message recieved.. Delete SGN: {}", identifier)); SceneGraphNode* sgn = global::renderEngine->scene()->sceneGraphNode(identifier); - + if (global::navigationHandler->orbitalNavigator().anchorNode() == sgn) { openspace::global::scriptEngine->queueScript( "openspace.setPropertyValueSingle('NavigationHandler.OrbitalNavigator.Anchor', 'Sun')" @@ -510,7 +481,7 @@ namespace openspace { propertyValue = "T"; std::string subject = lengthOfIdentifier + identifier + propertyValue; - // We don't need a lengthOfValue here because it will always be 1 character + // We don't need a lengthOfValue here because it will always be 1 character // Format length of subject to always be 4 digits std::ostringstream os;