From f9e712a8e788bb04d5305b8b72e2da27eb34f42e Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 9 Feb 2021 13:56:42 +0100 Subject: [PATCH 1/8] Supress a warning in exoplanets task --- modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp b/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp index e4fb0a4801..058122d86f 100644 --- a/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp +++ b/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp @@ -407,7 +407,7 @@ float ExoplanetsDataPreparationTask::bvFromTeff(float teff) { float bv = 0.f; float bvUpper = 0.f; float bvLower = 0.f; - float teffLower; + float teffLower = 0.f; float teffUpper; std::string row; while (std::getline(teffToBvFile, row)) { From 39d5be5b171591c8c8b5e386bdee5e5ee6724157 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 9 Feb 2021 15:10:59 +0100 Subject: [PATCH 2/8] Small habitable zone updates * Show optimistic boundaries per default * Shorten down interval UI name to make tooltip visible * Increase interval for Kopparapu's formula --- data/assets/scene/solarsystem/sun/habitablezone.asset | 3 ++- modules/space/rendering/renderablehabitablezone.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/data/assets/scene/solarsystem/sun/habitablezone.asset b/data/assets/scene/solarsystem/sun/habitablezone.asset index 9727e641fa..1816f4500b 100644 --- a/data/assets/scene/solarsystem/sun/habitablezone.asset +++ b/data/assets/scene/solarsystem/sun/habitablezone.asset @@ -11,7 +11,8 @@ local HabitableZone = { Texture = textures .. "/hot_to_cold_faded.png", EffectiveTemperature = 5780, -- Kelvin Luminosity = 1, -- solar - Opacity = 0.1 + Opacity = 0.1, + Optimistic = true }, GUI = { Name = "Sun Habitable Zone", diff --git a/modules/space/rendering/renderablehabitablezone.cpp b/modules/space/rendering/renderablehabitablezone.cpp index f2888a28c0..a8d0d4dc1d 100644 --- a/modules/space/rendering/renderablehabitablezone.cpp +++ b/modules/space/rendering/renderablehabitablezone.cpp @@ -69,10 +69,10 @@ namespace { constexpr openspace::properties::Property::PropertyInfo KopparapuTeffIntervalInfo = { "KopparapuTeffInterval", - "Effective Temperature Interval (Kopparapu's formula)" , - "The range for which Kopparapu's formula is used for the habitable zone " - "computation. For stars with effective temperatures outside the range, a " - "simpler method by Tom E. Harris is used. This method only uses the star " + "Kopparapu TEFF" , + "The effective temperature interval for which Kopparapu's formula is used for " + "the habitable zone computation. For stars with temperatures outside the range, " + "a simpler method by Tom E. Harris is used. This method only uses the star " "luminosity and does not include computation of the optimistic boundaries." }; } // namespace @@ -130,7 +130,7 @@ RenderableHabitableZone::RenderableHabitableZone(const ghoul::Dictionary& dictio , _teff(EffectiveTemperatureInfo, 5780.f, 0.f, 7.5e4f) , _luminosity(LuminosityInfo, 1.f, 0.f, 1e8f) , _showOptimistic(OptimisticInfo, false) - , _kopparapuTeffInterval(KopparapuTeffIntervalInfo, glm::vec2(2000.f, 8000.f)) + , _kopparapuTeffInterval(KopparapuTeffIntervalInfo, glm::vec2(1000.f, 10000.f)) { documentation::testSpecificationAndThrow( Documentation(), From 06be5f55910f5f5c5df17ab1ce19382f58f5c52e Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 9 Feb 2021 15:14:44 +0100 Subject: [PATCH 3/8] Suppress GCC warnings for float comparison --- support/cmake/set_openspace_compile_settings.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/support/cmake/set_openspace_compile_settings.cmake b/support/cmake/set_openspace_compile_settings.cmake index 3dee265c93..a0c96ab0a9 100644 --- a/support/cmake/set_openspace_compile_settings.cmake +++ b/support/cmake/set_openspace_compile_settings.cmake @@ -203,6 +203,7 @@ function (set_openspace_compile_settings target) "-Wlogical-op" "-Wint-in-bool-context" "-Wno-deprecated-copy" + "-Wno-float-equal" "-Wno-write-strings" "-Wnon-virtual-dtor" "-Wold-style-cast" From 9eb9095c127885db7fe3922502d7db52cdf042b5 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 10 Feb 2021 10:54:33 +0100 Subject: [PATCH 4/8] Tiny cleanup --- modules/globebrowsing/globebrowsingmodule.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index ffc5aa159b..bdfdd16a6f 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -67,8 +67,8 @@ #include "globebrowsingmodule_lua.inl" namespace { - constexpr const char* _loggerCat = "GlobeBrowsingModule"; - constexpr const char* _factoryName = "TileProvider"; + constexpr const char _loggerCat[] = "GlobeBrowsingModule"; + constexpr const char _factoryName[] = "TileProvider"; constexpr const openspace::properties::Property::PropertyInfo WMSCacheEnabledInfo = { "WMSCacheEnabled", @@ -163,19 +163,19 @@ namespace { struct [[codegen::Dictionary(GlobeBrowsingModule)]] Parameters { // [[codegen::verbatim(WMSCacheEnabledInfo.description)]] std::optional cacheEnabled [[codegen::key("WMSCacheEnabled")]]; - + // [[codegen::verbatim(OfflineModeInfo.description)]] std::optional offlineMode; - + // [[codegen::verbatim(WMSCacheLocationInfo.description)]] std::optional cacheLocation [[codegen::key("WMSCacheLocation")]]; - + // [[codegen::verbatim(WMSCacheSizeInfo.description)]] std::optional wmsCacheSize [[codegen::key("WMSCacheSize")]]; - + // [[codegen::verbatim(TileCacheSizeInfo.description)]] std::optional tileCacheSize; - + // If you know what you are doing and you have WMS caching *disabled* but offline // mode *enabled*, you can set this value to 'true' to silence a warning that you // would otherwise get at startup From 548d673e8bf968b6d8d0567e4fe36dab236faab3 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 11 Feb 2021 13:43:36 +0100 Subject: [PATCH 5/8] Add drag and drop support for images and assets (#1497) --- apps/OpenSpace/main.cpp | 12 ++++++ include/openspace/engine/openspaceengine.h | 1 + scripts/drag_drop_handler.lua | 43 ++++++++++++++++++++ src/engine/openspaceengine.cpp | 47 ++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 scripts/drag_drop_handler.lua diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index b370da39e6..2efc3e7061 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -660,6 +660,17 @@ void mainCharCallback(unsigned int codepoint, int modifiers) { +void mainDropCallback(int amount, const char** paths) { + ghoul_assert(amount > 0, "Expected at least one file path"); + ghoul_assert(paths, "expected non-nullptr"); + + for (int i = 0; i < amount; ++i) { + global::openSpaceEngine->handleDragDrop(paths[i]); + } +} + + + std::vector mainEncodeFun() { ZoneScoped LTRACE("main::mainEncodeFun(begin)"); @@ -1252,6 +1263,7 @@ int main(int argc, char* argv[]) { callbacks.mousePos = mainMousePosCallback; callbacks.mouseScroll = mainMouseScrollCallback; callbacks.character = mainCharCallback; + callbacks.drop = mainDropCallback; callbacks.encode = mainEncodeFun; callbacks.decode = mainDecodeFun; Log::instance().setNotifyLevel(Log::Level::Debug); diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 42612a9368..2710a709f3 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -86,6 +86,7 @@ public: void touchDetectionCallback(TouchInput input); void touchUpdateCallback(TouchInput input); void touchExitCallback(TouchInput input); + void handleDragDrop(const std::string& file); std::vector encode(); void decode(std::vector data); diff --git a/scripts/drag_drop_handler.lua b/scripts/drag_drop_handler.lua new file mode 100644 index 0000000000..7042333633 --- /dev/null +++ b/scripts/drag_drop_handler.lua @@ -0,0 +1,43 @@ +-- This script gets two parameters in its global scope: +-- filename: The full path for the file that was dropped on the application. +-- Example: C:/OpenSpace/openspace.cfg +-- basename: Only the name of the actual file with extension, but without the full rest +-- of the path. +-- Example: openspace.cfg +-- extension: The extention of the file +-- Example: .cfg +-- +-- From this script, we need to return the script that we want to be executed in response +-- to the drag event. If we don't want anything to happen, don't return anything or +-- return an empty string + +if filename == nil or filename == "" or + basename == nil or basename == "" or + extension == nil or extension == "" then + do return "" end +end + +-- Lua doesn't enjoy \ that are used by Windows extensively. So we convert all \ into / +filename = filename:gsub("\\", "/") +basename = basename:gsub("\\", "/") +basename_without_extension = basename:sub(0, #basename - extension:len()) + +is_image_file = function(extension) + return extension == ".png" or extension == ".jpg" or extension == ".jpeg" or + extension == ".tif" or extension == ".tga" or extension == ".bmp" or + extension == ".psd" or extension == ".gif" or extension == ".hdr" or + extension == ".pic" or extension == ".pnm" +end + +if is_image_file(extension) then + identifier = basename_without_extension:gsub(" ", "_") + return [[openspace.addScreenSpaceRenderable({ + Identifier = "]] .. identifier .. [[", + Type = "ScreenSpaceImageLocal", + TexturePath = "]] .. filename .. [[" + });]] +elseif extension == ".asset" then + return [[openspace.asset.add("]] .. filename .. [[")]] +elseif extension == ".osrec" or extension == ".osrectxt" then + return [[openspace.sessionRecording.startPlayback("]] .. basename .. [[")]] +end diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 00c135152d..3d1d6dd868 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -83,6 +83,7 @@ #include #include #include +#include #include #include #include @@ -1444,6 +1445,52 @@ void OpenSpaceEngine::touchExitCallback(TouchInput input) { } } +void OpenSpaceEngine::handleDragDrop(const std::string& file) { + std::filesystem::path f(file); + + ghoul::lua::LuaState s(ghoul::lua::LuaState::IncludeStandardLibrary::Yes); + std::string absolutePath = absPath("${SCRIPTS}/drag_drop_handler.lua"); + int status = luaL_loadfile(s, absolutePath.c_str()); + if (status != LUA_OK) { + std::string error = lua_tostring(s, -1); + LERROR(error); + return; + } + + ghoul::lua::push(s, file); + lua_setglobal(s, "filename"); + + std::string basename = f.filename().string(); + ghoul::lua::push(s, basename); + lua_setglobal(s, "basename"); + + std::string extension = f.extension().string(); + std::transform( + extension.begin(), extension.end(), + extension.begin(), + [](char c) { return static_cast(::tolower(c)); } + ); + ghoul::lua::push(s, extension); + lua_setglobal(s, "extension"); + + status = lua_pcall(s, 0, 1, 0); + if (status != LUA_OK) { + std::string error = lua_tostring(s, -1); + LERROR(error); + return; + } + + if (lua_isnil(s, -1)) { + LWARNING(fmt::format("Unhandled file dropped: {}", file)); + return; + } + + std::string script = ghoul::lua::value(s); + global::scriptEngine->queueScript( + script, + scripting::ScriptEngine::RemoteScripting::Yes + ); +} std::vector OpenSpaceEngine::encode() { ZoneScoped From 88122d1dbbc9cef9c48bf78bc6222063aa8b50e6 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 11 Feb 2021 14:44:13 +0100 Subject: [PATCH 6/8] Adapt to new Ghoul; fix previously undetected errors in uniform setting --- ext/ghoul | 2 +- modules/base/rendering/renderablemodel.cpp | 6 ++---- .../rendering/renderableplanetprojection.cpp | 2 +- .../volume/rendering/basicvolumeraycaster.cpp | 4 ++-- modules/volume/tasks/generaterawvolumetask.cpp | 8 ++++++++ src/documentation/documentation.cpp | 17 ++++++++++------- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index 2f1bb7c483..6cc191d429 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 2f1bb7c483f4792317b8f1a3da17e2270c0d0ae7 +Subproject commit 6cc191d4293a68faf559d090dd33e340b9137d63 diff --git a/modules/base/rendering/renderablemodel.cpp b/modules/base/rendering/renderablemodel.cpp index ec98dc83e8..274bdd1d6a 100644 --- a/modules/base/rendering/renderablemodel.cpp +++ b/modules/base/rendering/renderablemodel.cpp @@ -438,13 +438,11 @@ void RenderableModel::render(const RenderData& data, RendererTasks&) { ); _program->setUniform( _uniformCache.lightIntensities, - _lightIntensitiesBuffer.data(), - nLightSources + _lightIntensitiesBuffer ); _program->setUniform( _uniformCache.lightDirectionsViewSpace, - _lightDirectionsViewSpaceBuffer.data(), - nLightSources + _lightDirectionsViewSpaceBuffer ); _program->setUniform( _uniformCache.modelViewTransform, diff --git a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp index 23ac686770..4c2f2479ee 100644 --- a/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplanetprojection.cpp @@ -481,7 +481,7 @@ void RenderablePlanetProjection::imageProjectGPU( if (_geometry->hasProperty("Radius")) { std::any r = _geometry->property("Radius")->get(); if (glm::vec3* radius = std::any_cast(&r)){ - _fboProgramObject->setUniform(_fboUniformCache.radius, radius); + _fboProgramObject->setUniform(_fboUniformCache.radius, *radius); } } else { diff --git a/modules/volume/rendering/basicvolumeraycaster.cpp b/modules/volume/rendering/basicvolumeraycaster.cpp index d4f8516134..ed547063ca 100644 --- a/modules/volume/rendering/basicvolumeraycaster.cpp +++ b/modules/volume/rendering/basicvolumeraycaster.cpp @@ -135,8 +135,8 @@ void BasicVolumeRaycaster::preRaycast(const RaycastData& data, int nClips = static_cast(clipNormals.size()); program.setUniform("nClips_" + id, nClips); - program.setUniform("clipNormals_" + id, clipNormals.data(), nClips); - program.setUniform("clipOffsets_" + id, clipOffsets.data(), nClips); + program.setUniform("clipNormals_" + id, clipNormals); + program.setUniform("clipOffsets_" + id, clipOffsets); program.setUniform("opacity_" + id, _opacity); program.setUniform("rNormalization_" + id, _rNormalization); program.setUniform("rUpperBound_" + id, _rUpperBound); diff --git a/modules/volume/tasks/generaterawvolumetask.cpp b/modules/volume/tasks/generaterawvolumetask.cpp index 68e889fc72..6de0d6af6a 100644 --- a/modules/volume/tasks/generaterawvolumetask.cpp +++ b/modules/volume/tasks/generaterawvolumetask.cpp @@ -101,11 +101,15 @@ void GenerateRawVolumeTask::perform(const Task::ProgressCallback& progressCallba ghoul::lua::LuaState state; ghoul::lua::runScript(state, _valueFunctionLua); +#if (defined(NDEBUG) || defined(DEBUG)) ghoul::lua::verifyStackSize(state, 1); +#endif int functionReference = luaL_ref(state, LUA_REGISTRYINDEX); +#if (defined(NDEBUG) || defined(DEBUG)) ghoul::lua::verifyStackSize(state, 0); +#endif glm::vec3 domainSize = _upperDomainBound - _lowerDomainBound; @@ -117,14 +121,18 @@ void GenerateRawVolumeTask::perform(const Task::ProgressCallback& progressCallba glm::vec3 coord = _lowerDomainBound + glm::vec3(cell) / glm::vec3(_dimensions) * domainSize; +#if (defined(NDEBUG) || defined(DEBUG)) ghoul::lua::verifyStackSize(state, 0); +#endif lua_rawgeti(state, LUA_REGISTRYINDEX, functionReference); lua_pushnumber(state, coord.x); lua_pushnumber(state, coord.y); lua_pushnumber(state, coord.z); +#if (defined(NDEBUG) || defined(DEBUG)) ghoul::lua::verifyStackSize(state, 4); +#endif if (lua_pcall(state, 3, 1, 0) != LUA_OK) { return; diff --git a/src/documentation/documentation.cpp b/src/documentation/documentation.cpp index ef1bfc8843..4cf633f28e 100644 --- a/src/documentation/documentation.cpp +++ b/src/documentation/documentation.cpp @@ -129,17 +129,20 @@ namespace openspace::documentation { const std::string DocumentationEntry::Wildcard = "*"; +std::string concatenate(const std::vector& offenses) { + std::string result = "Error in specification ("; + for (const TestResult::Offense& o : offenses) { + result += o.offender + ','; + } + result.back() = ')'; + return result; +} + SpecificationError::SpecificationError(TestResult res, std::string comp) - : ghoul::RuntimeError("Error in specification", std::move(comp)) + : ghoul::RuntimeError(concatenate(res.offenses), std::move(comp)) , result(std::move(res)) { ghoul_assert(!result.success, "Result's success must be false"); - - message += " ("; - for (const TestResult::Offense& o : result.offenses) { - message += o.offender + ','; - } - message.back() = ')'; } DocumentationEntry::DocumentationEntry(std::string k, std::shared_ptr v, From aeb62978ab1641479ac7cd469b2f8488487f9248 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 11 Feb 2021 14:51:53 +0100 Subject: [PATCH 7/8] Set the default startup project in Visual Studio to 'OpenSpace' (closes #1503) --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a3c2a8c767..96ab1ca6c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,6 +203,12 @@ begin_header("Configuring Applications") add_subdirectory("${OPENSPACE_APPS_DIR}") end_header("End: Configuring Applications") + +if (MSVC AND TARGET OpenSpace) + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT OpenSpace) +endif() + + option(OPENSPACE_HAVE_TESTS "Activate the OpenSpace unit tests" ON) if (OPENSPACE_HAVE_TESTS) begin_header("Generating OpenSpace unit test") From 11e5bc36abc2cc122f2c5d8ad4ab6c01634a26ac Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 11 Feb 2021 16:24:36 +0100 Subject: [PATCH 8/8] Prevent exception when querying renderable of non-existing SGN --- src/query/query.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/query/query.cpp b/src/query/query.cpp index 5f84919aab..6ab37a893d 100644 --- a/src/query/query.cpp +++ b/src/query/query.cpp @@ -45,6 +45,9 @@ SceneGraphNode* sceneGraphNode(const std::string& name) { const Renderable* renderable(const std::string& name) { SceneGraphNode* node = sceneGraphNode(name); + if (!node) { + return nullptr; + } return node->renderable(); }