From c102f2ce67e1e6f0142cd46ea4a0ac192206faff Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 14 Mar 2018 13:12:45 -0400 Subject: [PATCH 001/123] empty exoplanet module --- modules/exoplanets/CMakeLists.txt | 42 ++++++++++++++++++++ modules/exoplanets/exoplanetsmodule.cpp | 51 +++++++++++++++++++++++++ modules/exoplanets/exoplanetsmodule.h | 47 +++++++++++++++++++++++ modules/exoplanets/include.cmake | 1 + 4 files changed, 141 insertions(+) create mode 100644 modules/exoplanets/CMakeLists.txt create mode 100644 modules/exoplanets/exoplanetsmodule.cpp create mode 100644 modules/exoplanets/exoplanetsmodule.h create mode 100644 modules/exoplanets/include.cmake diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt new file mode 100644 index 0000000000..5316d83dde --- /dev/null +++ b/modules/exoplanets/CMakeLists.txt @@ -0,0 +1,42 @@ +########################################################################################## +# # +# OpenSpace # +# # +# Copyright (c) 2014-2018 # +# # +# Permission is hereby granted, free of charge, to any person obtaining a copy of this # +# software and associated documentation files (the "Software"), to deal in the Software # +# without restriction, including without limitation the rights to use, copy, modify, # +# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to # +# permit persons to whom the Software is furnished to do so, subject to the following # +# conditions: # +# # +# The above copyright notice and this permission notice shall be included in all copies # +# or substantial portions of the Software. # +# # +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, # +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A # +# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT # +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF # +# CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE # +# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # +########################################################################################## + +include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) + +set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h +) +source_group("Header Files" FILES ${HEADER_FILES}) + +set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp +) +source_group("Source Files" FILES ${SOURCE_FILES}) + +create_new_module( + "Exoplanets" + exoplanets_module + STATIC + ${HEADER_FILES} ${SOURCE_FILES} +) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp new file mode 100644 index 0000000000..ccf17963f7 --- /dev/null +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -0,0 +1,51 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +//#include +//#include + +//#include + +namespace openspace { + +ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} + +void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { + //auto fRenderable = FactoryManager::ref().factory(); + //ghoul_assert(fRenderable, "No renderable factory existed"); + + //fRenderable->registerClass("RenderableDebugPlane"); +} + +std::vector ExoplanetsModule::documentations() const { + return { + //RenderableDebugPlane::Documentation() + }; +} + + +} // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h new file mode 100644 index 0000000000..0d95e99f4e --- /dev/null +++ b/modules/exoplanets/exoplanetsmodule.h @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ +#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ + +#include + +namespace openspace { + +class ExoplanetsModule : public OpenSpaceModule { +public: + constexpr static const char* Name = "Exoplanets"; + + ExoplanetsModule(); + + + std::vector documentations() const override; + +protected: + void internalInitialize(const ghoul::Dictionary&) override; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ diff --git a/modules/exoplanets/include.cmake b/modules/exoplanets/include.cmake new file mode 100644 index 0000000000..ffea0ac430 --- /dev/null +++ b/modules/exoplanets/include.cmake @@ -0,0 +1 @@ +set(DEFAULT_MODULE ON) From c0d04bbe228dcdc52a29fcb46991e473780e257a Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 15 Mar 2018 16:01:18 -0400 Subject: [PATCH 002/123] first lua-script to add scene graph nodes with renderable plane for star at arbitrary position --- modules/exoplanets/exoplanetsmodule.cpp | 66 ++++++++++++++++++++++--- modules/exoplanets/exoplanetsmodule.h | 6 ++- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index ccf17963f7..bb88ce4b3e 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -25,27 +25,79 @@ #include #include +#include + //#include //#include -//#include +#include namespace openspace { ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} -void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { +int addNode(lua_State* L) { + + // get name of star and add a node at the position of the star. + // position is found in the star-files + // after the node has been added one should be able to select it as a focus point. + + //start + + const int StringLocation = -1; //first argument + const std::string starname = luaL_checkstring(L, StringLocation); + + //printf(starname.c_str()); + + // adding the parent node of the exoplanet system + const std::string luaTableParent = "{ Name = '" + starname +"', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = {4662120063743.592773, 1263245003503.724854, -955413856565.788086} } }}"; // positionen must be gathered from star.speck + const std::string scriptParent = "openspace.addSceneGraphNode("+ luaTableParent +");"; + OsEng.scriptEngine().queueScript( + scriptParent, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + // adding a renderable in the place of the stars + const std::string luaTableStarGlare = "{ Name = '" + starname + "Plane', Parent = '" + starname +"', Renderable = { Type = 'RenderablePlaneImageLocal', Size = 1.3*10^10.5, Billboard = true, Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png', BlendMode = 'Additive' } }"; + const std::string scriptGlare= "openspace.addSceneGraphNode("+ luaTableStarGlare +");"; + OsEng.scriptEngine().queueScript( + scriptGlare, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + +} + +scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { + + scripting::LuaLibrary res; + res.name = "exoplanets"; + res.functions = { + { + "addNode", + &addNode, + {}, + "string", + "Adds print message." + } + + }; + + return res; +} + +//void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { //auto fRenderable = FactoryManager::ref().factory(); //ghoul_assert(fRenderable, "No renderable factory existed"); //fRenderable->registerClass("RenderableDebugPlane"); -} +//} -std::vector ExoplanetsModule::documentations() const { - return { +//std::vector ExoplanetsModule::documentations() const { + //return { //RenderableDebugPlane::Documentation() - }; -} + //}; +//} } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index 0d95e99f4e..d37f6a721f 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ #include +#include namespace openspace { @@ -35,11 +36,12 @@ public: ExoplanetsModule(); + scripting::LuaLibrary luaLibrary() const override; - std::vector documentations() const override; + //std::vector documentations() const override; protected: - void internalInitialize(const ghoul::Dictionary&) override; + //void internalInitialize(const ghoul::Dictionary&) override; }; } // namespace openspace From 3fd846530fe9ed55147bf115ff93b8005fc66d86 Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 16 Mar 2018 14:04:00 -0400 Subject: [PATCH 003/123] WIP: getting position of star from stars.speck --- modules/exoplanets/exoplanetsmodule.cpp | 97 +++++++++++++++++++++++-- 1 file changed, 92 insertions(+), 5 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index bb88ce4b3e..be8a0551a0 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -32,10 +32,96 @@ #include +#include + namespace openspace { ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} +std::vector readSpeckFile(std::string starname) { + std::ifstream file("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/stars.speck"); + if (!file.good()) { + std::cout << "Failed to open Speck file '{}'"; + } + + int _nValuesPerStar = 0; + + // The beginning of the speck file has a header that either contains comments + // (signaled by a preceding '#') or information about the structure of the file + // (signaled by the keywords 'datavar', 'texturevar', and 'texture') + std::string line = ""; + while (true) { + std::streampos position = file.tellg(); + std::getline(file, line); + + if (line[0] == '#' || line.empty()) { + continue; + } + + if (line.substr(0, 7) != "datavar" && + line.substr(0, 10) != "texturevar" && + line.substr(0, 7) != "texture") + { + // we read a line that doesn't belong to the header, so we have to jump back + // before the beginning of the current line + file.seekg(position); + break; + } + + if (line.substr(0, 7) == "datavar") { + // datavar lines are structured as follows: + // datavar # description + // where # is the index of the data variable; so if we repeatedly overwrite + // the 'nValues' variable with the latest index, we will end up with the total + // number of values (+3 since X Y Z are not counted in the Speck file index) + std::stringstream str(line); + + std::string dummy; + str >> dummy; + str >> _nValuesPerStar; + _nValuesPerStar += 1; // We want the number, but the index is 0 based + } + } + + _nValuesPerStar += 3; // X Y Z are not counted in the Speck file indices + + do { + std::vector values(_nValuesPerStar); + + std::getline(file, line); + std::stringstream str(line); + + for (int i = 0; i < _nValuesPerStar; ++i) { + str >> values[i]; + } + + std::string next; + std::getline(str, next); + std::stringstream namestr(next); + + // 1. ignore first # + // 2. push all names in the rest of the stream to a array + std::string value; + std::vector names; + + while (namestr >> value) { + if (value == "#" || value == "|") + continue; + else { + names.push_back(value); + } + } + + for (size_t i = 0; i < names.size(); ++i) { + if (!names[i].empty() && names[i].compare(starname) == 0) { + return values; + } + } + + } while (!file.eof()); + +} + int addNode(lua_State* L) { // get name of star and add a node at the position of the star. @@ -47,15 +133,17 @@ int addNode(lua_State* L) { const int StringLocation = -1; //first argument const std::string starname = luaL_checkstring(L, StringLocation); - //printf(starname.c_str()); + std::vector values = readSpeckFile(starname); + printf(std::to_string(values[0]).c_str()); // adding the parent node of the exoplanet system - const std::string luaTableParent = "{ Name = '" + starname +"', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = {4662120063743.592773, 1263245003503.724854, -955413856565.788086} } }}"; // positionen must be gathered from star.speck + //const std::string luaTableParent = "{ Name = '" + starname +"', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = {" + std::to_string(values[0]) + ", " + std::to_string(values[1]) + ", " + std::to_string(values[2]) + "} } }}"; // positionen must be gathered from star.speck + const std::string luaTableParent = "{ Name = '" + starname + "', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = { -6.5825, -1.6713, 25.2259} } }}"; const std::string scriptParent = "openspace.addSceneGraphNode("+ luaTableParent +");"; OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + ); // adding a renderable in the place of the stars const std::string luaTableStarGlare = "{ Name = '" + starname + "Plane', Parent = '" + starname +"', Renderable = { Type = 'RenderablePlaneImageLocal', Size = 1.3*10^10.5, Billboard = true, Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png', BlendMode = 'Additive' } }"; @@ -65,7 +153,6 @@ int addNode(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - } scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { @@ -78,7 +165,7 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { &addNode, {}, "string", - "Adds print message." + "Adds two nodes to the scenegraph, one position node and one node to represenet the star." } }; From fdf8038306f921bb4e23a13059ebe9ca6947f3d4 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 19 Mar 2018 13:59:07 -0400 Subject: [PATCH 004/123] lua function adds nodes to place star at position stated in star.speck --- modules/exoplanets/exoplanetsmodule.cpp | 77 +++++++++++++++---------- 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index be8a0551a0..ba970d2fa4 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -41,7 +41,7 @@ ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} std::vector readSpeckFile(std::string starname) { std::ifstream file("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/stars.speck"); if (!file.good()) { - std::cout << "Failed to open Speck file '{}'"; + std::cout << "Failed to open Speck file"; } int _nValuesPerStar = 0; @@ -84,25 +84,24 @@ std::vector readSpeckFile(std::string starname) { } _nValuesPerStar += 3; // X Y Z are not counted in the Speck file indices + std::vector coords; do { - std::vector values(_nValuesPerStar); + std::vector temp(_nValuesPerStar); std::getline(file, line); std::stringstream str(line); for (int i = 0; i < _nValuesPerStar; ++i) { - str >> values[i]; + str >> temp[i]; } std::string next; std::getline(str, next); std::stringstream namestr(next); - // 1. ignore first # - // 2. push all names in the rest of the stream to a array std::string value; - std::vector names; + std::vector names; while (namestr >> value) { if (value == "#" || value == "|") @@ -113,45 +112,61 @@ std::vector readSpeckFile(std::string starname) { } for (size_t i = 0; i < names.size(); ++i) { - if (!names[i].empty() && names[i].compare(starname) == 0) { - return values; + if (names[i].compare(starname) == 0) { + for (int i = 0; i < 3; i++) { + coords.push_back(temp[i]); + } + return coords; } } } while (!file.eof()); + return coords; } int addNode(lua_State* L) { - // get name of star and add a node at the position of the star. - // position is found in the star-files - // after the node has been added one should be able to select it as a focus point. - - //start - - const int StringLocation = -1; //first argument + const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); std::vector values = readSpeckFile(starname); - printf(std::to_string(values[0]).c_str()); - // adding the parent node of the exoplanet system - //const std::string luaTableParent = "{ Name = '" + starname +"', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = {" + std::to_string(values[0]) + ", " + std::to_string(values[1]) + ", " + std::to_string(values[2]) + "} } }}"; // positionen must be gathered from star.speck - const std::string luaTableParent = "{ Name = '" + starname + "', Parent = 'SolarSystemBarycenter', Transform = { Translation = { Type = 'StaticTranslation', Position = { -6.5825, -1.6713, 25.2259} } }}"; - const std::string scriptParent = "openspace.addSceneGraphNode("+ luaTableParent +");"; - OsEng.scriptEngine().queueScript( - scriptParent, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + if (!values.empty()) + { + double parsecinmeter = 3.08567758*10e16; - // adding a renderable in the place of the stars - const std::string luaTableStarGlare = "{ Name = '" + starname + "Plane', Parent = '" + starname +"', Renderable = { Type = 'RenderablePlaneImageLocal', Size = 1.3*10^10.5, Billboard = true, Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png', BlendMode = 'Additive' } }"; - const std::string scriptGlare= "openspace.addSceneGraphNode("+ luaTableStarGlare +");"; - OsEng.scriptEngine().queueScript( - scriptGlare, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + const std::string luaTableParent = "{" + "Name = '" + starname + "'," + "Parent = 'SolarSystemBarycenter'," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(values[0] * parsecinmeter) + ", " + std::to_string(values[1] * parsecinmeter) + ", " + std::to_string(values[2] * parsecinmeter) + "}" + "}" + "}" + "}"; + const std::string luaTableStarGlare = "{" + "Name = '" + starname + "Plane'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 1.3*10^10.5," + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," + "BlendMode = 'Additive'" + "}" + "}"; + const std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ");"; + OsEng.scriptEngine().queueScript( + scriptParent, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + else + { + printf("No star with that name."); + } } From e0c6ec973022c4a72c616a31fd8e3f25bf996c53 Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 22 Mar 2018 10:47:51 -0400 Subject: [PATCH 005/123] adds a node for an exoplanet around the star. corrections to the units. --- modules/exoplanets/exoplanetsmodule.cpp | 57 ++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index ba970d2fa4..527942195a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -151,13 +151,45 @@ int addNode(lua_State* L) { "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderablePlaneImageLocal'," - "Size = 1.3*10^10.5," + "Size = 0.68 * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," "BlendMode = 'Additive'" "}" "}"; - const std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ");"; + const std::string luaTablePlanet = "{" + "Name = '" + starname + "Planet'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = 0.1*7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "SegmentsPerPatch = 64," + "Layers = {" + "ColorLayers = {" + "{" + "Name = 'Exoplanet Texture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" + "}" + "}" + "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = 0.05," //ECC + "SemiMajorAxis = 0.177758 * 149597871," // 149 597 871km = 1 AU. A + "Inclination = 88.91," //I + "AscendingNode = 35.5," //BIGOM + "ArgumentOfPeriapsis = 356.2," //OM + "MeanAnomaly = 0.0," + "Epoch = '2010 07 14 19:34:21.8'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = 32.03 * 86400" //PER. 86 400sec = 1 day. + "}" + "}," + "}"; + + const std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + "); openspace.addSceneGraphNode(" + luaTablePlanet + ");"; OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -168,6 +200,20 @@ int addNode(lua_State* L) { printf("No star with that name."); } + return 0; +} + +int removeNode(lua_State* L) { + const int StringLocation = -1; + const std::string starname = luaL_checkstring(L, StringLocation); + + const std::string scriptParent = "openspace.removeSceneGraphNode('" + starname + "Planet'); openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');"; + OsEng.scriptEngine().queueScript( + scriptParent, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + return 0; } scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { @@ -181,6 +227,13 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { {}, "string", "Adds two nodes to the scenegraph, one position node and one node to represenet the star." + }, + { + "removeNode", + &removeNode, + {}, + "string", + "Removes the node with the name given in teh arguments." } }; From e094904269fbe31ad200231a92820459d91b55fb Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 6 Apr 2018 17:28:21 -0400 Subject: [PATCH 006/123] getting the data for the nodes from the bin file with the parsed data --- modules/exoplanets/exoplanetsmodule.cpp | 236 ++++++++++++++---------- 1 file changed, 136 insertions(+), 100 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 527942195a..7bd424a5a6 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -33,107 +33,142 @@ #include #include +#include +#include + +struct exoplanet { + float A; + double AUPPER; + double ALOWER; + double UA; + float BIGOM; + float BIGOMUPPER; + float BIGOMLOWER; + float UBIGOM; + float ECC; + float ECCUPPER; + float ECCLOWER; + float UECC; + float I; + float IUPPER; + float ILOWER; + float UI; + float KOI; + int MULT; // 0 and 1 are values(boolean), -1 indicates missing value + float OM; + float OMUPPER; + float OMLOWER; + float UOM; + double PER; + float PERUPPER; //skrivs med e ibland + float PERLOWER; //skrivs med e ibland + float UPER; //skrivs med e ibland + double R; + double RUPPER; + double RLOWER; + double UR; + float RSTAR; + float RSTARUPPER; + float RSTARLOWER; + float URSTAR; + float TEFF; + float TEFFUPPER; + float TEFFLOWER; + float UTEFF; + double TT; + float TTUPPER; + float TTLOWER; + float UTT; + float POSITIONX; + float POSITIONY; + float POSITIONZ; +}; namespace openspace { ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} -std::vector readSpeckFile(std::string starname) { - std::ifstream file("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/stars.speck"); - if (!file.good()) { - std::cout << "Failed to open Speck file"; - } - - int _nValuesPerStar = 0; - - // The beginning of the speck file has a header that either contains comments - // (signaled by a preceding '#') or information about the structure of the file - // (signaled by the keywords 'datavar', 'texturevar', and 'texture') - std::string line = ""; - while (true) { - std::streampos position = file.tellg(); - std::getline(file, line); - - if (line[0] == '#' || line.empty()) { - continue; - } - - if (line.substr(0, 7) != "datavar" && - line.substr(0, 10) != "texturevar" && - line.substr(0, 7) != "texture") - { - // we read a line that doesn't belong to the header, so we have to jump back - // before the beginning of the current line - file.seekg(position); - break; - } - - if (line.substr(0, 7) == "datavar") { - // datavar lines are structured as follows: - // datavar # description - // where # is the index of the data variable; so if we repeatedly overwrite - // the 'nValues' variable with the latest index, we will end up with the total - // number of values (+3 since X Y Z are not counted in the Speck file index) - std::stringstream str(line); - - std::string dummy; - str >> dummy; - str >> _nValuesPerStar; - _nValuesPerStar += 1; // We want the number, but the index is 0 based - } - } - - _nValuesPerStar += 3; // X Y Z are not counted in the Speck file indices - std::vector coords; - - do { - std::vector temp(_nValuesPerStar); - - std::getline(file, line); - std::stringstream str(line); - - for (int i = 0; i < _nValuesPerStar; ++i) { - str >> temp[i]; - } - - std::string next; - std::getline(str, next); - std::stringstream namestr(next); - - std::string value; - std::vector names; - - while (namestr >> value) { - if (value == "#" || value == "|") - continue; - else { - names.push_back(value); - } - } - - for (size_t i = 0; i < names.size(); ++i) { - if (names[i].compare(starname) == 0) { - for (int i = 0; i < 3; i++) { - coords.push_back(temp[i]); - } - return coords; - } - } - - } while (!file.eof()); - - return coords; -} - int addNode(lua_State* L) { const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); + const std::string starname = luaL_checkstring(L, StringLocation); // has white spaces - std::vector values = readSpeckFile(starname); - if (!values.empty()) + std::ifstream data("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/data.bin", std::ios::in | std::ios::binary); + if (!data.good()) { + std::cout << "Failed to open exoplanets data file"; + } + + std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lut.txt"); + if (!lut.good()) { + std::cout << "Failed to open exoplanets look-up table file"; + } + + //1. search lut for the starname and return the corresponding location + //2. go to that location in the data file + //3. read sizeof(exoplanet) bytes into an exoplanet object. + std::string planetname; + size_t len = 0; + exoplanet p; + std::string line; + bool found = false; + while (getline(lut, line)) { + + std::istringstream ss(line); + getline(ss, planetname, ','); + + if (planetname.compare(0, starname.length(), starname) == 0) { + std::string location_s; + getline(ss, location_s); + long location = std::stol(location_s.c_str()); + + data.seekg(location); + data.read((char*)&p, sizeof(struct exoplanet)); + + found = true; + } + } + data.close(); + lut.close(); + + + if (found && !isnan(p.POSITIONX)) { + + if (isnan(p.RSTAR)) + { + p.RSTAR = 1.46046; + } + if (isnan(p.R)) + { + p.R = 0.320116; + } + if (isnan(p.ECC)) + { + p.ECC = 0.0585235; + } + if (isnan(p.A)) + { + p.A = 0.435568; + } + if (isnan(p.I)) + { + p.I = 86.6873; + } + if (isnan(p.BIGOM)) + { + p.BIGOM = 44.705; + } + if (isnan(p.OM)) + { + p.OM = 90; + } + if (isnan(p.PER)) + { + p.PER = 358.802; + } + + double parsecinmeter = 3.08567758*10e16; const std::string luaTableParent = "{" @@ -142,7 +177,7 @@ int addNode(lua_State* L) { "Transform = {" "Translation = {" "Type = 'StaticTranslation'," - "Position = {" + std::to_string(values[0] * parsecinmeter) + ", " + std::to_string(values[1] * parsecinmeter) + ", " + std::to_string(values[2] * parsecinmeter) + "}" + "Position = {" + std::to_string(p.POSITIONX * parsecinmeter) + ", " + std::to_string(p.POSITIONY * parsecinmeter) + ", " + std::to_string(p.POSITIONZ * parsecinmeter) + "}" "}" "}" "}"; @@ -151,7 +186,7 @@ int addNode(lua_State* L) { "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderablePlaneImageLocal'," - "Size = 0.68 * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Size = "+ std::to_string(p.RSTAR) +" * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," "BlendMode = 'Additive'" @@ -162,7 +197,7 @@ int addNode(lua_State* L) { "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = 0.1*7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "Radii = "+ std::to_string(p.R) +" *7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m "SegmentsPerPatch = 64," "Layers = {" "ColorLayers = {" @@ -177,14 +212,14 @@ int addNode(lua_State* L) { "Transform = {" "Translation = {" "Type = 'KeplerTranslation'," - "Eccentricity = 0.05," //ECC - "SemiMajorAxis = 0.177758 * 149597871," // 149 597 871km = 1 AU. A - "Inclination = 88.91," //I - "AscendingNode = 35.5," //BIGOM - "ArgumentOfPeriapsis = 356.2," //OM + "Eccentricity = "+ std::to_string(p.ECC) +"," //ECC + "SemiMajorAxis = "+ std::to_string(p.A) +" * 149597871," // 149 597 871km = 1 AU. A + "Inclination = "+ std::to_string(p.I) +"," //I + "AscendingNode = "+ std::to_string(p.BIGOM) +"," //BIGOM + "ArgumentOfPeriapsis = "+ std::to_string(p.OM) +"," //OM "MeanAnomaly = 0.0," "Epoch = '2010 07 14 19:34:21.8'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = 32.03 * 86400" //PER. 86 400sec = 1 day. + "Period = "+ std::to_string(p.PER) +" * 86400" //PER. 86 400sec = 1 day. "}" "}," "}"; @@ -194,12 +229,13 @@ int addNode(lua_State* L) { scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + } else { printf("No star with that name."); } - + return 0; } From 25e56d19a7feae8444a252a1bf0163919eb3345d Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 9 Apr 2018 16:25:23 -0400 Subject: [PATCH 007/123] adds and removes all exoplanets in a system --- modules/exoplanets/exoplanetsmodule.cpp | 214 +++++++++++++++--------- 1 file changed, 132 insertions(+), 82 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 7bd424a5a6..916fc9670e 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -29,12 +29,14 @@ //#include //#include +#include #include #include #include #include +#include struct exoplanet { float A; @@ -45,6 +47,7 @@ struct exoplanet { float BIGOMUPPER; float BIGOMLOWER; float UBIGOM; + int BINARY; float ECC; float ECCUPPER; float ECCLOWER; @@ -53,8 +56,8 @@ struct exoplanet { float IUPPER; float ILOWER; float UI; - float KOI; - int MULT; // 0 and 1 are values(boolean), -1 indicates missing value + //int MULT; // 0 and 1 are values(boolean), -1 indicates missing value + int NCOMP; float OM; float OMUPPER; float OMLOWER; @@ -112,119 +115,144 @@ int addNode(lua_State* L) { exoplanet p; std::string line; bool found = false; + + std::vector plsy; + std::vector plna; while (getline(lut, line)) { std::istringstream ss(line); getline(ss, planetname, ','); - if (planetname.compare(0, starname.length(), starname) == 0) { + if (planetname.compare(0, planetname.length()-2, starname) == 0) { std::string location_s; getline(ss, location_s); long location = std::stol(location_s.c_str()); data.seekg(location); data.read((char*)&p, sizeof(struct exoplanet)); - + plna.push_back(planetname); + plsy.push_back(p); found = true; } } data.close(); lut.close(); + int ncomp = plsy[0].NCOMP; + printf( std::to_string( plsy.size() ).c_str() ); if (found && !isnan(p.POSITIONX)) { - - if (isnan(p.RSTAR)) - { - p.RSTAR = 1.46046; - } - if (isnan(p.R)) - { - p.R = 0.320116; - } - if (isnan(p.ECC)) - { - p.ECC = 0.0585235; - } - if (isnan(p.A)) - { - p.A = 0.435568; - } - if (isnan(p.I)) - { - p.I = 86.6873; - } - if (isnan(p.BIGOM)) - { - p.BIGOM = 44.705; - } - if (isnan(p.OM)) - { - p.OM = 90; - } - if (isnan(p.PER)) - { - p.PER = 358.802; - } - - + Time epoch; double parsecinmeter = 3.08567758*10e16; const std::string luaTableParent = "{" "Name = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsecinmeter) + ", " + std::to_string(p.POSITIONY * parsecinmeter) + ", " + std::to_string(p.POSITIONZ * parsecinmeter) + "}" - "}" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(p.POSITIONX * parsecinmeter) + ", " + std::to_string(p.POSITIONY * parsecinmeter) + ", " + std::to_string(p.POSITIONZ * parsecinmeter) + "}" "}" - "}"; + "}" + "}"; + const std::string luaTableStarGlare = "{" "Name = '" + starname + "Plane'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = "+ std::to_string(p.RSTAR) +" * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," - "BlendMode = 'Additive'" + "Type = 'RenderablePlaneImageLocal'," + "Size = " + std::to_string(p.RSTAR) + " * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," + "BlendMode = 'Additive'" "}" - "}"; - const std::string luaTablePlanet = "{" - "Name = '" + starname + "Planet'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = "+ std::to_string(p.R) +" *7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m - "SegmentsPerPatch = 64," - "Layers = {" - "ColorLayers = {" - "{" - "Name = 'Exoplanet Texture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," - "Enabled = true" + "}"; + + std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ")"; + + for (size_t i = 0; i < plsy.size(); i++) + { + if (isnan(plsy[i].RSTAR)) + { + plsy[i].RSTAR = 1.46046; + } + if (isnan(plsy[i].R)) + { + plsy[i].R = 0.320116; + } + if (isnan(plsy[i].ECC)) + { + plsy[i].ECC = 0.0585235; + } + if (isnan(plsy[i].A)) + { + plsy[i].A = 0.435568; + } + if (isnan(plsy[i].I)) + { + plsy[i].I = 86.6873; + } + if (isnan(plsy[i].BIGOM)) + { + plsy[i].BIGOM = 44.705; + } + if (isnan(plsy[i].OM)) + { + plsy[i].OM = 90; + } + if (isnan(plsy[i].PER)) + { + plsy[i].PER = 358.802; + } + std::string sepoch; + if (!isnan(plsy[i].TT)) { + epoch.setTime("JD " + std::to_string(plsy[i].TT)); + sepoch = epoch.ISO8601(); + } + else + sepoch = "2009-05-19T07:11:34.080"; + + + const std::string luaTablePlanet = "{" + "Name = '" + plna[i] + "'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(plsy[i].R) + " *7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "SegmentsPerPatch = 64," + "Layers = {" + "ColorLayers = {" + "{" + "Name = 'Exoplanet Texture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" + "}" "}" "}" - "}" - "}," - "Transform = {" - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = "+ std::to_string(p.ECC) +"," //ECC - "SemiMajorAxis = "+ std::to_string(p.A) +" * 149597871," // 149 597 871km = 1 AU. A - "Inclination = "+ std::to_string(p.I) +"," //I - "AscendingNode = "+ std::to_string(p.BIGOM) +"," //BIGOM - "ArgumentOfPeriapsis = "+ std::to_string(p.OM) +"," //OM - "MeanAnomaly = 0.0," - "Epoch = '2010 07 14 19:34:21.8'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = "+ std::to_string(p.PER) +" * 86400" //PER. 86 400sec = 1 day. - "}" - "}," - "}"; + "}," + "Transform = {" + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + " * 86400" //PER. 86 400sec = 1 day. + "}" + "}," + "}"; - const std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + "); openspace.addSceneGraphNode(" + luaTablePlanet + ");"; + scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ")"; + + } + + scriptParent += ";"; + + OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -233,7 +261,7 @@ int addNode(lua_State* L) { } else { - printf("No star with that name."); + printf("No star with that name or not enought data about it."); } return 0; @@ -243,7 +271,29 @@ int removeNode(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); - const std::string scriptParent = "openspace.removeSceneGraphNode('" + starname + "Planet'); openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');"; + std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lut.txt"); + if (!lut.good()) { + std::cout << "Failed to open exoplanets look-up table file"; + } + std::string line; + std::string planetname; + std::vector plna; + while (getline(lut, line)) { + + std::istringstream ss(line); + getline(ss, planetname, ','); + + if (planetname.compare(0, planetname.length() - 2, starname) == 0) { + plna.push_back(planetname); + } + } + + std::string scriptParent; + for (size_t i = 0; i < plna.size(); i++) + { + scriptParent += "openspace.removeSceneGraphNode('" + plna[i] + "');"; + } + scriptParent += " openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');"; OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes From bb51614716e7f7e9d69e53a0b3e9c63d91d181ab Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 17 Apr 2018 18:17:16 -0400 Subject: [PATCH 008/123] csv to bin task added --- data/tasks/csvtobin.task | 11 + modules/exoplanets/CMakeLists.txt | 2 + modules/exoplanets/exoplanetsmodule.cpp | 109 +-- modules/exoplanets/exoplanetsmodule.h | 7 +- .../tasks/exoplanetscsvtobintask.cpp | 813 ++++++++++++++++++ .../exoplanets/tasks/exoplanetscsvtobintask.h | 103 +++ 6 files changed, 990 insertions(+), 55 deletions(-) create mode 100644 data/tasks/csvtobin.task create mode 100644 modules/exoplanets/tasks/exoplanetscsvtobintask.cpp create mode 100644 modules/exoplanets/tasks/exoplanetscsvtobintask.h diff --git a/data/tasks/csvtobin.task b/data/tasks/csvtobin.task new file mode 100644 index 0000000000..f051cc8bc2 --- /dev/null +++ b/data/tasks/csvtobin.task @@ -0,0 +1,11 @@ +return { + { + Type = "ExoplanetsCsvToBinTask", + + InputCSV = "${BASE}/modules/exoplanets/exoplanets.csv", + InputSPECK = "${BASE}/modules/exoplanets/expl.speck", + OutputBIN = "${BASE}/modules/exoplanets/expl_data.bin", + OutputLUT = "${BASE}/modules/exoplanets/lookup.txt" + -- OutputBIN = "${BASE}/sync/http/exoplanets_data/1/expl_data.bin" + } +} diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 5316d83dde..86d4e5588f 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -26,11 +26,13 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h + ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 916fc9670e..c3247d9ee5 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -27,18 +27,23 @@ #include #include -//#include -//#include +#include #include #include +#include + #include #include #include #include -struct exoplanet { +namespace openspace { + +using namespace exoplanets; + +struct Exoplanet { float A; double AUPPER; double ALOWER; @@ -47,7 +52,7 @@ struct exoplanet { float BIGOMUPPER; float BIGOMLOWER; float UBIGOM; - int BINARY; + bool BINARY; float ECC; float ECCUPPER; float ECCLOWER; @@ -56,16 +61,15 @@ struct exoplanet { float IUPPER; float ILOWER; float UI; - //int MULT; // 0 and 1 are values(boolean), -1 indicates missing value int NCOMP; float OM; float OMUPPER; float OMLOWER; float UOM; double PER; - float PERUPPER; //skrivs med e ibland - float PERLOWER; //skrivs med e ibland - float UPER; //skrivs med e ibland + float PERUPPER; + float PERLOWER; + float UPER; double R; double RUPPER; double RLOWER; @@ -87,22 +91,21 @@ struct exoplanet { float POSITIONZ; }; -namespace openspace { ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} int addNode(lua_State* L) { const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); // has white spaces + const std::string starname = luaL_checkstring(L, StringLocation); - std::ifstream data("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/data.bin", std::ios::in | std::ios::binary); + std::ifstream data("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/expl_data.bin", std::ios::in | std::ios::binary); if (!data.good()) { std::cout << "Failed to open exoplanets data file"; } - std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lut.txt"); + std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lookup.txt"); if (!lut.good()) { std::cout << "Failed to open exoplanets look-up table file"; } @@ -112,11 +115,11 @@ int addNode(lua_State* L) { //3. read sizeof(exoplanet) bytes into an exoplanet object. std::string planetname; size_t len = 0; - exoplanet p; + Exoplanet p; std::string line; bool found = false; - std::vector plsy; + std::vector plsy; std::vector plna; while (getline(lut, line)) { @@ -129,7 +132,7 @@ int addNode(lua_State* L) { long location = std::stol(location_s.c_str()); data.seekg(location); - data.read((char*)&p, sizeof(struct exoplanet)); + data.read((char*)&p, sizeof(struct Exoplanet)); plna.push_back(planetname); plsy.push_back(p); found = true; @@ -137,11 +140,9 @@ int addNode(lua_State* L) { } data.close(); lut.close(); - int ncomp = plsy[0].NCOMP; - printf( std::to_string( plsy.size() ).c_str() ); - if (found && !isnan(p.POSITIONX)) + if (found && !isnan(p.POSITIONX) && !p.BINARY ) { Time epoch; double parsecinmeter = 3.08567758*10e16; @@ -150,33 +151,35 @@ int addNode(lua_State* L) { "Name = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsecinmeter) + ", " + std::to_string(p.POSITIONY * parsecinmeter) + ", " + std::to_string(p.POSITIONZ * parsecinmeter) + "}" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(p.POSITIONX * parsecinmeter) + ", " + std::to_string(p.POSITIONY * parsecinmeter) + ", " + std::to_string(p.POSITIONZ * parsecinmeter) + "}" + "}" "}" - "}" - "}"; + "}"; + if (isnan(p.RSTAR)) + { + p.RSTAR = 1.46046; + } + // radius of star and size of billboard should not be same? the light in the texture reaches furter than the actual size of the globe... const std::string luaTableStarGlare = "{" "Name = '" + starname + "Plane'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/glare.png'," - "BlendMode = 'Additive'" + "Type = 'RenderablePlaneImageLocal'," + "Size = " + std::to_string(p.RSTAR) + " * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," + "BlendMode = 'Additive'" "}" - "}"; + "}"; std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ")"; for (size_t i = 0; i < plsy.size(); i++) { - if (isnan(plsy[i].RSTAR)) - { - plsy[i].RSTAR = 1.46046; - } + if (isnan(plsy[i].R)) { plsy[i].R = 0.320116; @@ -212,7 +215,7 @@ int addNode(lua_State* L) { } else sepoch = "2009-05-19T07:11:34.080"; - + const std::string luaTablePlanet = "{" "Name = '" + plna[i] + "'," @@ -240,7 +243,7 @@ int addNode(lua_State* L) { "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(plsy[i].PER) + " * 86400" //PER. 86 400sec = 1 day. "}" "}," @@ -249,10 +252,10 @@ int addNode(lua_State* L) { scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ")"; } - + scriptParent += ";"; - - + + OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -261,9 +264,9 @@ int addNode(lua_State* L) { } else { - printf("No star with that name or not enought data about it."); + printf("No star with that name or not enough data about it."); } - + return 0; } @@ -271,7 +274,7 @@ int removeNode(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); - std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lut.txt"); + std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lookup.txt"); if (!lut.good()) { std::cout << "Failed to open exoplanets look-up table file"; } @@ -319,7 +322,7 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { &removeNode, {}, "string", - "Removes the node with the name given in teh arguments." + "Removes the node with the name given in the arguments." } }; @@ -327,18 +330,18 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { return res; } -//void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { - //auto fRenderable = FactoryManager::ref().factory(); - //ghoul_assert(fRenderable, "No renderable factory existed"); +void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { + + auto fTask = FactoryManager::ref().factory(); + ghoul_assert(fTask, "No task factory existed"); + fTask->registerClass("ExoplanetsCsvToBinTask"); +} - //fRenderable->registerClass("RenderableDebugPlane"); -//} - -//std::vector ExoplanetsModule::documentations() const { - //return { - //RenderableDebugPlane::Documentation() - //}; -//} +std::vector ExoplanetsModule::documentations() const { + return { + ExoplanetsCsvToBinTask::documentation() + }; +} } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index d37f6a721f..e5e3679666 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ #include +#include #include namespace openspace { @@ -35,13 +36,15 @@ public: constexpr static const char* Name = "Exoplanets"; ExoplanetsModule(); + virtual ~ExoplanetsModule() = default; scripting::LuaLibrary luaLibrary() const override; - //std::vector documentations() const override; + std::vector documentations() const override; protected: - //void internalInitialize(const ghoul::Dictionary&) override; + void internalInitialize(const ghoul::Dictionary&) override; + }; } // namespace openspace diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp new file mode 100644 index 0000000000..900b63853f --- /dev/null +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -0,0 +1,813 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include + +#include +#include +#include +#include + +#include + +namespace { + const char* KeyInputCSV = "InputCSV"; + const char* KeyInputSPECK = "InputSPECK"; + const char* KeyOutputBIN = "OutputBIN"; + const char* KeyOutputLUT = "OutputLUT"; + + constexpr const char* _loggerCat = "CsvToBinTask"; +} // namespace + +namespace openspace { +namespace exoplanets { + +ExoplanetsCsvToBinTask::ExoplanetsCsvToBinTask(const ghoul::Dictionary& dictionary){ + openspace::documentation::testSpecificationAndThrow( + documentation(), + dictionary, + "ExoplanetsCsvToBinTask" + ); + + _inputCSVPath = absPath(dictionary.value(KeyInputCSV)); + _inputSPECKPath = absPath(dictionary.value(KeyInputSPECK)); + _outputBINPath = absPath(dictionary.value(KeyOutputBIN)); + _outputLUTPath = absPath(dictionary.value(KeyOutputLUT)); +} + +std::string ExoplanetsCsvToBinTask::description() { + return "Extract metadata from csv-file " + _inputCSVPath + + " and write as bin to " + _outputBINPath; +} + +std::string ExoplanetsCsvToBinTask::getExplName(std::string csvName){ + std::string explName = csvName; + if (csvName == "HD 1237") + explName = "GJ 3021"; + else if (csvName == "MOA-2009-BLG-387L") + explName = "MOA 2009-BLG-387L"; + else if (csvName == "HD 126614 A") + explName = "HD 126614"; + else if (csvName == "epsilon Ret") + explName = "HD 27442"; + else if (csvName == "PH-1") + explName = "PH1"; + else if (csvName == "gamma Leo A") + explName = "gam 1 Leo"; + else if (csvName == "OGLE-2007-BLG-368L") + explName = "OGLE 2007-BLG-368L"; + else if (csvName == "alpha Ari") + explName = "alf Ari"; + else if (csvName == "mu Ara") + explName = "HD 160691"; + else if (csvName == "OGLE-05-169L") + explName = "OGLE 2005-BLG-169L"; + else if (csvName == "tau Gru") + explName = "HD 216435"; + else if (csvName == "iota Hor") + explName = "HR 810"; + else if (csvName == "OGLE-05-071L") + explName = "OGLE 2005-BLG-71L"; + else if (csvName == "OGLE235-MOA53") + explName = "OGLE 2003-BLG-235L"; + else if (csvName == "MOA-2008-BLG-310L") + explName = "MOA 2008-BLG-310L"; + else if (csvName == "KIC 11442793") + explName = "KOI-351"; + else if (csvName == "OGLE-2006-BLG-109L") + explName = "OGLE 2006-BLG-109L"; + else if (csvName == "HD 137388") + explName = "HD 137388 A"; + else if (csvName == "kappa CrB") + explName = "kap CrB"; + else if (csvName == "XO-2") + explName = "XO-2 N"; + else if (csvName == "epsilon Tau") + explName = "eps Tau"; + else if (csvName == "epsilon Eri") + explName = "eps Eri"; + else if (csvName == "Kepler-448") + explName = "KOI-12"; + else if (csvName == "omega Ser") + explName = "ome Ser"; + else if (csvName == "MOA-2010-BLG-477L") + explName = "MOA 2010-BLG-477L"; + else if (csvName == "GJ 176") + explName = "HD 285968"; + else if (csvName == "HIP 2247") + explName = "BD-17 63"; + else if (csvName == "MOA-2009-BLG-266L") + explName = "MOA 2009-BLG-266L"; + else if (csvName == "Kepler-89") + explName = "KOI-94"; + else if (csvName == "iota Dra") + explName = "HIP 75458"; + else if (csvName == "MOA-2007-BLG-400L") + explName = "MOA 2007-BLG-400L"; + else if (csvName == "upsilon And") + explName = "ups And"; + else if (csvName == "OGLE-2011-BLG-0251") + explName = "OGLE 2011-BLG-251L"; + else if (csvName == "OGLE-05-390L") + explName = "OGLE 2005-BLG-390L"; + else if (csvName == "Kepler-420") + explName = "KOI-1257"; + else if (csvName == "beta Pic") + explName = "bet Pic"; + else if (csvName == "gamma Cep") + explName = "gam Cep"; + else if (csvName == "MOA-2007-BLG-192L") + explName = "MOA 2007-BLG-192L"; + else if (csvName == "MOA-2009-BLG-319L") + explName = "MOA 2009-BLG-319L"; + else if (csvName == "omicron CrB") + explName = "omi CrB"; + else if (csvName == "beta Gem") + explName = "HD 62509"; + else if (csvName == "epsilon CrB") + explName = "eps CrB"; + else if (csvName == "omicron UMa") + explName = "omi UMa"; + else if (csvName == "HD 142022") + explName = "HD 142022 A"; + + return explName; +} + +std::vector ExoplanetsCsvToBinTask::getStarPosition(std::string starName) +{ + std::vector pos = std::vector(3); + pos[0] = NAN; + pos[1] = NAN; + pos[2] = NAN; + std::ifstream expl_file(_inputSPECKPath); + if (!expl_file) { + LERROR(fmt::format("Error opening file expl.speck.")); + } + + + std::string line; + std::string d; + std::string n; + while (getline(expl_file, line)) + { + if (line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" || line.empty()) { + continue; + } + + std::istringstream linestream(line); + + getline(linestream, d, '#'); + getline(linestream, n); + n.erase(0, 1); + + std::string coord; + if (n.compare(starName) == 0) + { + std::stringstream datastream(d); + getline(datastream, coord, ' '); + pos[0] = std::stof(coord.c_str(), nullptr); + getline(datastream, coord, ' '); + pos[1] = std::stof(coord.c_str(), nullptr); + getline(datastream, coord, ' '); + pos[2] = std::stof(coord.c_str(), nullptr); + break; + } + } + + expl_file.close(); + return pos; +} + +void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallback) { + + std::ifstream csv_file(_inputCSVPath); + if (!csv_file.good()) { + LERROR(fmt::format("Failed to open Speck file '{}'", _inputCSVPath)); + return; + } + + std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); + std::ofstream lut_file(_outputLUTPath); + + int version = 1; + bin_file.write((char *)&version, sizeof(int)); + + Exoplanet p; + + std::string planetname; + std::string planet_row; + getline(csv_file, planet_row); // The first line, containing the data names + + std::string data_s; + bool iskeplerobject = false; + + while (getline(csv_file, planet_row)) { + + std::istringstream lineStream(planet_row); + + getline(lineStream, data_s, ','); // A + if (!data_s.empty()) + p.A = std::stof(data_s.c_str(), nullptr); + else + p.A = NAN; + getline(lineStream, data_s, ','); // AUPPER + if (!data_s.empty()) + p.AUPPER = std::stod(data_s.c_str(), nullptr); + else + p.AUPPER = NAN; + getline(lineStream, data_s, ','); // ALOWER + if (!data_s.empty()) + p.ALOWER = std::stod(data_s.c_str(), nullptr); + else + p.ALOWER = NAN; + getline(lineStream, data_s, ','); // UA + if (!data_s.empty()) + p.UA = std::stod(data_s.c_str(), nullptr); + else + p.UA = NAN; + getline(lineStream, data_s, ','); // AREF + getline(lineStream, data_s, ','); // AURL + getline(lineStream, data_s, ','); // AR + getline(lineStream, data_s, ','); // ARUPPER + getline(lineStream, data_s, ','); // ARLOWER + getline(lineStream, data_s, ','); // UAR + getline(lineStream, data_s, ','); // ARREF + getline(lineStream, data_s, ','); // ARURL + getline(lineStream, data_s, ','); // ASTROMETRY + getline(lineStream, data_s, ','); // B + getline(lineStream, data_s, ','); // BUPPER + getline(lineStream, data_s, ','); // BLOWER + getline(lineStream, data_s, ','); // UB + getline(lineStream, data_s, ','); // BREF + getline(lineStream, data_s, ','); // BURL + getline(lineStream, data_s, ','); // BIGOM + if (!data_s.empty()) + p.BIGOM = std::stof(data_s.c_str(), nullptr); + else + p.BIGOM = NAN; + getline(lineStream, data_s, ','); // BIGOMUPPER + if (!data_s.empty()) + p.BIGOMUPPER = std::stof(data_s.c_str(), nullptr); + else + p.BIGOMUPPER = NAN; + getline(lineStream, data_s, ','); // BIGOMLOWER + if (!data_s.empty()) + p.BIGOMLOWER = std::stof(data_s.c_str(), nullptr); + else + p.BIGOMLOWER = NAN; + getline(lineStream, data_s, ','); // UBIGOM + if (!data_s.empty()) + p.UBIGOM = std::stof(data_s.c_str(), nullptr); + else + p.UBIGOM = NAN; + getline(lineStream, data_s, ','); // BIGOMREF + getline(lineStream, data_s, ','); // BIGOMURL + getline(lineStream, data_s, ','); // BINARY + if (!data_s.empty()) + p.BINARY = std::stoi(data_s.c_str(), nullptr); + else + p.BINARY = -1; + getline(lineStream, data_s, ','); // BINARYREF + getline(lineStream, data_s, ','); // BINARYURL + getline(lineStream, data_s, ','); // BMV + getline(lineStream, data_s, ','); // CHI2 + getline(lineStream, data_s, ','); // COMP + getline(lineStream, data_s, ','); // DATE + getline(lineStream, data_s, ','); // DEC + getline(lineStream, data_s, ','); // DEC_STRING + getline(lineStream, data_s, ','); // DENSITY + getline(lineStream, data_s, ','); // DENSITYUPPER + getline(lineStream, data_s, ','); // DENSITYLOWER + getline(lineStream, data_s, ','); // UDENSITY + getline(lineStream, data_s, ','); // DENSITYREF + getline(lineStream, data_s, ','); // DENSITYURL + getline(lineStream, data_s, ','); // DEPTH + getline(lineStream, data_s, ','); // DEPTHUPPER + getline(lineStream, data_s, ','); // DEPTHLOWER + getline(lineStream, data_s, ','); // UDEPTH + getline(lineStream, data_s, ','); // DEPTHREF + getline(lineStream, data_s, ','); // DEPTHURL + getline(lineStream, data_s, ','); // DIST + getline(lineStream, data_s, ','); // DISTUPPER + getline(lineStream, data_s, ','); // DISTLOWER + getline(lineStream, data_s, ','); // UDIST + getline(lineStream, data_s, ','); // DISTREF + getline(lineStream, data_s, ','); // DISTURL + getline(lineStream, data_s, ','); // DR + getline(lineStream, data_s, ','); // DRUPPER + getline(lineStream, data_s, ','); // DRLOWER + getline(lineStream, data_s, ','); // UDR + getline(lineStream, data_s, ','); // DRREF + getline(lineStream, data_s, ','); // DRURL + getline(lineStream, data_s, ','); // DVDT + getline(lineStream, data_s, ','); // DVDTUPPER + getline(lineStream, data_s, ','); // DVDTLOWER + getline(lineStream, data_s, ','); // UDVDT + getline(lineStream, data_s, ','); // DVDTREF + getline(lineStream, data_s, ','); // DVDTURL + getline(lineStream, data_s, ','); // EANAME + getline(lineStream, data_s, ','); // EAURL + getline(lineStream, data_s, ','); // ECC + if (!data_s.empty()) + p.ECC = std::stof(data_s.c_str(), nullptr); + else + p.ECC = NAN; + + getline(lineStream, data_s, ','); // ECCUPPER + if (!data_s.empty()) + p.ECCUPPER = std::stof(data_s.c_str(), nullptr); + else + p.ECCUPPER = NAN; + + getline(lineStream, data_s, ','); // ECCLOWER + if (!data_s.empty()) + p.ECCLOWER = std::stof(data_s.c_str(), nullptr); + else + p.ECCLOWER = NAN; + + getline(lineStream, data_s, ','); // UECC + if (!data_s.empty()) + p.UECC = std::stof(data_s.c_str(), nullptr); + else + p.UECC = NAN; + + getline(lineStream, data_s, ','); // ECCREF + getline(lineStream, data_s, ','); // ECCURL + getline(lineStream, data_s, ','); // EOD + getline(lineStream, data_s, ','); // ETDNAME + getline(lineStream, data_s, ','); // ETDURL + getline(lineStream, data_s, ','); // FE + getline(lineStream, data_s, ','); // FEUPPER + getline(lineStream, data_s, ','); // FELOWER + getline(lineStream, data_s, ','); // UFE + getline(lineStream, data_s, ','); // FEREF + getline(lineStream, data_s, ','); // FEURL + getline(lineStream, data_s, ','); // FIRSTREF + getline(lineStream, data_s, ','); // FIRSTURL + getline(lineStream, data_s, ','); // FREEZE_ECC + getline(lineStream, data_s, ','); // GAMMA + getline(lineStream, data_s, ','); // GAMMAUPPER + getline(lineStream, data_s, ','); // GAMMALOWER + getline(lineStream, data_s, ','); // UGAMMA + getline(lineStream, data_s, ','); // GAMMAREF + getline(lineStream, data_s, ','); // GAMMAURL + getline(lineStream, data_s, ','); // GL + getline(lineStream, data_s, ','); // GRAVITY + getline(lineStream, data_s, ','); // GRAVITYUPPER + getline(lineStream, data_s, ','); // GRAVITYLOWER + getline(lineStream, data_s, ','); // UGRAVITY + getline(lineStream, data_s, ','); // GRAVITYREF + getline(lineStream, data_s, ','); // GRAVITYURL + getline(lineStream, data_s, ','); // H + getline(lineStream, data_s, ','); // HD + getline(lineStream, data_s, ','); // HIPP + getline(lineStream, data_s, ','); // HR + getline(lineStream, data_s, ','); // I + if (!data_s.empty()) + p.I = std::stof(data_s.c_str(), nullptr); + else + p.I = NAN; + + getline(lineStream, data_s, ','); // IUPPER + if (!data_s.empty()) + p.IUPPER = std::stof(data_s.c_str(), nullptr); + else + p.IUPPER = NAN; + + getline(lineStream, data_s, ','); // ILOWER + if (!data_s.empty()) + p.ILOWER = std::stof(data_s.c_str(), nullptr); + else + p.ILOWER = NAN; + + getline(lineStream, data_s, ','); // UI + if (!data_s.empty()) + p.UI = std::stof(data_s.c_str(), nullptr); + else + p.UI = NAN; + + getline(lineStream, data_s, ','); // IREF + getline(lineStream, data_s, ','); // IURL + getline(lineStream, data_s, ','); // IMAGING + getline(lineStream, data_s, ','); // J + getline(lineStream, data_s, ','); // JSNAME + getline(lineStream, data_s, ','); // EPEURL + getline(lineStream, data_s, ','); // K + getline(lineStream, data_s, ','); // KUPPER + getline(lineStream, data_s, ','); // KLOWER + getline(lineStream, data_s, ','); // UK + getline(lineStream, data_s, ','); // KREF + getline(lineStream, data_s, ','); // KURL + getline(lineStream, data_s, ','); // KOI + getline(lineStream, data_s, ','); // KS + getline(lineStream, data_s, ','); // KP + getline(lineStream, data_s, ','); // LAMBDA + getline(lineStream, data_s, ','); // LAMBDAUPPER + getline(lineStream, data_s, ','); // LAMBDALOWER + getline(lineStream, data_s, ','); // ULAMBDA + getline(lineStream, data_s, ','); // LAMBDAREF + getline(lineStream, data_s, ','); // LAMBDAURL + getline(lineStream, data_s, ','); // LOGG + getline(lineStream, data_s, ','); // LOGGUPPER + getline(lineStream, data_s, ','); // LOGGLOWER + getline(lineStream, data_s, ','); // ULOGG + getline(lineStream, data_s, ','); // LOGGREF + getline(lineStream, data_s, ','); // LOGGURL; + getline(lineStream, data_s, ','); // MASS + getline(lineStream, data_s, ','); // MASSUPPER + getline(lineStream, data_s, ','); // MASSLOWER + getline(lineStream, data_s, ','); // UMASS + getline(lineStream, data_s, ','); // MASSREF + getline(lineStream, data_s, ','); // MASSURL + getline(lineStream, data_s, ','); // MICROLENSING + getline(lineStream, data_s, ','); // MSINI + getline(lineStream, data_s, ','); // MSINIUPPER + getline(lineStream, data_s, ','); // MSINILOWER + getline(lineStream, data_s, ','); // UMSINI + getline(lineStream, data_s, ','); // MSINIREF + getline(lineStream, data_s, ','); // MSINIURL + getline(lineStream, data_s, ','); // MSTAR + getline(lineStream, data_s, ','); // MSTARUPPER + getline(lineStream, data_s, ','); // MSTARLOWER + getline(lineStream, data_s, ','); // UMSTAR + getline(lineStream, data_s, ','); // MSTARREF + getline(lineStream, data_s, ','); // MSTARURL + getline(lineStream, data_s, ','); // MULT + getline(lineStream, data_s, ','); // NAME + planetname = data_s; + + getline(lineStream, data_s, ','); // NCOMP + if (!data_s.empty()) + p.NCOMP = std::stoi(data_s.c_str(), nullptr); + else + p.NCOMP = -1; + getline(lineStream, data_s, ','); // NOBS + getline(lineStream, data_s, ','); // OM + if (!data_s.empty()) + p.OM = std::stof(data_s.c_str(), nullptr); + else + p.OM = NAN; + + getline(lineStream, data_s, ','); // OMUPPER + if (!data_s.empty()) + p.OMUPPER = std::stof(data_s.c_str(), nullptr); + else + p.OMUPPER = NAN; + + getline(lineStream, data_s, ','); // OMLOWER + if (!data_s.empty()) + p.OMLOWER = std::stof(data_s.c_str(), nullptr); + else + p.OMLOWER = NAN; + + getline(lineStream, data_s, ','); // UOM + if (!data_s.empty()) + p.UOM = std::stof(data_s.c_str(), nullptr); + else + p.UOM = NAN; + + getline(lineStream, data_s, ','); // OMREF + getline(lineStream, data_s, ','); // OMURL + getline(lineStream, data_s, ','); // ORBREF + getline(lineStream, data_s, ','); // ORBURL + getline(lineStream, data_s, ','); // OTHERNAME + getline(lineStream, data_s, ','); // PAR + getline(lineStream, data_s, ','); // PARUPPER + getline(lineStream, data_s, ','); // PARLOWER + getline(lineStream, data_s, ','); // UPAR + getline(lineStream, data_s, ','); // PER + if (!data_s.empty()) + p.PER = std::stod(data_s.c_str(), nullptr); + else + p.PER = NAN; + + getline(lineStream, data_s, ','); // PERUPPER + if (!data_s.empty()) + p.PERUPPER = std::stof(data_s.c_str(), nullptr); + else + p.PERUPPER = NAN; + + getline(lineStream, data_s, ','); // PERLOWER + if (!data_s.empty()) + p.PERLOWER = std::stof(data_s.c_str(), nullptr); + else + p.PERLOWER = NAN; + + getline(lineStream, data_s, ','); // UPER + if (!data_s.empty()) + p.UPER = std::stof(data_s.c_str(), nullptr); + else + p.UPER = NAN; + + getline(lineStream, data_s, ','); // PERREF + getline(lineStream, data_s, ','); // PERURL + getline(lineStream, data_s, ','); // PLANETDISCMETH + getline(lineStream, data_s, ','); // R + if (!data_s.empty()) + p.R = std::stod(data_s.c_str(), nullptr); + else + p.R = NAN; + + getline(lineStream, data_s, ','); // RUPPER + if (!data_s.empty()) + p.RUPPER = std::stod(data_s.c_str(), nullptr); + else + p.RUPPER = NAN; + + getline(lineStream, data_s, ','); // RLOWER + if (!data_s.empty()) + p.RLOWER = std::stod(data_s.c_str(), nullptr); + else + p.RLOWER = NAN; + + getline(lineStream, data_s, ','); //UR + if (!data_s.empty()) + p.UR = std::stod(data_s.c_str(), nullptr); + else + p.UR = NAN; + + getline(lineStream, data_s, ','); // RREF + getline(lineStream, data_s, ','); // RURL + getline(lineStream, data_s, ','); // RA + getline(lineStream, data_s, ','); // RA_STRING + getline(lineStream, data_s, ','); // RHK + getline(lineStream, data_s, ','); // RHOSTAR + getline(lineStream, data_s, ','); // RHOSTARUPPER + getline(lineStream, data_s, ','); // RHOSTARLOWER + getline(lineStream, data_s, ','); // URHOSTAR + getline(lineStream, data_s, ','); // RHOSTARREF + getline(lineStream, data_s, ','); // RHOSTARURL + getline(lineStream, data_s, ','); // RMS + getline(lineStream, data_s, ','); // RR + getline(lineStream, data_s, ','); // RRUPPER + getline(lineStream, data_s, ','); // RRLOWER + getline(lineStream, data_s, ','); // URR + getline(lineStream, data_s, ','); // RRREF + getline(lineStream, data_s, ','); // RRURL + getline(lineStream, data_s, ','); // RSTAR + if (!data_s.empty()) + p.RSTAR = std::stof(data_s.c_str(), nullptr); + else + p.RSTAR = NAN; + + getline(lineStream, data_s, ','); // RSTARUPPER + if (!data_s.empty()) + p.RSTARUPPER = std::stof(data_s.c_str(), nullptr); + else + p.RSTARUPPER = NAN; + + getline(lineStream, data_s, ','); // RSTARLOWER + if (!data_s.empty()) + p.RSTARLOWER = std::stof(data_s.c_str(), nullptr); + else + p.RSTARLOWER = NAN; + + getline(lineStream, data_s, ','); // URSTAR + if (!data_s.empty()) + p.URSTAR = std::stof(data_s.c_str(), nullptr); + else + p.URSTAR = NAN; + + getline(lineStream, data_s, ','); // RSTARREF + getline(lineStream, data_s, ','); // RSTARURL + getline(lineStream, data_s, ','); // SAO + getline(lineStream, data_s, ','); // SE + getline(lineStream, data_s, ','); // SEREF + getline(lineStream, data_s, ','); // SEURL + getline(lineStream, data_s, ','); // SEDEPTHJ + getline(lineStream, data_s, ','); // SEDEPTHJUPPER + getline(lineStream, data_s, ','); // SEDEPTHJLOWER + getline(lineStream, data_s, ','); // USEDEPTHJ + getline(lineStream, data_s, ','); // SEDEPTHJREF + getline(lineStream, data_s, ','); // SEDEPTHJURL + getline(lineStream, data_s, ','); // SEDEPTHH + getline(lineStream, data_s, ','); // SEDEPTHHUPPER + getline(lineStream, data_s, ','); // SEDEPTHHLOWER + getline(lineStream, data_s, ','); // USEDEPTHH + getline(lineStream, data_s, ','); // SEDEPTHHREF + getline(lineStream, data_s, ','); // SEDEPTHHURL + getline(lineStream, data_s, ','); // SEDEPTHKS + getline(lineStream, data_s, ','); // SEDEPTHKSUPPER + getline(lineStream, data_s, ','); // SEDEPTHKSLOWER + getline(lineStream, data_s, ','); // USEDEPTHKS + getline(lineStream, data_s, ','); // SEDEPTHKSREF + getline(lineStream, data_s, ','); // SEDEPTHKSURL + getline(lineStream, data_s, ','); // SEDEPTHKP + getline(lineStream, data_s, ','); // SEDEPTHKPUPPER + getline(lineStream, data_s, ','); // SEDEPTHKPLOWER + getline(lineStream, data_s, ','); // USEDEPTHKP + getline(lineStream, data_s, ','); // SEDEPTHKPREF + getline(lineStream, data_s, ','); // SEDEPTHKPURL + getline(lineStream, data_s, ','); // SEDEPTH36 + getline(lineStream, data_s, ','); // SEDEPTH36UPPER + getline(lineStream, data_s, ','); // SEDEPTH36LOWER + getline(lineStream, data_s, ','); // USEDEPTH36 + getline(lineStream, data_s, ','); // SEDEPTH36REFx + getline(lineStream, data_s, ','); // SEDEPTH36URLx + getline(lineStream, data_s, ','); // SEDEPTH45 + getline(lineStream, data_s, ','); // SEDEPTH45UPPER + getline(lineStream, data_s, ','); // SEDEPTH45LOWER + getline(lineStream, data_s, ','); // USEDEPTH45 + getline(lineStream, data_s, ','); // SEDEPTH45REF + getline(lineStream, data_s, ','); // SEDEPTH45URL + getline(lineStream, data_s, ','); // SEDEPTH58 + getline(lineStream, data_s, ','); // SEDEPTH58UPPER + getline(lineStream, data_s, ','); // SEDEPTH58LOWER + getline(lineStream, data_s, ','); // USEDEPTH58 + getline(lineStream, data_s, ','); // EDEPTH58REF + getline(lineStream, data_s, ','); // SEDEPTH58URL + getline(lineStream, data_s, ','); // SEDEPTH80 + getline(lineStream, data_s, ','); // SEDEPTH80UPPER + getline(lineStream, data_s, ','); // SEDEPTH80LOWER + getline(lineStream, data_s, ','); // USEDEPTH80 + getline(lineStream, data_s, ','); // SEDEPTH80REF + getline(lineStream, data_s, ','); // SEDEPTH80URL + getline(lineStream, data_s, ','); // SEP + getline(lineStream, data_s, ','); // SEPUPPER + getline(lineStream, data_s, ','); // SEPLOWER + getline(lineStream, data_s, ','); // USEP + getline(lineStream, data_s, ','); // SEPREF + getline(lineStream, data_s, ','); // SEPURL + getline(lineStream, data_s, ','); // SET + getline(lineStream, data_s, ','); // SETUPPER + getline(lineStream, data_s, ','); // SETLOWER + getline(lineStream, data_s, ','); // USET + getline(lineStream, data_s, ','); // SETREF + getline(lineStream, data_s, ','); // SETURL + getline(lineStream, data_s, ','); // SHK + getline(lineStream, data_s, ','); // SIMBADNAME + getline(lineStream, data_s, ','); // SIMBADURL + getline(lineStream, data_s, ','); // SPECREF + getline(lineStream, data_s, ','); // SPECURL + getline(lineStream, data_s, ','); // STAR + std::string starname = getExplName(data_s); + std::vector pos = getStarPosition(starname); + p.POSITIONX = pos[0]; + p.POSITIONY = pos[1]; + p.POSITIONZ = pos[2]; + + getline(lineStream, data_s, ','); // STARDISCMETH + getline(lineStream, data_s, ','); // T0 + getline(lineStream, data_s, ','); // T0UPPER + getline(lineStream, data_s, ','); // T0LOWER + getline(lineStream, data_s, ','); // UT0 + getline(lineStream, data_s, ','); // T0REF + getline(lineStream, data_s, ','); // T0URL + getline(lineStream, data_s, ','); // T14 + getline(lineStream, data_s, ','); // T14UPPER + getline(lineStream, data_s, ','); // T14LOWER + getline(lineStream, data_s, ','); // UT14 + getline(lineStream, data_s, ','); // T14REF + getline(lineStream, data_s, ','); // T14URL + getline(lineStream, data_s, ','); // TEFF + if (!data_s.empty()) + p.TEFF = std::stof(data_s.c_str(), nullptr); + else + p.TEFF = NAN; + + getline(lineStream, data_s, ','); // TEFFUPPER + if (!data_s.empty()) + p.TEFFUPPER = std::stof(data_s.c_str(), nullptr); + else + p.TEFFUPPER = NAN; + + getline(lineStream, data_s, ','); // TEFFLOWER + if (!data_s.empty()) + p.TEFFLOWER = std::stof(data_s.c_str(), nullptr); + else + p.TEFFLOWER = NAN; + + getline(lineStream, data_s, ','); // UTEFF + if (!data_s.empty()) + p.UTEFF = std::stof(data_s.c_str(), nullptr); + else + p.UTEFF = NAN; + + getline(lineStream, data_s, ','); // TEFFREF + getline(lineStream, data_s, ','); // TEFFURL + getline(lineStream, data_s, ','); // TIMING + getline(lineStream, data_s, ','); // TRANSIT + getline(lineStream, data_s, ','); // TRANSITREF + getline(lineStream, data_s, ','); // TRANSITURL + getline(lineStream, data_s, ','); // TREND + getline(lineStream, data_s, ','); // TT + if (!data_s.empty()) + p.TT = std::stod(data_s.c_str(), nullptr); + else + p.TT = NAN; + + getline(lineStream, data_s, ','); // TTUPPER + if (!data_s.empty()) + p.TTUPPER = std::stof(data_s.c_str(), nullptr); + else + p.TTUPPER = NAN; + + getline(lineStream, data_s, ','); // TTLOWER + if (!data_s.empty()) + p.TTLOWER = std::stof(data_s.c_str(), nullptr); + else + p.TTLOWER = NAN; + + getline(lineStream, data_s, ','); // UTT + if (!data_s.empty()) + p.UTT = std::stof(data_s.c_str(), nullptr); + else + p.UTT = NAN; + + getline(lineStream, data_s, ','); // TTREF + getline(lineStream, data_s, ','); // TTURL + getline(lineStream, data_s, ','); // V + getline(lineStream, data_s, ','); // VREF + getline(lineStream, data_s, ','); // VURL + getline(lineStream, data_s, ','); // VSINI + getline(lineStream, data_s, ','); // VSINIUPPER + getline(lineStream, data_s, ','); // VSINILOWER + getline(lineStream, data_s, ','); // UVSINI + getline(lineStream, data_s, ','); // VSINIREF + getline(lineStream, data_s, ','); // VSINIURL + getline(lineStream, data_s, ','); // KEPID + if (!data_s.empty()) + iskeplerobject = true; + getline(lineStream, data_s); // KDE + + if (!iskeplerobject) { + long pos = bin_file.tellp(); + lut_file << planetname << "," << pos << std::endl; + bin_file.write((char *)&p, sizeof(struct Exoplanet)); + } + } + + csv_file.close(); + bin_file.close(); + lut_file.close(); + + progressCallback(1.0f); +} + +documentation::Documentation ExoplanetsCsvToBinTask::documentation() { + using namespace documentation; + return { + "ExoplanetsCsvToBinTask", + "exoplanets_csv_to_bin_task", + { + { + "Type", + new StringEqualVerifier("ExoplanetsCsvToBinTask"), + Optional::No, + "The type of this task" + }, + { + KeyInputCSV, + new StringAnnotationVerifier("A file path to a csv file"), + Optional::No, + "The csv file to extract data from" + }, + { + KeyInputSPECK, + new StringAnnotationVerifier("A file path to a speck file"), + Optional::No, + "The speck file to with star location" + }, + { + KeyOutputBIN, + new StringAnnotationVerifier("A valid filepath"), + Optional::No, + "The bin file to export data into" + }, + { + KeyOutputLUT, + new StringAnnotationVerifier("A valid filepath"), + Optional::No, + "The txt file to write look-up table into" + } + } + }; +} + +} // namespace exoplanets +} // namespace openspace diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h new file mode 100644 index 0000000000..7d7fdc4692 --- /dev/null +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -0,0 +1,103 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ +#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ + +#include + +#include + +namespace openspace { +namespace exoplanets { + +class ExoplanetsCsvToBinTask : public Task { +public: + ExoplanetsCsvToBinTask(const ghoul::Dictionary& dictionary); + std::string description() override; + void perform(const Task::ProgressCallback& progressCallback) override; + static documentation::Documentation documentation(); + +private: + std::string _inputCSVPath; + std::string _inputSPECKPath; + std::string _outputBINPath; + std::string _outputLUTPath; + + std::string getExplName(std::string csvName); + std::vector getStarPosition(std::string starName); + + struct Exoplanet { + float A; + double AUPPER; + double ALOWER; + double UA; + float BIGOM; + float BIGOMUPPER; + float BIGOMLOWER; + float UBIGOM; + int BINARY; // **one or more stars** + float ECC; + float ECCUPPER; + float ECCLOWER; + float UECC; + float I; + float IUPPER; + float ILOWER; + float UI; + int NCOMP; // **number of planets** + float OM; + float OMUPPER; + float OMLOWER; + float UOM; + double PER; + float PERUPPER; + float PERLOWER; + float UPER; + double R; + double RUPPER; + double RLOWER; + double UR; + float RSTAR; + float RSTARUPPER; + float RSTARLOWER; + float URSTAR; + float TEFF; + float TEFFUPPER; + float TEFFLOWER; + float UTEFF; + double TT; + float TTUPPER; + float TTLOWER; + float UTT; + float POSITIONX; + float POSITIONY; + float POSITIONZ; + }; +}; + +} // namespace exoplanets +} // namespace openspace + +#endif // __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ From 62acf30c1c637614b950b36a792474739a74ab01 Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 19 Apr 2018 10:20:31 -0400 Subject: [PATCH 009/123] Unit transformationMatrix added. --- .../exoplanets/tasks/exoplanetscsvtobintask.cpp | 15 +++++++++++---- modules/exoplanets/tasks/exoplanetscsvtobintask.h | 3 ++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 900b63853f..243a329ea5 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -158,9 +159,9 @@ std::string ExoplanetsCsvToBinTask::getExplName(std::string csvName){ return explName; } -std::vector ExoplanetsCsvToBinTask::getStarPosition(std::string starName) +glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { - std::vector pos = std::vector(3); + glm::vec3 pos; pos[0] = NAN; pos[1] = NAN; pos[2] = NAN; @@ -199,8 +200,14 @@ std::vector ExoplanetsCsvToBinTask::getStarPosition(std::string starName) } } + //Apply transformation matrix to pos + glm::dmat4 _transformationMatrix = glm::dmat4(1.0); + glm::vec3 transformedPos = glm::vec3( + _transformationMatrix * glm::dvec4(pos, 1.0) + ); + expl_file.close(); - return pos; + return transformedPos; } void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallback) { @@ -666,7 +673,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data_s, ','); // SPECURL getline(lineStream, data_s, ','); // STAR std::string starname = getExplName(data_s); - std::vector pos = getStarPosition(starname); + glm::vec3 pos = getStarPosition(starname); p.POSITIONX = pos[0]; p.POSITIONY = pos[1]; p.POSITIONZ = pos[2]; diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 7d7fdc4692..2060336c15 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ #include +#include #include @@ -46,7 +47,7 @@ private: std::string _outputLUTPath; std::string getExplName(std::string csvName); - std::vector getStarPosition(std::string starName); + glm::vec3 getStarPosition(std::string starName); struct Exoplanet { float A; From 80f8b7dca906f485958a2698019327690696813e Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 19 Apr 2018 15:24:31 -0400 Subject: [PATCH 010/123] Correction of star position --- modules/exoplanets/exoplanetsmodule.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index c3247d9ee5..c9528f3eb2 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -145,7 +145,7 @@ int addNode(lua_State* L) { if (found && !isnan(p.POSITIONX) && !p.BINARY ) { Time epoch; - double parsecinmeter = 3.08567758*10e16; + double parsec = 0.308567756E17; const std::string luaTableParent = "{" "Name = '" + starname + "'," @@ -153,7 +153,7 @@ int addNode(lua_State* L) { "Transform = {" "Translation = {" "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsecinmeter) + ", " + std::to_string(p.POSITIONY * parsecinmeter) + ", " + std::to_string(p.POSITIONZ * parsecinmeter) + "}" + "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" "}" "}" "}"; @@ -175,7 +175,7 @@ int addNode(lua_State* L) { "}" "}"; - std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ")"; + std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ");"; for (size_t i = 0; i < plsy.size(); i++) { @@ -249,12 +249,10 @@ int addNode(lua_State* L) { "}," "}"; - scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ")"; + scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ");"; } - scriptParent += ";"; - OsEng.scriptEngine().queueScript( scriptParent, From 560235d9d7ba08b3c8344ed5948ecbd8b3abced8 Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 20 Apr 2018 13:35:33 -0400 Subject: [PATCH 011/123] Orbit lines added. --- modules/exoplanets/exoplanetsmodule.cpp | 29 ++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index c9528f3eb2..62a9ce2a8e 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -224,6 +224,7 @@ int addNode(lua_State* L) { "Type = 'RenderableGlobe'," "Radii = " + std::to_string(plsy[i].R) + " *7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m "SegmentsPerPatch = 64," + "PerformShading = false," "Layers = {" "ColorLayers = {" "{" @@ -244,12 +245,34 @@ int addNode(lua_State* L) { "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + " * 86400" //PER. 86 400sec = 1 day. + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. "}" "}," "}"; - scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ");"; + const std::string PlanetTrail = "{" + "Name = '" + plna[i] + "Trail'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableTrailOrbit'," + "Period = " + std::to_string(plsy[i].PER) + "," + "Resolution = 100," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}," + "Color = { 1, 0, 0 }" + "}," + "}"; + + scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + "); openspace.addSceneGraphNode(" + PlanetTrail + ");"; } @@ -292,7 +315,7 @@ int removeNode(lua_State* L) { std::string scriptParent; for (size_t i = 0; i < plna.size(); i++) { - scriptParent += "openspace.removeSceneGraphNode('" + plna[i] + "');"; + scriptParent += "openspace.removeSceneGraphNode('" + plna[i] + "Trail'); openspace.removeSceneGraphNode('" + plna[i] + "');"; } scriptParent += " openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');"; OsEng.scriptEngine().queueScript( From 737ef795f1349569aa06b84e52141f1b74d4763a Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 23 Apr 2018 13:18:48 -0400 Subject: [PATCH 012/123] Small changes to default values of exoplanets translations. --- modules/exoplanets/exoplanetsmodule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 62a9ce2a8e..97bdcc92f8 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -194,11 +194,11 @@ int addNode(lua_State* L) { } if (isnan(plsy[i].I)) { - plsy[i].I = 86.6873; + plsy[i].I = 90.00; } if (isnan(plsy[i].BIGOM)) { - plsy[i].BIGOM = 44.705; + plsy[i].BIGOM = 45; } if (isnan(plsy[i].OM)) { From cf897648d23027a7b9c87d0d8e53d75906445073 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 30 Apr 2018 13:50:31 -0400 Subject: [PATCH 013/123] Calculates and saves a B-V value for each exoplanet(star) --- modules/exoplanets/exoplanetsmodule.cpp | 36 ++++++--- .../tasks/exoplanetscsvtobintask.cpp | 78 +++++++++++++++++-- .../exoplanets/tasks/exoplanetscsvtobintask.h | 9 ++- 3 files changed, 100 insertions(+), 23 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 97bdcc92f8..73c429cbe2 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -53,6 +53,7 @@ struct Exoplanet { float BIGOMLOWER; float UBIGOM; bool BINARY; + float BMV; float ECC; float ECCUPPER; float ECCLOWER; @@ -78,10 +79,10 @@ struct Exoplanet { float RSTARUPPER; float RSTARLOWER; float URSTAR; - float TEFF; - float TEFFUPPER; - float TEFFLOWER; - float UTEFF; + //float TEFF; + //float TEFFUPPER; + //float TEFFLOWER; + //float UTEFF; double TT; float TTUPPER; float TTLOWER; @@ -162,16 +163,29 @@ int addNode(lua_State* L) { { p.RSTAR = 1.46046; } - // radius of star and size of billboard should not be same? the light in the texture reaches furter than the actual size of the globe... + const std::string luaTableStarGlare = "{" "Name = '" + starname + "Plane'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " * 6.95700*10e8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," - "BlendMode = 'Additive'" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Name = 'Star Texture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) + "Enabled = true" + "}" + "}" + "}" + //"Type = 'RenderablePlaneImageLocal'," + //"Size = " + std::to_string(p.RSTAR) + " * 6.95700E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + //"Billboard = true," + //"Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," + //"BlendMode = 'Additive'" "}" "}"; @@ -222,7 +236,7 @@ int addNode(lua_State* L) { "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(plsy[i].R) + " *7.1492*10e7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 243a329ea5..7730fcf888 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -221,6 +221,8 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); std::ofstream lut_file(_outputLUTPath); + std::ofstream bmv_file("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/bmv.txt"); + int version = 1; bin_file.write((char *)&version, sizeof(int)); @@ -302,6 +304,10 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data_s, ','); // BINARYREF getline(lineStream, data_s, ','); // BINARYURL getline(lineStream, data_s, ','); // BMV + if (!data_s.empty()) + p.BMV = std::stof(data_s.c_str(), nullptr); + else + p.BMV = NAN; getline(lineStream, data_s, ','); // CHI2 getline(lineStream, data_s, ','); // COMP getline(lineStream, data_s, ','); // DATE @@ -692,28 +698,29 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data_s, ','); // T14REF getline(lineStream, data_s, ','); // T14URL getline(lineStream, data_s, ','); // TEFF + float teff; if (!data_s.empty()) - p.TEFF = std::stof(data_s.c_str(), nullptr); + teff = std::stof(data_s.c_str(), nullptr); else - p.TEFF = NAN; + teff = NAN; getline(lineStream, data_s, ','); // TEFFUPPER - if (!data_s.empty()) + /*if (!data_s.empty()) p.TEFFUPPER = std::stof(data_s.c_str(), nullptr); else - p.TEFFUPPER = NAN; + p.TEFFUPPER = NAN;*/ getline(lineStream, data_s, ','); // TEFFLOWER - if (!data_s.empty()) + /*if (!data_s.empty()) p.TEFFLOWER = std::stof(data_s.c_str(), nullptr); else - p.TEFFLOWER = NAN; + p.TEFFLOWER = NAN;*/ getline(lineStream, data_s, ','); // UTEFF - if (!data_s.empty()) + /*if (!data_s.empty()) p.UTEFF = std::stof(data_s.c_str(), nullptr); else - p.UTEFF = NAN; + p.UTEFF = NAN;*/ getline(lineStream, data_s, ','); // TEFFREF getline(lineStream, data_s, ','); // TEFFURL @@ -763,15 +770,70 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data_s); // KDE if (!iskeplerobject) { + + // calculate B-V from Teff if not exsisting + if (std::isnan(p.BMV) ) + { + if (!std::isnan(teff)) + { + + float teff_current, teff_upper, teff_lower, BV, bv_upper, bv_lower = 0; + + std::ifstream teff_bv("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/teff_bv.txt"); + if (!teff_bv.good()) { + LERROR(fmt::format("Failed to open teff_bv.txt file")); + return; + } + + std::string row, teff_string, bv_string; + while (getline(teff_bv, row)) { + std::istringstream lineStream(row); + getline(lineStream, teff_string, ','); + getline(lineStream, bv_string); + + teff_current= std::stof(teff_string.c_str(), nullptr); + + if (teff > teff_current) + { + teff_lower = teff_current; + bv_lower = std::stof(bv_string.c_str(), nullptr); + } + else + { + + teff_upper = teff_current; + bv_upper = std::stof(bv_string.c_str(), nullptr); + if (bv_lower == 0) + { + BV = 1.45; + } + else + BV = (((bv_upper - bv_lower)*(teff - teff_lower)) / (teff_upper - teff_lower)) + bv_lower; + + break; + } + } + + teff_bv.close(); + p.BMV = BV; + + } + else + p.BMV = NAN; + } + long pos = bin_file.tellp(); lut_file << planetname << "," << pos << std::endl; bin_file.write((char *)&p, sizeof(struct Exoplanet)); + + bmv_file << planetname << " " << teff << " " << p.BMV << std::endl; } } csv_file.close(); bin_file.close(); lut_file.close(); + bmv_file.close(); progressCallback(1.0f); } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 2060336c15..c01dd5f51f 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -59,6 +59,7 @@ private: float BIGOMLOWER; float UBIGOM; int BINARY; // **one or more stars** + float BMV; float ECC; float ECCUPPER; float ECCLOWER; @@ -84,10 +85,10 @@ private: float RSTARUPPER; float RSTARLOWER; float URSTAR; - float TEFF; - float TEFFUPPER; - float TEFFLOWER; - float UTEFF; + //float TEFF; + //float TEFFUPPER; + //float TEFFLOWER; + //float UTEFF; double TT; float TTUPPER; float TTLOWER; From 0380fa8ca4b18f2912403d2a087e8033963478d8 Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 1 May 2018 15:29:32 -0400 Subject: [PATCH 014/123] Colors the star according to its B-V value. --- modules/exoplanets/exoplanetsmodule.cpp | 65 +++++++++++++++++++++---- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 73c429cbe2..af6358ce8f 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -92,6 +92,34 @@ struct Exoplanet { float POSITIONZ; }; +std::string getStarColor(float bv){ + std::string colorString; + + std::ifstream colormap("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/colorbv.cmap", std::ios::in); + if (!colormap.good()) { + std::cout << "Failed to open colormap data file"; + } + + int t = round(((bv + 0.4) / (2.0 + 0.4))*255); + + std::string color; + for (size_t i = 0; i < t+12; i++) + { + getline(colormap, color); + } + + std::istringstream colorstream(color); + std::string r, g, b; + getline(colorstream, r, ' '); + getline(colorstream, g, ' '); + getline(colorstream, b, ' '); + colorString = "{" + r + ", " + g + ", " + b + "}"; + + colormap.close(); + + return colorString; +} + ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} @@ -143,7 +171,7 @@ int addNode(lua_State* L) { lut.close(); - if (found && !isnan(p.POSITIONX) && !p.BINARY ) + if (found && !isnan(p.POSITIONX) && !p.BINARY) { Time epoch; double parsec = 0.308567756E17; @@ -152,18 +180,19 @@ int addNode(lua_State* L) { "Name = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" - "}" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" "}" - "}"; + "}" + "}"; if (isnan(p.RSTAR)) { p.RSTAR = 1.46046; } - + + std::string color = getStarColor(p.BMV); const std::string luaTableStarGlare = "{" "Name = '" + starname + "Plane'," "Parent = '" + starname + "'," @@ -175,12 +204,28 @@ int addNode(lua_State* L) { "Layers = {" "ColorLayers = {" "{" - "Name = 'Star Texture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) - "Enabled = true" + "Name = 'Star Texture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) + "BlendMode = 'Color'," + "Enabled = true" + "}," + "{" + "Name = 'Star Color'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Multiply'," + "Enabled = true" "}" "}" "}" + + /*"Name = '" + starname + "Plane'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableSphere'," + "Size = " + std::to_string(p.RSTAR) + " * 6.957E8,"//solar radii to m + "Segments = 40," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'"*/ //"Type = 'RenderablePlaneImageLocal'," //"Size = " + std::to_string(p.RSTAR) + " * 6.95700E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m //"Billboard = true," From f2445b78534781a00272ed3f86ef1cb3107e3c4f Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 2 May 2018 11:15:46 -0400 Subject: [PATCH 015/123] Added star glare. --- modules/exoplanets/exoplanetsmodule.cpp | 51 ++++++++++++++----------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index af6358ce8f..df7749f0a2 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -99,7 +99,7 @@ std::string getStarColor(float bv){ if (!colormap.good()) { std::cout << "Failed to open colormap data file"; } - + int t = round(((bv + 0.4) / (2.0 + 0.4))*255); std::string color; @@ -176,7 +176,7 @@ int addNode(lua_State* L) { Time epoch; double parsec = 0.308567756E17; - const std::string luaTableParent = "{" + const std::string starParent = "{" "Name = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" @@ -193,8 +193,8 @@ int addNode(lua_State* L) { } std::string color = getStarColor(p.BMV); - const std::string luaTableStarGlare = "{" - "Name = '" + starname + "Plane'," + const std::string starGlobe = "{" + "Name = '" + starname + "Globe'," "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderableGlobe'," @@ -203,39 +203,44 @@ int addNode(lua_State* L) { "PerformShading = false," "Layers = {" "ColorLayers = {" + + "{" + "Name = 'Star Color'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," "{" "Name = 'Star Texture'," "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) "BlendMode = 'Color'," "Enabled = true" - "}," - "{" - "Name = 'Star Color'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Multiply'," - "Enabled = true" "}" "}" "}" - - /*"Name = '" + starname + "Plane'," + "}" + "}"; + const std::string starGlare = "{" + "Name = '" + starname + "Glare'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableSphere'," - "Size = " + std::to_string(p.RSTAR) + " * 6.957E8,"//solar radii to m - "Segments = 40," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'"*/ - //"Type = 'RenderablePlaneImageLocal'," - //"Size = " + std::to_string(p.RSTAR) + " * 6.95700E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - //"Billboard = true," - //"Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," - //"BlendMode = 'Additive'" + "Type = 'RenderablePlaneImageLocal'," + "Size = " + std::to_string(p.RSTAR) + " *(1.3*10^10.5)," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," + "BlendMode = 'Additive'" "}" "}"; - std::string scriptParent = "openspace.addSceneGraphNode(" + luaTableParent + "); openspace.addSceneGraphNode(" + luaTableStarGlare + ");"; + std::string scriptParent = "openspace.addSceneGraphNode(" + starParent + ");openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; + OsEng.scriptEngine().queueScript( + scriptParent, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + scriptParent = ""; for (size_t i = 0; i < plsy.size(); i++) { From e99d600a961d966dd43485f6e82303cbec927578 Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 3 May 2018 16:18:09 -0400 Subject: [PATCH 016/123] Only visualizes an exoplanet/star if its radius is known. --- modules/exoplanets/exoplanetsmodule.cpp | 170 ++++++++++++------------ 1 file changed, 84 insertions(+), 86 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index df7749f0a2..83d0c4db4f 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -171,10 +171,11 @@ int addNode(lua_State* L) { lut.close(); - if (found && !isnan(p.POSITIONX) && !p.BINARY) + if (found && !isnan(p.POSITIONX) && !p.BINARY && !isnan(p.A) && !isnan(p.PER)) { Time epoch; double parsec = 0.308567756E17; + std::string scriptParent; const std::string starParent = "{" "Name = '" + starname + "'," @@ -186,92 +187,80 @@ int addNode(lua_State* L) { "}" "}" "}"; + scriptParent = "openspace.addSceneGraphNode(" + starParent + ");"; - if (isnan(p.RSTAR)) + if (!isnan(p.RSTAR)) { - p.RSTAR = 1.46046; - } - - std::string color = getStarColor(p.BMV); - const std::string starGlobe = "{" - "Name = '" + starname + "Globe'," - "Parent = '" + starname + "'," - "Renderable = {" + std::string color = getStarColor(p.BMV); + const std::string starGlobe = "{" + "Name = '" + starname + "Globe'," + "Parent = '" + starname + "'," + "Renderable = {" "Type = 'RenderableGlobe'," "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" - "ColorLayers = {" - - "{" - "Name = 'Star Color'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" - "}," - "{" - "Name = 'Star Texture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) - "BlendMode = 'Color'," - "Enabled = true" - "}" - "}" + "ColorLayers = {" + + "{" + "Name = 'Star Color'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Name = 'Star Texture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) + "BlendMode = 'Color'," + "Enabled = true" "}" - "}" - "}"; - const std::string starGlare = "{" - "Name = '" + starname + "Glare'," - "Parent = '" + starname + "'," - "Renderable = {" + "}" + "}" + "}" + "}"; + const std::string starGlare = "{" + "Name = '" + starname + "Glare'," + "Parent = '" + starname + "'," + "Renderable = {" "Type = 'RenderablePlaneImageLocal'," "Size = " + std::to_string(p.RSTAR) + " *(1.3*10^10.5)," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," "BlendMode = 'Additive'" - "}" - "}"; + "}" + "}"; - std::string scriptParent = "openspace.addSceneGraphNode(" + starParent + ");openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; + scriptParent += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; + } OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + - scriptParent = ""; for (size_t i = 0; i < plsy.size(); i++) { - - if (isnan(plsy[i].R)) - { - plsy[i].R = 0.320116; - } + scriptParent = ""; + if (isnan(plsy[i].ECC)) { - plsy[i].ECC = 0.0585235; - } - if (isnan(plsy[i].A)) - { - plsy[i].A = 0.435568; + plsy[i].ECC = 0; } if (isnan(plsy[i].I)) { - plsy[i].I = 90.00; + plsy[i].I = 90; } if (isnan(plsy[i].BIGOM)) { - plsy[i].BIGOM = 45; + plsy[i].BIGOM = 0; } if (isnan(plsy[i].OM)) { plsy[i].OM = 90; } - if (isnan(plsy[i].PER)) - { - plsy[i].PER = 358.802; - } std::string sepoch; if (!isnan(plsy[i].TT)) { epoch.setTime("JD " + std::to_string(plsy[i].TT)); @@ -280,39 +269,45 @@ int addNode(lua_State* L) { else sepoch = "2009-05-19T07:11:34.080"; - - const std::string luaTablePlanet = "{" - "Name = '" + plna[i] + "'," - "Parent = '" + starname + "'," - "Renderable = {" + if (!isnan(plsy[i].R)) + { + const std::string luaTablePlanet = "{" + "Name = '" + plna[i] + "'," + "Parent = '" + starname + "'," + "Renderable = {" "Type = 'RenderableGlobe'," "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" - "ColorLayers = {" - "{" - "Name = 'Exoplanet Texture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," - "Enabled = true" - "}" - "}" + "ColorLayers = {" + "{" + "Name = 'Exoplanet Texture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" "}" - "}," - "Transform = {" + "}" + "}" + "}," + "Transform = {" "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. "}" - "}," - "}"; + "}," + "}"; + + scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ");"; + + } + const std::string PlanetTrail = "{" "Name = '" + plna[i] + "Trail'," @@ -336,15 +331,17 @@ int addNode(lua_State* L) { "}," "}"; - scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + "); openspace.addSceneGraphNode(" + PlanetTrail + ");"; + scriptParent += " openspace.addSceneGraphNode(" + PlanetTrail + ");"; + + OsEng.scriptEngine().queueScript( + scriptParent, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); } - OsEng.scriptEngine().queueScript( - scriptParent, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + } else @@ -359,7 +356,7 @@ int removeNode(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); - std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lookup.txt"); + /*std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lookup.txt"); if (!lut.good()) { std::cout << "Failed to open exoplanets look-up table file"; } @@ -374,14 +371,15 @@ int removeNode(lua_State* L) { if (planetname.compare(0, planetname.length() - 2, starname) == 0) { plna.push_back(planetname); } - } + }*/ - std::string scriptParent; + /*std::string scriptParent; for (size_t i = 0; i < plna.size(); i++) { scriptParent += "openspace.removeSceneGraphNode('" + plna[i] + "Trail'); openspace.removeSceneGraphNode('" + plna[i] + "');"; } - scriptParent += " openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');"; + scriptParent += " openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');";*/ + std::string scriptParent = "openspace.removeSceneGraphNode('" + starname + "');"; OsEng.scriptEngine().queueScript( scriptParent, openspace::scripting::ScriptEngine::RemoteScripting::Yes From 974777b00c0090d8d3f78073eec1c7d599dd81d5 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 9 May 2018 13:43:27 -0400 Subject: [PATCH 017/123] Modified path. --- data/tasks/csvtobin.task | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/tasks/csvtobin.task b/data/tasks/csvtobin.task index f051cc8bc2..70079659f9 100644 --- a/data/tasks/csvtobin.task +++ b/data/tasks/csvtobin.task @@ -3,7 +3,7 @@ return { Type = "ExoplanetsCsvToBinTask", InputCSV = "${BASE}/modules/exoplanets/exoplanets.csv", - InputSPECK = "${BASE}/modules/exoplanets/expl.speck", + InputSPECK = "${SYNC}/http/digitaluniverse_exoplanets_speck/1/expl.speck", OutputBIN = "${BASE}/modules/exoplanets/expl_data.bin", OutputLUT = "${BASE}/modules/exoplanets/lookup.txt" -- OutputBIN = "${BASE}/sync/http/exoplanets_data/1/expl_data.bin" From 6eda714ce868b6ab0728f2ce007d7796c5b5c0ad Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 9 May 2018 15:01:07 -0400 Subject: [PATCH 018/123] Changed Name to Identifier in nodes. --- modules/exoplanets/exoplanetsmodule.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 83d0c4db4f..85b394d11a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -178,7 +178,7 @@ int addNode(lua_State* L) { std::string scriptParent; const std::string starParent = "{" - "Name = '" + starname + "'," + "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" "Translation = {" @@ -193,7 +193,7 @@ int addNode(lua_State* L) { { std::string color = getStarColor(p.BMV); const std::string starGlobe = "{" - "Name = '" + starname + "Globe'," + "Identifier = '" + starname + "Globe'," "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderableGlobe'," @@ -204,14 +204,14 @@ int addNode(lua_State* L) { "ColorLayers = {" "{" - "Name = 'Star Color'," + "Identifier = 'StarColor'," "Type = 'SolidColor'," "Color = " + color + "," "BlendMode = 'Normal'," "Enabled = true" "}," "{" - "Name = 'Star Texture'," + "Identifier = 'StarTexture'," "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) "BlendMode = 'Color'," "Enabled = true" @@ -221,7 +221,7 @@ int addNode(lua_State* L) { "}" "}"; const std::string starGlare = "{" - "Name = '" + starname + "Glare'," + "Identifier = '" + starname + "Glare'," "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderablePlaneImageLocal'," @@ -272,7 +272,7 @@ int addNode(lua_State* L) { if (!isnan(plsy[i].R)) { const std::string luaTablePlanet = "{" - "Name = '" + plna[i] + "'," + "Identifier = '" + plna[i] + "'," "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderableGlobe'," @@ -282,7 +282,7 @@ int addNode(lua_State* L) { "Layers = {" "ColorLayers = {" "{" - "Name = 'Exoplanet Texture'," + "Identifier = 'ExoplanetTexture'," "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," "Enabled = true" "}" @@ -310,7 +310,7 @@ int addNode(lua_State* L) { const std::string PlanetTrail = "{" - "Name = '" + plna[i] + "Trail'," + "Identifier = '" + plna[i] + "Trail'," "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderableTrailOrbit'," @@ -340,9 +340,6 @@ int addNode(lua_State* L) { } - - - } else { From f728d1c1dd88788b90153ec6f553995f07490dd0 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 9 May 2018 15:46:10 -0400 Subject: [PATCH 019/123] Cleanup. --- modules/exoplanets/exoplanetsmodule.cpp | 171 ++++++++++-------------- 1 file changed, 71 insertions(+), 100 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 85b394d11a..3d19cbb7f5 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -79,10 +79,6 @@ struct Exoplanet { float RSTARUPPER; float RSTARLOWER; float URSTAR; - //float TEFF; - //float TEFFUPPER; - //float TEFFLOWER; - //float UTEFF; double TT; float TTUPPER; float TTLOWER; @@ -175,19 +171,19 @@ int addNode(lua_State* L) { { Time epoch; double parsec = 0.308567756E17; - std::string scriptParent; + std::string script; const std::string starParent = "{" "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" + "}" "}" - "}" - "}"; - scriptParent = "openspace.addSceneGraphNode(" + starParent + ");"; + "}"; + script = "openspace.addSceneGraphNode(" + starParent + ");"; if (!isnan(p.RSTAR)) { @@ -196,54 +192,54 @@ int addNode(lua_State* L) { "Identifier = '" + starname + "Globe'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'StarColor'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Identifier = 'StarTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) + "BlendMode = 'Color'," + "Enabled = true" + "}" + "}" + "}" + "}" + "}"; - "{" - "Identifier = 'StarColor'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" - "}," - "{" - "Identifier = 'StarTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) - "BlendMode = 'Color'," - "Enabled = true" - "}" - "}" - "}" - "}" - "}"; const std::string starGlare = "{" "Identifier = '" + starname + "Glare'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " *(1.3*10^10.5)," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," - "BlendMode = 'Additive'" + "Type = 'RenderablePlaneImageLocal'," + "Size = " + std::to_string(p.RSTAR) + " *(1.3*10^10.5)," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," + "BlendMode = 'Additive'" "}" - "}"; + "}"; - scriptParent += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; + script += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; } OsEng.scriptEngine().queueScript( - scriptParent, + script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); for (size_t i = 0; i < plsy.size(); i++) { - scriptParent = ""; + script = ""; if (isnan(plsy[i].ECC)) { @@ -271,45 +267,44 @@ int addNode(lua_State* L) { if (!isnan(plsy[i].R)) { - const std::string luaTablePlanet = "{" + const std::string planet = "{" "Identifier = '" + plna[i] + "'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'ExoplanetTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," - "Enabled = true" - "}" - "}" - "}" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'ExoplanetTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" + "}" + "}" + "}" "}," "Transform = {" - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}" + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}" "}," - "}"; + "}"; - scriptParent += "openspace.addSceneGraphNode(" + luaTablePlanet + ");"; + script += "openspace.addSceneGraphNode(" + planet + ");"; } - - const std::string PlanetTrail = "{" + const std::string planetTrail = "{" "Identifier = '" + plna[i] + "Trail'," "Parent = '" + starname + "'," "Renderable = {" @@ -331,10 +326,10 @@ int addNode(lua_State* L) { "}," "}"; - scriptParent += " openspace.addSceneGraphNode(" + PlanetTrail + ");"; + script += " openspace.addSceneGraphNode(" + planetTrail + ");"; OsEng.scriptEngine().queueScript( - scriptParent, + script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -353,32 +348,9 @@ int removeNode(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); - /*std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lookup.txt"); - if (!lut.good()) { - std::cout << "Failed to open exoplanets look-up table file"; - } - std::string line; - std::string planetname; - std::vector plna; - while (getline(lut, line)) { - - std::istringstream ss(line); - getline(ss, planetname, ','); - - if (planetname.compare(0, planetname.length() - 2, starname) == 0) { - plna.push_back(planetname); - } - }*/ - - /*std::string scriptParent; - for (size_t i = 0; i < plna.size(); i++) - { - scriptParent += "openspace.removeSceneGraphNode('" + plna[i] + "Trail'); openspace.removeSceneGraphNode('" + plna[i] + "');"; - } - scriptParent += " openspace.removeSceneGraphNode('" + starname + "Plane'); openspace.removeSceneGraphNode('" + starname + "');";*/ - std::string scriptParent = "openspace.removeSceneGraphNode('" + starname + "');"; + std::string script = "openspace.removeSceneGraphNode('" + starname + "');"; OsEng.scriptEngine().queueScript( - scriptParent, + script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -423,5 +395,4 @@ std::vector ExoplanetsModule::documentations() con }; } - } // namespace openspace From 4860120c56b8b98df6c2e4d6abc324419a2dfca3 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 9 May 2018 15:54:35 -0400 Subject: [PATCH 020/123] Clearer lua-function names. --- modules/exoplanets/exoplanetsmodule.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 3d19cbb7f5..2cd4c741cb 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -119,7 +119,7 @@ std::string getStarColor(float bv){ ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} -int addNode(lua_State* L) { +int addExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); @@ -344,7 +344,7 @@ int addNode(lua_State* L) { return 0; } -int removeNode(lua_State* L) { +int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); @@ -363,18 +363,18 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { res.name = "exoplanets"; res.functions = { { - "addNode", - &addNode, + "addExoplanetSystem", + &addExoplanetSystem, {}, "string", - "Adds two nodes to the scenegraph, one position node and one node to represenet the star." + "Adds the nodes to the scene graph of the exoplanet system." }, { - "removeNode", - &removeNode, + "removeExoplanetSystem", + &removeExoplanetSystem, {}, "string", - "Removes the node with the name given in the arguments." + "Removes the nodes from the scene graph of the exoplanet system." } }; From 0a220a23e4992f7336c41c82ecdc3361439f156e Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 10 May 2018 09:17:46 -0400 Subject: [PATCH 021/123] Some paths of more generic type. --- modules/exoplanets/exoplanetsmodule.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 2cd4c741cb..220fa02476 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -31,6 +31,7 @@ #include #include +#include #include @@ -91,7 +92,7 @@ struct Exoplanet { std::string getStarColor(float bv){ std::string colorString; - std::ifstream colormap("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/colorbv.cmap", std::ios::in); + std::ifstream colormap(absPath("${BASE}/modules/exoplanets/colorbv.cmap"), std::ios::in); if (!colormap.good()) { std::cout << "Failed to open colormap data file"; } @@ -125,12 +126,12 @@ int addExoplanetSystem(lua_State* L) { const std::string starname = luaL_checkstring(L, StringLocation); - std::ifstream data("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/expl_data.bin", std::ios::in | std::ios::binary); + std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); if (!data.good()) { std::cout << "Failed to open exoplanets data file"; } - std::ifstream lut("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/lookup.txt"); + std::ifstream lut(absPath("${BASE}/modules/exoplanets/lookup.txt")); if (!lut.good()) { std::cout << "Failed to open exoplanets look-up table file"; } @@ -188,6 +189,7 @@ int addExoplanetSystem(lua_State* L) { if (!isnan(p.RSTAR)) { std::string color = getStarColor(p.BMV); + const std::string starGlobe = "{" "Identifier = '" + starname + "Globe'," "Parent = '" + starname + "'," @@ -207,7 +209,7 @@ int addExoplanetSystem(lua_State* L) { "}," "{" "Identifier = 'StarTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"//'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," // adapt texture according to strar-temperature (TEFF) + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'," "BlendMode = 'Color'," "Enabled = true" "}" @@ -215,7 +217,7 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}"; - + const std::string starGlare = "{" "Identifier = '" + starname + "Glare'," "Parent = '" + starname + "'," From 0b36ccc0bb6e11fb9d6c6d7fce75b6c3db006af4 Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 22 May 2018 11:05:14 -0400 Subject: [PATCH 022/123] Cleanup comments --- .../tasks/exoplanetscsvtobintask.cpp | 21 +++---------------- .../exoplanets/tasks/exoplanetscsvtobintask.h | 4 ---- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 7730fcf888..ebb82d47e7 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -221,7 +221,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); std::ofstream lut_file(_outputLUTPath); - std::ofstream bmv_file("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/bmv.txt"); + std::ofstream bmv_file(absPath("${BASE}/modules/exoplanets/bmv.txt")); int version = 1; bin_file.write((char *)&version, sizeof(int)); @@ -705,23 +705,8 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb teff = NAN; getline(lineStream, data_s, ','); // TEFFUPPER - /*if (!data_s.empty()) - p.TEFFUPPER = std::stof(data_s.c_str(), nullptr); - else - p.TEFFUPPER = NAN;*/ - getline(lineStream, data_s, ','); // TEFFLOWER - /*if (!data_s.empty()) - p.TEFFLOWER = std::stof(data_s.c_str(), nullptr); - else - p.TEFFLOWER = NAN;*/ - getline(lineStream, data_s, ','); // UTEFF - /*if (!data_s.empty()) - p.UTEFF = std::stof(data_s.c_str(), nullptr); - else - p.UTEFF = NAN;*/ - getline(lineStream, data_s, ','); // TEFFREF getline(lineStream, data_s, ','); // TEFFURL getline(lineStream, data_s, ','); // TIMING @@ -779,7 +764,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb float teff_current, teff_upper, teff_lower, BV, bv_upper, bv_lower = 0; - std::ifstream teff_bv("C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/teff_bv.txt"); + std::ifstream teff_bv(absPath("${BASE}/modules/exoplanets/teff_bv.txt")); if (!teff_bv.good()) { LERROR(fmt::format("Failed to open teff_bv.txt file")); return; @@ -826,7 +811,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb lut_file << planetname << "," << pos << std::endl; bin_file.write((char *)&p, sizeof(struct Exoplanet)); - bmv_file << planetname << " " << teff << " " << p.BMV << std::endl; + bmv_file << planetname << " " << p.ECC << " " << p.ECCLOWER << " " << p.ECCUPPER << std::endl; } } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index c01dd5f51f..b6f6a83b68 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -85,10 +85,6 @@ private: float RSTARUPPER; float RSTARLOWER; float URSTAR; - //float TEFF; - //float TEFFUPPER; - //float TEFFLOWER; - //float UTEFF; double TT; float TTUPPER; float TTLOWER; From 2722aef8954f2e0cd063c97f0d8dd76b136bad49 Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 22 May 2018 11:10:00 -0400 Subject: [PATCH 023/123] New RenderableOrbitdisc that visualizes uncertainty in the semi-major axis --- modules/exoplanets/CMakeLists.txt | 10 +- .../rendering/renderableorbitdisc.cpp | 348 ++++++++++++++++++ .../rendering/renderableorbitdisc.h | 87 +++++ modules/exoplanets/shaders/orbitdisc_fs.glsl | 115 ++++++ modules/exoplanets/shaders/orbitdisc_vs.glsl | 47 +++ 5 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 modules/exoplanets/rendering/renderableorbitdisc.cpp create mode 100644 modules/exoplanets/rendering/renderableorbitdisc.h create mode 100644 modules/exoplanets/shaders/orbitdisc_fs.glsl create mode 100644 modules/exoplanets/shaders/orbitdisc_vs.glsl diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 86d4e5588f..33edec6fd2 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -27,18 +27,26 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) +set(SHADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/orbitdisc_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/orbitdisc_vs.glsl +) +source_group("Shader Files" FILES ${SHADER_FILES}) + create_new_module( "Exoplanets" exoplanets_module STATIC - ${HEADER_FILES} ${SOURCE_FILES} + ${HEADER_FILES} ${SOURCE_FILES} ${SHADER_FILES} ) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp new file mode 100644 index 0000000000..fdadad8feb --- /dev/null +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -0,0 +1,348 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace { + static const openspace::properties::Property::PropertyInfo TextureInfo = { + "Texture", + "Texture", + "This value is the path to a texture on disk that contains a one-dimensional " + "texture which is used for these rings." + }; + + static const openspace::properties::Property::PropertyInfo SizeInfo = { + "Size", + "Size", + "This value specifies the semi-major axis of teh orbit in meter." + }; + + static const openspace::properties::Property::PropertyInfo EccentricityInfo = { + "Eccentricity", + "Eccentricity", + "This value determines the eccentricity, that is the deviation from a perfect sphere, for this orbit." + }; + + static const openspace::properties::Property::PropertyInfo OffsetInfo = { + "Offset", + "Offset", + "This value is used to limit the width of the rings. Each of the two values is " + "the lower and the upper uncertainties of the semi-major axis. " + }; + + static const openspace::properties::Property::PropertyInfo TransparencyInfo = { + "Transparency", + "Transparency", + "This value determines the transparency of part of the rings depending on the " + "color values. For this value v, the transparency is equal to length(color) / v." + }; +} // namespace + +namespace openspace { + +documentation::Documentation RenderableOrbitdisc::Documentation() { + using namespace documentation; + return { + "Renderable Orbitdisc", + "exoplanets_renderable_orbitdisc", + { + { + "Type", + new StringEqualVerifier("RenderableOrbitdisc"), + Optional::No + }, + { + TextureInfo.identifier, + new StringVerifier, + Optional::No, + TextureInfo.description + }, + { + SizeInfo.identifier, + new DoubleVerifier, + Optional::No, + SizeInfo.description + }, + { + EccentricityInfo.identifier, + new DoubleVerifier, + Optional::No, + EccentricityInfo.description + }, + { + OffsetInfo.identifier, + new DoubleVector2Verifier, + Optional::Yes, + OffsetInfo.description + }, + { + TransparencyInfo.identifier, + new DoubleVerifier, + Optional::Yes, + TransparencyInfo.description + } + } + }; +} + +RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) + : Renderable(dictionary) + , _texturePath(TextureInfo) + , _size(SizeInfo, 1.f, 0.f, 3.0e11f) + , _eccentricity(EccentricityInfo, 0.f, 0.f, 1.f) + , _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f)) + , _transparency(TransparencyInfo, 0.15f, 0.f, 1.f) + , _shader(nullptr) + , _texture(nullptr) + , _textureFile(nullptr) + , _textureIsDirty(false) + , _quad(0) + , _vertexPositionBuffer(0) + , _planeIsDirty(false) +{ + using ghoul::filesystem::File; + + documentation::testSpecificationAndThrow( + Documentation(), + dictionary, + "RenderableOrbitdisc" + ); + + if (dictionary.hasKey(OffsetInfo.identifier)) { + _offset = dictionary.value(OffsetInfo.identifier); + } + addProperty(_offset); + + _size = static_cast(dictionary.value(SizeInfo.identifier)); + _size = _size + (_offset.value().y * 149597870700); + setBoundingSphere(_size); + _size.onChange([&]() { _planeIsDirty = true; }); + addProperty(_size); + + _texturePath = absPath(dictionary.value(TextureInfo.identifier)); + _textureFile = std::make_unique(_texturePath); + + _texturePath.onChange([&]() { loadTexture(); }); + addProperty(_texturePath); + + _textureFile->setCallback([&](const File&) { _textureIsDirty = true; }); + + if (dictionary.hasKey(TransparencyInfo.identifier)) { + _transparency = static_cast( + dictionary.value(TransparencyInfo.identifier) + ); + } + addProperty(_transparency); + + _eccentricity = static_cast(dictionary.value(EccentricityInfo.identifier)); + _eccentricity.onChange([&]() { _planeIsDirty = true; }); + addProperty(_eccentricity); +} + +bool RenderableOrbitdisc::isReady() const { + return _shader && _texture; +} + +void RenderableOrbitdisc::initializeGL() { + _shader = OsEng.renderEngine().buildRenderProgram( + "OrbitdiscProgram", + absPath("${BASE}/modules/exoplanets/shaders/orbitdisc_vs.glsl"), + absPath("${BASE}/modules/exoplanets/shaders/orbitdisc_fs.glsl") + ); + + _uniformCache.modelViewProjection = _shader->uniformLocation( + "modelViewProjectionTransform" + ); + _uniformCache.textureOffset = _shader->uniformLocation("textureOffset"); + _uniformCache.transparency = _shader->uniformLocation("transparency"); + //_uniformCache.sunPosition = _shader->uniformLocation("sunPosition"); + _uniformCache.texture = _shader->uniformLocation("texture1"); + _uniformCache.eccentricity = _shader->uniformLocation("eccentricity"); + _uniformCache.semiMajorAxis = _shader->uniformLocation("semiMajorAxis"); + + glGenVertexArrays(1, &_quad); + glGenBuffers(1, &_vertexPositionBuffer); + + createPlane(); + loadTexture(); +} + +void RenderableOrbitdisc::deinitializeGL() { + glDeleteVertexArrays(1, &_quad); + _quad = 0; + + glDeleteBuffers(1, &_vertexPositionBuffer); + _vertexPositionBuffer = 0; + + _textureFile = nullptr; + _texture = nullptr; + + OsEng.renderEngine().removeRenderProgram(_shader.get()); + _shader = nullptr; +} + +void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { + _shader->activate(); + + glm::dmat4 modelTransform = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * + glm::dmat4(data.modelTransform.rotation) * + glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); + + glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; + + _shader->setUniform( + _uniformCache.modelViewProjection, + data.camera.projectionMatrix() * glm::mat4(modelViewTransform) + ); + _shader->setUniform(_uniformCache.textureOffset, _offset); + _shader->setUniform(_uniformCache.transparency, _transparency); + _shader->setUniform(_uniformCache.eccentricity, _eccentricity); + _shader->setUniform(_uniformCache.semiMajorAxis, _size); + //_shader->setUniform(_uniformCache.sunPosition, _sunPosition); + + //setPscUniforms(*_shader, data.camera, data.position); + + ghoul::opengl::TextureUnit unit; + unit.activate(); + _texture->bind(); + _shader->setUniform(_uniformCache.texture, unit); + + glDisable(GL_CULL_FACE); + + glBindVertexArray(_quad); + glDrawArrays(GL_TRIANGLES, 0, 6); + + glEnable(GL_CULL_FACE); + _shader->deactivate(); +} + +void RenderableOrbitdisc::update(const UpdateData& data) { + if (_shader->isDirty()) { + _shader->rebuildFromFile(); + + _uniformCache.modelViewProjection = _shader->uniformLocation( + "modelViewProjectionTransform" + ); + _uniformCache.textureOffset = _shader->uniformLocation("textureOffset"); + _uniformCache.transparency = _shader->uniformLocation("transparency"); + //_uniformCache.sunPosition = _shader->uniformLocation("sunPosition"); + _uniformCache.texture = _shader->uniformLocation("texture1"); + _uniformCache.eccentricity = _shader->uniformLocation("eccentricity"); + _uniformCache.semiMajorAxis = _shader->uniformLocation("semiMajorAxis"); + } + + if (_planeIsDirty) { + createPlane(); + _planeIsDirty = false; + } + + if (_textureIsDirty) { + loadTexture(); + _textureIsDirty = false; + } + + //_sunPosition = OsEng.renderEngine().scene()->sceneGraphNode("Sun")->worldPosition() - + //data.modelTransform.translation; +} + +void RenderableOrbitdisc::loadTexture() { + if (_texturePath.value() != "") { + std::unique_ptr texture = + ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); + + if (texture) { + LDEBUGC( + "RenderableOrbitdisc", + fmt::format("Loaded texture from '{}'", absPath(_texturePath)) + ); + _texture = std::move(texture); + + _texture->uploadTexture(); + _texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); + + _textureFile = std::make_unique(_texturePath); + _textureFile->setCallback( + [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + ); + } + } +} + +void RenderableOrbitdisc::createPlane() { + const GLfloat size = _size.value() * (1.0 + _eccentricity.value()); + + struct VertexData { + GLfloat x; + GLfloat y; + GLfloat s; + GLfloat t; + }; + + VertexData data[] = { + { -size, -size, 0.f, 0.f }, + { size, size, 1.f, 1.f }, + { -size, size, 0.f, 1.f }, + { -size, -size, 0.f, 0.f }, + { size, -size, 1.f, 0.f }, + { size, size, 1.f, 1.f }, + }; + + glBindVertexArray(_quad); + glBindBuffer(GL_ARRAY_BUFFER, _vertexPositionBuffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(data), data, GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glVertexAttribPointer( + 0, + 2, + GL_FLOAT, + GL_FALSE, + sizeof(VertexData), + nullptr + ); + glEnableVertexAttribArray(1); + glVertexAttribPointer( + 1, + 2, + GL_FLOAT, + GL_FALSE, + sizeof(VertexData), + reinterpret_cast(offsetof(VertexData, s)) + ); +} + +} // namespace openspace diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h new file mode 100644 index 0000000000..8ddc4be64d --- /dev/null +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -0,0 +1,87 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_EXOPLENETS___RENDERABLEORBITDISC___H__ +#define __OPENSPACE_MODULE_EXOPLANETS___RENDERABLEORBITDISC___H__ + +#include + +#include +#include +#include +#include + +#include + +namespace ghoul::filesystem { class File; } +namespace ghoul::opengl { + class ProgramObject; + class Texture; +} // namespace ghoul::opengl + +namespace openspace { + +namespace documentation { struct Documentation; } + +class RenderableOrbitdisc : public Renderable { +public: + RenderableOrbitdisc(const ghoul::Dictionary& dictionary); + + void initializeGL() override; + void deinitializeGL() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + +private: + void loadTexture(); + void createPlane(); + + properties::StringProperty _texturePath; + properties::FloatProperty _size; + properties::FloatProperty _eccentricity; + properties::Vec2Property _offset; + //properties::FloatProperty _nightFactor; + properties::FloatProperty _transparency; + + std::unique_ptr _shader; + UniformCache(modelViewProjection, textureOffset, transparency, + texture, eccentricity, semiMajorAxis) _uniformCache; + std::unique_ptr _texture; + std::unique_ptr _textureFile; + + bool _textureIsDirty; + GLuint _quad; + GLuint _vertexPositionBuffer; + bool _planeIsDirty; + +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_SPACE___RENDERABLERINGS___H__ diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl new file mode 100644 index 0000000000..aacf432515 --- /dev/null +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -0,0 +1,115 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include "PowerScaling/powerScaling_fs.hglsl" +#include "fragment.glsl" + +in vec2 vs_st; +in vec4 vs_position; +//in vec4 vs_gPosition; +//in vec3 vs_gNormal; + +uniform sampler1D texture1; +uniform vec2 textureOffset; +uniform float transparency; +uniform float eccentricity; +uniform float semiMajorAxis; + +uniform bool hasSunPosition; +uniform vec3 sunPosition; +//uniform float _nightFactor; + + +Fragment getFragment() { + // Moving the origin to the center + vec2 st = (vs_st - vec2(0.5)) * 2.0; + + + // The length of the texture coordinates vector is our distance from the center + float radius; + float radius_inner; + + float semiMinorAxis = semiMajorAxis * sqrt(1.0 - pow(eccentricity, 2.0)); + float focus = sqrt(pow(semiMajorAxis, 2.0) - pow(semiMinorAxis, 2.0)); + float apoapsisDistance = semiMajorAxis * (1 + eccentricity); + + float semiMajorAxis_inner = semiMajorAxis - textureOffset.x * 149597870700.0 - textureOffset.y * 149597870700.0; + float semiMinorAxis_inner = semiMajorAxis_inner * sqrt(1.0 - pow(eccentricity, 2.0)); + float focus_inner = sqrt(pow(semiMajorAxis_inner, 2.0) - pow(semiMinorAxis_inner, 2.0)); + + if(eccentricity <= 0.0){ + radius = length(st); + radius_inner = pow(st.x , 2.0) / pow(semiMajorAxis_inner/apoapsisDistance, 2.0) + ( pow(st.y, 2.0) / (pow(semiMajorAxis_inner/apoapsisDistance, 2.0)) ); + } + else { + radius = ( pow((st.x + focus/apoapsisDistance), 2.0) ) / pow(semiMajorAxis/apoapsisDistance, 2.0) + ( pow(st.y, 2.0) / (pow(semiMinorAxis/apoapsisDistance, 2.0)) ); + radius_inner = ( pow((st.x + focus_inner/apoapsisDistance), 2.0) ) / pow(semiMajorAxis_inner/apoapsisDistance, 2.0) + ( pow(st.y, 2.0) / (pow(semiMinorAxis_inner/apoapsisDistance, 2.0)) ); + } + + // We only want to consider ring-like objects so we need to discard everything outside the largest radius + if (radius > 1.0 ) + discard; + // We also need to discard ecerthing inside the smallest radius + if (radius_inner < 1.0 ) + discard; + + // Remapping the texture coordinates + // Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y] + // textureOffset.x -> 0 + // textureOffset.y -> 1 + + // textureOffset is not the same as it was when the following row was written. + // But as long as the texture is one color it doesnt seem to matter. + float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x); + + vec4 diffuse = texture(texture1, texCoord); + float colorValue = length(diffuse.rgb); + // times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want + // to normalize the transparency value to [0,1] + if (colorValue < 3.0 * transparency) { + diffuse.a = pow(colorValue / (3.0 * transparency), 1); + } + + // The normal for the one plane depends on whether we are dealing + // with a front facing or back facing fragment + vec3 normal; + // The plane is oriented on the xz plane + // WARNING: This might not be the case for Uranus + if (gl_FrontFacing) { + normal = vec3(-1.0, 0.0, 0.0); + } + else { + normal = vec3(1.0, 0.0, 0.0); + } + + + Fragment frag; + frag.color = diffuse; + frag.depth = vs_position.w; + + //frag.gPosition = vs_gPosition; + //frag.gNormal = vs_gNormal; + + return frag; +} diff --git a/modules/exoplanets/shaders/orbitdisc_vs.glsl b/modules/exoplanets/shaders/orbitdisc_vs.glsl new file mode 100644 index 0000000000..2f71337783 --- /dev/null +++ b/modules/exoplanets/shaders/orbitdisc_vs.glsl @@ -0,0 +1,47 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#version __CONTEXT__ + +#include "PowerScaling/powerScaling_vs.hglsl" + +layout(location = 0) in vec2 in_position; +layout(location = 1) in vec2 in_st; + +out vec2 vs_st; +out vec4 vs_position; +//out vec4 vs_gPosition; +//out vec3 vs_gNormal; + +uniform mat4 modelViewProjectionTransform; + +void main() { + vs_st = in_st; + + vs_position = z_normalization( + modelViewProjectionTransform * vec4(in_position.xy, 0.0, 1.0) + ); + gl_Position = vs_position; + +} From 8e4b23b49ff51ba341121206d536b0a76c8cac9e Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 22 May 2018 11:13:32 -0400 Subject: [PATCH 024/123] Adds the renderable Orbitdiscs for each orbitline where there is an uncertainty of the semi-major axis --- modules/exoplanets/exoplanetsmodule.cpp | 129 ++++++++++++++++++++++-- 1 file changed, 121 insertions(+), 8 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 220fa02476..b402924d25 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -32,8 +32,11 @@ #include #include +#include +#include #include +#include #include #include @@ -117,6 +120,25 @@ std::string getStarColor(float bv){ return colorString; } +std::string computeRotationMatrix(float i, float bigom, float om) { + + const glm::vec3 ascendingNodeAxisRot = { 0.f, 1.f, 0.f }; + const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; + const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; + + const double asc = glm::radians(bigom); + const double inc = glm::radians(i); + const double per = glm::radians(om); + + glm::dmat3 orbitPlaneRotation = + glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * + glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * + glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); + + return std::to_string(orbitPlaneRotation); + +} + ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} @@ -162,17 +184,18 @@ int addExoplanetSystem(lua_State* L) { plna.push_back(planetname); plsy.push_back(p); found = true; + } } data.close(); lut.close(); - if (found && !isnan(p.POSITIONX) && !p.BINARY && !isnan(p.A) && !isnan(p.PER)) + if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY { Time epoch; double parsec = 0.308567756E17; - std::string script; + std::string script = ""; const std::string starParent = "{" "Identifier = '" + starname + "'," @@ -302,9 +325,15 @@ int addExoplanetSystem(lua_State* L) { "}," "}"; - script += "openspace.addSceneGraphNode(" + planet + ");"; + script = "openspace.addSceneGraphNode(" + planet + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + script = ""; } + const std::string planetTrail = "{" "Identifier = '" + plna[i] + "Trail'," @@ -312,10 +341,10 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableTrailOrbit'," "Period = " + std::to_string(plsy[i].PER) + "," - "Resolution = 100," + "Resolution = 1000," "Translation = {" "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A "Inclination = " + std::to_string(plsy[i].I) + "," //I "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM @@ -328,15 +357,97 @@ int addExoplanetSystem(lua_State* L) { "}," "}"; - script += " openspace.addSceneGraphNode(" + planetTrail + ");"; - OsEng.scriptEngine().queueScript( - script, + "openspace.addSceneGraphNode(" + planetTrail + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + + if(!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) + { + std::string rotation_matrix = computeRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); + + const std::string disc = "{" + "Identifier = '" + plna[i] + "Disc'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = "+ std::to_string(plsy[i].ECC) +"," + "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend + "Transparency = 0.99" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + rotation_matrix + "," + "}" + "}," + "}"; + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + disc + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + if(!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) + { + const std::string discECCLOWER = "{" + "Identifier = '" + plna[i] + "discECCLOWER'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = "+ std::to_string(plsy[i].ECC - plsy[i].ECCLOWER) +"," + "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend + "Transparency = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + rotation_matrix + "," + "}" + "}," + "}"; + + + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + discECCLOWER + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + const std::string discECCUPPER = "{" + "Identifier = '" + plna[i] + "discECCUPPER'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = "+ std::to_string(plsy[i].ECC + plsy[i].ECCUPPER) +"," + "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend + "Transparency = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + rotation_matrix + "," + "}" + "}," + "}"; + + + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + discECCUPPER + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } } + } else { @@ -387,8 +498,10 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { auto fTask = FactoryManager::ref().factory(); + auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fTask, "No task factory existed"); fTask->registerClass("ExoplanetsCsvToBinTask"); + fRenderable->registerClass("RenderableOrbitdisc"); } std::vector ExoplanetsModule::documentations() const { From f8bc262958370eaf1811dc2d79c94f58e19b8645 Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 24 May 2018 17:50:22 -0400 Subject: [PATCH 025/123] Now the input star name has to be in the same form as it is in the expl.speck file --- modules/exoplanets/exoplanetsmodule.cpp | 141 +++++++++++++++++++++++- 1 file changed, 138 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index b402924d25..7767137173 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -139,6 +139,100 @@ std::string computeRotationMatrix(float i, float bigom, float om) { } +std::string getCsvStarname(std::string explName) { + std::string csvName = explName; + if (explName == "GJ 3021") + csvName = "HD 1237"; + else if (explName == "MOA 2009-BLG-387L") + csvName = "MOA-2009-BLG-387L"; + else if (explName == "HD 126614") + csvName = "HD 126614 A"; + else if (explName == "HD 27442") + csvName = "epsilon Ret"; + else if (explName == "PH1") + csvName = "PH-1"; + else if (explName == "gam 1 Leo") + csvName = "gamma Leo A"; + else if (explName == "OGLE 2007-BLG-368L") + csvName = "OGLE-2007-BLG-368L"; + else if (explName == "alf Ari") + csvName = "alpha Ari"; + else if (explName == "HD 160691") + csvName = "mu Ara"; + else if (explName == "OGLE 2005-BLG-169L") + csvName = "OGLE-05-169L"; + else if (explName == "HD 216435") + csvName = "tau Gru"; + else if (explName == "HR 810") + csvName = "iota Hor"; + else if (explName == "OGLE 2005-BLG-71L") + csvName = "OGLE-05-071L"; + else if (explName == "OGLE 2003-BLG-235L") + csvName = "OGLE235-MOA53"; + else if (explName == "MOA 2008-BLG-310L") + csvName = "MOA-2008-BLG-310L"; + else if (explName == "KOI-351") + csvName = "KIC 11442793"; + else if (explName == "OGLE 2006-BLG-109L") + csvName = "OGLE-2006-BLG-109L"; + else if (explName == "HD 137388 A") + csvName = "HD 137388"; + else if (explName == "kap CrB") + csvName = "kappa CrB"; + else if (explName == "XO-2 N") + csvName = "XO-2"; + else if (explName == "eps Tau") + csvName = "epsilon Tau"; + else if (explName == "eps Eri") + csvName = "epsilon Eri"; + else if (explName == "KOI-12") + csvName = "Kepler-448"; + else if (explName == "ome Ser") + csvName = "omega Ser"; + else if (explName == "MOA 2010-BLG-477L") + csvName = "MOA-2010-BLG-477L"; + else if (explName == "HD 285968") + csvName = "GJ 176"; + else if (explName == "BD-17 63") + csvName = "HIP 2247"; + else if (explName == "MOA 2009-BLG-266L") + csvName = "MOA-2009-BLG-266L"; + else if (explName == "KOI-94") + csvName = "Kepler-89"; + else if (explName == "HIP 75458") + csvName = "iota Dra"; + else if (explName == "MOA 2007-BLG-400L") + csvName = "MOA-2007-BLG-400L"; + else if (explName == "ups And") + csvName = "upsilon And"; + else if (explName == "OGLE 2011-BLG-251L") + csvName = "OGLE-2011-BLG-0251"; + else if (explName == "OGLE 2005-BLG-390L") + csvName = "OGLE-05-390L"; + else if (explName == "KOI-1257") + csvName = "Kepler-420"; + else if (explName == "bet Pic") + csvName = "beta Pic"; + else if (explName == "gam Cep") + csvName = "gamma Cep"; + else if (explName == "MOA 2007-BLG-192L") + csvName = "MOA-2007-BLG-192L"; + else if (explName == "MOA 2009-BLG-319L") + csvName = "MOA-2009-BLG-319L"; + else if (explName == "omi CrB") + csvName = "omicron CrB"; + else if (explName == "HD 62509") + csvName = "beta Gem"; + else if (explName == "eps CrB") + csvName = "epsilon CrB"; + else if (explName == "omi UMa") + csvName = "omicron UMa"; + else if (explName == "HD 142022 A") + csvName = "HD 142022"; + + return csvName; +} + ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} @@ -147,6 +241,8 @@ int addExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); + //change expl-starname to exoplanet.csv-starname + std::string starname_csv = getCsvStarname(starname); std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); if (!data.good()) { @@ -174,7 +270,7 @@ int addExoplanetSystem(lua_State* L) { std::istringstream ss(line); getline(ss, planetname, ','); - if (planetname.compare(0, planetname.length()-2, starname) == 0) { + if (planetname.compare(0, planetname.length()-2, starname_csv) == 0) { std::string location_s; getline(ss, location_s); long location = std::stol(location_s.c_str()); @@ -212,7 +308,33 @@ int addExoplanetSystem(lua_State* L) { if (!isnan(p.RSTAR)) { std::string color = getStarColor(p.BMV); - + + if (isnan(p.ECC)) + { + p.ECC = 0; + } + if (isnan(p.I)) + { + p.I = 90; + } + if (isnan(p.BIGOM)) + { + p.BIGOM = 0; + } + if (isnan(p.OM)) + { + p.OM = 90; + } + std::string epoch_string; + if (!isnan(p.TT)) { + epoch.setTime("JD " + std::to_string(p.TT)); + epoch_string = epoch.ISO8601(); + } + else { + epoch.setTime("JD " + std::to_string(2454970.0)); + epoch_string = epoch.ISO8601(); + } + const std::string starGlobe = "{" "Identifier = '" + starname + "Globe'," "Parent = '" + starname + "'," @@ -238,7 +360,20 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}" - "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(p.ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(p.A) + " * 149597871 * 0.1," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(p.I) + "," //I + "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + epoch_string + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. + "}" + "}," "}"; const std::string starGlare = "{" From 30e21ae7fd4594a70cde03b5beacf643be70ab27 Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 24 May 2018 19:07:16 -0400 Subject: [PATCH 026/123] Star glare smaller --- modules/exoplanets/exoplanetsmodule.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 7767137173..05deb2634a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -309,7 +309,7 @@ int addExoplanetSystem(lua_State* L) { { std::string color = getStarColor(p.BMV); - if (isnan(p.ECC)) + /* if (isnan(p.ECC)) { p.ECC = 0; } @@ -333,7 +333,7 @@ int addExoplanetSystem(lua_State* L) { else { epoch.setTime("JD " + std::to_string(2454970.0)); epoch_string = epoch.ISO8601(); - } + }*/ const std::string starGlobe = "{" "Identifier = '" + starname + "Globe'," @@ -361,7 +361,7 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}," - "Transform = {" + /*"Transform = {" "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(p.ECC) + "," //ECC @@ -373,7 +373,7 @@ int addExoplanetSystem(lua_State* L) { "Epoch = '" + epoch_string + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. "}" - "}," + "},"*/ "}"; const std::string starGlare = "{" @@ -381,7 +381,7 @@ int addExoplanetSystem(lua_State* L) { "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " *(1.3*10^10.5)," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," "BlendMode = 'Additive'" From 13bbcfa12ae1db91dff917802e4eb8565e81a7bd Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 28 May 2018 12:14:39 -0400 Subject: [PATCH 027/123] Limiting the value of the eccentricity to be between 0 and 1 --- modules/exoplanets/exoplanetsmodule.cpp | 80 ++++++++++++------------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 05deb2634a..8d6387790c 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -45,6 +46,8 @@ namespace openspace { +const char* _loggerCat = "exoplanets"; + using namespace exoplanets; struct Exoplanet { @@ -309,32 +312,6 @@ int addExoplanetSystem(lua_State* L) { { std::string color = getStarColor(p.BMV); - /* if (isnan(p.ECC)) - { - p.ECC = 0; - } - if (isnan(p.I)) - { - p.I = 90; - } - if (isnan(p.BIGOM)) - { - p.BIGOM = 0; - } - if (isnan(p.OM)) - { - p.OM = 90; - } - std::string epoch_string; - if (!isnan(p.TT)) { - epoch.setTime("JD " + std::to_string(p.TT)); - epoch_string = epoch.ISO8601(); - } - else { - epoch.setTime("JD " + std::to_string(2454970.0)); - epoch_string = epoch.ISO8601(); - }*/ - const std::string starGlobe = "{" "Identifier = '" + starname + "Globe'," "Parent = '" + starname + "'," @@ -361,19 +338,6 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}," - /*"Transform = {" - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(p.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(p.A) + " * 149597871 * 0.1," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(p.I) + "," //I - "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + epoch_string + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. - "}" - "},"*/ "}"; const std::string starGlare = "{" @@ -524,8 +488,14 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + if(!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) { + double lower_ecc = plsy[i].ECC - plsy[i].ECCLOWER; + if (lower_ecc < 0.0) + { + lower_ecc = 0.0; + } const std::string discECCLOWER = "{" "Identifier = '" + plna[i] + "discECCLOWER'," "Parent = '" + starname + "'," @@ -533,7 +503,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'RenderableOrbitdisc'," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = "+ std::to_string(plsy[i].ECC - plsy[i].ECCLOWER) +"," + "Eccentricity = "+ std::to_string(lower_ecc) +"," "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend "Transparency = 0.98," "Enabled = false" @@ -552,6 +522,11 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + double upper_ecc = plsy[i].ECC + plsy[i].ECCUPPER; + if (upper_ecc > 1.0) + { + upper_ecc = 1.0; + } const std::string discECCUPPER = "{" "Identifier = '" + plna[i] + "discECCUPPER'," "Parent = '" + starname + "'," @@ -559,7 +534,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'RenderableOrbitdisc'," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = "+ std::to_string(plsy[i].ECC + plsy[i].ECCUPPER) +"," + "Eccentricity = "+ std::to_string(upper_ecc)+"," "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend "Transparency = 0.98," "Enabled = false" @@ -605,6 +580,22 @@ int removeExoplanetSystem(lua_State* L) { return 0; } +int showSpectograph(lua_State* L) { + + const std::string luaTable = + "{Type = 'ScreenSpaceImageLocal', TexturePath = openspace.absPath('C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg') }"; + + std::string script = "openspace.addScreenSpaceRenderableLocal("+luaTable+");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + return 0; +} + + + scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { scripting::LuaLibrary res; @@ -623,6 +614,13 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { {}, "string", "Removes the nodes from the scene graph of the exoplanet system." + }, + { + "showSpectograph", + &showSpectograph, + {}, + "", + "Shows spectograph." } }; From e0f4afa9f604c4f1cdac53c473c9a2664a99875d Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 30 May 2018 10:57:16 -0400 Subject: [PATCH 028/123] Separate file for lua functions --- modules/exoplanets/exoplanetsmodule.cpp | 571 +------------------- modules/exoplanets/exoplanetsmodule.h | 1 - modules/exoplanets/exoplanetsmodule_lua.inl | 562 +++++++++++++++++++ 3 files changed, 565 insertions(+), 569 deletions(-) create mode 100644 modules/exoplanets/exoplanetsmodule_lua.inl diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 8d6387790c..5808060f38 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -23,26 +23,12 @@ ****************************************************************************************/ #include - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include - #include #include -#include -#include -#include -#include +#include + +#include "exoplanetsmodule_lua.inl" namespace openspace { @@ -50,552 +36,8 @@ const char* _loggerCat = "exoplanets"; using namespace exoplanets; -struct Exoplanet { - float A; - double AUPPER; - double ALOWER; - double UA; - float BIGOM; - float BIGOMUPPER; - float BIGOMLOWER; - float UBIGOM; - bool BINARY; - float BMV; - float ECC; - float ECCUPPER; - float ECCLOWER; - float UECC; - float I; - float IUPPER; - float ILOWER; - float UI; - int NCOMP; - float OM; - float OMUPPER; - float OMLOWER; - float UOM; - double PER; - float PERUPPER; - float PERLOWER; - float UPER; - double R; - double RUPPER; - double RLOWER; - double UR; - float RSTAR; - float RSTARUPPER; - float RSTARLOWER; - float URSTAR; - double TT; - float TTUPPER; - float TTLOWER; - float UTT; - float POSITIONX; - float POSITIONY; - float POSITIONZ; -}; - -std::string getStarColor(float bv){ - std::string colorString; - - std::ifstream colormap(absPath("${BASE}/modules/exoplanets/colorbv.cmap"), std::ios::in); - if (!colormap.good()) { - std::cout << "Failed to open colormap data file"; - } - - int t = round(((bv + 0.4) / (2.0 + 0.4))*255); - - std::string color; - for (size_t i = 0; i < t+12; i++) - { - getline(colormap, color); - } - - std::istringstream colorstream(color); - std::string r, g, b; - getline(colorstream, r, ' '); - getline(colorstream, g, ' '); - getline(colorstream, b, ' '); - colorString = "{" + r + ", " + g + ", " + b + "}"; - - colormap.close(); - - return colorString; -} - -std::string computeRotationMatrix(float i, float bigom, float om) { - - const glm::vec3 ascendingNodeAxisRot = { 0.f, 1.f, 0.f }; - const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; - const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; - - const double asc = glm::radians(bigom); - const double inc = glm::radians(i); - const double per = glm::radians(om); - - glm::dmat3 orbitPlaneRotation = - glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * - glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * - glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); - - return std::to_string(orbitPlaneRotation); - -} - -std::string getCsvStarname(std::string explName) { - std::string csvName = explName; - if (explName == "GJ 3021") - csvName = "HD 1237"; - else if (explName == "MOA 2009-BLG-387L") - csvName = "MOA-2009-BLG-387L"; - else if (explName == "HD 126614") - csvName = "HD 126614 A"; - else if (explName == "HD 27442") - csvName = "epsilon Ret"; - else if (explName == "PH1") - csvName = "PH-1"; - else if (explName == "gam 1 Leo") - csvName = "gamma Leo A"; - else if (explName == "OGLE 2007-BLG-368L") - csvName = "OGLE-2007-BLG-368L"; - else if (explName == "alf Ari") - csvName = "alpha Ari"; - else if (explName == "HD 160691") - csvName = "mu Ara"; - else if (explName == "OGLE 2005-BLG-169L") - csvName = "OGLE-05-169L"; - else if (explName == "HD 216435") - csvName = "tau Gru"; - else if (explName == "HR 810") - csvName = "iota Hor"; - else if (explName == "OGLE 2005-BLG-71L") - csvName = "OGLE-05-071L"; - else if (explName == "OGLE 2003-BLG-235L") - csvName = "OGLE235-MOA53"; - else if (explName == "MOA 2008-BLG-310L") - csvName = "MOA-2008-BLG-310L"; - else if (explName == "KOI-351") - csvName = "KIC 11442793"; - else if (explName == "OGLE 2006-BLG-109L") - csvName = "OGLE-2006-BLG-109L"; - else if (explName == "HD 137388 A") - csvName = "HD 137388"; - else if (explName == "kap CrB") - csvName = "kappa CrB"; - else if (explName == "XO-2 N") - csvName = "XO-2"; - else if (explName == "eps Tau") - csvName = "epsilon Tau"; - else if (explName == "eps Eri") - csvName = "epsilon Eri"; - else if (explName == "KOI-12") - csvName = "Kepler-448"; - else if (explName == "ome Ser") - csvName = "omega Ser"; - else if (explName == "MOA 2010-BLG-477L") - csvName = "MOA-2010-BLG-477L"; - else if (explName == "HD 285968") - csvName = "GJ 176"; - else if (explName == "BD-17 63") - csvName = "HIP 2247"; - else if (explName == "MOA 2009-BLG-266L") - csvName = "MOA-2009-BLG-266L"; - else if (explName == "KOI-94") - csvName = "Kepler-89"; - else if (explName == "HIP 75458") - csvName = "iota Dra"; - else if (explName == "MOA 2007-BLG-400L") - csvName = "MOA-2007-BLG-400L"; - else if (explName == "ups And") - csvName = "upsilon And"; - else if (explName == "OGLE 2011-BLG-251L") - csvName = "OGLE-2011-BLG-0251"; - else if (explName == "OGLE 2005-BLG-390L") - csvName = "OGLE-05-390L"; - else if (explName == "KOI-1257") - csvName = "Kepler-420"; - else if (explName == "bet Pic") - csvName = "beta Pic"; - else if (explName == "gam Cep") - csvName = "gamma Cep"; - else if (explName == "MOA 2007-BLG-192L") - csvName = "MOA-2007-BLG-192L"; - else if (explName == "MOA 2009-BLG-319L") - csvName = "MOA-2009-BLG-319L"; - else if (explName == "omi CrB") - csvName = "omicron CrB"; - else if (explName == "HD 62509") - csvName = "beta Gem"; - else if (explName == "eps CrB") - csvName = "epsilon CrB"; - else if (explName == "omi UMa") - csvName = "omicron UMa"; - else if (explName == "HD 142022 A") - csvName = "HD 142022"; - - return csvName; -} - - ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} -int addExoplanetSystem(lua_State* L) { - - const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); - - //change expl-starname to exoplanet.csv-starname - std::string starname_csv = getCsvStarname(starname); - - std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); - if (!data.good()) { - std::cout << "Failed to open exoplanets data file"; - } - - std::ifstream lut(absPath("${BASE}/modules/exoplanets/lookup.txt")); - if (!lut.good()) { - std::cout << "Failed to open exoplanets look-up table file"; - } - - //1. search lut for the starname and return the corresponding location - //2. go to that location in the data file - //3. read sizeof(exoplanet) bytes into an exoplanet object. - std::string planetname; - size_t len = 0; - Exoplanet p; - std::string line; - bool found = false; - - std::vector plsy; - std::vector plna; - while (getline(lut, line)) { - - std::istringstream ss(line); - getline(ss, planetname, ','); - - if (planetname.compare(0, planetname.length()-2, starname_csv) == 0) { - std::string location_s; - getline(ss, location_s); - long location = std::stol(location_s.c_str()); - - data.seekg(location); - data.read((char*)&p, sizeof(struct Exoplanet)); - plna.push_back(planetname); - plsy.push_back(p); - found = true; - - } - } - data.close(); - lut.close(); - - - if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY - { - Time epoch; - double parsec = 0.308567756E17; - std::string script = ""; - - const std::string starParent = "{" - "Identifier = '" + starname + "'," - "Parent = 'SolarSystemBarycenter'," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" - "}" - "}" - "}"; - script = "openspace.addSceneGraphNode(" + starParent + ");"; - - if (!isnan(p.RSTAR)) - { - std::string color = getStarColor(p.BMV); - - const std::string starGlobe = "{" - "Identifier = '" + starname + "Globe'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'StarColor'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" - "}," - "{" - "Identifier = 'StarTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'," - "BlendMode = 'Color'," - "Enabled = true" - "}" - "}" - "}" - "}," - "}"; - - const std::string starGlare = "{" - "Identifier = '" + starname + "Glare'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," - "BlendMode = 'Additive'" - "}" - "}"; - - script += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; - } - - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - - for (size_t i = 0; i < plsy.size(); i++) - { - script = ""; - - if (isnan(plsy[i].ECC)) - { - plsy[i].ECC = 0; - } - if (isnan(plsy[i].I)) - { - plsy[i].I = 90; - } - if (isnan(plsy[i].BIGOM)) - { - plsy[i].BIGOM = 0; - } - if (isnan(plsy[i].OM)) - { - plsy[i].OM = 90; - } - std::string sepoch; - if (!isnan(plsy[i].TT)) { - epoch.setTime("JD " + std::to_string(plsy[i].TT)); - sepoch = epoch.ISO8601(); - } - else - sepoch = "2009-05-19T07:11:34.080"; - - if (!isnan(plsy[i].R)) - { - const std::string planet = "{" - "Identifier = '" + plna[i] + "'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'ExoplanetTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," - "Enabled = true" - "}" - "}" - "}" - "}," - "Transform = {" - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}" - "}," - "}"; - - script = "openspace.addSceneGraphNode(" + planet + ");"; - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - script = ""; - - } - - - const std::string planetTrail = "{" - "Identifier = '" + plna[i] + "Trail'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableTrailOrbit'," - "Period = " + std::to_string(plsy[i].PER) + "," - "Resolution = 1000," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}," - "Color = { 1, 0, 0 }" - "}," - "}"; - - OsEng.scriptEngine().queueScript( - "openspace.addSceneGraphNode(" + planetTrail + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - if(!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) - { - std::string rotation_matrix = computeRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); - - const std::string disc = "{" - "Identifier = '" + plna[i] + "Disc'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = "+ std::to_string(plsy[i].ECC) +"," - "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend - "Transparency = 0.99" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + rotation_matrix + "," - "}" - "}," - "}"; - OsEng.scriptEngine().queueScript( - "openspace.addSceneGraphNode(" + disc + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - - if(!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) - { - double lower_ecc = plsy[i].ECC - plsy[i].ECCLOWER; - if (lower_ecc < 0.0) - { - lower_ecc = 0.0; - } - const std::string discECCLOWER = "{" - "Identifier = '" + plna[i] + "discECCLOWER'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = "+ std::to_string(lower_ecc) +"," - "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend - "Transparency = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + rotation_matrix + "," - "}" - "}," - "}"; - - - OsEng.scriptEngine().queueScript( - "openspace.addSceneGraphNode(" + discECCLOWER + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - double upper_ecc = plsy[i].ECC + plsy[i].ECCUPPER; - if (upper_ecc > 1.0) - { - upper_ecc = 1.0; - } - const std::string discECCUPPER = "{" - "Identifier = '" + plna[i] + "discECCUPPER'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = "+ std::to_string(upper_ecc)+"," - "Offset = { "+ std::to_string(plsy[i].ALOWER) +", "+ std::to_string(plsy[i].AUPPER) +" }," //min / max extend - "Transparency = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + rotation_matrix + "," - "}" - "}," - "}"; - - - OsEng.scriptEngine().queueScript( - "openspace.addSceneGraphNode(" + discECCUPPER + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - } - - } - - - } - else - { - printf("No star with that name or not enough data about it."); - } - - return 0; -} - -int removeExoplanetSystem(lua_State* L) { - const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); - - std::string script = "openspace.removeSceneGraphNode('" + starname + "');"; - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - return 0; -} - -int showSpectograph(lua_State* L) { - - const std::string luaTable = - "{Type = 'ScreenSpaceImageLocal', TexturePath = openspace.absPath('C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg') }"; - - std::string script = "openspace.addScreenSpaceRenderableLocal("+luaTable+");"; - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - return 0; -} - - - scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { scripting::LuaLibrary res; @@ -614,13 +56,6 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { {}, "string", "Removes the nodes from the scene graph of the exoplanet system." - }, - { - "showSpectograph", - &showSpectograph, - {}, - "", - "Shows spectograph." } }; diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index e5e3679666..2499124237 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -27,7 +27,6 @@ #include #include -#include namespace openspace { diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl new file mode 100644 index 0000000000..1fb6cc15a5 --- /dev/null +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -0,0 +1,562 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +#include + +#include +#include +#include + +#include + +namespace openspace{ + +struct Exoplanet { + float A; + double AUPPER; + double ALOWER; + double UA; + float BIGOM; + float BIGOMUPPER; + float BIGOMLOWER; + float UBIGOM; + bool BINARY; + float BMV; + float ECC; + float ECCUPPER; + float ECCLOWER; + float UECC; + float I; + float IUPPER; + float ILOWER; + float UI; + int NCOMP; + float OM; + float OMUPPER; + float OMLOWER; + float UOM; + double PER; + float PERUPPER; + float PERLOWER; + float UPER; + double R; + double RUPPER; + double RLOWER; + double UR; + float RSTAR; + float RSTARUPPER; + float RSTARLOWER; + float URSTAR; + double TT; + float TTUPPER; + float TTLOWER; + float UTT; + float POSITIONX; + float POSITIONY; + float POSITIONZ; +}; + +std::string getStarColor(float bv) { + std::string colorString; + + std::ifstream colormap(absPath("${BASE}/modules/exoplanets/colorbv.cmap"), std::ios::in); + if (!colormap.good()) { + std::cout << "Failed to open colormap data file"; + } + + int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); + + std::string color; + for (size_t i = 0; i < t + 12; i++) + { + getline(colormap, color); + } + + std::istringstream colorstream(color); + std::string r, g, b; + getline(colorstream, r, ' '); + getline(colorstream, g, ' '); + getline(colorstream, b, ' '); + colorString = "{" + r + ", " + g + ", " + b + "}"; + + colormap.close(); + + return colorString; +} + +std::string computeRotationMatrix(float i, float bigom, float om) { + + const glm::vec3 ascendingNodeAxisRot = { 0.f, 1.f, 0.f }; + const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; + const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; + + const double asc = glm::radians(bigom); + const double inc = glm::radians(i); + const double per = glm::radians(om); + + glm::dmat3 orbitPlaneRotation = + glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * + glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * + glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); + + return std::to_string(orbitPlaneRotation); + +} + +std::string getCsvStarname(std::string explName) { + std::string csvName = explName; + if (explName == "GJ 3021") + csvName = "HD 1237"; + else if (explName == "MOA 2009-BLG-387L") + csvName = "MOA-2009-BLG-387L"; + else if (explName == "HD 126614") + csvName = "HD 126614 A"; + else if (explName == "HD 27442") + csvName = "epsilon Ret"; + else if (explName == "PH1") + csvName = "PH-1"; + else if (explName == "gam 1 Leo") + csvName = "gamma Leo A"; + else if (explName == "OGLE 2007-BLG-368L") + csvName = "OGLE-2007-BLG-368L"; + else if (explName == "alf Ari") + csvName = "alpha Ari"; + else if (explName == "HD 160691") + csvName = "mu Ara"; + else if (explName == "OGLE 2005-BLG-169L") + csvName = "OGLE-05-169L"; + else if (explName == "HD 216435") + csvName = "tau Gru"; + else if (explName == "HR 810") + csvName = "iota Hor"; + else if (explName == "OGLE 2005-BLG-71L") + csvName = "OGLE-05-071L"; + else if (explName == "OGLE 2003-BLG-235L") + csvName = "OGLE235-MOA53"; + else if (explName == "MOA 2008-BLG-310L") + csvName = "MOA-2008-BLG-310L"; + else if (explName == "KOI-351") + csvName = "KIC 11442793"; + else if (explName == "OGLE 2006-BLG-109L") + csvName = "OGLE-2006-BLG-109L"; + else if (explName == "HD 137388 A") + csvName = "HD 137388"; + else if (explName == "kap CrB") + csvName = "kappa CrB"; + else if (explName == "XO-2 N") + csvName = "XO-2"; + else if (explName == "eps Tau") + csvName = "epsilon Tau"; + else if (explName == "eps Eri") + csvName = "epsilon Eri"; + else if (explName == "KOI-12") + csvName = "Kepler-448"; + else if (explName == "ome Ser") + csvName = "omega Ser"; + else if (explName == "MOA 2010-BLG-477L") + csvName = "MOA-2010-BLG-477L"; + else if (explName == "HD 285968") + csvName = "GJ 176"; + else if (explName == "BD-17 63") + csvName = "HIP 2247"; + else if (explName == "MOA 2009-BLG-266L") + csvName = "MOA-2009-BLG-266L"; + else if (explName == "KOI-94") + csvName = "Kepler-89"; + else if (explName == "HIP 75458") + csvName = "iota Dra"; + else if (explName == "MOA 2007-BLG-400L") + csvName = "MOA-2007-BLG-400L"; + else if (explName == "ups And") + csvName = "upsilon And"; + else if (explName == "OGLE 2011-BLG-251L") + csvName = "OGLE-2011-BLG-0251"; + else if (explName == "OGLE 2005-BLG-390L") + csvName = "OGLE-05-390L"; + else if (explName == "KOI-1257") + csvName = "Kepler-420"; + else if (explName == "bet Pic") + csvName = "beta Pic"; + else if (explName == "gam Cep") + csvName = "gamma Cep"; + else if (explName == "MOA 2007-BLG-192L") + csvName = "MOA-2007-BLG-192L"; + else if (explName == "MOA 2009-BLG-319L") + csvName = "MOA-2009-BLG-319L"; + else if (explName == "omi CrB") + csvName = "omicron CrB"; + else if (explName == "HD 62509") + csvName = "beta Gem"; + else if (explName == "eps CrB") + csvName = "epsilon CrB"; + else if (explName == "omi UMa") + csvName = "omicron UMa"; + else if (explName == "HD 142022 A") + csvName = "HD 142022"; + + return csvName; +} + + +int addExoplanetSystem(lua_State* L) { + + const int StringLocation = -1; + const std::string starname = luaL_checkstring(L, StringLocation); + + //change expl-starname to exoplanet.csv-starname + std::string starname_csv = getCsvStarname(starname); + + std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); + if (!data.good()) { + std::cout << "Failed to open exoplanets data file"; + } + + std::ifstream lut(absPath("${BASE}/modules/exoplanets/lookup.txt")); + if (!lut.good()) { + std::cout << "Failed to open exoplanets look-up table file"; + } + + //1. search lut for the starname and return the corresponding location + //2. go to that location in the data file + //3. read sizeof(exoplanet) bytes into an exoplanet object. + std::string planetname; + size_t len = 0; + Exoplanet p; + std::string line; + bool found = false; + + std::vector plsy; + std::vector plna; + while (getline(lut, line)) { + + std::istringstream ss(line); + getline(ss, planetname, ','); + + if (planetname.compare(0, planetname.length() - 2, starname_csv) == 0) { + std::string location_s; + getline(ss, location_s); + long location = std::stol(location_s.c_str()); + + data.seekg(location); + data.read((char*)&p, sizeof(struct Exoplanet)); + plna.push_back(planetname); + plsy.push_back(p); + found = true; + + } + } + data.close(); + lut.close(); + + + if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY + { + Time epoch; + double parsec = 0.308567756E17; + std::string script = ""; + + const std::string starParent = "{" + "Identifier = '" + starname + "'," + "Parent = 'SolarSystemBarycenter'," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" + "}" + "}" + "}"; + script = "openspace.addSceneGraphNode(" + starParent + ");"; + + if (!isnan(p.RSTAR)) + { + std::string color = getStarColor(p.BMV); + + const std::string starGlobe = "{" + "Identifier = '" + starname + "Globe'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'StarColor'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Identifier = 'StarTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'," + "BlendMode = 'Color'," + "Enabled = true" + "}" + "}" + "}" + "}," + "}"; + + const std::string starGlare = "{" + "Identifier = '" + starname + "Glare'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," + "BlendMode = 'Additive'" + "}" + "}"; + + script += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; + } + + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + + for (size_t i = 0; i < plsy.size(); i++) + { + script = ""; + + if (isnan(plsy[i].ECC)) + { + plsy[i].ECC = 0; + } + if (isnan(plsy[i].I)) + { + plsy[i].I = 90; + } + if (isnan(plsy[i].BIGOM)) + { + plsy[i].BIGOM = 0; + } + if (isnan(plsy[i].OM)) + { + plsy[i].OM = 90; + } + std::string sepoch; + if (!isnan(plsy[i].TT)) { + epoch.setTime("JD " + std::to_string(plsy[i].TT)); + sepoch = epoch.ISO8601(); + } + else + sepoch = "2009-05-19T07:11:34.080"; + + if (!isnan(plsy[i].R)) + { + const std::string planet = "{" + "Identifier = '" + plna[i] + "'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'ExoplanetTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" + "}" + "}" + "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}" + "}," + "}"; + + script = "openspace.addSceneGraphNode(" + planet + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + script = ""; + + } + + + const std::string planetTrail = "{" + "Identifier = '" + plna[i] + "Trail'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableTrailOrbit'," + "Period = " + std::to_string(plsy[i].PER) + "," + "Resolution = 1000," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}," + "Color = { 1, 0, 0 }" + "}," + "}"; + + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + planetTrail + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) + { + std::string rotation_matrix = computeRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); + + const std::string disc = "{" + "Identifier = '" + plna[i] + "Disc'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.99" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + rotation_matrix + "," + "}" + "}," + "}"; + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + disc + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + + if (!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) + { + double lower_ecc = plsy[i].ECC - plsy[i].ECCLOWER; + if (lower_ecc < 0.0) + { + lower_ecc = 0.0; + } + const std::string discECCLOWER = "{" + "Identifier = '" + plna[i] + "discECCLOWER'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(lower_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + rotation_matrix + "," + "}" + "}," + "}"; + + + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + discECCLOWER + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + double upper_ecc = plsy[i].ECC + plsy[i].ECCUPPER; + if (upper_ecc > 1.0) + { + upper_ecc = 1.0; + } + const std::string discECCUPPER = "{" + "Identifier = '" + plna[i] + "discECCUPPER'," + "Parent = '" + starname + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(upper_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + rotation_matrix + "," + "}" + "}," + "}"; + + + OsEng.scriptEngine().queueScript( + "openspace.addSceneGraphNode(" + discECCUPPER + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } + + } + + + } + else + { + printf("No star with that name or not enough data about it."); + } + + return 0; +} + +int removeExoplanetSystem(lua_State* L) { + const int StringLocation = -1; + const std::string starname = luaL_checkstring(L, StringLocation); + + std::string script = "openspace.removeSceneGraphNode('" + starname + "');"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + return 0; +} +} //namespace \ No newline at end of file From 3defbe6f7fcb467fa9a1a4514dedb3daf1932077 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 30 May 2018 14:34:46 -0400 Subject: [PATCH 029/123] Added module property class that will toggle the discovery method modes --- modules/exoplanets/CMakeLists.txt | 2 + .../discoverymethods/discoverymethods.cpp | 63 +++++++++++++++++++ .../discoverymethods/discoverymethods.h | 46 ++++++++++++++ modules/exoplanets/exoplanetsmodule.cpp | 5 ++ modules/exoplanets/exoplanetsmodule.h | 5 ++ 5 files changed, 121 insertions(+) create mode 100644 modules/exoplanets/discoverymethods/discoverymethods.cpp create mode 100644 modules/exoplanets/discoverymethods/discoverymethods.h diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 33edec6fd2..0bd3798bbf 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -28,6 +28,7 @@ set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h + ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -35,6 +36,7 @@ set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp new file mode 100644 index 0000000000..1a41cff022 --- /dev/null +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -0,0 +1,63 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +#include +#include + +#include +#include +#include +#include + +namespace { + constexpr const char* _loggerCat = "DiscoveryMethods"; + + static const openspace::properties::Property::PropertyInfo TransitMethodInfo = { + "TransitMethod", + "Show transit method", + "Change the view so that the transit method can be presented." + }; + + static const openspace::properties::Property::PropertyInfo DopplerMethodInfo = { + "DopplerMethod", + "Show doppler method", + "Change the view so that the doppler method can be presented." + }; +} // namespace + +namespace openspace::exoplanets{ + + DiscoveryMethods::DiscoveryMethods() + : PropertyOwner({ "DiscoveryMethods" }) + , _showTransit(TransitMethodInfo, false) + , _showDoppler(DopplerMethodInfo, false) + { + addProperty(_showTransit); + addProperty(_showDoppler); + _showTransit.onChange([&]() { LINFO("transit"); }); + _showDoppler.onChange([&]() { LINFO("doppler"); }); + } + +} // namespce + diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h new file mode 100644 index 0000000000..36ebdb0f52 --- /dev/null +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -0,0 +1,46 @@ +/***************************************************************************************** +* * +* OpenSpace * +* * +* Copyright (c) 2014-2018 * +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy of this * +* software and associated documentation files (the "Software"), to deal in the Software * +* without restriction, including without limitation the rights to use, copy, modify, * +* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * +* permit persons to whom the Software is furnished to do so, subject to the following * +* conditions: * +* * +* The above copyright notice and this permission notice shall be included in all copies * +* or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * +****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_EXOPLANETS___DISCOVERY_METHODS___H__ +#define __OPENSPACE_MODULE_EXOPLANETS___DISCOVERY_METHODS___H__ + +#include +#include + + +namespace openspace::exoplanets { + +class DiscoveryMethods : public properties::PropertyOwner { +public: + DiscoveryMethods(); + +private: + properties::BoolProperty _showTransit; + properties::BoolProperty _showDoppler; + +}; + +} // namespace + +#endif // __OPENSPACE_MODULE_EXOPLANETS___TRANSIT_METHOD___H__ diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 5808060f38..68ea65d4e2 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -70,6 +70,11 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { ghoul_assert(fTask, "No task factory existed"); fTask->registerClass("ExoplanetsCsvToBinTask"); fRenderable->registerClass("RenderableOrbitdisc"); + + OsEng.registerModuleCallback(OpenSpaceEngine::CallbackOption::Initialize, [&] { + _discoveryMethods = std::make_unique(); + addPropertySubOwner(*_discoveryMethods); + }); } std::vector ExoplanetsModule::documentations() const { diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index 2499124237..8564079266 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -25,9 +25,13 @@ #ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ + + #include #include +#include + namespace openspace { class ExoplanetsModule : public OpenSpaceModule { @@ -43,6 +47,7 @@ public: protected: void internalInitialize(const ghoul::Dictionary&) override; + std::unique_ptr _discoveryMethods; }; From 33f8d30bde46fb8e6fdc992ed76ac3fdbb0d0aa8 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 4 Jun 2018 13:18:45 -0400 Subject: [PATCH 030/123] Start of discovery method visualization components --- .../discoverymethods/discoverymethods.cpp | 102 ++++++++- .../discoverymethods/discoverymethods.h | 9 + modules/exoplanets/exoplanetsmodule.cpp | 18 +- modules/exoplanets/exoplanetsmodule.h | 51 +++++ modules/exoplanets/exoplanetsmodule_lua.inl | 213 +++++++++--------- 5 files changed, 287 insertions(+), 106 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 1a41cff022..a94d2a6325 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -28,7 +28,10 @@ #include #include #include +#include #include +#include +#include namespace { constexpr const char* _loggerCat = "DiscoveryMethods"; @@ -48,6 +51,70 @@ namespace { namespace openspace::exoplanets{ + void DiscoveryMethods::addTransitMethodVisualization() { + + LINFO("addTransit"); + std::string starName = OsEng.moduleEngine().module()->getStarName(); + scaleStar(starName, 1.5); + moveCamera(); + } + void DiscoveryMethods::removeTransitMethodVisualization() { + + std::string starName = OsEng.moduleEngine().module()->getStarName(); + scaleStar(starName, 1.0); + } + + void DiscoveryMethods::addDopplerMethodVisualization() { + + std::string starName = OsEng.moduleEngine().module()->getStarName(); + float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + float starSemiMajorAxis = 0.1 * planetSemiMajorAxis * 149597871; // 10% of exoplanets semiMajorAxis (get value from em) + moveStar(starName, starSemiMajorAxis); + } + + void DiscoveryMethods::removeDopplerMethodVisualization() { + + } + + void DiscoveryMethods::scaleStar(std::string starName, float scalefactor) { + std::string script = "openspace.setPropertyValue( 'Scene."+starName+"Globe.Scale.Scale', " + std::to_string(scalefactor) + ", 1, 'single', 'linear');"; //get name of current star from em + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + + void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { + std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; //get name of current star from em + script += "openspace.setPropertyValueSingle( 'Scene." + starName + "Globe.Translation.MeanAnomaly', 180, 1);"; //get name of current star from em + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + + void DiscoveryMethods::moveCamera() { + //glm::dvec3 originalPosition = _camera->positionVec3(); + Camera* cam = OsEng.navigationHandler().camera(); + glm::dvec3 originalPosition = cam->positionVec3(); + + SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); + std::string id = focusNode->identifier(); + glm::dvec3 starPosition = focusNode->worldPosition(); + + // get the vector between star and the sun + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); + + // a position along that vector (twice the semimajor axis away from the sun) + float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * starToSunVec); + + //move camera to that pos + cam->setPositionVec3(newCameraPosition); + OsEng.navigationHandler().resetCameraDirection(); + + } + DiscoveryMethods::DiscoveryMethods() : PropertyOwner({ "DiscoveryMethods" }) , _showTransit(TransitMethodInfo, false) @@ -55,8 +122,39 @@ namespace openspace::exoplanets{ { addProperty(_showTransit); addProperty(_showDoppler); - _showTransit.onChange([&]() { LINFO("transit"); }); - _showDoppler.onChange([&]() { LINFO("doppler"); }); + _showTransit.onChange([&]() { + if (_showTransit) //just changed to true + { + if (_showDoppler) //only one viz at the time + { + _showDoppler = false; + removeDopplerMethodVisualization(); + } + + addTransitMethodVisualization(); + } + else //just changed to false + { + removeTransitMethodVisualization(); + } + + }); + _showDoppler.onChange([&]() { + if (_showDoppler) //just changed to true + { + if (_showTransit) + { + _showTransit = false; + removeTransitMethodVisualization(); + } + addDopplerMethodVisualization(); + } + else //just changed to false + { + removeDopplerMethodVisualization(); + } + + }); } } // namespce diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index 36ebdb0f52..b368c036c1 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -39,6 +39,15 @@ private: properties::BoolProperty _showTransit; properties::BoolProperty _showDoppler; + void addTransitMethodVisualization(); + void removeTransitMethodVisualization(); + void addDopplerMethodVisualization(); + void removeDopplerMethodVisualization(); + + void scaleStar(std::string, float); + void moveStar(std::string, float); + void moveCamera(); + }; } // namespace diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 68ea65d4e2..ee3c8c8ecf 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -38,6 +38,22 @@ using namespace exoplanets; ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} +void ExoplanetsModule::setClosestExoplanet(Exoplanet closestExo) { + _exo = closestExo; +} + +Exoplanet ExoplanetsModule::getClosestExoplanet() { + return _exo; +} + +void ExoplanetsModule::setStarName(std::string starName) { + _starName = starName; +} + +std::string ExoplanetsModule::getStarName() { + return _starName; +} + scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { scripting::LuaLibrary res; @@ -64,7 +80,7 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { } void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { - + auto fTask = FactoryManager::ref().factory(); auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fTask, "No task factory existed"); diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index 8564079266..e7cd06b2fb 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -33,6 +33,50 @@ #include namespace openspace { + struct Exoplanet { + float A; + double AUPPER; + double ALOWER; + double UA; + float BIGOM; + float BIGOMUPPER; + float BIGOMLOWER; + float UBIGOM; + bool BINARY; + float BMV; + float ECC; + float ECCUPPER; + float ECCLOWER; + float UECC; + float I; + float IUPPER; + float ILOWER; + float UI; + int NCOMP; + float OM; + float OMUPPER; + float OMLOWER; + float UOM; + double PER; + float PERUPPER; + float PERLOWER; + float UPER; + double R; + double RUPPER; + double RLOWER; + double UR; + float RSTAR; + float RSTARUPPER; + float RSTARLOWER; + float URSTAR; + double TT; + float TTUPPER; + float TTLOWER; + float UTT; + float POSITIONX; + float POSITIONY; + float POSITIONZ; + }; class ExoplanetsModule : public OpenSpaceModule { public: @@ -45,10 +89,17 @@ public: std::vector documentations() const override; + void setClosestExoplanet(Exoplanet); + Exoplanet getClosestExoplanet(); + void setStarName(std::string); + std::string getStarName(); + protected: void internalInitialize(const ghoul::Dictionary&) override; std::unique_ptr _discoveryMethods; + Exoplanet _exo; + std::string _starName; }; } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 1fb6cc15a5..88f95bb107 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -23,6 +23,7 @@ ****************************************************************************************/ #include +#include #include #include @@ -32,51 +33,6 @@ namespace openspace{ -struct Exoplanet { - float A; - double AUPPER; - double ALOWER; - double UA; - float BIGOM; - float BIGOMUPPER; - float BIGOMLOWER; - float UBIGOM; - bool BINARY; - float BMV; - float ECC; - float ECCUPPER; - float ECCLOWER; - float UECC; - float I; - float IUPPER; - float ILOWER; - float UI; - int NCOMP; - float OM; - float OMUPPER; - float OMLOWER; - float UOM; - double PER; - float PERUPPER; - float PERLOWER; - float UPER; - double R; - double RUPPER; - double RLOWER; - double UR; - float RSTAR; - float RSTARUPPER; - float RSTARLOWER; - float URSTAR; - double TT; - float TTUPPER; - float TTLOWER; - float UTT; - float POSITIONX; - float POSITIONY; - float POSITIONZ; -}; - std::string getStarColor(float bv) { std::string colorString; @@ -224,6 +180,8 @@ int addExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); + OsEng.moduleEngine().module()->setStarName(starname); + //change expl-starname to exoplanet.csv-starname std::string starname_csv = getCsvStarname(starname); @@ -269,6 +227,7 @@ int addExoplanetSystem(lua_State* L) { data.close(); lut.close(); + OsEng.moduleEngine().module()->setClosestExoplanet(p); if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY { @@ -280,65 +239,113 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" + "}" "}" - "}" - "}"; + "}"; script = "openspace.addSceneGraphNode(" + starParent + ");"; if (!isnan(p.RSTAR)) { std::string color = getStarColor(p.BMV); + if (isnan(p.ECC)) + { + p.ECC = 0; + } + if (isnan(p.I)) + { + p.I = 90; + } + if (isnan(p.BIGOM)) + { + p.BIGOM = 0; + } + if (isnan(p.OM)) + { + p.OM = 90; + } + std::string sepoch_star; + if (!isnan(p.TT)) { + epoch.setTime("JD " + std::to_string(p.TT)); + sepoch_star = epoch.ISO8601(); + } + else + sepoch_star = "2009-05-19T07:11:34.080"; const std::string starGlobe = "{" "Identifier = '" + starname + "Globe'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'StarColor'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'StarColor'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Identifier = 'StarTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'," + "BlendMode = 'Color'," + "Enabled = true" + "}" + "}" + "}" "}," - "{" - "Identifier = 'StarTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'," - "BlendMode = 'Color'," - "Enabled = true" + "Transform = {" + "Scale = {" + "Type = 'StaticScale'," + "Scale = 1.0," + "}," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(p.ECC) + "," //ECC + "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(p.I) + "," //I + "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. + "}" "}" - "}" - "}" - "}," - "}"; + "}"; + + script += " openspace.addSceneGraphNode(" + starGlobe + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + script = ""; const std::string starGlare = "{" "Identifier = '" + starname + "Glare'," "Parent = '" + starname + "'," "Renderable = {" "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," "BlendMode = 'Additive'" "}" "}"; - script += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");"; + script = "openspace.addSceneGraphNode(" + starGlare + ");"; + //OsEng.scriptEngine().queueScript( + // script, + // openspace::scripting::ScriptEngine::RemoteScripting::Yes + // ); } - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + for (size_t i = 0; i < plsy.size(); i++) @@ -375,34 +382,34 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + plna[i] + "'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'ExoplanetTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," - "Enabled = true" - "}" - "}" - "}" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'ExoplanetTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" + "}" + "}" + "}" "}," "Transform = {" - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}" + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}" "}," - "}"; + "}"; script = "openspace.addSceneGraphNode(" + planet + ");"; OsEng.scriptEngine().queueScript( @@ -559,4 +566,4 @@ int removeExoplanetSystem(lua_State* L) { return 0; } -} //namespace \ No newline at end of file +} //namespace From edc330d6261629ab7a05facd23e2ee5eaf596829 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 6 Jun 2018 16:32:45 -0400 Subject: [PATCH 031/123] Adjusted the rotation of the whole exoplanetsytem according to the exoplanet definition of the inclination --- modules/exoplanets/exoplanetsmodule_lua.inl | 155 +++++++++++++------- 1 file changed, 106 insertions(+), 49 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 88f95bb107..d4e3df9f8c 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include @@ -61,23 +63,24 @@ std::string getStarColor(float bv) { return colorString; } -std::string computeRotationMatrix(float i, float bigom, float om) { - - const glm::vec3 ascendingNodeAxisRot = { 0.f, 1.f, 0.f }; +glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { + // Exoplanet defined inclination changed to be used as Kepler defined inclination + float iModified = 90.0 - i; + const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; const double asc = glm::radians(bigom); - const double inc = glm::radians(i); + const double inc = glm::radians(iModified); const double per = glm::radians(om); - glm::dmat3 orbitPlaneRotation = + glm::dmat4 orbitPlaneRotation = + glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * - glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); - return std::to_string(orbitPlaneRotation); - + return orbitPlaneRotation; + //return std::to_string(orbitPlaneRotation); } std::string getCsvStarname(std::string explName) { @@ -174,6 +177,45 @@ std::string getCsvStarname(std::string explName) { return csvName; } +// Rotate the original coordinate system (where x is pointing to First Point of Aries) +// so that x is pointing from star to the sun. +// Modified from http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-find-the-rotation-between-2-vectors- +glm::dmat3 getExoplanetSystemRotation(glm::dvec3 pos) { + + glm::quat rotInQuat; + glm::dvec3 oldXVec = glm::dvec3(1.0, 0.0, 0.0); //parent nod x-vec + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - pos); + + float cosTheta = dot(oldXVec, starToSunVec); + glm::dvec3 rotationAxis; + + if (cosTheta < -1 + 0.001f) { + // special case when vectors in opposite directions: + // there is no "ideal" rotation axis + // So guess one; any will do as long as it's perpendicular to startvector(oldXVec) + rotationAxis = cross(glm::dvec3(0.0f, 0.0f, 1.0f), oldXVec); + if (length2(rotationAxis) < 0.01) // bad luck, they were parallel, try again! + rotationAxis = cross(glm::dvec3(1.0f, 0.0f, 0.0f), oldXVec); + + rotationAxis = normalize(rotationAxis); + rotInQuat = glm::quat(glm::radians(180.0f), rotationAxis); + return glm::dmat3(toMat4(rotInQuat)); + } + + rotationAxis = cross(oldXVec, starToSunVec); + + float s = sqrt((1 + cosTheta) * 2); + float invs = 1 / s; + + rotInQuat = glm::quat( + s * 0.5f, + rotationAxis.x * invs, + rotationAxis.y * invs, + rotationAxis.z * invs + ); + + return glm::dmat3(toMat4(rotInQuat)); +} int addExoplanetSystem(lua_State* L) { @@ -218,6 +260,7 @@ int addExoplanetSystem(lua_State* L) { data.seekg(location); data.read((char*)&p, sizeof(struct Exoplanet)); + plna.push_back(planetname); plsy.push_back(p); found = true; @@ -235,18 +278,28 @@ int addExoplanetSystem(lua_State* L) { double parsec = 0.308567756E17; std::string script = ""; + glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); + + glm::dmat3 exoplanetSystemRot = getExoplanetSystemRotation(position); const std::string starParent = "{" "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(exoplanetSystemRot) + "," + "}," "Translation = {" "Type = 'StaticTranslation'," - "Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}" - "}" + "Position = " + std::to_string(position) + "," + "}," "}" "}"; script = "openspace.addSceneGraphNode(" + starParent + ");"; - + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); if (!isnan(p.RSTAR)) { std::string color = getStarColor(p.BMV); @@ -261,7 +314,7 @@ int addExoplanetSystem(lua_State* L) { } if (isnan(p.BIGOM)) { - p.BIGOM = 0; + p.BIGOM = 270; } if (isnan(p.OM)) { @@ -309,7 +362,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(p.ECC) + "," //ECC "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(p.I) + "," //I + "Inclination = 90 - " + std::to_string(p.I) + "," //I "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM "MeanAnomaly = 0.0," @@ -318,8 +371,8 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}"; - - script += " openspace.addSceneGraphNode(" + starGlobe + ");"; + script = ""; + script = " openspace.addSceneGraphNode(" + starGlobe + ");"; OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -362,7 +415,7 @@ int addExoplanetSystem(lua_State* L) { } if (isnan(plsy[i].BIGOM)) { - plsy[i].BIGOM = 0; + plsy[i].BIGOM = 270; } if (isnan(plsy[i].OM)) { @@ -376,6 +429,7 @@ int addExoplanetSystem(lua_State* L) { else sepoch = "2009-05-19T07:11:34.080"; + if (!isnan(plsy[i].R)) { const std::string planet = "{" @@ -401,13 +455,13 @@ int addExoplanetSystem(lua_State* L) { "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I + "Inclination = 90 - " + std::to_string(plsy[i].I) + "," //I "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}" + "}," "}," "}"; @@ -420,28 +474,28 @@ int addExoplanetSystem(lua_State* L) { } - + const std::string planetTrail = "{" "Identifier = '" + plna[i] + "Trail'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableTrailOrbit'," - "Period = " + std::to_string(plsy[i].PER) + "," - "Resolution = 1000," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "Type = 'RenderableTrailOrbit'," + "Period = " + std::to_string(plsy[i].PER) + "," + "Resolution = 1000," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = 90 - " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}," + "Color = { 1, 0, 0 }" "}," - "Color = { 1, 0, 0 }" - "}," - "}"; + "}"; OsEng.scriptEngine().queueScript( "openspace.addSceneGraphNode(" + planetTrail + ");", @@ -450,26 +504,29 @@ int addExoplanetSystem(lua_State* L) { if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) { - std::string rotation_matrix = computeRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); + // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation + glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); + glm::dmat4 exoplanetSystemRotInverse = transpose(exoplanetSystemRot); + glm::dmat3 rot = glm::dmat4(exoplanetSystemRot) * orbitPlaneRotationMatrix * exoplanetSystemRotInverse; const std::string disc = "{" "Identifier = '" + plna[i] + "Disc'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.99" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.99" "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + rotation_matrix + "," - "}" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(rot) + "," + "}" "}," - "}"; + "}"; OsEng.scriptEngine().queueScript( "openspace.addSceneGraphNode(" + disc + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -498,7 +555,7 @@ int addExoplanetSystem(lua_State* L) { "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + rotation_matrix + "," + "Rotation = " + std::to_string(rot) + "," "}" "}," "}"; @@ -529,7 +586,7 @@ int addExoplanetSystem(lua_State* L) { "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + rotation_matrix + "," + "Rotation = " + std::to_string(rot) + "," "}" "}," "}"; From 8cf28d530807c50dd4e06af02af8a5e0550fc8b9 Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 8 Jun 2018 12:35:09 -0400 Subject: [PATCH 032/123] Rotating the exoplanetsystem coordinates so that the reference direction is the north-celetial-pole-vector projected on the skyplane --- modules/exoplanets/exoplanetsmodule_lua.inl | 40 +++++++++++++-------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index d4e3df9f8c..165b962ad3 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -65,13 +65,13 @@ std::string getStarColor(float bv) { glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { // Exoplanet defined inclination changed to be used as Kepler defined inclination - float iModified = 90.0 - i; + const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; const double asc = glm::radians(bigom); - const double inc = glm::radians(iModified); + const double inc = glm::radians(i); const double per = glm::radians(om); glm::dmat4 orbitPlaneRotation = @@ -180,29 +180,29 @@ std::string getCsvStarname(std::string explName) { // Rotate the original coordinate system (where x is pointing to First Point of Aries) // so that x is pointing from star to the sun. // Modified from http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-find-the-rotation-between-2-vectors- -glm::dmat3 getExoplanetSystemRotation(glm::dvec3 pos) { +glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { glm::quat rotInQuat; - glm::dvec3 oldXVec = glm::dvec3(1.0, 0.0, 0.0); //parent nod x-vec - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - pos); + //glm::dvec3 oldXVec = glm::dvec3(1.0, 0.0, 0.0); //parent nod x-vec + //glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - end); - float cosTheta = dot(oldXVec, starToSunVec); + float cosTheta = dot(start, end); glm::dvec3 rotationAxis; if (cosTheta < -1 + 0.001f) { // special case when vectors in opposite directions: // there is no "ideal" rotation axis // So guess one; any will do as long as it's perpendicular to startvector(oldXVec) - rotationAxis = cross(glm::dvec3(0.0f, 0.0f, 1.0f), oldXVec); + rotationAxis = cross(glm::dvec3(0.0f, 0.0f, 1.0f), start); if (length2(rotationAxis) < 0.01) // bad luck, they were parallel, try again! - rotationAxis = cross(glm::dvec3(1.0f, 0.0f, 0.0f), oldXVec); + rotationAxis = cross(glm::dvec3(1.0f, 0.0f, 0.0f), start); rotationAxis = normalize(rotationAxis); rotInQuat = glm::quat(glm::radians(180.0f), rotationAxis); return glm::dmat3(toMat4(rotInQuat)); } - rotationAxis = cross(oldXVec, starToSunVec); + rotationAxis = cross(start, end); float s = sqrt((1 + cosTheta) * 2); float invs = 1 / s; @@ -280,7 +280,17 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); - glm::dmat3 exoplanetSystemRot = getExoplanetSystemRotation(position); + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - position); + glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + // Earths north vector (0,0,1) projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) + glm::dvec3 northProjected = normalize(glm::length(north)*glm::sin(dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); + + glm::dmat3 firstRotation = getExoplanetSystemRotation(glm::dvec3(0.0,0.0,1.0), starToSunVec); + glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0) ; + glm::dmat3 secondRotation = getExoplanetSystemRotation(newX, northProjected); + + glm::dmat3 exoplanetSystemRot = firstRotation; //secondRotation * + const std::string starParent = "{" "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," @@ -314,7 +324,7 @@ int addExoplanetSystem(lua_State* L) { } if (isnan(p.BIGOM)) { - p.BIGOM = 270; + p.BIGOM = 0; } if (isnan(p.OM)) { @@ -362,7 +372,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(p.ECC) + "," //ECC "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A - "Inclination = 90 - " + std::to_string(p.I) + "," //I + "Inclination = " + std::to_string(p.I) + "," //I "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM "MeanAnomaly = 0.0," @@ -415,7 +425,7 @@ int addExoplanetSystem(lua_State* L) { } if (isnan(plsy[i].BIGOM)) { - plsy[i].BIGOM = 270; + plsy[i].BIGOM = 0; } if (isnan(plsy[i].OM)) { @@ -455,7 +465,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = 90 - " + std::to_string(plsy[i].I) + "," //I + "Inclination = " + std::to_string(plsy[i].I) + "," //I "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM "MeanAnomaly = 0.0," @@ -486,7 +496,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = 90 - " + std::to_string(plsy[i].I) + "," //I + "Inclination = " + std::to_string(plsy[i].I) + "," //I "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM "MeanAnomaly = 0.0," From 9d7b0fad17a4c421c29cbc5b8be508153fdf6648 Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 8 Jun 2018 13:25:45 -0400 Subject: [PATCH 033/123] correction to the rotation --- modules/exoplanets/exoplanetsmodule_lua.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 165b962ad3..a26eed0ce2 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -289,7 +289,7 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0) ; glm::dmat3 secondRotation = getExoplanetSystemRotation(newX, northProjected); - glm::dmat3 exoplanetSystemRot = firstRotation; //secondRotation * + glm::dmat3 exoplanetSystemRot = secondRotation * firstRotation; const std::string starParent = "{" "Identifier = '" + starname + "'," From 9a320ad02b6370d5c267d6ab673d69f9f3043361 Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 8 Jun 2018 15:44:47 -0400 Subject: [PATCH 034/123] More features to discovery method vizualisation, like face on camera setting and adjustment to scaling --- .../discoverymethods/discoverymethods.cpp | 72 +++++++++++++++---- .../discoverymethods/discoverymethods.h | 3 +- modules/exoplanets/exoplanetsmodule_lua.inl | 6 +- 3 files changed, 65 insertions(+), 16 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index a94d2a6325..8fc3649195 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -52,16 +52,31 @@ namespace { namespace openspace::exoplanets{ void DiscoveryMethods::addTransitMethodVisualization() { - - LINFO("addTransit"); + std::string starName = OsEng.moduleEngine().module()->getStarName(); - scaleStar(starName, 1.5); - moveCamera(); + float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; // AU + float eccentricity = (OsEng.moduleEngine().module()->getClosestExoplanet()).ECC; + float starRadius = (OsEng.moduleEngine().module()->getClosestExoplanet()).RSTAR; // Solar Radii + + // periapsis radius + float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); + // to km + periapsisRadius *= 149597871; + starRadius *= 695700; + + // increase star radius to two thirds of periapsis radius + float scaleFactor = (0.666 * periapsisRadius) / starRadius; + std::string planetName = starName + " b"; + scaleStar(starName +"Globe", scaleFactor); + scaleStar(planetName, scaleFactor); + moveCameraTransitView(); } void DiscoveryMethods::removeTransitMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); - scaleStar(starName, 1.0); + std::string planetName = starName + " b"; + scaleStar(starName + "Globe", 1); + scaleStar(planetName, 1); } void DiscoveryMethods::addDopplerMethodVisualization() { @@ -69,15 +84,28 @@ namespace openspace::exoplanets{ std::string starName = OsEng.moduleEngine().module()->getStarName(); float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; float starSemiMajorAxis = 0.1 * planetSemiMajorAxis * 149597871; // 10% of exoplanets semiMajorAxis (get value from em) + float eccentricity = (OsEng.moduleEngine().module()->getClosestExoplanet()).ECC; + float starRadius = (OsEng.moduleEngine().module()->getClosestExoplanet()).RSTAR; // Solar Radii + + float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); + // to km + periapsisRadius *= 149597871; + starRadius *= 695700; + float scaleFactor = (0.1 * periapsisRadius) / starRadius; + + moveCameraDopplerView(); + scaleStar(starName + "Globe", scaleFactor); moveStar(starName, starSemiMajorAxis); } void DiscoveryMethods::removeDopplerMethodVisualization() { - + std::string starName = OsEng.moduleEngine().module()->getStarName(); + scaleStar(starName + "Globe", 1.0); + moveStar(starName, 0.0); } - void DiscoveryMethods::scaleStar(std::string starName, float scalefactor) { - std::string script = "openspace.setPropertyValue( 'Scene."+starName+"Globe.Scale.Scale', " + std::to_string(scalefactor) + ", 1, 'single', 'linear');"; //get name of current star from em + void DiscoveryMethods::scaleStar(std::string nodeName, float scalefactor) { + std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -86,22 +114,18 @@ namespace openspace::exoplanets{ void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; //get name of current star from em - script += "openspace.setPropertyValueSingle( 'Scene." + starName + "Globe.Translation.MeanAnomaly', 180, 1);"; //get name of current star from em OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - void DiscoveryMethods::moveCamera() { - //glm::dvec3 originalPosition = _camera->positionVec3(); + void DiscoveryMethods::moveCameraTransitView() { + Camera* cam = OsEng.navigationHandler().camera(); - glm::dvec3 originalPosition = cam->positionVec3(); SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); - std::string id = focusNode->identifier(); glm::dvec3 starPosition = focusNode->worldPosition(); - // get the vector between star and the sun glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); @@ -113,6 +137,26 @@ namespace openspace::exoplanets{ cam->setPositionVec3(newCameraPosition); OsEng.navigationHandler().resetCameraDirection(); + } + + void DiscoveryMethods::moveCameraDopplerView() { + + Camera* cam = OsEng.navigationHandler().camera(); + + SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); + glm::dvec3 starPosition = focusNode->worldPosition(); + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); + glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); + glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, northProjected)); + // a position along that vector (twice the semimajor axis away from the sun) + float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * faceOnVector); + + //move camera to that pos + cam->setPositionVec3(newCameraPosition); + OsEng.navigationHandler().resetCameraDirection(); + } DiscoveryMethods::DiscoveryMethods() diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index b368c036c1..18e2b516cf 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -46,7 +46,8 @@ private: void scaleStar(std::string, float); void moveStar(std::string, float); - void moveCamera(); + void moveCameraTransitView(); + void moveCameraDopplerView(); }; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index a26eed0ce2..b511d39bf2 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -375,7 +375,7 @@ int addExoplanetSystem(lua_State* L) { "Inclination = " + std::to_string(p.I) + "," //I "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM - "MeanAnomaly = 0.0," + "MeanAnomaly = 180.0," "Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. "}" @@ -461,6 +461,10 @@ int addExoplanetSystem(lua_State* L) { "}" "}," "Transform = {" + "Scale = {" + "Type = 'StaticScale'," + "Scale = 1.0," + "}," "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC From 7940fbc86efa7bf2f98beaeabb4ba81a609ed329 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 13 Jun 2018 15:53:22 -0400 Subject: [PATCH 035/123] Hides all planets but one for the doppler method visualisation. --- .../discoverymethods/discoverymethods.cpp | 48 +++++-- .../discoverymethods/discoverymethods.h | 1 + modules/exoplanets/exoplanetsmodule.cpp | 12 ++ modules/exoplanets/exoplanetsmodule.h | 6 + modules/exoplanets/exoplanetsmodule_lua.inl | 119 ++++++++++-------- 5 files changed, 124 insertions(+), 62 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 8fc3649195..5be5117a91 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -54,9 +54,10 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addTransitMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); - float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; // AU - float eccentricity = (OsEng.moduleEngine().module()->getClosestExoplanet()).ECC; - float starRadius = (OsEng.moduleEngine().module()->getClosestExoplanet()).RSTAR; // Solar Radii + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + float planetSemiMajorAxis = planets[0].A; // AU + float eccentricity = planets[0].ECC; + float starRadius = planets[0].RSTAR; // Solar Radii // periapsis radius float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); @@ -82,10 +83,12 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addDopplerMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); - float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + //float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + float planetSemiMajorAxis = planets[0].A; float starSemiMajorAxis = 0.1 * planetSemiMajorAxis * 149597871; // 10% of exoplanets semiMajorAxis (get value from em) - float eccentricity = (OsEng.moduleEngine().module()->getClosestExoplanet()).ECC; - float starRadius = (OsEng.moduleEngine().module()->getClosestExoplanet()).RSTAR; // Solar Radii + float eccentricity = planets[0].ECC; + float starRadius = planets[0].RSTAR; // Solar Radii float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); // to km @@ -96,12 +99,14 @@ namespace openspace::exoplanets{ moveCameraDopplerView(); scaleStar(starName + "Globe", scaleFactor); moveStar(starName, starSemiMajorAxis); + toggleVisabilityOuterPlanets("false"); } void DiscoveryMethods::removeDopplerMethodVisualization() { std::string starName = OsEng.moduleEngine().module()->getStarName(); scaleStar(starName + "Globe", 1.0); moveStar(starName, 0.0); + toggleVisabilityOuterPlanets("true"); } void DiscoveryMethods::scaleStar(std::string nodeName, float scalefactor) { @@ -138,6 +143,30 @@ namespace openspace::exoplanets{ OsEng.navigationHandler().resetCameraDirection(); } + + void DiscoveryMethods::toggleVisabilityOuterPlanets(std::string visability) { + //std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + + if (planetNames.size()>1) + { + //keeping first planet in the list, wich dosn't neccesarily mean the closest one... + for (size_t i = 1; i < planetNames.size(); i++) { + std::string script = ""; + //remove planetglobe + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".renderable.Enabled', "+visability+"); "; + //remove trail + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; + //remove disc + script += "openspace.setPropertyValueSingle( 'Scene."+planetNames[i]+"Disc.renderable.Enabled', " + visability + "); "; + + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } + } void DiscoveryMethods::moveCameraDopplerView() { @@ -149,8 +178,10 @@ namespace openspace::exoplanets{ glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, northProjected)); - // a position along that vector (twice the semimajor axis away from the sun) - float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + // a position along that vector (3x the semimajor axis away from the star) + //float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + float semiMajorAxis = planets[0].A; glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * faceOnVector); //move camera to that pos @@ -199,6 +230,7 @@ namespace openspace::exoplanets{ } }); + } } // namespce diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index 18e2b516cf..c340c62e3a 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -48,6 +48,7 @@ private: void moveStar(std::string, float); void moveCameraTransitView(); void moveCameraDopplerView(); + void toggleVisabilityOuterPlanets(std::string); }; diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index ee3c8c8ecf..0f60d9a86a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -53,6 +53,18 @@ void ExoplanetsModule::setStarName(std::string starName) { std::string ExoplanetsModule::getStarName() { return _starName; } +void ExoplanetsModule::setPlsy(std::vector plsy) { + _plsy = plsy; +} +std::vector ExoplanetsModule::getPlsy() { + return _plsy; +} +void ExoplanetsModule::setPlna(std::vector plna) { + _plna = plna; +} +std::vector ExoplanetsModule::getPlna() { + return _plna; +} scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index e7cd06b2fb..a473ccfc0b 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -93,6 +93,10 @@ public: Exoplanet getClosestExoplanet(); void setStarName(std::string); std::string getStarName(); + void setPlsy(std::vector); + std::vector getPlsy(); + void setPlna(std::vector); + std::vector getPlna(); protected: void internalInitialize(const ghoul::Dictionary&) override; @@ -100,6 +104,8 @@ protected: Exoplanet _exo; std::string _starName; + std::vector _plsy; + std::vector _plna; }; } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index b511d39bf2..2f5532f5ef 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -63,12 +63,16 @@ std::string getStarColor(float bv) { return colorString; } -glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { +glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om, glm::dmat3 rot) { // Exoplanet defined inclination changed to be used as Kepler defined inclination - const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; - const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; - const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f }; + const glm::dvec3 ascendingNodeAxisRot = rot * glm::dvec3(0.f, 0.f, 1.f); + const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); + const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); + + /*const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; + const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; + const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f };*/ const double asc = glm::radians(bigom); const double inc = glm::radians(i); @@ -267,9 +271,11 @@ int addExoplanetSystem(lua_State* L) { } } + data.close(); lut.close(); - + OsEng.moduleEngine().module()->setPlna(plna); + OsEng.moduleEngine().module()->setPlsy(plsy); OsEng.moduleEngine().module()->setClosestExoplanet(p); if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY @@ -281,12 +287,14 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - position); - glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + glm::dvec3 northEclipticPole = glm::dvec3(0.0, 0.0, 1.0); // , 1.0); + //glm::dvec3 northCelectialPole = northEclipticPole * glm::rotate(glm::radians(336.6), glm::dvec3(1.f, 0.f, 0.f)); + printf(std::to_string(northEclipticPole).c_str()); // Earths north vector (0,0,1) projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) - glm::dvec3 northProjected = normalize(glm::length(north)*glm::sin(dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); - + glm::dvec3 northProjected = normalize(glm::length(northEclipticPole)*glm::sin(dot(northEclipticPole, starToSunVec)) * glm::cross(starToSunVec, glm::cross(northEclipticPole, starToSunVec))); + printf(std::to_string(northProjected).c_str()); glm::dmat3 firstRotation = getExoplanetSystemRotation(glm::dvec3(0.0,0.0,1.0), starToSunVec); - glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0) ; + glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0); glm::dmat3 secondRotation = getExoplanetSystemRotation(newX, northProjected); glm::dmat3 exoplanetSystemRot = secondRotation * firstRotation; @@ -295,9 +303,9 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(exoplanetSystemRot) + "," + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(exoplanetSystemRot) + "," "}," "Translation = {" "Type = 'StaticTranslation'," @@ -305,6 +313,7 @@ int addExoplanetSystem(lua_State* L) { "}," "}" "}"; + script = "openspace.addSceneGraphNode(" + starParent + ");"; OsEng.scriptEngine().queueScript( script, @@ -314,25 +323,25 @@ int addExoplanetSystem(lua_State* L) { { std::string color = getStarColor(p.BMV); - if (isnan(p.ECC)) + if (isnan(plsy[0].ECC)) { - p.ECC = 0; + plsy[0].ECC = 0; } - if (isnan(p.I)) + if (isnan(plsy[0].I)) { - p.I = 90; + plsy[0].I = 90; } - if (isnan(p.BIGOM)) + if (isnan(plsy[0].BIGOM)) { - p.BIGOM = 0; + plsy[0].BIGOM = 0; } - if (isnan(p.OM)) + if (isnan(plsy[0].OM)) { - p.OM = 90; + plsy[0].OM = 90; } std::string sepoch_star; - if (!isnan(p.TT)) { - epoch.setTime("JD " + std::to_string(p.TT)); + if (!isnan(plsy[0].TT)) { + epoch.setTime("JD " + std::to_string(plsy[0].TT)); sepoch_star = epoch.ISO8601(); } else @@ -370,14 +379,14 @@ int addExoplanetSystem(lua_State* L) { "}," "Translation = {" "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(p.ECC) + "," //ECC + "Eccentricity = " + std::to_string(plsy[0].ECC) + "," //ECC "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(p.I) + "," //I - "AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM + "Inclination = " + std::to_string(plsy[0].I) + "," //I + "AscendingNode = " + std::to_string(plsy[0].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[0].OM) + "," //OM "MeanAnomaly = 180.0," "Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day. + "Period = " + std::to_string(plsy[0].PER) + "* 86400" //PER. 86 400sec = 1 day. "}" "}" "}"; @@ -445,6 +454,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planet = "{" "Identifier = '" + plna[i] + "'," "Parent = '" + starname + "'," + "Enabled = true," "Renderable = {" "Type = 'RenderableGlobe'," "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m @@ -492,6 +502,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planetTrail = "{" "Identifier = '" + plna[i] + "Trail'," "Parent = '" + starname + "'," + "Enabled = true," "Renderable = {" "Type = 'RenderableTrailOrbit'," "Period = " + std::to_string(plsy[i].PER) + "," @@ -519,13 +530,13 @@ int addExoplanetSystem(lua_State* L) { if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation - glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); - glm::dmat4 exoplanetSystemRotInverse = transpose(exoplanetSystemRot); - glm::dmat3 rot = glm::dmat4(exoplanetSystemRot) * orbitPlaneRotationMatrix * exoplanetSystemRotInverse; + glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); + glm::dmat3 rot = orbitPlaneRotationMatrix; const std::string disc = "{" "Identifier = '" + plna[i] + "Disc'," "Parent = '" + starname + "'," + "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," @@ -558,21 +569,21 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + plna[i] + "discECCLOWER'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(lower_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(lower_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," - "}" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(rot) + "," + "}" "}," - "}"; + "}"; OsEng.scriptEngine().queueScript( @@ -589,21 +600,21 @@ int addExoplanetSystem(lua_State* L) { "Identifier = '" + plna[i] + "discECCUPPER'," "Parent = '" + starname + "'," "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(upper_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" + "Type = 'RenderableOrbitdisc'," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(upper_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," - "}" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(rot) + "," + "}" "}," - "}"; + "}"; OsEng.scriptEngine().queueScript( From fa79cac63e76bf3bffb9cbd16f0fa38785da5702 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 20 Jun 2018 17:22:46 -0400 Subject: [PATCH 036/123] Discovery method viz updates on a bit of everything --- .../discoverymethods/discoverymethods.cpp | 393 +++++++++++++----- .../discoverymethods/discoverymethods.h | 18 +- modules/exoplanets/exoplanetsmodule.cpp | 50 +++ modules/exoplanets/exoplanetsmodule_lua.inl | 25 +- 4 files changed, 377 insertions(+), 109 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 5be5117a91..ec671b2273 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -32,6 +32,9 @@ #include #include #include +#include +#include +#include namespace { constexpr const char* _loggerCat = "DiscoveryMethods"; @@ -51,65 +54,115 @@ namespace { namespace openspace::exoplanets{ - void DiscoveryMethods::addTransitMethodVisualization() { - - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - float planetSemiMajorAxis = planets[0].A; // AU - float eccentricity = planets[0].ECC; - float starRadius = planets[0].RSTAR; // Solar Radii + void DiscoveryMethods::addDirectionsMarkers(glm::dvec3 viewDirecionPos, glm::dvec3 northDirectionPos, float starRadius) { - // periapsis radius - float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); - // to km - periapsisRadius *= 149597871; - starRadius *= 695700; - - // increase star radius to two thirds of periapsis radius - float scaleFactor = (0.666 * periapsisRadius) / starRadius; - std::string planetName = starName + " b"; - scaleStar(starName +"Globe", scaleFactor); - scaleStar(planetName, scaleFactor); - moveCameraTransitView(); + const std::string markerView = "{" + "Identifier = 'markerView'," + "Parent = 'SolarSystemBarycenter'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(starRadius) + "* 0.5," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'dir'," + "Type = 'SolidColor'," + "BlendMode = 'Normal'," + "Color = {1.0,0.0,0.0}," + "Enabled = true" + "}," + "}" + "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + std::to_string(viewDirecionPos) + "," + "}," + "}," + "}"; + std::string script = "openspace.addSceneGraphNode(" + markerView + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + const std::string markerNorth = "{" + "Identifier = 'markerNorth'," + "Parent = 'SolarSystemBarycenter'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(starRadius) + "* 0.5," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'dir'," + "Type = 'SolidColor'," + "BlendMode = 'Normal'," + "Color = {0.0,0.0,1.0}," + "Enabled = true" + "}," + "}" + "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + std::to_string(northDirectionPos) + "," + "}," + "}," + "}"; + script = ""; + script = "openspace.addSceneGraphNode(" + markerNorth + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); } - void DiscoveryMethods::removeTransitMethodVisualization() { - - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::string planetName = starName + " b"; - scaleStar(starName + "Globe", 1); - scaleStar(planetName, 1); + void DiscoveryMethods::removeDirectionsMarkers() { + std::string script = "openspace.removeSceneGraphNode('markerView'); openspace.removeSceneGraphNode('markerNorth');"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); } - void DiscoveryMethods::addDopplerMethodVisualization() { - - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - //float planetSemiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; - float planetSemiMajorAxis = planets[0].A; - float starSemiMajorAxis = 0.1 * planetSemiMajorAxis * 149597871; // 10% of exoplanets semiMajorAxis (get value from em) - float eccentricity = planets[0].ECC; - float starRadius = planets[0].RSTAR; // Solar Radii - - float periapsisRadius = planetSemiMajorAxis * (1.0 - eccentricity); - // to km - periapsisRadius *= 149597871; - starRadius *= 695700; - float scaleFactor = (0.1 * periapsisRadius) / starRadius; - - moveCameraDopplerView(); - scaleStar(starName + "Globe", scaleFactor); - moveStar(starName, starSemiMajorAxis); - toggleVisabilityOuterPlanets("false"); + float DiscoveryMethods::getTransitScaleFactor() { + return _transitScaleFactor; } - void DiscoveryMethods::removeDopplerMethodVisualization() { - std::string starName = OsEng.moduleEngine().module()->getStarName(); - scaleStar(starName + "Globe", 1.0); - moveStar(starName, 0.0); - toggleVisabilityOuterPlanets("true"); + void addDopplerGraphs() { + std::string script = "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'DopplerShift2'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/stripes2.png')," + "EuclideanPosition = {0.0, -0.7}" + "}" + ");" + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'DopplerShift1'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/spectrum.jpg')," + "EuclideanPosition = {0.0, -0.7}" + "}" + ");"; + + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); } - void DiscoveryMethods::scaleStar(std::string nodeName, float scalefactor) { + + + void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em OsEng.scriptEngine().queueScript( script, @@ -118,85 +171,228 @@ namespace openspace::exoplanets{ } void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { - std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; //get name of current star from em + std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - void DiscoveryMethods::moveCameraTransitView() { - - Camera* cam = OsEng.navigationHandler().camera(); - - SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); - glm::dvec3 starPosition = focusNode->worldPosition(); - // get the vector between star and the sun - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - - // a position along that vector (twice the semimajor axis away from the sun) - float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; - glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * starToSunVec); - - //move camera to that pos - cam->setPositionVec3(newCameraPosition); - OsEng.navigationHandler().resetCameraDirection(); - - } - - void DiscoveryMethods::toggleVisabilityOuterPlanets(std::string visability) { - //std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + void DiscoveryMethods::toggleVisabilityOuterPlanets(std::vector planetNames, std::string visability) { + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + //std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); if (planetNames.size()>1) { //keeping first planet in the list, wich dosn't neccesarily mean the closest one... for (size_t i = 1; i < planetNames.size(); i++) { + std::string script = ""; //remove planetglobe - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".renderable.Enabled', "+visability+"); "; + if (!isnan(planets[i].R)) { + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".renderable.Enabled', " + visability + "); "; + } //remove trail script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; //remove disc - script += "openspace.setPropertyValueSingle( 'Scene."+planetNames[i]+"Disc.renderable.Enabled', " + visability + "); "; - + if (!isnan(planets[i].AUPPER) && !isnan(planets[i].ALOWER)) { + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Disc.renderable.Enabled', " + visability + "); "; + } + OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - } + } + } + + void DiscoveryMethods::toggleVisabilityPlanet(std::string nodeName, std::string visability) { + std::string script = "openspace.setPropertyValueSingle( 'Scene." +nodeName + ".RenderableGlobe.Enabled', " + visability + "); "; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); } - void DiscoveryMethods::moveCameraDopplerView() { + void DiscoveryMethods::moveCameraDopplerView(glm::dvec3 pos) { Camera* cam = OsEng.navigationHandler().camera(); - - SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); - glm::dvec3 starPosition = focusNode->worldPosition(); - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); - glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); - glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, northProjected)); - // a position along that vector (3x the semimajor axis away from the star) - //float semiMajorAxis = (OsEng.moduleEngine().module()->getClosestExoplanet()).A; - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - float semiMajorAxis = planets[0].A; - glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * faceOnVector); - - //move camera to that pos - cam->setPositionVec3(newCameraPosition); + cam->setPositionVec3(pos); OsEng.navigationHandler().resetCameraDirection(); } + void DiscoveryMethods::moveCameraTransitView(glm::dvec3 pos) { + + Camera* cam = OsEng.navigationHandler().camera(); + cam->setPositionVec3(pos); + OsEng.navigationHandler().resetCameraDirection(); + + } + + bool DiscoveryMethods::isDoppler() { + return _showDoppler; + } + bool DiscoveryMethods::isTransit() { + return _showTransit; + } + void DiscoveryMethods::setDopplerImagePos(float value) { + std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; //get name of current star from em + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + + void DiscoveryMethods::addDopplerMethodVisualization() { + SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); + std::string starName = OsEng.moduleEngine().module()->getStarName(); // getStarName + glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + + float semiMajorAxis = planets[0].A; // in AU + float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis + float eccentricity = planets[0].ECC; + float starRadius = planets[0].RSTAR; // in Solar Radii + + glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + //glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); + glm::dvec3 northProjected = normalize(north - (((dot(north, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); + + // MOVE CAMERA + glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, northProjected)); + glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * faceOnVector); + moveCameraDopplerView(cameraPosition); + // END CAMERA + + // SCALE STAR AND PLANET + float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU + periapsisDistance *= 149597870700.0; // in m + starRadius *= 6.957E8; // in m + float scale = (0.1 * periapsisDistance) / starRadius; + scaleNode(starName + "Globe", scale); + scaleNode(planetNames[0], scale); // using planetNames[0] because i know that will be the one visible after removing outer planets + // END SCALE + + // MOVE STAR + starSemiMajorAxis *= 149597871.0; // in km + moveStar(starName, starSemiMajorAxis); + + // SHOW ONE PLANET + // for planets found with doppler method, the radius is not always known. + //so this "fake" planet is shown for the sake of the vizualisation + toggleVisabilityPlanet(planetNames[0], "true"); + + // HIDE THE REST OF THE PLANETS + // in some cases there are multiple planets in the system, but for the viz only one can be shown + toggleVisabilityOuterPlanets(planetNames, "false"); + + // SHOW GRAPHS + addDopplerGraphs(); + + + // HELPER MARKERS + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * northProjected); + glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); + addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); + // END MARKERS + + } + + void DiscoveryMethods::removeDopplerMethodVisualization() { + std::string starName = OsEng.moduleEngine().module()->getStarName(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + + //SCALE STAR AND PLANET + scaleNode(starName + "Globe", 1.0); + scaleNode(planetNames[0], 1.0); + + // MOVE STAR + moveStar(starName, 0.0); + + //HIDE THE PLANET (if it was hidden from the start) + if (isnan(planets[0].R)) { + toggleVisabilityPlanet(planetNames[0], "false"); + } + + // SHOW THE REST OF THE PLANETS + toggleVisabilityOuterPlanets(planetNames, "true"); + + // HIDE GRAPHS + std::string script = "openspace.removeScreenSpaceRenderable('DopplerShift1'); openspace.removeScreenSpaceRenderable('DopplerShift2');"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + //REMOVE HELP MARKERS + removeDirectionsMarkers(); + } + + void DiscoveryMethods::addTransitMethodVisualization() { + + SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); + std::string starName = OsEng.moduleEngine().module()->getStarName(); // getStarName + glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + + float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) + float eccentricity = planets[0].ECC; + float starRadius = planets[0].RSTAR; // in Solar Radii + + // MOVE CAMERA + //borde kanske va periapsis distance, men det gÃ¥r bra ändÃ¥ + glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * starToSunVec);; + moveCameraTransitView(cameraPosition); + // END CAMERA + toggleVisabilityPlanet(planetNames[0], "true"); + + // SCALE BOTH STAR AND PLANET + // want star to take up 2/3 of the radius, the radius is as smallest at the periapsis + float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU + periapsisDistance *= 149597870700.0; // in m + starRadius *= 6.957E8; // in m + + float scale = (0.666 * periapsisDistance) / starRadius; // actual radius * scale = wanted radius + scaleNode(starName + "Globe", scale); + scaleNode(planetNames[0], scale); //eller använda getPlna()? + _transitScaleFactor = scale; + // END SCALE + + // HELPER MARKERS + glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + //glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); + glm::dvec3 northProjected = normalize(north - (((dot(north, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * northProjected); + glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); + addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); + // END MARKERS + } + void DiscoveryMethods::removeTransitMethodVisualization() { + + //SCALE STAR AND PLANET + std::string starName = OsEng.moduleEngine().module()->getStarName(); + scaleNode(starName + "Globe", 1); + scaleNode(starName + " b", 1); + + + + //REMOVE HELP MARKERS + removeDirectionsMarkers(); + } + + DiscoveryMethods::DiscoveryMethods() : PropertyOwner({ "DiscoveryMethods" }) , _showTransit(TransitMethodInfo, false) , _showDoppler(DopplerMethodInfo, false) { - addProperty(_showTransit); - addProperty(_showDoppler); _showTransit.onChange([&]() { if (_showTransit) //just changed to true { @@ -214,11 +410,13 @@ namespace openspace::exoplanets{ } }); + addProperty(_showTransit); _showDoppler.onChange([&]() { if (_showDoppler) //just changed to true { if (_showTransit) { + _showTransit = false; removeTransitMethodVisualization(); } @@ -230,7 +428,8 @@ namespace openspace::exoplanets{ } }); - + addProperty(_showDoppler); + printf("slut pa constructor"); } } // namespce diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index c340c62e3a..c5e5afdfaa 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -34,6 +34,11 @@ namespace openspace::exoplanets { class DiscoveryMethods : public properties::PropertyOwner { public: DiscoveryMethods(); + bool isDoppler(); + bool isTransit(); + void setDopplerImagePos(float); + void setTransitImagePos(float, float); + float getTransitScaleFactor(); private: properties::BoolProperty _showTransit; @@ -44,11 +49,16 @@ private: void addDopplerMethodVisualization(); void removeDopplerMethodVisualization(); - void scaleStar(std::string, float); + void addDirectionsMarkers(glm::dvec3, glm::dvec3, float); + void removeDirectionsMarkers(); + void scaleNode(std::string, float); void moveStar(std::string, float); - void moveCameraTransitView(); - void moveCameraDopplerView(); - void toggleVisabilityOuterPlanets(std::string); + void moveCameraTransitView(glm::dvec3); + void moveCameraDopplerView(glm::dvec3); + void toggleVisabilityOuterPlanets(std::vector, std::string); + void toggleVisabilityPlanet(std::string, std::string); + + float _transitScaleFactor; }; diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 0f60d9a86a..9cbbeecd0d 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -26,8 +26,15 @@ #include #include +#include +#include +#include +#include #include +#include +#include + #include "exoplanetsmodule_lua.inl" namespace openspace { @@ -103,6 +110,49 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { _discoveryMethods = std::make_unique(); addPropertySubOwner(*_discoveryMethods); }); + + // Render + OsEng.registerModuleCallback(OpenSpaceEngine::CallbackOption::Render, [&] { + + if (_discoveryMethods->isDoppler()) + { + std::string starName = OsEng.moduleEngine().module()->getStarName(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + SceneGraphNode* planetNode = OsEng.renderEngine().scene()->sceneGraphNode(planetNames[0]); + SceneGraphNode* starNode = OsEng.renderEngine().scene()->sceneGraphNode(starName); + glm::dvec3 planetPos = planetNode->worldPosition(); + glm::dvec3 starPos = starNode->worldPosition(); + glm::dvec3 starToPosVec = normalize(planetPos - starPos); + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPos); + glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); + glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); + float northAngle = glm::acos(glm::dot(starToPosVec, northProjected)) * 57.2957795; + float viewAngle = glm::acos(glm::dot(starToPosVec, starToSunVec)) * 57.2957795; + + float imagePos = 0; + if ( viewAngle <= 90.0 && northAngle <= 90.0) + { + imagePos = viewAngle / -90.0; + } + else if (viewAngle > 90.0 && northAngle <= 90.0) + { + imagePos = (180.0 - viewAngle) / -90.0; + } + else if (viewAngle > 90.0 && northAngle > 90.0) + { + imagePos = (180.0 - viewAngle) / 90.0; + } + else if (viewAngle <= 90.0 && northAngle > 90.0) + { + imagePos = viewAngle / 90.0; + } + + imagePos *= 0.01; + _discoveryMethods->setDopplerImagePos(imagePos); + + } + + }); } std::vector ExoplanetsModule::documentations() const { diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 2f5532f5ef..b0d8f20a66 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -285,14 +285,12 @@ int addExoplanetSystem(lua_State* L) { std::string script = ""; glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - position); glm::dvec3 northEclipticPole = glm::dvec3(0.0, 0.0, 1.0); // , 1.0); //glm::dvec3 northCelectialPole = northEclipticPole * glm::rotate(glm::radians(336.6), glm::dvec3(1.f, 0.f, 0.f)); - printf(std::to_string(northEclipticPole).c_str()); + // Earths north vector (0,0,1) projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) glm::dvec3 northProjected = normalize(glm::length(northEclipticPole)*glm::sin(dot(northEclipticPole, starToSunVec)) * glm::cross(starToSunVec, glm::cross(northEclipticPole, starToSunVec))); - printf(std::to_string(northProjected).c_str()); glm::dmat3 firstRotation = getExoplanetSystemRotation(glm::dvec3(0.0,0.0,1.0), starToSunVec); glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0); glm::dmat3 secondRotation = getExoplanetSystemRotation(newX, northProjected); @@ -448,16 +446,27 @@ int addExoplanetSystem(lua_State* L) { else sepoch = "2009-05-19T07:11:34.080"; - - if (!isnan(plsy[i].R)) - { + float planetradius; + std::string enabled = ""; + if (isnan(plsy[i].R)) + { + planetradius = plsy[i].RSTAR; + enabled = "false"; + + } + else { + planetradius = plsy[i].R; + enabled = "true"; + } + const std::string planet = "{" "Identifier = '" + plna[i] + "'," "Parent = '" + starname + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "Enabled = "+ enabled +"," + "Radii = " + std::to_string(planetradius) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" @@ -496,7 +505,7 @@ int addExoplanetSystem(lua_State* L) { ); script = ""; - } + const std::string planetTrail = "{" From cd35309d11f41926b1f4ff409f915473b74689f2 Mon Sep 17 00:00:00 2001 From: KarRei Date: Thu, 21 Jun 2018 16:30:26 -0400 Subject: [PATCH 037/123] Added reference objects. --- .../discoverymethods/discoverymethods.cpp | 127 +++++++++++++++++- .../discoverymethods/discoverymethods.h | 6 +- modules/exoplanets/exoplanetsmodule.cpp | 25 ++++ modules/exoplanets/exoplanetsmodule.h | 3 + modules/exoplanets/exoplanetsmodule_lua.inl | 35 ++--- 5 files changed, 175 insertions(+), 21 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index ec671b2273..85479c16d4 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -50,6 +50,12 @@ namespace { "Show doppler method", "Change the view so that the doppler method can be presented." }; + + static const openspace::properties::Property::PropertyInfo SolarSystemReferenceInfo = { + "SolarSystemReference", + "Show solar system reference", + "Show the size of the solar system as a reference for size." + }; } // namespace namespace openspace::exoplanets{ @@ -228,7 +234,6 @@ namespace openspace::exoplanets{ Camera* cam = OsEng.navigationHandler().camera(); cam->setPositionVec3(pos); OsEng.navigationHandler().resetCameraDirection(); - } bool DiscoveryMethods::isDoppler() { @@ -237,8 +242,21 @@ namespace openspace::exoplanets{ bool DiscoveryMethods::isTransit() { return _showTransit; } + bool DiscoveryMethods::isReference() { + return _showSolarSystemReference; + } + + //void DiscoveryMethods::setSunReferencePosition(glm::dvec3 pos) { + // std::string script = "openspace.setPropertyValueSingle( 'Scene.SunReference.Translation.Position', " + std::to_string(pos) + ");"; + // OsEng.scriptEngine().queueScript( + // script, + // openspace::scripting::ScriptEngine::RemoteScripting::Yes + // ); + //} + + void DiscoveryMethods::setDopplerImagePos(float value) { - std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; //get name of current star from em + std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -388,10 +406,104 @@ namespace openspace::exoplanets{ } + void DiscoveryMethods::addSolarSystemReferenceVisualization() { + + std::string starName = OsEng.moduleEngine().module()->getStarName(); + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + + // SUN + const std::string sunRef = "{" + "Identifier = 'SunReference'," + "Parent = '" + starName + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "BlendMode = 'Additive'" + "}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {0, 0, 0}," //"+ std::to_string(planets[0].RSTAR) + "* 6.957E8 + "}," + "}," + "}"; + + std::string script = "openspace.addSceneGraphNode(" + sunRef + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + // EARTH + const std::string earthRef = "{" + "Identifier = 'EarthReference'," + "Parent = '" + planetNames[0] + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 6378137," // in meters + "Billboard = true," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "BlendMode = 'Additive'" + "}," + //"Transform = {" + // "Translation = {" + // "Type = 'StaticTranslation'," + // "Position = {" + std::to_string(planets[0].R) + "* 7.1492E7, 0," + std::to_string(planets[0].R) + "* 7.1492E7}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 + // "}," + //"}," + "}"; + script = ""; + script = "openspace.addSceneGraphNode(" + earthRef + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + glm::dmat3 rotation = OsEng.moduleEngine().module()->getRotation(); + // ORBIT + const std::string orbitRef = "{" + "Identifier = 'OrbitReference'," + "Parent = '" + starName + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 1.496E11," // earths semi-major axis in m + "Billboard = false," + "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "BlendMode = 'Additive'" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(rotation) + "," + "}" + "}," + "}"; + script = ""; + script = "openspace.addSceneGraphNode(" + orbitRef + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + + void DiscoveryMethods::removeSolarSystemReferenceVisualization() { + std::string script = "openspace.removeSceneGraphNode('SunReference');" + "openspace.removeSceneGraphNode('EarthReference');" + "openspace.removeSceneGraphNode('OrbitReference');"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + DiscoveryMethods::DiscoveryMethods() : PropertyOwner({ "DiscoveryMethods" }) , _showTransit(TransitMethodInfo, false) , _showDoppler(DopplerMethodInfo, false) + , _showSolarSystemReference(SolarSystemReferenceInfo, false) { _showTransit.onChange([&]() { if (_showTransit) //just changed to true @@ -429,7 +541,16 @@ namespace openspace::exoplanets{ }); addProperty(_showDoppler); - printf("slut pa constructor"); + + _showSolarSystemReference.onChange([&]() { + if (_showSolarSystemReference) { + addSolarSystemReferenceVisualization(); + } + else { + removeSolarSystemReferenceVisualization(); + } + }); + addProperty(_showSolarSystemReference); } } // namespce diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index c5e5afdfaa..bb8e4d35af 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -36,14 +36,18 @@ public: DiscoveryMethods(); bool isDoppler(); bool isTransit(); + bool isReference(); void setDopplerImagePos(float); - void setTransitImagePos(float, float); float getTransitScaleFactor(); + //void setSunReferencePosition(glm::dvec3); private: properties::BoolProperty _showTransit; properties::BoolProperty _showDoppler; + properties::BoolProperty _showSolarSystemReference; + void addSolarSystemReferenceVisualization(); + void removeSolarSystemReferenceVisualization(); void addTransitMethodVisualization(); void removeTransitMethodVisualization(); void addDopplerMethodVisualization(); diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 9cbbeecd0d..8637ed57e2 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -27,10 +27,12 @@ #include #include + #include #include #include #include +#include #include #include @@ -73,6 +75,13 @@ std::vector ExoplanetsModule::getPlna() { return _plna; } +void ExoplanetsModule::setRotation(glm::dmat3 rot) { + _rotation = rot; +} +glm::dmat3 ExoplanetsModule::getRotation() { + return _rotation; +} + scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { scripting::LuaLibrary res; @@ -151,6 +160,22 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { _discoveryMethods->setDopplerImagePos(imagePos); } + /*if (_discoveryMethods->isReference()) { + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + float starRadius = planets[0].RSTAR * 6.957E8; //m + + std::string starName = OsEng.moduleEngine().module()->getStarName(); + SceneGraphNode* starNode = OsEng.renderEngine().scene()->sceneGraphNode(starName); + glm::dvec3 starPos = starNode->worldPosition(); // in m + Camera* cam = OsEng.navigationHandler().camera(); + glm::dvec3 cameraPos = cam->positionVec3(); // in m? + glm::dvec3 starToCamera = normalize(cameraPos - starPos); + + + glm::dvec3 referencePos = (double(starRadius) * starToCamera); + + _discoveryMethods->setSunReferencePosition(referencePos); + }*/ }); } diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index a473ccfc0b..2dffe81fad 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -97,6 +97,8 @@ public: std::vector getPlsy(); void setPlna(std::vector); std::vector getPlna(); + void setRotation(glm::dmat3); + glm::dmat3 getRotation(); protected: void internalInitialize(const ghoul::Dictionary&) override; @@ -106,6 +108,7 @@ protected: std::string _starName; std::vector _plsy; std::vector _plna; + glm::dmat3 _rotation; }; } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index b0d8f20a66..7d03fa7563 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -297,6 +297,7 @@ int addExoplanetSystem(lua_State* L) { glm::dmat3 exoplanetSystemRot = secondRotation * firstRotation; + const std::string starParent = "{" "Identifier = '" + starname + "'," "Parent = 'SolarSystemBarycenter'," @@ -394,25 +395,25 @@ int addExoplanetSystem(lua_State* L) { script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - script = ""; + //script = ""; - const std::string starGlare = "{" - "Identifier = '" + starname + "Glare'," - "Parent = '" + starname + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png'," - "BlendMode = 'Additive'" - "}" - "}"; - - script = "openspace.addSceneGraphNode(" + starGlare + ");"; + //const std::string starGlare = "{" + // "Identifier = '" + starname + "Glare'," + // "Parent = '" + starname + "'," + // "Renderable = {" + // "Type = 'RenderablePlaneImageLocal'," + // "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + // "Billboard = true," + // "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue.png'," + // "BlendMode = 'Additive'" + // "}" + // "}"; + // + //script = "openspace.addSceneGraphNode(" + starGlare + ");"; //OsEng.scriptEngine().queueScript( // script, - // openspace::scripting::ScriptEngine::RemoteScripting::Yes - // ); + // openspace::scripting::ScriptEngine::RemoteScripting::Yes + //); } @@ -541,7 +542,7 @@ int addExoplanetSystem(lua_State* L) { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); glm::dmat3 rot = orbitPlaneRotationMatrix; - + OsEng.moduleEngine().module()->setRotation(rot); const std::string disc = "{" "Identifier = '" + plna[i] + "Disc'," "Parent = '" + starname + "'," From 0a480428b5cb6c1a148c85eeb8f823174906486a Mon Sep 17 00:00:00 2001 From: KarRei Date: Sat, 23 Jun 2018 13:14:17 -0400 Subject: [PATCH 038/123] Correct north vector, now earths north vector projected onto skyplane. --- .../discoverymethods/discoverymethods.cpp | 39 +-- modules/exoplanets/exoplanetsmodule.cpp | 22 +- modules/exoplanets/exoplanetsmodule.h | 3 + modules/exoplanets/exoplanetsmodule_lua.inl | 233 +++++++++--------- 4 files changed, 145 insertions(+), 152 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 85479c16d4..556811e83d 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -246,15 +246,6 @@ namespace openspace::exoplanets{ return _showSolarSystemReference; } - //void DiscoveryMethods::setSunReferencePosition(glm::dvec3 pos) { - // std::string script = "openspace.setPropertyValueSingle( 'Scene.SunReference.Translation.Position', " + std::to_string(pos) + ");"; - // OsEng.scriptEngine().queueScript( - // script, - // openspace::scripting::ScriptEngine::RemoteScripting::Yes - // ); - //} - - void DiscoveryMethods::setDopplerImagePos(float value) { std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; OsEng.scriptEngine().queueScript( @@ -276,12 +267,10 @@ namespace openspace::exoplanets{ float eccentricity = planets[0].ECC; float starRadius = planets[0].RSTAR; // in Solar Radii - glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); - //glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); - glm::dvec3 northProjected = normalize(north - (((dot(north, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); + glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); // MOVE CAMERA - glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, northProjected)); + glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * faceOnVector); moveCameraDopplerView(cameraPosition); // END CAMERA @@ -313,7 +302,7 @@ namespace openspace::exoplanets{ // HELPER MARKERS - glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * northProjected); + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); // END MARKERS @@ -384,20 +373,18 @@ namespace openspace::exoplanets{ // END SCALE // HELPER MARKERS - glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); - //glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); - glm::dvec3 northProjected = normalize(north - (((dot(north, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); - glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * northProjected); + glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); // END MARKERS } void DiscoveryMethods::removeTransitMethodVisualization() { - + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); //SCALE STAR AND PLANET std::string starName = OsEng.moduleEngine().module()->getStarName(); scaleNode(starName + "Globe", 1); - scaleNode(starName + " b", 1); + scaleNode(planetNames[0], 1); @@ -448,12 +435,12 @@ namespace openspace::exoplanets{ "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," "BlendMode = 'Additive'" "}," - //"Transform = {" - // "Translation = {" - // "Type = 'StaticTranslation'," - // "Position = {" + std::to_string(planets[0].R) + "* 7.1492E7, 0," + std::to_string(planets[0].R) + "* 7.1492E7}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 - // "}," - //"}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {0, 0, 0}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 + "}," + "}," "}"; script = ""; script = "openspace.addSceneGraphNode(" + earthRef + ");"; diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 8637ed57e2..66db4c1987 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -81,6 +81,12 @@ void ExoplanetsModule::setRotation(glm::dmat3 rot) { glm::dmat3 ExoplanetsModule::getRotation() { return _rotation; } +void ExoplanetsModule::setNorthVector(glm::dvec3 vector) { + _north = vector; +} +glm::dvec3 ExoplanetsModule::getNorthVector() { + return _north; +} scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { @@ -160,22 +166,6 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { _discoveryMethods->setDopplerImagePos(imagePos); } - /*if (_discoveryMethods->isReference()) { - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - float starRadius = planets[0].RSTAR * 6.957E8; //m - - std::string starName = OsEng.moduleEngine().module()->getStarName(); - SceneGraphNode* starNode = OsEng.renderEngine().scene()->sceneGraphNode(starName); - glm::dvec3 starPos = starNode->worldPosition(); // in m - Camera* cam = OsEng.navigationHandler().camera(); - glm::dvec3 cameraPos = cam->positionVec3(); // in m? - glm::dvec3 starToCamera = normalize(cameraPos - starPos); - - - glm::dvec3 referencePos = (double(starRadius) * starToCamera); - - _discoveryMethods->setSunReferencePosition(referencePos); - }*/ }); } diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index 2dffe81fad..7a795e180b 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -99,6 +99,8 @@ public: std::vector getPlna(); void setRotation(glm::dmat3); glm::dmat3 getRotation(); + void setNorthVector(glm::dvec3); + glm::dvec3 getNorthVector(); protected: void internalInitialize(const ghoul::Dictionary&) override; @@ -109,6 +111,7 @@ protected: std::vector _plsy; std::vector _plna; glm::dmat3 _rotation; + glm::dvec3 _north; }; } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 7d03fa7563..818cb0f1f6 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -24,6 +24,7 @@ #include #include +#include #include #include @@ -63,12 +64,15 @@ std::string getStarColor(float bv) { return colorString; } -glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om, glm::dmat3 rot) { +glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm::dmat3 rot) { // Exoplanet defined inclination changed to be used as Kepler defined inclination const glm::dvec3 ascendingNodeAxisRot = rot * glm::dvec3(0.f, 0.f, 1.f); + //const glm::dvec3 ascendingNodeAxisRot = glm::dvec3(0.f, 0.f, 1.f); const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); + //const glm::dvec3 inclinationAxisRot = glm::dvec3(1.f, 0.f, 0.f ); const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); + //const glm::vec3 argPeriapsisAxisRot = glm::dvec3( 0.f, 0.f, 1.f ); /*const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; @@ -285,26 +289,34 @@ int addExoplanetSystem(lua_State* L) { std::string script = ""; glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - position); - glm::dvec3 northEclipticPole = glm::dvec3(0.0, 0.0, 1.0); // , 1.0); - //glm::dvec3 northCelectialPole = northEclipticPole * glm::rotate(glm::radians(336.6), glm::dvec3(1.f, 0.f, 0.f)); + glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); + + glm::dmat3 galaxticToCelectialMatrix = SpiceManager::ref().positionTransformMatrix( // galaxtic north in celectial coordinates, or just celectial north? + "GALACTIC", + "J2000", + 0.0 + ); + glm::dvec3 celestialNorth = normalize(galaxticToCelectialMatrix * galacticNorth); + // Earths north vector (0,0,1) projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) - glm::dvec3 northProjected = normalize(glm::length(northEclipticPole)*glm::sin(dot(northEclipticPole, starToSunVec)) * glm::cross(starToSunVec, glm::cross(northEclipticPole, starToSunVec))); - glm::dmat3 firstRotation = getExoplanetSystemRotation(glm::dvec3(0.0,0.0,1.0), starToSunVec); - glm::dvec3 newX = firstRotation * glm::dvec3(1.0, 0.0, 0.0); - glm::dmat3 secondRotation = getExoplanetSystemRotation(newX, northProjected); - - glm::dmat3 exoplanetSystemRot = secondRotation * firstRotation; + glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); + OsEng.moduleEngine().module()->setNorthVector(northProjected); + glm::dvec3 beta = normalize(cross(northProjected, starToSunVec)); + glm::dmat3 exoplanetSystemRot = glm::dmat3(starToSunVec.x, starToSunVec.y, starToSunVec.z, + beta.x, beta.y, beta.z, + northProjected.x, northProjected.y, northProjected.z); const std::string starParent = "{" "Identifier = '" + starname + "'," - "Parent = 'SolarSystemBarycenter'," + "Parent = 'SolarSystemBarycenter'," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + std::to_string(exoplanetSystemRot) + "," + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + std::to_string(exoplanetSystemRot) + "," "}," "Translation = {" "Type = 'StaticTranslation'," @@ -419,38 +431,38 @@ int addExoplanetSystem(lua_State* L) { - for (size_t i = 0; i < plsy.size(); i++) - { - script = ""; + for (size_t i = 0; i < plsy.size(); i++) + { + script = ""; - if (isnan(plsy[i].ECC)) - { - plsy[i].ECC = 0; - } - if (isnan(plsy[i].I)) - { - plsy[i].I = 90; - } - if (isnan(plsy[i].BIGOM)) - { - plsy[i].BIGOM = 0; - } - if (isnan(plsy[i].OM)) - { - plsy[i].OM = 90; - } - std::string sepoch; - if (!isnan(plsy[i].TT)) { - epoch.setTime("JD " + std::to_string(plsy[i].TT)); - sepoch = epoch.ISO8601(); - } - else - sepoch = "2009-05-19T07:11:34.080"; + if (isnan(plsy[i].ECC)) + { + plsy[i].ECC = 0; + } + if (isnan(plsy[i].I)) + { + plsy[i].I = 90; + } + if (isnan(plsy[i].BIGOM)) + { + plsy[i].BIGOM = 0; + } + if (isnan(plsy[i].OM)) + { + plsy[i].OM = 90; + } + std::string sepoch; + if (!isnan(plsy[i].TT)) { + epoch.setTime("JD " + std::to_string(plsy[i].TT)); + sepoch = epoch.ISO8601(); + } + else + sepoch = "2009-05-19T07:11:34.080"; float planetradius; std::string enabled = ""; - if (isnan(plsy[i].R)) - { + if (isnan(plsy[i].R)) + { planetradius = plsy[i].RSTAR; enabled = "false"; @@ -460,76 +472,76 @@ int addExoplanetSystem(lua_State* L) { enabled = "true"; } - const std::string planet = "{" - "Identifier = '" + plna[i] + "'," - "Parent = '" + starname + "'," - "Enabled = true," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Enabled = "+ enabled +"," - "Radii = " + std::to_string(planetradius) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'ExoplanetTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," - "Enabled = true" - "}" - "}" - "}" - "}," - "Transform = {" - "Scale = {" - "Type = 'StaticScale'," - "Scale = 1.0," - "}," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}," - "}," - "}"; - - script = "openspace.addSceneGraphNode(" + planet + ");"; - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - script = ""; - - - - - const std::string planetTrail = "{" - "Identifier = '" + plna[i] + "Trail'," - "Parent = '" + starname + "'," + const std::string planet = "{" + "Identifier = '" + plna[i] + "'," + "Parent = '" + starname + "'," "Enabled = true," - "Renderable = {" - "Type = 'RenderableTrailOrbit'," - "Period = " + std::to_string(plsy[i].PER) + "," - "Resolution = 1000," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}," - "Color = { 1, 0, 0 }" - "}," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Enabled = " + enabled + "," + "Radii = " + std::to_string(planetradius) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'ExoplanetTexture'," + "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "Enabled = true" + "}" + "}" + "}" + "}," + "Transform = {" + "Scale = {" + "Type = 'StaticScale'," + "Scale = 1.0," + "}," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}," + "}," + "}"; + + script = "openspace.addSceneGraphNode(" + planet + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + script = ""; + + + + + const std::string planetTrail = "{" + "Identifier = '" + plna[i] + "Trail'," + "Parent = '" + starname + "'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableTrailOrbit'," + "Period = " + std::to_string(plsy[i].PER) + "," + "Resolution = 1000," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(plsy[i].I) + "," //I + "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. + "}," + "Color = { 1, 0, 0 }" + "}," "}"; OsEng.scriptEngine().queueScript( @@ -541,6 +553,7 @@ int addExoplanetSystem(lua_State* L) { { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); + //glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); // , exoplanetSystemRot); glm::dmat3 rot = orbitPlaneRotationMatrix; OsEng.moduleEngine().module()->setRotation(rot); const std::string disc = "{" From 79b6f479b3bfddcd5c5ddff3c7b78f46171b3377 Mon Sep 17 00:00:00 2001 From: KarRei Date: Wed, 27 Jun 2018 19:47:36 -0400 Subject: [PATCH 039/123] WIP: transit method graph --- .../discoverymethods/discoverymethods.cpp | 68 ++++++++++++---- .../discoverymethods/discoverymethods.h | 5 +- modules/exoplanets/exoplanetsmodule.cpp | 79 +++++++++++++++++++ 3 files changed, 133 insertions(+), 19 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 556811e83d..1f008552bb 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -166,6 +166,28 @@ namespace openspace::exoplanets{ ); } + void addTransitGraphs() { + std::string script = "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'Transit2'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/prick.png')," + "EuclideanPosition = {0.0, 0.0}," + "});" + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'Transit1'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/graph.png')," + "EuclideanPosition = {0.0, -0.7}," + "});"; + + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { @@ -220,16 +242,8 @@ namespace openspace::exoplanets{ openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - - void DiscoveryMethods::moveCameraDopplerView(glm::dvec3 pos) { - Camera* cam = OsEng.navigationHandler().camera(); - cam->setPositionVec3(pos); - OsEng.navigationHandler().resetCameraDirection(); - - } - - void DiscoveryMethods::moveCameraTransitView(glm::dvec3 pos) { + void DiscoveryMethods::moveCamera(glm::dvec3 pos) { Camera* cam = OsEng.navigationHandler().camera(); cam->setPositionVec3(pos); @@ -254,6 +268,14 @@ namespace openspace::exoplanets{ ); } + void DiscoveryMethods::setTransitImagePos(float valueX,float valueY) { + std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.Transit2.EuclideanPosition', {" + std::to_string(valueX) + "," + std::to_string(valueY) + "}); "; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + void DiscoveryMethods::addDopplerMethodVisualization() { SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); std::string starName = OsEng.moduleEngine().module()->getStarName(); // getStarName @@ -272,7 +294,7 @@ namespace openspace::exoplanets{ // MOVE CAMERA glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * faceOnVector); - moveCameraDopplerView(cameraPosition); + moveCamera(cameraPosition); // END CAMERA // SCALE STAR AND PLANET @@ -355,8 +377,13 @@ namespace openspace::exoplanets{ // MOVE CAMERA //borde kanske va periapsis distance, men det gÃ¥r bra ändÃ¥ - glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * starToSunVec);; - moveCameraTransitView(cameraPosition); + glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); + //glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); + glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * starToSunVec); + //glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * faceOnVector); + + + moveCamera(cameraPosition); // END CAMERA toggleVisabilityPlanet(planetNames[0], "true"); @@ -366,17 +393,21 @@ namespace openspace::exoplanets{ periapsisDistance *= 149597870700.0; // in m starRadius *= 6.957E8; // in m - float scale = (0.666 * periapsisDistance) / starRadius; // actual radius * scale = wanted radius + float scale = (0.5 * periapsisDistance) / starRadius; // actual radius * scale = wanted radius scaleNode(starName + "Globe", scale); scaleNode(planetNames[0], scale); //eller använda getPlna()? _transitScaleFactor = scale; // END SCALE + // ADD THE GRAPH + addTransitGraphs(); + // END GRAPH + // HELPER MARKERS - glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); - addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); + //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); // END MARKERS } void DiscoveryMethods::removeTransitMethodVisualization() { @@ -386,7 +417,12 @@ namespace openspace::exoplanets{ scaleNode(starName + "Globe", 1); scaleNode(planetNames[0], 1); - + // REMOVE GRAPH + std::string script = "openspace.removeScreenSpaceRenderable('Transit2');openspace.removeScreenSpaceRenderable('Transit1');"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); //REMOVE HELP MARKERS removeDirectionsMarkers(); diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index bb8e4d35af..38d9826546 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -38,8 +38,8 @@ public: bool isTransit(); bool isReference(); void setDopplerImagePos(float); + void setTransitImagePos(float,float); float getTransitScaleFactor(); - //void setSunReferencePosition(glm::dvec3); private: properties::BoolProperty _showTransit; @@ -57,8 +57,7 @@ private: void removeDirectionsMarkers(); void scaleNode(std::string, float); void moveStar(std::string, float); - void moveCameraTransitView(glm::dvec3); - void moveCameraDopplerView(glm::dvec3); + void moveCamera(glm::dvec3); void toggleVisabilityOuterPlanets(std::vector, std::string); void toggleVisabilityPlanet(std::string, std::string); diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 66db4c1987..3f9466ef7f 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -166,6 +166,85 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { _discoveryMethods->setDopplerImagePos(imagePos); } + if (_discoveryMethods->isTransit()) { + + std::string starName = OsEng.moduleEngine().module()->getStarName(); + std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + SceneGraphNode* planetNode = OsEng.renderEngine().scene()->sceneGraphNode(planetNames[0]); + SceneGraphNode* starNode = OsEng.renderEngine().scene()->sceneGraphNode(starName); + glm::dvec3 planetPos = planetNode->worldPosition(); + glm::dvec3 starPos = starNode->worldPosition(); + + glm::dvec3 starToPosVec = planetPos - starPos; + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPos); + + std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + float starRadius = planets[0].RSTAR * 6.957E8 * _discoveryMethods->getTransitScaleFactor(); // in m + + glm::dvec3 north = _north; + float northAngle = glm::acos(glm::dot(normalize(starToPosVec), north)) * 57.2957795; + float viewAngle = glm::acos(glm::dot(normalize(starToPosVec), starToSunVec)) * 57.2957795; + + glm::dvec3 posVecProjected = starToPosVec - (((dot(starToPosVec, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec); + float l = glm::length(posVecProjected); //in m + float imageYPos = -0.6; + if (l<(starRadius*0.76) && viewAngle <= 90.0) { // in front of star + imageYPos = -0.8; + } + //imageYPos = -0.7; + + float imageXPos = 0; + if (viewAngle <= 90.0 && northAngle <= 90.0) + { + imageXPos = (viewAngle / 90.0) * 0.5; + } + else if (viewAngle > 90.0 && northAngle <= 90.0) + { + imageXPos = (viewAngle / 90.0) * 0.5; + } + else if (viewAngle > 90.0 && northAngle > 90.0) + { + imageXPos = (viewAngle / 90.0) * -0.5; + } + else if (viewAngle <= 90.0 && northAngle > 90.0) + { + imageXPos = (viewAngle / 90.0) * -0.5; + } + imageXPos *= 0.25; + _discoveryMethods->setTransitImagePos(imageXPos, imageYPos); + + //glm::dvec3 sunPos = glm::dvec3(0.0, 0.0, 0.0); + /*Camera* cam = OsEng.navigationHandler().camera(); + glm::dvec3 sunPos = cam->positionVec3(); + glm::dvec3 radiusPos = starPos + (double(planets[0].RSTAR * _discoveryMethods->getTransitScaleFactor()) * _north); + glm::dvec3 sunToRadius = normalize(radiusPos - sunPos); + glm::dvec3 sunToStar = normalize(starPos - sunPos); + + glm::dvec3 sunToPlanet = normalize(planetPos - sunPos); + + + double angleRadiusStar = glm::acos(glm::dot(sunToRadius, sunToStar))*57.2957795; + + double anglePlanetStar = glm::acos(glm::dot(sunToPlanet, sunToStar))*57.2957795; + + glm::dvec3 starToSun = normalize(sunPos - starPos); + glm::dvec3 starToPlanet = normalize(planetPos - starPos); + + double anglePlanetSun = glm::dot(starToPlanet, starToSun); //glm::acos(glm::dot(starToPlanet, starToSun)) * 57.2957795; + + float anglePlanetNorth = glm::acos(glm::dot(starToPlanet, _north)) * 57.2957795; + + // + float imageYPos = 1.0; + //float viewAngle = glm::acos(glm::dot(starToPlanet, starToSun)) * 57.2957795; + //TRANSITING + if (anglePlanetStar < angleRadiusStar && anglePlanetSun >= 0.0) { + imageYPos = -1.0; + } + */ + + + } }); } From 2454043f1c5a13b11af57c8d24d4c7dc3767adf9 Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 2 Nov 2018 17:31:53 +0100 Subject: [PATCH 040/123] Transit graph --- .../discoverymethods/discoverymethods.cpp | 19 ++++++--- modules/exoplanets/exoplanetsmodule.cpp | 40 ++----------------- 2 files changed, 18 insertions(+), 41 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 1f008552bb..34b5ec3487 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -179,7 +179,16 @@ namespace openspace::exoplanets{ "Identifier = 'Transit1'," "Type = 'ScreenSpaceImageLocal'," "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/graph.png')," - "EuclideanPosition = {0.0, -0.7}," + "Scale = 0.485," + "EuclideanPosition = {0.0, -0.65}" + "});" + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'Transit3'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/axes.png')," + "Scale = 0.7," + "EuclideanPosition = {-0.05, -0.65}" "});"; OsEng.scriptEngine().queueScript( @@ -326,7 +335,7 @@ namespace openspace::exoplanets{ // HELPER MARKERS glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); - addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); + //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); // END MARKERS } @@ -359,7 +368,7 @@ namespace openspace::exoplanets{ ); //REMOVE HELP MARKERS - removeDirectionsMarkers(); + //removeDirectionsMarkers(); } void DiscoveryMethods::addTransitMethodVisualization() { @@ -418,14 +427,14 @@ namespace openspace::exoplanets{ scaleNode(planetNames[0], 1); // REMOVE GRAPH - std::string script = "openspace.removeScreenSpaceRenderable('Transit2');openspace.removeScreenSpaceRenderable('Transit1');"; + std::string script = "openspace.removeScreenSpaceRenderable('Transit3');openspace.removeScreenSpaceRenderable('Transit2');openspace.removeScreenSpaceRenderable('Transit1');"; OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); //REMOVE HELP MARKERS - removeDirectionsMarkers(); + //removeDirectionsMarkers(); } diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 3f9466ef7f..ef136bc87a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -187,11 +187,10 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { glm::dvec3 posVecProjected = starToPosVec - (((dot(starToPosVec, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec); float l = glm::length(posVecProjected); //in m - float imageYPos = -0.6; - if (l<(starRadius*0.76) && viewAngle <= 90.0) { // in front of star - imageYPos = -0.8; + float imageYPos = -0.60; + if (l<(starRadius*0.82) && viewAngle <= 90.0) { + imageYPos = -0.80; } - //imageYPos = -0.7; float imageXPos = 0; if (viewAngle <= 90.0 && northAngle <= 90.0) @@ -210,40 +209,9 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { { imageXPos = (viewAngle / 90.0) * -0.5; } - imageXPos *= 0.25; + imageXPos *= 0.5; _discoveryMethods->setTransitImagePos(imageXPos, imageYPos); - //glm::dvec3 sunPos = glm::dvec3(0.0, 0.0, 0.0); - /*Camera* cam = OsEng.navigationHandler().camera(); - glm::dvec3 sunPos = cam->positionVec3(); - glm::dvec3 radiusPos = starPos + (double(planets[0].RSTAR * _discoveryMethods->getTransitScaleFactor()) * _north); - glm::dvec3 sunToRadius = normalize(radiusPos - sunPos); - glm::dvec3 sunToStar = normalize(starPos - sunPos); - - glm::dvec3 sunToPlanet = normalize(planetPos - sunPos); - - - double angleRadiusStar = glm::acos(glm::dot(sunToRadius, sunToStar))*57.2957795; - - double anglePlanetStar = glm::acos(glm::dot(sunToPlanet, sunToStar))*57.2957795; - - glm::dvec3 starToSun = normalize(sunPos - starPos); - glm::dvec3 starToPlanet = normalize(planetPos - starPos); - - double anglePlanetSun = glm::dot(starToPlanet, starToSun); //glm::acos(glm::dot(starToPlanet, starToSun)) * 57.2957795; - - float anglePlanetNorth = glm::acos(glm::dot(starToPlanet, _north)) * 57.2957795; - - // - float imageYPos = 1.0; - //float viewAngle = glm::acos(glm::dot(starToPlanet, starToSun)) * 57.2957795; - //TRANSITING - if (anglePlanetStar < angleRadiusStar && anglePlanetSun >= 0.0) { - imageYPos = -1.0; - } - */ - - } }); From 831aa600fd8f7330005d8576cd05557a3adf679a Mon Sep 17 00:00:00 2001 From: KarRei Date: Fri, 2 Nov 2018 18:14:07 +0100 Subject: [PATCH 041/123] Correction on visability for outer planet function and setting ecc to zero if NAN --- .../exoplanets/discoverymethods/discoverymethods.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 34b5ec3487..f15101d0f1 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -227,7 +227,7 @@ namespace openspace::exoplanets{ std::string script = ""; //remove planetglobe if (!isnan(planets[i].R)) { - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".renderable.Enabled', " + visability + "); "; + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".RenderableGlobe.Enabled', " + visability + "); "; } //remove trail script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; @@ -296,6 +296,10 @@ namespace openspace::exoplanets{ float semiMajorAxis = planets[0].A; // in AU float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis float eccentricity = planets[0].ECC; + if (isnan(planets[0].ECC)) + { + eccentricity = 0.0; + } float starRadius = planets[0].RSTAR; // in Solar Radii glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); @@ -382,6 +386,10 @@ namespace openspace::exoplanets{ float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) float eccentricity = planets[0].ECC; + if (isnan(planets[0].ECC)) + { + eccentricity = 0.0; + } float starRadius = planets[0].RSTAR; // in Solar Radii // MOVE CAMERA From 6813a5a2c57033cb0a46bcaf6b8015409606c635 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 5 Nov 2018 11:53:39 +0100 Subject: [PATCH 042/123] Increased scale factor for RV method --- modules/exoplanets/discoverymethods/discoverymethods.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index f15101d0f1..bedd002e05 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -314,7 +314,7 @@ namespace openspace::exoplanets{ float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU periapsisDistance *= 149597870700.0; // in m starRadius *= 6.957E8; // in m - float scale = (0.1 * periapsisDistance) / starRadius; + float scale = (0.2 * periapsisDistance) / starRadius; scaleNode(starName + "Globe", scale); scaleNode(planetNames[0], scale); // using planetNames[0] because i know that will be the one visible after removing outer planets // END SCALE From 93379939e5f342d016f26fc184ade8dcdb768c44 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 5 Nov 2018 12:11:15 +0100 Subject: [PATCH 043/123] Earth reference added to all planets in system --- .../discoverymethods/discoverymethods.cpp | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index bedd002e05..8af369f982 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -460,7 +460,7 @@ namespace openspace::exoplanets{ "Type = 'RenderablePlaneImageLocal'," "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/target-blue-ring.png'," "BlendMode = 'Additive'" "}," "Transform = {" @@ -478,29 +478,33 @@ namespace openspace::exoplanets{ ); // EARTH - const std::string earthRef = "{" - "Identifier = 'EarthReference'," - "Parent = '" + planetNames[0] + "'," - "Renderable = {" + for (int i = 0; i < planetNames.size(); i++) + { + const std::string earthRef = "{" + "Identifier = 'EarthReference" + std::to_string(i) + "'," + "Parent = '" + planetNames[i] + "'," + "Renderable = {" "Type = 'RenderablePlaneImageLocal'," "Size = 6378137," // in meters "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/target-blue-ring.png'," "BlendMode = 'Additive'" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {0, 0, 0}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 "}," - "}," - "}"; - script = ""; - script = "openspace.addSceneGraphNode(" + earthRef + ");"; - OsEng.scriptEngine().queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {0, 0, 0}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 + "}," + "}," + "}"; + script = ""; + script = "openspace.addSceneGraphNode(" + earthRef + ");"; + OsEng.scriptEngine().queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + glm::dmat3 rotation = OsEng.moduleEngine().module()->getRotation(); // ORBIT @@ -511,7 +515,7 @@ namespace openspace::exoplanets{ "Type = 'RenderablePlaneImageLocal'," "Size = 1.496E11," // earths semi-major axis in m "Billboard = false," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/target-blue-ring.png'," "BlendMode = 'Additive'" "}," "Transform = {" From e4e25de2722b2762bda10b56c5ab389fb8531094 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 5 Nov 2018 12:31:56 +0100 Subject: [PATCH 044/123] Mapping of three colored texture --- modules/exoplanets/shaders/orbitdisc_fs.glsl | 64 ++++++++++++-------- 1 file changed, 39 insertions(+), 25 deletions(-) diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index aacf432515..2994e94aee 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -47,43 +47,57 @@ Fragment getFragment() { // The length of the texture coordinates vector is our distance from the center - float radius; - float radius_inner; + float outer; + float inner; + + float E = eccentricity; + float AU = semiMajorAxis; + float BU = AU * sqrt(1.0 - pow(E, 2.0)); // semi-minor axis + float CU = sqrt(pow(AU, 2.0) - pow(BU, 2.0)); + float apo = AU * (1 + E); - float semiMinorAxis = semiMajorAxis * sqrt(1.0 - pow(eccentricity, 2.0)); - float focus = sqrt(pow(semiMajorAxis, 2.0) - pow(semiMinorAxis, 2.0)); - float apoapsisDistance = semiMajorAxis * (1 + eccentricity); + float AL = AU - textureOffset.x * 149597870700.0 - textureOffset.y * 149597870700.0; + float BL = AL * sqrt(1.0 - pow(E, 2.0)); + float CL = sqrt(pow(AL, 2.0) - pow(BL, 2.0)); + float apo_inner = AL * (1 + E); - float semiMajorAxis_inner = semiMajorAxis - textureOffset.x * 149597870700.0 - textureOffset.y * 149597870700.0; - float semiMinorAxis_inner = semiMajorAxis_inner * sqrt(1.0 - pow(eccentricity, 2.0)); - float focus_inner = sqrt(pow(semiMajorAxis_inner, 2.0) - pow(semiMinorAxis_inner, 2.0)); - - if(eccentricity <= 0.0){ - radius = length(st); - radius_inner = pow(st.x , 2.0) / pow(semiMajorAxis_inner/apoapsisDistance, 2.0) + ( pow(st.y, 2.0) / (pow(semiMajorAxis_inner/apoapsisDistance, 2.0)) ); + if(eccentricity <= 0.000000){ + outer = pow(st.x , 2.0) / pow(AU/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BU/apo, 2.0)) ); + inner = pow(st.x , 2.0) / pow(AL/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BL/apo, 2.0)) ); } else { - radius = ( pow((st.x + focus/apoapsisDistance), 2.0) ) / pow(semiMajorAxis/apoapsisDistance, 2.0) + ( pow(st.y, 2.0) / (pow(semiMinorAxis/apoapsisDistance, 2.0)) ); - radius_inner = ( pow((st.x + focus_inner/apoapsisDistance), 2.0) ) / pow(semiMajorAxis_inner/apoapsisDistance, 2.0) + ( pow(st.y, 2.0) / (pow(semiMinorAxis_inner/apoapsisDistance, 2.0)) ); + outer = ( pow((st.x + CU/apo), 2.0) ) / pow(AU/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BU/apo, 2.0)) ); + inner = ( pow((st.x + CL/apo), 2.0) ) / pow(AL/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BL/apo, 2.0)) ); } - // We only want to consider ring-like objects so we need to discard everything outside the largest radius - if (radius > 1.0 ) + if (outer > 1.0 ) // point is outside outer ellipse discard; - // We also need to discard ecerthing inside the smallest radius - if (radius_inner < 1.0 ) + if (inner < 1.0 ) // point is inside inner ellipse discard; // Remapping the texture coordinates - // Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y] - // textureOffset.x -> 0 - // textureOffset.y -> 1 + vec2 dir = normalize(st); - // textureOffset is not the same as it was when the following row was written. - // But as long as the texture is one color it doesnt seem to matter. - float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x); + // Find outer ellipse: where along the direction is the equation = 1 + float scale; + if(eccentricity <= 0.000000){ + scale = sqrt( ( pow((AU/apo)*(BU/apo),2) ) / ((pow((BU/apo)*dir.x,2))+(pow((AU/apo)*dir.y,2))) ); + } + else{ + float first = -( pow(BU/apo, 2.0)*dir.x*(CU/apo) ) / ( pow((BU/apo)*dir.x, 2.0) + pow((AU/apo)*dir.y, 2.0) ); + float second = pow( ( pow(BU/apo, 2.0)*dir.x*(CU/apo) ) / ( pow((BU/apo)*dir.x, 2.0) + pow( (AU/apo)*dir.y, 2.0 ) ) , 2.0); + float third = ( pow( (BU/apo)*(CU/apo) , 2.0 ) - pow( (AU/apo)*(BU/apo), 2.0 ) ) / ( pow( (BU/apo)*dir.x, 2.0 ) + pow( (AU/apo)*dir.y, 2.0 ) ); + scale = first + sqrt( second - third); + } + + vec2 max = dir * scale; + vec2 min = max * (apo_inner/apo); - vec4 diffuse = texture(texture1, texCoord); + float distance1 = distance(max, min); + float distance2 = distance(max, st); + float textureCoord = distance2/distance1; + + vec4 diffuse = texture(texture1, textureCoord); float colorValue = length(diffuse.rgb); // times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want // to normalize the transparency value to [0,1] From e09f449c05e30f28dea972764cac03effece8f16 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 5 Nov 2018 15:34:42 +0100 Subject: [PATCH 045/123] comment change --- modules/exoplanets/rendering/renderableorbitdisc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index 8ddc4be64d..a1eb1bd7a9 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -84,4 +84,4 @@ private: } // namespace openspace -#endif // __OPENSPACE_MODULE_SPACE___RENDERABLERINGS___H__ +#endif // __OPENSPACE_MODULE_EXOPLENETS___RENDERABLEORBITDISC___H__ From 7fc61f2f1c9839b358d02a845193d1b5efef66c5 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 5 Nov 2018 15:35:36 +0100 Subject: [PATCH 046/123] Increased span for size gui slider --- modules/exoplanets/rendering/renderableorbitdisc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index fdadad8feb..91fb9b912f 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -48,7 +48,7 @@ namespace { static const openspace::properties::Property::PropertyInfo SizeInfo = { "Size", "Size", - "This value specifies the semi-major axis of teh orbit in meter." + "This value specifies the semi-major axis of the orbit in meter." }; static const openspace::properties::Property::PropertyInfo EccentricityInfo = { @@ -122,7 +122,7 @@ documentation::Documentation RenderableOrbitdisc::Documentation() { RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _texturePath(TextureInfo) - , _size(SizeInfo, 1.f, 0.f, 3.0e11f) + , _size(SizeInfo, 1.f, 0.f, 3.0e12f) , _eccentricity(EccentricityInfo, 0.f, 0.f, 1.f) , _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f)) , _transparency(TransparencyInfo, 0.15f, 0.f, 1.f) From 4c91ece7fce0148dd286d7a7a6f9627a77581527 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 5 Nov 2018 15:59:09 +0100 Subject: [PATCH 047/123] Planet name made up from STAR + COMP instead of taken from NAME and highest default value for B-V changed --- .../exoplanets/tasks/exoplanetscsvtobintask.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index ebb82d47e7..8924a3ccc6 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -221,14 +221,13 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); std::ofstream lut_file(_outputLUTPath); - std::ofstream bmv_file(absPath("${BASE}/modules/exoplanets/bmv.txt")); - int version = 1; bin_file.write((char *)&version, sizeof(int)); Exoplanet p; std::string planetname; + std::string component; std::string planet_row; getline(csv_file, planet_row); // The first line, containing the data names @@ -310,6 +309,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb p.BMV = NAN; getline(lineStream, data_s, ','); // CHI2 getline(lineStream, data_s, ','); // COMP + component = data_s; getline(lineStream, data_s, ','); // DATE getline(lineStream, data_s, ','); // DEC getline(lineStream, data_s, ','); // DEC_STRING @@ -472,8 +472,6 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data_s, ','); // MSTARURL getline(lineStream, data_s, ','); // MULT getline(lineStream, data_s, ','); // NAME - planetname = data_s; - getline(lineStream, data_s, ','); // NCOMP if (!data_s.empty()) p.NCOMP = std::stoi(data_s.c_str(), nullptr); @@ -678,8 +676,8 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data_s, ','); // SPECREF getline(lineStream, data_s, ','); // SPECURL getline(lineStream, data_s, ','); // STAR - std::string starname = getExplName(data_s); - glm::vec3 pos = getStarPosition(starname); + std::string speckStarname = getExplName(data_s); + glm::vec3 pos = getStarPosition(speckStarname); p.POSITIONX = pos[0]; p.POSITIONY = pos[1]; p.POSITIONZ = pos[2]; @@ -790,7 +788,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb bv_upper = std::stof(bv_string.c_str(), nullptr); if (bv_lower == 0) { - BV = 1.45; + BV = 2.00; } else BV = (((bv_upper - bv_lower)*(teff - teff_lower)) / (teff_upper - teff_lower)) + bv_lower; @@ -808,17 +806,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb } long pos = bin_file.tellp(); + planetname = speckStarname + " " + component; lut_file << planetname << "," << pos << std::endl; bin_file.write((char *)&p, sizeof(struct Exoplanet)); - bmv_file << planetname << " " << p.ECC << " " << p.ECCLOWER << " " << p.ECCUPPER << std::endl; } } csv_file.close(); bin_file.close(); lut_file.close(); - bmv_file.close(); progressCallback(1.0f); } From 2c73ad78a79cfec111adb4a9b0f4c9492b6739e5 Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 6 Nov 2018 16:37:40 +0100 Subject: [PATCH 048/123] Using only NASA Exoplent Archive starnames for display and correction of local coordinate system --- modules/exoplanets/exoplanetsmodule_lua.inl | 147 ++++++++++++++++---- 1 file changed, 122 insertions(+), 25 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 818cb0f1f6..2ceaec9ec8 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -91,6 +91,100 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm: //return std::to_string(orbitPlaneRotation); } +std::string getSpeckStarname(std::string csvName) { + std::string explName = csvName; + if (csvName == "HD 1237") + explName = "GJ 3021"; + else if (csvName == "MOA-2009-BLG-387L") + explName = "MOA 2009-BLG-387L"; + else if (csvName == "HD 126614 A") + explName = "HD 126614"; + else if (csvName == "epsilon Ret") + explName = "HD 27442"; + else if (csvName == "PH-1") + explName = "PH1"; + else if (csvName == "gamma Leo A") + explName = "gam 1 Leo"; + else if (csvName == "OGLE-2007-BLG-368L") + explName = "OGLE 2007-BLG-368L"; + else if (csvName == "alpha Ari") + explName = "alf Ari"; + else if (csvName == "mu Ara") + explName = "HD 160691"; + else if (csvName == "OGLE-05-169L") + explName = "OGLE 2005-BLG-169L"; + else if (csvName == "tau Gru") + explName = "HD 216435"; + else if (csvName == "iota Hor") + explName = "HR 810"; + else if (csvName == "OGLE-05-071L") + explName = "OGLE 2005-BLG-71L"; + else if (csvName == "OGLE235-MOA53") + explName = "OGLE 2003-BLG-235L"; + else if (csvName == "MOA-2008-BLG-310L") + explName = "MOA 2008-BLG-310L"; + else if (csvName == "KIC 11442793") + explName = "KOI-351"; + else if (csvName == "OGLE-2006-BLG-109L") + explName = "OGLE 2006-BLG-109L"; + else if (csvName == "HD 137388") + explName = "HD 137388 A"; + else if (csvName == "kappa CrB") + explName = "kap CrB"; + else if (csvName == "XO-2") + explName = "XO-2 N"; + else if (csvName == "epsilon Tau") + explName = "eps Tau"; + else if (csvName == "epsilon Eri") + explName = "eps Eri"; + else if (csvName == "Kepler-448") + explName = "KOI-12"; + else if (csvName == "omega Ser") + explName = "ome Ser"; + else if (csvName == "MOA-2010-BLG-477L") + explName = "MOA 2010-BLG-477L"; + else if (csvName == "GJ 176") + explName = "HD 285968"; + else if (csvName == "HIP 2247") + explName = "BD-17 63"; + else if (csvName == "MOA-2009-BLG-266L") + explName = "MOA 2009-BLG-266L"; + else if (csvName == "Kepler-89") + explName = "KOI-94"; + else if (csvName == "iota Dra") + explName = "HIP 75458"; + else if (csvName == "MOA-2007-BLG-400L") + explName = "MOA 2007-BLG-400L"; + else if (csvName == "upsilon And") + explName = "ups And"; + else if (csvName == "OGLE-2011-BLG-0251") + explName = "OGLE 2011-BLG-251L"; + else if (csvName == "OGLE-05-390L") + explName = "OGLE 2005-BLG-390L"; + else if (csvName == "Kepler-420") + explName = "KOI-1257"; + else if (csvName == "beta Pic") + explName = "bet Pic"; + else if (csvName == "gamma Cep") + explName = "gam Cep"; + else if (csvName == "MOA-2007-BLG-192L") + explName = "MOA 2007-BLG-192L"; + else if (csvName == "MOA-2009-BLG-319L") + explName = "MOA 2009-BLG-319L"; + else if (csvName == "omicron CrB") + explName = "omi CrB"; + else if (csvName == "beta Gem") + explName = "HD 62509"; + else if (csvName == "epsilon CrB") + explName = "eps CrB"; + else if (csvName == "omicron UMa") + explName = "omi UMa"; + else if (csvName == "HD 142022") + explName = "HD 142022 A"; + + return explName; +} + std::string getCsvStarname(std::string explName) { std::string csvName = explName; if (explName == "GJ 3021") @@ -230,10 +324,12 @@ int addExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); - OsEng.moduleEngine().module()->setStarName(starname); + //change expl-starname to exoplanet.csv-starname + std::string starname_csv = getCsvStarname(starname); + // If user have given name as in EOD, change it to speck-name + std::string starname_speck = getSpeckStarname(starname); - //change expl-starname to exoplanet.csv-starname - std::string starname_csv = getCsvStarname(starname); + OsEng.moduleEngine().module()->setStarName(starname_speck); std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); if (!data.good()) { @@ -261,7 +357,7 @@ int addExoplanetSystem(lua_State* L) { std::istringstream ss(line); getline(ss, planetname, ','); - if (planetname.compare(0, planetname.length() - 2, starname_csv) == 0) { + if (planetname.compare(0, planetname.length() - 2, starname_speck) == 0) { std::string location_s; getline(ss, location_s); long location = std::stol(location_s.c_str()); @@ -305,13 +401,14 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); OsEng.moduleEngine().module()->setNorthVector(northProjected); - glm::dvec3 beta = normalize(cross(northProjected, starToSunVec)); - glm::dmat3 exoplanetSystemRot = glm::dmat3(starToSunVec.x, starToSunVec.y, starToSunVec.z, - beta.x, beta.y, beta.z, - northProjected.x, northProjected.y, northProjected.z); + glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); + + glm::dmat3 exoplanetSystemRot = glm::dmat3(northProjected.x, northProjected.y, northProjected.z, + beta.x, beta.y, beta.z, + starToSunVec.x, starToSunVec.y, starToSunVec.z); const std::string starParent = "{" - "Identifier = '" + starname + "'," + "Identifier = '" + starname_speck + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" "Rotation = {" @@ -358,8 +455,8 @@ int addExoplanetSystem(lua_State* L) { else sepoch_star = "2009-05-19T07:11:34.080"; const std::string starGlobe = "{" - "Identifier = '" + starname + "Globe'," - "Parent = '" + starname + "'," + "Identifier = '" + starname_speck + "Globe'," + "Parent = '" + starname_speck + "'," "Renderable = {" "Type = 'RenderableGlobe'," "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," @@ -376,7 +473,7 @@ int addExoplanetSystem(lua_State* L) { "}," "{" "Identifier = 'StarTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg'," + "FilePath = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/sun.jpg'," "BlendMode = 'Color'," "Enabled = true" "}" @@ -410,8 +507,8 @@ int addExoplanetSystem(lua_State* L) { //script = ""; //const std::string starGlare = "{" - // "Identifier = '" + starname + "Glare'," - // "Parent = '" + starname + "'," + // "Identifier = '" + starname_speck + "Glare'," + // "Parent = '" + starname_speck + "'," // "Renderable = {" // "Type = 'RenderablePlaneImageLocal'," // "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m @@ -474,7 +571,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planet = "{" "Identifier = '" + plna[i] + "'," - "Parent = '" + starname + "'," + "Parent = '" + starname_speck + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableGlobe'," @@ -486,7 +583,7 @@ int addExoplanetSystem(lua_State* L) { "ColorLayers = {" "{" "Identifier = 'ExoplanetTexture'," - "FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg'," + "FilePath = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/data/test3.jpg'," "Enabled = true" "}" "}" @@ -523,7 +620,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planetTrail = "{" "Identifier = '" + plna[i] + "Trail'," - "Parent = '" + starname + "'," + "Parent = '" + starname_speck + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableTrailOrbit'," @@ -558,11 +655,11 @@ int addExoplanetSystem(lua_State* L) { OsEng.moduleEngine().module()->setRotation(rot); const std::string disc = "{" "Identifier = '" + plna[i] + "Disc'," - "Parent = '" + starname + "'," + "Parent = '" + starname_speck + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/disc.png'," + "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/disc3.png'," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(plsy[i].ECC) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend @@ -590,10 +687,10 @@ int addExoplanetSystem(lua_State* L) { } const std::string discECCLOWER = "{" "Identifier = '" + plna[i] + "discECCLOWER'," - "Parent = '" + starname + "'," + "Parent = '" + starname_speck + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discL.png'," + "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/discL.png'," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(lower_ecc) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend @@ -621,10 +718,10 @@ int addExoplanetSystem(lua_State* L) { } const std::string discECCUPPER = "{" "Identifier = '" + plna[i] + "discECCUPPER'," - "Parent = '" + starname + "'," + "Parent = '" + starname_speck + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/discU.png'," + "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/discU.png'," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(upper_ecc) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend @@ -662,8 +759,8 @@ int addExoplanetSystem(lua_State* L) { int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); - - std::string script = "openspace.removeSceneGraphNode('" + starname + "');"; + std::string starname_speck = getSpeckStarname(starname); + std::string script = "openspace.removeSceneGraphNode('" + starname_speck + "');"; OsEng.scriptEngine().queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes From 316aae1e48a75a4a34c148705e4b28fff524d50d Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 6 Nov 2018 16:41:04 +0100 Subject: [PATCH 049/123] Placing ascending node so it's where the planet is moving away from the observer --- modules/exoplanets/exoplanetsmodule_lua.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 2ceaec9ec8..e7f882ba01 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -441,7 +441,7 @@ int addExoplanetSystem(lua_State* L) { } if (isnan(plsy[0].BIGOM)) { - plsy[0].BIGOM = 0; + plsy[0].BIGOM = 180; } if (isnan(plsy[0].OM)) { @@ -542,7 +542,7 @@ int addExoplanetSystem(lua_State* L) { } if (isnan(plsy[i].BIGOM)) { - plsy[i].BIGOM = 0; + plsy[i].BIGOM = 180; } if (isnan(plsy[i].OM)) { From 991a287f6e041bab156aefcf00a784f61217fec1 Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 6 Nov 2018 16:59:45 +0100 Subject: [PATCH 050/123] Default value for planet radius --- modules/exoplanets/exoplanetsmodule_lua.inl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index e7f882ba01..d6af253a0c 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -560,12 +560,18 @@ int addExoplanetSystem(lua_State* L) { std::string enabled = ""; if (isnan(plsy[i].R)) { - planetradius = plsy[i].RSTAR; + if (isnan(plsy[i].RSTAR)) { + planetradius = plsy[i].A * 149597870700 * 0.001; + } + else { + planetradius = plsy[i].RSTAR *6.95700E8 *0.1; + } + enabled = "false"; } else { - planetradius = plsy[i].R; + planetradius = plsy[i].R *7.1492E7; enabled = "true"; } @@ -576,7 +582,7 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableGlobe'," "Enabled = " + enabled + "," - "Radii = " + std::to_string(planetradius) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m + "Radii = " + std::to_string(planetradius) + "," //R. in meters. 1 jupiter radii = 7.1492×10e7 m "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" From 5d2d1b474aa31c187acaccfa4021e6f7ebcea20d Mon Sep 17 00:00:00 2001 From: KarRei Date: Tue, 6 Nov 2018 17:03:09 +0100 Subject: [PATCH 051/123] Changed apperance of trail and disc --- modules/exoplanets/exoplanetsmodule_lua.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index d6af253a0c..56e59dea04 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -643,7 +643,7 @@ int addExoplanetSystem(lua_State* L) { "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. "}," - "Color = { 1, 0, 0 }" + "Color = { 1, 1, 1 }" "}," "}"; @@ -669,7 +669,7 @@ int addExoplanetSystem(lua_State* L) { "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(plsy[i].ECC) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.99" + "Transparency = 0.5" "}," "Transform = {" "Rotation = {" From 10ddabdc40eb6a5a51df9479829c1406b0c4575a Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 19 Nov 2018 21:04:25 +0100 Subject: [PATCH 052/123] OsEng -> global --- .../discoverymethods/discoverymethods.cpp | 82 +++++++++---------- modules/exoplanets/exoplanetsmodule.cpp | 25 +++--- modules/exoplanets/exoplanetsmodule_lua.inl | 43 +++++----- .../rendering/renderableorbitdisc.cpp | 7 +- 4 files changed, 82 insertions(+), 75 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 8af369f982..0f96f2798f 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -25,8 +25,8 @@ #include #include +#include #include -#include #include #include #include @@ -34,6 +34,7 @@ #include #include #include +#include #include namespace { @@ -91,7 +92,7 @@ namespace openspace::exoplanets{ "}," "}"; std::string script = "openspace.addSceneGraphNode(" + markerView + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -125,14 +126,14 @@ namespace openspace::exoplanets{ "}"; script = ""; script = "openspace.addSceneGraphNode(" + markerNorth + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } void DiscoveryMethods::removeDirectionsMarkers() { std::string script = "openspace.removeSceneGraphNode('markerView'); openspace.removeSceneGraphNode('markerNorth');"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -160,7 +161,7 @@ namespace openspace::exoplanets{ "}" ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -191,7 +192,7 @@ namespace openspace::exoplanets{ "EuclideanPosition = {-0.05, -0.65}" "});"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -201,7 +202,7 @@ namespace openspace::exoplanets{ void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -209,15 +210,14 @@ namespace openspace::exoplanets{ void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } void DiscoveryMethods::toggleVisabilityOuterPlanets(std::vector planetNames, std::string visability) { - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - //std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + std::vector planets = global::moduleEngine.module()->getPlsy(); if (planetNames.size()>1) { @@ -236,7 +236,7 @@ namespace openspace::exoplanets{ script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Disc.renderable.Enabled', " + visability + "); "; } - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -246,7 +246,7 @@ namespace openspace::exoplanets{ void DiscoveryMethods::toggleVisabilityPlanet(std::string nodeName, std::string visability) { std::string script = "openspace.setPropertyValueSingle( 'Scene." +nodeName + ".RenderableGlobe.Enabled', " + visability + "); "; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -254,9 +254,9 @@ namespace openspace::exoplanets{ void DiscoveryMethods::moveCamera(glm::dvec3 pos) { - Camera* cam = OsEng.navigationHandler().camera(); + Camera* cam = global::navigationHandler.camera(); cam->setPositionVec3(pos); - OsEng.navigationHandler().resetCameraDirection(); + global::navigationHandler.resetCameraDirection(); } bool DiscoveryMethods::isDoppler() { @@ -271,7 +271,7 @@ namespace openspace::exoplanets{ void DiscoveryMethods::setDopplerImagePos(float value) { std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -279,19 +279,19 @@ namespace openspace::exoplanets{ void DiscoveryMethods::setTransitImagePos(float valueX,float valueY) { std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.Transit2.EuclideanPosition', {" + std::to_string(valueX) + "," + std::to_string(valueY) + "}); "; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } void DiscoveryMethods::addDopplerMethodVisualization() { - SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); - std::string starName = OsEng.moduleEngine().module()->getStarName(); // getStarName + SceneGraphNode* focusNode = global::navigationHandler.focusNode(); + std::string starName = global::moduleEngine.module()->getStarName(); // getStarName glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + std::vector planets = global::moduleEngine.module()->getPlsy(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); float semiMajorAxis = planets[0].A; // in AU float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis @@ -302,7 +302,7 @@ namespace openspace::exoplanets{ } float starRadius = planets[0].RSTAR; // in Solar Radii - glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); + glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); // MOVE CAMERA glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); @@ -345,9 +345,9 @@ namespace openspace::exoplanets{ } void DiscoveryMethods::removeDopplerMethodVisualization() { - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::string starName = global::moduleEngine.module()->getStarName(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); + std::vector planets = global::moduleEngine.module()->getPlsy(); //SCALE STAR AND PLANET scaleNode(starName + "Globe", 1.0); @@ -366,7 +366,7 @@ namespace openspace::exoplanets{ // HIDE GRAPHS std::string script = "openspace.removeScreenSpaceRenderable('DopplerShift1'); openspace.removeScreenSpaceRenderable('DopplerShift2');"; - OsEng.scriptEngine().queueScript( + global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -377,12 +377,12 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addTransitMethodVisualization() { - SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode(); - std::string starName = OsEng.moduleEngine().module()->getStarName(); // getStarName + SceneGraphNode* focusNode = global::navigationHandler.focusNode(); + std::string starName = global::moduleEngine.module()->getStarName(); // getStarName glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + std::vector planets = global::moduleEngine.module()->getPlsy(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) float eccentricity = planets[0].ECC; @@ -394,7 +394,7 @@ namespace openspace::exoplanets{ // MOVE CAMERA //borde kanske va periapsis distance, men det gÃ¥r bra ändÃ¥ - glm::dvec3 north = OsEng.moduleEngine().module()->getNorthVector(); + glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); //glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * starToSunVec); //glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * faceOnVector); @@ -428,15 +428,15 @@ namespace openspace::exoplanets{ // END MARKERS } void DiscoveryMethods::removeTransitMethodVisualization() { - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); //SCALE STAR AND PLANET - std::string starName = OsEng.moduleEngine().module()->getStarName(); + std::string starName = global::moduleEngine.module()->getStarName(); scaleNode(starName + "Globe", 1); scaleNode(planetNames[0], 1); // REMOVE GRAPH std::string script = "openspace.removeScreenSpaceRenderable('Transit3');openspace.removeScreenSpaceRenderable('Transit2');openspace.removeScreenSpaceRenderable('Transit1');"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -448,9 +448,9 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addSolarSystemReferenceVisualization() { - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); + std::string starName = global::moduleEngine.module()->getStarName(); + std::vector planets = global::moduleEngine.module()->getPlsy(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); // SUN const std::string sunRef = "{" @@ -472,7 +472,7 @@ namespace openspace::exoplanets{ "}"; std::string script = "openspace.addSceneGraphNode(" + sunRef + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -499,14 +499,14 @@ namespace openspace::exoplanets{ "}"; script = ""; script = "openspace.addSceneGraphNode(" + earthRef + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - glm::dmat3 rotation = OsEng.moduleEngine().module()->getRotation(); + glm::dmat3 rotation = global::moduleEngine.module()->getRotation(); // ORBIT const std::string orbitRef = "{" "Identifier = 'OrbitReference'," @@ -527,7 +527,7 @@ namespace openspace::exoplanets{ "}"; script = ""; script = "openspace.addSceneGraphNode(" + orbitRef + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -537,7 +537,7 @@ namespace openspace::exoplanets{ std::string script = "openspace.removeSceneGraphNode('SunReference');" "openspace.removeSceneGraphNode('EarthReference');" "openspace.removeSceneGraphNode('OrbitReference');"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index ef136bc87a..62d03d4373 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -26,7 +26,8 @@ #include #include -#include +#include +#include #include #include @@ -121,20 +122,20 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { fTask->registerClass("ExoplanetsCsvToBinTask"); fRenderable->registerClass("RenderableOrbitdisc"); - OsEng.registerModuleCallback(OpenSpaceEngine::CallbackOption::Initialize, [&] { + global::callback::initializeGL.push_back([&]() { _discoveryMethods = std::make_unique(); addPropertySubOwner(*_discoveryMethods); }); // Render - OsEng.registerModuleCallback(OpenSpaceEngine::CallbackOption::Render, [&] { + global::callback::render.push_back([&]() { if (_discoveryMethods->isDoppler()) { - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); - SceneGraphNode* planetNode = OsEng.renderEngine().scene()->sceneGraphNode(planetNames[0]); - SceneGraphNode* starNode = OsEng.renderEngine().scene()->sceneGraphNode(starName); + std::string starName = global::moduleEngine.module()->getStarName(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); + SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); + SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); glm::dvec3 planetPos = planetNode->worldPosition(); glm::dvec3 starPos = starNode->worldPosition(); glm::dvec3 starToPosVec = normalize(planetPos - starPos); @@ -168,17 +169,17 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { } if (_discoveryMethods->isTransit()) { - std::string starName = OsEng.moduleEngine().module()->getStarName(); - std::vector planetNames = OsEng.moduleEngine().module()->getPlna(); - SceneGraphNode* planetNode = OsEng.renderEngine().scene()->sceneGraphNode(planetNames[0]); - SceneGraphNode* starNode = OsEng.renderEngine().scene()->sceneGraphNode(starName); + std::string starName = global::moduleEngine.module()->getStarName(); + std::vector planetNames = global::moduleEngine.module()->getPlna(); + SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); + SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); glm::dvec3 planetPos = planetNode->worldPosition(); glm::dvec3 starPos = starNode->worldPosition(); glm::dvec3 starToPosVec = planetPos - starPos; glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPos); - std::vector planets = OsEng.moduleEngine().module()->getPlsy(); + std::vector planets = global::moduleEngine.module()->getPlsy(); float starRadius = planets[0].RSTAR * 6.957E8 * _discoveryMethods->getTransitScaleFactor(); // in m glm::dvec3 north = _north; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 56e59dea04..26f202b320 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -22,17 +22,21 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include #include #include +#include +#include #include #include +#include #include #include #include #include +#include +#include namespace openspace{ @@ -329,7 +333,7 @@ int addExoplanetSystem(lua_State* L) { // If user have given name as in EOD, change it to speck-name std::string starname_speck = getSpeckStarname(starname); - OsEng.moduleEngine().module()->setStarName(starname_speck); + global::moduleEngine.module()->setStarName(starname_speck); std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); if (!data.good()) { @@ -374,9 +378,9 @@ int addExoplanetSystem(lua_State* L) { data.close(); lut.close(); - OsEng.moduleEngine().module()->setPlna(plna); - OsEng.moduleEngine().module()->setPlsy(plsy); - OsEng.moduleEngine().module()->setClosestExoplanet(p); + global::moduleEngine.module()->setPlna(plna); + global::moduleEngine.module()->setPlsy(plsy); + global::moduleEngine.module()->setClosestExoplanet(p); if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY { @@ -397,9 +401,9 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 celestialNorth = normalize(galaxticToCelectialMatrix * galacticNorth); - // Earths north vector (0,0,1) projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) + // Earths north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); - OsEng.moduleEngine().module()->setNorthVector(northProjected); + global::moduleEngine.module()->setNorthVector(northProjected); glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); @@ -423,7 +427,7 @@ int addExoplanetSystem(lua_State* L) { "}"; script = "openspace.addSceneGraphNode(" + starParent + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -500,7 +504,7 @@ int addExoplanetSystem(lua_State* L) { "}"; script = ""; script = " openspace.addSceneGraphNode(" + starGlobe + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -519,9 +523,9 @@ int addExoplanetSystem(lua_State* L) { // "}"; // //script = "openspace.addSceneGraphNode(" + starGlare + ");"; - //OsEng.scriptEngine().queueScript( + //global::scriptEngine.queueScript( // script, - // openspace::scripting::ScriptEngine::RemoteScripting::Yes + // scripting::ScriptEngine::RemoteScripting::Yes //); } @@ -615,7 +619,7 @@ int addExoplanetSystem(lua_State* L) { "}"; script = "openspace.addSceneGraphNode(" + planet + ");"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -647,7 +651,7 @@ int addExoplanetSystem(lua_State* L) { "}," "}"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + planetTrail + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -658,7 +662,7 @@ int addExoplanetSystem(lua_State* L) { glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); //glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); // , exoplanetSystemRot); glm::dmat3 rot = orbitPlaneRotationMatrix; - OsEng.moduleEngine().module()->setRotation(rot); + global::moduleEngine.module()->setRotation(rot); const std::string disc = "{" "Identifier = '" + plna[i] + "Disc'," "Parent = '" + starname_speck + "'," @@ -678,7 +682,7 @@ int addExoplanetSystem(lua_State* L) { "}" "}," "}"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + disc + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -712,7 +716,7 @@ int addExoplanetSystem(lua_State* L) { "}"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + discECCLOWER + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -743,7 +747,7 @@ int addExoplanetSystem(lua_State* L) { "}"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + discECCUPPER + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); @@ -759,6 +763,7 @@ int addExoplanetSystem(lua_State* L) { printf("No star with that name or not enough data about it."); } + return 0; } @@ -767,9 +772,9 @@ int removeExoplanetSystem(lua_State* L) { const std::string starname = luaL_checkstring(L, StringLocation); std::string starname_speck = getSpeckStarname(starname); std::string script = "openspace.removeSceneGraphNode('" + starname_speck + "');"; - OsEng.scriptEngine().queueScript( + openspace::global::scriptEngine.queueScript( script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes + scripting::ScriptEngine::RemoteScripting::Yes ); return 0; diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 91fb9b912f..e962f3d92a 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -26,11 +26,12 @@ #include #include -#include +#include #include #include #include +#include #include #include #include @@ -178,7 +179,7 @@ bool RenderableOrbitdisc::isReady() const { } void RenderableOrbitdisc::initializeGL() { - _shader = OsEng.renderEngine().buildRenderProgram( + _shader = global::renderEngine.buildRenderProgram( "OrbitdiscProgram", absPath("${BASE}/modules/exoplanets/shaders/orbitdisc_vs.glsl"), absPath("${BASE}/modules/exoplanets/shaders/orbitdisc_fs.glsl") @@ -211,7 +212,7 @@ void RenderableOrbitdisc::deinitializeGL() { _textureFile = nullptr; _texture = nullptr; - OsEng.renderEngine().removeRenderProgram(_shader.get()); + global::renderEngine.removeRenderProgram(_shader.get()); _shader = nullptr; } From eb3f7b9559cab0369e87e16c0e754c589b4f2761 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 6 Dec 2018 15:30:01 -0500 Subject: [PATCH 053/123] Adapt hardcoded paths Don't crash when adding new scenegraphnodes --- apps/TaskRunner/main.cpp | 1 + include/openspace/engine/openspaceengine.h | 4 ++- .../discoverymethods/discoverymethods.cpp | 6 ++-- modules/exoplanets/exoplanetsmodule_lua.inl | 22 +++++++++----- .../tasks/exoplanetscsvtobintask.cpp | 11 +++++++ src/engine/openspaceengine.cpp | 5 ++-- src/scene/sceneinitializer.cpp | 29 +++++++++++-------- 7 files changed, 51 insertions(+), 27 deletions(-) diff --git a/apps/TaskRunner/main.cpp b/apps/TaskRunner/main.cpp index 9088490c48..c6bb3db9b0 100644 --- a/apps/TaskRunner/main.cpp +++ b/apps/TaskRunner/main.cpp @@ -108,6 +108,7 @@ int main(int argc, char** argv) { std::string configFile = configuration::findConfiguration(); global::configuration = configuration::loadConfigurationFromFile(configFile); + openspace::global::openSpaceEngine.registerPathTokens(); global::openSpaceEngine.initialize(); diff --git a/include/openspace/engine/openspaceengine.h b/include/openspace/engine/openspaceengine.h index 42c4245eea..913d40f569 100644 --- a/include/openspace/engine/openspaceengine.h +++ b/include/openspace/engine/openspaceengine.h @@ -88,7 +88,9 @@ public: // Guaranteed to return a valid pointer AssetManager& assetManager(); - LoadingScreen& loadingScreen(); + + // Could be nullptr (and will be after startup) + LoadingScreen* loadingScreen(); void writeSceneDocumentation(); void writeStaticDocumentation(); diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 0f96f2798f..dc94b983e2 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -460,7 +460,7 @@ namespace openspace::exoplanets{ "Type = 'RenderablePlaneImageLocal'," "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," "BlendMode = 'Additive'" "}," "Transform = {" @@ -487,7 +487,7 @@ namespace openspace::exoplanets{ "Type = 'RenderablePlaneImageLocal'," "Size = 6378137," // in meters "Billboard = true," - "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," "BlendMode = 'Additive'" "}," "Transform = {" @@ -515,7 +515,7 @@ namespace openspace::exoplanets{ "Type = 'RenderablePlaneImageLocal'," "Size = 1.496E11," // earths semi-major axis in m "Billboard = false," - "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/target-blue-ring.png'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," "BlendMode = 'Additive'" "}," "Transform = {" diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 26f202b320..07957189b4 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -43,7 +43,7 @@ namespace openspace{ std::string getStarColor(float bv) { std::string colorString; - std::ifstream colormap(absPath("${BASE}/modules/exoplanets/colorbv.cmap"), std::ios::in); + std::ifstream colormap(absPath("${MODULE_EXOPLANETS}/colorbv.cmap"), std::ios::in); if (!colormap.good()) { std::cout << "Failed to open colormap data file"; } @@ -332,15 +332,16 @@ int addExoplanetSystem(lua_State* L) { std::string starname_csv = getCsvStarname(starname); // If user have given name as in EOD, change it to speck-name std::string starname_speck = getSpeckStarname(starname); + std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); global::moduleEngine.module()->setStarName(starname_speck); - std::ifstream data(absPath("${BASE}/modules/exoplanets/expl_data.bin"), std::ios::in | std::ios::binary); + std::ifstream data(absPath("${MODULE_EXOPLANETS}/expl_data.bin"), std::ios::in | std::ios::binary); if (!data.good()) { std::cout << "Failed to open exoplanets data file"; } - std::ifstream lut(absPath("${BASE}/modules/exoplanets/lookup.txt")); + std::ifstream lut(absPath("${MODULE_EXOPLANETS}/lookup.txt")); if (!lut.good()) { std::cout << "Failed to open exoplanets look-up table file"; } @@ -411,6 +412,9 @@ int addExoplanetSystem(lua_State* L) { beta.x, beta.y, beta.z, starToSunVec.x, starToSunVec.y, starToSunVec.z); + std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); + + const std::string starParent = "{" "Identifier = '" + starname_speck + "'," "Parent = 'SolarSystemBarycenter'," @@ -458,6 +462,7 @@ int addExoplanetSystem(lua_State* L) { } else sepoch_star = "2009-05-19T07:11:34.080"; + const std::string starGlobe = "{" "Identifier = '" + starname_speck + "Globe'," "Parent = '" + starname_speck + "'," @@ -477,7 +482,7 @@ int addExoplanetSystem(lua_State* L) { "}," "{" "Identifier = 'StarTexture'," - "FilePath = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/sun.jpg'," + "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," "BlendMode = 'Color'," "Enabled = true" "}" @@ -593,7 +598,7 @@ int addExoplanetSystem(lua_State* L) { "ColorLayers = {" "{" "Identifier = 'ExoplanetTexture'," - "FilePath = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/data/test3.jpg'," + "FilePath = openspace.absPath('${DATA}/test3.jpg')," "Enabled = true" "}" "}" @@ -669,7 +674,7 @@ int addExoplanetSystem(lua_State* L) { "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/disc3.png'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(plsy[i].ECC) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend @@ -700,7 +705,7 @@ int addExoplanetSystem(lua_State* L) { "Parent = '" + starname_speck + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/discL.png'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(lower_ecc) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend @@ -731,7 +736,7 @@ int addExoplanetSystem(lua_State* L) { "Parent = '" + starname_speck + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = 'C:/Users/Karin/Documents/LiU/Exjobb/clone_to_branch/OpenSpace/modules/exoplanets/discU.png'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A "Eccentricity = " + std::to_string(upper_ecc) + "," "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend @@ -771,6 +776,7 @@ int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starname = luaL_checkstring(L, StringLocation); std::string starname_speck = getSpeckStarname(starname); + std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); std::string script = "openspace.removeSceneGraphNode('" + starname_speck + "');"; openspace::global::scriptEngine.queueScript( script, diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 8924a3ccc6..d23a553f1c 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -233,8 +233,19 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::string data_s; bool iskeplerobject = false; + int total = 0; + while (getline(csv_file, planet_row)) { + ++total; + } + csv_file.clear(); + csv_file.seekg(0); + getline(csv_file, planet_row); // The first line, containing the data names + LINFOC("CSVTOBIN", fmt::format("Loading {} stars", total)); + int count = 0; while (getline(csv_file, planet_row)) { + ++count; + progressCallback(static_cast(count) / static_cast(total)); std::istringstream lineStream(planet_row); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index dbd99f0c21..9a4b405a73 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1349,9 +1349,8 @@ scripting::LuaLibrary OpenSpaceEngine::luaLibrary() { }; } -LoadingScreen& OpenSpaceEngine::loadingScreen() { - ghoul_assert(_loadingScreen, "Loading Screen must not be nullptr"); - return *_loadingScreen; +LoadingScreen* OpenSpaceEngine::loadingScreen() { + return _loadingScreen.get(); } AssetManager& OpenSpaceEngine::assetManager() { diff --git a/src/scene/sceneinitializer.cpp b/src/scene/sceneinitializer.cpp index 9a220bf2c4..03e8b01db3 100644 --- a/src/scene/sceneinitializer.cpp +++ b/src/scene/sceneinitializer.cpp @@ -52,11 +52,14 @@ MultiThreadedSceneInitializer::MultiThreadedSceneInitializer(unsigned int nThrea void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { auto initFunction = [this, node]() { - LoadingScreen& loadingScreen = global::openSpaceEngine.loadingScreen(); + LoadingScreen* loadingScreen = global::openSpaceEngine.loadingScreen(); + if (!loadingScreen) { + return; + } LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = 1.f; - loadingScreen.updateItem( + loadingScreen->updateItem( node->identifier(), node->guiName(), LoadingScreen::ItemStatus::Initializing, @@ -68,7 +71,7 @@ void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { _initializedNodes.push_back(node); _initializingNodes.erase(node); - loadingScreen.updateItem( + loadingScreen->updateItem( node->identifier(), node->guiName(), LoadingScreen::ItemStatus::Finished, @@ -79,16 +82,18 @@ void MultiThreadedSceneInitializer::initializeNode(SceneGraphNode* node) { LoadingScreen::ProgressInfo progressInfo; progressInfo.progress = 0.f; - LoadingScreen& loadingScreen = global::openSpaceEngine.loadingScreen(); - loadingScreen.setItemNumber(loadingScreen.itemNumber() + 1); - loadingScreen.updateItem( - node->identifier(), - node->guiName(), - LoadingScreen::ItemStatus::Started, - progressInfo - ); + LoadingScreen* loadingScreen = global::openSpaceEngine.loadingScreen(); + if (loadingScreen) { + loadingScreen->setItemNumber(loadingScreen->itemNumber() + 1); + loadingScreen->updateItem( + node->identifier(), + node->guiName(), + LoadingScreen::ItemStatus::Started, + progressInfo + ); + } - std::lock_guard g(_mutex); + std::lock_guard g(_mutex); _initializingNodes.insert(node); _threadPool.enqueue(initFunction); } From 939210465ec30cd576cd080dde49aacba7502e5b Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Sat, 4 May 2019 15:42:25 +0200 Subject: [PATCH 054/123] updated to_string for ghoul namespace --- .../exoplanets/discoverymethods/discoverymethods.cpp | 9 ++++++--- modules/exoplanets/exoplanetsmodule_lua.inl | 12 ++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index dc94b983e2..bb59cbb367 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -37,6 +37,9 @@ #include #include +#include + + namespace { constexpr const char* _loggerCat = "DiscoveryMethods"; @@ -87,7 +90,7 @@ namespace openspace::exoplanets{ "Transform = {" "Translation = {" "Type = 'StaticTranslation'," - "Position = " + std::to_string(viewDirecionPos) + "," + "Position = " + ghoul::to_string(viewDirecionPos) + "," "}," "}," "}"; @@ -120,7 +123,7 @@ namespace openspace::exoplanets{ "Transform = {" "Translation = {" "Type = 'StaticTranslation'," - "Position = " + std::to_string(northDirectionPos) + "," + "Position = " + ghoul::to_string(northDirectionPos) + "," "}," "}," "}"; @@ -521,7 +524,7 @@ namespace openspace::exoplanets{ "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rotation) + "," + "Rotation = " + ghoul::to_string(rotation) + "," "}" "}," "}"; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 07957189b4..e2e81fb21e 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -408,7 +408,7 @@ int addExoplanetSystem(lua_State* L) { glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); - glm::dmat3 exoplanetSystemRot = glm::dmat3(northProjected.x, northProjected.y, northProjected.z, + const glm::dmat3 exoplanetSystemRot = glm::dmat3(northProjected.x, northProjected.y, northProjected.z, beta.x, beta.y, beta.z, starToSunVec.x, starToSunVec.y, starToSunVec.z); @@ -421,11 +421,11 @@ int addExoplanetSystem(lua_State* L) { "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + std::to_string(exoplanetSystemRot) + "," + "Rotation = " + ghoul::to_string(exoplanetSystemRot) + "," "}," "Translation = {" "Type = 'StaticTranslation'," - "Position = " + std::to_string(position) + "," + "Position = " + ghoul::to_string(position) + "," "}," "}" "}"; @@ -683,7 +683,7 @@ int addExoplanetSystem(lua_State* L) { "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," + "Rotation = " + ghoul::to_string(rot) + "," "}" "}," "}"; @@ -715,7 +715,7 @@ int addExoplanetSystem(lua_State* L) { "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," + "Rotation = " + ghoul::to_string(rot) + "," "}" "}," "}"; @@ -746,7 +746,7 @@ int addExoplanetSystem(lua_State* L) { "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + std::to_string(rot) + "," + "Rotation = " + ghoul::to_string(rot) + "," "}" "}," "}"; From c03f98717a98104d0e141b4666187beac1afb652 Mon Sep 17 00:00:00 2001 From: GPayne Date: Fri, 30 Aug 2019 16:25:09 -0600 Subject: [PATCH 055/123] Initial non-working version of convert recording format task. --- .../interaction/tasks/convertrecformattask.h | 56 +++++++++ .../tasks/convertrecformattask.cpp | 116 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 include/openspace/interaction/tasks/convertrecformattask.h create mode 100644 src/interaction/tasks/convertrecformattask.cpp diff --git a/include/openspace/interaction/tasks/convertrecformattask.h b/include/openspace/interaction/tasks/convertrecformattask.h new file mode 100644 index 0000000000..ae89b4ab3a --- /dev/null +++ b/include/openspace/interaction/tasks/convertrecformattask.h @@ -0,0 +1,56 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_CORE___CONVERTRECFORMATTASK___H__ +#define __OPENSPACE_CORE___CONVERTRECFORMATTASK___H__ + +#include + +#include + +#include + +namespace openspace { + +class ConvertRecFormatTask : public Task { +public: + enum class ConversionDirection { + ToAscii = 0, + ToBinary + }; + ConvertRecFormatTask(const ghoul::Dictionary& dictionary); + std::string description() override; + void perform(const Task::ProgressCallback& progressCallback) override; + static documentation::Documentation documentation(); + +private: + std::string _inFilePath; + std::string _outFilePath; + + std::string _valueFunctionLua; +}; + +} // namespace openspace + +#endif //__OPENSPACE_CORE___CONVERTRECFORMATTASK___H__ diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp new file mode 100644 index 0000000000..ce8b004353 --- /dev/null +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -0,0 +1,116 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2019 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include +#include +#include + +#include +#include +#include +#include + +namespace { + constexpr const char* KeyConvertToAscii = "ConvertToAscii"; + constexpr const char* KeyConvertToBinary = "ConvertToBinary"; + constexpr const char* KeyInFilePath = "InputFilePath"; + constexpr const char* KeyOutFilePath = "OutputFilePath"; +} + +namespace openspace { + +ConvertRecFormatTask::ConvertRecFormatTask(const ghoul::Dictionary& dictionary) { + openspace::documentation::testSpecificationAndThrow( + documentation(), + dictionary, + "ConvertRecFormatTask" + ); + + _inFilePath = absPath(dictionary.value(KeyInFilePath)); + _outFilePath = absPath(dictionary.value(KeyOutFilePath)); +} + +void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallback) { + +} + +void ConvertRecFormatTask::convert() { + RecordedDataMode type = formatType(); + + if (type == RecordedDataMode::Ascii) { + convertToBinary(); + } + else if (type == RecordedDataMode::Binary) { + convertToAscii(); + } + else { + //Add error output for file type not recognized + } +} + +RecordedDataMode ConvertRecFormatTask::formatType() { + //Read file at _inFilePath + + //Read first line + + //First verify that the line starts with the valid string + + //Get last character which should be either 'A' or 'B', and return Ascii or Binary based on this. +} + +void ConvertRecFormatTask::convertToAscii() { + +} + +void ConvertRecFormatTask::convertToBinary() { + +} + +documentation::Documentation ConvertRecFormatTask::documentation() { + using namespace documentation; + return { + "ConvertRecFormatTask", + "convert_format_task", + { + { + "Type", + new StringEqualVerifier("ConvertRecFormatTask"), + Optional::No, + "The type of this task", + }, + { + KeyInFilePath, + new StringAnnotationVerifier("A valid filename to convert"), + Optional::No, + "The filename to convert to the opposite format.", + }, + { + KeyOutFilePath, + new StringAnnotationVerifier("A valid output filename"), + Optional::No, + "The filename containing the converted result.", + }, + }, + }; +} From 40526b11a2918e270cb2c16a72245142d17ebb5f Mon Sep 17 00:00:00 2001 From: GPayne Date: Fri, 30 Aug 2019 16:57:48 -0600 Subject: [PATCH 056/123] Added command to save current delta time when recording starts. --- src/interaction/sessionrecording.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index b46206e6d7..73000cc2fd 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -168,8 +168,15 @@ bool SessionRecording::startRecording(const std::string& filename) { } _recordFile << '\n'; + //Record the current delta time so this is preserved in recording + double currentDeltaTime = global::timeManager.deltaTime(); + std::string scriptCommandForInitializingDeltaTime = "openspace.time.setDeltaTime("; + scriptCommandForInitializingDeltaTime << currentDeltaTime << ");"; + saveScriptKeyframe(scriptCommandForInitializingDeltaTime); + LINFO("Session recording started"); _timestampRecordStarted = global::windowDelegate.applicationTime(); + return true; } From 1e426f3c4604924cb3bd8589869c3049f9f97e41 Mon Sep 17 00:00:00 2001 From: GPayne Date: Wed, 4 Sep 2019 11:10:08 -0600 Subject: [PATCH 057/123] Prevent changing the simulation time rate during playback --- include/openspace/util/timemanager.h | 1 + src/interaction/sessionrecording.cpp | 5 +++-- src/util/timemanager.cpp | 13 ++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/openspace/util/timemanager.h b/include/openspace/util/timemanager.h index 523ec5da5b..fb9d5293e2 100644 --- a/include/openspace/util/timemanager.h +++ b/include/openspace/util/timemanager.h @@ -105,6 +105,7 @@ public: void removeTimeChangeCallback(CallbackHandle handle); void removeDeltaTimeChangeCallback(CallbackHandle handle); void triggerPlaybackStart(); + void stopPlayback(); void removeTimeJumpCallback(CallbackHandle handle); void removeTimelineChangeCallback(CallbackHandle handle); diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 73000cc2fd..0c51e6ad23 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -170,8 +170,8 @@ bool SessionRecording::startRecording(const std::string& filename) { //Record the current delta time so this is preserved in recording double currentDeltaTime = global::timeManager.deltaTime(); - std::string scriptCommandForInitializingDeltaTime = "openspace.time.setDeltaTime("; - scriptCommandForInitializingDeltaTime << currentDeltaTime << ");"; + std::string scriptCommandForInitializingDeltaTime = + "openspace.time.setDeltaTime(" + std::to_string(currentDeltaTime) + ");"; saveScriptKeyframe(scriptCommandForInitializingDeltaTime); LINFO("Session recording started"); @@ -360,6 +360,7 @@ void SessionRecording::stopPlayback() { void SessionRecording::cleanUpPlayback() { global::navigationHandler.stopPlayback(); + global::timeManager.stopPlayback(); Camera* camera = global::navigationHandler.camera(); ghoul_assert(camera != nullptr, "Camera must not be nullptr"); diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index d8e920d2a7..430e4035b5 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -103,6 +103,10 @@ TimeManager::TimeManager() } void TimeManager::interpolateTime(double targetTime, double durationSeconds) { + if (_playbackModeEnabled) { + return; + } + ghoul_precondition(durationSeconds > 0.f, "durationSeconds must be positive"); const double now = global::windowDelegate.applicationTime(); @@ -275,8 +279,7 @@ void TimeManager::progressTime(double dt) { // and time is not paused, just advance time. _deltaTime = _targetDeltaTime; _currentTime.data().advanceTime(dt * _deltaTime); - _playbackModeEnabled = false; - } + } if (hasPastKeyframes) { _latestConsumedTimestamp = lastPastKeyframe->timestamp; @@ -456,6 +459,10 @@ void TimeManager::triggerPlaybackStart() { _playbackModeEnabled = true; } +void TimeManager::stopPlayback() { + _playbackModeEnabled = false; +} + void TimeManager::removeTimeJumpCallback(CallbackHandle handle) { const auto it = std::find_if( _timeJumpCallbacks.begin(), @@ -520,7 +527,7 @@ double TimeManager::targetDeltaTime() const { void TimeManager::interpolateDeltaTime(double newDeltaTime, double interpolationDuration) { - if (newDeltaTime == _targetDeltaTime) { + if (newDeltaTime == _targetDeltaTime || _playbackModeEnabled) { return; } From b375205c1a5f7b63745eaafeec792bbd6b84d32e Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 5 Sep 2019 12:42:01 -0600 Subject: [PATCH 058/123] Undo on recently-added changes that restricted time manipulation during playback. --- src/util/timemanager.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/util/timemanager.cpp b/src/util/timemanager.cpp index 430e4035b5..3a03fd3cc0 100644 --- a/src/util/timemanager.cpp +++ b/src/util/timemanager.cpp @@ -103,10 +103,6 @@ TimeManager::TimeManager() } void TimeManager::interpolateTime(double targetTime, double durationSeconds) { - if (_playbackModeEnabled) { - return; - } - ghoul_precondition(durationSeconds > 0.f, "durationSeconds must be positive"); const double now = global::windowDelegate.applicationTime(); @@ -279,7 +275,7 @@ void TimeManager::progressTime(double dt) { // and time is not paused, just advance time. _deltaTime = _targetDeltaTime; _currentTime.data().advanceTime(dt * _deltaTime); - } + } if (hasPastKeyframes) { _latestConsumedTimestamp = lastPastKeyframe->timestamp; @@ -527,7 +523,7 @@ double TimeManager::targetDeltaTime() const { void TimeManager::interpolateDeltaTime(double newDeltaTime, double interpolationDuration) { - if (newDeltaTime == _targetDeltaTime || _playbackModeEnabled) { + if (newDeltaTime == _targetDeltaTime) { return; } From 5b4ecf2b62d550a5f3ba1920ca96a356978e5755 Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 5 Sep 2019 14:56:11 -0600 Subject: [PATCH 059/123] Fixed timestamp problem with time rate script at start of recording --- src/interaction/sessionrecording.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 0c51e6ad23..3ae0695f60 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -168,14 +168,15 @@ bool SessionRecording::startRecording(const std::string& filename) { } _recordFile << '\n'; + _timestampRecordStarted = global::windowDelegate.applicationTime(); + //Record the current delta time so this is preserved in recording double currentDeltaTime = global::timeManager.deltaTime(); std::string scriptCommandForInitializingDeltaTime = - "openspace.time.setDeltaTime(" + std::to_string(currentDeltaTime) + ");"; + "openspace.time.setDeltaTime(" + std::to_string(currentDeltaTime) + ")"; saveScriptKeyframe(scriptCommandForInitializingDeltaTime); LINFO("Session recording started"); - _timestampRecordStarted = global::windowDelegate.applicationTime(); return true; } From 299c4f10c43c9c08eb5425e5d3db0ef0c9e64d81 Mon Sep 17 00:00:00 2001 From: GPayne Date: Fri, 11 Oct 2019 11:45:55 -0600 Subject: [PATCH 060/123] Added some file handling to record conversion tasks --- .../openspace/interaction/sessionrecording.h | 8 +++ .../interaction/tasks/convertrecformattask.h | 13 ++++ src/interaction/sessionrecording.cpp | 21 ------ .../tasks/convertrecformattask.cpp | 71 +++++++++++++++---- 4 files changed, 77 insertions(+), 36 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 26c5f5a094..82e22f38c2 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -45,6 +45,14 @@ public: Playback }; + const std::string FileHeaderTitle = "OpenSpace_record/playback"; + constexpr const size_t FileHeaderVersionLength = 5; + constexpr const char FileHeaderVersion[FileHeaderVersionLength] = { + '0', '0', '.', '8', '5' + }; + constexpr const char DataFormatAsciiTag = 'A'; + constexpr const char DataFormatBinaryTag = 'B'; + using CallbackHandle = int; using StateChangeCallback = std::function; diff --git a/include/openspace/interaction/tasks/convertrecformattask.h b/include/openspace/interaction/tasks/convertrecformattask.h index ae89b4ab3a..65c6aeef28 100644 --- a/include/openspace/interaction/tasks/convertrecformattask.h +++ b/include/openspace/interaction/tasks/convertrecformattask.h @@ -31,6 +31,13 @@ #include +namespace { + constexpr const char* KeyConvertToAscii = "ConvertToAscii"; + constexpr const char* KeyConvertToBinary = "ConvertToBinary"; + constexpr const char* KeyInFilePath = "InputFilePath"; + constexpr const char* KeyOutFilePath = "OutputFilePath"; +} + namespace openspace { class ConvertRecFormatTask : public Task { @@ -40,13 +47,19 @@ public: ToBinary }; ConvertRecFormatTask(const ghoul::Dictionary& dictionary); + ~ConvertRecFormatTask(); std::string description() override; void perform(const Task::ProgressCallback& progressCallback) override; static documentation::Documentation documentation(); private: + void convertToAscii(); + void convertToBinary(); + std::string _inFilePath; std::string _outFilePath; + std::ifstream _iFile; + std::ifstream _oFile; std::string _valueFunctionLua; }; diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 0c51e6ad23..1eb8fd2d03 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -46,14 +46,6 @@ namespace { constexpr const char* _loggerCat = "SessionRecording"; constexpr const bool UsingTimeKeyframes = false; - const std::string FileHeaderTitle = "OpenSpace_record/playback"; - constexpr const size_t FileHeaderVersionLength = 5; - constexpr const char FileHeaderVersion[FileHeaderVersionLength] = { - '0', '0', '.', '8', '5' - }; - constexpr const char DataFormatAsciiTag = 'A'; - constexpr const char DataFormatBinaryTag = 'B'; - template T readFromPlayback(std::ifstream& stream) { @@ -979,19 +971,6 @@ void SessionRecording::playbackScript() { } } double timeRef = appropriateTimestamp(timeOs, timeRec, timeSim); - //timeRef = getEquivalentSimulationTime(timeOs, timeRec, timeSim); - - //Call script scheduler with this new script entry - //std::string timeDescription = SpiceManager::ref().dateFromEphemerisTime( - // timeRef, - // "YYYY MON DD HR:MN:SC.###" - //); - //ghoul::Dictionary scriptDict(ghoul::Dictionary{ - // { KeyTime, timeDescription }, - // { KeyForwardScript, pbFrame._script} - //} - // ); - //global::scriptScheduler.loadScripts({ { "1", scriptDict } }); addKeyframe(timeRef, pbFrame._script); } diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index ce8b004353..1425e04e51 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -30,13 +30,11 @@ #include #include #include +#include namespace { - constexpr const char* KeyConvertToAscii = "ConvertToAscii"; - constexpr const char* KeyConvertToBinary = "ConvertToBinary"; - constexpr const char* KeyInFilePath = "InputFilePath"; - constexpr const char* KeyOutFilePath = "OutputFilePath"; -} + constexpr const char* _loggerCat = "ConvertRecFormatTask"; +} // namespace namespace openspace { @@ -49,6 +47,20 @@ ConvertRecFormatTask::ConvertRecFormatTask(const ghoul::Dictionary& dictionary) _inFilePath = absPath(dictionary.value(KeyInFilePath)); _outFilePath = absPath(dictionary.value(KeyOutFilePath)); + + ghoul_assert(FileSys.fileExists(_inFilePath), "The filename must exist"); + if (!FileSys.fileExists(_inFilePath)) { + LERROR(fmt::format("Failed to load session recording file: {}", _inFilePath)); + //throw ghoul::FileNotFoundError(_inFilePath); + } + + _iFile.exceptions(std::ofstream::failbit | std::ofstream::badbit); + _iFile.open(_inFilePath); +} + +ConvertRecFormatTask::~ConvertRecFormatTask() { + _iFile.close(); + _oFile.close(); } void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallback) { @@ -56,35 +68,64 @@ void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallbac } void ConvertRecFormatTask::convert() { - RecordedDataMode type = formatType(); + interaction::RecordedDataMode type = formatType(); - if (type == RecordedDataMode::Ascii) { + if (type == interaction::RecordedDataMode::Ascii) { convertToBinary(); } - else if (type == RecordedDataMode::Binary) { + else if (type == interaction::RecordedDataMode::Binary) { convertToAscii(); } else { //Add error output for file type not recognized + LERROR("Session recording file unrecognized format type."); } } RecordedDataMode ConvertRecFormatTask::formatType() { - //Read file at _inFilePath + const std::string expectedHeader = "OpenSpace_record/playback"; + std::string line; + //Get first line, which is ASCII regardless of format + std::getline(_iFile, line); - //Read first line - - //First verify that the line starts with the valid string - - //Get last character which should be either 'A' or 'B', and return Ascii or Binary based on this. + if (line.substr(0, interaction::FileHeaderTitle.length()) + != interaction::FileHeaderTitle) + { + LERROR(fmt::format("Session recording file {} does not have expected header.", _inFilePath)); + return RecordedDataMode::Binary + 1; + } + else { + if (line.back() == DataFormatAsciiTag) { + return RecordedDataMode::Ascii; + } + else if (line.back() == DataFormatBinaryTag) { + return RecordedDataMode::Binary; + } + else { + return RecordedDataMode::Binary + 1; + } + } } void ConvertRecFormatTask::convertToAscii() { - + _outFilePath = addFileSuffix(_inFilePath, "_ascii"); } void ConvertRecFormatTask::convertToBinary() { + _outFilePath = addFileSuffix(_inFilePath, "_binary"); +} +std::string ConvertRecFormatTask::addFileSuffix(const std::string& filePath, + const std::string& suffix) +{ + size_t lastdot = filename.find_last_of("."); + std::string extension = filePath.substr(0, lastdot); + if (lastdot == std::string::npos) { + return filePath + suffix; + } + else { + return filePath.substr(0, lastdot) + suffix + extension; + } } documentation::Documentation ConvertRecFormatTask::documentation() { From 27ef369338991affeb6687703d5027e79fd8d49d Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 17 Oct 2019 18:20:37 -0600 Subject: [PATCH 061/123] Separated playback keyframe extraction into steps (file read & parse) --- .../openspace/interaction/keyframenavigator.h | 8 ++ .../openspace/interaction/sessionrecording.h | 30 ++++ include/openspace/network/messagestructures.h | 16 +++ src/interaction/sessionrecording.cpp | 135 +++++++++--------- 4 files changed, 120 insertions(+), 69 deletions(-) diff --git a/include/openspace/interaction/keyframenavigator.h b/include/openspace/interaction/keyframenavigator.h index a241815c2c..77783d6bd4 100644 --- a/include/openspace/interaction/keyframenavigator.h +++ b/include/openspace/interaction/keyframenavigator.h @@ -54,6 +54,14 @@ public: std::string focusNode; float scale; bool followFocusNodeRotation; + + CameraPose(const openspace::datamessagestructures::CameraKeyframe& kf) { + position = kf._position; + rotation = kf._rotation; + focusNode = kf._focusNode; + scale = kf._scale; + followFocusNodeRotation = kf._followNodeRotation; + } }; /** diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 82e22f38c2..025a91a7d7 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -45,6 +45,12 @@ public: Playback }; + struct timestamps { + double timeOs; + double timeRec; + double timeSim; + }; + const std::string FileHeaderTitle = "OpenSpace_record/playback"; constexpr const size_t FileHeaderVersionLength = 5; constexpr const char FileHeaderVersion[FileHeaderVersionLength] = { @@ -216,6 +222,30 @@ public: */ std::vector playbackList() const; + /** + * Reads a camera keyframe from a binary format playback file, and populates input + * references with the parameters of the keyframe. + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a camera keyframe which contains camera details + * \param file an ifstream reference to the playback file being read + * \param lineN keyframe number in playback file where this keyframe resides + */ + static void readCameraKeyframeBinary(timestamps& times, + datamessagestructures::CameraKeyframe& kf, std::ifstream& file, int lineN); + + /** + * Reads a camera keyframe from an ascii format playback file, and populates input + * references with the parameters of the keyframe. + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a camera keyframe which contains camera details + * \param filenameRead a string containing the playback filename + * \param lineN line number in playback file where this keyframe resides + */ + static void readCameraKeyframeAscii(timestamps& times, + datamessagestructures::CameraKeyframe& kf, std::string filenameRead, int lineN); + private: enum class RecordedType { Camera = 0, diff --git a/include/openspace/network/messagestructures.h b/include/openspace/network/messagestructures.h index d1e60f7bb3..aa873d8ca4 100644 --- a/include/openspace/network/messagestructures.h +++ b/include/openspace/network/messagestructures.h @@ -233,6 +233,22 @@ struct CameraKeyframe { sizeof(_timestamp) ); }; + + void read(std::istringstream* iss) { + std::string rotationFollowing; + + iss >> _position.x + >> _position.y + >> _position.z + >> _rotation.x + >> _rotation.y + >> _rotation.z + >> _rotation.w + >> _scale + >> rotationFollowing + >> _focusNode; + _followNodeRotation = (rotationFollowing == "F"); + }; }; struct TimeKeyframe { diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 37a9303403..091c7fe1d1 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -781,84 +781,81 @@ double SessionRecording::fixedDeltaTimeDuringFrameOutput() const { } void SessionRecording::playbackCamera() { - double timeOs; - double timeRec; - double timeSim; - std::string rotationFollowing; - interaction::KeyframeNavigator::CameraPose pbFrame; + timestamps times; datamessagestructures::CameraKeyframe kf; + if (_recordingDataMode == RecordedDataMode::Binary) { - timeOs = readFromPlayback(_playbackFile); - timeRec = readFromPlayback(_playbackFile); - timeSim = readFromPlayback(_playbackFile); - try { - kf.read(&_playbackFile); - } - catch (std::bad_alloc&) { - LERROR(fmt::format( - "Allocation error with camera playback from keyframe entry {}", - _playbackLineNum - 1 - )); - return; - } - catch (std::length_error&) { - LERROR(fmt::format( - "length_error with camera playback from keyframe entry {}", - _playbackLineNum - 1 - )); - return; - } - - timeOs = kf._timestamp; - - pbFrame.focusNode = kf._focusNode; - pbFrame.position = kf._position; - pbFrame.rotation = kf._rotation; - pbFrame.scale = kf._scale; - pbFrame.followFocusNodeRotation = kf._followNodeRotation; - - if (!_playbackFile) { - LINFO(fmt::format( - "Error reading camera playback from keyframe entry {}", - _playbackLineNum - 1 - )); - return; - } + readCameraKeyframeBinary(times, kf, _playbackFile, _playbackLineNum); } else { - std::istringstream iss(_playbackLineParsing); - std::string entryType; - iss >> entryType; - iss >> timeOs >> timeRec >> timeSim; - iss >> pbFrame.position.x - >> pbFrame.position.y - >> pbFrame.position.z - >> pbFrame.rotation.x - >> pbFrame.rotation.y - >> pbFrame.rotation.z - >> pbFrame.rotation.w - >> pbFrame.scale - >> rotationFollowing - >> pbFrame.focusNode; - if (iss.fail() || !iss.eof()) { - LERROR(fmt::format( - "Error parsing camera line {} of playback file", _playbackLineNum - )); - return; - } - pbFrame.followFocusNodeRotation = (rotationFollowing == "F"); + readCameraKeyframeAscii(times, kf, _playbackLineParsing, _playbackLineNum); } - if (_setSimulationTimeWithNextCameraKeyframe) { - global::timeManager.setTimeNextFrame(Time(timeSim)); - _setSimulationTimeWithNextCameraKeyframe = false; - _saveRenderingCurrentRecordedTime = timeRec; - } - double timeRef = appropriateTimestamp(timeOs, timeRec, timeSim); - //global::navigationHandler.keyframeNavigator().addKeyframe(timeRef, pbFrame); + if (_setSimulationTimeWithNextCameraKeyframe) { + global::timeManager.setTimeNextFrame(Time(times.timeSim)); + _setSimulationTimeWithNextCameraKeyframe = false; + _saveRenderingCurrentRecordedTime = times.timeRec; + } + double timeRef = appropriateTimestamp(times.timeOs, times.timeRec, times.timeSim); + + interaction::KeyframeNavigator::CameraPose pbFrame(kf); addKeyframe(timeRef, pbFrame); } +static void SessionRecording::readCameraKeyframeBinary(timestamps& times, + datamessagestructures::CameraKeyframe& kf, + std::ifstream& file, int lineN) +{ + times.timeOs = readFromPlayback(file); + times.timeRec = readFromPlayback(file); + times.timeSim = readFromPlayback(file); + try { + kf.read(&file); + } + catch (std::bad_alloc&) { + LERROR(fmt::format( + "Allocation error with camera playback from keyframe entry {}", + lineN - 1 + )); + return; + } + catch (std::length_error&) { + LERROR(fmt::format( + "length_error with camera playback from keyframe entry {}", + lineN - 1 + )); + return; + } + times.timeOs = kf._timestamp; + + if (!file) { + LINFO(fmt::format( + "Error reading camera playback from keyframe entry {}", + lineN - 1 + )); + return; + } +} + +static void SessionRecording::readCameraKeyframeAscii(timestamps& times, + datamessagestructures::CameraKeyframe& kf, + std::string filenameRead, + int lineN) +{ + std::string rotationFollowing; + std::string entryType; + + std::istringstream iss(filenameRead); + iss >> entryType; + iss >> times.timeOs >> times.timeRec >> times.timeSim; + kf.read(&iss); + + if (iss.fail() || !iss.eof()) { + LERROR(fmt::format("Error parsing camera line {} of playback file", lineN)); + return; + } +} + void SessionRecording::playbackTimeChange() { double timeOs; double timeRec; From a549993727a314305fc895a2cf41892f3c9df3fc Mon Sep 17 00:00:00 2001 From: GPayne Date: Wed, 23 Oct 2019 18:02:20 -0600 Subject: [PATCH 062/123] Finished time and script keyframe types into separate read & parse steps --- .../openspace/interaction/sessionrecording.h | 50 ++++ include/openspace/network/messagestructures.h | 24 ++ src/interaction/sessionrecording.cpp | 231 ++++++++++-------- 3 files changed, 203 insertions(+), 102 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 025a91a7d7..7cf6905312 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -246,6 +246,56 @@ public: static void readCameraKeyframeAscii(timestamps& times, datamessagestructures::CameraKeyframe& kf, std::string filenameRead, int lineN); + /** + * Reads a time keyframe from a binary format playback file, and populates input + * references with the parameters of the keyframe. + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a time keyframe which contains time details + * \param file an ifstream reference to the playback file being read + * \param lineN keyframe number in playback file where this keyframe resides + */ + static void SessionRecording::readTimeKeyframeBinary(timestamps& times, + datamessagestructures::TimeKeyframe& kf, std::ifstream& file, int lineN); + + /** + * Reads a time keyframe from an ascii format playback file, and populates input + * references with the parameters of the keyframe. + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a time keyframe which contains time details + * \param filenameRead a string containing the playback filename + * \param lineN line number in playback file where this keyframe resides + */ + static void SessionRecording::readTimeKeyframeAscii(timestamps& times, + datamessagestructures::TimeKeyframe& kf, std::string filenameRead, int lineN); + + /** + * Reads a script keyframe from a binary format playback file, and populates input + * references with the parameters of the keyframe. + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a script keyframe which contains the size of the script + * (in chars) and the text itself + * \param file an ifstream reference to the playback file being read + * \param lineN keyframe number in playback file where this keyframe resides + */ + static void SessionRecording::readScriptKeyframeBinary(timestamps& times, + datamessagestructures::ScriptMessage& kf, std::ifstream& file, int lineN); + + /** + * Reads a script keyframe from an ascii format playback file, and populates input + * references with the parameters of the keyframe. + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a script keyframe which contains the size of the script + * (in chars) and the text itself + * \param filenameRead a string containing the playback filename + * \param lineN line number in playback file where this keyframe resides + */ + static void SessionRecording::readScriptKeyframeAscii(timestamps& times, + datamessagestructures::ScriptMessage& kf, std::string filenameRead, int lineN); + private: enum class RecordedType { Camera = 0, diff --git a/include/openspace/network/messagestructures.h b/include/openspace/network/messagestructures.h index aa873d8ca4..8b9d72cc64 100644 --- a/include/openspace/network/messagestructures.h +++ b/include/openspace/network/messagestructures.h @@ -290,6 +290,16 @@ struct TimeKeyframe { sizeof(TimeKeyframe) ); }; + + void read(std::istringstream* iss) { + std::string paused, jump; + + iss >> _dt + >> paused + >> jump; + _paused = (paused == "P"); + _requiresTimeJump = (jump == "J"); + }; }; struct TimeTimeline { @@ -404,6 +414,20 @@ struct ScriptMessage { _script.erase(); _script = temp.data(); }; + + void read(std::istringstream* iss) { + int numScriptLines; + iss >> numScriptLines; + std::string tmpReadbackScript; + _script.erase(); + for (unsigned int i = 0; i < numScriptLines; ++i) { + std::getline(iss, tmpReadbackScript); + _script.append(tmpReadbackScript); + if (i < (numScriptLines - 1)) { + _script.append("\n"); + } + } + }; }; } // namespace openspace::messagestructures diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 091c7fe1d1..656298d65a 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -803,7 +803,7 @@ void SessionRecording::playbackCamera() { } static void SessionRecording::readCameraKeyframeBinary(timestamps& times, - datamessagestructures::CameraKeyframe& kf, + datamessagestructures::CameraKeyframe& kf, std::ifstream& file, int lineN) { times.timeOs = readFromPlayback(file); @@ -838,7 +838,7 @@ static void SessionRecording::readCameraKeyframeBinary(timestamps& times, } static void SessionRecording::readCameraKeyframeAscii(timestamps& times, - datamessagestructures::CameraKeyframe& kf, + datamessagestructures::CameraKeyframe& kf, std::string filenameRead, int lineN) { @@ -857,119 +857,146 @@ static void SessionRecording::readCameraKeyframeAscii(timestamps& times, } void SessionRecording::playbackTimeChange() { - double timeOs; - double timeRec; - double timeSim; - datamessagestructures::TimeKeyframe pbFrame; + timestamps times; + datamessagestructures::TimeKeyframe kf; + if (_recordingDataMode == RecordedDataMode::Binary) { - timeOs = readFromPlayback(_playbackFile); - timeRec = readFromPlayback(_playbackFile); - timeSim = readFromPlayback(_playbackFile); - pbFrame._dt = readFromPlayback(_playbackFile); - pbFrame._paused = readFromPlayback(_playbackFile); - pbFrame._requiresTimeJump = readFromPlayback(_playbackFile); - - if (!_playbackFile) { - LERROR(fmt::format( - "Error reading time playback from keyframe entry {}", _playbackLineNum - 1 - )); - return; - } + readTimeKeyframeBinary(times, kf, _playbackFile, _playbackLineNum); } else { - std::istringstream iss(_playbackLineParsing); - std::string entryType; - //double timeRef; - std::string paused, jump; - iss >> entryType; - iss >> timeOs >> timeRec >> timeSim; - iss >> pbFrame._dt - >> paused - >> jump; - if (iss.fail() || !iss.eof()) { - LERROR(fmt::format( - "Error parsing time line {} of playback file", _playbackLineNum - )); - return; - } - pbFrame._paused = (paused == "P"); - pbFrame._requiresTimeJump = (jump == "J"); + readTimeKeyframeAscii(times, kf, _playbackLineParsing, _playbackLineNum); } - pbFrame._timestamp = equivalentApplicationTime(timeOs, timeRec, timeSim); + kf._timestamp = equivalentApplicationTime(times.timeOs, times.timeRec, times.timeSim); - pbFrame._time = pbFrame._timestamp + _timestampApplicationStarted_simulation; + kf._time = kf._timestamp + _timestampApplicationStarted_simulation; //global::timeManager.addKeyframe(timeRef, pbFrame._timestamp); //_externInteract.timeInteraction(pbFrame); - addKeyframe(pbFrame._timestamp, pbFrame); + addKeyframe(kf._timestamp, kf); +} + +static void SessionRecording::readTimeKeyframeBinary(timestamps& times, + datamessagestructures::TimeKeyframe& kf, + std::ifstream& file, int lineN) +{ + times.timeOs = readFromPlayback(file); + times.timeRec = readFromPlayback(file); + times.timeSim = readFromPlayback(file); + + try { + kf.read(&file); + } + catch (std::bad_alloc&) { + LERROR(fmt::format( + "Allocation error with time playback from keyframe entry {}", + lineN - 1 + )); + return; + } + catch (std::length_error&) { + LERROR(fmt::format( + "length_error with time playback from keyframe entry {}", + lineN - 1 + )); + return; + } + + if (!file) { + LERROR(fmt::format( + "Error reading time playback from keyframe entry {}", lineN - 1 + )); + return; + } +} + +static void SessionRecording::readTimeKeyframeAscii(timestamps& times, + datamessagestructures::TimeKeyframe& kf, + std::string filenameRead, + int lineN) +{ + std::string entryType; + + std::istringstream iss(filenameRead); + iss >> entryType; + iss >> times.timeOs >> times.timeRec >> times.timeSim; + kf.read(&iss); + + if (iss.fail() || !iss.eof()) { + LERROR(fmt::format( + "Error parsing time line {} of playback file", _playbackLineNum + )); + return; + } } void SessionRecording::playbackScript() { - double timeOs; - double timeRec; - double timeSim; - unsigned int numScriptLines; - datamessagestructures::ScriptMessage pbFrame; + timestamps times; + datamessagestructures::ScriptMessage kf; if (_recordingDataMode == RecordedDataMode::Binary) { - timeOs = readFromPlayback(_playbackFile); - timeRec = readFromPlayback(_playbackFile); - timeSim = readFromPlayback(_playbackFile); - try { - pbFrame._script = readFromPlayback(_playbackFile); - } - catch (std::bad_alloc&) { - LERROR(fmt::format( - "Allocation error with script playback from keyframe entry {}", - _playbackLineNum - 1 - )); - return; - } - catch (std::length_error&) { - LERROR(fmt::format( - "length_error with script playback from keyframe entry {}", - _playbackLineNum - 1 - )); - return; - } - - if (!_playbackFile) { - LERROR(fmt::format( - "Error reading script playback from keyframe entry {}", - _playbackLineNum - 1 - )); - return; - } + readScriptKeyframeBinary(times, kf, _playbackFile, _playbackLineNum); } else { - std::istringstream iss(_playbackLineParsing); - std::string entryType; - std::string tmpReadbackScript; - - iss >> entryType; - iss >> timeOs >> timeRec >> timeSim; - iss >> numScriptLines; - std::getline(iss, tmpReadbackScript); //iss >> tmpReadbackScript; - pbFrame._script.append(tmpReadbackScript); - if (iss.fail()) { - LERROR(fmt::format( - "Error parsing script line {} of playback file", _playbackLineNum - )); - return; - } else if (!iss.eof()) { - LERROR(fmt::format( - "Did not find an EOL at line {} of playback file", _playbackLineNum - )); - return; - } - if (numScriptLines > 1) { - //Now loop to read any subsequent lines if is a multi-line script - for (unsigned int i = 1; i < numScriptLines; ++i) { - pbFrame._script.append("\n"); - std::getline(_playbackFile, tmpReadbackScript); - pbFrame._script.append(tmpReadbackScript); - } - } + readScriptKeyframeAscii(times, kf, _playbackLineParsing, _playbackLineNum); + } + + double timeRef = appropriateTimestamp(times.timeOs, times.timeRec, times.timeSim); + addKeyframe(timeRef, kf._script); +} + +static void SessionRecording::readScriptKeyframeBinary(timestamps& times, + datamessagestructures::ScriptMessage& kf, + std::ifstream& file, int lineN) +{ + times.timeOs = readFromPlayback(file); + times.timeRec = readFromPlayback(file); + times.timeSim = readFromPlayback(file); + + try { + kf.read(&file); + } + catch (std::bad_alloc&) { + LERROR(fmt::format( + "Allocation error with script playback from keyframe entry {}", + lineN - 1 + )); + return; + } + catch (std::length_error&) { + LERROR(fmt::format( + "length_error with script playback from keyframe entry {}", + lineN - 1 + )); + return; + } + + if (!file) { + LERROR(fmt::format( + "Error reading script playback from keyframe entry {}", + lineN - 1 + )); + return; + } +} + +static void SessionRecording::readScriptKeyframeAscii(timestamps& times, + datamessagestructures::ScriptMessage& kf, + std::string filenameRead, + int lineN) +{ + std::string entryType; + std::istringstream iss(filenameRead); + iss >> entryType; + iss >> times.timeOs >> times.timeRec >> times.timeSim; + kf.read(&iss); + if (iss.fail()) { + LERROR(fmt::format( + "Error parsing script line {} of playback file", _playbackLineNum + )); + return; + } else if (!iss.eof()) { + LERROR(fmt::format( + "Did not find an EOL at line {} of playback file", _playbackLineNum + )); + return; } - double timeRef = appropriateTimestamp(timeOs, timeRec, timeSim); - addKeyframe(timeRef, pbFrame._script); } void SessionRecording::addKeyframe(double timestamp, From 915eefbf11c1d9aec00070c4f23d50ec04d16216 Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 24 Oct 2019 13:06:52 -0600 Subject: [PATCH 063/123] Working on separating writing of recording keyframes into separate read & parse steps --- .../openspace/interaction/sessionrecording.h | 37 +++- src/interaction/sessionrecording.cpp | 179 +++++++++++------- 2 files changed, 137 insertions(+), 79 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 7cf6905312..69ddb74ee5 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -296,6 +296,29 @@ public: static void SessionRecording::readScriptKeyframeAscii(timestamps& times, datamessagestructures::ScriptMessage& kf, std::string filenameRead, int lineN); + /** + * Writes a camera keyframe to a binary format recording file using a CameraKeyframe + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a camera keyframe which contains the camera details + * \param kfBuffer a buffer temporarily used for preparing data to be written + * \param idx index into the temporary buffer + * \param file an ofstream reference to the playback file being written-to + */ + static void SessionRecording::saveCameraKeyframeBinary(timestamps times, + datamessagestructures::CameraKeyframe& kf, unsigned char* kfBuffer, size_t& idx, + std::ofstream& file); + + /** + * Writes a camera keyframe to an ascii format recording file using a CameraKeyframe + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a camera keyframe which contains the camera details + * \param file an ofstream reference to the playback file being written-to + */ + static void SessionRecording::saveCameraKeyframeAscii(timestamps times, + datamessagestructures::CameraKeyframe& kf, std::ofstream& file); + private: enum class RecordedType { Camera = 0, @@ -323,14 +346,11 @@ private: void playbackScript(); bool playbackAddEntriesToTimeline(); void signalPlaybackFinishedForComponent(RecordedType type); - void writeToFileBuffer(double src); - void writeToFileBuffer(std::vector& cvec); - void writeToFileBuffer(unsigned char c); - void writeToFileBuffer(bool b); void saveStringToFile(const std::string& s); - void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size); + void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size, + std::ofstream& file); void findFirstCameraKeyframeInTimeline(); - void saveKeyframeToFile(std::string entry); + void saveKeyframeToFile(std::string entry, std::ofstream& file); void addKeyframe(double timestamp, interaction::KeyframeNavigator::CameraPose keyframe); @@ -355,6 +375,11 @@ private: double getPrevTimestamp(); void cleanUpPlayback(); + static void writeToFileBuffer(unsigned char* buf, size_t& idx, double src); + static void writeToFileBuffer(unsigned char* buf, size_t& idx, std::vector& cv); + static void writeToFileBuffer(unsigned char* buf, size_t& idx, unsigned char c); + static void writeToFileBuffer(unsigned char* buf, size_t& idx, bool b); + RecordedDataMode _recordingDataMode = RecordedDataMode::Binary; SessionState _state = SessionState::Idle; SessionState _lastState = SessionState::Idle; diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 656298d65a..89bde19f33 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -385,28 +385,40 @@ void SessionRecording::cleanUpPlayback() { _cleanupNeeded = false; } -void SessionRecording::writeToFileBuffer(double src) { +static void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + double src) +{ const size_t writeSize_bytes = sizeof(double); unsigned char const *p = reinterpret_cast(&src); - memcpy((_keyframeBuffer + _bufferIndex), p, writeSize_bytes); - _bufferIndex += writeSize_bytes; + memcpy((buf + idx), p, writeSize_bytes); + idx += writeSize_bytes; } -void SessionRecording::writeToFileBuffer(std::vector& cvec) { - const size_t writeSize_bytes = cvec.size() * sizeof(char); - memcpy((_keyframeBuffer + _bufferIndex), cvec.data(), writeSize_bytes); - _bufferIndex += writeSize_bytes; +static void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + std::vector& cv) +{ + const size_t writeSize_bytes = cv.size() * sizeof(char); + memcpy((buf + idx), cv.data(), writeSize_bytes); + idx += writeSize_bytes; } -void SessionRecording::writeToFileBuffer(unsigned char c) { +static void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + unsigned char c) +{ const size_t writeSize_bytes = sizeof(char); - _keyframeBuffer[_bufferIndex] = c; - _bufferIndex += writeSize_bytes; + buf[idx] = c; + idx += writeSize_bytes; } -void SessionRecording::writeToFileBuffer(bool b) { - _keyframeBuffer[_bufferIndex] = b ? 1 : 0; - _bufferIndex += sizeof(char); +static void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + bool b) +{ + buf[idx] = b ? 1 : 0; + idx += sizeof(char); } void SessionRecording::saveStringToFile(const std::string& s) { @@ -417,7 +429,7 @@ void SessionRecording::saveStringToFile(const std::string& s) { unsigned char const *p = reinterpret_cast(&strLen); memcpy((_keyframeBuffer + _bufferIndex), p, writeSize_bytes); _bufferIndex += static_cast(writeSize_bytes); - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex); + saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex, _recordFile); _recordFile.write(s.c_str(), s.size()); } @@ -456,54 +468,71 @@ void SessionRecording::saveCameraKeyframe() { // & orientation of camera datamessagestructures::CameraKeyframe kf = _externInteract.generateCameraKeyframe(); + timestamps times = { + kf._timestamp, + kf._timestamp - _timestampRecordStarted, + global::timeManager.time().j2000Seconds() + }; if (_recordingDataMode == RecordedDataMode::Binary) { - // Writing to a binary session recording file - _bufferIndex = 0; - _keyframeBuffer[_bufferIndex++] = 'c'; - - // Writing to internal buffer, and then to file, for performance reasons - writeToFileBuffer(kf._timestamp); - writeToFileBuffer(kf._timestamp - _timestampRecordStarted); - writeToFileBuffer(global::timeManager.time().j2000Seconds()); - std::vector kfBuffer; - kf.serialize(kfBuffer); - writeToFileBuffer(kfBuffer); - - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex); + saveCameraKeyframeBinary(times, kf, _keyframeBuffer, _bufferIndex, _recordFile); } else { - // Writing to an ASCII session recording file - std::stringstream keyframeLine = std::stringstream(); - // Add simulation timestamp, timestamp relative, simulation time to recording - // start - keyframeLine << "camera "; - keyframeLine << kf._timestamp << ' '; - keyframeLine << (kf._timestamp - _timestampRecordStarted) << ' '; - keyframeLine << std::fixed << std::setprecision(3) << - global::timeManager.time().j2000Seconds(); - keyframeLine << ' '; - // Add camera position - keyframeLine << std::fixed << std::setprecision(7) << kf._position.x << ' ' - << std::fixed << std::setprecision(7) << kf._position.y << ' ' - << std::fixed << std::setprecision(7) << kf._position.z << ' '; - // Add camera rotation - keyframeLine << std::fixed << std::setprecision(7) << kf._rotation.x << ' ' - << std::fixed << std::setprecision(7) << kf._rotation.y << ' ' - << std::fixed << std::setprecision(7) << kf._rotation.z << ' ' - << std::fixed << std::setprecision(7) << kf._rotation.w << ' '; - keyframeLine << std::scientific << kf._scale << ' '; - if (kf._followNodeRotation) { - keyframeLine << "F "; - } - else { - keyframeLine << "- "; - } - keyframeLine << kf._focusNode; - - saveKeyframeToFile(keyframeLine.str()); + saveCameraKeyframeAscii(times, kf, _recordFile); } } +static void SessionRecording::saveCameraKeyframeBinary(timestamps times, + datamessagestructures::CameraKeyframe& kf, + unsigned char* kfBuffer, + size_t& idx, + std::ofstream& file) +{ + // Writing to a binary session recording file + idx = 0; + kfBuffer[idx++] = 'c'; + + // Writing to internal buffer, and then to file, for performance reasons + writeToFileBuffer(kfBuffer, idx, times.timeOs); + writeToFileBuffer(kfBuffer, idx, times.timeRec); + writeToFileBuffer(kfBuffer, idx, times.timeSim); + std::vector writeBuffer; + kf.serialize(writeBuffer); + writeToFileBuffer(kfBuffer, idx, writeBuffer); + + saveKeyframeToFileBinary(kfBuffer, idx, file); +} + +static void SessionRecording::saveCameraKeyframeAscii(timestamps times, + datamessagestructures::CameraKeyframe& kf, + std::ofstream& file) +{ + std::stringstream keyframeLine = std::stringstream(); + // Add simulation timestamp, timestamp relative, simulation time to recording start + keyframeLine << "camera "; + keyframeLine << times.timeOs << ' '; + keyframeLine << times.timeRec << ' '; + keyframeLine << std::fixed << std::setprecision(3) << times.timeSim << ' '; + // Add camera position + keyframeLine << std::fixed << std::setprecision(7) << kf._position.x << ' ' + << std::fixed << std::setprecision(7) << kf._position.y << ' ' + << std::fixed << std::setprecision(7) << kf._position.z << ' '; + // Add camera rotation + keyframeLine << std::fixed << std::setprecision(7) << kf._rotation.x << ' ' + << std::fixed << std::setprecision(7) << kf._rotation.y << ' ' + << std::fixed << std::setprecision(7) << kf._rotation.z << ' ' + << std::fixed << std::setprecision(7) << kf._rotation.w << ' '; + keyframeLine << std::scientific << kf._scale << ' '; + if (kf._followNodeRotation) { + keyframeLine << "F "; + } + else { + keyframeLine << "- "; + } + keyframeLine << kf._focusNode; + + saveKeyframeToFile(keyframeLine.str(), file); +} + void SessionRecording::saveTimeKeyframe() { if (_state != SessionState::Recording) { return; @@ -515,14 +544,15 @@ void SessionRecording::saveTimeKeyframe() { if (_recordingDataMode == RecordedDataMode::Binary) { _bufferIndex = 0; _keyframeBuffer[_bufferIndex++] = 't'; - writeToFileBuffer(kf._timestamp); - writeToFileBuffer(kf._timestamp - _timestampRecordStarted); - writeToFileBuffer(kf._time); - writeToFileBuffer(kf._dt); - writeToFileBuffer(kf._paused); - writeToFileBuffer(kf._requiresTimeJump); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._timestamp); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._timestamp + - _timestampRecordStarted); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._time); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._dt); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._paused); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._requiresTimeJump); - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex); + saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex, _recordFile); } else { std::stringstream keyframeLine = std::stringstream(); //Add simulation timestamp, timestamp relative, simulation time to recording start @@ -545,7 +575,7 @@ void SessionRecording::saveTimeKeyframe() { else { keyframeLine << " -"; } - saveKeyframeToFile(keyframeLine.str()); + saveKeyframeToFile(keyframeLine.str(), _recordFile); } } @@ -560,11 +590,11 @@ void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { if (_recordingDataMode == RecordedDataMode::Binary) { _bufferIndex = 0; _keyframeBuffer[_bufferIndex++] = 's'; - writeToFileBuffer(sm._timestamp); - writeToFileBuffer(sm._timestamp - _timestampRecordStarted); - writeToFileBuffer(global::timeManager.time().j2000Seconds()); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, sm._timestamp); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, sm._timestamp - _timestampRecordStarted); + writeToFileBuffer(_keyframeBuffer, _bufferIndex, global::timeManager.time().j2000Seconds()); //Write header to file - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex); + saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex, _recordFile); saveStringToFile(scriptToSave); } @@ -583,7 +613,7 @@ void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { keyframeLine << (numLinesInScript + 1) << ' '; keyframeLine << scriptToSave; - saveKeyframeToFile(keyframeLine.str()); + saveKeyframeToFile(keyframeLine.str(), _recordFile); } } @@ -1320,12 +1350,15 @@ SessionRecording::RecordedType SessionRecording::getPrevKeyframeType() { } } -void SessionRecording::saveKeyframeToFileBinary(unsigned char* buffer, size_t size) { - _recordFile.write(reinterpret_cast(buffer), size); +void SessionRecording::saveKeyframeToFileBinary(unsigned char* buffer, + size_t size, + std::ofstream& file) +{ + file.write(reinterpret_cast(buffer), size); } -void SessionRecording::saveKeyframeToFile(std::string entry) { - _recordFile << std::move(entry) << std::endl; +void SessionRecording::saveKeyframeToFile(std::string entry, std::ofstream& file) { + file << std::move(entry) << std::endl; } SessionRecording::CallbackHandle SessionRecording::addStateChangeCallback( From ae5da23b0434d8b228dee72e3dc9b6a56cd3f435 Mon Sep 17 00:00:00 2001 From: GPayne Date: Mon, 28 Oct 2019 15:56:27 -0600 Subject: [PATCH 064/123] Separated writing of time keyframes into separate read & parse steps --- .../openspace/interaction/sessionrecording.h | 27 +++++- src/interaction/sessionrecording.cpp | 91 ++++++++++++------- 2 files changed, 81 insertions(+), 37 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 69ddb74ee5..a584dd56c6 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -303,7 +303,7 @@ public: * \param kf reference to a camera keyframe which contains the camera details * \param kfBuffer a buffer temporarily used for preparing data to be written * \param idx index into the temporary buffer - * \param file an ofstream reference to the playback file being written-to + * \param file an ofstream reference to the recording file being written-to */ static void SessionRecording::saveCameraKeyframeBinary(timestamps times, datamessagestructures::CameraKeyframe& kf, unsigned char* kfBuffer, size_t& idx, @@ -314,11 +314,34 @@ public: * * \param times reference to a timestamps structure which contains recorded times * \param kf reference to a camera keyframe which contains the camera details - * \param file an ofstream reference to the playback file being written-to + * \param file an ofstream reference to the recording file being written-to */ static void SessionRecording::saveCameraKeyframeAscii(timestamps times, datamessagestructures::CameraKeyframe& kf, std::ofstream& file); + /** + * Writes a time keyframe to a binary format recording file using a TimeKeyframe + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a time keyframe which contains the time details + * \param kfBuffer a buffer temporarily used for preparing data to be written + * \param idx index into the temporary buffer + * \param file an ofstream reference to the recording file being written-to + */ + static void SessionRecording::saveTimeKeyframeBinary(timestamps times, + datamessagestructures::TimeKeyframe& kf, unsigned char* kfBuffer, size_t& idx, + std::ofstream& file); + + /** + * Writes a time keyframe to an ascii format recording file using a TimeKeyframe + * + * \param times reference to a timestamps structure which contains recorded times + * \param kf reference to a time keyframe which contains the time details + * \param file an ofstream reference to the recording file being written-to + */ + static void SessionRecording::saveTimeKeyframeAscii(timestamps times, + datamessagestructures::TimeKeyframe& kf, std::ofstream& file); + private: enum class RecordedType { Camera = 0, diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 89bde19f33..7547c834a9 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -513,11 +513,13 @@ static void SessionRecording::saveCameraKeyframeAscii(timestamps times, keyframeLine << times.timeRec << ' '; keyframeLine << std::fixed << std::setprecision(3) << times.timeSim << ' '; // Add camera position - keyframeLine << std::fixed << std::setprecision(7) << kf._position.x << ' ' + keyframeLine + << std::fixed << std::setprecision(7) << kf._position.x << ' ' << std::fixed << std::setprecision(7) << kf._position.y << ' ' << std::fixed << std::setprecision(7) << kf._position.z << ' '; // Add camera rotation - keyframeLine << std::fixed << std::setprecision(7) << kf._rotation.x << ' ' + keyframeLine + << std::fixed << std::setprecision(7) << kf._rotation.x << ' ' << std::fixed << std::setprecision(7) << kf._rotation.y << ' ' << std::fixed << std::setprecision(7) << kf._rotation.z << ' ' << std::fixed << std::setprecision(7) << kf._rotation.w << ' '; @@ -541,44 +543,63 @@ void SessionRecording::saveTimeKeyframe() { //Create a time keyframe, then call to populate it with current time props datamessagestructures::TimeKeyframe kf = _externInteract.generateTimeKeyframe(); + timestamps times = { + kf._timestamp, + kf._timestamp - _timestampRecordStarted, + global::timeManager.time().j2000Seconds() + }; if (_recordingDataMode == RecordedDataMode::Binary) { - _bufferIndex = 0; - _keyframeBuffer[_bufferIndex++] = 't'; - writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._timestamp); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._timestamp - - _timestampRecordStarted); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._time); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._dt); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._paused); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, kf._requiresTimeJump); - - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex, _recordFile); + saveTimeKeyframeBinary(times, kf, _keyframeBuffer, _bufferIndex, _recordFile); } else { - std::stringstream keyframeLine = std::stringstream(); - //Add simulation timestamp, timestamp relative, simulation time to recording start - keyframeLine << "time "; - keyframeLine << kf._timestamp << ' '; - keyframeLine << (kf._timestamp - _timestampRecordStarted) << ' '; - - keyframeLine << std::fixed << std::setprecision(3) << kf._time; - - keyframeLine << ' ' << kf._dt; - if (kf._paused) { - keyframeLine << " P"; - } - else { - keyframeLine << " R"; - } - if (kf._requiresTimeJump) { - keyframeLine << " J"; - } - else { - keyframeLine << " -"; - } - saveKeyframeToFile(keyframeLine.str(), _recordFile); + saveTimeKeyframeAscii(times, kf, _recordFile); } } +static void SessionRecording::saveTimeKeyframeBinary(timestamps times, + datamessagestructures::TimeKeyframe& kf, + unsigned char* kfBuffer, + size_t& idx, + std::ofstream& file) +{ + idx = 0; + kfBuffer[idx++] = 't'; + writeToFileBuffer(kfBuffer, idx, times.timeOs); + writeToFileBuffer(kfBuffer, idx, times.timeRec); + writeToFileBuffer(kfBuffer, idx, times.timeSim); + std::vector writeBuffer; + kf.serialize(writeBuffer); + writeToFileBuffer(kfBuffer, idx, writeBuffer); + + saveKeyframeToFileBinary(kfBuffer, idx, file); +} + +static void SessionRecording::saveTimeKeyframeAscii(timestamps times, + datamessagestructures::CameraKeyframe& kf, + std::ofstream& file) +{ + std::stringstream keyframeLine = std::stringstream(); + //Add simulation timestamp, timestamp relative, simulation time to recording start + keyframeLine << "time "; + keyframeLine << times.timeOs << ' '; + keyframeLine << times.timeRec << ' '; + keyframeLine << std::fixed << std::setprecision(3) << times.timeSim << ' '; + + keyframeLine << ' ' << kf._dt; + if (kf._paused) { + keyframeLine << " P"; + } + else { + keyframeLine << " R"; + } + if (kf._requiresTimeJump) { + keyframeLine << " J"; + } + else { + keyframeLine << " -"; + } + saveKeyframeToFile(keyframeLine.str(), _recordFile); +} + void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { if (_state != SessionState::Recording) { return; From 37924c273464acdb1f9b19da27e7cb5e037ec9d4 Mon Sep 17 00:00:00 2001 From: GPayne Date: Tue, 29 Oct 2019 19:23:34 -0600 Subject: [PATCH 065/123] Finished separating script messages into separate read & parse steps --- .../openspace/interaction/sessionrecording.h | 34 +++- include/openspace/network/messagestructures.h | 59 ++++++ src/interaction/sessionrecording.cpp | 172 ++++++++---------- 3 files changed, 166 insertions(+), 99 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index a584dd56c6..a9dc5852c1 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -302,11 +302,10 @@ public: * \param times reference to a timestamps structure which contains recorded times * \param kf reference to a camera keyframe which contains the camera details * \param kfBuffer a buffer temporarily used for preparing data to be written - * \param idx index into the temporary buffer * \param file an ofstream reference to the recording file being written-to */ static void SessionRecording::saveCameraKeyframeBinary(timestamps times, - datamessagestructures::CameraKeyframe& kf, unsigned char* kfBuffer, size_t& idx, + datamessagestructures::CameraKeyframe& kf, unsigned char* kfBuffer, std::ofstream& file); /** @@ -325,11 +324,10 @@ public: * \param times reference to a timestamps structure which contains recorded times * \param kf reference to a time keyframe which contains the time details * \param kfBuffer a buffer temporarily used for preparing data to be written - * \param idx index into the temporary buffer * \param file an ofstream reference to the recording file being written-to */ static void SessionRecording::saveTimeKeyframeBinary(timestamps times, - datamessagestructures::TimeKeyframe& kf, unsigned char* kfBuffer, size_t& idx, + datamessagestructures::TimeKeyframe& kf, unsigned char* kfBuffer, std::ofstream& file); /** @@ -342,6 +340,28 @@ public: static void SessionRecording::saveTimeKeyframeAscii(timestamps times, datamessagestructures::TimeKeyframe& kf, std::ofstream& file); + /** + * Writes a script keyframe to a binary format recording file using a ScriptMessage + * + * \param times reference to a timestamps structure which contains recorded times + * \param sm reference to a ScriptMessage object which contains the script details + * \param smBuffer a buffer temporarily used for preparing data to be written + * \param file an ofstream reference to the recording file being written-to + */ + static void SessionRecording::saveScriptKeyframeBinary(timestamps times, + datamessagestructures::ScriptMessage& sm, unsigned char* smBuffer, + std::string& script, std::ofstream& file); + + /** + * Writes a script keyframe to an ascii format recording file using a ScriptMessage + * + * \param times reference to a timestamps structure which contains recorded times + * \param sm reference to a ScriptMessage which contains the script details + * \param file an ofstream reference to the recording file being written-to + */ + static void SessionRecording::saveScriptKeyframeAscii(timestamps times, + datamessagestructures::ScriptMessage& sm, std::ofstream& file); + private: enum class RecordedType { Camera = 0, @@ -403,6 +423,11 @@ private: static void writeToFileBuffer(unsigned char* buf, size_t& idx, unsigned char c); static void writeToFileBuffer(unsigned char* buf, size_t& idx, bool b); + static void SessionRecording::saveHeaderBinary(timestamps times, char type, + unsigned char* kfBuffer, size_t& idx); + static void SessionRecording::saveHeaderAscii(timestamps times, std::string& type, + std::stringstream& line); + RecordedDataMode _recordingDataMode = RecordedDataMode::Binary; SessionState _state = SessionState::Idle; SessionState _lastState = SessionState::Idle; @@ -430,7 +455,6 @@ private: + saveBufferCameraSize_min + saveBufferStringSize_max; unsigned char _keyframeBuffer[_saveBufferMaxSize_bytes]; - size_t _bufferIndex = 0; bool _cleanupNeeded = false; diff --git a/include/openspace/network/messagestructures.h b/include/openspace/network/messagestructures.h index 8b9d72cc64..d68b0b6ab3 100644 --- a/include/openspace/network/messagestructures.h +++ b/include/openspace/network/messagestructures.h @@ -188,6 +188,26 @@ struct CameraKeyframe { ); }; + void write(std::stringstream& out) const { + // Add camera position + out << std::fixed << std::setprecision(7) << _position.x << ' ' + << std::fixed << std::setprecision(7) << _position.y << ' ' + << std::fixed << std::setprecision(7) << _position.z << ' '; + // Add camera rotation + out << std::fixed << std::setprecision(7) << _rotation.x << ' ' + << std::fixed << std::setprecision(7) << _rotation.y << ' ' + << std::fixed << std::setprecision(7) << _rotation.z << ' ' + << std::fixed << std::setprecision(7) << _rotation.w << ' '; + out << std::scientific << _scale << ' '; + if (_followNodeRotation) { + out << "F "; + } + else { + out << "- "; + } + out << _focusNode; + }; + void read(std::istream* in) { // Read position in->read( @@ -284,6 +304,22 @@ struct TimeKeyframe { ); }; + void write(std::stringstream out) const { + out << ' ' << _dt; + if (_paused) { + out << " P"; + } + else { + out << " R"; + } + if (_requiresTimeJump) { + out << " J"; + } + else { + out << " -"; + } + }; + void read(std::istream* in) { in->read( reinterpret_cast(this), @@ -402,6 +438,29 @@ struct ScriptMessage { out->write(_script.c_str(), _script.size()); }; + void write(unsigned char* buf, size_t& idx, std::ofstream& file) const { + size_t strLen = _script.size(); + size_t writeSize_bytes = sizeof(size_t); + + unsigned char const *p = reinterpret_cast(&strLen); + memcpy((buf + idx), p, writeSize_bytes); + idx += static_cast(writeSize_bytes); + + memcpy((buf + idx), _script.c_str(), _script.size()); + idx += static_cast(strLen); + file.write(reinterpret_cast(buf), idx); + //Write directly to file because some scripts can be very long + file.write(_script.c_str(), _script.size()); + }; + + void write(std::stringstream& ss) const { + unsigned int numLinesInScript = static_cast( + std::count(_script.begin(), _script.end(), '\n') + ); + ss << ' ' << (numLinesInScript + 1) << ' '; + ss << _script; + } + void read(std::istream* in) { size_t strLen; //Read string length from file diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 7547c834a9..93e54dc8f6 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -421,17 +421,21 @@ static void SessionRecording::writeToFileBuffer(unsigned char* buf, idx += sizeof(char); } -void SessionRecording::saveStringToFile(const std::string& s) { +void SessionRecording::saveStringToFile(const std::string& s, + unsigned char* kfBuffer, + size_t& idx, + std::ofstream& file) +{ size_t strLen = s.size(); size_t writeSize_bytes = sizeof(size_t); - _bufferIndex = 0; + idx = 0; unsigned char const *p = reinterpret_cast(&strLen); - memcpy((_keyframeBuffer + _bufferIndex), p, writeSize_bytes); - _bufferIndex += static_cast(writeSize_bytes); - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex, _recordFile); + memcpy((kfBuffer + idx), p, writeSize_bytes); + idx += static_cast(writeSize_bytes); + saveKeyframeToFileBinary(kfBuffer, idx, file); - _recordFile.write(s.c_str(), s.size()); + file.write(s.c_str(), s.size()); } bool SessionRecording::hasCameraChangedFromPrev( @@ -474,31 +478,46 @@ void SessionRecording::saveCameraKeyframe() { global::timeManager.time().j2000Seconds() }; if (_recordingDataMode == RecordedDataMode::Binary) { - saveCameraKeyframeBinary(times, kf, _keyframeBuffer, _bufferIndex, _recordFile); + saveCameraKeyframeBinary(times, kf, _keyframeBuffer, _recordFile); } else { saveCameraKeyframeAscii(times, kf, _recordFile); } } -static void SessionRecording::saveCameraKeyframeBinary(timestamps times, - datamessagestructures::CameraKeyframe& kf, - unsigned char* kfBuffer, - size_t& idx, - std::ofstream& file) +static void SessionRecording::saveHeaderBinary(timestamps times, + char type, + unsigned char* kfBuffer, + size_t& idx) { - // Writing to a binary session recording file - idx = 0; - kfBuffer[idx++] = 'c'; - - // Writing to internal buffer, and then to file, for performance reasons + kfBuffer[idx++] = type; writeToFileBuffer(kfBuffer, idx, times.timeOs); writeToFileBuffer(kfBuffer, idx, times.timeRec); writeToFileBuffer(kfBuffer, idx, times.timeSim); +} + +static void SessionRecording::saveHeaderAscii(timestamps times, + std::string& type, + std::stringstream& line) +{ + line << type << ' '; + line << times.timeOs << ' '; + line << times.timeRec << ' '; + line << std::fixed << std::setprecision(3) << times.timeSim << ' '; +} + +static void SessionRecording::saveCameraKeyframeBinary(timestamps times, + datamessagestructures::CameraKeyframe& kf, + unsigned char* kfBuffer, + std::ofstream& file) +{ + // Writing to a binary session recording file + size_t idx = 0; + saveHeaderBinary(times, 'c', kfBuffer, idx); + // Writing to internal buffer, and then to file, for performance reasons std::vector writeBuffer; kf.serialize(writeBuffer); writeToFileBuffer(kfBuffer, idx, writeBuffer); - saveKeyframeToFileBinary(kfBuffer, idx, file); } @@ -507,31 +526,8 @@ static void SessionRecording::saveCameraKeyframeAscii(timestamps times, std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); - // Add simulation timestamp, timestamp relative, simulation time to recording start - keyframeLine << "camera "; - keyframeLine << times.timeOs << ' '; - keyframeLine << times.timeRec << ' '; - keyframeLine << std::fixed << std::setprecision(3) << times.timeSim << ' '; - // Add camera position - keyframeLine - << std::fixed << std::setprecision(7) << kf._position.x << ' ' - << std::fixed << std::setprecision(7) << kf._position.y << ' ' - << std::fixed << std::setprecision(7) << kf._position.z << ' '; - // Add camera rotation - keyframeLine - << std::fixed << std::setprecision(7) << kf._rotation.x << ' ' - << std::fixed << std::setprecision(7) << kf._rotation.y << ' ' - << std::fixed << std::setprecision(7) << kf._rotation.z << ' ' - << std::fixed << std::setprecision(7) << kf._rotation.w << ' '; - keyframeLine << std::scientific << kf._scale << ' '; - if (kf._followNodeRotation) { - keyframeLine << "F "; - } - else { - keyframeLine << "- "; - } - keyframeLine << kf._focusNode; - + saveHeaderAscii(times, "camera", keyframeLine); + kf.write(keyframeLine); saveKeyframeToFile(keyframeLine.str(), file); } @@ -549,7 +545,7 @@ void SessionRecording::saveTimeKeyframe() { global::timeManager.time().j2000Seconds() }; if (_recordingDataMode == RecordedDataMode::Binary) { - saveTimeKeyframeBinary(times, kf, _keyframeBuffer, _bufferIndex, _recordFile); + saveTimeKeyframeBinary(times, kf, _keyframeBuffer, _recordFile); } else { saveTimeKeyframeAscii(times, kf, _recordFile); } @@ -558,18 +554,13 @@ void SessionRecording::saveTimeKeyframe() { static void SessionRecording::saveTimeKeyframeBinary(timestamps times, datamessagestructures::TimeKeyframe& kf, unsigned char* kfBuffer, - size_t& idx, std::ofstream& file) { - idx = 0; - kfBuffer[idx++] = 't'; - writeToFileBuffer(kfBuffer, idx, times.timeOs); - writeToFileBuffer(kfBuffer, idx, times.timeRec); - writeToFileBuffer(kfBuffer, idx, times.timeSim); + size_t idx = 0; + saveHeaderBinary(times, 't', kfBuffer, idx); std::vector writeBuffer; kf.serialize(writeBuffer); writeToFileBuffer(kfBuffer, idx, writeBuffer); - saveKeyframeToFileBinary(kfBuffer, idx, file); } @@ -578,25 +569,8 @@ static void SessionRecording::saveTimeKeyframeAscii(timestamps times, std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); - //Add simulation timestamp, timestamp relative, simulation time to recording start - keyframeLine << "time "; - keyframeLine << times.timeOs << ' '; - keyframeLine << times.timeRec << ' '; - keyframeLine << std::fixed << std::setprecision(3) << times.timeSim << ' '; - - keyframeLine << ' ' << kf._dt; - if (kf._paused) { - keyframeLine << " P"; - } - else { - keyframeLine << " R"; - } - if (kf._requiresTimeJump) { - keyframeLine << " J"; - } - else { - keyframeLine << " -"; - } + saveHeaderAscii(times, "time", keyframeLine); + kf.write(keyframeLine); saveKeyframeToFile(keyframeLine.str(), _recordFile); } @@ -608,36 +582,46 @@ void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { datamessagestructures::ScriptMessage sm = _externInteract.generateScriptMessage(scriptToSave); - if (_recordingDataMode == RecordedDataMode::Binary) { - _bufferIndex = 0; - _keyframeBuffer[_bufferIndex++] = 's'; - writeToFileBuffer(_keyframeBuffer, _bufferIndex, sm._timestamp); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, sm._timestamp - _timestampRecordStarted); - writeToFileBuffer(_keyframeBuffer, _bufferIndex, global::timeManager.time().j2000Seconds()); - //Write header to file - saveKeyframeToFileBinary(_keyframeBuffer, _bufferIndex, _recordFile); + timestamps times = { + sm._timestamp, + sm._timestamp - _timestampRecordStarted, + global::timeManager.time().j2000Seconds() + }; - saveStringToFile(scriptToSave); + if (_recordingDataMode == RecordedDataMode::Binary) { + saveScriptKeyframeBinary(times, sm, _keyframeBuffer, scriptToSave, + _recordFile); } else { - unsigned int numLinesInScript = static_cast( - std::count(scriptToSave.begin(), scriptToSave.end(), '\n') - ); - std::stringstream keyframeLine = std::stringstream(); - //Add simulation timestamp, timestamp relative, simulation time to recording start - keyframeLine << "script "; - keyframeLine << sm._timestamp << ' '; - keyframeLine << (sm._timestamp - _timestampRecordStarted) << ' '; - keyframeLine << std::fixed << std::setprecision(3) << - global::timeManager.time().j2000Seconds(); - keyframeLine << ' '; - keyframeLine << (numLinesInScript + 1) << ' '; - keyframeLine << scriptToSave; - - saveKeyframeToFile(keyframeLine.str(), _recordFile); + saveScriptKeyframeAscii(times, sm, _recordFile); } } +static void SessionRecording::saveScriptKeyframeBinary(timestamps times, + datamessagestructures::ScriptMessage& sm, + unsigned char* smBuffer, + std::string& script, + std::ofstream& file) +{ + size_t idx = 0; + saveHeaderBinary(times, 's', smBuffer, idx); + //Write script header to file + saveKeyframeToFileBinary(smBuffer, idx, file); + //Write script data to file + sm.write(smBuffer, idx, file); +} + +static void SessionRecording::saveScriptKeyframeAscii(timestamps times, + datamessagestructures::ScriptMessage& sm, + std::ofstream& file) +{ + + std::stringstream keyframeLine = std::stringstream(); + saveHeaderAscii(times, "script", keyframeLine); + sm.write(keyframeLine); + saveKeyframeToFile(keyframeLine.str(), _recordFile); +} + void SessionRecording::preSynchronization() { if (_state == SessionState::Recording) { saveCameraKeyframe(); From 88135c1db00873440984c84c6bd83e3a5c92085d Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 31 Oct 2019 14:48:26 -0600 Subject: [PATCH 066/123] Fixed compile issues, now needs testing --- .../openspace/interaction/keyframenavigator.h | 10 +- .../openspace/interaction/sessionrecording.h | 43 ++--- include/openspace/network/messagestructures.h | 15 +- src/interaction/sessionrecording.cpp | 178 ++++++++---------- 4 files changed, 119 insertions(+), 127 deletions(-) diff --git a/include/openspace/interaction/keyframenavigator.h b/include/openspace/interaction/keyframenavigator.h index 77783d6bd4..50fae1d9eb 100644 --- a/include/openspace/interaction/keyframenavigator.h +++ b/include/openspace/interaction/keyframenavigator.h @@ -55,13 +55,21 @@ public: float scale; bool followFocusNodeRotation; + CameraPose() { + position = {0., 0., 0.}; + rotation = {0., 0., 0., 0.}; + focusNode = ""; + scale = 1.0; + followFocusNodeRotation = false; + }; + CameraPose(const openspace::datamessagestructures::CameraKeyframe& kf) { position = kf._position; rotation = kf._rotation; focusNode = kf._focusNode; scale = kf._scale; followFocusNodeRotation = kf._followNodeRotation; - } + }; }; /** diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index a9dc5852c1..46441feead 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -52,12 +52,12 @@ public: }; const std::string FileHeaderTitle = "OpenSpace_record/playback"; - constexpr const size_t FileHeaderVersionLength = 5; - constexpr const char FileHeaderVersion[FileHeaderVersionLength] = { + static const size_t FileHeaderVersionLength = 5; + const char FileHeaderVersion[FileHeaderVersionLength] = { '0', '0', '.', '8', '5' }; - constexpr const char DataFormatAsciiTag = 'A'; - constexpr const char DataFormatBinaryTag = 'B'; + const char DataFormatAsciiTag = 'A'; + const char DataFormatBinaryTag = 'B'; using CallbackHandle = int; using StateChangeCallback = std::function; @@ -255,7 +255,7 @@ public: * \param file an ifstream reference to the playback file being read * \param lineN keyframe number in playback file where this keyframe resides */ - static void SessionRecording::readTimeKeyframeBinary(timestamps& times, + static void readTimeKeyframeBinary(timestamps& times, datamessagestructures::TimeKeyframe& kf, std::ifstream& file, int lineN); /** @@ -267,7 +267,7 @@ public: * \param filenameRead a string containing the playback filename * \param lineN line number in playback file where this keyframe resides */ - static void SessionRecording::readTimeKeyframeAscii(timestamps& times, + static void readTimeKeyframeAscii(timestamps& times, datamessagestructures::TimeKeyframe& kf, std::string filenameRead, int lineN); /** @@ -280,7 +280,7 @@ public: * \param file an ifstream reference to the playback file being read * \param lineN keyframe number in playback file where this keyframe resides */ - static void SessionRecording::readScriptKeyframeBinary(timestamps& times, + static void readScriptKeyframeBinary(timestamps& times, datamessagestructures::ScriptMessage& kf, std::ifstream& file, int lineN); /** @@ -293,7 +293,7 @@ public: * \param filenameRead a string containing the playback filename * \param lineN line number in playback file where this keyframe resides */ - static void SessionRecording::readScriptKeyframeAscii(timestamps& times, + static void readScriptKeyframeAscii(timestamps& times, datamessagestructures::ScriptMessage& kf, std::string filenameRead, int lineN); /** @@ -304,7 +304,7 @@ public: * \param kfBuffer a buffer temporarily used for preparing data to be written * \param file an ofstream reference to the recording file being written-to */ - static void SessionRecording::saveCameraKeyframeBinary(timestamps times, + static void saveCameraKeyframeBinary(timestamps times, datamessagestructures::CameraKeyframe& kf, unsigned char* kfBuffer, std::ofstream& file); @@ -315,7 +315,7 @@ public: * \param kf reference to a camera keyframe which contains the camera details * \param file an ofstream reference to the recording file being written-to */ - static void SessionRecording::saveCameraKeyframeAscii(timestamps times, + static void saveCameraKeyframeAscii(timestamps times, datamessagestructures::CameraKeyframe& kf, std::ofstream& file); /** @@ -326,7 +326,7 @@ public: * \param kfBuffer a buffer temporarily used for preparing data to be written * \param file an ofstream reference to the recording file being written-to */ - static void SessionRecording::saveTimeKeyframeBinary(timestamps times, + static void saveTimeKeyframeBinary(timestamps times, datamessagestructures::TimeKeyframe& kf, unsigned char* kfBuffer, std::ofstream& file); @@ -337,7 +337,7 @@ public: * \param kf reference to a time keyframe which contains the time details * \param file an ofstream reference to the recording file being written-to */ - static void SessionRecording::saveTimeKeyframeAscii(timestamps times, + static void saveTimeKeyframeAscii(timestamps times, datamessagestructures::TimeKeyframe& kf, std::ofstream& file); /** @@ -348,9 +348,9 @@ public: * \param smBuffer a buffer temporarily used for preparing data to be written * \param file an ofstream reference to the recording file being written-to */ - static void SessionRecording::saveScriptKeyframeBinary(timestamps times, + static void saveScriptKeyframeBinary(timestamps times, datamessagestructures::ScriptMessage& sm, unsigned char* smBuffer, - std::string& script, std::ofstream& file); + std::ofstream& file); /** * Writes a script keyframe to an ascii format recording file using a ScriptMessage @@ -359,7 +359,7 @@ public: * \param sm reference to a ScriptMessage which contains the script details * \param file an ofstream reference to the recording file being written-to */ - static void SessionRecording::saveScriptKeyframeAscii(timestamps times, + static void saveScriptKeyframeAscii(timestamps times, datamessagestructures::ScriptMessage& sm, std::ofstream& file); private: @@ -389,11 +389,12 @@ private: void playbackScript(); bool playbackAddEntriesToTimeline(); void signalPlaybackFinishedForComponent(RecordedType type); - void saveStringToFile(const std::string& s); - void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size, - std::ofstream& file); void findFirstCameraKeyframeInTimeline(); - void saveKeyframeToFile(std::string entry, std::ofstream& file); + static void saveStringToFile(const std::string& s, unsigned char* kfBuffer, size_t& idx, + std::ofstream& file); + static void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size, + std::ofstream& file); + static void saveKeyframeToFile(std::string entry, std::ofstream& file); void addKeyframe(double timestamp, interaction::KeyframeNavigator::CameraPose keyframe); @@ -423,9 +424,9 @@ private: static void writeToFileBuffer(unsigned char* buf, size_t& idx, unsigned char c); static void writeToFileBuffer(unsigned char* buf, size_t& idx, bool b); - static void SessionRecording::saveHeaderBinary(timestamps times, char type, + static void saveHeaderBinary(timestamps times, char type, unsigned char* kfBuffer, size_t& idx); - static void SessionRecording::saveHeaderAscii(timestamps times, std::string& type, + static void saveHeaderAscii(timestamps times, const std::string& type, std::stringstream& line); RecordedDataMode _recordingDataMode = RecordedDataMode::Binary; diff --git a/include/openspace/network/messagestructures.h b/include/openspace/network/messagestructures.h index d68b0b6ab3..4f1bf0c4a8 100644 --- a/include/openspace/network/messagestructures.h +++ b/include/openspace/network/messagestructures.h @@ -30,6 +30,8 @@ #include #include #include +#include +#include namespace openspace::datamessagestructures { @@ -254,7 +256,7 @@ struct CameraKeyframe { ); }; - void read(std::istringstream* iss) { + void read(std::istringstream& iss) { std::string rotationFollowing; iss >> _position.x @@ -304,7 +306,7 @@ struct TimeKeyframe { ); }; - void write(std::stringstream out) const { + void write(std::stringstream& out) const { out << ' ' << _dt; if (_paused) { out << " P"; @@ -327,7 +329,7 @@ struct TimeKeyframe { ); }; - void read(std::istringstream* iss) { + void read(std::istringstream& iss) { std::string paused, jump; iss >> _dt @@ -474,12 +476,15 @@ struct ScriptMessage { _script = temp.data(); }; - void read(std::istringstream* iss) { + void read(std::istringstream& iss) { int numScriptLines; iss >> numScriptLines; + if (numScriptLines < 0) { + numScriptLines = 0; + } std::string tmpReadbackScript; _script.erase(); - for (unsigned int i = 0; i < numScriptLines; ++i) { + for (int i = 0; i < numScriptLines; ++i) { std::getline(iss, tmpReadbackScript); _script.append(tmpReadbackScript); if (i < (numScriptLines - 1)) { diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 93e54dc8f6..96b437a00f 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -54,30 +54,6 @@ namespace { return res; } - template <> - bool readFromPlayback(std::ifstream& stream) { - unsigned char b; - stream.read(reinterpret_cast(&b), sizeof(unsigned char)); - if (b == 0) { - return false; - } - else { - return true; - } - } - - template <> - std::string readFromPlayback(std::ifstream& stream) { - size_t strLen; - // Read string length from file - stream.read(reinterpret_cast(&strLen), sizeof(strLen)); - // Read back full string - std::vector temp(strLen + 1); - stream.read(temp.data(), strLen); - temp[strLen] = '\0'; - return temp.data(); - } - std::string readHeaderElement(std::ifstream& stream, size_t readLen_chars) { std::vector readTemp(readLen_chars); stream.read(&readTemp[0], readLen_chars); @@ -183,7 +159,8 @@ void SessionRecording::stopRecording() { } bool SessionRecording::startPlayback(const std::string& filename, - KeyframeTimeRef timeMode, bool forceSimTimeAtStart) + KeyframeTimeRef timeMode, + bool forceSimTimeAtStart) { if (filename.find("/") != std::string::npos) { LERROR("Playback filename must not contain path (/) elements"); @@ -385,9 +362,9 @@ void SessionRecording::cleanUpPlayback() { _cleanupNeeded = false; } -static void SessionRecording::writeToFileBuffer(unsigned char* buf, - size_t& idx, - double src) +void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + double src) { const size_t writeSize_bytes = sizeof(double); unsigned char const *p = reinterpret_cast(&src); @@ -395,27 +372,27 @@ static void SessionRecording::writeToFileBuffer(unsigned char* buf, idx += writeSize_bytes; } -static void SessionRecording::writeToFileBuffer(unsigned char* buf, - size_t& idx, - std::vector& cv) +void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + std::vector& cv) { const size_t writeSize_bytes = cv.size() * sizeof(char); memcpy((buf + idx), cv.data(), writeSize_bytes); idx += writeSize_bytes; } -static void SessionRecording::writeToFileBuffer(unsigned char* buf, - size_t& idx, - unsigned char c) +void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + unsigned char c) { const size_t writeSize_bytes = sizeof(char); buf[idx] = c; idx += writeSize_bytes; } -static void SessionRecording::writeToFileBuffer(unsigned char* buf, - size_t& idx, - bool b) +void SessionRecording::writeToFileBuffer(unsigned char* buf, + size_t& idx, + bool b) { buf[idx] = b ? 1 : 0; idx += sizeof(char); @@ -439,7 +416,7 @@ void SessionRecording::saveStringToFile(const std::string& s, } bool SessionRecording::hasCameraChangedFromPrev( - datamessagestructures::CameraKeyframe kfNew) + datamessagestructures::CameraKeyframe kfNew) { constexpr const double threshold = 1e-2; bool hasChanged = false; @@ -485,10 +462,10 @@ void SessionRecording::saveCameraKeyframe() { } } -static void SessionRecording::saveHeaderBinary(timestamps times, - char type, - unsigned char* kfBuffer, - size_t& idx) +void SessionRecording::saveHeaderBinary(timestamps times, + char type, + unsigned char* kfBuffer, + size_t& idx) { kfBuffer[idx++] = type; writeToFileBuffer(kfBuffer, idx, times.timeOs); @@ -496,9 +473,9 @@ static void SessionRecording::saveHeaderBinary(timestamps times, writeToFileBuffer(kfBuffer, idx, times.timeSim); } -static void SessionRecording::saveHeaderAscii(timestamps times, - std::string& type, - std::stringstream& line) +void SessionRecording::saveHeaderAscii(timestamps times, + const std::string& type, + std::stringstream& line) { line << type << ' '; line << times.timeOs << ' '; @@ -506,10 +483,10 @@ static void SessionRecording::saveHeaderAscii(timestamps times, line << std::fixed << std::setprecision(3) << times.timeSim << ' '; } -static void SessionRecording::saveCameraKeyframeBinary(timestamps times, - datamessagestructures::CameraKeyframe& kf, - unsigned char* kfBuffer, - std::ofstream& file) +void SessionRecording::saveCameraKeyframeBinary(timestamps times, + datamessagestructures::CameraKeyframe& kf, + unsigned char* kfBuffer, + std::ofstream& file) { // Writing to a binary session recording file size_t idx = 0; @@ -521,9 +498,9 @@ static void SessionRecording::saveCameraKeyframeBinary(timestamps times, saveKeyframeToFileBinary(kfBuffer, idx, file); } -static void SessionRecording::saveCameraKeyframeAscii(timestamps times, +void SessionRecording::saveCameraKeyframeAscii(timestamps times, datamessagestructures::CameraKeyframe& kf, - std::ofstream& file) + std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); saveHeaderAscii(times, "camera", keyframeLine); @@ -551,10 +528,10 @@ void SessionRecording::saveTimeKeyframe() { } } -static void SessionRecording::saveTimeKeyframeBinary(timestamps times, - datamessagestructures::TimeKeyframe& kf, - unsigned char* kfBuffer, - std::ofstream& file) +void SessionRecording::saveTimeKeyframeBinary(timestamps times, + datamessagestructures::TimeKeyframe& kf, + unsigned char* kfBuffer, + std::ofstream& file) { size_t idx = 0; saveHeaderBinary(times, 't', kfBuffer, idx); @@ -564,14 +541,14 @@ static void SessionRecording::saveTimeKeyframeBinary(timestamps times, saveKeyframeToFileBinary(kfBuffer, idx, file); } -static void SessionRecording::saveTimeKeyframeAscii(timestamps times, - datamessagestructures::CameraKeyframe& kf, - std::ofstream& file) +void SessionRecording::saveTimeKeyframeAscii(timestamps times, + datamessagestructures::TimeKeyframe& kf, + std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); saveHeaderAscii(times, "time", keyframeLine); kf.write(keyframeLine); - saveKeyframeToFile(keyframeLine.str(), _recordFile); + saveKeyframeToFile(keyframeLine.str(), file); } void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { @@ -589,19 +566,17 @@ void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { }; if (_recordingDataMode == RecordedDataMode::Binary) { - saveScriptKeyframeBinary(times, sm, _keyframeBuffer, scriptToSave, - _recordFile); + saveScriptKeyframeBinary(times, sm, _keyframeBuffer, _recordFile); } else { saveScriptKeyframeAscii(times, sm, _recordFile); } } -static void SessionRecording::saveScriptKeyframeBinary(timestamps times, - datamessagestructures::ScriptMessage& sm, - unsigned char* smBuffer, - std::string& script, - std::ofstream& file) +void SessionRecording::saveScriptKeyframeBinary(timestamps times, + datamessagestructures::ScriptMessage& sm, + unsigned char* smBuffer, + std::ofstream& file) { size_t idx = 0; saveHeaderBinary(times, 's', smBuffer, idx); @@ -611,15 +586,15 @@ static void SessionRecording::saveScriptKeyframeBinary(timestamps times, sm.write(smBuffer, idx, file); } -static void SessionRecording::saveScriptKeyframeAscii(timestamps times, - datamessagestructures::ScriptMessage& sm, - std::ofstream& file) +void SessionRecording::saveScriptKeyframeAscii(timestamps times, + datamessagestructures::ScriptMessage& sm, + std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); saveHeaderAscii(times, "script", keyframeLine); sm.write(keyframeLine); - saveKeyframeToFile(keyframeLine.str(), _recordFile); + saveKeyframeToFile(keyframeLine.str(), file); } void SessionRecording::preSynchronization() { @@ -743,7 +718,8 @@ bool SessionRecording::playbackAddEntriesToTimeline() { return !parsingErrorsFound; } -double SessionRecording::appropriateTimestamp(double timeOs, double timeRec, +double SessionRecording::appropriateTimestamp(double timeOs, + double timeRec, double timeSim) { if (_playbackTimeReferenceMode == KeyframeTimeRef::Relative_recordedStart) { @@ -757,7 +733,8 @@ double SessionRecording::appropriateTimestamp(double timeOs, double timeRec, } } -double SessionRecording::equivalentSimulationTime(double timeOs, double timeRec, +double SessionRecording::equivalentSimulationTime(double timeOs, + double timeRec, double timeSim) { if (_playbackTimeReferenceMode == KeyframeTimeRef::Relative_recordedStart) { @@ -771,7 +748,8 @@ double SessionRecording::equivalentSimulationTime(double timeOs, double timeRec, } } -double SessionRecording::equivalentApplicationTime(double timeOs, double timeRec, +double SessionRecording::equivalentApplicationTime(double timeOs, + double timeRec, double timeSim) { if (_playbackTimeReferenceMode == KeyframeTimeRef::Relative_recordedStart) { @@ -837,9 +815,9 @@ void SessionRecording::playbackCamera() { addKeyframe(timeRef, pbFrame); } -static void SessionRecording::readCameraKeyframeBinary(timestamps& times, - datamessagestructures::CameraKeyframe& kf, - std::ifstream& file, int lineN) +void SessionRecording::readCameraKeyframeBinary(timestamps& times, + datamessagestructures::CameraKeyframe& kf, + std::ifstream& file, int lineN) { times.timeOs = readFromPlayback(file); times.timeRec = readFromPlayback(file); @@ -872,10 +850,10 @@ static void SessionRecording::readCameraKeyframeBinary(timestamps& times, } } -static void SessionRecording::readCameraKeyframeAscii(timestamps& times, - datamessagestructures::CameraKeyframe& kf, - std::string filenameRead, - int lineN) +void SessionRecording::readCameraKeyframeAscii(timestamps& times, + datamessagestructures::CameraKeyframe& kf, + std::string filenameRead, + int lineN) { std::string rotationFollowing; std::string entryType; @@ -883,7 +861,7 @@ static void SessionRecording::readCameraKeyframeAscii(timestamps& times, std::istringstream iss(filenameRead); iss >> entryType; iss >> times.timeOs >> times.timeRec >> times.timeSim; - kf.read(&iss); + kf.read(iss); if (iss.fail() || !iss.eof()) { LERROR(fmt::format("Error parsing camera line {} of playback file", lineN)); @@ -908,9 +886,9 @@ void SessionRecording::playbackTimeChange() { addKeyframe(kf._timestamp, kf); } -static void SessionRecording::readTimeKeyframeBinary(timestamps& times, - datamessagestructures::TimeKeyframe& kf, - std::ifstream& file, int lineN) +void SessionRecording::readTimeKeyframeBinary(timestamps& times, + datamessagestructures::TimeKeyframe& kf, + std::ifstream& file, int lineN) { times.timeOs = readFromPlayback(file); times.timeRec = readFromPlayback(file); @@ -942,21 +920,21 @@ static void SessionRecording::readTimeKeyframeBinary(timestamps& times, } } -static void SessionRecording::readTimeKeyframeAscii(timestamps& times, - datamessagestructures::TimeKeyframe& kf, - std::string filenameRead, - int lineN) +void SessionRecording::readTimeKeyframeAscii(timestamps& times, + datamessagestructures::TimeKeyframe& kf, + std::string filenameRead, + int lineN) { std::string entryType; std::istringstream iss(filenameRead); iss >> entryType; iss >> times.timeOs >> times.timeRec >> times.timeSim; - kf.read(&iss); + kf.read(iss); if (iss.fail() || !iss.eof()) { LERROR(fmt::format( - "Error parsing time line {} of playback file", _playbackLineNum + "Error parsing time line {} of playback file", lineN )); return; } @@ -976,9 +954,9 @@ void SessionRecording::playbackScript() { addKeyframe(timeRef, kf._script); } -static void SessionRecording::readScriptKeyframeBinary(timestamps& times, - datamessagestructures::ScriptMessage& kf, - std::ifstream& file, int lineN) +void SessionRecording::readScriptKeyframeBinary(timestamps& times, + datamessagestructures::ScriptMessage& kf, + std::ifstream& file, int lineN) { times.timeOs = readFromPlayback(file); times.timeRec = readFromPlayback(file); @@ -1011,24 +989,24 @@ static void SessionRecording::readScriptKeyframeBinary(timestamps& times, } } -static void SessionRecording::readScriptKeyframeAscii(timestamps& times, - datamessagestructures::ScriptMessage& kf, - std::string filenameRead, - int lineN) +void SessionRecording::readScriptKeyframeAscii(timestamps& times, + datamessagestructures::ScriptMessage& kf, + std::string filenameRead, + int lineN) { std::string entryType; std::istringstream iss(filenameRead); iss >> entryType; iss >> times.timeOs >> times.timeRec >> times.timeSim; - kf.read(&iss); + kf.read(iss); if (iss.fail()) { LERROR(fmt::format( - "Error parsing script line {} of playback file", _playbackLineNum + "Error parsing script line {} of playback file", lineN )); return; } else if (!iss.eof()) { LERROR(fmt::format( - "Did not find an EOL at line {} of playback file", _playbackLineNum + "Did not find an EOL at line {} of playback file", lineN )); return; } From 97e393b0f6b78c103f258cc0ed848db6f8ac6eea Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 27 Feb 2020 13:35:10 -0700 Subject: [PATCH 067/123] Added task code for conversion to ascii --- .../openspace/interaction/sessionrecording.h | 9 +++ .../interaction/sessionrecording.inl | 7 ++ .../interaction/tasks/convertrecformattask.h | 13 ++- src/interaction/sessionrecording.cpp | 20 ++--- .../tasks/convertrecformattask.cpp | 80 +++++++++++++++---- 5 files changed, 99 insertions(+), 30 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 46441feead..3b3372ba56 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -362,6 +362,15 @@ public: static void saveScriptKeyframeAscii(timestamps times, datamessagestructures::ScriptMessage& sm, std::ofstream& file); + /** + * Reads header information from a session recording file + * + * \param stream reference to ifstream that contains the session recording file data + * \param readLen_chars number of characters to be read, which may be the expected + * length of the header line, or an arbitrary number of characters within it + */ + static std::string readHeaderElement(std::ifstream& stream, size_t readLen_chars); + private: enum class RecordedType { Camera = 0, diff --git a/include/openspace/interaction/sessionrecording.inl b/include/openspace/interaction/sessionrecording.inl index 0839562306..30876e95f8 100644 --- a/include/openspace/interaction/sessionrecording.inl +++ b/include/openspace/interaction/sessionrecording.inl @@ -51,4 +51,11 @@ T prevKeyframeObj(unsigned int index, const std::vector& keyframeContainer) { } } +template +T readFromPlayback(std::ifstream& stream) { + T res; + stream.read(reinterpret_cast(&res), sizeof(T)); + return res; +} + } // namespace openspace::interaction diff --git a/include/openspace/interaction/tasks/convertrecformattask.h b/include/openspace/interaction/tasks/convertrecformattask.h index 65c6aeef28..fab8dfab51 100644 --- a/include/openspace/interaction/tasks/convertrecformattask.h +++ b/include/openspace/interaction/tasks/convertrecformattask.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___CONVERTRECFORMATTASK___H__ #include +#include #include @@ -38,7 +39,7 @@ namespace { constexpr const char* KeyOutFilePath = "OutputFilePath"; } -namespace openspace { +namespace openspace::interaction { class ConvertRecFormatTask : public Task { public: @@ -51,19 +52,23 @@ public: std::string description() override; void perform(const Task::ProgressCallback& progressCallback) override; static documentation::Documentation documentation(); + void convert(); + SessionRecording::RecordedDataMode ConvertRecFormatTask::formatType(); private: void convertToAscii(); void convertToBinary(); - + std::string addFileSuffix(const std::string& filePath, const std::string& suffix); std::string _inFilePath; std::string _outFilePath; std::ifstream _iFile; - std::ifstream _oFile; + std::ofstream _oFile; std::string _valueFunctionLua; + + SessionRecording sr; }; -} // namespace openspace +} // namespace openspace::interaction #endif //__OPENSPACE_CORE___CONVERTRECFORMATTASK___H__ diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 96b437a00f..c425d76b74 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -47,18 +47,6 @@ namespace { constexpr const bool UsingTimeKeyframes = false; - template - T readFromPlayback(std::ifstream& stream) { - T res; - stream.read(reinterpret_cast(&res), sizeof(T)); - return res; - } - - std::string readHeaderElement(std::ifstream& stream, size_t readLen_chars) { - std::vector readTemp(readLen_chars); - stream.read(&readTemp[0], readLen_chars); - return std::string(readTemp.begin(), readTemp.end()); - } } // namespace @@ -940,6 +928,14 @@ void SessionRecording::readTimeKeyframeAscii(timestamps& times, } } +static std::string SessionRecording::readHeaderElement(std::ifstream& stream, + size_t readLen_chars) +{ + std::vector readTemp(readLen_chars); + stream.read(&readTemp[0], readLen_chars); + return std::string(readTemp.begin(), readTemp.end()); +} + void SessionRecording::playbackScript() { timestamps times; datamessagestructures::ScriptMessage kf; diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index 1425e04e51..fbed41dd71 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -36,7 +36,7 @@ namespace { constexpr const char* _loggerCat = "ConvertRecFormatTask"; } // namespace -namespace openspace { +namespace openspace::interaction { ConvertRecFormatTask::ConvertRecFormatTask(const ghoul::Dictionary& dictionary) { openspace::documentation::testSpecificationAndThrow( @@ -68,12 +68,12 @@ void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallbac } void ConvertRecFormatTask::convert() { - interaction::RecordedDataMode type = formatType(); + SessionRecording::RecordedDataMode type = formatType(); - if (type == interaction::RecordedDataMode::Ascii) { + if (type == SessionRecording::RecordedDataMode::Ascii) { convertToBinary(); } - else if (type == interaction::RecordedDataMode::Binary) { + else if (type == SessionRecording::RecordedDataMode::Binary) { convertToAscii(); } else { @@ -82,33 +82,83 @@ void ConvertRecFormatTask::convert() { } } -RecordedDataMode ConvertRecFormatTask::formatType() { +SessionRecording::RecordedDataMode ConvertRecFormatTask::formatType() { const std::string expectedHeader = "OpenSpace_record/playback"; std::string line; //Get first line, which is ASCII regardless of format std::getline(_iFile, line); - if (line.substr(0, interaction::FileHeaderTitle.length()) - != interaction::FileHeaderTitle) + if (line.substr(0, SessionRecording::FileHeaderTitle.length()) + != SessionRecording::FileHeaderTitle) { LERROR(fmt::format("Session recording file {} does not have expected header.", _inFilePath)); - return RecordedDataMode::Binary + 1; + return SessionRecording::RecordedDataMode::Binary + 1; } else { - if (line.back() == DataFormatAsciiTag) { - return RecordedDataMode::Ascii; + if (line.back() == SessionRecording::DataFormatAsciiTag) { + return SessionRecording::RecordedDataMode::Ascii; } - else if (line.back() == DataFormatBinaryTag) { - return RecordedDataMode::Binary; + else if (line.back() == SessionRecording::DataFormatBinaryTag) { + return SessionRecording::RecordedDataMode::Binary; } else { - return RecordedDataMode::Binary + 1; + return SessionRecording::RecordedDataMode::Binary + 1; } } } void ConvertRecFormatTask::convertToAscii() { + SessionRecording::timestamps times; + datamessagestructures::CameraKeyframe ckf; + datamessagestructures::TimeKeyframe tkf; + datamessagestructures::ScriptMessage skf; + int lineNum = 1; + unsigned char frameType; _outFilePath = addFileSuffix(_inFilePath, "_ascii"); + + bool fileReadOk = true; + while (fileReadOk) { + frameType = readFromPlayback(_iFile); + // Check if have reached EOF + if (!_iFile) { + LINFO(fmt::format( + "Finished converting {} entries from playback file {}", + lineNum - 1, _inFilePath + )); + fileReadOk = false; + break; + } + + if (frameType == 'c') { + SessionRecording::readCameraKeyframeBinary(times, ckf, _iFile, lineNum); + std::stringstream keyframeLine = std::stringstream(); + SessionRecording::saveHeaderAscii(times, "camera", keyframeLine); + ckf.write(keyframeLine); + SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); + } + else if (frameType == 't') { + SessionRecording::readTimeKeyframeBinary(times, tkf, _iFile, lineNum); + std::stringstream keyframeLine = std::stringstream(); + SessionRecording::saveHeaderAscii(times, "time", keyframeLine); + ckf.write(keyframeLine); + SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); + } + else if (frameType == 's') { + SessionRecording::readScriptKeyframeBinary(times, skf, _iFile, lineNum); + std::stringstream keyframeLine = std::stringstream(); + SessionRecording::saveHeaderAscii(times, "script", keyframeLine); + ckf.write(keyframeLine); + SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); + } + else { + LERROR(fmt::format( + "Unknown frame type @ index {} of playback file {}", + lineNum - 1, _inFilePath + )); + break; + } + lineNum++; + } } void ConvertRecFormatTask::convertToBinary() { @@ -118,7 +168,7 @@ void ConvertRecFormatTask::convertToBinary() { std::string ConvertRecFormatTask::addFileSuffix(const std::string& filePath, const std::string& suffix) { - size_t lastdot = filename.find_last_of("."); + size_t lastdot = filePath.find_last_of("."); std::string extension = filePath.substr(0, lastdot); if (lastdot == std::string::npos) { return filePath + suffix; @@ -155,3 +205,5 @@ documentation::Documentation ConvertRecFormatTask::documentation() { }, }; } + +} From 754dfd9c91864a009d1aa2885484f66a10f69f53 Mon Sep 17 00:00:00 2001 From: GPayne Date: Thu, 27 Feb 2020 13:45:30 -0700 Subject: [PATCH 068/123] Corrections to ascii conversion steps --- src/interaction/tasks/convertrecformattask.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index fbed41dd71..d54c64f09e 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -115,6 +115,7 @@ void ConvertRecFormatTask::convertToAscii() { int lineNum = 1; unsigned char frameType; _outFilePath = addFileSuffix(_inFilePath, "_ascii"); + std::stringstream keyframeLine = std::stringstream(); bool fileReadOk = true; while (fileReadOk) { @@ -129,26 +130,21 @@ void ConvertRecFormatTask::convertToAscii() { break; } + keyframeLine.str(std::string()); if (frameType == 'c') { SessionRecording::readCameraKeyframeBinary(times, ckf, _iFile, lineNum); - std::stringstream keyframeLine = std::stringstream(); SessionRecording::saveHeaderAscii(times, "camera", keyframeLine); ckf.write(keyframeLine); - SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); } else if (frameType == 't') { SessionRecording::readTimeKeyframeBinary(times, tkf, _iFile, lineNum); - std::stringstream keyframeLine = std::stringstream(); SessionRecording::saveHeaderAscii(times, "time", keyframeLine); - ckf.write(keyframeLine); - SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); + tkf.write(keyframeLine); } else if (frameType == 's') { SessionRecording::readScriptKeyframeBinary(times, skf, _iFile, lineNum); - std::stringstream keyframeLine = std::stringstream(); SessionRecording::saveHeaderAscii(times, "script", keyframeLine); - ckf.write(keyframeLine); - SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); + skf.write(keyframeLine); } else { LERROR(fmt::format( @@ -157,6 +153,7 @@ void ConvertRecFormatTask::convertToAscii() { )); break; } + SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); lineNum++; } } From 9ba31ee0825bf9c292bae627cabc3ea33af5a71a Mon Sep 17 00:00:00 2001 From: GPayne Date: Wed, 4 Mar 2020 09:55:51 -0700 Subject: [PATCH 069/123] Added code for conversion to binary format --- .../openspace/interaction/sessionrecording.h | 12 ++-- .../tasks/convertrecformattask.cpp | 55 ++++++++++++++++++- 2 files changed, 59 insertions(+), 8 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 3b3372ba56..b0d523e8b9 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -59,6 +59,12 @@ public: const char DataFormatAsciiTag = 'A'; const char DataFormatBinaryTag = 'B'; + static const size_t keyframeHeaderSize_bytes = 33; + static const size_t saveBufferCameraSize_min = 82; + static const size_t saveBufferStringSize_max = 500; + static const size_t _saveBufferMaxSize_bytes = keyframeHeaderSize_bytes + + + saveBufferCameraSize_min + saveBufferStringSize_max; + using CallbackHandle = int; using StateChangeCallback = std::function; @@ -458,12 +464,6 @@ private: double _saveRenderingDeltaTime = 1.0 / 30.0; double _saveRenderingCurrentRecordedTime; - static const size_t keyframeHeaderSize_bytes = 33; - static const size_t saveBufferCameraSize_min = 82; - static const size_t saveBufferStringSize_max = 500; - static const size_t _saveBufferMaxSize_bytes = keyframeHeaderSize_bytes + - + saveBufferCameraSize_min - + saveBufferStringSize_max; unsigned char _keyframeBuffer[_saveBufferMaxSize_bytes]; bool _cleanupNeeded = false; diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index d54c64f09e..8b79e4477e 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -123,7 +123,7 @@ void ConvertRecFormatTask::convertToAscii() { // Check if have reached EOF if (!_iFile) { LINFO(fmt::format( - "Finished converting {} entries from playback file {}", + "Finished converting {} entries from file {}", lineNum - 1, _inFilePath )); fileReadOk = false; @@ -159,7 +159,58 @@ void ConvertRecFormatTask::convertToAscii() { } void ConvertRecFormatTask::convertToBinary() { - _outFilePath = addFileSuffix(_inFilePath, "_binary"); + SessionRecording::timestamps times; + datamessagestructures::CameraKeyframe ckf; + datamessagestructures::TimeKeyframe tkf; + datamessagestructures::ScriptMessage skf; + int lineNum = 1; + std::string lineContents; + unsigned char keyframeBuffer[SessionRecording::_saveBufferMaxSize_bytes]; + std::ofstream saveFile; + saveFile.open(_outFilePath, std::ios::binary); + size_t idx = 0; + + while (std::getline(_iFile, lineContents)) { + lineNum++; + + std::istringstream iss(lineContents); + std::string entryType; + if (!(iss >> entryType)) { + LERROR(fmt::format( + "Error reading entry type @ line {} of file {}", + lineNum, _inFilePath + )); + break; + } + + if (entryType == "camera") { + SessionRecording::readCameraKeyframeAscii(times, ckf, _inFilePath, lineNum); + SessionRecording::saveCameraKeyframeBinary(times, ckf, keyframeBuffer, + saveFile); + } + else if (entryType == "time") { + SessionRecording::readTimeKeyframeAscii(times, tkf, _inFilePath, lineNum); + SessionRecording::saveTimeKeyframeBinary(times, tkf, keyframeBuffer, + saveFile); + } + else if (entryType == "script") { + SessionRecording::readScriptKeyframeAscii(times, skf, _inFilePath, lineNum); + SessionRecording::saveScriptKeyframeBinary(times, skf, keyframeBuffer, + saveFile); + } + else { + LERROR(fmt::format( + "Unknown frame type {} @ line {} of file {}", + entryType, lineContents, _inFilePath + )); + break; + } + } + saveFile.close(); + LINFO(fmt::format( + "Finished converting {} entries from file {}", + lineNum, _inFilePath + )); } std::string ConvertRecFormatTask::addFileSuffix(const std::string& filePath, From cd7be9b87045f731a5a4b7dec0653e398bcf40d3 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Tue, 14 Jul 2020 17:19:24 -0600 Subject: [PATCH 070/123] Conversion task working for both directions --- data/tasks/sessionRecordConvertExample1.task | 7 + .../openspace/interaction/sessionrecording.h | 80 +++++++---- .../interaction/tasks/convertrecformattask.h | 5 +- include/openspace/network/messagestructures.h | 8 ++ src/CMakeLists.txt | 2 + src/interaction/sessionrecording.cpp | 100 +++++++------- src/interaction/sessionrecording_lua.inl | 4 +- .../tasks/convertrecformattask.cpp | 124 ++++++++++++------ 8 files changed, 211 insertions(+), 119 deletions(-) create mode 100644 data/tasks/sessionRecordConvertExample1.task diff --git a/data/tasks/sessionRecordConvertExample1.task b/data/tasks/sessionRecordConvertExample1.task new file mode 100644 index 0000000000..2237c462e8 --- /dev/null +++ b/data/tasks/sessionRecordConvertExample1.task @@ -0,0 +1,7 @@ +return { + { + Type = "ConvertRecFormatTask", + InputFilePath = "../../recordings/input", + OutputFilePath = "../../recordings/output" + } +} diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index bcfedcd918..fbfc1b5c9c 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -32,13 +32,21 @@ namespace openspace::interaction { +enum class SessionRecordingDataMode { + Ascii = 0, + Binary, + Unknown +}; +static const std::string SessionRecordingFileHeaderTitle = "OpenSpace_record/playback"; +static const std::string SessionRecordingHeaderCameraAscii = "camera"; +static const std::string SessionRecordingHeaderTimeAscii = "time"; +static const std::string SessionRecordingHeaderScriptAscii = "script"; +static const char SessionRecordingHeaderCameraBinary = 'c'; +static const char SessionRecordingHeaderTimeBinary = 't'; +static const char SessionRecordingHeaderScriptBinary = 's'; + class SessionRecording : public properties::PropertyOwner { public: - enum class RecordedDataMode { - Ascii = 0, - Binary - }; - enum class SessionState { Idle = 0, Recording, @@ -51,14 +59,12 @@ public: double timeSim; }; - const std::string FileHeaderTitle = "OpenSpace_record/playback"; static const size_t FileHeaderVersionLength = 5; - const char FileHeaderVersion[FileHeaderVersionLength] = { + static constexpr char FileHeaderVersion[FileHeaderVersionLength] = { '0', '0', '.', '8', '5' }; - const char DataFormatAsciiTag = 'A'; - const char DataFormatBinaryTag = 'B'; - + static const char DataFormatAsciiTag = 'A'; + static const char DataFormatBinaryTag = 'B'; static const size_t keyframeHeaderSize_bytes = 33; static const size_t saveBufferCameraSize_min = 82; static const size_t saveBufferStringSize_max = 500; @@ -114,7 +120,7 @@ public: * * \return \c true if recording to file starts without errors */ - void setRecordDataFormat(RecordedDataMode dataMode); + void setRecordDataFormat(SessionRecordingDataMode dataMode); /** * Used to stop a recording in progress. If open, the recording file will be closed, @@ -246,11 +252,12 @@ public: * * \param times reference to a timestamps structure which contains recorded times * \param kf reference to a camera keyframe which contains camera details - * \param filenameRead a string containing the playback filename + * \param currentParsingLine string containing the most current line that was read * \param lineN line number in playback file where this keyframe resides */ static void readCameraKeyframeAscii(timestamps& times, - datamessagestructures::CameraKeyframe& kf, std::string filenameRead, int lineN); + datamessagestructures::CameraKeyframe& kf, std::string currentParsingLine, + int lineN); /** * Reads a time keyframe from a binary format playback file, and populates input @@ -270,11 +277,12 @@ public: * * \param times reference to a timestamps structure which contains recorded times * \param kf reference to a time keyframe which contains time details - * \param filenameRead a string containing the playback filename + * \param currentParsingLine string containing the most current line that was read * \param lineN line number in playback file where this keyframe resides */ static void readTimeKeyframeAscii(timestamps& times, - datamessagestructures::TimeKeyframe& kf, std::string filenameRead, int lineN); + datamessagestructures::TimeKeyframe& kf, std::string currentParsingLine, + int lineN); /** * Reads a script keyframe from a binary format playback file, and populates input @@ -296,11 +304,12 @@ public: * \param times reference to a timestamps structure which contains recorded times * \param kf reference to a script keyframe which contains the size of the script * (in chars) and the text itself - * \param filenameRead a string containing the playback filename + * \param currentParsingLine string containing the most current line that was read * \param lineN line number in playback file where this keyframe resides */ static void readScriptKeyframeAscii(timestamps& times, - datamessagestructures::ScriptMessage& kf, std::string filenameRead, int lineN); + datamessagestructures::ScriptMessage& kf, std::string currentParsingLine, + int lineN); /** * Writes a camera keyframe to a binary format recording file using a CameraKeyframe @@ -377,6 +386,35 @@ public: */ static std::string readHeaderElement(std::ifstream& stream, size_t readLen_chars); + /** + * Writes a header to a binary recording file buffer + * + * \param times reference to a timestamps structure which contains recorded times + * \param type single character signifying the keyframe type + * \param kfBuffer the char buffer holding the recording info to be written + * \param idx index into write buffer (this is updated with the num of chars written) + */ + static void saveHeaderBinary(timestamps times, char type, unsigned char* kfBuffer, + size_t& idx); + + /** + * Writes a header to an ascii recording file buffer + * + * \param times reference to a timestamps structure which contains recorded times + * \param type string signifying the keyframe type + * \param line the stringstream buffer being written to + */ + static void saveHeaderAscii(timestamps times, const std::string& type, + std::stringstream& line); + + /** + * Saves a keyframe to an ascii recording file + * + * \param entry the ascii string version of the keyframe (any type) + * \param file ofstream object to write to + */ + static void saveKeyframeToFile(std::string entry, std::ofstream& file); + private: enum class RecordedType { Camera = 0, @@ -409,7 +447,6 @@ private: std::ofstream& file); static void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size, std::ofstream& file); - static void saveKeyframeToFile(std::string entry, std::ofstream& file); void addKeyframe(double timestamp, interaction::KeyframeNavigator::CameraPose keyframe); @@ -439,12 +476,7 @@ private: static void writeToFileBuffer(unsigned char* buf, size_t& idx, unsigned char c); static void writeToFileBuffer(unsigned char* buf, size_t& idx, bool b); - static void saveHeaderBinary(timestamps times, char type, - unsigned char* kfBuffer, size_t& idx); - static void saveHeaderAscii(timestamps times, const std::string& type, - std::stringstream& line); - - RecordedDataMode _recordingDataMode = RecordedDataMode::Binary; + SessionRecordingDataMode _recordingDataMode = SessionRecordingDataMode::Binary; SessionState _state = SessionState::Idle; SessionState _lastState = SessionState::Idle; std::string _playbackFilename; diff --git a/include/openspace/interaction/tasks/convertrecformattask.h b/include/openspace/interaction/tasks/convertrecformattask.h index fab8dfab51..d084bec2a6 100644 --- a/include/openspace/interaction/tasks/convertrecformattask.h +++ b/include/openspace/interaction/tasks/convertrecformattask.h @@ -53,20 +53,19 @@ public: void perform(const Task::ProgressCallback& progressCallback) override; static documentation::Documentation documentation(); void convert(); - SessionRecording::RecordedDataMode ConvertRecFormatTask::formatType(); private: void convertToAscii(); void convertToBinary(); + void determineFormatType(); std::string addFileSuffix(const std::string& filePath, const std::string& suffix); std::string _inFilePath; std::string _outFilePath; std::ifstream _iFile; std::ofstream _oFile; + SessionRecordingDataMode _fileFormatType; std::string _valueFunctionLua; - - SessionRecording sr; }; } // namespace openspace::interaction diff --git a/include/openspace/network/messagestructures.h b/include/openspace/network/messagestructures.h index bad251b66f..0131383ebe 100644 --- a/include/openspace/network/messagestructures.h +++ b/include/openspace/network/messagestructures.h @@ -429,6 +429,12 @@ struct ScriptMessage { double _timestamp; void serialize(std::vector &buffer) const { + size_t strLen = _script.size(); + size_t writeSize_bytes = sizeof(size_t); + + unsigned char const *p = reinterpret_cast(&strLen); + buffer.insert(buffer.end(), p, p + writeSize_bytes); + buffer.insert(buffer.end(), _script.begin(), _script.end()); }; @@ -486,6 +492,8 @@ struct ScriptMessage { _script.erase(); for (int i = 0; i < numScriptLines; ++i) { std::getline(iss, tmpReadbackScript); + size_t start = tmpReadbackScript.find_first_not_of(" "); + tmpReadbackScript = tmpReadbackScript.substr(start); _script.append(tmpReadbackScript); if (i < (numScriptLines - 1)) { _script.append("\n"); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5642e724a..ae2315ffc6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -63,6 +63,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/interaction/shortcutmanager_lua.inl ${OPENSPACE_BASE_DIR}/src/interaction/websocketinputstate.cpp ${OPENSPACE_BASE_DIR}/src/interaction/websocketcamerastates.cpp + ${OPENSPACE_BASE_DIR}/src/interaction/tasks/convertrecformattask.cpp ${OPENSPACE_BASE_DIR}/src/mission/mission.cpp ${OPENSPACE_BASE_DIR}/src/mission/missionmanager.cpp ${OPENSPACE_BASE_DIR}/src/mission/missionmanager_lua.inl @@ -245,6 +246,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/interaction/shortcutmanager.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/websocketinputstate.h ${OPENSPACE_BASE_DIR}/include/openspace/interaction/websocketcamerastates.h + ${OPENSPACE_BASE_DIR}/include/openspace/interaction/tasks/convertrecformattask.h ${OPENSPACE_BASE_DIR}/include/openspace/mission/mission.h ${OPENSPACE_BASE_DIR}/include/openspace/mission/missionmanager.h ${OPENSPACE_BASE_DIR}/include/openspace/network/parallelconnection.h diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index eba6a4313a..8e26877d3d 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,8 @@ #include #include #include +#include +#include #include #include #include @@ -57,7 +60,11 @@ namespace openspace::interaction { SessionRecording::SessionRecording() : properties::PropertyOwner({ "SessionRecording", "Session Recording" }) -{} +{ + auto fTask = FactoryManager::ref().factory(); + ghoul_assert(fRenderable, "No task factory existed"); + fTask->registerClass("ConvertRecFormatTask"); +} SessionRecording::~SessionRecording() {} // NOLINT @@ -66,7 +73,7 @@ void SessionRecording::deinitialize() { stopPlayback(); } -void SessionRecording::setRecordDataFormat(RecordedDataMode dataMode) { +void SessionRecording::setRecordDataFormat(SessionRecordingDataMode dataMode) { _recordingDataMode = dataMode; } @@ -102,7 +109,7 @@ bool SessionRecording::startRecording(const std::string& filename) { _playbackActive_camera = false; _playbackActive_time = false; _playbackActive_script = false; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { _recordFile.open(absFilename, std::ios::binary); } else { @@ -115,9 +122,9 @@ bool SessionRecording::startRecording(const std::string& filename) { )); return false; } - _recordFile << FileHeaderTitle; + _recordFile << SessionRecordingFileHeaderTitle; _recordFile.write(FileHeaderVersion, FileHeaderVersionLength); - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { _recordFile << DataFormatBinaryTag; } else { @@ -180,9 +187,9 @@ bool SessionRecording::startPlayback(const std::string& filename, // Read header std::string readBackHeaderString = readHeaderElement( _playbackFile, - FileHeaderTitle.length() + SessionRecordingFileHeaderTitle.length() ); - if (readBackHeaderString != FileHeaderTitle) { + if (readBackHeaderString != SessionRecordingFileHeaderTitle) { LERROR("Specified playback file does not contain expected header."); cleanUpPlayback(); return false; @@ -190,10 +197,10 @@ bool SessionRecording::startPlayback(const std::string& filename, readHeaderElement(_playbackFile, FileHeaderVersionLength); std::string readDataMode = readHeaderElement(_playbackFile, 1); if (readDataMode[0] == DataFormatAsciiTag) { - _recordingDataMode = RecordedDataMode::Ascii; + _recordingDataMode = SessionRecordingDataMode::Ascii; } else if (readDataMode[0] == DataFormatBinaryTag) { - _recordingDataMode = RecordedDataMode::Binary; + _recordingDataMode = SessionRecordingDataMode::Binary; } else { LERROR("Unknown data type in header (should be Ascii or Binary)"); @@ -201,13 +208,14 @@ bool SessionRecording::startPlayback(const std::string& filename, } std::string throwawayNewlineChar = readHeaderElement(_playbackFile, 1); - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { //Close & re-open the file, starting from the beginning, and do dummy read // past the header, version, and data type _playbackFile.close(); _playbackFile.open(_playbackFilename, std::ifstream::in | std::ios::binary); - size_t headerSize = FileHeaderTitle.length() + FileHeaderVersionLength + - sizeof(DataFormatBinaryTag) + sizeof('\n'); + size_t headerSize = SessionRecordingFileHeaderTitle.length() + + FileHeaderVersionLength + + sizeof(DataFormatBinaryTag) + sizeof('\n'); _playbackFile.read(reinterpret_cast(&_keyframeBuffer), headerSize); } @@ -443,7 +451,7 @@ void SessionRecording::saveCameraKeyframe() { kf._timestamp - _timestampRecordStarted, global::timeManager.time().j2000Seconds() }; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { saveCameraKeyframeBinary(times, kf, _keyframeBuffer, _recordFile); } else { @@ -479,7 +487,7 @@ void SessionRecording::saveCameraKeyframeBinary(timestamps times, { // Writing to a binary session recording file size_t idx = 0; - saveHeaderBinary(times, 'c', kfBuffer, idx); + saveHeaderBinary(times, SessionRecordingHeaderCameraBinary, kfBuffer, idx); // Writing to internal buffer, and then to file, for performance reasons std::vector writeBuffer; kf.serialize(writeBuffer); @@ -492,7 +500,7 @@ void SessionRecording::saveCameraKeyframeAscii(timestamps times, std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); - saveHeaderAscii(times, "camera", keyframeLine); + saveHeaderAscii(times, SessionRecordingHeaderCameraAscii, keyframeLine); kf.write(keyframeLine); saveKeyframeToFile(keyframeLine.str(), file); } @@ -510,7 +518,7 @@ void SessionRecording::saveTimeKeyframe() { kf._timestamp - _timestampRecordStarted, global::timeManager.time().j2000Seconds() }; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { saveTimeKeyframeBinary(times, kf, _keyframeBuffer, _recordFile); } else { saveTimeKeyframeAscii(times, kf, _recordFile); @@ -523,7 +531,7 @@ void SessionRecording::saveTimeKeyframeBinary(timestamps times, std::ofstream& file) { size_t idx = 0; - saveHeaderBinary(times, 't', kfBuffer, idx); + saveHeaderBinary(times, SessionRecordingHeaderTimeBinary, kfBuffer, idx); std::vector writeBuffer; kf.serialize(writeBuffer); writeToFileBuffer(kfBuffer, idx, writeBuffer); @@ -535,7 +543,7 @@ void SessionRecording::saveTimeKeyframeAscii(timestamps times, std::ofstream& file) { std::stringstream keyframeLine = std::stringstream(); - saveHeaderAscii(times, "time", keyframeLine); + saveHeaderAscii(times, SessionRecordingHeaderTimeAscii, keyframeLine); kf.write(keyframeLine); saveKeyframeToFile(keyframeLine.str(), file); } @@ -554,7 +562,7 @@ void SessionRecording::saveScriptKeyframe(std::string scriptToSave) { global::timeManager.time().j2000Seconds() }; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { saveScriptKeyframeBinary(times, sm, _keyframeBuffer, _recordFile); } else { @@ -568,11 +576,12 @@ void SessionRecording::saveScriptKeyframeBinary(timestamps times, std::ofstream& file) { size_t idx = 0; - saveHeaderBinary(times, 's', smBuffer, idx); - //Write script header to file + saveHeaderBinary(times, SessionRecordingHeaderScriptBinary, smBuffer, idx); + // Writing to internal buffer, and then to file, for performance reasons + std::vector writeBuffer; + sm.serialize(writeBuffer); + writeToFileBuffer(smBuffer, idx, writeBuffer); saveKeyframeToFileBinary(smBuffer, idx, file); - //Write script data to file - sm.write(smBuffer, idx, file); } void SessionRecording::saveScriptKeyframeAscii(timestamps times, @@ -581,7 +590,7 @@ void SessionRecording::saveScriptKeyframeAscii(timestamps times, { std::stringstream keyframeLine = std::stringstream(); - saveHeaderAscii(times, "script", keyframeLine); + saveHeaderAscii(times, SessionRecordingHeaderScriptAscii, keyframeLine); sm.write(keyframeLine); saveKeyframeToFile(keyframeLine.str(), file); } @@ -632,7 +641,7 @@ SessionRecording::SessionState SessionRecording::state() const { bool SessionRecording::playbackAddEntriesToTimeline() { bool parsingErrorsFound = false; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { unsigned char frameType; bool fileReadOk = true; @@ -647,13 +656,13 @@ bool SessionRecording::playbackAddEntriesToTimeline() { fileReadOk = false; break; } - if (frameType == 'c') { + if (frameType == SessionRecordingHeaderCameraBinary) { playbackCamera(); } - else if (frameType == 't') { + else if (frameType == SessionRecordingHeaderTimeBinary) { playbackTimeChange(); } - else if (frameType == 's') { + else if (frameType == SessionRecordingHeaderScriptBinary) { playbackScript(); } else { @@ -682,13 +691,13 @@ bool SessionRecording::playbackAddEntriesToTimeline() { break; } - if (entryType == "camera") { + if (entryType == SessionRecordingHeaderCameraAscii) { playbackCamera(); } - else if (entryType == "time") { + else if (entryType == SessionRecordingHeaderTimeAscii) { playbackTimeChange(); } - else if (entryType == "script") { + else if (entryType == SessionRecordingHeaderScriptAscii) { playbackScript(); } else { @@ -788,7 +797,7 @@ void SessionRecording::playbackCamera() { timestamps times; datamessagestructures::CameraKeyframe kf; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { readCameraKeyframeBinary(times, kf, _playbackFile, _playbackLineNum); } else { @@ -843,16 +852,18 @@ void SessionRecording::readCameraKeyframeBinary(timestamps& times, void SessionRecording::readCameraKeyframeAscii(timestamps& times, datamessagestructures::CameraKeyframe& kf, - std::string filenameRead, + std::string currentParsingLine, int lineN) { std::string rotationFollowing; std::string entryType; - std::istringstream iss(filenameRead); + std::istringstream iss(currentParsingLine); iss >> entryType; iss >> times.timeOs >> times.timeRec >> times.timeSim; kf.read(iss); + //ASCII format does not contain trailing timestamp so add it here + kf._timestamp = times.timeOs; if (iss.fail() || !iss.eof()) { LERROR(fmt::format("Error parsing camera line {} of playback file", lineN)); @@ -864,7 +875,7 @@ void SessionRecording::playbackTimeChange() { timestamps times; datamessagestructures::TimeKeyframe kf; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { readTimeKeyframeBinary(times, kf, _playbackFile, _playbackLineNum); } else { readTimeKeyframeAscii(times, kf, _playbackLineParsing, _playbackLineNum); @@ -913,12 +924,12 @@ void SessionRecording::readTimeKeyframeBinary(timestamps& times, void SessionRecording::readTimeKeyframeAscii(timestamps& times, datamessagestructures::TimeKeyframe& kf, - std::string filenameRead, + std::string currentParsingLine, int lineN) { std::string entryType; - std::istringstream iss(filenameRead); + std::istringstream iss(currentParsingLine); iss >> entryType; iss >> times.timeOs >> times.timeRec >> times.timeSim; kf.read(iss); @@ -931,8 +942,8 @@ void SessionRecording::readTimeKeyframeAscii(timestamps& times, } } -static std::string SessionRecording::readHeaderElement(std::ifstream& stream, - size_t readLen_chars) +std::string SessionRecording::readHeaderElement(std::ifstream& stream, + size_t readLen_chars) { std::vector readTemp(readLen_chars); stream.read(&readTemp[0], readLen_chars); @@ -943,7 +954,7 @@ void SessionRecording::playbackScript() { timestamps times; datamessagestructures::ScriptMessage kf; - if (_recordingDataMode == RecordedDataMode::Binary) { + if (_recordingDataMode == SessionRecordingDataMode::Binary) { readScriptKeyframeBinary(times, kf, _playbackFile, _playbackLineNum); } else { readScriptKeyframeAscii(times, kf, _playbackLineParsing, _playbackLineNum); @@ -990,11 +1001,11 @@ void SessionRecording::readScriptKeyframeBinary(timestamps& times, void SessionRecording::readScriptKeyframeAscii(timestamps& times, datamessagestructures::ScriptMessage& kf, - std::string filenameRead, + std::string currentParsingLine, int lineN) { std::string entryType; - std::istringstream iss(filenameRead); + std::istringstream iss(currentParsingLine); iss >> entryType; iss >> times.timeOs >> times.timeRec >> times.timeSim; kf.read(iss); @@ -1156,11 +1167,6 @@ bool SessionRecording::doesTimelineEntryContainCamera(unsigned int index) const } bool SessionRecording::processNextNonCameraKeyframeAheadInTime() { - //LINFO(fmt::format( - // "Keyframe at {} frame={} timelineIndex={}", - // now, global::renderEngine._frameNumber, _idxTimeline - //)); - switch (getNextKeyframeType()) { case RecordedType::Camera: // Just return true since this function no longer handles camera keyframes diff --git a/src/interaction/sessionrecording_lua.inl b/src/interaction/sessionrecording_lua.inl index 8a1c2409b4..8e4761295b 100644 --- a/src/interaction/sessionrecording_lua.inl +++ b/src/interaction/sessionrecording_lua.inl @@ -40,7 +40,7 @@ int startRecording(lua_State* L) { return luaL_error(L, "filepath string is empty"); } global::sessionRecording.setRecordDataFormat( - openspace::interaction::SessionRecording::RecordedDataMode::Binary + openspace::interaction::SessionRecordingDataMode::Binary ); global::sessionRecording.startRecording(recordFilePath); @@ -63,7 +63,7 @@ int startRecordingAscii(lua_State* L) { return luaL_error(L, "filepath string is empty"); } global::sessionRecording.setRecordDataFormat( - openspace::interaction::SessionRecording::RecordedDataMode::Ascii + openspace::interaction::SessionRecordingDataMode::Ascii ); global::sessionRecording.startRecording(recordFilePath); diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index 8b79e4477e..6cbe5257db 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -51,11 +51,11 @@ ConvertRecFormatTask::ConvertRecFormatTask(const ghoul::Dictionary& dictionary) ghoul_assert(FileSys.fileExists(_inFilePath), "The filename must exist"); if (!FileSys.fileExists(_inFilePath)) { LERROR(fmt::format("Failed to load session recording file: {}", _inFilePath)); - //throw ghoul::FileNotFoundError(_inFilePath); } - - _iFile.exceptions(std::ofstream::failbit | std::ofstream::badbit); - _iFile.open(_inFilePath); + else { + _iFile.open(_inFilePath, std::ifstream::in); + determineFormatType(); + } } ConvertRecFormatTask::~ConvertRecFormatTask() { @@ -63,17 +63,42 @@ ConvertRecFormatTask::~ConvertRecFormatTask() { _oFile.close(); } -void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallback) { +std::string ConvertRecFormatTask::description() { + std::string description = "Convert session recording file '" + _inFilePath + "' "; + if (_fileFormatType == SessionRecordingDataMode::Ascii) { + description += "(ascii format) "; + } + else if (_fileFormatType == SessionRecordingDataMode::Binary) { + description += "(binary format) "; + } + else { + description += "(UNKNOWN format) "; + } + description += "conversion to file '" + _outFilePath + "'."; + return description; +} +void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallback) { + convert(); } void ConvertRecFormatTask::convert() { - SessionRecording::RecordedDataMode type = formatType(); + if (_fileFormatType == SessionRecordingDataMode::Ascii) { + _oFile.open(_outFilePath); + } + else if (_fileFormatType == SessionRecordingDataMode::Binary) { + _oFile.open(_outFilePath, std::ios::binary); + } + _oFile.write(SessionRecordingFileHeaderTitle.c_str(), + SessionRecordingFileHeaderTitle.length()); + _oFile.write(SessionRecording::FileHeaderVersion, + SessionRecording::FileHeaderVersionLength); + _oFile.close(); - if (type == SessionRecording::RecordedDataMode::Ascii) { + if (_fileFormatType == SessionRecordingDataMode::Ascii) { convertToBinary(); } - else if (type == SessionRecording::RecordedDataMode::Binary) { + else if (_fileFormatType == SessionRecordingDataMode::Binary) { convertToAscii(); } else { @@ -82,27 +107,31 @@ void ConvertRecFormatTask::convert() { } } -SessionRecording::RecordedDataMode ConvertRecFormatTask::formatType() { - const std::string expectedHeader = "OpenSpace_record/playback"; +void ConvertRecFormatTask::determineFormatType() { + _fileFormatType = SessionRecordingDataMode::Unknown; std::string line; - //Get first line, which is ASCII regardless of format - std::getline(_iFile, line); - if (line.substr(0, SessionRecording::FileHeaderTitle.length()) - != SessionRecording::FileHeaderTitle) + line = SessionRecording::readHeaderElement(_iFile, + SessionRecordingFileHeaderTitle.length()); + + if (line.substr(0, SessionRecordingFileHeaderTitle.length()) + != SessionRecordingFileHeaderTitle) { - LERROR(fmt::format("Session recording file {} does not have expected header.", _inFilePath)); - return SessionRecording::RecordedDataMode::Binary + 1; + LERROR(fmt::format("Session recording file {} does not have expected header.", + _inFilePath)); } else { - if (line.back() == SessionRecording::DataFormatAsciiTag) { - return SessionRecording::RecordedDataMode::Ascii; + //Read version string and throw it away (and also line feed character at end) + SessionRecording::readHeaderElement(_iFile, + SessionRecording::FileHeaderVersionLength); + line = SessionRecording::readHeaderElement(_iFile, 1); + SessionRecording::readHeaderElement(_iFile, 1); + + if (line.at(0) == SessionRecording::DataFormatAsciiTag) { + _fileFormatType = SessionRecordingDataMode::Ascii; } - else if (line.back() == SessionRecording::DataFormatBinaryTag) { - return SessionRecording::RecordedDataMode::Binary; - } - else { - return SessionRecording::RecordedDataMode::Binary + 1; + else if (line.at(0) == SessionRecording::DataFormatBinaryTag) { + _fileFormatType = SessionRecordingDataMode::Binary; } } } @@ -114,8 +143,10 @@ void ConvertRecFormatTask::convertToAscii() { datamessagestructures::ScriptMessage skf; int lineNum = 1; unsigned char frameType; - _outFilePath = addFileSuffix(_inFilePath, "_ascii"); - std::stringstream keyframeLine = std::stringstream(); + _oFile.open(_outFilePath, std::ifstream::app); + char tmpType = SessionRecording::DataFormatAsciiTag; + _oFile.write(&tmpType, 1); + _oFile.write("\n", 1); bool fileReadOk = true; while (fileReadOk) { @@ -130,20 +161,24 @@ void ConvertRecFormatTask::convertToAscii() { break; } + std::stringstream keyframeLine = std::stringstream(); keyframeLine.str(std::string()); - if (frameType == 'c') { + if (frameType == SessionRecordingHeaderCameraBinary) { SessionRecording::readCameraKeyframeBinary(times, ckf, _iFile, lineNum); - SessionRecording::saveHeaderAscii(times, "camera", keyframeLine); + SessionRecording::saveHeaderAscii(times, SessionRecordingHeaderCameraAscii, + keyframeLine); ckf.write(keyframeLine); } - else if (frameType == 't') { + else if (frameType == SessionRecordingHeaderTimeBinary) { SessionRecording::readTimeKeyframeBinary(times, tkf, _iFile, lineNum); - SessionRecording::saveHeaderAscii(times, "time", keyframeLine); + SessionRecording::saveHeaderAscii(times, SessionRecordingHeaderTimeAscii, + keyframeLine); tkf.write(keyframeLine); } - else if (frameType == 's') { + else if (frameType == SessionRecordingHeaderScriptBinary) { SessionRecording::readScriptKeyframeBinary(times, skf, _iFile, lineNum); - SessionRecording::saveHeaderAscii(times, "script", keyframeLine); + SessionRecording::saveHeaderAscii(times, SessionRecordingHeaderScriptAscii, + keyframeLine); skf.write(keyframeLine); } else { @@ -156,6 +191,7 @@ void ConvertRecFormatTask::convertToAscii() { SessionRecording::saveKeyframeToFile(keyframeLine.str(), _oFile); lineNum++; } + _oFile.close(); } void ConvertRecFormatTask::convertToBinary() { @@ -166,8 +202,10 @@ void ConvertRecFormatTask::convertToBinary() { int lineNum = 1; std::string lineContents; unsigned char keyframeBuffer[SessionRecording::_saveBufferMaxSize_bytes]; - std::ofstream saveFile; - saveFile.open(_outFilePath, std::ios::binary); + _oFile.open(_outFilePath, std::ifstream::app | std::ios::binary); + char tmpType = SessionRecording::DataFormatBinaryTag; + _oFile.write(&tmpType, 1); + _oFile.write("\n", 1); size_t idx = 0; while (std::getline(_iFile, lineContents)) { @@ -183,20 +221,20 @@ void ConvertRecFormatTask::convertToBinary() { break; } - if (entryType == "camera") { - SessionRecording::readCameraKeyframeAscii(times, ckf, _inFilePath, lineNum); + if (entryType == SessionRecordingHeaderCameraAscii) { + SessionRecording::readCameraKeyframeAscii(times, ckf, lineContents, lineNum); SessionRecording::saveCameraKeyframeBinary(times, ckf, keyframeBuffer, - saveFile); + _oFile); } - else if (entryType == "time") { - SessionRecording::readTimeKeyframeAscii(times, tkf, _inFilePath, lineNum); + else if (entryType == SessionRecordingHeaderTimeAscii) { + SessionRecording::readTimeKeyframeAscii(times, tkf, lineContents, lineNum); SessionRecording::saveTimeKeyframeBinary(times, tkf, keyframeBuffer, - saveFile); + _oFile); } - else if (entryType == "script") { - SessionRecording::readScriptKeyframeAscii(times, skf, _inFilePath, lineNum); + else if (entryType == SessionRecordingHeaderScriptAscii) { + SessionRecording::readScriptKeyframeAscii(times, skf, lineContents, lineNum); SessionRecording::saveScriptKeyframeBinary(times, skf, keyframeBuffer, - saveFile); + _oFile); } else { LERROR(fmt::format( @@ -206,7 +244,7 @@ void ConvertRecFormatTask::convertToBinary() { break; } } - saveFile.close(); + _oFile.close(); LINFO(fmt::format( "Finished converting {} entries from file {}", lineNum, _inFilePath From 273e04464755f4cacc9ac1a3be8ec119c2084887 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Wed, 15 Jul 2020 08:39:31 -0600 Subject: [PATCH 071/123] Added handling of playback file that is too large for memory --- .../openspace/interaction/sessionrecording.h | 21 ++-- src/interaction/sessionrecording.cpp | 101 ++++++++++++------ 2 files changed, 78 insertions(+), 44 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index fbfc1b5c9c..5fb72268a4 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -437,21 +437,24 @@ private: double equivalentSimulationTime(double timeOs, double timeRec, double timeSim); double equivalentApplicationTime(double timeOs, double timeRec, double timeSim); - void playbackCamera(); - void playbackTimeChange(); - void playbackScript(); + bool playbackCamera(); + bool playbackTimeChange(); + bool playbackScript(); bool playbackAddEntriesToTimeline(); void signalPlaybackFinishedForComponent(RecordedType type); void findFirstCameraKeyframeInTimeline(); - static void saveStringToFile(const std::string& s, unsigned char* kfBuffer, size_t& idx, - std::ofstream& file); + static void saveStringToFile(const std::string& s, unsigned char* kfBuffer, + size_t& idx, std::ofstream& file); static void saveKeyframeToFileBinary(unsigned char* bufferSource, size_t size, std::ofstream& file); - void addKeyframe(double timestamp, - interaction::KeyframeNavigator::CameraPose keyframe); - void addKeyframe(double timestamp, datamessagestructures::TimeKeyframe keyframe); - void addKeyframe(double timestamp, std::string scriptToQueue); + bool addKeyframe(double timestamp, + interaction::KeyframeNavigator::CameraPose keyframe, int lineNum); + bool addKeyframe(double timestamp, datamessagestructures::TimeKeyframe keyframe, + int lineNum); + bool addKeyframe(double timestamp, std::string scriptToQueue, int lineNum); + bool addKeyframeToTimeline(RecordedType type, size_t indexIntoTypeKeyframes, + double timestamp, int lineNum); void moveAheadInTime(); void lookForNonCameraKeyframesThatHaveComeDue(double currTime); void updateCameraWithOrWithoutNewKeyframes(double currTime); diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 8e26877d3d..4a545275b7 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -639,13 +639,13 @@ SessionRecording::SessionState SessionRecording::state() const { } bool SessionRecording::playbackAddEntriesToTimeline() { - bool parsingErrorsFound = false; + bool parsingStatusOk = true; if (_recordingDataMode == SessionRecordingDataMode::Binary) { unsigned char frameType; bool fileReadOk = true; - while (fileReadOk) { + while (parsingStatusOk && fileReadOk) { frameType = readFromPlayback(_playbackFile); // Check if have reached EOF if (!_playbackFile) { @@ -657,20 +657,20 @@ bool SessionRecording::playbackAddEntriesToTimeline() { break; } if (frameType == SessionRecordingHeaderCameraBinary) { - playbackCamera(); + parsingStatusOk = playbackCamera(); } else if (frameType == SessionRecordingHeaderTimeBinary) { - playbackTimeChange(); + parsingStatusOk = playbackTimeChange(); } else if (frameType == SessionRecordingHeaderScriptBinary) { - playbackScript(); + parsingStatusOk = playbackScript(); } else { LERROR(fmt::format( "Unknown frame type {} @ index {} of playback file {}", frameType, _playbackLineNum - 1, _playbackFilename )); - parsingErrorsFound = true; + parsingStatusOk = false; break; } @@ -678,7 +678,7 @@ bool SessionRecording::playbackAddEntriesToTimeline() { } } else { - while (std::getline(_playbackFile, _playbackLineParsing)) { + while (parsingStatusOk && std::getline(_playbackFile, _playbackLineParsing)) { _playbackLineNum++; std::istringstream iss(_playbackLineParsing); @@ -692,20 +692,20 @@ bool SessionRecording::playbackAddEntriesToTimeline() { } if (entryType == SessionRecordingHeaderCameraAscii) { - playbackCamera(); + parsingStatusOk = playbackCamera(); } else if (entryType == SessionRecordingHeaderTimeAscii) { - playbackTimeChange(); + parsingStatusOk = playbackTimeChange(); } else if (entryType == SessionRecordingHeaderScriptAscii) { - playbackScript(); + parsingStatusOk = playbackScript(); } else { LERROR(fmt::format( "Unknown frame type {} @ line {} of playback file {}", entryType, _playbackLineNum, _playbackFilename )); - parsingErrorsFound = true; + parsingStatusOk = false; break; } } @@ -715,7 +715,7 @@ bool SessionRecording::playbackAddEntriesToTimeline() { )); } - return !parsingErrorsFound; + return parsingStatusOk; } double SessionRecording::appropriateTimestamp(double timeOs, @@ -793,7 +793,7 @@ double SessionRecording::fixedDeltaTimeDuringFrameOutput() const { } } -void SessionRecording::playbackCamera() { +bool SessionRecording::playbackCamera() { timestamps times; datamessagestructures::CameraKeyframe kf; @@ -812,7 +812,7 @@ void SessionRecording::playbackCamera() { double timeRef = appropriateTimestamp(times.timeOs, times.timeRec, times.timeSim); interaction::KeyframeNavigator::CameraPose pbFrame(kf); - addKeyframe(timeRef, pbFrame); + return addKeyframe(timeRef, pbFrame, _playbackLineNum); } void SessionRecording::readCameraKeyframeBinary(timestamps& times, @@ -871,7 +871,7 @@ void SessionRecording::readCameraKeyframeAscii(timestamps& times, } } -void SessionRecording::playbackTimeChange() { +bool SessionRecording::playbackTimeChange() { timestamps times; datamessagestructures::TimeKeyframe kf; @@ -885,7 +885,7 @@ void SessionRecording::playbackTimeChange() { kf._time = kf._timestamp + _timestampApplicationStarted_simulation; //global::timeManager.addKeyframe(timeRef, pbFrame._timestamp); //_externInteract.timeInteraction(pbFrame); - addKeyframe(kf._timestamp, kf); + return addKeyframe(kf._timestamp, kf, _playbackLineNum); } void SessionRecording::readTimeKeyframeBinary(timestamps& times, @@ -950,7 +950,7 @@ std::string SessionRecording::readHeaderElement(std::ifstream& stream, return std::string(readTemp.begin(), readTemp.end()); } -void SessionRecording::playbackScript() { +bool SessionRecording::playbackScript() { timestamps times; datamessagestructures::ScriptMessage kf; @@ -961,7 +961,7 @@ void SessionRecording::playbackScript() { } double timeRef = appropriateTimestamp(times.timeOs, times.timeRec, times.timeSim); - addKeyframe(timeRef, kf._script); + return addKeyframe(timeRef, kf._script, _playbackLineNum); } void SessionRecording::readScriptKeyframeBinary(timestamps& times, @@ -1022,38 +1022,69 @@ void SessionRecording::readScriptKeyframeAscii(timestamps& times, } } -void SessionRecording::addKeyframe(double timestamp, - interaction::KeyframeNavigator::CameraPose keyframe) +bool SessionRecording::addKeyframe(double timestamp, + interaction::KeyframeNavigator::CameraPose keyframe, + int lineNum) { size_t indexIntoCameraKeyframesFromMainTimeline = _keyframesCamera.size(); _keyframesCamera.push_back(std::move(keyframe)); - _timeline.push_back({ + return addKeyframeToTimeline( RecordedType::Camera, - static_cast(indexIntoCameraKeyframesFromMainTimeline), - timestamp - }); + indexIntoCameraKeyframesFromMainTimeline, + timestamp, + lineNum + ); } -void SessionRecording::addKeyframe(double timestamp, - datamessagestructures::TimeKeyframe keyframe) +bool SessionRecording::addKeyframe(double timestamp, + datamessagestructures::TimeKeyframe keyframe, + int lineNum) { size_t indexIntoTimeKeyframesFromMainTimeline = _keyframesTime.size(); _keyframesTime.push_back(std::move(keyframe)); - _timeline.push_back({ + return addKeyframeToTimeline( RecordedType::Time, - static_cast(indexIntoTimeKeyframesFromMainTimeline), - timestamp - }); + indexIntoTimeKeyframesFromMainTimeline, + timestamp, + lineNum + ); } -void SessionRecording::addKeyframe(double timestamp, std::string scriptToQueue) { +bool SessionRecording::addKeyframe(double timestamp, + std::string scriptToQueue, + int lineNum) +{ size_t indexIntoScriptKeyframesFromMainTimeline = _keyframesScript.size(); _keyframesScript.push_back(std::move(scriptToQueue)); - _timeline.push_back({ + return addKeyframeToTimeline( RecordedType::Script, - static_cast(indexIntoScriptKeyframesFromMainTimeline), - timestamp - }); + indexIntoScriptKeyframesFromMainTimeline, + timestamp, + lineNum + ); +} + +bool SessionRecording::addKeyframeToTimeline(RecordedType type, + size_t indexIntoTypeKeyframes, + double timestamp, + int lineNum) +{ + try { + _timeline.push_back({ + type, + static_cast(indexIntoTypeKeyframes), + timestamp + }); + } + catch(...) { + LERROR(fmt::format( + "Timeline memory allocation error trying to add keyframe {}. " + "The playback file may be too large for system memory.", + lineNum - 1 + )); + return false; + } + return true; } void SessionRecording::moveAheadInTime() { From 5a23ae35c8ce51741d13175314e38c92846dfe1e Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Wed, 15 Jul 2020 13:04:39 -0600 Subject: [PATCH 072/123] Added file extensions for session recording files --- .../openspace/interaction/sessionrecording.h | 13 +- src/interaction/sessionrecording.cpp | 120 ++++++++++++------ .../tasks/convertrecformattask.cpp | 32 +++++ 3 files changed, 123 insertions(+), 42 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 5fb72268a4..23635a7780 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -41,10 +41,13 @@ static const std::string SessionRecordingFileHeaderTitle = "OpenSpace_record/pla static const std::string SessionRecordingHeaderCameraAscii = "camera"; static const std::string SessionRecordingHeaderTimeAscii = "time"; static const std::string SessionRecordingHeaderScriptAscii = "script"; +static const std::string SessionRecordingFileExtensionBinary = ".osrec"; +static const std::string SessionRecordingFileExtensionAscii = ".osrectxt"; static const char SessionRecordingHeaderCameraBinary = 'c'; static const char SessionRecordingHeaderTimeBinary = 't'; static const char SessionRecordingHeaderScriptBinary = 's'; + class SessionRecording : public properties::PropertyOwner { public: enum class SessionState { @@ -415,6 +418,14 @@ public: */ static void saveKeyframeToFile(std::string entry, std::ofstream& file); + /** + * Checks if a specified recording file ends with a particular file extension + * + * \param filename the name of the file to record to + * \param extension the file extension to check for + */ + static bool hasFileExtension(std::string filename, std::string extension); + private: enum class RecordedType { Camera = 0, @@ -436,7 +447,7 @@ private: double appropriateTimestamp(double timeOs, double timeRec, double timeSim); double equivalentSimulationTime(double timeOs, double timeRec, double timeSim); double equivalentApplicationTime(double timeOs, double timeRec, double timeSim); - + bool handleRecordingFile(std::string filenameIn); bool playbackCamera(); bool playbackTimeChange(); bool playbackScript(); diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 4a545275b7..a39e059351 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -77,18 +77,41 @@ void SessionRecording::setRecordDataFormat(SessionRecordingDataMode dataMode) { _recordingDataMode = dataMode; } -bool SessionRecording::startRecording(const std::string& filename) { - if (filename.find("/") != std::string::npos) { +bool SessionRecording::hasFileExtension(std::string filename, std::string extension) { + if (filename.length() <= extension.length()) { + return false; + } + else { + return (filename.substr(filename.length() - extension.length()) == extension); + } +} + +bool SessionRecording::handleRecordingFile(std::string filenameIn) { + if (filenameIn.find("/") != std::string::npos) { LERROR("Recording filename must not contain path (/) elements"); return false; } - if (!FileSys.directoryExists(absPath("${RECORDINGS}"))) { - FileSys.createDirectory( - absPath("${RECORDINGS}"), - ghoul::filesystem::FileSystem::Recursive::Yes - ); + + if (_recordingDataMode == SessionRecordingDataMode::Binary) { + if (hasFileExtension(filenameIn, SessionRecordingFileExtensionAscii)) { + LERROR("Specified filename for binary recording has ascii file extension"); + return false; + } + else if (!hasFileExtension(filenameIn, SessionRecordingFileExtensionBinary)) { + filenameIn += SessionRecordingFileExtensionBinary; + } } - const std::string absFilename = absPath("${RECORDINGS}/" + filename); + else if (_recordingDataMode == SessionRecordingDataMode::Ascii) { + if (hasFileExtension(filenameIn, SessionRecordingFileExtensionBinary)) { + LERROR("Specified filename for ascii recording has binary file extension"); + return false; + } + else if (!hasFileExtension(filenameIn, SessionRecordingFileExtensionAscii)) { + filenameIn += SessionRecordingFileExtensionAscii; + } + } + + std::string absFilename = absPath("${RECORDINGS}/" + filenameIn); if (FileSys.fileExists(absFilename)) { LERROR(fmt::format( @@ -96,19 +119,6 @@ bool SessionRecording::startRecording(const std::string& filename) { )); return false; } - if (_state == SessionState::Recording) { - LERROR("Unable to start recording while already in recording mode"); - return false; - } - else if (_state == SessionState::Playback) { - LERROR("Unable to start recording while in session playback mode"); - return false; - } - - _state = SessionState::Recording; - _playbackActive_camera = false; - _playbackActive_time = false; - _playbackActive_script = false; if (_recordingDataMode == SessionRecordingDataMode::Binary) { _recordFile.open(absFilename, std::ios::binary); } @@ -122,29 +132,57 @@ bool SessionRecording::startRecording(const std::string& filename) { )); return false; } - _recordFile << SessionRecordingFileHeaderTitle; - _recordFile.write(FileHeaderVersion, FileHeaderVersionLength); - if (_recordingDataMode == SessionRecordingDataMode::Binary) { - _recordFile << DataFormatBinaryTag; - } - else { - _recordFile << DataFormatAsciiTag; - } - _recordFile << '\n'; - - _timestampRecordStarted = global::windowDelegate.applicationTime(); - - //Record the current delta time so this is preserved in recording - double currentDeltaTime = global::timeManager.deltaTime(); - std::string scriptCommandForInitializingDeltaTime = - "openspace.time.setDeltaTime(" + std::to_string(currentDeltaTime) + ")"; - saveScriptKeyframe(scriptCommandForInitializingDeltaTime); - - LINFO("Session recording started"); - return true; } +bool SessionRecording::startRecording(const std::string& filename) { + if (_state == SessionState::Recording) { + LERROR("Unable to start recording while already in recording mode"); + return false; + } + else if (_state == SessionState::Playback) { + LERROR("Unable to start recording while in session playback mode"); + return false; + } + if (!FileSys.directoryExists(absPath("${RECORDINGS}"))) { + FileSys.createDirectory( + absPath("${RECORDINGS}"), + ghoul::filesystem::FileSystem::Recursive::Yes + ); + } + + bool recordingFileOK = handleRecordingFile(filename); + + if (recordingFileOK) { + _state = SessionState::Recording; + _playbackActive_camera = false; + _playbackActive_time = false; + _playbackActive_script = false; + + _recordFile << SessionRecordingFileHeaderTitle; + _recordFile.write(FileHeaderVersion, FileHeaderVersionLength); + if (_recordingDataMode == SessionRecordingDataMode::Binary) { + _recordFile << DataFormatBinaryTag; + } + else { + _recordFile << DataFormatAsciiTag; + } + _recordFile << '\n'; + + _timestampRecordStarted = global::windowDelegate.applicationTime(); + + //Record the current delta time so this is preserved in recording + double currentDeltaTime = global::timeManager.deltaTime(); + std::string scriptCommandForInitializingDeltaTime = + "openspace.time.setDeltaTime(" + std::to_string(currentDeltaTime) + ")"; + saveScriptKeyframe(scriptCommandForInitializingDeltaTime); + + LINFO("Session recording started"); + } + + return recordingFileOK; +} + void SessionRecording::stopRecording() { if (_state == SessionState::Recording) { _state = SessionState::Idle; diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index 6cbe5257db..de938626ec 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -83,6 +83,38 @@ void ConvertRecFormatTask::perform(const Task::ProgressCallback& progressCallbac } void ConvertRecFormatTask::convert() { + std::string expectedFileExtension_in, expectedFileExtension_out; + std::string currentFormat; + if (_fileFormatType == SessionRecordingDataMode::Binary) { + currentFormat = "binary"; + expectedFileExtension_in = SessionRecordingFileExtensionBinary; + expectedFileExtension_out = SessionRecordingFileExtensionAscii; + } + else if (_fileFormatType == SessionRecordingDataMode::Ascii) { + currentFormat = "ascii"; + expectedFileExtension_in = SessionRecordingFileExtensionAscii; + expectedFileExtension_out = SessionRecordingFileExtensionBinary; + } + + if (!SessionRecording::hasFileExtension(_inFilePath, expectedFileExtension_in)) { + LWARNING(fmt::format( + "Input filename doesn't have expected {} " + "format file extension", + currentFormat) + ); + } + if (SessionRecording::hasFileExtension(_outFilePath, expectedFileExtension_in)) { + LERROR(fmt::format( + "Output filename has {} file extension, but is conversion from {}", + currentFormat, + currentFormat) + ); + return; + } + else if (!SessionRecording::hasFileExtension(_outFilePath, expectedFileExtension_out)) { + _outFilePath += expectedFileExtension_out; + } + if (_fileFormatType == SessionRecordingDataMode::Ascii) { _oFile.open(_outFilePath); } From 3ee1a112571b14772dd0b86b795dad0ff7278f13 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Thu, 16 Jul 2020 09:49:21 -0600 Subject: [PATCH 073/123] Added support for comment line in ascii session recording file --- include/openspace/interaction/sessionrecording.h | 1 + src/interaction/sessionrecording.cpp | 3 +++ src/interaction/tasks/convertrecformattask.cpp | 3 +++ 3 files changed, 7 insertions(+) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 23635a7780..2a23252cd6 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -41,6 +41,7 @@ static const std::string SessionRecordingFileHeaderTitle = "OpenSpace_record/pla static const std::string SessionRecordingHeaderCameraAscii = "camera"; static const std::string SessionRecordingHeaderTimeAscii = "time"; static const std::string SessionRecordingHeaderScriptAscii = "script"; +static const std::string SessionRecordingHeaderCommentAscii = "#"; static const std::string SessionRecordingFileExtensionBinary = ".osrec"; static const std::string SessionRecordingFileExtensionAscii = ".osrectxt"; static const char SessionRecordingHeaderCameraBinary = 'c'; diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index a39e059351..9d31e5ba43 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -738,6 +738,9 @@ bool SessionRecording::playbackAddEntriesToTimeline() { else if (entryType == SessionRecordingHeaderScriptAscii) { parsingStatusOk = playbackScript(); } + else if (entryType.substr(0, 1) == SessionRecordingHeaderCommentAscii) { + continue; + } else { LERROR(fmt::format( "Unknown frame type {} @ line {} of playback file {}", diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index de938626ec..05ad083dae 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -268,6 +268,9 @@ void ConvertRecFormatTask::convertToBinary() { SessionRecording::saveScriptKeyframeBinary(times, skf, keyframeBuffer, _oFile); } + else if (entryType.substr(0, 1) == SessionRecordingHeaderCommentAscii) { + continue; + } else { LERROR(fmt::format( "Unknown frame type {} @ line {} of file {}", From 993be1b50420954cdd2603d9e1b0e92b555ed2cb Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 15:26:40 +0200 Subject: [PATCH 074/123] Make branch run with new master --- modules/exoplanets/discoverymethods/discoverymethods.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index bb59cbb367..87617e4083 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -289,7 +289,7 @@ namespace openspace::exoplanets{ } void DiscoveryMethods::addDopplerMethodVisualization() { - SceneGraphNode* focusNode = global::navigationHandler.focusNode(); + const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); std::string starName = global::moduleEngine.module()->getStarName(); // getStarName glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); @@ -380,7 +380,7 @@ namespace openspace::exoplanets{ void DiscoveryMethods::addTransitMethodVisualization() { - SceneGraphNode* focusNode = global::navigationHandler.focusNode(); + const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); std::string starName = global::moduleEngine.module()->getStarName(); // getStarName glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); From 9fac7fbd838a2bcd84ab43fbc3d26cbaac02777e Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 16:19:43 +0200 Subject: [PATCH 075/123] Untabify and start cleanup --- modules/exoplanets/CMakeLists.txt | 10 +- .../discoverymethods/discoverymethods.cpp | 124 +- .../discoverymethods/discoverymethods.h | 10 +- modules/exoplanets/exoplanetsmodule.cpp | 49 +- modules/exoplanets/exoplanetsmodule.h | 102 +- modules/exoplanets/exoplanetsmodule_lua.inl | 646 ++++----- .../rendering/renderableorbitdisc.cpp | 6 +- .../rendering/renderableorbitdisc.h | 1 - modules/exoplanets/shaders/orbitdisc_fs.glsl | 1 - modules/exoplanets/shaders/orbitdisc_vs.glsl | 1 - .../tasks/exoplanetscsvtobintask.cpp | 1281 ++++++++--------- .../exoplanets/tasks/exoplanetscsvtobintask.h | 82 +- 12 files changed, 1132 insertions(+), 1181 deletions(-) diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 0bd3798bbf..8fb5dc0ae9 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -27,22 +27,22 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h - ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h + ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) set(SHADER_FILES - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/orbitdisc_fs.glsl - ${CMAKE_CURRENT_SOURCE_DIR}/shaders/orbitdisc_vs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/orbitdisc_fs.glsl + ${CMAKE_CURRENT_SOURCE_DIR}/shaders/orbitdisc_vs.glsl ) source_group("Shader Files" FILES ${SHADER_FILES}) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 87617e4083..456606a204 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -41,31 +41,30 @@ namespace { - constexpr const char* _loggerCat = "DiscoveryMethods"; + constexpr const char* _loggerCat = "DiscoveryMethods"; - static const openspace::properties::Property::PropertyInfo TransitMethodInfo = { - "TransitMethod", - "Show transit method", - "Change the view so that the transit method can be presented." - }; - - static const openspace::properties::Property::PropertyInfo DopplerMethodInfo = { - "DopplerMethod", - "Show doppler method", - "Change the view so that the doppler method can be presented." - }; + static const openspace::properties::Property::PropertyInfo TransitMethodInfo = { + "TransitMethod", + "Show transit method", + "Change the view so that the transit method can be presented." + }; + + static const openspace::properties::Property::PropertyInfo DopplerMethodInfo = { + "DopplerMethod", + "Show doppler method", + "Change the view so that the doppler method can be presented." + }; static const openspace::properties::Property::PropertyInfo SolarSystemReferenceInfo = { - "SolarSystemReference", - "Show solar system reference", - "Show the size of the solar system as a reference for size." - }; + "SolarSystemReference", + "Show solar system reference", + "Show the size of the solar system as a reference for size." + }; } // namespace -namespace openspace::exoplanets{ +namespace openspace::exoplanets { void DiscoveryMethods::addDirectionsMarkers(glm::dvec3 viewDirecionPos, glm::dvec3 northDirectionPos, float starRadius) { - const std::string markerView = "{" "Identifier = 'markerView'," "Parent = 'SolarSystemBarycenter'," @@ -147,22 +146,21 @@ namespace openspace::exoplanets{ } void addDopplerGraphs() { - std::string script = "openspace.addScreenSpaceRenderable(" - "{" + std::string script = + "openspace.addScreenSpaceRenderable(" + "{" "Identifier = 'DopplerShift2'," "Type = 'ScreenSpaceImageLocal'," "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/stripes2.png')," "EuclideanPosition = {0.0, -0.7}" - "}" - ");" + "});" "openspace.addScreenSpaceRenderable(" - "{" + "{" "Identifier = 'DopplerShift1'," "Type = 'ScreenSpaceImageLocal'," "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/spectrum.jpg')," "EuclideanPosition = {0.0, -0.7}" - "}" - ");"; + "});"; openspace::global::scriptEngine.queueScript( script, @@ -171,7 +169,8 @@ namespace openspace::exoplanets{ } void addTransitGraphs() { - std::string script = "openspace.addScreenSpaceRenderable(" + std::string script = + "openspace.addScreenSpaceRenderable(" "{" "Identifier = 'Transit2'," "Type = 'ScreenSpaceImageLocal'," @@ -201,8 +200,6 @@ namespace openspace::exoplanets{ ); } - - void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em openspace::global::scriptEngine.queueScript( @@ -226,7 +223,6 @@ namespace openspace::exoplanets{ { //keeping first planet in the list, wich dosn't neccesarily mean the closest one... for (size_t i = 1; i < planetNames.size(); i++) { - std::string script = ""; //remove planetglobe if (!isnan(planets[i].R)) { @@ -256,7 +252,6 @@ namespace openspace::exoplanets{ } void DiscoveryMethods::moveCamera(glm::dvec3 pos) { - Camera* cam = global::navigationHandler.camera(); cam->setPositionVec3(pos); global::navigationHandler.resetCameraDirection(); @@ -299,8 +294,7 @@ namespace openspace::exoplanets{ float semiMajorAxis = planets[0].A; // in AU float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis float eccentricity = planets[0].ECC; - if (isnan(planets[0].ECC)) - { + if (isnan(planets[0].ECC)) { eccentricity = 0.0; } float starRadius = planets[0].RSTAR; // in Solar Radii @@ -344,7 +338,6 @@ namespace openspace::exoplanets{ glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); // END MARKERS - } void DiscoveryMethods::removeDopplerMethodVisualization() { @@ -379,7 +372,6 @@ namespace openspace::exoplanets{ } void DiscoveryMethods::addTransitMethodVisualization() { - const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); std::string starName = global::moduleEngine.module()->getStarName(); // getStarName glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) @@ -389,8 +381,7 @@ namespace openspace::exoplanets{ float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) float eccentricity = planets[0].ECC; - if (isnan(planets[0].ECC)) - { + if (isnan(planets[0].ECC)) { eccentricity = 0.0; } float starRadius = planets[0].RSTAR; // in Solar Radii @@ -402,7 +393,6 @@ namespace openspace::exoplanets{ glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * starToSunVec); //glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * faceOnVector); - moveCamera(cameraPosition); // END CAMERA toggleVisabilityPlanet(planetNames[0], "true"); @@ -430,6 +420,7 @@ namespace openspace::exoplanets{ //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); // END MARKERS } + void DiscoveryMethods::removeTransitMethodVisualization() { std::vector planetNames = global::moduleEngine.module()->getPlna(); //SCALE STAR AND PLANET @@ -438,7 +429,10 @@ namespace openspace::exoplanets{ scaleNode(planetNames[0], 1); // REMOVE GRAPH - std::string script = "openspace.removeScreenSpaceRenderable('Transit3');openspace.removeScreenSpaceRenderable('Transit2');openspace.removeScreenSpaceRenderable('Transit1');"; + std::string script = "openspace.removeScreenSpaceRenderable('Transit3');" + "openspace.removeScreenSpaceRenderable('Transit2');" + "openspace.removeScreenSpaceRenderable('Transit1');"; + openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -448,24 +442,22 @@ namespace openspace::exoplanets{ //removeDirectionsMarkers(); } - void DiscoveryMethods::addSolarSystemReferenceVisualization() { - std::string starName = global::moduleEngine.module()->getStarName(); std::vector planets = global::moduleEngine.module()->getPlsy(); std::vector planetNames = global::moduleEngine.module()->getPlna(); // SUN const std::string sunRef = "{" - "Identifier = 'SunReference'," - "Parent = '" + starName + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," - "BlendMode = 'Additive'" - "}," + "Identifier = 'SunReference'," + "Parent = '" + starName + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," + "BlendMode = 'Additive'" + "}," "Transform = {" "Translation = {" "Type = 'StaticTranslation'," @@ -507,9 +499,9 @@ namespace openspace::exoplanets{ openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - glm::dmat3 rotation = global::moduleEngine.module()->getRotation(); + // ORBIT const std::string orbitRef = "{" "Identifier = 'OrbitReference'," @@ -546,46 +538,40 @@ namespace openspace::exoplanets{ ); } - DiscoveryMethods::DiscoveryMethods() - : PropertyOwner({ "DiscoveryMethods" }) - , _showTransit(TransitMethodInfo, false) - , _showDoppler(DopplerMethodInfo, false) - , _showSolarSystemReference(SolarSystemReferenceInfo, false) - { + DiscoveryMethods::DiscoveryMethods() + : PropertyOwner({ "DiscoveryMethods" }) + , _showTransit(TransitMethodInfo, false) + , _showDoppler(DopplerMethodInfo, false) + , _showSolarSystemReference(SolarSystemReferenceInfo, false) + { _showTransit.onChange([&]() { if (_showTransit) //just changed to true { - if (_showDoppler) //only one viz at the time - { + if (_showDoppler) { //only one viz at the time _showDoppler = false; removeDopplerMethodVisualization(); } - addTransitMethodVisualization(); } - else //just changed to false - { + else { //just changed to false removeTransitMethodVisualization(); } }); addProperty(_showTransit); + _showDoppler.onChange([&]() { if (_showDoppler) //just changed to true { - if (_showTransit) - { - + if (_showTransit) { _showTransit = false; removeTransitMethodVisualization(); } addDopplerMethodVisualization(); } - else //just changed to false - { + else { //just changed to false removeDopplerMethodVisualization(); } - }); addProperty(_showDoppler); @@ -598,7 +584,5 @@ namespace openspace::exoplanets{ } }); addProperty(_showSolarSystemReference); - } - + } } // namespce - diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h index 38d9826546..958d471188 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ b/modules/exoplanets/discoverymethods/discoverymethods.h @@ -28,12 +28,11 @@ #include #include - namespace openspace::exoplanets { class DiscoveryMethods : public properties::PropertyOwner { public: - DiscoveryMethods(); + DiscoveryMethods(); bool isDoppler(); bool isTransit(); bool isReference(); @@ -42,9 +41,9 @@ public: float getTransitScaleFactor(); private: - properties::BoolProperty _showTransit; - properties::BoolProperty _showDoppler; - properties::BoolProperty _showSolarSystemReference; + properties::BoolProperty _showTransit; + properties::BoolProperty _showDoppler; + properties::BoolProperty _showSolarSystemReference; void addSolarSystemReferenceVisualization(); void removeSolarSystemReferenceVisualization(); @@ -62,7 +61,6 @@ private: void toggleVisabilityPlanet(std::string, std::string); float _transitScaleFactor; - }; } // namespace diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 62d03d4373..a9de21163e 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -90,7 +90,6 @@ glm::dvec3 ExoplanetsModule::getNorthVector() { } scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { - scripting::LuaLibrary res; res.name = "exoplanets"; res.functions = { @@ -108,14 +107,12 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { "string", "Removes the nodes from the scene graph of the exoplanet system." } - }; return res; } void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { - auto fTask = FactoryManager::ref().factory(); auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fTask, "No task factory existed"); @@ -129,9 +126,7 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { // Render global::callback::render.push_back([&]() { - - if (_discoveryMethods->isDoppler()) - { + if (_discoveryMethods->isDoppler()) { std::string starName = global::moduleEngine.module()->getStarName(); std::vector planetNames = global::moduleEngine.module()->getPlna(); SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); @@ -141,34 +136,31 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { glm::dvec3 starToPosVec = normalize(planetPos - starPos); glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPos); glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); - glm::dvec3 northProjected = glm::normalize(glm::length(north)*glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec))); + glm::dvec3 northProjected = glm::normalize( + glm::length(north) * glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec)) + ); float northAngle = glm::acos(glm::dot(starToPosVec, northProjected)) * 57.2957795; float viewAngle = glm::acos(glm::dot(starToPosVec, starToSunVec)) * 57.2957795; float imagePos = 0; - if ( viewAngle <= 90.0 && northAngle <= 90.0) - { + if ( viewAngle <= 90.0 && northAngle <= 90.0) { imagePos = viewAngle / -90.0; } - else if (viewAngle > 90.0 && northAngle <= 90.0) - { + else if (viewAngle > 90.0 && northAngle <= 90.0) { imagePos = (180.0 - viewAngle) / -90.0; } - else if (viewAngle > 90.0 && northAngle > 90.0) - { + else if (viewAngle > 90.0 && northAngle > 90.0) { imagePos = (180.0 - viewAngle) / 90.0; } - else if (viewAngle <= 90.0 && northAngle > 90.0) - { + else if (viewAngle <= 90.0 && northAngle > 90.0) { imagePos = viewAngle / 90.0; } imagePos *= 0.01; _discoveryMethods->setDopplerImagePos(imagePos); - } - if (_discoveryMethods->isTransit()) { + if (_discoveryMethods->isTransit()) { std::string starName = global::moduleEngine.module()->getStarName(); std::vector planetNames = global::moduleEngine.module()->getPlna(); SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); @@ -189,32 +181,27 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { glm::dvec3 posVecProjected = starToPosVec - (((dot(starToPosVec, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec); float l = glm::length(posVecProjected); //in m float imageYPos = -0.60; + if (l<(starRadius*0.82) && viewAngle <= 90.0) { imageYPos = -0.80; } float imageXPos = 0; - if (viewAngle <= 90.0 && northAngle <= 90.0) - { - imageXPos = (viewAngle / 90.0) * 0.5; + if (viewAngle <= 90.0 && northAngle <= 90.0) { + imageXPos = (viewAngle / 90.0) * 0.5; } - else if (viewAngle > 90.0 && northAngle <= 90.0) - { - imageXPos = (viewAngle / 90.0) * 0.5; + else if (viewAngle > 90.0 && northAngle <= 90.0) { + imageXPos = (viewAngle / 90.0) * 0.5; } - else if (viewAngle > 90.0 && northAngle > 90.0) - { - imageXPos = (viewAngle / 90.0) * -0.5; + else if (viewAngle > 90.0 && northAngle > 90.0) { + imageXPos = (viewAngle / 90.0) * -0.5; } - else if (viewAngle <= 90.0 && northAngle > 90.0) - { - imageXPos = (viewAngle / 90.0) * -0.5; + else if (viewAngle <= 90.0 && northAngle > 90.0) { + imageXPos = (viewAngle / 90.0) * -0.5; } imageXPos *= 0.5; _discoveryMethods->setTransitImagePos(imageXPos, imageYPos); - } - }); } diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index 7a795e180b..e983502628 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -33,50 +33,50 @@ #include namespace openspace { - struct Exoplanet { - float A; - double AUPPER; - double ALOWER; - double UA; - float BIGOM; - float BIGOMUPPER; - float BIGOMLOWER; - float UBIGOM; - bool BINARY; - float BMV; - float ECC; - float ECCUPPER; - float ECCLOWER; - float UECC; - float I; - float IUPPER; - float ILOWER; - float UI; - int NCOMP; - float OM; - float OMUPPER; - float OMLOWER; - float UOM; - double PER; - float PERUPPER; - float PERLOWER; - float UPER; - double R; - double RUPPER; - double RLOWER; - double UR; - float RSTAR; - float RSTARUPPER; - float RSTARLOWER; - float URSTAR; - double TT; - float TTUPPER; - float TTLOWER; - float UTT; - float POSITIONX; - float POSITIONY; - float POSITIONZ; - }; + struct Exoplanet { + float A; + double AUPPER; + double ALOWER; + double UA; + float BIGOM; + float BIGOMUPPER; + float BIGOMLOWER; + float UBIGOM; + bool BINARY; + float BMV; + float ECC; + float ECCUPPER; + float ECCLOWER; + float UECC; + float I; + float IUPPER; + float ILOWER; + float UI; + int NCOMP; + float OM; + float OMUPPER; + float OMLOWER; + float UOM; + double PER; + float PERUPPER; + float PERLOWER; + float UPER; + double R; + double RUPPER; + double RLOWER; + double UR; + float RSTAR; + float RSTARUPPER; + float RSTARLOWER; + float URSTAR; + double TT; + float TTUPPER; + float TTLOWER; + float UTT; + float POSITIONX; + float POSITIONY; + float POSITIONZ; + }; class ExoplanetsModule : public OpenSpaceModule { public: @@ -89,25 +89,25 @@ public: std::vector documentations() const override; - void setClosestExoplanet(Exoplanet); - Exoplanet getClosestExoplanet(); - void setStarName(std::string); - std::string getStarName(); + void setClosestExoplanet(Exoplanet); + Exoplanet getClosestExoplanet(); + void setStarName(std::string); + std::string getStarName(); void setPlsy(std::vector); std::vector getPlsy(); void setPlna(std::vector); std::vector getPlna(); void setRotation(glm::dmat3); glm::dmat3 getRotation(); - void setNorthVector(glm::dvec3); + void setNorthVector(glm::dvec3); glm::dvec3 getNorthVector(); protected: void internalInitialize(const ghoul::Dictionary&) override; std::unique_ptr _discoveryMethods; - Exoplanet _exo; - std::string _starName; + Exoplanet _exo; + std::string _starName; std::vector _plsy; std::vector _plna; glm::dmat3 _rotation; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index e2e81fb21e..fb456a8095 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -41,31 +41,31 @@ namespace openspace{ std::string getStarColor(float bv) { - std::string colorString; + std::string colorString; - std::ifstream colormap(absPath("${MODULE_EXOPLANETS}/colorbv.cmap"), std::ios::in); - if (!colormap.good()) { - std::cout << "Failed to open colormap data file"; - } + std::ifstream colormap(absPath("${MODULE_EXOPLANETS}/colorbv.cmap"), std::ios::in); + if (!colormap.good()) { + std::cout << "Failed to open colormap data file"; + } - int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); + int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); - std::string color; - for (size_t i = 0; i < t + 12; i++) - { - getline(colormap, color); - } + std::string color; + for (size_t i = 0; i < t + 12; i++) + { + getline(colormap, color); + } - std::istringstream colorstream(color); - std::string r, g, b; - getline(colorstream, r, ' '); - getline(colorstream, g, ' '); - getline(colorstream, b, ' '); - colorString = "{" + r + ", " + g + ", " + b + "}"; + std::istringstream colorstream(color); + std::string r, g, b; + getline(colorstream, r, ' '); + getline(colorstream, g, ' '); + getline(colorstream, b, ' '); + colorString = "{" + r + ", " + g + ", " + b + "}"; - colormap.close(); + colormap.close(); - return colorString; + return colorString; } glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm::dmat3 rot) { @@ -75,24 +75,24 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm: //const glm::dvec3 ascendingNodeAxisRot = glm::dvec3(0.f, 0.f, 1.f); const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); //const glm::dvec3 inclinationAxisRot = glm::dvec3(1.f, 0.f, 0.f ); - const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); - //const glm::vec3 argPeriapsisAxisRot = glm::dvec3( 0.f, 0.f, 1.f ); + const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); + //const glm::vec3 argPeriapsisAxisRot = glm::dvec3( 0.f, 0.f, 1.f ); /*const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f };*/ - const double asc = glm::radians(bigom); - const double inc = glm::radians(i); - const double per = glm::radians(om); + const double asc = glm::radians(bigom); + const double inc = glm::radians(i); + const double per = glm::radians(om); - glm::dmat4 orbitPlaneRotation = + glm::dmat4 orbitPlaneRotation = glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * - glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * - glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); + glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * + glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); - return orbitPlaneRotation; - //return std::to_string(orbitPlaneRotation); + return orbitPlaneRotation; + //return std::to_string(orbitPlaneRotation); } std::string getSpeckStarname(std::string csvName) { @@ -190,97 +190,97 @@ std::string getSpeckStarname(std::string csvName) { } std::string getCsvStarname(std::string explName) { - std::string csvName = explName; - if (explName == "GJ 3021") - csvName = "HD 1237"; - else if (explName == "MOA 2009-BLG-387L") - csvName = "MOA-2009-BLG-387L"; - else if (explName == "HD 126614") - csvName = "HD 126614 A"; - else if (explName == "HD 27442") - csvName = "epsilon Ret"; - else if (explName == "PH1") - csvName = "PH-1"; - else if (explName == "gam 1 Leo") - csvName = "gamma Leo A"; - else if (explName == "OGLE 2007-BLG-368L") - csvName = "OGLE-2007-BLG-368L"; - else if (explName == "alf Ari") - csvName = "alpha Ari"; - else if (explName == "HD 160691") - csvName = "mu Ara"; - else if (explName == "OGLE 2005-BLG-169L") - csvName = "OGLE-05-169L"; - else if (explName == "HD 216435") - csvName = "tau Gru"; - else if (explName == "HR 810") - csvName = "iota Hor"; - else if (explName == "OGLE 2005-BLG-71L") - csvName = "OGLE-05-071L"; - else if (explName == "OGLE 2003-BLG-235L") - csvName = "OGLE235-MOA53"; - else if (explName == "MOA 2008-BLG-310L") - csvName = "MOA-2008-BLG-310L"; - else if (explName == "KOI-351") - csvName = "KIC 11442793"; - else if (explName == "OGLE 2006-BLG-109L") - csvName = "OGLE-2006-BLG-109L"; - else if (explName == "HD 137388 A") - csvName = "HD 137388"; - else if (explName == "kap CrB") - csvName = "kappa CrB"; - else if (explName == "XO-2 N") - csvName = "XO-2"; - else if (explName == "eps Tau") - csvName = "epsilon Tau"; - else if (explName == "eps Eri") - csvName = "epsilon Eri"; - else if (explName == "KOI-12") - csvName = "Kepler-448"; - else if (explName == "ome Ser") - csvName = "omega Ser"; - else if (explName == "MOA 2010-BLG-477L") - csvName = "MOA-2010-BLG-477L"; - else if (explName == "HD 285968") - csvName = "GJ 176"; - else if (explName == "BD-17 63") - csvName = "HIP 2247"; - else if (explName == "MOA 2009-BLG-266L") - csvName = "MOA-2009-BLG-266L"; - else if (explName == "KOI-94") - csvName = "Kepler-89"; - else if (explName == "HIP 75458") - csvName = "iota Dra"; - else if (explName == "MOA 2007-BLG-400L") - csvName = "MOA-2007-BLG-400L"; - else if (explName == "ups And") - csvName = "upsilon And"; - else if (explName == "OGLE 2011-BLG-251L") - csvName = "OGLE-2011-BLG-0251"; - else if (explName == "OGLE 2005-BLG-390L") - csvName = "OGLE-05-390L"; - else if (explName == "KOI-1257") - csvName = "Kepler-420"; - else if (explName == "bet Pic") - csvName = "beta Pic"; - else if (explName == "gam Cep") - csvName = "gamma Cep"; - else if (explName == "MOA 2007-BLG-192L") - csvName = "MOA-2007-BLG-192L"; - else if (explName == "MOA 2009-BLG-319L") - csvName = "MOA-2009-BLG-319L"; - else if (explName == "omi CrB") - csvName = "omicron CrB"; - else if (explName == "HD 62509") - csvName = "beta Gem"; - else if (explName == "eps CrB") - csvName = "epsilon CrB"; - else if (explName == "omi UMa") - csvName = "omicron UMa"; - else if (explName == "HD 142022 A") - csvName = "HD 142022"; + std::string csvName = explName; + if (explName == "GJ 3021") + csvName = "HD 1237"; + else if (explName == "MOA 2009-BLG-387L") + csvName = "MOA-2009-BLG-387L"; + else if (explName == "HD 126614") + csvName = "HD 126614 A"; + else if (explName == "HD 27442") + csvName = "epsilon Ret"; + else if (explName == "PH1") + csvName = "PH-1"; + else if (explName == "gam 1 Leo") + csvName = "gamma Leo A"; + else if (explName == "OGLE 2007-BLG-368L") + csvName = "OGLE-2007-BLG-368L"; + else if (explName == "alf Ari") + csvName = "alpha Ari"; + else if (explName == "HD 160691") + csvName = "mu Ara"; + else if (explName == "OGLE 2005-BLG-169L") + csvName = "OGLE-05-169L"; + else if (explName == "HD 216435") + csvName = "tau Gru"; + else if (explName == "HR 810") + csvName = "iota Hor"; + else if (explName == "OGLE 2005-BLG-71L") + csvName = "OGLE-05-071L"; + else if (explName == "OGLE 2003-BLG-235L") + csvName = "OGLE235-MOA53"; + else if (explName == "MOA 2008-BLG-310L") + csvName = "MOA-2008-BLG-310L"; + else if (explName == "KOI-351") + csvName = "KIC 11442793"; + else if (explName == "OGLE 2006-BLG-109L") + csvName = "OGLE-2006-BLG-109L"; + else if (explName == "HD 137388 A") + csvName = "HD 137388"; + else if (explName == "kap CrB") + csvName = "kappa CrB"; + else if (explName == "XO-2 N") + csvName = "XO-2"; + else if (explName == "eps Tau") + csvName = "epsilon Tau"; + else if (explName == "eps Eri") + csvName = "epsilon Eri"; + else if (explName == "KOI-12") + csvName = "Kepler-448"; + else if (explName == "ome Ser") + csvName = "omega Ser"; + else if (explName == "MOA 2010-BLG-477L") + csvName = "MOA-2010-BLG-477L"; + else if (explName == "HD 285968") + csvName = "GJ 176"; + else if (explName == "BD-17 63") + csvName = "HIP 2247"; + else if (explName == "MOA 2009-BLG-266L") + csvName = "MOA-2009-BLG-266L"; + else if (explName == "KOI-94") + csvName = "Kepler-89"; + else if (explName == "HIP 75458") + csvName = "iota Dra"; + else if (explName == "MOA 2007-BLG-400L") + csvName = "MOA-2007-BLG-400L"; + else if (explName == "ups And") + csvName = "upsilon And"; + else if (explName == "OGLE 2011-BLG-251L") + csvName = "OGLE-2011-BLG-0251"; + else if (explName == "OGLE 2005-BLG-390L") + csvName = "OGLE-05-390L"; + else if (explName == "KOI-1257") + csvName = "Kepler-420"; + else if (explName == "bet Pic") + csvName = "beta Pic"; + else if (explName == "gam Cep") + csvName = "gamma Cep"; + else if (explName == "MOA 2007-BLG-192L") + csvName = "MOA-2007-BLG-192L"; + else if (explName == "MOA 2009-BLG-319L") + csvName = "MOA-2009-BLG-319L"; + else if (explName == "omi CrB") + csvName = "omicron CrB"; + else if (explName == "HD 62509") + csvName = "beta Gem"; + else if (explName == "eps CrB") + csvName = "epsilon CrB"; + else if (explName == "omi UMa") + csvName = "omicron UMa"; + else if (explName == "HD 142022 A") + csvName = "HD 142022"; - return csvName; + return csvName; } // Rotate the original coordinate system (where x is pointing to First Point of Aries) @@ -325,8 +325,8 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { int addExoplanetSystem(lua_State* L) { - const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); + const int StringLocation = -1; + const std::string starname = luaL_checkstring(L, StringLocation); //change expl-starname to exoplanet.csv-starname std::string starname_csv = getCsvStarname(starname); @@ -336,58 +336,58 @@ int addExoplanetSystem(lua_State* L) { global::moduleEngine.module()->setStarName(starname_speck); - std::ifstream data(absPath("${MODULE_EXOPLANETS}/expl_data.bin"), std::ios::in | std::ios::binary); - if (!data.good()) { - std::cout << "Failed to open exoplanets data file"; - } + std::ifstream data(absPath("${MODULE_EXOPLANETS}/expl_data.bin"), std::ios::in | std::ios::binary); + if (!data.good()) { + std::cout << "Failed to open exoplanets data file"; + } - std::ifstream lut(absPath("${MODULE_EXOPLANETS}/lookup.txt")); - if (!lut.good()) { - std::cout << "Failed to open exoplanets look-up table file"; - } + std::ifstream lut(absPath("${MODULE_EXOPLANETS}/lookup.txt")); + if (!lut.good()) { + std::cout << "Failed to open exoplanets look-up table file"; + } - //1. search lut for the starname and return the corresponding location - //2. go to that location in the data file - //3. read sizeof(exoplanet) bytes into an exoplanet object. - std::string planetname; - size_t len = 0; - Exoplanet p; - std::string line; - bool found = false; + //1. search lut for the starname and return the corresponding location + //2. go to that location in the data file + //3. read sizeof(exoplanet) bytes into an exoplanet object. + std::string planetname; + size_t len = 0; + Exoplanet p; + std::string line; + bool found = false; - std::vector plsy; - std::vector plna; - while (getline(lut, line)) { + std::vector plsy; + std::vector plna; + while (getline(lut, line)) { - std::istringstream ss(line); - getline(ss, planetname, ','); + std::istringstream ss(line); + getline(ss, planetname, ','); - if (planetname.compare(0, planetname.length() - 2, starname_speck) == 0) { - std::string location_s; - getline(ss, location_s); - long location = std::stol(location_s.c_str()); + if (planetname.compare(0, planetname.length() - 2, starname_speck) == 0) { + std::string location_s; + getline(ss, location_s); + long location = std::stol(location_s.c_str()); - data.seekg(location); - data.read((char*)&p, sizeof(struct Exoplanet)); + data.seekg(location); + data.read((char*)&p, sizeof(struct Exoplanet)); - plna.push_back(planetname); - plsy.push_back(p); - found = true; + plna.push_back(planetname); + plsy.push_back(p); + found = true; - } - } + } + } - data.close(); - lut.close(); + data.close(); + lut.close(); global::moduleEngine.module()->setPlna(plna); global::moduleEngine.module()->setPlsy(plsy); global::moduleEngine.module()->setClosestExoplanet(p); - if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY - { - Time epoch; - double parsec = 0.308567756E17; - std::string script = ""; + if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY + { + Time epoch; + double parsec = 0.308567756E17; + std::string script = ""; glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); @@ -415,29 +415,29 @@ int addExoplanetSystem(lua_State* L) { std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); - const std::string starParent = "{" - "Identifier = '" + starname_speck + "'," - "Parent = 'SolarSystemBarycenter'," - "Transform = {" + const std::string starParent = "{" + "Identifier = '" + starname_speck + "'," + "Parent = 'SolarSystemBarycenter'," + "Transform = {" "Rotation = {" "Type = 'StaticRotation'," "Rotation = " + ghoul::to_string(exoplanetSystemRot) + "," "}," - "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(position) + "," - "}," - "}" - "}"; + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + ghoul::to_string(position) + "," + "}," + "}" + "}"; - script = "openspace.addSceneGraphNode(" + starParent + ");"; + script = "openspace.addSceneGraphNode(" + starParent + ");"; openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - if (!isnan(p.RSTAR)) - { - std::string color = getStarColor(p.BMV); + if (!isnan(p.RSTAR)) + { + std::string color = getStarColor(p.BMV); if (isnan(plsy[0].ECC)) { @@ -463,37 +463,37 @@ int addExoplanetSystem(lua_State* L) { else sepoch_star = "2009-05-19T07:11:34.080"; - const std::string starGlobe = "{" - "Identifier = '" + starname_speck + "Globe'," - "Parent = '" + starname_speck + "'," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'StarColor'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" - "}," - "{" - "Identifier = 'StarTexture'," - "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," - "BlendMode = 'Color'," - "Enabled = true" - "}" - "}" - "}" - "}," - "Transform = {" - "Scale = {" - "Type = 'StaticScale'," - "Scale = 1.0," - "}," + const std::string starGlobe = "{" + "Identifier = '" + starname_speck + "Globe'," + "Parent = '" + starname_speck + "'," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'StarColor'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Identifier = 'StarTexture'," + "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," + "BlendMode = 'Color'," + "Enabled = true" + "}" + "}" + "}" + "}," + "Transform = {" + "Scale = {" + "Type = 'StaticScale'," + "Scale = 1.0," + "}," "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(plsy[0].ECC) + "," //ECC @@ -505,8 +505,8 @@ int addExoplanetSystem(lua_State* L) { "Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(plsy[0].PER) + "* 86400" //PER. 86 400sec = 1 day. "}" - "}" - "}"; + "}" + "}"; script = ""; script = " openspace.addSceneGraphNode(" + starGlobe + ");"; openspace::global::scriptEngine.queueScript( @@ -515,26 +515,26 @@ int addExoplanetSystem(lua_State* L) { ); //script = ""; - //const std::string starGlare = "{" - // "Identifier = '" + starname_speck + "Glare'," - // "Parent = '" + starname_speck + "'," - // "Renderable = {" - // "Type = 'RenderablePlaneImageLocal'," - // "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - // "Billboard = true," - // "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue.png'," - // "BlendMode = 'Additive'" - // "}" - // "}"; + //const std::string starGlare = "{" + // "Identifier = '" + starname_speck + "Glare'," + // "Parent = '" + starname_speck + "'," + // "Renderable = {" + // "Type = 'RenderablePlaneImageLocal'," + // "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + // "Billboard = true," + // "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue.png'," + // "BlendMode = 'Additive'" + // "}" + // "}"; // - //script = "openspace.addSceneGraphNode(" + starGlare + ");"; + //script = "openspace.addSceneGraphNode(" + starGlare + ");"; //global::scriptEngine.queueScript( // script, // scripting::ScriptEngine::RemoteScripting::Yes //); - } + } - + for (size_t i = 0; i < plsy.size(); i++) @@ -654,135 +654,135 @@ int addExoplanetSystem(lua_State* L) { "}," "Color = { 1, 1, 1 }" "}," - "}"; + "}"; - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + planetTrail + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + planetTrail + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); - if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) - { + if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) + { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); //glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); // , exoplanetSystemRot); glm::dmat3 rot = orbitPlaneRotationMatrix; global::moduleEngine.module()->setRotation(rot); - const std::string disc = "{" - "Identifier = '" + plna[i] + "Disc'," - "Parent = '" + starname_speck + "'," + const std::string disc = "{" + "Identifier = '" + plna[i] + "Disc'," + "Parent = '" + starname_speck + "'," "Enabled = true," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.5" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rot) + "," - "}" - "}," - "}"; - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + disc + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(plsy[i].ECC) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.5" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + ghoul::to_string(rot) + "," + "}" + "}," + "}"; + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + disc + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); - if (!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) - { - double lower_ecc = plsy[i].ECC - plsy[i].ECCLOWER; - if (lower_ecc < 0.0) - { - lower_ecc = 0.0; - } - const std::string discECCLOWER = "{" - "Identifier = '" + plna[i] + "discECCLOWER'," - "Parent = '" + starname_speck + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(lower_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," + if (!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) + { + double lower_ecc = plsy[i].ECC - plsy[i].ECCLOWER; + if (lower_ecc < 0.0) + { + lower_ecc = 0.0; + } + const std::string discECCLOWER = "{" + "Identifier = '" + plna[i] + "discECCLOWER'," + "Parent = '" + starname_speck + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(lower_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," "Rotation = " + ghoul::to_string(rot) + "," - "}" - "}," - "}"; + "}" + "}," + "}"; - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + discECCLOWER + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + discECCLOWER + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); - double upper_ecc = plsy[i].ECC + plsy[i].ECCUPPER; - if (upper_ecc > 1.0) - { - upper_ecc = 1.0; - } - const std::string discECCUPPER = "{" - "Identifier = '" + plna[i] + "discECCUPPER'," - "Parent = '" + starname_speck + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(upper_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," + double upper_ecc = plsy[i].ECC + plsy[i].ECCUPPER; + if (upper_ecc > 1.0) + { + upper_ecc = 1.0; + } + const std::string discECCUPPER = "{" + "Identifier = '" + plna[i] + "discECCUPPER'," + "Parent = '" + starname_speck + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," + "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(upper_ecc) + "," + "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend + "Transparency = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," "Rotation = " + ghoul::to_string(rot) + "," - "}" - "}," - "}"; + "}" + "}," + "}"; - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + discECCUPPER + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - } + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + discECCUPPER + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } - } + } - } - else - { - printf("No star with that name or not enough data about it."); - } + } + else + { + printf("No star with that name or not enough data about it."); + } - return 0; + return 0; } int removeExoplanetSystem(lua_State* L) { - const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); + const int StringLocation = -1; + const std::string starname = luaL_checkstring(L, StringLocation); std::string starname_speck = getSpeckStarname(starname); std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); - std::string script = "openspace.removeSceneGraphNode('" + starname_speck + "');"; - openspace::global::scriptEngine.queueScript( - script, - scripting::ScriptEngine::RemoteScripting::Yes - ); + std::string script = "openspace.removeSceneGraphNode('" + starname_speck + "');"; + openspace::global::scriptEngine.queueScript( + script, + scripting::ScriptEngine::RemoteScripting::Yes + ); - return 0; + return 0; } } //namespace diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index e962f3d92a..522ae3a6aa 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -219,9 +219,9 @@ void RenderableOrbitdisc::deinitializeGL() { void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { _shader->activate(); - glm::dmat4 modelTransform = - glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * - glm::dmat4(data.modelTransform.rotation) * + glm::dmat4 modelTransform = + glm::translate(glm::dmat4(1.0), data.modelTransform.translation) * + glm::dmat4(data.modelTransform.rotation) * glm::scale(glm::dmat4(1.0), glm::dvec3(data.modelTransform.scale)); glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform; diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index a1eb1bd7a9..ba046408d3 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -79,7 +79,6 @@ private: GLuint _quad; GLuint _vertexPositionBuffer; bool _planeIsDirty; - }; } // namespace openspace diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 2994e94aee..168409a696 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -44,7 +44,6 @@ uniform vec3 sunPosition; Fragment getFragment() { // Moving the origin to the center vec2 st = (vs_st - vec2(0.5)) * 2.0; - // The length of the texture coordinates vector is our distance from the center float outer; diff --git a/modules/exoplanets/shaders/orbitdisc_vs.glsl b/modules/exoplanets/shaders/orbitdisc_vs.glsl index 2f71337783..ce3a4eb0bd 100644 --- a/modules/exoplanets/shaders/orbitdisc_vs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_vs.glsl @@ -43,5 +43,4 @@ void main() { modelViewProjectionTransform * vec4(in_position.xy, 0.0, 1.0) ); gl_Position = vs_position; - } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index d23a553f1c..0984cd075f 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -26,13 +26,11 @@ #include #include - -#include #include -#include #include #include - +#include +#include #include namespace { @@ -47,7 +45,7 @@ namespace { namespace openspace { namespace exoplanets { -ExoplanetsCsvToBinTask::ExoplanetsCsvToBinTask(const ghoul::Dictionary& dictionary){ +ExoplanetsCsvToBinTask::ExoplanetsCsvToBinTask(const ghoul::Dictionary& dictionary) { openspace::documentation::testSpecificationAndThrow( documentation(), dictionary, @@ -65,174 +63,170 @@ std::string ExoplanetsCsvToBinTask::description() { " and write as bin to " + _outputBINPath; } -std::string ExoplanetsCsvToBinTask::getExplName(std::string csvName){ - std::string explName = csvName; - if (csvName == "HD 1237") - explName = "GJ 3021"; - else if (csvName == "MOA-2009-BLG-387L") - explName = "MOA 2009-BLG-387L"; - else if (csvName == "HD 126614 A") - explName = "HD 126614"; - else if (csvName == "epsilon Ret") - explName = "HD 27442"; - else if (csvName == "PH-1") - explName = "PH1"; - else if (csvName == "gamma Leo A") - explName = "gam 1 Leo"; - else if (csvName == "OGLE-2007-BLG-368L") - explName = "OGLE 2007-BLG-368L"; - else if (csvName == "alpha Ari") - explName = "alf Ari"; - else if (csvName == "mu Ara") - explName = "HD 160691"; - else if (csvName == "OGLE-05-169L") - explName = "OGLE 2005-BLG-169L"; - else if (csvName == "tau Gru") - explName = "HD 216435"; - else if (csvName == "iota Hor") - explName = "HR 810"; - else if (csvName == "OGLE-05-071L") - explName = "OGLE 2005-BLG-71L"; - else if (csvName == "OGLE235-MOA53") - explName = "OGLE 2003-BLG-235L"; - else if (csvName == "MOA-2008-BLG-310L") - explName = "MOA 2008-BLG-310L"; - else if (csvName == "KIC 11442793") - explName = "KOI-351"; - else if (csvName == "OGLE-2006-BLG-109L") - explName = "OGLE 2006-BLG-109L"; - else if (csvName == "HD 137388") - explName = "HD 137388 A"; - else if (csvName == "kappa CrB") - explName = "kap CrB"; - else if (csvName == "XO-2") - explName = "XO-2 N"; - else if (csvName == "epsilon Tau") - explName = "eps Tau"; - else if (csvName == "epsilon Eri") - explName = "eps Eri"; - else if (csvName == "Kepler-448") - explName = "KOI-12"; - else if (csvName == "omega Ser") - explName = "ome Ser"; - else if (csvName == "MOA-2010-BLG-477L") - explName = "MOA 2010-BLG-477L"; - else if (csvName == "GJ 176") - explName = "HD 285968"; - else if (csvName == "HIP 2247") - explName = "BD-17 63"; - else if (csvName == "MOA-2009-BLG-266L") - explName = "MOA 2009-BLG-266L"; - else if (csvName == "Kepler-89") - explName = "KOI-94"; - else if (csvName == "iota Dra") - explName = "HIP 75458"; - else if (csvName == "MOA-2007-BLG-400L") - explName = "MOA 2007-BLG-400L"; - else if (csvName == "upsilon And") - explName = "ups And"; - else if (csvName == "OGLE-2011-BLG-0251") - explName = "OGLE 2011-BLG-251L"; - else if (csvName == "OGLE-05-390L") - explName = "OGLE 2005-BLG-390L"; - else if (csvName == "Kepler-420") - explName = "KOI-1257"; - else if (csvName == "beta Pic") - explName = "bet Pic"; - else if (csvName == "gamma Cep") - explName = "gam Cep"; - else if (csvName == "MOA-2007-BLG-192L") - explName = "MOA 2007-BLG-192L"; - else if (csvName == "MOA-2009-BLG-319L") - explName = "MOA 2009-BLG-319L"; - else if (csvName == "omicron CrB") - explName = "omi CrB"; - else if (csvName == "beta Gem") - explName = "HD 62509"; - else if (csvName == "epsilon CrB") - explName = "eps CrB"; - else if (csvName == "omicron UMa") - explName = "omi UMa"; - else if (csvName == "HD 142022") - explName = "HD 142022 A"; +std::string ExoplanetsCsvToBinTask::getExplName(std::string csvName) { + std::string explName = csvName; + if (csvName == "HD 1237") + explName = "GJ 3021"; + else if (csvName == "MOA-2009-BLG-387L") + explName = "MOA 2009-BLG-387L"; + else if (csvName == "HD 126614 A") + explName = "HD 126614"; + else if (csvName == "epsilon Ret") + explName = "HD 27442"; + else if (csvName == "PH-1") + explName = "PH1"; + else if (csvName == "gamma Leo A") + explName = "gam 1 Leo"; + else if (csvName == "OGLE-2007-BLG-368L") + explName = "OGLE 2007-BLG-368L"; + else if (csvName == "alpha Ari") + explName = "alf Ari"; + else if (csvName == "mu Ara") + explName = "HD 160691"; + else if (csvName == "OGLE-05-169L") + explName = "OGLE 2005-BLG-169L"; + else if (csvName == "tau Gru") + explName = "HD 216435"; + else if (csvName == "iota Hor") + explName = "HR 810"; + else if (csvName == "OGLE-05-071L") + explName = "OGLE 2005-BLG-71L"; + else if (csvName == "OGLE235-MOA53") + explName = "OGLE 2003-BLG-235L"; + else if (csvName == "MOA-2008-BLG-310L") + explName = "MOA 2008-BLG-310L"; + else if (csvName == "KIC 11442793") + explName = "KOI-351"; + else if (csvName == "OGLE-2006-BLG-109L") + explName = "OGLE 2006-BLG-109L"; + else if (csvName == "HD 137388") + explName = "HD 137388 A"; + else if (csvName == "kappa CrB") + explName = "kap CrB"; + else if (csvName == "XO-2") + explName = "XO-2 N"; + else if (csvName == "epsilon Tau") + explName = "eps Tau"; + else if (csvName == "epsilon Eri") + explName = "eps Eri"; + else if (csvName == "Kepler-448") + explName = "KOI-12"; + else if (csvName == "omega Ser") + explName = "ome Ser"; + else if (csvName == "MOA-2010-BLG-477L") + explName = "MOA 2010-BLG-477L"; + else if (csvName == "GJ 176") + explName = "HD 285968"; + else if (csvName == "HIP 2247") + explName = "BD-17 63"; + else if (csvName == "MOA-2009-BLG-266L") + explName = "MOA 2009-BLG-266L"; + else if (csvName == "Kepler-89") + explName = "KOI-94"; + else if (csvName == "iota Dra") + explName = "HIP 75458"; + else if (csvName == "MOA-2007-BLG-400L") + explName = "MOA 2007-BLG-400L"; + else if (csvName == "upsilon And") + explName = "ups And"; + else if (csvName == "OGLE-2011-BLG-0251") + explName = "OGLE 2011-BLG-251L"; + else if (csvName == "OGLE-05-390L") + explName = "OGLE 2005-BLG-390L"; + else if (csvName == "Kepler-420") + explName = "KOI-1257"; + else if (csvName == "beta Pic") + explName = "bet Pic"; + else if (csvName == "gamma Cep") + explName = "gam Cep"; + else if (csvName == "MOA-2007-BLG-192L") + explName = "MOA 2007-BLG-192L"; + else if (csvName == "MOA-2009-BLG-319L") + explName = "MOA 2009-BLG-319L"; + else if (csvName == "omicron CrB") + explName = "omi CrB"; + else if (csvName == "beta Gem") + explName = "HD 62509"; + else if (csvName == "epsilon CrB") + explName = "eps CrB"; + else if (csvName == "omicron UMa") + explName = "omi UMa"; + else if (csvName == "HD 142022") + explName = "HD 142022 A"; - return explName; + return explName; } glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { glm::vec3 pos; - pos[0] = NAN; - pos[1] = NAN; - pos[2] = NAN; - std::ifstream expl_file(_inputSPECKPath); - if (!expl_file) { + pos[0] = NAN; + pos[1] = NAN; + pos[2] = NAN; + std::ifstream expl_file(_inputSPECKPath); + if (!expl_file) { LERROR(fmt::format("Error opening file expl.speck.")); - } + } + std::string line; + std::string d; + std::string n; + while (getline(expl_file, line)) + { + if (line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" || line.empty()) { + continue; + } - std::string line; - std::string d; - std::string n; - while (getline(expl_file, line)) - { - if (line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" || line.empty()) { - continue; - } + std::istringstream linestream(line); - std::istringstream linestream(line); + getline(linestream, d, '#'); + getline(linestream, n); + n.erase(0, 1); - getline(linestream, d, '#'); - getline(linestream, n); - n.erase(0, 1); - - std::string coord; - if (n.compare(starName) == 0) - { - std::stringstream datastream(d); - getline(datastream, coord, ' '); - pos[0] = std::stof(coord.c_str(), nullptr); - getline(datastream, coord, ' '); - pos[1] = std::stof(coord.c_str(), nullptr); - getline(datastream, coord, ' '); - pos[2] = std::stof(coord.c_str(), nullptr); - break; - } - } + std::string coord; + if (n.compare(starName) == 0) + { + std::stringstream datastream(d); + getline(datastream, coord, ' '); + pos[0] = std::stof(coord.c_str(), nullptr); + getline(datastream, coord, ' '); + pos[1] = std::stof(coord.c_str(), nullptr); + getline(datastream, coord, ' '); + pos[2] = std::stof(coord.c_str(), nullptr); + break; + } + } //Apply transformation matrix to pos glm::dmat4 _transformationMatrix = glm::dmat4(1.0); - glm::vec3 transformedPos = glm::vec3( - _transformationMatrix * glm::dvec4(pos, 1.0) - ); + glm::vec3 transformedPos = glm::vec3(_transformationMatrix * glm::dvec4(pos, 1.0)); - expl_file.close(); - return transformedPos; + expl_file.close(); + return transformedPos; } void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallback) { - std::ifstream csv_file(_inputCSVPath); if (!csv_file.good()) { LERROR(fmt::format("Failed to open Speck file '{}'", _inputCSVPath)); return; } - std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); + std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); std::ofstream lut_file(_outputLUTPath); - int version = 1; - bin_file.write((char *)&version, sizeof(int)); + int version = 1; + bin_file.write((char *)&version, sizeof(int)); - Exoplanet p; + Exoplanet p; - std::string planetname; + std::string planetname; std::string component; - std::string planet_row; - getline(csv_file, planet_row); // The first line, containing the data names + std::string planet_row; + getline(csv_file, planet_row); // The first line, containing the data names - std::string data_s; - bool iskeplerobject = false; + std::string data_s; + bool iskeplerobject = false; int total = 0; while (getline(csv_file, planet_row)) { ++total; @@ -243,534 +237,530 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb LINFOC("CSVTOBIN", fmt::format("Loading {} stars", total)); int count = 0; - while (getline(csv_file, planet_row)) { + while (getline(csv_file, planet_row)) { ++count; progressCallback(static_cast(count) / static_cast(total)); - std::istringstream lineStream(planet_row); + std::istringstream lineStream(planet_row); - getline(lineStream, data_s, ','); // A - if (!data_s.empty()) - p.A = std::stof(data_s.c_str(), nullptr); - else - p.A = NAN; - getline(lineStream, data_s, ','); // AUPPER - if (!data_s.empty()) - p.AUPPER = std::stod(data_s.c_str(), nullptr); - else - p.AUPPER = NAN; - getline(lineStream, data_s, ','); // ALOWER - if (!data_s.empty()) - p.ALOWER = std::stod(data_s.c_str(), nullptr); - else - p.ALOWER = NAN; - getline(lineStream, data_s, ','); // UA - if (!data_s.empty()) - p.UA = std::stod(data_s.c_str(), nullptr); - else - p.UA = NAN; - getline(lineStream, data_s, ','); // AREF - getline(lineStream, data_s, ','); // AURL - getline(lineStream, data_s, ','); // AR - getline(lineStream, data_s, ','); // ARUPPER - getline(lineStream, data_s, ','); // ARLOWER - getline(lineStream, data_s, ','); // UAR - getline(lineStream, data_s, ','); // ARREF - getline(lineStream, data_s, ','); // ARURL - getline(lineStream, data_s, ','); // ASTROMETRY - getline(lineStream, data_s, ','); // B - getline(lineStream, data_s, ','); // BUPPER - getline(lineStream, data_s, ','); // BLOWER - getline(lineStream, data_s, ','); // UB - getline(lineStream, data_s, ','); // BREF - getline(lineStream, data_s, ','); // BURL - getline(lineStream, data_s, ','); // BIGOM - if (!data_s.empty()) - p.BIGOM = std::stof(data_s.c_str(), nullptr); - else - p.BIGOM = NAN; - getline(lineStream, data_s, ','); // BIGOMUPPER - if (!data_s.empty()) - p.BIGOMUPPER = std::stof(data_s.c_str(), nullptr); - else - p.BIGOMUPPER = NAN; - getline(lineStream, data_s, ','); // BIGOMLOWER - if (!data_s.empty()) - p.BIGOMLOWER = std::stof(data_s.c_str(), nullptr); - else - p.BIGOMLOWER = NAN; - getline(lineStream, data_s, ','); // UBIGOM - if (!data_s.empty()) - p.UBIGOM = std::stof(data_s.c_str(), nullptr); - else - p.UBIGOM = NAN; - getline(lineStream, data_s, ','); // BIGOMREF - getline(lineStream, data_s, ','); // BIGOMURL - getline(lineStream, data_s, ','); // BINARY - if (!data_s.empty()) - p.BINARY = std::stoi(data_s.c_str(), nullptr); - else - p.BINARY = -1; - getline(lineStream, data_s, ','); // BINARYREF - getline(lineStream, data_s, ','); // BINARYURL - getline(lineStream, data_s, ','); // BMV + getline(lineStream, data_s, ','); // A + if (!data_s.empty()) + p.A = std::stof(data_s.c_str(), nullptr); + else + p.A = NAN; + getline(lineStream, data_s, ','); // AUPPER + if (!data_s.empty()) + p.AUPPER = std::stod(data_s.c_str(), nullptr); + else + p.AUPPER = NAN; + getline(lineStream, data_s, ','); // ALOWER + if (!data_s.empty()) + p.ALOWER = std::stod(data_s.c_str(), nullptr); + else + p.ALOWER = NAN; + getline(lineStream, data_s, ','); // UA + if (!data_s.empty()) + p.UA = std::stod(data_s.c_str(), nullptr); + else + p.UA = NAN; + getline(lineStream, data_s, ','); // AREF + getline(lineStream, data_s, ','); // AURL + getline(lineStream, data_s, ','); // AR + getline(lineStream, data_s, ','); // ARUPPER + getline(lineStream, data_s, ','); // ARLOWER + getline(lineStream, data_s, ','); // UAR + getline(lineStream, data_s, ','); // ARREF + getline(lineStream, data_s, ','); // ARURL + getline(lineStream, data_s, ','); // ASTROMETRY + getline(lineStream, data_s, ','); // B + getline(lineStream, data_s, ','); // BUPPER + getline(lineStream, data_s, ','); // BLOWER + getline(lineStream, data_s, ','); // UB + getline(lineStream, data_s, ','); // BREF + getline(lineStream, data_s, ','); // BURL + getline(lineStream, data_s, ','); // BIGOM + if (!data_s.empty()) + p.BIGOM = std::stof(data_s.c_str(), nullptr); + else + p.BIGOM = NAN; + getline(lineStream, data_s, ','); // BIGOMUPPER + if (!data_s.empty()) + p.BIGOMUPPER = std::stof(data_s.c_str(), nullptr); + else + p.BIGOMUPPER = NAN; + getline(lineStream, data_s, ','); // BIGOMLOWER + if (!data_s.empty()) + p.BIGOMLOWER = std::stof(data_s.c_str(), nullptr); + else + p.BIGOMLOWER = NAN; + getline(lineStream, data_s, ','); // UBIGOM + if (!data_s.empty()) + p.UBIGOM = std::stof(data_s.c_str(), nullptr); + else + p.UBIGOM = NAN; + getline(lineStream, data_s, ','); // BIGOMREF + getline(lineStream, data_s, ','); // BIGOMURL + getline(lineStream, data_s, ','); // BINARY + if (!data_s.empty()) + p.BINARY = std::stoi(data_s.c_str(), nullptr); + else + p.BINARY = -1; + getline(lineStream, data_s, ','); // BINARYREF + getline(lineStream, data_s, ','); // BINARYURL + getline(lineStream, data_s, ','); // BMV if (!data_s.empty()) p.BMV = std::stof(data_s.c_str(), nullptr); else p.BMV = NAN; - getline(lineStream, data_s, ','); // CHI2 - getline(lineStream, data_s, ','); // COMP + getline(lineStream, data_s, ','); // CHI2 + getline(lineStream, data_s, ','); // COMP component = data_s; - getline(lineStream, data_s, ','); // DATE - getline(lineStream, data_s, ','); // DEC - getline(lineStream, data_s, ','); // DEC_STRING - getline(lineStream, data_s, ','); // DENSITY - getline(lineStream, data_s, ','); // DENSITYUPPER - getline(lineStream, data_s, ','); // DENSITYLOWER - getline(lineStream, data_s, ','); // UDENSITY - getline(lineStream, data_s, ','); // DENSITYREF - getline(lineStream, data_s, ','); // DENSITYURL - getline(lineStream, data_s, ','); // DEPTH - getline(lineStream, data_s, ','); // DEPTHUPPER - getline(lineStream, data_s, ','); // DEPTHLOWER - getline(lineStream, data_s, ','); // UDEPTH - getline(lineStream, data_s, ','); // DEPTHREF - getline(lineStream, data_s, ','); // DEPTHURL - getline(lineStream, data_s, ','); // DIST - getline(lineStream, data_s, ','); // DISTUPPER - getline(lineStream, data_s, ','); // DISTLOWER - getline(lineStream, data_s, ','); // UDIST - getline(lineStream, data_s, ','); // DISTREF - getline(lineStream, data_s, ','); // DISTURL - getline(lineStream, data_s, ','); // DR - getline(lineStream, data_s, ','); // DRUPPER - getline(lineStream, data_s, ','); // DRLOWER - getline(lineStream, data_s, ','); // UDR - getline(lineStream, data_s, ','); // DRREF - getline(lineStream, data_s, ','); // DRURL - getline(lineStream, data_s, ','); // DVDT - getline(lineStream, data_s, ','); // DVDTUPPER - getline(lineStream, data_s, ','); // DVDTLOWER - getline(lineStream, data_s, ','); // UDVDT - getline(lineStream, data_s, ','); // DVDTREF - getline(lineStream, data_s, ','); // DVDTURL - getline(lineStream, data_s, ','); // EANAME - getline(lineStream, data_s, ','); // EAURL - getline(lineStream, data_s, ','); // ECC - if (!data_s.empty()) - p.ECC = std::stof(data_s.c_str(), nullptr); - else - p.ECC = NAN; + getline(lineStream, data_s, ','); // DATE + getline(lineStream, data_s, ','); // DEC + getline(lineStream, data_s, ','); // DEC_STRING + getline(lineStream, data_s, ','); // DENSITY + getline(lineStream, data_s, ','); // DENSITYUPPER + getline(lineStream, data_s, ','); // DENSITYLOWER + getline(lineStream, data_s, ','); // UDENSITY + getline(lineStream, data_s, ','); // DENSITYREF + getline(lineStream, data_s, ','); // DENSITYURL + getline(lineStream, data_s, ','); // DEPTH + getline(lineStream, data_s, ','); // DEPTHUPPER + getline(lineStream, data_s, ','); // DEPTHLOWER + getline(lineStream, data_s, ','); // UDEPTH + getline(lineStream, data_s, ','); // DEPTHREF + getline(lineStream, data_s, ','); // DEPTHURL + getline(lineStream, data_s, ','); // DIST + getline(lineStream, data_s, ','); // DISTUPPER + getline(lineStream, data_s, ','); // DISTLOWER + getline(lineStream, data_s, ','); // UDIST + getline(lineStream, data_s, ','); // DISTREF + getline(lineStream, data_s, ','); // DISTURL + getline(lineStream, data_s, ','); // DR + getline(lineStream, data_s, ','); // DRUPPER + getline(lineStream, data_s, ','); // DRLOWER + getline(lineStream, data_s, ','); // UDR + getline(lineStream, data_s, ','); // DRREF + getline(lineStream, data_s, ','); // DRURL + getline(lineStream, data_s, ','); // DVDT + getline(lineStream, data_s, ','); // DVDTUPPER + getline(lineStream, data_s, ','); // DVDTLOWER + getline(lineStream, data_s, ','); // UDVDT + getline(lineStream, data_s, ','); // DVDTREF + getline(lineStream, data_s, ','); // DVDTURL + getline(lineStream, data_s, ','); // EANAME + getline(lineStream, data_s, ','); // EAURL + getline(lineStream, data_s, ','); // ECC + if (!data_s.empty()) + p.ECC = std::stof(data_s.c_str(), nullptr); + else + p.ECC = NAN; - getline(lineStream, data_s, ','); // ECCUPPER - if (!data_s.empty()) - p.ECCUPPER = std::stof(data_s.c_str(), nullptr); - else - p.ECCUPPER = NAN; + getline(lineStream, data_s, ','); // ECCUPPER + if (!data_s.empty()) + p.ECCUPPER = std::stof(data_s.c_str(), nullptr); + else + p.ECCUPPER = NAN; - getline(lineStream, data_s, ','); // ECCLOWER - if (!data_s.empty()) - p.ECCLOWER = std::stof(data_s.c_str(), nullptr); - else - p.ECCLOWER = NAN; + getline(lineStream, data_s, ','); // ECCLOWER + if (!data_s.empty()) + p.ECCLOWER = std::stof(data_s.c_str(), nullptr); + else + p.ECCLOWER = NAN; - getline(lineStream, data_s, ','); // UECC - if (!data_s.empty()) - p.UECC = std::stof(data_s.c_str(), nullptr); - else - p.UECC = NAN; + getline(lineStream, data_s, ','); // UECC + if (!data_s.empty()) + p.UECC = std::stof(data_s.c_str(), nullptr); + else + p.UECC = NAN; - getline(lineStream, data_s, ','); // ECCREF - getline(lineStream, data_s, ','); // ECCURL - getline(lineStream, data_s, ','); // EOD - getline(lineStream, data_s, ','); // ETDNAME - getline(lineStream, data_s, ','); // ETDURL - getline(lineStream, data_s, ','); // FE - getline(lineStream, data_s, ','); // FEUPPER - getline(lineStream, data_s, ','); // FELOWER - getline(lineStream, data_s, ','); // UFE - getline(lineStream, data_s, ','); // FEREF - getline(lineStream, data_s, ','); // FEURL - getline(lineStream, data_s, ','); // FIRSTREF - getline(lineStream, data_s, ','); // FIRSTURL - getline(lineStream, data_s, ','); // FREEZE_ECC - getline(lineStream, data_s, ','); // GAMMA - getline(lineStream, data_s, ','); // GAMMAUPPER - getline(lineStream, data_s, ','); // GAMMALOWER - getline(lineStream, data_s, ','); // UGAMMA - getline(lineStream, data_s, ','); // GAMMAREF - getline(lineStream, data_s, ','); // GAMMAURL - getline(lineStream, data_s, ','); // GL - getline(lineStream, data_s, ','); // GRAVITY - getline(lineStream, data_s, ','); // GRAVITYUPPER - getline(lineStream, data_s, ','); // GRAVITYLOWER - getline(lineStream, data_s, ','); // UGRAVITY - getline(lineStream, data_s, ','); // GRAVITYREF - getline(lineStream, data_s, ','); // GRAVITYURL - getline(lineStream, data_s, ','); // H - getline(lineStream, data_s, ','); // HD - getline(lineStream, data_s, ','); // HIPP - getline(lineStream, data_s, ','); // HR - getline(lineStream, data_s, ','); // I - if (!data_s.empty()) - p.I = std::stof(data_s.c_str(), nullptr); - else - p.I = NAN; + getline(lineStream, data_s, ','); // ECCREF + getline(lineStream, data_s, ','); // ECCURL + getline(lineStream, data_s, ','); // EOD + getline(lineStream, data_s, ','); // ETDNAME + getline(lineStream, data_s, ','); // ETDURL + getline(lineStream, data_s, ','); // FE + getline(lineStream, data_s, ','); // FEUPPER + getline(lineStream, data_s, ','); // FELOWER + getline(lineStream, data_s, ','); // UFE + getline(lineStream, data_s, ','); // FEREF + getline(lineStream, data_s, ','); // FEURL + getline(lineStream, data_s, ','); // FIRSTREF + getline(lineStream, data_s, ','); // FIRSTURL + getline(lineStream, data_s, ','); // FREEZE_ECC + getline(lineStream, data_s, ','); // GAMMA + getline(lineStream, data_s, ','); // GAMMAUPPER + getline(lineStream, data_s, ','); // GAMMALOWER + getline(lineStream, data_s, ','); // UGAMMA + getline(lineStream, data_s, ','); // GAMMAREF + getline(lineStream, data_s, ','); // GAMMAURL + getline(lineStream, data_s, ','); // GL + getline(lineStream, data_s, ','); // GRAVITY + getline(lineStream, data_s, ','); // GRAVITYUPPER + getline(lineStream, data_s, ','); // GRAVITYLOWER + getline(lineStream, data_s, ','); // UGRAVITY + getline(lineStream, data_s, ','); // GRAVITYREF + getline(lineStream, data_s, ','); // GRAVITYURL + getline(lineStream, data_s, ','); // H + getline(lineStream, data_s, ','); // HD + getline(lineStream, data_s, ','); // HIPP + getline(lineStream, data_s, ','); // HR + getline(lineStream, data_s, ','); // I + if (!data_s.empty()) + p.I = std::stof(data_s.c_str(), nullptr); + else + p.I = NAN; - getline(lineStream, data_s, ','); // IUPPER - if (!data_s.empty()) - p.IUPPER = std::stof(data_s.c_str(), nullptr); - else - p.IUPPER = NAN; + getline(lineStream, data_s, ','); // IUPPER + if (!data_s.empty()) + p.IUPPER = std::stof(data_s.c_str(), nullptr); + else + p.IUPPER = NAN; - getline(lineStream, data_s, ','); // ILOWER - if (!data_s.empty()) - p.ILOWER = std::stof(data_s.c_str(), nullptr); - else - p.ILOWER = NAN; + getline(lineStream, data_s, ','); // ILOWER + if (!data_s.empty()) + p.ILOWER = std::stof(data_s.c_str(), nullptr); + else + p.ILOWER = NAN; - getline(lineStream, data_s, ','); // UI - if (!data_s.empty()) - p.UI = std::stof(data_s.c_str(), nullptr); - else - p.UI = NAN; + getline(lineStream, data_s, ','); // UI + if (!data_s.empty()) + p.UI = std::stof(data_s.c_str(), nullptr); + else + p.UI = NAN; - getline(lineStream, data_s, ','); // IREF - getline(lineStream, data_s, ','); // IURL - getline(lineStream, data_s, ','); // IMAGING - getline(lineStream, data_s, ','); // J - getline(lineStream, data_s, ','); // JSNAME - getline(lineStream, data_s, ','); // EPEURL - getline(lineStream, data_s, ','); // K - getline(lineStream, data_s, ','); // KUPPER - getline(lineStream, data_s, ','); // KLOWER - getline(lineStream, data_s, ','); // UK - getline(lineStream, data_s, ','); // KREF - getline(lineStream, data_s, ','); // KURL - getline(lineStream, data_s, ','); // KOI - getline(lineStream, data_s, ','); // KS - getline(lineStream, data_s, ','); // KP - getline(lineStream, data_s, ','); // LAMBDA - getline(lineStream, data_s, ','); // LAMBDAUPPER - getline(lineStream, data_s, ','); // LAMBDALOWER - getline(lineStream, data_s, ','); // ULAMBDA - getline(lineStream, data_s, ','); // LAMBDAREF - getline(lineStream, data_s, ','); // LAMBDAURL - getline(lineStream, data_s, ','); // LOGG - getline(lineStream, data_s, ','); // LOGGUPPER - getline(lineStream, data_s, ','); // LOGGLOWER - getline(lineStream, data_s, ','); // ULOGG - getline(lineStream, data_s, ','); // LOGGREF - getline(lineStream, data_s, ','); // LOGGURL; - getline(lineStream, data_s, ','); // MASS - getline(lineStream, data_s, ','); // MASSUPPER - getline(lineStream, data_s, ','); // MASSLOWER - getline(lineStream, data_s, ','); // UMASS - getline(lineStream, data_s, ','); // MASSREF - getline(lineStream, data_s, ','); // MASSURL - getline(lineStream, data_s, ','); // MICROLENSING - getline(lineStream, data_s, ','); // MSINI - getline(lineStream, data_s, ','); // MSINIUPPER - getline(lineStream, data_s, ','); // MSINILOWER - getline(lineStream, data_s, ','); // UMSINI - getline(lineStream, data_s, ','); // MSINIREF - getline(lineStream, data_s, ','); // MSINIURL - getline(lineStream, data_s, ','); // MSTAR - getline(lineStream, data_s, ','); // MSTARUPPER - getline(lineStream, data_s, ','); // MSTARLOWER - getline(lineStream, data_s, ','); // UMSTAR - getline(lineStream, data_s, ','); // MSTARREF - getline(lineStream, data_s, ','); // MSTARURL - getline(lineStream, data_s, ','); // MULT - getline(lineStream, data_s, ','); // NAME - getline(lineStream, data_s, ','); // NCOMP - if (!data_s.empty()) - p.NCOMP = std::stoi(data_s.c_str(), nullptr); - else - p.NCOMP = -1; - getline(lineStream, data_s, ','); // NOBS - getline(lineStream, data_s, ','); // OM - if (!data_s.empty()) - p.OM = std::stof(data_s.c_str(), nullptr); - else - p.OM = NAN; + getline(lineStream, data_s, ','); // IREF + getline(lineStream, data_s, ','); // IURL + getline(lineStream, data_s, ','); // IMAGING + getline(lineStream, data_s, ','); // J + getline(lineStream, data_s, ','); // JSNAME + getline(lineStream, data_s, ','); // EPEURL + getline(lineStream, data_s, ','); // K + getline(lineStream, data_s, ','); // KUPPER + getline(lineStream, data_s, ','); // KLOWER + getline(lineStream, data_s, ','); // UK + getline(lineStream, data_s, ','); // KREF + getline(lineStream, data_s, ','); // KURL + getline(lineStream, data_s, ','); // KOI + getline(lineStream, data_s, ','); // KS + getline(lineStream, data_s, ','); // KP + getline(lineStream, data_s, ','); // LAMBDA + getline(lineStream, data_s, ','); // LAMBDAUPPER + getline(lineStream, data_s, ','); // LAMBDALOWER + getline(lineStream, data_s, ','); // ULAMBDA + getline(lineStream, data_s, ','); // LAMBDAREF + getline(lineStream, data_s, ','); // LAMBDAURL + getline(lineStream, data_s, ','); // LOGG + getline(lineStream, data_s, ','); // LOGGUPPER + getline(lineStream, data_s, ','); // LOGGLOWER + getline(lineStream, data_s, ','); // ULOGG + getline(lineStream, data_s, ','); // LOGGREF + getline(lineStream, data_s, ','); // LOGGURL; + getline(lineStream, data_s, ','); // MASS + getline(lineStream, data_s, ','); // MASSUPPER + getline(lineStream, data_s, ','); // MASSLOWER + getline(lineStream, data_s, ','); // UMASS + getline(lineStream, data_s, ','); // MASSREF + getline(lineStream, data_s, ','); // MASSURL + getline(lineStream, data_s, ','); // MICROLENSING + getline(lineStream, data_s, ','); // MSINI + getline(lineStream, data_s, ','); // MSINIUPPER + getline(lineStream, data_s, ','); // MSINILOWER + getline(lineStream, data_s, ','); // UMSINI + getline(lineStream, data_s, ','); // MSINIREF + getline(lineStream, data_s, ','); // MSINIURL + getline(lineStream, data_s, ','); // MSTAR + getline(lineStream, data_s, ','); // MSTARUPPER + getline(lineStream, data_s, ','); // MSTARLOWER + getline(lineStream, data_s, ','); // UMSTAR + getline(lineStream, data_s, ','); // MSTARREF + getline(lineStream, data_s, ','); // MSTARURL + getline(lineStream, data_s, ','); // MULT + getline(lineStream, data_s, ','); // NAME + getline(lineStream, data_s, ','); // NCOMP + if (!data_s.empty()) + p.NCOMP = std::stoi(data_s.c_str(), nullptr); + else + p.NCOMP = -1; + getline(lineStream, data_s, ','); // NOBS + getline(lineStream, data_s, ','); // OM + if (!data_s.empty()) + p.OM = std::stof(data_s.c_str(), nullptr); + else + p.OM = NAN; - getline(lineStream, data_s, ','); // OMUPPER - if (!data_s.empty()) - p.OMUPPER = std::stof(data_s.c_str(), nullptr); - else - p.OMUPPER = NAN; + getline(lineStream, data_s, ','); // OMUPPER + if (!data_s.empty()) + p.OMUPPER = std::stof(data_s.c_str(), nullptr); + else + p.OMUPPER = NAN; - getline(lineStream, data_s, ','); // OMLOWER - if (!data_s.empty()) - p.OMLOWER = std::stof(data_s.c_str(), nullptr); - else - p.OMLOWER = NAN; + getline(lineStream, data_s, ','); // OMLOWER + if (!data_s.empty()) + p.OMLOWER = std::stof(data_s.c_str(), nullptr); + else + p.OMLOWER = NAN; - getline(lineStream, data_s, ','); // UOM - if (!data_s.empty()) - p.UOM = std::stof(data_s.c_str(), nullptr); - else - p.UOM = NAN; + getline(lineStream, data_s, ','); // UOM + if (!data_s.empty()) + p.UOM = std::stof(data_s.c_str(), nullptr); + else + p.UOM = NAN; - getline(lineStream, data_s, ','); // OMREF - getline(lineStream, data_s, ','); // OMURL - getline(lineStream, data_s, ','); // ORBREF - getline(lineStream, data_s, ','); // ORBURL - getline(lineStream, data_s, ','); // OTHERNAME - getline(lineStream, data_s, ','); // PAR - getline(lineStream, data_s, ','); // PARUPPER - getline(lineStream, data_s, ','); // PARLOWER - getline(lineStream, data_s, ','); // UPAR - getline(lineStream, data_s, ','); // PER - if (!data_s.empty()) - p.PER = std::stod(data_s.c_str(), nullptr); - else - p.PER = NAN; + getline(lineStream, data_s, ','); // OMREF + getline(lineStream, data_s, ','); // OMURL + getline(lineStream, data_s, ','); // ORBREF + getline(lineStream, data_s, ','); // ORBURL + getline(lineStream, data_s, ','); // OTHERNAME + getline(lineStream, data_s, ','); // PAR + getline(lineStream, data_s, ','); // PARUPPER + getline(lineStream, data_s, ','); // PARLOWER + getline(lineStream, data_s, ','); // UPAR + getline(lineStream, data_s, ','); // PER + if (!data_s.empty()) + p.PER = std::stod(data_s.c_str(), nullptr); + else + p.PER = NAN; - getline(lineStream, data_s, ','); // PERUPPER - if (!data_s.empty()) - p.PERUPPER = std::stof(data_s.c_str(), nullptr); - else - p.PERUPPER = NAN; + getline(lineStream, data_s, ','); // PERUPPER + if (!data_s.empty()) + p.PERUPPER = std::stof(data_s.c_str(), nullptr); + else + p.PERUPPER = NAN; - getline(lineStream, data_s, ','); // PERLOWER - if (!data_s.empty()) - p.PERLOWER = std::stof(data_s.c_str(), nullptr); - else - p.PERLOWER = NAN; + getline(lineStream, data_s, ','); // PERLOWER + if (!data_s.empty()) + p.PERLOWER = std::stof(data_s.c_str(), nullptr); + else + p.PERLOWER = NAN; - getline(lineStream, data_s, ','); // UPER - if (!data_s.empty()) - p.UPER = std::stof(data_s.c_str(), nullptr); - else - p.UPER = NAN; + getline(lineStream, data_s, ','); // UPER + if (!data_s.empty()) + p.UPER = std::stof(data_s.c_str(), nullptr); + else + p.UPER = NAN; - getline(lineStream, data_s, ','); // PERREF - getline(lineStream, data_s, ','); // PERURL - getline(lineStream, data_s, ','); // PLANETDISCMETH - getline(lineStream, data_s, ','); // R - if (!data_s.empty()) - p.R = std::stod(data_s.c_str(), nullptr); - else - p.R = NAN; + getline(lineStream, data_s, ','); // PERREF + getline(lineStream, data_s, ','); // PERURL + getline(lineStream, data_s, ','); // PLANETDISCMETH + getline(lineStream, data_s, ','); // R + if (!data_s.empty()) + p.R = std::stod(data_s.c_str(), nullptr); + else + p.R = NAN; - getline(lineStream, data_s, ','); // RUPPER - if (!data_s.empty()) - p.RUPPER = std::stod(data_s.c_str(), nullptr); - else - p.RUPPER = NAN; + getline(lineStream, data_s, ','); // RUPPER + if (!data_s.empty()) + p.RUPPER = std::stod(data_s.c_str(), nullptr); + else + p.RUPPER = NAN; - getline(lineStream, data_s, ','); // RLOWER - if (!data_s.empty()) - p.RLOWER = std::stod(data_s.c_str(), nullptr); - else - p.RLOWER = NAN; + getline(lineStream, data_s, ','); // RLOWER + if (!data_s.empty()) + p.RLOWER = std::stod(data_s.c_str(), nullptr); + else + p.RLOWER = NAN; - getline(lineStream, data_s, ','); //UR - if (!data_s.empty()) - p.UR = std::stod(data_s.c_str(), nullptr); - else - p.UR = NAN; + getline(lineStream, data_s, ','); //UR + if (!data_s.empty()) + p.UR = std::stod(data_s.c_str(), nullptr); + else + p.UR = NAN; - getline(lineStream, data_s, ','); // RREF - getline(lineStream, data_s, ','); // RURL - getline(lineStream, data_s, ','); // RA - getline(lineStream, data_s, ','); // RA_STRING - getline(lineStream, data_s, ','); // RHK - getline(lineStream, data_s, ','); // RHOSTAR - getline(lineStream, data_s, ','); // RHOSTARUPPER - getline(lineStream, data_s, ','); // RHOSTARLOWER - getline(lineStream, data_s, ','); // URHOSTAR - getline(lineStream, data_s, ','); // RHOSTARREF - getline(lineStream, data_s, ','); // RHOSTARURL - getline(lineStream, data_s, ','); // RMS - getline(lineStream, data_s, ','); // RR - getline(lineStream, data_s, ','); // RRUPPER - getline(lineStream, data_s, ','); // RRLOWER - getline(lineStream, data_s, ','); // URR - getline(lineStream, data_s, ','); // RRREF - getline(lineStream, data_s, ','); // RRURL - getline(lineStream, data_s, ','); // RSTAR - if (!data_s.empty()) - p.RSTAR = std::stof(data_s.c_str(), nullptr); - else - p.RSTAR = NAN; + getline(lineStream, data_s, ','); // RREF + getline(lineStream, data_s, ','); // RURL + getline(lineStream, data_s, ','); // RA + getline(lineStream, data_s, ','); // RA_STRING + getline(lineStream, data_s, ','); // RHK + getline(lineStream, data_s, ','); // RHOSTAR + getline(lineStream, data_s, ','); // RHOSTARUPPER + getline(lineStream, data_s, ','); // RHOSTARLOWER + getline(lineStream, data_s, ','); // URHOSTAR + getline(lineStream, data_s, ','); // RHOSTARREF + getline(lineStream, data_s, ','); // RHOSTARURL + getline(lineStream, data_s, ','); // RMS + getline(lineStream, data_s, ','); // RR + getline(lineStream, data_s, ','); // RRUPPER + getline(lineStream, data_s, ','); // RRLOWER + getline(lineStream, data_s, ','); // URR + getline(lineStream, data_s, ','); // RRREF + getline(lineStream, data_s, ','); // RRURL + getline(lineStream, data_s, ','); // RSTAR + if (!data_s.empty()) + p.RSTAR = std::stof(data_s.c_str(), nullptr); + else + p.RSTAR = NAN; - getline(lineStream, data_s, ','); // RSTARUPPER - if (!data_s.empty()) - p.RSTARUPPER = std::stof(data_s.c_str(), nullptr); - else - p.RSTARUPPER = NAN; + getline(lineStream, data_s, ','); // RSTARUPPER + if (!data_s.empty()) + p.RSTARUPPER = std::stof(data_s.c_str(), nullptr); + else + p.RSTARUPPER = NAN; - getline(lineStream, data_s, ','); // RSTARLOWER - if (!data_s.empty()) - p.RSTARLOWER = std::stof(data_s.c_str(), nullptr); - else - p.RSTARLOWER = NAN; + getline(lineStream, data_s, ','); // RSTARLOWER + if (!data_s.empty()) + p.RSTARLOWER = std::stof(data_s.c_str(), nullptr); + else + p.RSTARLOWER = NAN; - getline(lineStream, data_s, ','); // URSTAR - if (!data_s.empty()) - p.URSTAR = std::stof(data_s.c_str(), nullptr); - else - p.URSTAR = NAN; + getline(lineStream, data_s, ','); // URSTAR + if (!data_s.empty()) + p.URSTAR = std::stof(data_s.c_str(), nullptr); + else + p.URSTAR = NAN; - getline(lineStream, data_s, ','); // RSTARREF - getline(lineStream, data_s, ','); // RSTARURL - getline(lineStream, data_s, ','); // SAO - getline(lineStream, data_s, ','); // SE - getline(lineStream, data_s, ','); // SEREF - getline(lineStream, data_s, ','); // SEURL - getline(lineStream, data_s, ','); // SEDEPTHJ - getline(lineStream, data_s, ','); // SEDEPTHJUPPER - getline(lineStream, data_s, ','); // SEDEPTHJLOWER - getline(lineStream, data_s, ','); // USEDEPTHJ - getline(lineStream, data_s, ','); // SEDEPTHJREF - getline(lineStream, data_s, ','); // SEDEPTHJURL - getline(lineStream, data_s, ','); // SEDEPTHH - getline(lineStream, data_s, ','); // SEDEPTHHUPPER - getline(lineStream, data_s, ','); // SEDEPTHHLOWER - getline(lineStream, data_s, ','); // USEDEPTHH - getline(lineStream, data_s, ','); // SEDEPTHHREF - getline(lineStream, data_s, ','); // SEDEPTHHURL - getline(lineStream, data_s, ','); // SEDEPTHKS - getline(lineStream, data_s, ','); // SEDEPTHKSUPPER - getline(lineStream, data_s, ','); // SEDEPTHKSLOWER - getline(lineStream, data_s, ','); // USEDEPTHKS - getline(lineStream, data_s, ','); // SEDEPTHKSREF - getline(lineStream, data_s, ','); // SEDEPTHKSURL - getline(lineStream, data_s, ','); // SEDEPTHKP - getline(lineStream, data_s, ','); // SEDEPTHKPUPPER - getline(lineStream, data_s, ','); // SEDEPTHKPLOWER - getline(lineStream, data_s, ','); // USEDEPTHKP - getline(lineStream, data_s, ','); // SEDEPTHKPREF - getline(lineStream, data_s, ','); // SEDEPTHKPURL - getline(lineStream, data_s, ','); // SEDEPTH36 - getline(lineStream, data_s, ','); // SEDEPTH36UPPER - getline(lineStream, data_s, ','); // SEDEPTH36LOWER - getline(lineStream, data_s, ','); // USEDEPTH36 - getline(lineStream, data_s, ','); // SEDEPTH36REFx - getline(lineStream, data_s, ','); // SEDEPTH36URLx - getline(lineStream, data_s, ','); // SEDEPTH45 - getline(lineStream, data_s, ','); // SEDEPTH45UPPER - getline(lineStream, data_s, ','); // SEDEPTH45LOWER - getline(lineStream, data_s, ','); // USEDEPTH45 - getline(lineStream, data_s, ','); // SEDEPTH45REF - getline(lineStream, data_s, ','); // SEDEPTH45URL - getline(lineStream, data_s, ','); // SEDEPTH58 - getline(lineStream, data_s, ','); // SEDEPTH58UPPER - getline(lineStream, data_s, ','); // SEDEPTH58LOWER - getline(lineStream, data_s, ','); // USEDEPTH58 - getline(lineStream, data_s, ','); // EDEPTH58REF - getline(lineStream, data_s, ','); // SEDEPTH58URL - getline(lineStream, data_s, ','); // SEDEPTH80 - getline(lineStream, data_s, ','); // SEDEPTH80UPPER - getline(lineStream, data_s, ','); // SEDEPTH80LOWER - getline(lineStream, data_s, ','); // USEDEPTH80 - getline(lineStream, data_s, ','); // SEDEPTH80REF - getline(lineStream, data_s, ','); // SEDEPTH80URL - getline(lineStream, data_s, ','); // SEP - getline(lineStream, data_s, ','); // SEPUPPER - getline(lineStream, data_s, ','); // SEPLOWER - getline(lineStream, data_s, ','); // USEP - getline(lineStream, data_s, ','); // SEPREF - getline(lineStream, data_s, ','); // SEPURL - getline(lineStream, data_s, ','); // SET - getline(lineStream, data_s, ','); // SETUPPER - getline(lineStream, data_s, ','); // SETLOWER - getline(lineStream, data_s, ','); // USET - getline(lineStream, data_s, ','); // SETREF - getline(lineStream, data_s, ','); // SETURL - getline(lineStream, data_s, ','); // SHK - getline(lineStream, data_s, ','); // SIMBADNAME - getline(lineStream, data_s, ','); // SIMBADURL - getline(lineStream, data_s, ','); // SPECREF - getline(lineStream, data_s, ','); // SPECURL - getline(lineStream, data_s, ','); // STAR - std::string speckStarname = getExplName(data_s); + getline(lineStream, data_s, ','); // RSTARREF + getline(lineStream, data_s, ','); // RSTARURL + getline(lineStream, data_s, ','); // SAO + getline(lineStream, data_s, ','); // SE + getline(lineStream, data_s, ','); // SEREF + getline(lineStream, data_s, ','); // SEURL + getline(lineStream, data_s, ','); // SEDEPTHJ + getline(lineStream, data_s, ','); // SEDEPTHJUPPER + getline(lineStream, data_s, ','); // SEDEPTHJLOWER + getline(lineStream, data_s, ','); // USEDEPTHJ + getline(lineStream, data_s, ','); // SEDEPTHJREF + getline(lineStream, data_s, ','); // SEDEPTHJURL + getline(lineStream, data_s, ','); // SEDEPTHH + getline(lineStream, data_s, ','); // SEDEPTHHUPPER + getline(lineStream, data_s, ','); // SEDEPTHHLOWER + getline(lineStream, data_s, ','); // USEDEPTHH + getline(lineStream, data_s, ','); // SEDEPTHHREF + getline(lineStream, data_s, ','); // SEDEPTHHURL + getline(lineStream, data_s, ','); // SEDEPTHKS + getline(lineStream, data_s, ','); // SEDEPTHKSUPPER + getline(lineStream, data_s, ','); // SEDEPTHKSLOWER + getline(lineStream, data_s, ','); // USEDEPTHKS + getline(lineStream, data_s, ','); // SEDEPTHKSREF + getline(lineStream, data_s, ','); // SEDEPTHKSURL + getline(lineStream, data_s, ','); // SEDEPTHKP + getline(lineStream, data_s, ','); // SEDEPTHKPUPPER + getline(lineStream, data_s, ','); // SEDEPTHKPLOWER + getline(lineStream, data_s, ','); // USEDEPTHKP + getline(lineStream, data_s, ','); // SEDEPTHKPREF + getline(lineStream, data_s, ','); // SEDEPTHKPURL + getline(lineStream, data_s, ','); // SEDEPTH36 + getline(lineStream, data_s, ','); // SEDEPTH36UPPER + getline(lineStream, data_s, ','); // SEDEPTH36LOWER + getline(lineStream, data_s, ','); // USEDEPTH36 + getline(lineStream, data_s, ','); // SEDEPTH36REFx + getline(lineStream, data_s, ','); // SEDEPTH36URLx + getline(lineStream, data_s, ','); // SEDEPTH45 + getline(lineStream, data_s, ','); // SEDEPTH45UPPER + getline(lineStream, data_s, ','); // SEDEPTH45LOWER + getline(lineStream, data_s, ','); // USEDEPTH45 + getline(lineStream, data_s, ','); // SEDEPTH45REF + getline(lineStream, data_s, ','); // SEDEPTH45URL + getline(lineStream, data_s, ','); // SEDEPTH58 + getline(lineStream, data_s, ','); // SEDEPTH58UPPER + getline(lineStream, data_s, ','); // SEDEPTH58LOWER + getline(lineStream, data_s, ','); // USEDEPTH58 + getline(lineStream, data_s, ','); // EDEPTH58REF + getline(lineStream, data_s, ','); // SEDEPTH58URL + getline(lineStream, data_s, ','); // SEDEPTH80 + getline(lineStream, data_s, ','); // SEDEPTH80UPPER + getline(lineStream, data_s, ','); // SEDEPTH80LOWER + getline(lineStream, data_s, ','); // USEDEPTH80 + getline(lineStream, data_s, ','); // SEDEPTH80REF + getline(lineStream, data_s, ','); // SEDEPTH80URL + getline(lineStream, data_s, ','); // SEP + getline(lineStream, data_s, ','); // SEPUPPER + getline(lineStream, data_s, ','); // SEPLOWER + getline(lineStream, data_s, ','); // USEP + getline(lineStream, data_s, ','); // SEPREF + getline(lineStream, data_s, ','); // SEPURL + getline(lineStream, data_s, ','); // SET + getline(lineStream, data_s, ','); // SETUPPER + getline(lineStream, data_s, ','); // SETLOWER + getline(lineStream, data_s, ','); // USET + getline(lineStream, data_s, ','); // SETREF + getline(lineStream, data_s, ','); // SETURL + getline(lineStream, data_s, ','); // SHK + getline(lineStream, data_s, ','); // SIMBADNAME + getline(lineStream, data_s, ','); // SIMBADURL + getline(lineStream, data_s, ','); // SPECREF + getline(lineStream, data_s, ','); // SPECURL + getline(lineStream, data_s, ','); // STAR + std::string speckStarname = getExplName(data_s); glm::vec3 pos = getStarPosition(speckStarname); - p.POSITIONX = pos[0]; - p.POSITIONY = pos[1]; - p.POSITIONZ = pos[2]; + p.POSITIONX = pos[0]; + p.POSITIONY = pos[1]; + p.POSITIONZ = pos[2]; - getline(lineStream, data_s, ','); // STARDISCMETH - getline(lineStream, data_s, ','); // T0 - getline(lineStream, data_s, ','); // T0UPPER - getline(lineStream, data_s, ','); // T0LOWER - getline(lineStream, data_s, ','); // UT0 - getline(lineStream, data_s, ','); // T0REF - getline(lineStream, data_s, ','); // T0URL - getline(lineStream, data_s, ','); // T14 - getline(lineStream, data_s, ','); // T14UPPER - getline(lineStream, data_s, ','); // T14LOWER - getline(lineStream, data_s, ','); // UT14 - getline(lineStream, data_s, ','); // T14REF - getline(lineStream, data_s, ','); // T14URL - getline(lineStream, data_s, ','); // TEFF + getline(lineStream, data_s, ','); // STARDISCMETH + getline(lineStream, data_s, ','); // T0 + getline(lineStream, data_s, ','); // T0UPPER + getline(lineStream, data_s, ','); // T0LOWER + getline(lineStream, data_s, ','); // UT0 + getline(lineStream, data_s, ','); // T0REF + getline(lineStream, data_s, ','); // T0URL + getline(lineStream, data_s, ','); // T14 + getline(lineStream, data_s, ','); // T14UPPER + getline(lineStream, data_s, ','); // T14LOWER + getline(lineStream, data_s, ','); // UT14 + getline(lineStream, data_s, ','); // T14REF + getline(lineStream, data_s, ','); // T14URL + getline(lineStream, data_s, ','); // TEFF float teff; - if (!data_s.empty()) - teff = std::stof(data_s.c_str(), nullptr); - else - teff = NAN; + if (!data_s.empty()) + teff = std::stof(data_s.c_str(), nullptr); + else + teff = NAN; - getline(lineStream, data_s, ','); // TEFFUPPER - getline(lineStream, data_s, ','); // TEFFLOWER - getline(lineStream, data_s, ','); // UTEFF - getline(lineStream, data_s, ','); // TEFFREF - getline(lineStream, data_s, ','); // TEFFURL - getline(lineStream, data_s, ','); // TIMING - getline(lineStream, data_s, ','); // TRANSIT - getline(lineStream, data_s, ','); // TRANSITREF - getline(lineStream, data_s, ','); // TRANSITURL - getline(lineStream, data_s, ','); // TREND - getline(lineStream, data_s, ','); // TT - if (!data_s.empty()) - p.TT = std::stod(data_s.c_str(), nullptr); - else - p.TT = NAN; + getline(lineStream, data_s, ','); // TEFFUPPER + getline(lineStream, data_s, ','); // TEFFLOWER + getline(lineStream, data_s, ','); // UTEFF + getline(lineStream, data_s, ','); // TEFFREF + getline(lineStream, data_s, ','); // TEFFURL + getline(lineStream, data_s, ','); // TIMING + getline(lineStream, data_s, ','); // TRANSIT + getline(lineStream, data_s, ','); // TRANSITREF + getline(lineStream, data_s, ','); // TRANSITURL + getline(lineStream, data_s, ','); // TREND + getline(lineStream, data_s, ','); // TT + if (!data_s.empty()) + p.TT = std::stod(data_s.c_str(), nullptr); + else + p.TT = NAN; - getline(lineStream, data_s, ','); // TTUPPER - if (!data_s.empty()) - p.TTUPPER = std::stof(data_s.c_str(), nullptr); - else - p.TTUPPER = NAN; + getline(lineStream, data_s, ','); // TTUPPER + if (!data_s.empty()) + p.TTUPPER = std::stof(data_s.c_str(), nullptr); + else + p.TTUPPER = NAN; - getline(lineStream, data_s, ','); // TTLOWER - if (!data_s.empty()) - p.TTLOWER = std::stof(data_s.c_str(), nullptr); - else - p.TTLOWER = NAN; + getline(lineStream, data_s, ','); // TTLOWER + if (!data_s.empty()) + p.TTLOWER = std::stof(data_s.c_str(), nullptr); + else + p.TTLOWER = NAN; - getline(lineStream, data_s, ','); // UTT - if (!data_s.empty()) - p.UTT = std::stof(data_s.c_str(), nullptr); - else - p.UTT = NAN; + getline(lineStream, data_s, ','); // UTT + if (!data_s.empty()) + p.UTT = std::stof(data_s.c_str(), nullptr); + else + p.UTT = NAN; - getline(lineStream, data_s, ','); // TTREF - getline(lineStream, data_s, ','); // TTURL - getline(lineStream, data_s, ','); // V - getline(lineStream, data_s, ','); // VREF - getline(lineStream, data_s, ','); // VURL - getline(lineStream, data_s, ','); // VSINI - getline(lineStream, data_s, ','); // VSINIUPPER - getline(lineStream, data_s, ','); // VSINILOWER - getline(lineStream, data_s, ','); // UVSINI - getline(lineStream, data_s, ','); // VSINIREF - getline(lineStream, data_s, ','); // VSINIURL - getline(lineStream, data_s, ','); // KEPID - if (!data_s.empty()) - iskeplerobject = true; - getline(lineStream, data_s); // KDE - - if (!iskeplerobject) { + getline(lineStream, data_s, ','); // TTREF + getline(lineStream, data_s, ','); // TTURL + getline(lineStream, data_s, ','); // V + getline(lineStream, data_s, ','); // VREF + getline(lineStream, data_s, ','); // VURL + getline(lineStream, data_s, ','); // VSINI + getline(lineStream, data_s, ','); // VSINIUPPER + getline(lineStream, data_s, ','); // VSINILOWER + getline(lineStream, data_s, ','); // UVSINI + getline(lineStream, data_s, ','); // VSINIREF + getline(lineStream, data_s, ','); // VSINIURL + getline(lineStream, data_s, ','); // KEPID + if (!data_s.empty()) + iskeplerobject = true; + getline(lineStream, data_s); // KDE + if (!iskeplerobject) { // calculate B-V from Teff if not exsisting - if (std::isnan(p.BMV) ) - { - if (!std::isnan(teff)) - { - + if (std::isnan(p.BMV)) { + if (!std::isnan(teff)) { float teff_current, teff_upper, teff_lower, BV, bv_upper, bv_lower = 0; std::ifstream teff_bv(absPath("${BASE}/modules/exoplanets/teff_bv.txt")); @@ -787,46 +777,41 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb teff_current= std::stof(teff_string.c_str(), nullptr); - if (teff > teff_current) - { + if (teff > teff_current) { teff_lower = teff_current; bv_lower = std::stof(bv_string.c_str(), nullptr); } - else - { - + else { teff_upper = teff_current; bv_upper = std::stof(bv_string.c_str(), nullptr); - if (bv_lower == 0) - { + if (bv_lower == 0) { BV = 2.00; } - else + else { BV = (((bv_upper - bv_lower)*(teff - teff_lower)) / (teff_upper - teff_lower)) + bv_lower; - + } break; } } teff_bv.close(); p.BMV = BV; - } - else + else { p.BMV = NAN; + } } - long pos = bin_file.tellp(); + long pos = bin_file.tellp(); planetname = speckStarname + " " + component; - lut_file << planetname << "," << pos << std::endl; - bin_file.write((char *)&p, sizeof(struct Exoplanet)); + lut_file << planetname << "," << pos << std::endl; + bin_file.write((char *)&p, sizeof(struct Exoplanet)); + } + } - } - } - - csv_file.close(); - bin_file.close(); - lut_file.close(); + csv_file.close(); + bin_file.close(); + lut_file.close(); progressCallback(1.0f); } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index b6f6a83b68..4a2c7bb302 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -50,48 +50,48 @@ private: glm::vec3 getStarPosition(std::string starName); struct Exoplanet { - float A; - double AUPPER; - double ALOWER; - double UA; - float BIGOM; - float BIGOMUPPER; - float BIGOMLOWER; - float UBIGOM; - int BINARY; // **one or more stars** + float A; + double AUPPER; + double ALOWER; + double UA; + float BIGOM; + float BIGOMUPPER; + float BIGOMLOWER; + float UBIGOM; + int BINARY; // **one or more stars** float BMV; - float ECC; - float ECCUPPER; - float ECCLOWER; - float UECC; - float I; - float IUPPER; - float ILOWER; - float UI; - int NCOMP; // **number of planets** - float OM; - float OMUPPER; - float OMLOWER; - float UOM; - double PER; - float PERUPPER; - float PERLOWER; - float UPER; - double R; - double RUPPER; - double RLOWER; - double UR; - float RSTAR; - float RSTARUPPER; - float RSTARLOWER; - float URSTAR; - double TT; - float TTUPPER; - float TTLOWER; - float UTT; - float POSITIONX; - float POSITIONY; - float POSITIONZ; + float ECC; + float ECCUPPER; + float ECCLOWER; + float UECC; + float I; + float IUPPER; + float ILOWER; + float UI; + int NCOMP; // **number of planets** + float OM; + float OMUPPER; + float OMLOWER; + float UOM; + double PER; + float PERUPPER; + float PERLOWER; + float UPER; + double R; + double RUPPER; + double RLOWER; + double UR; + float RSTAR; + float RSTARUPPER; + float RSTARLOWER; + float URSTAR; + double TT; + float TTUPPER; + float TTLOWER; + float UTT; + float POSITIONX; + float POSITIONY; + float POSITIONZ; }; }; From 9e5251630aff80ea12f0ee01e58305e867e29241 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 16:57:41 +0200 Subject: [PATCH 076/123] Clean up code and get it to run (using correct data files) --- modules/exoplanets/CMakeLists.txt | 9 +- .../discoverymethods/discoverymethods.cpp | 981 ++++++++-------- modules/exoplanets/exoplanetsmodule.cpp | 122 +- modules/exoplanets/exoplanetsmodule.h | 26 +- modules/exoplanets/exoplanetsmodule_lua.inl | 713 ++++++------ .../rendering/renderableorbitdisc.cpp | 46 +- .../rendering/renderableorbitdisc.h | 10 +- modules/exoplanets/shaders/orbitdisc_fs.glsl | 53 +- modules/exoplanets/shaders/orbitdisc_vs.glsl | 4 +- .../tasks/exoplanetscsvtobintask.cpp | 1022 ++++++++--------- .../exoplanets/tasks/exoplanetscsvtobintask.h | 19 +- 11 files changed, 1458 insertions(+), 1547 deletions(-) diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 8fb5dc0ae9..41c41a7d7f 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -26,17 +26,18 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h - ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.h + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h + ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h ) source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule_lua.inl ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp index 456606a204..81bfecdbd8 100644 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ b/modules/exoplanets/discoverymethods/discoverymethods.cpp @@ -64,525 +64,524 @@ namespace { namespace openspace::exoplanets { - void DiscoveryMethods::addDirectionsMarkers(glm::dvec3 viewDirecionPos, glm::dvec3 northDirectionPos, float starRadius) { - const std::string markerView = "{" - "Identifier = 'markerView'," - "Parent = 'SolarSystemBarycenter'," - "Enabled = true," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadius) + "* 0.5," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'dir'," - "Type = 'SolidColor'," - "BlendMode = 'Normal'," - "Color = {1.0,0.0,0.0}," - "Enabled = true" - "}," - "}" +void DiscoveryMethods::addDirectionsMarkers(glm::dvec3 viewDirecionPos, glm::dvec3 northDirectionPos, float starRadius) { + const std::string markerView = "{" + "Identifier = 'markerView'," + "Parent = 'SolarSystemBarycenter'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(starRadius) + "* 0.5," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'dir'," + "Type = 'SolidColor'," + "BlendMode = 'Normal'," + "Color = {1.0,0.0,0.0}," + "Enabled = true" + "}," "}" + "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + ghoul::to_string(viewDirecionPos) + "," "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(viewDirecionPos) + "," - "}," - "}," - "}"; - std::string script = "openspace.addSceneGraphNode(" + markerView + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - const std::string markerNorth = "{" - "Identifier = 'markerNorth'," - "Parent = 'SolarSystemBarycenter'," - "Enabled = true," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadius) + "* 0.5," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'dir'," - "Type = 'SolidColor'," - "BlendMode = 'Normal'," - "Color = {0.0,0.0,1.0}," - "Enabled = true" - "}," - "}" + "}," + "}"; + std::string script = "openspace.addSceneGraphNode(" + markerView + ");"; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + const std::string markerNorth = "{" + "Identifier = 'markerNorth'," + "Parent = 'SolarSystemBarycenter'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(starRadius) + "* 0.5," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'dir'," + "Type = 'SolidColor'," + "BlendMode = 'Normal'," + "Color = {0.0,0.0,1.0}," + "Enabled = true" + "}," "}" + "}" + "}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + ghoul::to_string(northDirectionPos) + "," "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(northDirectionPos) + "," - "}," + "}," + "}"; + script = ""; + script = "openspace.addSceneGraphNode(" + markerNorth + ");"; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} +void DiscoveryMethods::removeDirectionsMarkers() { + std::string script = "openspace.removeSceneGraphNode('markerView'); openspace.removeSceneGraphNode('markerNorth');"; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +float DiscoveryMethods::getTransitScaleFactor() { + return _transitScaleFactor; +} + +void addDopplerGraphs() { + std::string script = + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'DopplerShift2'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/stripes2.png')," + "EuclideanPosition = {0.0, -0.7}" + "});" + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'DopplerShift1'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/spectrum.jpg')," + "EuclideanPosition = {0.0, -0.7}" + "});"; + + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void addTransitGraphs() { + std::string script = + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'Transit2'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/prick.png')," + "EuclideanPosition = {0.0, 0.0}," + "});" + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'Transit1'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/graph.png')," + "Scale = 0.485," + "EuclideanPosition = {0.0, -0.65}" + "});" + "openspace.addScreenSpaceRenderable(" + "{" + "Identifier = 'Transit3'," + "Type = 'ScreenSpaceImageLocal'," + "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/axes.png')," + "Scale = 0.7," + "EuclideanPosition = {-0.05, -0.65}" + "});"; + + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { + std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { + std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void DiscoveryMethods::toggleVisabilityOuterPlanets(std::vector planetNames, std::string visability) { + std::vector planets = global::moduleEngine.module()->planetSystem(); + + if (planetNames.size()>1) + { + //keeping first planet in the list, wich dosn't neccesarily mean the closest one... + for (size_t i = 1; i < planetNames.size(); i++) { + std::string script = ""; + //remove planetglobe + if (!isnan(planets[i].R)) { + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".RenderableGlobe.Enabled', " + visability + "); "; + } + //remove trail + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; + //remove disc + if (!isnan(planets[i].AUPPER) && !isnan(planets[i].ALOWER)) { + script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Disc.renderable.Enabled', " + visability + "); "; + } + + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + } + } +} + +void DiscoveryMethods::toggleVisabilityPlanet(std::string nodeName, std::string visability) { + std::string script = "openspace.setPropertyValueSingle( 'Scene." +nodeName + ".RenderableGlobe.Enabled', " + visability + "); "; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void DiscoveryMethods::moveCamera(glm::dvec3 pos) { + Camera* cam = global::navigationHandler.camera(); + cam->setPositionVec3(pos); + global::navigationHandler.resetCameraDirection(); +} + +bool DiscoveryMethods::isDoppler() { + return _showDoppler; +} +bool DiscoveryMethods::isTransit() { + return _showTransit; +} +bool DiscoveryMethods::isReference() { + return _showSolarSystemReference; +} + +void DiscoveryMethods::setDopplerImagePos(float value) { + std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void DiscoveryMethods::setTransitImagePos(float valueX,float valueY) { + std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.Transit2.EuclideanPosition', {" + std::to_string(valueX) + "," + std::to_string(valueY) + "}); "; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +void DiscoveryMethods::addDopplerMethodVisualization() { + const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); + std::string starName = global::moduleEngine.module()->getStarName(); // getStarName + glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); + std::vector planets = global::moduleEngine.module()->planetSystem(); + std::vector planetNames = global::moduleEngine.module()->planetNames(); + + float semiMajorAxis = planets[0].A; // in AU + float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis + float eccentricity = planets[0].ECC; + if (isnan(planets[0].ECC)) { + eccentricity = 0.0; + } + float starRadius = planets[0].RSTAR; // in Solar Radii + + glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); + + // MOVE CAMERA + glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); + glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * faceOnVector); + moveCamera(cameraPosition); + // END CAMERA + + // SCALE STAR AND PLANET + float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU + periapsisDistance *= 149597870700.0; // in m + starRadius *= 6.957E8; // in m + float scale = (0.2 * periapsisDistance) / starRadius; + scaleNode(starName + "Globe", scale); + scaleNode(planetNames[0], scale); // using planetNames[0] because i know that will be the one visible after removing outer planets + // END SCALE + + // MOVE STAR + starSemiMajorAxis *= 149597871.0; // in km + moveStar(starName, starSemiMajorAxis); + + // SHOW ONE PLANET + // for planets found with doppler method, the radius is not always known. + //so this "fake" planet is shown for the sake of the vizualisation + toggleVisabilityPlanet(planetNames[0], "true"); + + // HIDE THE REST OF THE PLANETS + // in some cases there are multiple planets in the system, but for the viz only one can be shown + toggleVisabilityOuterPlanets(planetNames, "false"); + + // SHOW GRAPHS + addDopplerGraphs(); + + + // HELPER MARKERS + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); + glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); + //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); + // END MARKERS +} + +void DiscoveryMethods::removeDopplerMethodVisualization() { + std::string starName = global::moduleEngine.module()->getStarName(); + std::vector planetNames = global::moduleEngine.module()->planetNames(); + std::vector planets = global::moduleEngine.module()->planetSystem(); + + //SCALE STAR AND PLANET + scaleNode(starName + "Globe", 1.0); + scaleNode(planetNames[0], 1.0); + + // MOVE STAR + moveStar(starName, 0.0); + + //HIDE THE PLANET (if it was hidden from the start) + if (isnan(planets[0].R)) { + toggleVisabilityPlanet(planetNames[0], "false"); + } + + // SHOW THE REST OF THE PLANETS + toggleVisabilityOuterPlanets(planetNames, "true"); + + // HIDE GRAPHS + std::string script = "openspace.removeScreenSpaceRenderable('DopplerShift1'); openspace.removeScreenSpaceRenderable('DopplerShift2');"; + global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + //REMOVE HELP MARKERS + //removeDirectionsMarkers(); +} + +void DiscoveryMethods::addTransitMethodVisualization() { + const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); + std::string starName = global::moduleEngine.module()->getStarName(); // getStarName + glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); + std::vector planets = global::moduleEngine.module()->planetSystem(); + std::vector planetNames = global::moduleEngine.module()->planetNames(); + + float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) + float eccentricity = planets[0].ECC; + if (isnan(planets[0].ECC)) { + eccentricity = 0.0; + } + float starRadius = planets[0].RSTAR; // in Solar Radii + + // MOVE CAMERA + //borde kanske va periapsis distance, men det gÃ¥r bra ändÃ¥ + glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); + //glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); + glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * starToSunVec); + //glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * faceOnVector); + + moveCamera(cameraPosition); + // END CAMERA + toggleVisabilityPlanet(planetNames[0], "true"); + + // SCALE BOTH STAR AND PLANET + // want star to take up 2/3 of the radius, the radius is as smallest at the periapsis + float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU + periapsisDistance *= 149597870700.0; // in m + starRadius *= 6.957E8; // in m + + float scale = (0.5 * periapsisDistance) / starRadius; // actual radius * scale = wanted radius + scaleNode(starName + "Globe", scale); + scaleNode(planetNames[0], scale); //eller använda getPlna()? + _transitScaleFactor = scale; + // END SCALE + + // ADD THE GRAPH + addTransitGraphs(); + // END GRAPH + + // HELPER MARKERS + + glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); + glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); + //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); + // END MARKERS +} + +void DiscoveryMethods::removeTransitMethodVisualization() { + std::vector planetNames = global::moduleEngine.module()->planetNames(); + //SCALE STAR AND PLANET + std::string starName = global::moduleEngine.module()->getStarName(); + scaleNode(starName + "Globe", 1); + scaleNode(planetNames[0], 1); + + // REMOVE GRAPH + std::string script = "openspace.removeScreenSpaceRenderable('Transit3');" + "openspace.removeScreenSpaceRenderable('Transit2');" + "openspace.removeScreenSpaceRenderable('Transit1');"; + + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + //REMOVE HELP MARKERS + //removeDirectionsMarkers(); +} + +void DiscoveryMethods::addSolarSystemReferenceVisualization() { + std::string starName = global::moduleEngine.module()->getStarName(); + std::vector planets = global::moduleEngine.module()->planetSystem(); + std::vector planetNames = global::moduleEngine.module()->planetNames(); + + // SUN + const std::string sunRef = "{" + "Identifier = 'SunReference'," + "Parent = '" + starName + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m + "Billboard = true," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," + "BlendMode = 'Additive'" + "}," + "Transform = {" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {0, 0, 0}," //"+ std::to_string(planets[0].RSTAR) + "* 6.957E8 "}," - "}"; - script = ""; - script = "openspace.addSceneGraphNode(" + markerNorth + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - void DiscoveryMethods::removeDirectionsMarkers() { - std::string script = "openspace.removeSceneGraphNode('markerView'); openspace.removeSceneGraphNode('markerNorth');"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - float DiscoveryMethods::getTransitScaleFactor() { - return _transitScaleFactor; - } - - void addDopplerGraphs() { - std::string script = - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'DopplerShift2'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/stripes2.png')," - "EuclideanPosition = {0.0, -0.7}" - "});" - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'DopplerShift1'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/spectrum.jpg')," - "EuclideanPosition = {0.0, -0.7}" - "});"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void addTransitGraphs() { - std::string script = - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'Transit2'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/prick.png')," - "EuclideanPosition = {0.0, 0.0}," - "});" - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'Transit1'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/graph.png')," - "Scale = 0.485," - "EuclideanPosition = {0.0, -0.65}" - "});" - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'Transit3'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/axes.png')," - "Scale = 0.7," - "EuclideanPosition = {-0.05, -0.65}" - "});"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { - std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { - std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void DiscoveryMethods::toggleVisabilityOuterPlanets(std::vector planetNames, std::string visability) { - std::vector planets = global::moduleEngine.module()->getPlsy(); - - if (planetNames.size()>1) - { - //keeping first planet in the list, wich dosn't neccesarily mean the closest one... - for (size_t i = 1; i < planetNames.size(); i++) { - std::string script = ""; - //remove planetglobe - if (!isnan(planets[i].R)) { - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".RenderableGlobe.Enabled', " + visability + "); "; - } - //remove trail - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; - //remove disc - if (!isnan(planets[i].AUPPER) && !isnan(planets[i].ALOWER)) { - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Disc.renderable.Enabled', " + visability + "); "; - } - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - } - } - - void DiscoveryMethods::toggleVisabilityPlanet(std::string nodeName, std::string visability) { - std::string script = "openspace.setPropertyValueSingle( 'Scene." +nodeName + ".RenderableGlobe.Enabled', " + visability + "); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void DiscoveryMethods::moveCamera(glm::dvec3 pos) { - Camera* cam = global::navigationHandler.camera(); - cam->setPositionVec3(pos); - global::navigationHandler.resetCameraDirection(); - } - - bool DiscoveryMethods::isDoppler() { - return _showDoppler; - } - bool DiscoveryMethods::isTransit() { - return _showTransit; - } - bool DiscoveryMethods::isReference() { - return _showSolarSystemReference; - } - - void DiscoveryMethods::setDopplerImagePos(float value) { - std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void DiscoveryMethods::setTransitImagePos(float valueX,float valueY) { - std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.Transit2.EuclideanPosition', {" + std::to_string(valueX) + "," + std::to_string(valueY) + "}); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - void DiscoveryMethods::addDopplerMethodVisualization() { - const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); - std::string starName = global::moduleEngine.module()->getStarName(); // getStarName - glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = global::moduleEngine.module()->getPlsy(); - std::vector planetNames = global::moduleEngine.module()->getPlna(); - - float semiMajorAxis = planets[0].A; // in AU - float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis - float eccentricity = planets[0].ECC; - if (isnan(planets[0].ECC)) { - eccentricity = 0.0; - } - float starRadius = planets[0].RSTAR; // in Solar Radii - - glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); - - // MOVE CAMERA - glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); - glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * faceOnVector); - moveCamera(cameraPosition); - // END CAMERA - - // SCALE STAR AND PLANET - float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU - periapsisDistance *= 149597870700.0; // in m - starRadius *= 6.957E8; // in m - float scale = (0.2 * periapsisDistance) / starRadius; - scaleNode(starName + "Globe", scale); - scaleNode(planetNames[0], scale); // using planetNames[0] because i know that will be the one visible after removing outer planets - // END SCALE - - // MOVE STAR - starSemiMajorAxis *= 149597871.0; // in km - moveStar(starName, starSemiMajorAxis); - - // SHOW ONE PLANET - // for planets found with doppler method, the radius is not always known. - //so this "fake" planet is shown for the sake of the vizualisation - toggleVisabilityPlanet(planetNames[0], "true"); - - // HIDE THE REST OF THE PLANETS - // in some cases there are multiple planets in the system, but for the viz only one can be shown - toggleVisabilityOuterPlanets(planetNames, "false"); - - // SHOW GRAPHS - addDopplerGraphs(); - - - // HELPER MARKERS - glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); - glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); - //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); - // END MARKERS - } - - void DiscoveryMethods::removeDopplerMethodVisualization() { - std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planetNames = global::moduleEngine.module()->getPlna(); - std::vector planets = global::moduleEngine.module()->getPlsy(); - - //SCALE STAR AND PLANET - scaleNode(starName + "Globe", 1.0); - scaleNode(planetNames[0], 1.0); - - // MOVE STAR - moveStar(starName, 0.0); - - //HIDE THE PLANET (if it was hidden from the start) - if (isnan(planets[0].R)) { - toggleVisabilityPlanet(planetNames[0], "false"); - } + "}," + "}"; - // SHOW THE REST OF THE PLANETS - toggleVisabilityOuterPlanets(planetNames, "true"); + std::string script = "openspace.addSceneGraphNode(" + sunRef + ");"; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); - // HIDE GRAPHS - std::string script = "openspace.removeScreenSpaceRenderable('DopplerShift1'); openspace.removeScreenSpaceRenderable('DopplerShift2');"; - global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - //REMOVE HELP MARKERS - //removeDirectionsMarkers(); - } - - void DiscoveryMethods::addTransitMethodVisualization() { - const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); - std::string starName = global::moduleEngine.module()->getStarName(); // getStarName - glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = global::moduleEngine.module()->getPlsy(); - std::vector planetNames = global::moduleEngine.module()->getPlna(); - - float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) - float eccentricity = planets[0].ECC; - if (isnan(planets[0].ECC)) { - eccentricity = 0.0; - } - float starRadius = planets[0].RSTAR; // in Solar Radii - - // MOVE CAMERA - //borde kanske va periapsis distance, men det gÃ¥r bra ändÃ¥ - glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); - //glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); - glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * starToSunVec); - //glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * faceOnVector); - - moveCamera(cameraPosition); - // END CAMERA - toggleVisabilityPlanet(planetNames[0], "true"); - - // SCALE BOTH STAR AND PLANET - // want star to take up 2/3 of the radius, the radius is as smallest at the periapsis - float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU - periapsisDistance *= 149597870700.0; // in m - starRadius *= 6.957E8; // in m - - float scale = (0.5 * periapsisDistance) / starRadius; // actual radius * scale = wanted radius - scaleNode(starName + "Globe", scale); - scaleNode(planetNames[0], scale); //eller använda getPlna()? - _transitScaleFactor = scale; - // END SCALE - - // ADD THE GRAPH - addTransitGraphs(); - // END GRAPH - - // HELPER MARKERS - - glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); - glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); - //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); - // END MARKERS - } - - void DiscoveryMethods::removeTransitMethodVisualization() { - std::vector planetNames = global::moduleEngine.module()->getPlna(); - //SCALE STAR AND PLANET - std::string starName = global::moduleEngine.module()->getStarName(); - scaleNode(starName + "Globe", 1); - scaleNode(planetNames[0], 1); - - // REMOVE GRAPH - std::string script = "openspace.removeScreenSpaceRenderable('Transit3');" - "openspace.removeScreenSpaceRenderable('Transit2');" - "openspace.removeScreenSpaceRenderable('Transit1');"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - //REMOVE HELP MARKERS - //removeDirectionsMarkers(); - } - - void DiscoveryMethods::addSolarSystemReferenceVisualization() { - std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planets = global::moduleEngine.module()->getPlsy(); - std::vector planetNames = global::moduleEngine.module()->getPlna(); - - // SUN - const std::string sunRef = "{" - "Identifier = 'SunReference'," - "Parent = '" + starName + "'," + // EARTH + for (int i = 0; i < planetNames.size(); i++) + { + const std::string earthRef = "{" + "Identifier = 'EarthReference" + std::to_string(i) + "'," + "Parent = '" + planetNames[i] + "'," "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," - "BlendMode = 'Additive'" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {0, 0, 0}," //"+ std::to_string(planets[0].RSTAR) + "* 6.957E8 - "}," - "}," - "}"; - - std::string script = "openspace.addSceneGraphNode(" + sunRef + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - // EARTH - for (int i = 0; i < planetNames.size(); i++) - { - const std::string earthRef = "{" - "Identifier = 'EarthReference" + std::to_string(i) + "'," - "Parent = '" + planetNames[i] + "'," - "Renderable = {" "Type = 'RenderablePlaneImageLocal'," "Size = 6378137," // in meters "Billboard = true," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," "BlendMode = 'Additive'" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {0, 0, 0}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 - "}," - "}," - "}"; - script = ""; - script = "openspace.addSceneGraphNode(" + earthRef + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - glm::dmat3 rotation = global::moduleEngine.module()->getRotation(); - - // ORBIT - const std::string orbitRef = "{" - "Identifier = 'OrbitReference'," - "Parent = '" + starName + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = 1.496E11," // earths semi-major axis in m - "Billboard = false," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," - "BlendMode = 'Additive'" "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rotation) + "," - "}" + "Translation = {" + "Type = 'StaticTranslation'," + "Position = {0, 0, 0}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 + "}," "}," "}"; script = ""; - script = "openspace.addSceneGraphNode(" + orbitRef + ");"; + script = "openspace.addSceneGraphNode(" + earthRef + ");"; openspace::global::scriptEngine.queueScript( script, openspace::scripting::ScriptEngine::RemoteScripting::Yes ); } - void DiscoveryMethods::removeSolarSystemReferenceVisualization() { - std::string script = "openspace.removeSceneGraphNode('SunReference');" - "openspace.removeSceneGraphNode('EarthReference');" - "openspace.removeSceneGraphNode('OrbitReference');"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } + glm::dmat3 rotation = global::moduleEngine.module()->getRotation(); - DiscoveryMethods::DiscoveryMethods() - : PropertyOwner({ "DiscoveryMethods" }) - , _showTransit(TransitMethodInfo, false) - , _showDoppler(DopplerMethodInfo, false) - , _showSolarSystemReference(SolarSystemReferenceInfo, false) - { - _showTransit.onChange([&]() { - if (_showTransit) //just changed to true - { - if (_showDoppler) { //only one viz at the time - _showDoppler = false; - removeDopplerMethodVisualization(); - } - addTransitMethodVisualization(); - } - else { //just changed to false - removeTransitMethodVisualization(); - } - - }); - addProperty(_showTransit); + // ORBIT + const std::string orbitRef = "{" + "Identifier = 'OrbitReference'," + "Parent = '" + starName + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = 1.496E11," // earths semi-major axis in m + "Billboard = false," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," + "BlendMode = 'Additive'" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + ghoul::to_string(rotation) + "," + "}" + "}," + "}"; + script = ""; + script = "openspace.addSceneGraphNode(" + orbitRef + ");"; + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} - _showDoppler.onChange([&]() { - if (_showDoppler) //just changed to true - { - if (_showTransit) { - _showTransit = false; - removeTransitMethodVisualization(); - } - addDopplerMethodVisualization(); - } - else { //just changed to false +void DiscoveryMethods::removeSolarSystemReferenceVisualization() { + std::string script = "openspace.removeSceneGraphNode('SunReference');" + "openspace.removeSceneGraphNode('EarthReference');" + "openspace.removeSceneGraphNode('OrbitReference');"; + + openspace::global::scriptEngine.queueScript( + script, + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); +} + +DiscoveryMethods::DiscoveryMethods() + : PropertyOwner({ "DiscoveryMethods" }) + , _showTransit(TransitMethodInfo, false) + , _showDoppler(DopplerMethodInfo, false) + , _showSolarSystemReference(SolarSystemReferenceInfo, false) +{ + _showTransit.onChange([&]() { + if (_showTransit) { //just changed to true + if (_showDoppler) { //only one viz at the time + _showDoppler = false; removeDopplerMethodVisualization(); } - }); - addProperty(_showDoppler); + addTransitMethodVisualization(); + } + else { //just changed to false + removeTransitMethodVisualization(); + } + }); + addProperty(_showTransit); - _showSolarSystemReference.onChange([&]() { - if (_showSolarSystemReference) { - addSolarSystemReferenceVisualization(); + _showDoppler.onChange([&]() { + if (_showDoppler) { //just changed to true + if (_showTransit) { + _showTransit = false; + removeTransitMethodVisualization(); } - else { - removeSolarSystemReferenceVisualization(); - } - }); - addProperty(_showSolarSystemReference); - } + addDopplerMethodVisualization(); + } + else { //just changed to false + removeDopplerMethodVisualization(); + } + }); + addProperty(_showDoppler); + + _showSolarSystemReference.onChange([&]() { + if (_showSolarSystemReference) { + addSolarSystemReferenceVisualization(); + } + else { + removeSolarSystemReferenceVisualization(); + } + }); + addProperty(_showSolarSystemReference); +} + } // namespce diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index a9de21163e..43ecb92890 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -23,18 +23,16 @@ ****************************************************************************************/ #include -#include -#include +#include +#include #include #include - +#include #include #include #include #include -#include - #include #include @@ -49,42 +47,49 @@ using namespace exoplanets; ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} void ExoplanetsModule::setClosestExoplanet(Exoplanet closestExo) { - _exo = closestExo; + _exo = closestExo; } -Exoplanet ExoplanetsModule::getClosestExoplanet() { - return _exo; +Exoplanet ExoplanetsModule::closestExoplanet() { + return _exo; } void ExoplanetsModule::setStarName(std::string starName) { - _starName = starName; + _starName = starName; } std::string ExoplanetsModule::getStarName() { - return _starName; + return _starName; } -void ExoplanetsModule::setPlsy(std::vector plsy) { - _plsy = plsy; + +void ExoplanetsModule::setPlanetSystem(std::vector planets) { + _planetSystem = planets; } -std::vector ExoplanetsModule::getPlsy() { - return _plsy; + +std::vector ExoplanetsModule::planetSystem() { + return _planetSystem; } -void ExoplanetsModule::setPlna(std::vector plna) { - _plna = plna; + +void ExoplanetsModule::setPlanetNames(std::vector names) { + _planetNames = names; } -std::vector ExoplanetsModule::getPlna() { - return _plna; + +std::vector ExoplanetsModule::planetNames() { + return _planetNames; } void ExoplanetsModule::setRotation(glm::dmat3 rot) { _rotation = rot; } + glm::dmat3 ExoplanetsModule::getRotation() { return _rotation; } + void ExoplanetsModule::setNorthVector(glm::dvec3 vector) { _north = vector; } + glm::dvec3 ExoplanetsModule::getNorthVector() { return _north; } @@ -95,14 +100,14 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { res.functions = { { "addExoplanetSystem", - &addExoplanetSystem, + &exoplanets::luascriptfunctions::addExoplanetSystem, {}, "string", "Adds the nodes to the scene graph of the exoplanet system." }, { "removeExoplanetSystem", - &removeExoplanetSystem, + &exoplanets::luascriptfunctions::removeExoplanetSystem, {}, "string", "Removes the nodes from the scene graph of the exoplanet system." @@ -128,7 +133,7 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { global::callback::render.push_back([&]() { if (_discoveryMethods->isDoppler()) { std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planetNames = global::moduleEngine.module()->getPlna(); + std::vector planetNames = global::moduleEngine.module()->planetNames(); SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); glm::dvec3 planetPos = planetNode->worldPosition(); @@ -139,67 +144,66 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { glm::dvec3 northProjected = glm::normalize( glm::length(north) * glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec)) ); - float northAngle = glm::acos(glm::dot(starToPosVec, northProjected)) * 57.2957795; - float viewAngle = glm::acos(glm::dot(starToPosVec, starToSunVec)) * 57.2957795; + float northAngle = glm::acos(glm::dot(starToPosVec, northProjected)) * 57.2957795f; + float viewAngle = glm::acos(glm::dot(starToPosVec, starToSunVec)) * 57.2957795f; - float imagePos = 0; - if ( viewAngle <= 90.0 && northAngle <= 90.0) { - imagePos = viewAngle / -90.0; + float imagePos = 0.0f; + if ( viewAngle <= 90.f && northAngle <= 90.f) { + imagePos = viewAngle / -90.f; } - else if (viewAngle > 90.0 && northAngle <= 90.0) { - imagePos = (180.0 - viewAngle) / -90.0; + else if (viewAngle > 90.f && northAngle <= 90.f) { + imagePos = (180.f - viewAngle) / -90.f; } - else if (viewAngle > 90.0 && northAngle > 90.0) { - imagePos = (180.0 - viewAngle) / 90.0; + else if (viewAngle > 90.f && northAngle > 90.f) { + imagePos = (180.f - viewAngle) / 90.f; } - else if (viewAngle <= 90.0 && northAngle > 90.0) { - imagePos = viewAngle / 90.0; + else if (viewAngle <= 90.f && northAngle > 90.f) { + imagePos = viewAngle / 90.f; } - imagePos *= 0.01; + imagePos *= 0.01f; _discoveryMethods->setDopplerImagePos(imagePos); } if (_discoveryMethods->isTransit()) { std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planetNames = global::moduleEngine.module()->getPlna(); - SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); - SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); - glm::dvec3 planetPos = planetNode->worldPosition(); - glm::dvec3 starPos = starNode->worldPosition(); + std::vector planetNames = global::moduleEngine.module()->planetNames(); + const SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); + const SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); + glm::dvec3 planetPosition = planetNode->worldPosition(); + glm::dvec3 starPosition = starNode->worldPosition(); - glm::dvec3 starToPosVec = planetPos - starPos; - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPos); + glm::dvec3 starToPosVec = planetPosition - starPosition; + glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = global::moduleEngine.module()->getPlsy(); - float starRadius = planets[0].RSTAR * 6.957E8 * _discoveryMethods->getTransitScaleFactor(); // in m + std::vector planets = global::moduleEngine.module()->planetSystem(); + float starRadius = planets[0].RSTAR * 6.957E8f * _discoveryMethods->getTransitScaleFactor(); // in m - glm::dvec3 north = _north; - float northAngle = glm::acos(glm::dot(normalize(starToPosVec), north)) * 57.2957795; - float viewAngle = glm::acos(glm::dot(normalize(starToPosVec), starToSunVec)) * 57.2957795; + float northAngle = glm::acos(glm::dot(normalize(starToPosVec), _north)) * 57.2957795f; + float viewAngle = glm::acos(glm::dot(normalize(starToPosVec), starToSunVec)) * 57.2957795f; glm::dvec3 posVecProjected = starToPosVec - (((dot(starToPosVec, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec); - float l = glm::length(posVecProjected); //in m - float imageYPos = -0.60; + float l = static_cast(glm::length(posVecProjected)); //in m + float imageYPos = -0.6f; - if (l<(starRadius*0.82) && viewAngle <= 90.0) { - imageYPos = -0.80; + if (l < (starRadius * 0.82f) && viewAngle <= 90.f) { + imageYPos = -0.8f; } - float imageXPos = 0; - if (viewAngle <= 90.0 && northAngle <= 90.0) { - imageXPos = (viewAngle / 90.0) * 0.5; + float imageXPos = 0.f; + if (viewAngle <= 90.f && northAngle <= 90.f) { + imageXPos = (viewAngle / 90.f) * 0.5f; } - else if (viewAngle > 90.0 && northAngle <= 90.0) { - imageXPos = (viewAngle / 90.0) * 0.5; + else if (viewAngle > 90.f && northAngle <= 90.f) { + imageXPos = (viewAngle / 90.f) * 0.5f; } - else if (viewAngle > 90.0 && northAngle > 90.0) { - imageXPos = (viewAngle / 90.0) * -0.5; + else if (viewAngle > 90.f && northAngle > 90.f) { + imageXPos = (viewAngle / 90.f) * -0.5f; } - else if (viewAngle <= 90.0 && northAngle > 90.0) { - imageXPos = (viewAngle / 90.0) * -0.5; + else if (viewAngle <= 90.f && northAngle > 90.f) { + imageXPos = (viewAngle / 90.f) * -0.5f; } - imageXPos *= 0.5; + imageXPos *= 0.5f; _discoveryMethods->setTransitImagePos(imageXPos, imageYPos); } }); diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index e983502628..f62271ac3d 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -25,12 +25,9 @@ #ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ - - -#include -#include - #include +#include +#include namespace openspace { struct Exoplanet { @@ -90,16 +87,17 @@ public: std::vector documentations() const override; void setClosestExoplanet(Exoplanet); - Exoplanet getClosestExoplanet(); void setStarName(std::string); - std::string getStarName(); - void setPlsy(std::vector); - std::vector getPlsy(); - void setPlna(std::vector); - std::vector getPlna(); + void setPlanetSystem(std::vector); + void setPlanetNames(std::vector); void setRotation(glm::dmat3); - glm::dmat3 getRotation(); void setNorthVector(glm::dvec3); + + Exoplanet closestExoplanet(); + std::string getStarName(); + std::vector planetSystem(); + std::vector planetNames(); + glm::dmat3 getRotation(); glm::dvec3 getNorthVector(); protected: @@ -108,8 +106,8 @@ protected: Exoplanet _exo; std::string _starName; - std::vector _plsy; - std::vector _plna; + std::vector _planetSystem; + std::vector _planetNames; glm::dmat3 _rotation; glm::dvec3 _north; }; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index fb456a8095..fff404548d 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -22,37 +22,29 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include -#include #include +#include #include - +#include #include #include #include -#include #include #include - +#include #include #include #include -namespace openspace{ +namespace openspace::exoplanets::luascriptfunctions { -std::string getStarColor(float bv) { +std::string getStarColor(float bv, std::ifstream& colormap) { std::string colorString; - std::ifstream colormap(absPath("${MODULE_EXOPLANETS}/colorbv.cmap"), std::ios::in); - if (!colormap.good()) { - std::cout << "Failed to open colormap data file"; - } - int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); std::string color; - for (size_t i = 0; i < t + 12; i++) - { + for (size_t i = 0; i < t + 12; i++) { getline(colormap, color); } @@ -72,11 +64,8 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm: // Exoplanet defined inclination changed to be used as Kepler defined inclination const glm::dvec3 ascendingNodeAxisRot = rot * glm::dvec3(0.f, 0.f, 1.f); - //const glm::dvec3 ascendingNodeAxisRot = glm::dvec3(0.f, 0.f, 1.f); const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); - //const glm::dvec3 inclinationAxisRot = glm::dvec3(1.f, 0.f, 0.f ); const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); - //const glm::vec3 argPeriapsisAxisRot = glm::dvec3( 0.f, 0.f, 1.f ); /*const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; @@ -92,7 +81,6 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm: glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); return orbitPlaneRotation; - //return std::to_string(orbitPlaneRotation); } std::string getSpeckStarname(std::string csvName) { @@ -287,8 +275,7 @@ std::string getCsvStarname(std::string explName) { // so that x is pointing from star to the sun. // Modified from http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-find-the-rotation-between-2-vectors- glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { - - glm::quat rotInQuat; + glm::quat rotationQuat; //glm::dvec3 oldXVec = glm::dvec3(1.0, 0.0, 0.0); //parent nod x-vec //glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - end); @@ -299,13 +286,13 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { // special case when vectors in opposite directions: // there is no "ideal" rotation axis // So guess one; any will do as long as it's perpendicular to startvector(oldXVec) - rotationAxis = cross(glm::dvec3(0.0f, 0.0f, 1.0f), start); + rotationAxis = cross(glm::dvec3(0.0, 0.0, 1.0), start); if (length2(rotationAxis) < 0.01) // bad luck, they were parallel, try again! - rotationAxis = cross(glm::dvec3(1.0f, 0.0f, 0.0f), start); + rotationAxis = cross(glm::dvec3(1.0, 0.0, 0.0), start); rotationAxis = normalize(rotationAxis); - rotInQuat = glm::quat(glm::radians(180.0f), rotationAxis); - return glm::dmat3(toMat4(rotInQuat)); + rotationQuat = glm::quat(glm::radians(180.f), rotationAxis); + return glm::dmat3(toMat4(rotationQuat)); } rotationAxis = cross(start, end); @@ -313,56 +300,58 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { float s = sqrt((1 + cosTheta) * 2); float invs = 1 / s; - rotInQuat = glm::quat( + rotationQuat = glm::quat( s * 0.5f, rotationAxis.x * invs, rotationAxis.y * invs, rotationAxis.z * invs ); - return glm::dmat3(toMat4(rotInQuat)); + return glm::dmat3(toMat4(rotationQuat)); } int addExoplanetSystem(lua_State* L) { - const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); + const std::string starName = luaL_checkstring(L, StringLocation); //change expl-starname to exoplanet.csv-starname - std::string starname_csv = getCsvStarname(starname); + std::string starnameCsv = getCsvStarname(starName); // If user have given name as in EOD, change it to speck-name - std::string starname_speck = getSpeckStarname(starname); - std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); + std::string starNameSpeck = getSpeckStarname(starName); + std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); - global::moduleEngine.module()->setStarName(starname_speck); + global::moduleEngine.module()->setStarName(starNameSpeck); + + std::ifstream data( + absPath("${MODULE_EXOPLANETS}/expl_data.bin"), + std::ios::in | std::ios::binary + ); - std::ifstream data(absPath("${MODULE_EXOPLANETS}/expl_data.bin"), std::ios::in | std::ios::binary); if (!data.good()) { - std::cout << "Failed to open exoplanets data file"; + return ghoul::lua::luaError(L, "Failed to open exoplanets data file"); } std::ifstream lut(absPath("${MODULE_EXOPLANETS}/lookup.txt")); if (!lut.good()) { - std::cout << "Failed to open exoplanets look-up table file"; + return ghoul::lua::luaError(L, "Failed to open exoplanets look-up table file"); } //1. search lut for the starname and return the corresponding location //2. go to that location in the data file //3. read sizeof(exoplanet) bytes into an exoplanet object. - std::string planetname; - size_t len = 0; Exoplanet p; std::string line; bool found = false; - std::vector plsy; - std::vector plna; + std::vector planetSystem; + std::vector planetNames; + while (getline(lut, line)) { - std::istringstream ss(line); - getline(ss, planetname, ','); + std::string name; + getline(ss, name, ','); - if (planetname.compare(0, planetname.length() - 2, starname_speck) == 0) { + if (name.compare(0, name.length() - 2, starNameSpeck) == 0) { std::string location_s; getline(ss, location_s); long location = std::stol(location_s.c_str()); @@ -370,419 +359,393 @@ int addExoplanetSystem(lua_State* L) { data.seekg(location); data.read((char*)&p, sizeof(struct Exoplanet)); - plna.push_back(planetname); - plsy.push_back(p); + planetNames.push_back(name); + planetSystem.push_back(p); found = true; - } } data.close(); lut.close(); - global::moduleEngine.module()->setPlna(plna); - global::moduleEngine.module()->setPlsy(plsy); + global::moduleEngine.module()->setPlanetNames(planetNames); + global::moduleEngine.module()->setPlanetSystem(planetSystem); global::moduleEngine.module()->setClosestExoplanet(p); - if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY - { - Time epoch; - double parsec = 0.308567756E17; - std::string script = ""; + if (!found || isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER)) { // || p.BINARY + return ghoul::lua::luaError(L, "No star with that name or not enough data about it."); + } - glm::dvec3 position = glm::dvec3(p.POSITIONX * parsec , p.POSITIONY * parsec, p.POSITIONZ * parsec); - - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - position); - glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); + Time epoch; + const double parsec = 0.308567756E17; - glm::dmat3 galaxticToCelectialMatrix = SpiceManager::ref().positionTransformMatrix( // galaxtic north in celectial coordinates, or just celectial north? - "GALACTIC", - "J2000", - 0.0 - ); - glm::dvec3 celestialNorth = normalize(galaxticToCelectialMatrix * galacticNorth); + glm::dvec3 starPosition = glm::dvec3( + p.POSITIONX * parsec, + p.POSITIONY * parsec, + p.POSITIONZ * parsec + ); + + glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); + glm::dvec3 starToSunVec = normalize(sunPosition - starPosition); + glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); + glm::dmat3 galaxticToCelectialMatrix = SpiceManager::ref().positionTransformMatrix( // galaxtic north in celectial coordinates, or just celectial north? + "GALACTIC", + "J2000", + 0.0 + ); + glm::dvec3 celestialNorth = normalize(galaxticToCelectialMatrix * galacticNorth); - // Earths north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) - glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec)); - global::moduleEngine.module()->setNorthVector(northProjected); + // Earths north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) + glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec))) * starToSunVec)); + global::moduleEngine.module()->setNorthVector(northProjected); - glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); + glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); - const glm::dmat3 exoplanetSystemRot = glm::dmat3(northProjected.x, northProjected.y, northProjected.z, - beta.x, beta.y, beta.z, - starToSunVec.x, starToSunVec.y, starToSunVec.z); + const glm::dmat3 exoplanetSystemRotation = glm::dmat3( + northProjected.x, + northProjected.y, + northProjected.z, + beta.x, + beta.y, + beta.z, + starToSunVec.x, + starToSunVec.y, + starToSunVec.z + ); - std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); + std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); + const std::string starParent = "{" + "Identifier = '" + starNameSpeck + "'," + "Parent = 'SolarSystemBarycenter'," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + ghoul::to_string(exoplanetSystemRotation) + "" + "}," + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + ghoul::to_string(starPosition) + "" + "}" + "}" + "}"; - const std::string starParent = "{" - "Identifier = '" + starname_speck + "'," - "Parent = 'SolarSystemBarycenter'," + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + starParent + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + + float starRadius = p.RSTAR; + + if (!isnan(starRadius)) { + std::ifstream colorMap(absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), std::ios::in); + if (!colorMap.good()) { + ghoul::lua::luaError(L, "Failed to open colormap data file"); + } + + std::string color = getStarColor(p.BMV, colorMap); + Exoplanet firstPlanet = planetSystem[0]; + + if (isnan(firstPlanet.ECC)) { + firstPlanet.ECC = 0; + } + if (isnan(firstPlanet.I)) { + firstPlanet.I = 90; + } + if (isnan(firstPlanet.BIGOM)) { + firstPlanet.BIGOM = 180; + } + if (isnan(firstPlanet.OM)) { + firstPlanet.OM = 90; + } + std::string sEpochStar; + if (!isnan(firstPlanet.TT)) { + epoch.setTime("JD " + std::to_string(firstPlanet.TT)); + sEpochStar = epoch.ISO8601(); + } + else + sEpochStar = "2009-05-19T07:11:34.080"; + + const std::string starGlobeNode = "{" + "Identifier = '" + starNameSpeck + "Globe'," + "Parent = '" + starNameSpeck + "'," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(starRadius) + " * 6.957E8," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'StarColor'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Identifier = 'StarTexture'," + "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," + "BlendMode = 'Color'," + "Enabled = true" + "}" + "}" + "}" + "}," "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(exoplanetSystemRot) + "," + "Scale = {" + "Type = 'StaticScale'," + "Scale = 1.0," "}," "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(position) + "," - "}," + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(firstPlanet.ECC) + "," //ECC + "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(firstPlanet.I) + "," //I + "AscendingNode = " + std::to_string(firstPlanet.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(firstPlanet.OM) + "," //OM + "MeanAnomaly = 180.0," + "Epoch = '" + sEpochStar + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(firstPlanet.PER) + "* 86400" //PER. 86 400sec = 1 day. + "}" "}" "}"; - script = "openspace.addSceneGraphNode(" + starParent + ");"; openspace::global::scriptEngine.queueScript( - script, + "openspace.addSceneGraphNode(" + starGlobeNode + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - if (!isnan(p.RSTAR)) - { - std::string color = getStarColor(p.BMV); + } - if (isnan(plsy[0].ECC)) - { - plsy[0].ECC = 0; - } - if (isnan(plsy[0].I)) - { - plsy[0].I = 90; - } - if (isnan(plsy[0].BIGOM)) - { - plsy[0].BIGOM = 180; - } - if (isnan(plsy[0].OM)) - { - plsy[0].OM = 90; - } - std::string sepoch_star; - if (!isnan(plsy[0].TT)) { - epoch.setTime("JD " + std::to_string(plsy[0].TT)); - sepoch_star = epoch.ISO8601(); - } - else - sepoch_star = "2009-05-19T07:11:34.080"; + for (size_t i = 0; i < planetSystem.size(); i++) { + Exoplanet planet = planetSystem[i]; + std::string planetName = planetNames[i]; - const std::string starGlobe = "{" - "Identifier = '" + starname_speck + "Globe'," - "Parent = '" + starname_speck + "'," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(p.RSTAR) + " * 6.957E8," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'StarColor'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" - "}," - "{" - "Identifier = 'StarTexture'," - "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," - "BlendMode = 'Color'," - "Enabled = true" - "}" - "}" - "}" - "}," - "Transform = {" - "Scale = {" - "Type = 'StaticScale'," - "Scale = 1.0," - "}," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[0].ECC) + "," //ECC - "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[0].I) + "," //I - "AscendingNode = " + std::to_string(plsy[0].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[0].OM) + "," //OM - "MeanAnomaly = 180.0," - "Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[0].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}" - "}" - "}"; - script = ""; - script = " openspace.addSceneGraphNode(" + starGlobe + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - //script = ""; - - //const std::string starGlare = "{" - // "Identifier = '" + starname_speck + "Glare'," - // "Parent = '" + starname_speck + "'," - // "Renderable = {" - // "Type = 'RenderablePlaneImageLocal'," - // "Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - // "Billboard = true," - // "Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/target-blue.png'," - // "BlendMode = 'Additive'" - // "}" - // "}"; - // - //script = "openspace.addSceneGraphNode(" + starGlare + ");"; - //global::scriptEngine.queueScript( - // script, - // scripting::ScriptEngine::RemoteScripting::Yes - //); + if (isnan(planet.ECC)) { + planet.ECC = 0; } + if (isnan(planet.I)) { + planet.I = 90; + } + if (isnan(planet.BIGOM)) { + planet.BIGOM = 180; + } + if (isnan(planet.OM)) { + planet.OM = 90; + } + std::string sEpoch; + if (!isnan(planet.TT)) { + epoch.setTime("JD " + std::to_string(planet.TT)); + sEpoch = epoch.ISO8601(); + } + else + sEpoch = "2009-05-19T07:11:34.080"; - - - - for (size_t i = 0; i < plsy.size(); i++) - { - script = ""; - - if (isnan(plsy[i].ECC)) - { - plsy[i].ECC = 0; - } - if (isnan(plsy[i].I)) - { - plsy[i].I = 90; - } - if (isnan(plsy[i].BIGOM)) - { - plsy[i].BIGOM = 180; - } - if (isnan(plsy[i].OM)) - { - plsy[i].OM = 90; - } - std::string sepoch; - if (!isnan(plsy[i].TT)) { - epoch.setTime("JD " + std::to_string(plsy[i].TT)); - sepoch = epoch.ISO8601(); - } - else - sepoch = "2009-05-19T07:11:34.080"; - - float planetradius; - std::string enabled = ""; - if (isnan(plsy[i].R)) - { - if (isnan(plsy[i].RSTAR)) { - planetradius = plsy[i].A * 149597870700 * 0.001; - } - else { - planetradius = plsy[i].RSTAR *6.95700E8 *0.1; - } - - enabled = "false"; + float planetRadius; + std::string enabled = ""; + if (isnan(planet.R)) { + if (isnan(planet.RSTAR)) { + planetRadius = planet.A * 149597870700.f * 0.001f; } else { - planetradius = plsy[i].R *7.1492E7; - enabled = "true"; + planetRadius = planet.RSTAR * 6.95700E8f * 0.1f; } + enabled = "false"; + } + else { + planetRadius = planet.R * 7.1492E7; // 1 jupiter radii = 7.1492×10e7 m + enabled = "true"; + } - const std::string planet = "{" - "Identifier = '" + plna[i] + "'," - "Parent = '" + starname_speck + "'," - "Enabled = true," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Enabled = " + enabled + "," - "Radii = " + std::to_string(planetradius) + "," //R. in meters. 1 jupiter radii = 7.1492×10e7 m - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'ExoplanetTexture'," - "FilePath = openspace.absPath('${DATA}/test3.jpg')," - "Enabled = true" - "}" + const std::string planetNode = "{" + "Identifier = '" + planetName + "'," + "Parent = '" + starNameSpeck + "'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableGlobe'," + "Enabled = " + enabled + "," + "Radii = " + std::to_string(planetRadius) + "," //R. in meters. + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'ExoplanetTexture'," + "FilePath = openspace.absPath('${DATA}/test3.jpg')," + "Enabled = true" "}" "}" + "}" + "}," + "Transform = {" + "Scale = {" + "Type = 'StaticScale'," + "Scale = 1.0," "}," - "Transform = {" - "Scale = {" - "Type = 'StaticScale'," - "Scale = 1.0," - "}," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(planet.A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(planet.I) + "," //I + "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(planet.PER) + "* 86400" //PER. 86 400sec = 1 day. "}," - "}"; + "}," + "}"; - script = "openspace.addSceneGraphNode(" + planet + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - script = ""; + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + planetNode + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + const std::string planetTrailNode = "{" + "Identifier = '" + planetName + "Trail'," + "Parent = '" + starNameSpeck + "'," + "Enabled = true," + "Renderable = {" + "Type = 'RenderableTrailOrbit'," + "Period = " + std::to_string(planet.PER) + "," + "Resolution = 1000," + "Translation = {" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(planet.A) + " * 149597871," // 149 597 871km = 1 AU. A + "Inclination = " + std::to_string(planet.I) + "," //I + "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(planet.PER) + "* 86400" //PER. 86 400sec = 1 day. + "}," + "Color = { 1, 1, 1 }" + "}," + "}"; + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + planetTrailNode + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + bool hasUpperSemiMajor = !isnan(planet.AUPPER); + bool hasLowerSemiMajor = !isnan(planet.ALOWER); - const std::string planetTrail = "{" - "Identifier = '" + plna[i] + "Trail'," - "Parent = '" + starname_speck + "'," + if (hasUpperSemiMajor && hasLowerSemiMajor) + { + // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation + glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(planet.I, planet.BIGOM, planet.OM, exoplanetSystemRotation); + glm::dmat3 rotation = orbitPlaneRotationMatrix; + global::moduleEngine.module()->setRotation(rotation); + const std::string discNode = "{" + "Identifier = '" + planetName + "Disc'," + "Parent = '" + starNameSpeck + "'," "Enabled = true," "Renderable = {" - "Type = 'RenderableTrailOrbit'," - "Period = " + std::to_string(plsy[i].PER) + "," - "Resolution = 1000," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A - "Inclination = " + std::to_string(plsy[i].I) + "," //I - "AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day. - "}," - "Color = { 1, 1, 1 }" + "Type = 'RenderableOrbitdisc'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," + "Size = " + std::to_string(planet.A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(planet.ECC) + "," + "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend + "Opacity = 0.5" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + ghoul::to_string(rotation) + "," + "}" "}," "}"; openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + planetTrail + ");", + "openspace.addSceneGraphNode(" + discNode + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - if (!isnan(plsy[i].AUPPER) && !isnan(plsy[i].ALOWER)) + bool hasLowerUncertainty = !isnan(planet.ECCLOWER) && planet.ECCLOWER > 0.0; + bool hasUpperUncertainty = !isnan(planet.ECCUPPER) && (planet.ECCUPPER > 0.0); + + if (hasLowerUncertainty && hasUpperUncertainty) { - // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation - glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM, exoplanetSystemRot); - //glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(plsy[i].I, plsy[i].BIGOM, plsy[i].OM); // , exoplanetSystemRot); - glm::dmat3 rot = orbitPlaneRotationMatrix; - global::moduleEngine.module()->setRotation(rot); - const std::string disc = "{" - "Identifier = '" + plna[i] + "Disc'," - "Parent = '" + starname_speck + "'," - "Enabled = true," + double lowerEccentricity = planet.ECC - planet.ECCLOWER; + if (lowerEccentricity < 0.0) { + lowerEccentricity = 0.0; + } + + const std::string discLowerEccentricityNode = "{" + "Identifier = '" + planetName + "discECCLOWER'," + "Parent = '" + starNameSpeck + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(plsy[i].ECC) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.5" + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," + "Size = " + std::to_string(planet.A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(lowerEccentricity) + "," + "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend + "Opacity = 0.98," + "Enabled = false" "}," "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rot) + "," + "Rotation = " + ghoul::to_string(rotation) + "," "}" "}," "}"; + openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + disc + ");", + "openspace.addSceneGraphNode(" + discLowerEccentricityNode + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - - if (!isnan(plsy[i].ECCUPPER) && !isnan(plsy[i].ECCLOWER) && plsy[i].ECCUPPER > 0.0 && plsy[i].ECCLOWER > 0.0) - { - double lower_ecc = plsy[i].ECC - plsy[i].ECCLOWER; - if (lower_ecc < 0.0) - { - lower_ecc = 0.0; - } - const std::string discECCLOWER = "{" - "Identifier = '" + plna[i] + "discECCLOWER'," - "Parent = '" + starname_speck + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(lower_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rot) + "," - "}" - "}," - "}"; - - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + discECCLOWER + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - double upper_ecc = plsy[i].ECC + plsy[i].ECCUPPER; - if (upper_ecc > 1.0) - { - upper_ecc = 1.0; - } - const std::string discECCUPPER = "{" - "Identifier = '" + plna[i] + "discECCUPPER'," - "Parent = '" + starname_speck + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," - "Size = " + std::to_string(plsy[i].A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A - "Eccentricity = " + std::to_string(upper_ecc) + "," - "Offset = { " + std::to_string(plsy[i].ALOWER) + ", " + std::to_string(plsy[i].AUPPER) + " }," //min / max extend - "Transparency = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rot) + "," - "}" - "}," - "}"; - - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + discECCUPPER + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + double upperEccentricity = planet.ECC + planet.ECCUPPER; + if (upperEccentricity > 1.0) { + upperEccentricity = 1.0; } + + const std::string discUpperEccentricityNode = "{" + "Identifier = '" + planetName + "discECCUPPER'," + "Parent = '" + starNameSpeck + "'," + "Renderable = {" + "Type = 'RenderableOrbitdisc'," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," + "Size = " + std::to_string(planet.A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Eccentricity = " + std::to_string(upperEccentricity) + "," + "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend + "Opacity = 0.98," + "Enabled = false" + "}," + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + ghoul::to_string(rotation) + "," + "}" + "}," + "}"; + + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + discUpperEccentricityNode + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); } - } - - } - else - { - printf("No star with that name or not enough data about it."); - } - return 0; } int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; - const std::string starname = luaL_checkstring(L, StringLocation); - std::string starname_speck = getSpeckStarname(starname); - std::replace(starname_speck.begin(), starname_speck.end(), ' ', '_'); - std::string script = "openspace.removeSceneGraphNode('" + starname_speck + "');"; + const std::string starName = luaL_checkstring(L, StringLocation); + std::string starNameSpeck = getSpeckStarname(starName); + std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); + openspace::global::scriptEngine.queueScript( - script, + "openspace.removeSceneGraphNode('" + starNameSpeck + "');", scripting::ScriptEngine::RemoteScripting::Yes ); return 0; } -} //namespace +} //namespace openspace::exoplanets::luascriptfunctions diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 522ae3a6aa..dcc2d80692 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -64,13 +64,6 @@ namespace { "This value is used to limit the width of the rings. Each of the two values is " "the lower and the upper uncertainties of the semi-major axis. " }; - - static const openspace::properties::Property::PropertyInfo TransparencyInfo = { - "Transparency", - "Transparency", - "This value determines the transparency of part of the rings depending on the " - "color values. For this value v, the transparency is equal to length(color) / v." - }; } // namespace namespace openspace { @@ -109,12 +102,6 @@ documentation::Documentation RenderableOrbitdisc::Documentation() { new DoubleVector2Verifier, Optional::Yes, OffsetInfo.description - }, - { - TransparencyInfo.identifier, - new DoubleVerifier, - Optional::Yes, - TransparencyInfo.description } } }; @@ -126,7 +113,6 @@ RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) , _size(SizeInfo, 1.f, 0.f, 3.0e12f) , _eccentricity(EccentricityInfo, 0.f, 0.f, 1.f) , _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f)) - , _transparency(TransparencyInfo, 0.15f, 0.f, 1.f) , _shader(nullptr) , _texture(nullptr) , _textureFile(nullptr) @@ -162,16 +148,13 @@ RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) _textureFile->setCallback([&](const File&) { _textureIsDirty = true; }); - if (dictionary.hasKey(TransparencyInfo.identifier)) { - _transparency = static_cast( - dictionary.value(TransparencyInfo.identifier) - ); - } - addProperty(_transparency); - - _eccentricity = static_cast(dictionary.value(EccentricityInfo.identifier)); + _eccentricity = static_cast( + dictionary.value(EccentricityInfo.identifier) + ); _eccentricity.onChange([&]() { _planeIsDirty = true; }); addProperty(_eccentricity); + + addProperty(_opacity); } bool RenderableOrbitdisc::isReady() const { @@ -189,9 +172,8 @@ void RenderableOrbitdisc::initializeGL() { "modelViewProjectionTransform" ); _uniformCache.textureOffset = _shader->uniformLocation("textureOffset"); - _uniformCache.transparency = _shader->uniformLocation("transparency"); - //_uniformCache.sunPosition = _shader->uniformLocation("sunPosition"); - _uniformCache.texture = _shader->uniformLocation("texture1"); + _uniformCache.opacity = _shader->uniformLocation("opacity"); + _uniformCache.texture = _shader->uniformLocation("discTexture"); _uniformCache.eccentricity = _shader->uniformLocation("eccentricity"); _uniformCache.semiMajorAxis = _shader->uniformLocation("semiMajorAxis"); @@ -231,12 +213,9 @@ void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { data.camera.projectionMatrix() * glm::mat4(modelViewTransform) ); _shader->setUniform(_uniformCache.textureOffset, _offset); - _shader->setUniform(_uniformCache.transparency, _transparency); + _shader->setUniform(_uniformCache.opacity, _opacity); _shader->setUniform(_uniformCache.eccentricity, _eccentricity); _shader->setUniform(_uniformCache.semiMajorAxis, _size); - //_shader->setUniform(_uniformCache.sunPosition, _sunPosition); - - //setPscUniforms(*_shader, data.camera, data.position); ghoul::opengl::TextureUnit unit; unit.activate(); @@ -255,14 +234,12 @@ void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { void RenderableOrbitdisc::update(const UpdateData& data) { if (_shader->isDirty()) { _shader->rebuildFromFile(); - _uniformCache.modelViewProjection = _shader->uniformLocation( "modelViewProjectionTransform" ); _uniformCache.textureOffset = _shader->uniformLocation("textureOffset"); - _uniformCache.transparency = _shader->uniformLocation("transparency"); - //_uniformCache.sunPosition = _shader->uniformLocation("sunPosition"); - _uniformCache.texture = _shader->uniformLocation("texture1"); + _uniformCache.opacity = _shader->uniformLocation("opacity"); + _uniformCache.texture = _shader->uniformLocation("discTexture"); _uniformCache.eccentricity = _shader->uniformLocation("eccentricity"); _uniformCache.semiMajorAxis = _shader->uniformLocation("semiMajorAxis"); } @@ -276,9 +253,6 @@ void RenderableOrbitdisc::update(const UpdateData& data) { loadTexture(); _textureIsDirty = false; } - - //_sunPosition = OsEng.renderEngine().scene()->sceneGraphNode("Sun")->worldPosition() - - //data.modelTransform.translation; } void RenderableOrbitdisc::loadTexture() { diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index ba046408d3..d70751ba2b 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -25,13 +25,11 @@ #ifndef __OPENSPACE_MODULE_EXOPLENETS___RENDERABLEORBITDISC___H__ #define __OPENSPACE_MODULE_EXOPLANETS___RENDERABLEORBITDISC___H__ -#include - #include #include #include +#include #include - #include namespace ghoul::filesystem { class File; } @@ -66,19 +64,17 @@ private: properties::FloatProperty _size; properties::FloatProperty _eccentricity; properties::Vec2Property _offset; - //properties::FloatProperty _nightFactor; - properties::FloatProperty _transparency; std::unique_ptr _shader; - UniformCache(modelViewProjection, textureOffset, transparency, + UniformCache(modelViewProjection, textureOffset, opacity, texture, eccentricity, semiMajorAxis) _uniformCache; std::unique_ptr _texture; std::unique_ptr _textureFile; bool _textureIsDirty; + bool _planeIsDirty; GLuint _quad; GLuint _vertexPositionBuffer; - bool _planeIsDirty; }; } // namespace openspace diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 168409a696..9379f8951d 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -27,20 +27,13 @@ in vec2 vs_st; in vec4 vs_position; -//in vec4 vs_gPosition; -//in vec3 vs_gNormal; -uniform sampler1D texture1; +uniform sampler1D discTexture; uniform vec2 textureOffset; -uniform float transparency; +uniform float opacity; uniform float eccentricity; uniform float semiMajorAxis; -uniform bool hasSunPosition; -uniform vec3 sunPosition; -//uniform float _nightFactor; - - Fragment getFragment() { // Moving the origin to the center vec2 st = (vs_st - vec2(0.5)) * 2.0; @@ -61,17 +54,17 @@ Fragment getFragment() { float apo_inner = AL * (1 + E); if(eccentricity <= 0.000000){ - outer = pow(st.x , 2.0) / pow(AU/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BU/apo, 2.0)) ); - inner = pow(st.x , 2.0) / pow(AL/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BL/apo, 2.0)) ); + outer = pow(st.x, 2.0) / pow(AU/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BU/apo, 2.0))); + inner = pow(st.x, 2.0) / pow(AL/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BL/apo, 2.0))); } else { - outer = ( pow((st.x + CU/apo), 2.0) ) / pow(AU/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BU/apo, 2.0)) ); - inner = ( pow((st.x + CL/apo), 2.0) ) / pow(AL/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BL/apo, 2.0)) ); + outer = pow((st.x + CU/apo), 2.0) / pow(AU/apo, 2.0) + pow(st.y, 2.0) / (pow(BU/apo, 2.0)); + inner = pow((st.x + CL/apo), 2.0) / pow(AL/apo, 2.0) + pow(st.y, 2.0) / (pow(BL/apo, 2.0)); } - if (outer > 1.0 ) // point is outside outer ellipse + if (outer > 1.0) // point is outside outer ellipse discard; - if (inner < 1.0 ) // point is inside inner ellipse + if (inner < 1.0) // point is inside inner ellipse discard; // Remapping the texture coordinates @@ -79,14 +72,14 @@ Fragment getFragment() { // Find outer ellipse: where along the direction is the equation = 1 float scale; - if(eccentricity <= 0.000000){ - scale = sqrt( ( pow((AU/apo)*(BU/apo),2) ) / ((pow((BU/apo)*dir.x,2))+(pow((AU/apo)*dir.y,2))) ); + if (eccentricity <= 0.000000) { + scale = sqrt((pow((AU/apo) * (BU/apo), 2)) / ((pow((BU/apo) * dir.x, 2)) + (pow((AU/apo) * dir.y, 2)))); } - else{ - float first = -( pow(BU/apo, 2.0)*dir.x*(CU/apo) ) / ( pow((BU/apo)*dir.x, 2.0) + pow((AU/apo)*dir.y, 2.0) ); - float second = pow( ( pow(BU/apo, 2.0)*dir.x*(CU/apo) ) / ( pow((BU/apo)*dir.x, 2.0) + pow( (AU/apo)*dir.y, 2.0 ) ) , 2.0); - float third = ( pow( (BU/apo)*(CU/apo) , 2.0 ) - pow( (AU/apo)*(BU/apo), 2.0 ) ) / ( pow( (BU/apo)*dir.x, 2.0 ) + pow( (AU/apo)*dir.y, 2.0 ) ); - scale = first + sqrt( second - third); + else { + float first = -(pow(BU/apo, 2.0) * dir.x * (CU/apo)) / ( pow((BU/apo) * dir.x, 2.0) + pow((AU/apo) * dir.y, 2.0)); + float second = pow((pow(BU/apo, 2.0) * dir.x * (CU/apo)) / (pow((BU/apo) * dir.x, 2.0) + pow((AU/apo) * dir.y, 2.0)), 2.0); + float third = (pow( (BU/apo) * (CU/apo) , 2.0) - pow((AU/apo) * (BU/apo), 2.0)) / (pow((BU/apo) * dir.x, 2.0) + pow((AU/apo) * dir.y, 2.0)); + scale = first + sqrt(second - third); } vec2 max = dir * scale; @@ -94,15 +87,10 @@ Fragment getFragment() { float distance1 = distance(max, min); float distance2 = distance(max, st); - float textureCoord = distance2/distance1; + float textureCoord = distance2 / distance1; - vec4 diffuse = texture(texture1, textureCoord); - float colorValue = length(diffuse.rgb); - // times 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want - // to normalize the transparency value to [0,1] - if (colorValue < 3.0 * transparency) { - diffuse.a = pow(colorValue / (3.0 * transparency), 1); - } + vec4 diffuse = texture(discTexture, textureCoord); + diffuse.a *= opacity; // The normal for the one plane depends on whether we are dealing // with a front facing or back facing fragment @@ -116,13 +104,8 @@ Fragment getFragment() { normal = vec3(1.0, 0.0, 0.0); } - Fragment frag; frag.color = diffuse; frag.depth = vs_position.w; - - //frag.gPosition = vs_gPosition; - //frag.gNormal = vs_gNormal; - return frag; } diff --git a/modules/exoplanets/shaders/orbitdisc_vs.glsl b/modules/exoplanets/shaders/orbitdisc_vs.glsl index ce3a4eb0bd..1eebfb5d55 100644 --- a/modules/exoplanets/shaders/orbitdisc_vs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_vs.glsl @@ -31,16 +31,14 @@ layout(location = 1) in vec2 in_st; out vec2 vs_st; out vec4 vs_position; -//out vec4 vs_gPosition; -//out vec3 vs_gNormal; uniform mat4 modelViewProjectionTransform; void main() { vs_st = in_st; - vs_position = z_normalization( modelViewProjectionTransform * vec4(in_position.xy, 0.0, 1.0) ); + gl_Position = vs_position; } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 0984cd075f..ab03da3d43 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -34,151 +34,148 @@ #include namespace { - const char* KeyInputCSV = "InputCSV"; - const char* KeyInputSPECK = "InputSPECK"; - const char* KeyOutputBIN = "OutputBIN"; - const char* KeyOutputLUT = "OutputLUT"; + const char* KeyInputCsv = "InputCSV"; + const char* KeyInputSpeck = "InputSPECK"; + const char* KeyOutputBin = "OutputBIN"; + const char* KeyOutputLut = "OutputLUT"; constexpr const char* _loggerCat = "CsvToBinTask"; } // namespace -namespace openspace { -namespace exoplanets { +namespace openspace::exoplanets { ExoplanetsCsvToBinTask::ExoplanetsCsvToBinTask(const ghoul::Dictionary& dictionary) { - openspace::documentation::testSpecificationAndThrow( - documentation(), - dictionary, - "ExoplanetsCsvToBinTask" - ); + openspace::documentation::testSpecificationAndThrow( + documentation(), + dictionary, + "ExoplanetsCsvToBinTask" + ); - _inputCSVPath = absPath(dictionary.value(KeyInputCSV)); - _inputSPECKPath = absPath(dictionary.value(KeyInputSPECK)); - _outputBINPath = absPath(dictionary.value(KeyOutputBIN)); - _outputLUTPath = absPath(dictionary.value(KeyOutputLUT)); + _inputCsvPath = absPath(dictionary.value(KeyInputCsv)); + _inputSpeckPath = absPath(dictionary.value(KeyInputSpeck)); + _outputBinPath = absPath(dictionary.value(KeyOutputBin)); + _outputLutPath = absPath(dictionary.value(KeyOutputLut)); } std::string ExoplanetsCsvToBinTask::description() { - return "Extract metadata from csv-file " + _inputCSVPath + - " and write as bin to " + _outputBINPath; + return "Extract metadata from csv-file " + _inputCsvPath + + " and write as bin to " + _outputBinPath; } -std::string ExoplanetsCsvToBinTask::getExplName(std::string csvName) { - std::string explName = csvName; +std::string ExoplanetsCsvToBinTask::getExoplanetName(std::string csvName) { + std::string name = csvName; if (csvName == "HD 1237") - explName = "GJ 3021"; + name = "GJ 3021"; else if (csvName == "MOA-2009-BLG-387L") - explName = "MOA 2009-BLG-387L"; + name = "MOA 2009-BLG-387L"; else if (csvName == "HD 126614 A") - explName = "HD 126614"; + name = "HD 126614"; else if (csvName == "epsilon Ret") - explName = "HD 27442"; + name = "HD 27442"; else if (csvName == "PH-1") - explName = "PH1"; + name = "PH1"; else if (csvName == "gamma Leo A") - explName = "gam 1 Leo"; + name = "gam 1 Leo"; else if (csvName == "OGLE-2007-BLG-368L") - explName = "OGLE 2007-BLG-368L"; + name = "OGLE 2007-BLG-368L"; else if (csvName == "alpha Ari") - explName = "alf Ari"; + name = "alf Ari"; else if (csvName == "mu Ara") - explName = "HD 160691"; + name = "HD 160691"; else if (csvName == "OGLE-05-169L") - explName = "OGLE 2005-BLG-169L"; + name = "OGLE 2005-BLG-169L"; else if (csvName == "tau Gru") - explName = "HD 216435"; + name = "HD 216435"; else if (csvName == "iota Hor") - explName = "HR 810"; + name = "HR 810"; else if (csvName == "OGLE-05-071L") - explName = "OGLE 2005-BLG-71L"; + name = "OGLE 2005-BLG-71L"; else if (csvName == "OGLE235-MOA53") - explName = "OGLE 2003-BLG-235L"; + name = "OGLE 2003-BLG-235L"; else if (csvName == "MOA-2008-BLG-310L") - explName = "MOA 2008-BLG-310L"; + name = "MOA 2008-BLG-310L"; else if (csvName == "KIC 11442793") - explName = "KOI-351"; + name = "KOI-351"; else if (csvName == "OGLE-2006-BLG-109L") - explName = "OGLE 2006-BLG-109L"; + name = "OGLE 2006-BLG-109L"; else if (csvName == "HD 137388") - explName = "HD 137388 A"; + name = "HD 137388 A"; else if (csvName == "kappa CrB") - explName = "kap CrB"; + name = "kap CrB"; else if (csvName == "XO-2") - explName = "XO-2 N"; + name = "XO-2 N"; else if (csvName == "epsilon Tau") - explName = "eps Tau"; + name = "eps Tau"; else if (csvName == "epsilon Eri") - explName = "eps Eri"; + name = "eps Eri"; else if (csvName == "Kepler-448") - explName = "KOI-12"; + name = "KOI-12"; else if (csvName == "omega Ser") - explName = "ome Ser"; + name = "ome Ser"; else if (csvName == "MOA-2010-BLG-477L") - explName = "MOA 2010-BLG-477L"; + name = "MOA 2010-BLG-477L"; else if (csvName == "GJ 176") - explName = "HD 285968"; + name = "HD 285968"; else if (csvName == "HIP 2247") - explName = "BD-17 63"; + name = "BD-17 63"; else if (csvName == "MOA-2009-BLG-266L") - explName = "MOA 2009-BLG-266L"; + name = "MOA 2009-BLG-266L"; else if (csvName == "Kepler-89") - explName = "KOI-94"; + name = "KOI-94"; else if (csvName == "iota Dra") - explName = "HIP 75458"; + name = "HIP 75458"; else if (csvName == "MOA-2007-BLG-400L") - explName = "MOA 2007-BLG-400L"; + name = "MOA 2007-BLG-400L"; else if (csvName == "upsilon And") - explName = "ups And"; + name = "ups And"; else if (csvName == "OGLE-2011-BLG-0251") - explName = "OGLE 2011-BLG-251L"; + name = "OGLE 2011-BLG-251L"; else if (csvName == "OGLE-05-390L") - explName = "OGLE 2005-BLG-390L"; + name = "OGLE 2005-BLG-390L"; else if (csvName == "Kepler-420") - explName = "KOI-1257"; + name = "KOI-1257"; else if (csvName == "beta Pic") - explName = "bet Pic"; + name = "bet Pic"; else if (csvName == "gamma Cep") - explName = "gam Cep"; + name = "gam Cep"; else if (csvName == "MOA-2007-BLG-192L") - explName = "MOA 2007-BLG-192L"; + name = "MOA 2007-BLG-192L"; else if (csvName == "MOA-2009-BLG-319L") - explName = "MOA 2009-BLG-319L"; + name = "MOA 2009-BLG-319L"; else if (csvName == "omicron CrB") - explName = "omi CrB"; + name = "omi CrB"; else if (csvName == "beta Gem") - explName = "HD 62509"; + name = "HD 62509"; else if (csvName == "epsilon CrB") - explName = "eps CrB"; + name = "eps CrB"; else if (csvName == "omicron UMa") - explName = "omi UMa"; + name = "omi UMa"; else if (csvName == "HD 142022") - explName = "HD 142022 A"; + name = "HD 142022 A"; - return explName; + return name; } -glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) -{ - glm::vec3 pos; - pos[0] = NAN; - pos[1] = NAN; - pos[2] = NAN; - std::ifstream expl_file(_inputSPECKPath); - if (!expl_file) { +glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { + glm::vec3 position; + position[0] = NAN; + position[1] = NAN; + position[2] = NAN; + std::ifstream exoplanetsFile(_inputSpeckPath); + if (!exoplanetsFile) { LERROR(fmt::format("Error opening file expl.speck.")); } std::string line; std::string d; std::string n; - while (getline(expl_file, line)) + while (getline(exoplanetsFile, line)) { if (line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" || line.empty()) { continue; } std::istringstream linestream(line); - getline(linestream, d, '#'); getline(linestream, n); n.erase(0, 1); @@ -186,576 +183,578 @@ glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) std::string coord; if (n.compare(starName) == 0) { - std::stringstream datastream(d); - getline(datastream, coord, ' '); - pos[0] = std::stof(coord.c_str(), nullptr); - getline(datastream, coord, ' '); - pos[1] = std::stof(coord.c_str(), nullptr); - getline(datastream, coord, ' '); - pos[2] = std::stof(coord.c_str(), nullptr); + std::stringstream dataStream(d); + getline(dataStream, coord, ' '); + position[0] = std::stof(coord.c_str(), nullptr); + getline(dataStream, coord, ' '); + position[1] = std::stof(coord.c_str(), nullptr); + getline(dataStream, coord, ' '); + position[2] = std::stof(coord.c_str(), nullptr); break; } } - //Apply transformation matrix to pos + // Apply transformation matrix to pos glm::dmat4 _transformationMatrix = glm::dmat4(1.0); - glm::vec3 transformedPos = glm::vec3(_transformationMatrix * glm::dvec4(pos, 1.0)); + glm::vec3 transformedPosition = glm::vec3( + _transformationMatrix * glm::dvec4(position, 1.0) + ); - expl_file.close(); - return transformedPos; + exoplanetsFile.close(); + return transformedPosition; } void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallback) { - std::ifstream csv_file(_inputCSVPath); - if (!csv_file.good()) { - LERROR(fmt::format("Failed to open Speck file '{}'", _inputCSVPath)); + std::ifstream csvFile(_inputCsvPath); + if (!csvFile.good()) { + LERROR(fmt::format("Failed to open CSV file '{}'", _inputCsvPath)); return; } - std::ofstream bin_file(_outputBINPath, std::ios::out | std::ios::binary); - std::ofstream lut_file(_outputLUTPath); + std::ofstream binFile(_outputBinPath, std::ios::out | std::ios::binary); + std::ofstream lutFile(_outputLutPath); int version = 1; - bin_file.write((char *)&version, sizeof(int)); + binFile.write((char *)&version, sizeof(int)); Exoplanet p; std::string planetname; std::string component; - std::string planet_row; - getline(csv_file, planet_row); // The first line, containing the data names + std::string planetRow; + getline(csvFile, planetRow); // The first line, containing the data names - std::string data_s; bool iskeplerobject = false; int total = 0; - while (getline(csv_file, planet_row)) { + while (getline(csvFile, planetRow)) { ++total; } - csv_file.clear(); - csv_file.seekg(0); - getline(csv_file, planet_row); // The first line, containing the data names + csvFile.clear(); + csvFile.seekg(0); + getline(csvFile, planetRow); // The first line, containing the data names LINFOC("CSVTOBIN", fmt::format("Loading {} stars", total)); int count = 0; - while (getline(csv_file, planet_row)) { + std::string data; + while (getline(csvFile, planetRow)) { ++count; progressCallback(static_cast(count) / static_cast(total)); - std::istringstream lineStream(planet_row); + std::istringstream lineStream(planetRow); - getline(lineStream, data_s, ','); // A - if (!data_s.empty()) - p.A = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // A + if (!data.empty()) + p.A = std::stof(data.c_str(), nullptr); else p.A = NAN; - getline(lineStream, data_s, ','); // AUPPER - if (!data_s.empty()) - p.AUPPER = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // AUPPER + if (!data.empty()) + p.AUPPER = std::stod(data.c_str(), nullptr); else p.AUPPER = NAN; - getline(lineStream, data_s, ','); // ALOWER - if (!data_s.empty()) - p.ALOWER = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // ALOWER + if (!data.empty()) + p.ALOWER = std::stod(data.c_str(), nullptr); else p.ALOWER = NAN; - getline(lineStream, data_s, ','); // UA - if (!data_s.empty()) - p.UA = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UA + if (!data.empty()) + p.UA = std::stod(data.c_str(), nullptr); else p.UA = NAN; - getline(lineStream, data_s, ','); // AREF - getline(lineStream, data_s, ','); // AURL - getline(lineStream, data_s, ','); // AR - getline(lineStream, data_s, ','); // ARUPPER - getline(lineStream, data_s, ','); // ARLOWER - getline(lineStream, data_s, ','); // UAR - getline(lineStream, data_s, ','); // ARREF - getline(lineStream, data_s, ','); // ARURL - getline(lineStream, data_s, ','); // ASTROMETRY - getline(lineStream, data_s, ','); // B - getline(lineStream, data_s, ','); // BUPPER - getline(lineStream, data_s, ','); // BLOWER - getline(lineStream, data_s, ','); // UB - getline(lineStream, data_s, ','); // BREF - getline(lineStream, data_s, ','); // BURL - getline(lineStream, data_s, ','); // BIGOM - if (!data_s.empty()) - p.BIGOM = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // AREF + getline(lineStream, data, ','); // AURL + getline(lineStream, data, ','); // AR + getline(lineStream, data, ','); // ARUPPER + getline(lineStream, data, ','); // ARLOWER + getline(lineStream, data, ','); // UAR + getline(lineStream, data, ','); // ARREF + getline(lineStream, data, ','); // ARURL + getline(lineStream, data, ','); // ASTROMETRY + getline(lineStream, data, ','); // B + getline(lineStream, data, ','); // BUPPER + getline(lineStream, data, ','); // BLOWER + getline(lineStream, data, ','); // UB + getline(lineStream, data, ','); // BREF + getline(lineStream, data, ','); // BURL + getline(lineStream, data, ','); // BIGOM + if (!data.empty()) + p.BIGOM = std::stof(data.c_str(), nullptr); else p.BIGOM = NAN; - getline(lineStream, data_s, ','); // BIGOMUPPER - if (!data_s.empty()) - p.BIGOMUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // BIGOMUPPER + if (!data.empty()) + p.BIGOMUPPER = std::stof(data.c_str(), nullptr); else p.BIGOMUPPER = NAN; - getline(lineStream, data_s, ','); // BIGOMLOWER - if (!data_s.empty()) - p.BIGOMLOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // BIGOMLOWER + if (!data.empty()) + p.BIGOMLOWER = std::stof(data.c_str(), nullptr); else p.BIGOMLOWER = NAN; - getline(lineStream, data_s, ','); // UBIGOM - if (!data_s.empty()) - p.UBIGOM = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UBIGOM + if (!data.empty()) + p.UBIGOM = std::stof(data.c_str(), nullptr); else p.UBIGOM = NAN; - getline(lineStream, data_s, ','); // BIGOMREF - getline(lineStream, data_s, ','); // BIGOMURL - getline(lineStream, data_s, ','); // BINARY - if (!data_s.empty()) - p.BINARY = std::stoi(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // BIGOMREF + getline(lineStream, data, ','); // BIGOMURL + getline(lineStream, data, ','); // BINARY + if (!data.empty()) + p.BINARY = std::stoi(data.c_str(), nullptr); else p.BINARY = -1; - getline(lineStream, data_s, ','); // BINARYREF - getline(lineStream, data_s, ','); // BINARYURL - getline(lineStream, data_s, ','); // BMV - if (!data_s.empty()) - p.BMV = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // BINARYREF + getline(lineStream, data, ','); // BINARYURL + getline(lineStream, data, ','); // BMV + if (!data.empty()) + p.BMV = std::stof(data.c_str(), nullptr); else p.BMV = NAN; - getline(lineStream, data_s, ','); // CHI2 - getline(lineStream, data_s, ','); // COMP - component = data_s; - getline(lineStream, data_s, ','); // DATE - getline(lineStream, data_s, ','); // DEC - getline(lineStream, data_s, ','); // DEC_STRING - getline(lineStream, data_s, ','); // DENSITY - getline(lineStream, data_s, ','); // DENSITYUPPER - getline(lineStream, data_s, ','); // DENSITYLOWER - getline(lineStream, data_s, ','); // UDENSITY - getline(lineStream, data_s, ','); // DENSITYREF - getline(lineStream, data_s, ','); // DENSITYURL - getline(lineStream, data_s, ','); // DEPTH - getline(lineStream, data_s, ','); // DEPTHUPPER - getline(lineStream, data_s, ','); // DEPTHLOWER - getline(lineStream, data_s, ','); // UDEPTH - getline(lineStream, data_s, ','); // DEPTHREF - getline(lineStream, data_s, ','); // DEPTHURL - getline(lineStream, data_s, ','); // DIST - getline(lineStream, data_s, ','); // DISTUPPER - getline(lineStream, data_s, ','); // DISTLOWER - getline(lineStream, data_s, ','); // UDIST - getline(lineStream, data_s, ','); // DISTREF - getline(lineStream, data_s, ','); // DISTURL - getline(lineStream, data_s, ','); // DR - getline(lineStream, data_s, ','); // DRUPPER - getline(lineStream, data_s, ','); // DRLOWER - getline(lineStream, data_s, ','); // UDR - getline(lineStream, data_s, ','); // DRREF - getline(lineStream, data_s, ','); // DRURL - getline(lineStream, data_s, ','); // DVDT - getline(lineStream, data_s, ','); // DVDTUPPER - getline(lineStream, data_s, ','); // DVDTLOWER - getline(lineStream, data_s, ','); // UDVDT - getline(lineStream, data_s, ','); // DVDTREF - getline(lineStream, data_s, ','); // DVDTURL - getline(lineStream, data_s, ','); // EANAME - getline(lineStream, data_s, ','); // EAURL - getline(lineStream, data_s, ','); // ECC - if (!data_s.empty()) - p.ECC = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // CHI2 + getline(lineStream, data, ','); // COMP + component = data; + getline(lineStream, data, ','); // DATE + getline(lineStream, data, ','); // DEC + getline(lineStream, data, ','); // DEC_STRING + getline(lineStream, data, ','); // DENSITY + getline(lineStream, data, ','); // DENSITYUPPER + getline(lineStream, data, ','); // DENSITYLOWER + getline(lineStream, data, ','); // UDENSITY + getline(lineStream, data, ','); // DENSITYREF + getline(lineStream, data, ','); // DENSITYURL + getline(lineStream, data, ','); // DEPTH + getline(lineStream, data, ','); // DEPTHUPPER + getline(lineStream, data, ','); // DEPTHLOWER + getline(lineStream, data, ','); // UDEPTH + getline(lineStream, data, ','); // DEPTHREF + getline(lineStream, data, ','); // DEPTHURL + getline(lineStream, data, ','); // DIST + getline(lineStream, data, ','); // DISTUPPER + getline(lineStream, data, ','); // DISTLOWER + getline(lineStream, data, ','); // UDIST + getline(lineStream, data, ','); // DISTREF + getline(lineStream, data, ','); // DISTURL + getline(lineStream, data, ','); // DR + getline(lineStream, data, ','); // DRUPPER + getline(lineStream, data, ','); // DRLOWER + getline(lineStream, data, ','); // UDR + getline(lineStream, data, ','); // DRREF + getline(lineStream, data, ','); // DRURL + getline(lineStream, data, ','); // DVDT + getline(lineStream, data, ','); // DVDTUPPER + getline(lineStream, data, ','); // DVDTLOWER + getline(lineStream, data, ','); // UDVDT + getline(lineStream, data, ','); // DVDTREF + getline(lineStream, data, ','); // DVDTURL + getline(lineStream, data, ','); // EANAME + getline(lineStream, data, ','); // EAURL + getline(lineStream, data, ','); // ECC + if (!data.empty()) + p.ECC = std::stof(data.c_str(), nullptr); else p.ECC = NAN; - getline(lineStream, data_s, ','); // ECCUPPER - if (!data_s.empty()) - p.ECCUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // ECCUPPER + if (!data.empty()) + p.ECCUPPER = std::stof(data.c_str(), nullptr); else p.ECCUPPER = NAN; - getline(lineStream, data_s, ','); // ECCLOWER - if (!data_s.empty()) - p.ECCLOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // ECCLOWER + if (!data.empty()) + p.ECCLOWER = std::stof(data.c_str(), nullptr); else p.ECCLOWER = NAN; - getline(lineStream, data_s, ','); // UECC - if (!data_s.empty()) - p.UECC = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UECC + if (!data.empty()) + p.UECC = std::stof(data.c_str(), nullptr); else p.UECC = NAN; - getline(lineStream, data_s, ','); // ECCREF - getline(lineStream, data_s, ','); // ECCURL - getline(lineStream, data_s, ','); // EOD - getline(lineStream, data_s, ','); // ETDNAME - getline(lineStream, data_s, ','); // ETDURL - getline(lineStream, data_s, ','); // FE - getline(lineStream, data_s, ','); // FEUPPER - getline(lineStream, data_s, ','); // FELOWER - getline(lineStream, data_s, ','); // UFE - getline(lineStream, data_s, ','); // FEREF - getline(lineStream, data_s, ','); // FEURL - getline(lineStream, data_s, ','); // FIRSTREF - getline(lineStream, data_s, ','); // FIRSTURL - getline(lineStream, data_s, ','); // FREEZE_ECC - getline(lineStream, data_s, ','); // GAMMA - getline(lineStream, data_s, ','); // GAMMAUPPER - getline(lineStream, data_s, ','); // GAMMALOWER - getline(lineStream, data_s, ','); // UGAMMA - getline(lineStream, data_s, ','); // GAMMAREF - getline(lineStream, data_s, ','); // GAMMAURL - getline(lineStream, data_s, ','); // GL - getline(lineStream, data_s, ','); // GRAVITY - getline(lineStream, data_s, ','); // GRAVITYUPPER - getline(lineStream, data_s, ','); // GRAVITYLOWER - getline(lineStream, data_s, ','); // UGRAVITY - getline(lineStream, data_s, ','); // GRAVITYREF - getline(lineStream, data_s, ','); // GRAVITYURL - getline(lineStream, data_s, ','); // H - getline(lineStream, data_s, ','); // HD - getline(lineStream, data_s, ','); // HIPP - getline(lineStream, data_s, ','); // HR - getline(lineStream, data_s, ','); // I - if (!data_s.empty()) - p.I = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // ECCREF + getline(lineStream, data, ','); // ECCURL + getline(lineStream, data, ','); // EOD + getline(lineStream, data, ','); // ETDNAME + getline(lineStream, data, ','); // ETDURL + getline(lineStream, data, ','); // FE + getline(lineStream, data, ','); // FEUPPER + getline(lineStream, data, ','); // FELOWER + getline(lineStream, data, ','); // UFE + getline(lineStream, data, ','); // FEREF + getline(lineStream, data, ','); // FEURL + getline(lineStream, data, ','); // FIRSTREF + getline(lineStream, data, ','); // FIRSTURL + getline(lineStream, data, ','); // FREEZE_ECC + getline(lineStream, data, ','); // GAMMA + getline(lineStream, data, ','); // GAMMAUPPER + getline(lineStream, data, ','); // GAMMALOWER + getline(lineStream, data, ','); // UGAMMA + getline(lineStream, data, ','); // GAMMAREF + getline(lineStream, data, ','); // GAMMAURL + getline(lineStream, data, ','); // GL + getline(lineStream, data, ','); // GRAVITY + getline(lineStream, data, ','); // GRAVITYUPPER + getline(lineStream, data, ','); // GRAVITYLOWER + getline(lineStream, data, ','); // UGRAVITY + getline(lineStream, data, ','); // GRAVITYREF + getline(lineStream, data, ','); // GRAVITYURL + getline(lineStream, data, ','); // H + getline(lineStream, data, ','); // HD + getline(lineStream, data, ','); // HIPP + getline(lineStream, data, ','); // HR + getline(lineStream, data, ','); // I + if (!data.empty()) + p.I = std::stof(data.c_str(), nullptr); else p.I = NAN; - getline(lineStream, data_s, ','); // IUPPER - if (!data_s.empty()) - p.IUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // IUPPER + if (!data.empty()) + p.IUPPER = std::stof(data.c_str(), nullptr); else p.IUPPER = NAN; - getline(lineStream, data_s, ','); // ILOWER - if (!data_s.empty()) - p.ILOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // ILOWER + if (!data.empty()) + p.ILOWER = std::stof(data.c_str(), nullptr); else p.ILOWER = NAN; - getline(lineStream, data_s, ','); // UI - if (!data_s.empty()) - p.UI = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UI + if (!data.empty()) + p.UI = std::stof(data.c_str(), nullptr); else p.UI = NAN; - getline(lineStream, data_s, ','); // IREF - getline(lineStream, data_s, ','); // IURL - getline(lineStream, data_s, ','); // IMAGING - getline(lineStream, data_s, ','); // J - getline(lineStream, data_s, ','); // JSNAME - getline(lineStream, data_s, ','); // EPEURL - getline(lineStream, data_s, ','); // K - getline(lineStream, data_s, ','); // KUPPER - getline(lineStream, data_s, ','); // KLOWER - getline(lineStream, data_s, ','); // UK - getline(lineStream, data_s, ','); // KREF - getline(lineStream, data_s, ','); // KURL - getline(lineStream, data_s, ','); // KOI - getline(lineStream, data_s, ','); // KS - getline(lineStream, data_s, ','); // KP - getline(lineStream, data_s, ','); // LAMBDA - getline(lineStream, data_s, ','); // LAMBDAUPPER - getline(lineStream, data_s, ','); // LAMBDALOWER - getline(lineStream, data_s, ','); // ULAMBDA - getline(lineStream, data_s, ','); // LAMBDAREF - getline(lineStream, data_s, ','); // LAMBDAURL - getline(lineStream, data_s, ','); // LOGG - getline(lineStream, data_s, ','); // LOGGUPPER - getline(lineStream, data_s, ','); // LOGGLOWER - getline(lineStream, data_s, ','); // ULOGG - getline(lineStream, data_s, ','); // LOGGREF - getline(lineStream, data_s, ','); // LOGGURL; - getline(lineStream, data_s, ','); // MASS - getline(lineStream, data_s, ','); // MASSUPPER - getline(lineStream, data_s, ','); // MASSLOWER - getline(lineStream, data_s, ','); // UMASS - getline(lineStream, data_s, ','); // MASSREF - getline(lineStream, data_s, ','); // MASSURL - getline(lineStream, data_s, ','); // MICROLENSING - getline(lineStream, data_s, ','); // MSINI - getline(lineStream, data_s, ','); // MSINIUPPER - getline(lineStream, data_s, ','); // MSINILOWER - getline(lineStream, data_s, ','); // UMSINI - getline(lineStream, data_s, ','); // MSINIREF - getline(lineStream, data_s, ','); // MSINIURL - getline(lineStream, data_s, ','); // MSTAR - getline(lineStream, data_s, ','); // MSTARUPPER - getline(lineStream, data_s, ','); // MSTARLOWER - getline(lineStream, data_s, ','); // UMSTAR - getline(lineStream, data_s, ','); // MSTARREF - getline(lineStream, data_s, ','); // MSTARURL - getline(lineStream, data_s, ','); // MULT - getline(lineStream, data_s, ','); // NAME - getline(lineStream, data_s, ','); // NCOMP - if (!data_s.empty()) - p.NCOMP = std::stoi(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // IREF + getline(lineStream, data, ','); // IURL + getline(lineStream, data, ','); // IMAGING + getline(lineStream, data, ','); // J + getline(lineStream, data, ','); // JSNAME + getline(lineStream, data, ','); // EPEURL + getline(lineStream, data, ','); // K + getline(lineStream, data, ','); // KUPPER + getline(lineStream, data, ','); // KLOWER + getline(lineStream, data, ','); // UK + getline(lineStream, data, ','); // KREF + getline(lineStream, data, ','); // KURL + getline(lineStream, data, ','); // KOI + getline(lineStream, data, ','); // KS + getline(lineStream, data, ','); // KP + getline(lineStream, data, ','); // LAMBDA + getline(lineStream, data, ','); // LAMBDAUPPER + getline(lineStream, data, ','); // LAMBDALOWER + getline(lineStream, data, ','); // ULAMBDA + getline(lineStream, data, ','); // LAMBDAREF + getline(lineStream, data, ','); // LAMBDAURL + getline(lineStream, data, ','); // LOGG + getline(lineStream, data, ','); // LOGGUPPER + getline(lineStream, data, ','); // LOGGLOWER + getline(lineStream, data, ','); // ULOGG + getline(lineStream, data, ','); // LOGGREF + getline(lineStream, data, ','); // LOGGURL; + getline(lineStream, data, ','); // MASS + getline(lineStream, data, ','); // MASSUPPER + getline(lineStream, data, ','); // MASSLOWER + getline(lineStream, data, ','); // UMASS + getline(lineStream, data, ','); // MASSREF + getline(lineStream, data, ','); // MASSURL + getline(lineStream, data, ','); // MICROLENSING + getline(lineStream, data, ','); // MSINI + getline(lineStream, data, ','); // MSINIUPPER + getline(lineStream, data, ','); // MSINILOWER + getline(lineStream, data, ','); // UMSINI + getline(lineStream, data, ','); // MSINIREF + getline(lineStream, data, ','); // MSINIURL + getline(lineStream, data, ','); // MSTAR + getline(lineStream, data, ','); // MSTARUPPER + getline(lineStream, data, ','); // MSTARLOWER + getline(lineStream, data, ','); // UMSTAR + getline(lineStream, data, ','); // MSTARREF + getline(lineStream, data, ','); // MSTARURL + getline(lineStream, data, ','); // MULT + getline(lineStream, data, ','); // NAME + getline(lineStream, data, ','); // NCOMP + if (!data.empty()) + p.NCOMP = std::stoi(data.c_str(), nullptr); else p.NCOMP = -1; - getline(lineStream, data_s, ','); // NOBS - getline(lineStream, data_s, ','); // OM - if (!data_s.empty()) - p.OM = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // NOBS + getline(lineStream, data, ','); // OM + if (!data.empty()) + p.OM = std::stof(data.c_str(), nullptr); else p.OM = NAN; - getline(lineStream, data_s, ','); // OMUPPER - if (!data_s.empty()) - p.OMUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // OMUPPER + if (!data.empty()) + p.OMUPPER = std::stof(data.c_str(), nullptr); else p.OMUPPER = NAN; - getline(lineStream, data_s, ','); // OMLOWER - if (!data_s.empty()) - p.OMLOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // OMLOWER + if (!data.empty()) + p.OMLOWER = std::stof(data.c_str(), nullptr); else p.OMLOWER = NAN; - getline(lineStream, data_s, ','); // UOM - if (!data_s.empty()) - p.UOM = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UOM + if (!data.empty()) + p.UOM = std::stof(data.c_str(), nullptr); else p.UOM = NAN; - getline(lineStream, data_s, ','); // OMREF - getline(lineStream, data_s, ','); // OMURL - getline(lineStream, data_s, ','); // ORBREF - getline(lineStream, data_s, ','); // ORBURL - getline(lineStream, data_s, ','); // OTHERNAME - getline(lineStream, data_s, ','); // PAR - getline(lineStream, data_s, ','); // PARUPPER - getline(lineStream, data_s, ','); // PARLOWER - getline(lineStream, data_s, ','); // UPAR - getline(lineStream, data_s, ','); // PER - if (!data_s.empty()) - p.PER = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // OMREF + getline(lineStream, data, ','); // OMURL + getline(lineStream, data, ','); // ORBREF + getline(lineStream, data, ','); // ORBURL + getline(lineStream, data, ','); // OTHERNAME + getline(lineStream, data, ','); // PAR + getline(lineStream, data, ','); // PARUPPER + getline(lineStream, data, ','); // PARLOWER + getline(lineStream, data, ','); // UPAR + getline(lineStream, data, ','); // PER + if (!data.empty()) + p.PER = std::stod(data.c_str(), nullptr); else p.PER = NAN; - getline(lineStream, data_s, ','); // PERUPPER - if (!data_s.empty()) - p.PERUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // PERUPPER + if (!data.empty()) + p.PERUPPER = std::stof(data.c_str(), nullptr); else p.PERUPPER = NAN; - getline(lineStream, data_s, ','); // PERLOWER - if (!data_s.empty()) - p.PERLOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // PERLOWER + if (!data.empty()) + p.PERLOWER = std::stof(data.c_str(), nullptr); else p.PERLOWER = NAN; - getline(lineStream, data_s, ','); // UPER - if (!data_s.empty()) - p.UPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UPER + if (!data.empty()) + p.UPER = std::stof(data.c_str(), nullptr); else p.UPER = NAN; - getline(lineStream, data_s, ','); // PERREF - getline(lineStream, data_s, ','); // PERURL - getline(lineStream, data_s, ','); // PLANETDISCMETH - getline(lineStream, data_s, ','); // R - if (!data_s.empty()) - p.R = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // PERREF + getline(lineStream, data, ','); // PERURL + getline(lineStream, data, ','); // PLANETDISCMETH + getline(lineStream, data, ','); // R + if (!data.empty()) + p.R = std::stod(data.c_str(), nullptr); else p.R = NAN; - getline(lineStream, data_s, ','); // RUPPER - if (!data_s.empty()) - p.RUPPER = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // RUPPER + if (!data.empty()) + p.RUPPER = std::stod(data.c_str(), nullptr); else p.RUPPER = NAN; - getline(lineStream, data_s, ','); // RLOWER - if (!data_s.empty()) - p.RLOWER = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // RLOWER + if (!data.empty()) + p.RLOWER = std::stod(data.c_str(), nullptr); else p.RLOWER = NAN; - getline(lineStream, data_s, ','); //UR - if (!data_s.empty()) - p.UR = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); //UR + if (!data.empty()) + p.UR = std::stod(data.c_str(), nullptr); else p.UR = NAN; - getline(lineStream, data_s, ','); // RREF - getline(lineStream, data_s, ','); // RURL - getline(lineStream, data_s, ','); // RA - getline(lineStream, data_s, ','); // RA_STRING - getline(lineStream, data_s, ','); // RHK - getline(lineStream, data_s, ','); // RHOSTAR - getline(lineStream, data_s, ','); // RHOSTARUPPER - getline(lineStream, data_s, ','); // RHOSTARLOWER - getline(lineStream, data_s, ','); // URHOSTAR - getline(lineStream, data_s, ','); // RHOSTARREF - getline(lineStream, data_s, ','); // RHOSTARURL - getline(lineStream, data_s, ','); // RMS - getline(lineStream, data_s, ','); // RR - getline(lineStream, data_s, ','); // RRUPPER - getline(lineStream, data_s, ','); // RRLOWER - getline(lineStream, data_s, ','); // URR - getline(lineStream, data_s, ','); // RRREF - getline(lineStream, data_s, ','); // RRURL - getline(lineStream, data_s, ','); // RSTAR - if (!data_s.empty()) - p.RSTAR = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // RREF + getline(lineStream, data, ','); // RURL + getline(lineStream, data, ','); // RA + getline(lineStream, data, ','); // RA_STRING + getline(lineStream, data, ','); // RHK + getline(lineStream, data, ','); // RHOSTAR + getline(lineStream, data, ','); // RHOSTARUPPER + getline(lineStream, data, ','); // RHOSTARLOWER + getline(lineStream, data, ','); // URHOSTAR + getline(lineStream, data, ','); // RHOSTARREF + getline(lineStream, data, ','); // RHOSTARURL + getline(lineStream, data, ','); // RMS + getline(lineStream, data, ','); // RR + getline(lineStream, data, ','); // RRUPPER + getline(lineStream, data, ','); // RRLOWER + getline(lineStream, data, ','); // URR + getline(lineStream, data, ','); // RRREF + getline(lineStream, data, ','); // RRURL + getline(lineStream, data, ','); // RSTAR + if (!data.empty()) + p.RSTAR = std::stof(data.c_str(), nullptr); else p.RSTAR = NAN; - getline(lineStream, data_s, ','); // RSTARUPPER - if (!data_s.empty()) - p.RSTARUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // RSTARUPPER + if (!data.empty()) + p.RSTARUPPER = std::stof(data.c_str(), nullptr); else p.RSTARUPPER = NAN; - getline(lineStream, data_s, ','); // RSTARLOWER - if (!data_s.empty()) - p.RSTARLOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // RSTARLOWER + if (!data.empty()) + p.RSTARLOWER = std::stof(data.c_str(), nullptr); else p.RSTARLOWER = NAN; - getline(lineStream, data_s, ','); // URSTAR - if (!data_s.empty()) - p.URSTAR = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // URSTAR + if (!data.empty()) + p.URSTAR = std::stof(data.c_str(), nullptr); else p.URSTAR = NAN; - getline(lineStream, data_s, ','); // RSTARREF - getline(lineStream, data_s, ','); // RSTARURL - getline(lineStream, data_s, ','); // SAO - getline(lineStream, data_s, ','); // SE - getline(lineStream, data_s, ','); // SEREF - getline(lineStream, data_s, ','); // SEURL - getline(lineStream, data_s, ','); // SEDEPTHJ - getline(lineStream, data_s, ','); // SEDEPTHJUPPER - getline(lineStream, data_s, ','); // SEDEPTHJLOWER - getline(lineStream, data_s, ','); // USEDEPTHJ - getline(lineStream, data_s, ','); // SEDEPTHJREF - getline(lineStream, data_s, ','); // SEDEPTHJURL - getline(lineStream, data_s, ','); // SEDEPTHH - getline(lineStream, data_s, ','); // SEDEPTHHUPPER - getline(lineStream, data_s, ','); // SEDEPTHHLOWER - getline(lineStream, data_s, ','); // USEDEPTHH - getline(lineStream, data_s, ','); // SEDEPTHHREF - getline(lineStream, data_s, ','); // SEDEPTHHURL - getline(lineStream, data_s, ','); // SEDEPTHKS - getline(lineStream, data_s, ','); // SEDEPTHKSUPPER - getline(lineStream, data_s, ','); // SEDEPTHKSLOWER - getline(lineStream, data_s, ','); // USEDEPTHKS - getline(lineStream, data_s, ','); // SEDEPTHKSREF - getline(lineStream, data_s, ','); // SEDEPTHKSURL - getline(lineStream, data_s, ','); // SEDEPTHKP - getline(lineStream, data_s, ','); // SEDEPTHKPUPPER - getline(lineStream, data_s, ','); // SEDEPTHKPLOWER - getline(lineStream, data_s, ','); // USEDEPTHKP - getline(lineStream, data_s, ','); // SEDEPTHKPREF - getline(lineStream, data_s, ','); // SEDEPTHKPURL - getline(lineStream, data_s, ','); // SEDEPTH36 - getline(lineStream, data_s, ','); // SEDEPTH36UPPER - getline(lineStream, data_s, ','); // SEDEPTH36LOWER - getline(lineStream, data_s, ','); // USEDEPTH36 - getline(lineStream, data_s, ','); // SEDEPTH36REFx - getline(lineStream, data_s, ','); // SEDEPTH36URLx - getline(lineStream, data_s, ','); // SEDEPTH45 - getline(lineStream, data_s, ','); // SEDEPTH45UPPER - getline(lineStream, data_s, ','); // SEDEPTH45LOWER - getline(lineStream, data_s, ','); // USEDEPTH45 - getline(lineStream, data_s, ','); // SEDEPTH45REF - getline(lineStream, data_s, ','); // SEDEPTH45URL - getline(lineStream, data_s, ','); // SEDEPTH58 - getline(lineStream, data_s, ','); // SEDEPTH58UPPER - getline(lineStream, data_s, ','); // SEDEPTH58LOWER - getline(lineStream, data_s, ','); // USEDEPTH58 - getline(lineStream, data_s, ','); // EDEPTH58REF - getline(lineStream, data_s, ','); // SEDEPTH58URL - getline(lineStream, data_s, ','); // SEDEPTH80 - getline(lineStream, data_s, ','); // SEDEPTH80UPPER - getline(lineStream, data_s, ','); // SEDEPTH80LOWER - getline(lineStream, data_s, ','); // USEDEPTH80 - getline(lineStream, data_s, ','); // SEDEPTH80REF - getline(lineStream, data_s, ','); // SEDEPTH80URL - getline(lineStream, data_s, ','); // SEP - getline(lineStream, data_s, ','); // SEPUPPER - getline(lineStream, data_s, ','); // SEPLOWER - getline(lineStream, data_s, ','); // USEP - getline(lineStream, data_s, ','); // SEPREF - getline(lineStream, data_s, ','); // SEPURL - getline(lineStream, data_s, ','); // SET - getline(lineStream, data_s, ','); // SETUPPER - getline(lineStream, data_s, ','); // SETLOWER - getline(lineStream, data_s, ','); // USET - getline(lineStream, data_s, ','); // SETREF - getline(lineStream, data_s, ','); // SETURL - getline(lineStream, data_s, ','); // SHK - getline(lineStream, data_s, ','); // SIMBADNAME - getline(lineStream, data_s, ','); // SIMBADURL - getline(lineStream, data_s, ','); // SPECREF - getline(lineStream, data_s, ','); // SPECURL - getline(lineStream, data_s, ','); // STAR - std::string speckStarname = getExplName(data_s); + getline(lineStream, data, ','); // RSTARREF + getline(lineStream, data, ','); // RSTARURL + getline(lineStream, data, ','); // SAO + getline(lineStream, data, ','); // SE + getline(lineStream, data, ','); // SEREF + getline(lineStream, data, ','); // SEURL + getline(lineStream, data, ','); // SEDEPTHJ + getline(lineStream, data, ','); // SEDEPTHJUPPER + getline(lineStream, data, ','); // SEDEPTHJLOWER + getline(lineStream, data, ','); // USEDEPTHJ + getline(lineStream, data, ','); // SEDEPTHJREF + getline(lineStream, data, ','); // SEDEPTHJURL + getline(lineStream, data, ','); // SEDEPTHH + getline(lineStream, data, ','); // SEDEPTHHUPPER + getline(lineStream, data, ','); // SEDEPTHHLOWER + getline(lineStream, data, ','); // USEDEPTHH + getline(lineStream, data, ','); // SEDEPTHHREF + getline(lineStream, data, ','); // SEDEPTHHURL + getline(lineStream, data, ','); // SEDEPTHKS + getline(lineStream, data, ','); // SEDEPTHKSUPPER + getline(lineStream, data, ','); // SEDEPTHKSLOWER + getline(lineStream, data, ','); // USEDEPTHKS + getline(lineStream, data, ','); // SEDEPTHKSREF + getline(lineStream, data, ','); // SEDEPTHKSURL + getline(lineStream, data, ','); // SEDEPTHKP + getline(lineStream, data, ','); // SEDEPTHKPUPPER + getline(lineStream, data, ','); // SEDEPTHKPLOWER + getline(lineStream, data, ','); // USEDEPTHKP + getline(lineStream, data, ','); // SEDEPTHKPREF + getline(lineStream, data, ','); // SEDEPTHKPURL + getline(lineStream, data, ','); // SEDEPTH36 + getline(lineStream, data, ','); // SEDEPTH36UPPER + getline(lineStream, data, ','); // SEDEPTH36LOWER + getline(lineStream, data, ','); // USEDEPTH36 + getline(lineStream, data, ','); // SEDEPTH36REFx + getline(lineStream, data, ','); // SEDEPTH36URLx + getline(lineStream, data, ','); // SEDEPTH45 + getline(lineStream, data, ','); // SEDEPTH45UPPER + getline(lineStream, data, ','); // SEDEPTH45LOWER + getline(lineStream, data, ','); // USEDEPTH45 + getline(lineStream, data, ','); // SEDEPTH45REF + getline(lineStream, data, ','); // SEDEPTH45URL + getline(lineStream, data, ','); // SEDEPTH58 + getline(lineStream, data, ','); // SEDEPTH58UPPER + getline(lineStream, data, ','); // SEDEPTH58LOWER + getline(lineStream, data, ','); // USEDEPTH58 + getline(lineStream, data, ','); // EDEPTH58REF + getline(lineStream, data, ','); // SEDEPTH58URL + getline(lineStream, data, ','); // SEDEPTH80 + getline(lineStream, data, ','); // SEDEPTH80UPPER + getline(lineStream, data, ','); // SEDEPTH80LOWER + getline(lineStream, data, ','); // USEDEPTH80 + getline(lineStream, data, ','); // SEDEPTH80REF + getline(lineStream, data, ','); // SEDEPTH80URL + getline(lineStream, data, ','); // SEP + getline(lineStream, data, ','); // SEPUPPER + getline(lineStream, data, ','); // SEPLOWER + getline(lineStream, data, ','); // USEP + getline(lineStream, data, ','); // SEPREF + getline(lineStream, data, ','); // SEPURL + getline(lineStream, data, ','); // SET + getline(lineStream, data, ','); // SETUPPER + getline(lineStream, data, ','); // SETLOWER + getline(lineStream, data, ','); // USET + getline(lineStream, data, ','); // SETREF + getline(lineStream, data, ','); // SETURL + getline(lineStream, data, ','); // SHK + getline(lineStream, data, ','); // SIMBADNAME + getline(lineStream, data, ','); // SIMBADURL + getline(lineStream, data, ','); // SPECREF + getline(lineStream, data, ','); // SPECURL + getline(lineStream, data, ','); // STAR + std::string speckStarname = getExoplanetName(data); glm::vec3 pos = getStarPosition(speckStarname); p.POSITIONX = pos[0]; p.POSITIONY = pos[1]; p.POSITIONZ = pos[2]; - getline(lineStream, data_s, ','); // STARDISCMETH - getline(lineStream, data_s, ','); // T0 - getline(lineStream, data_s, ','); // T0UPPER - getline(lineStream, data_s, ','); // T0LOWER - getline(lineStream, data_s, ','); // UT0 - getline(lineStream, data_s, ','); // T0REF - getline(lineStream, data_s, ','); // T0URL - getline(lineStream, data_s, ','); // T14 - getline(lineStream, data_s, ','); // T14UPPER - getline(lineStream, data_s, ','); // T14LOWER - getline(lineStream, data_s, ','); // UT14 - getline(lineStream, data_s, ','); // T14REF - getline(lineStream, data_s, ','); // T14URL - getline(lineStream, data_s, ','); // TEFF + getline(lineStream, data, ','); // STARDISCMETH + getline(lineStream, data, ','); // T0 + getline(lineStream, data, ','); // T0UPPER + getline(lineStream, data, ','); // T0LOWER + getline(lineStream, data, ','); // UT0 + getline(lineStream, data, ','); // T0REF + getline(lineStream, data, ','); // T0URL + getline(lineStream, data, ','); // T14 + getline(lineStream, data, ','); // T14UPPER + getline(lineStream, data, ','); // T14LOWER + getline(lineStream, data, ','); // UT14 + getline(lineStream, data, ','); // T14REF + getline(lineStream, data, ','); // T14URL + getline(lineStream, data, ','); // TEFF float teff; - if (!data_s.empty()) - teff = std::stof(data_s.c_str(), nullptr); + if (!data.empty()) + teff = std::stof(data.c_str(), nullptr); else teff = NAN; - getline(lineStream, data_s, ','); // TEFFUPPER - getline(lineStream, data_s, ','); // TEFFLOWER - getline(lineStream, data_s, ','); // UTEFF - getline(lineStream, data_s, ','); // TEFFREF - getline(lineStream, data_s, ','); // TEFFURL - getline(lineStream, data_s, ','); // TIMING - getline(lineStream, data_s, ','); // TRANSIT - getline(lineStream, data_s, ','); // TRANSITREF - getline(lineStream, data_s, ','); // TRANSITURL - getline(lineStream, data_s, ','); // TREND - getline(lineStream, data_s, ','); // TT - if (!data_s.empty()) - p.TT = std::stod(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // TEFFUPPER + getline(lineStream, data, ','); // TEFFLOWER + getline(lineStream, data, ','); // UTEFF + getline(lineStream, data, ','); // TEFFREF + getline(lineStream, data, ','); // TEFFURL + getline(lineStream, data, ','); // TIMING + getline(lineStream, data, ','); // TRANSIT + getline(lineStream, data, ','); // TRANSITREF + getline(lineStream, data, ','); // TRANSITURL + getline(lineStream, data, ','); // TREND + getline(lineStream, data, ','); // TT + if (!data.empty()) + p.TT = std::stod(data.c_str(), nullptr); else p.TT = NAN; - getline(lineStream, data_s, ','); // TTUPPER - if (!data_s.empty()) - p.TTUPPER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // TTUPPER + if (!data.empty()) + p.TTUPPER = std::stof(data.c_str(), nullptr); else p.TTUPPER = NAN; - getline(lineStream, data_s, ','); // TTLOWER - if (!data_s.empty()) - p.TTLOWER = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // TTLOWER + if (!data.empty()) + p.TTLOWER = std::stof(data.c_str(), nullptr); else p.TTLOWER = NAN; - getline(lineStream, data_s, ','); // UTT - if (!data_s.empty()) - p.UTT = std::stof(data_s.c_str(), nullptr); + getline(lineStream, data, ','); // UTT + if (!data.empty()) + p.UTT = std::stof(data.c_str(), nullptr); else p.UTT = NAN; - getline(lineStream, data_s, ','); // TTREF - getline(lineStream, data_s, ','); // TTURL - getline(lineStream, data_s, ','); // V - getline(lineStream, data_s, ','); // VREF - getline(lineStream, data_s, ','); // VURL - getline(lineStream, data_s, ','); // VSINI - getline(lineStream, data_s, ','); // VSINIUPPER - getline(lineStream, data_s, ','); // VSINILOWER - getline(lineStream, data_s, ','); // UVSINI - getline(lineStream, data_s, ','); // VSINIREF - getline(lineStream, data_s, ','); // VSINIURL - getline(lineStream, data_s, ','); // KEPID - if (!data_s.empty()) + getline(lineStream, data, ','); // TTREF + getline(lineStream, data, ','); // TTURL + getline(lineStream, data, ','); // V + getline(lineStream, data, ','); // VREF + getline(lineStream, data, ','); // VURL + getline(lineStream, data, ','); // VSINI + getline(lineStream, data, ','); // VSINIUPPER + getline(lineStream, data, ','); // VSINILOWER + getline(lineStream, data, ','); // UVSINI + getline(lineStream, data, ','); // VSINIREF + getline(lineStream, data, ','); // VSINIURL + getline(lineStream, data, ','); // KEPID + if (!data.empty()) iskeplerobject = true; - getline(lineStream, data_s); // KDE + getline(lineStream, data); // KDE if (!iskeplerobject) { // calculate B-V from Teff if not exsisting @@ -788,12 +787,11 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb BV = 2.00; } else { - BV = (((bv_upper - bv_lower)*(teff - teff_lower)) / (teff_upper - teff_lower)) + bv_lower; + BV = (((bv_upper - bv_lower) * (teff - teff_lower)) / (teff_upper - teff_lower)) + bv_lower; } break; } } - teff_bv.close(); p.BMV = BV; } @@ -802,16 +800,17 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb } } - long pos = bin_file.tellp(); + // crate look-up table + long pos = binFile.tellp(); planetname = speckStarname + " " + component; - lut_file << planetname << "," << pos << std::endl; - bin_file.write((char *)&p, sizeof(struct Exoplanet)); + lutFile << planetname << "," << pos << std::endl; + binFile.write((char *)&p, sizeof(struct Exoplanet)); } } - csv_file.close(); - bin_file.close(); - lut_file.close(); + csvFile.close(); + binFile.close(); + lutFile.close(); progressCallback(1.0f); } @@ -829,25 +828,25 @@ documentation::Documentation ExoplanetsCsvToBinTask::documentation() { "The type of this task" }, { - KeyInputCSV, + KeyInputCsv, new StringAnnotationVerifier("A file path to a csv file"), Optional::No, "The csv file to extract data from" }, { - KeyInputSPECK, + KeyInputSpeck, new StringAnnotationVerifier("A file path to a speck file"), Optional::No, - "The speck file to with star location" + "The speck file with star location" }, { - KeyOutputBIN, + KeyOutputBin, new StringAnnotationVerifier("A valid filepath"), Optional::No, "The bin file to export data into" }, { - KeyOutputLUT, + KeyOutputLut, new StringAnnotationVerifier("A valid filepath"), Optional::No, "The txt file to write look-up table into" @@ -856,5 +855,4 @@ documentation::Documentation ExoplanetsCsvToBinTask::documentation() { }; } -} // namespace exoplanets -} // namespace openspace +} // namespace openspace::exoplanets diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 4a2c7bb302..9646f0c6d0 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -25,13 +25,11 @@ #ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ -#include #include - +#include #include -namespace openspace { -namespace exoplanets { +namespace openspace::exoplanets { class ExoplanetsCsvToBinTask : public Task { public: @@ -41,12 +39,12 @@ public: static documentation::Documentation documentation(); private: - std::string _inputCSVPath; - std::string _inputSPECKPath; - std::string _outputBINPath; - std::string _outputLUTPath; + std::string _inputCsvPath; + std::string _inputSpeckPath; + std::string _outputBinPath; + std::string _outputLutPath; - std::string getExplName(std::string csvName); + std::string getExoplanetName(std::string csvName); glm::vec3 getStarPosition(std::string starName); struct Exoplanet { @@ -95,7 +93,6 @@ private: }; }; -} // namespace exoplanets -} // namespace openspace +} // namespace openspace::exoplanets #endif // __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__ From 00814d07b151ace03546622c5fc6eb6b0dd2b185 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 27 Aug 2020 16:28:44 +0200 Subject: [PATCH 077/123] Simplify shader and increase readability --- modules/exoplanets/shaders/orbitdisc_fs.glsl | 87 ++++++++++++-------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 9379f8951d..457395f22a 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -34,56 +34,71 @@ uniform float opacity; uniform float eccentricity; uniform float semiMajorAxis; +const float AstronomicalUnit = 149597870700.0; // m +const float Epsilon = 0.0000001; + +// Compute semi minor axis from major axis, a, and eccentricity, e +float semiMinorAxis(float a, float e) { + return a * sqrt(1.0 - pow(e, 2.0)); +} + +// If returned value <= 1, the point is insdie or on the ellipse specified by the input: +// a and b are the semi-major and semi-minor axes, respectively. +// cx is the displacement of the center of the ellipse along the x-axis (for an orbit, +// the y-displacement is always zero) +float ellipseTest(vec2 point, float a, float b, float cx) { + float x = point.x; + float y = point.y; + return (pow(x - cx, 2.0) / (a*a)) + ((y*y) / (b*b)); +} + Fragment getFragment() { // Moving the origin to the center vec2 st = (vs_st - vec2(0.5)) * 2.0; - // The length of the texture coordinates vector is our distance from the center - float outer; - float inner; - - float E = eccentricity; - float AU = semiMajorAxis; - float BU = AU * sqrt(1.0 - pow(E, 2.0)); // semi-minor axis - float CU = sqrt(pow(AU, 2.0) - pow(BU, 2.0)); - float apo = AU * (1 + E); + float AUpper = semiMajorAxis; + float BUpper = semiMinorAxis(AUpper, eccentricity); + float CUpper = sqrt(AUpper*AUpper - BUpper*BUpper); + float outerApoapsisDistance = AUpper * (1 + eccentricity); - float AL = AU - textureOffset.x * 149597870700.0 - textureOffset.y * 149597870700.0; - float BL = AL * sqrt(1.0 - pow(E, 2.0)); - float CL = sqrt(pow(AL, 2.0) - pow(BL, 2.0)); - float apo_inner = AL * (1 + E); + float ALower = AUpper - AstronomicalUnit * (textureOffset.x + textureOffset.y); + float BLower = semiMinorAxis(ALower, eccentricity); + float CLower = sqrt(ALower*ALower - BLower*BLower); + float innerApoapsisDistance = ALower * (1 + eccentricity); - if(eccentricity <= 0.000000){ - outer = pow(st.x, 2.0) / pow(AU/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BU/apo, 2.0))); - inner = pow(st.x, 2.0) / pow(AL/apo, 2.0) + ( pow(st.y, 2.0) / (pow(BL/apo, 2.0))); + // Normalize based on outer apoapsis distance (size of plane) + float AU_n = AUpper / outerApoapsisDistance; + float BU_n = BUpper / outerApoapsisDistance; + float CU_n = CUpper / outerApoapsisDistance; + float AL_n = ALower / outerApoapsisDistance; + float BL_n = BLower / outerApoapsisDistance; + float CL_n = CLower / outerApoapsisDistance; + + if (eccentricity <= Epsilon) { + CU_n = 0.0; + CL_n = 0.0; } - else { - outer = pow((st.x + CU/apo), 2.0) / pow(AU/apo, 2.0) + pow(st.y, 2.0) / (pow(BU/apo, 2.0)); - inner = pow((st.x + CL/apo), 2.0) / pow(AL/apo, 2.0) + pow(st.y, 2.0) / (pow(BL/apo, 2.0)); + + float outer = ellipseTest(st, AU_n, BU_n, -CU_n); + float inner = ellipseTest(st, AL_n, BL_n, -CL_n); + if (outer > 1.0 || inner < 1.0) { + // point is outside outer ellipse or inside inner eliipse + discard; } - - if (outer > 1.0) // point is outside outer ellipse - discard; - if (inner < 1.0) // point is inside inner ellipse - discard; // Remapping the texture coordinates vec2 dir = normalize(st); - // Find outer ellipse: where along the direction is the equation = 1 - float scale; - if (eccentricity <= 0.000000) { - scale = sqrt((pow((AU/apo) * (BU/apo), 2)) / ((pow((BU/apo) * dir.x, 2)) + (pow((AU/apo) * dir.y, 2)))); - } - else { - float first = -(pow(BU/apo, 2.0) * dir.x * (CU/apo)) / ( pow((BU/apo) * dir.x, 2.0) + pow((AU/apo) * dir.y, 2.0)); - float second = pow((pow(BU/apo, 2.0) * dir.x * (CU/apo)) / (pow((BU/apo) * dir.x, 2.0) + pow((AU/apo) * dir.y, 2.0)), 2.0); - float third = (pow( (BU/apo) * (CU/apo) , 2.0) - pow((AU/apo) * (BU/apo), 2.0)) / (pow((BU/apo) * dir.x, 2.0) + pow((AU/apo) * dir.y, 2.0)); - scale = first + sqrt(second - third); - } + // Find outer ellipse: where along the direction does the equation == 1? + float denominator = pow(BU_n * dir.x, 2.0) + pow(AU_n * dir.y, 2.0); + float first = -(pow(BU_n, 2.0) * dir.x * CU_n) / denominator; + float second = pow((pow(BU_n, 2.0) * dir.x * CU_n) / denominator, 2.0); + float third = (pow(BU_n * CU_n, 2.0) - pow(AU_n * BU_n, 2.0)) / denominator; + + float scale = first + sqrt(second - third); vec2 max = dir * scale; - vec2 min = max * (apo_inner/apo); + vec2 min = max * (innerApoapsisDistance / outerApoapsisDistance); float distance1 = distance(max, min); float distance2 = distance(max, st); From 08e5c42d24110833623996d8f7c2ed5a33dcfb04 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 28 Aug 2020 08:29:18 +0200 Subject: [PATCH 078/123] Remove discovery methods code --- modules/exoplanets/CMakeLists.txt | 2 - .../discoverymethods/discoverymethods.cpp | 587 ------------------ .../discoverymethods/discoverymethods.h | 68 -- modules/exoplanets/exoplanetsmodule.cpp | 132 ---- modules/exoplanets/exoplanetsmodule.h | 24 - modules/exoplanets/exoplanetsmodule_lua.inl | 7 - 6 files changed, 820 deletions(-) delete mode 100644 modules/exoplanets/discoverymethods/discoverymethods.cpp delete mode 100644 modules/exoplanets/discoverymethods/discoverymethods.h diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 41c41a7d7f..2b34dd0c4f 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -26,7 +26,6 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h - ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h ) @@ -35,7 +34,6 @@ source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule_lua.inl - ${CMAKE_CURRENT_SOURCE_DIR}/discoverymethods/discoverymethods.cpp ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.cpp ) diff --git a/modules/exoplanets/discoverymethods/discoverymethods.cpp b/modules/exoplanets/discoverymethods/discoverymethods.cpp deleted file mode 100644 index 81bfecdbd8..0000000000 --- a/modules/exoplanets/discoverymethods/discoverymethods.cpp +++ /dev/null @@ -1,587 +0,0 @@ -/***************************************************************************************** -* * -* OpenSpace * -* * -* Copyright (c) 2014-2018 * -* * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this * -* software and associated documentation files (the "Software"), to deal in the Software * -* without restriction, including without limitation the rights to use, copy, modify, * -* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * -* permit persons to whom the Software is furnished to do so, subject to the following * -* conditions: * -* * -* The above copyright notice and this permission notice shall be included in all copies * -* or substantial portions of the Software. * -* * -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * -* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * -* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * -* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * -* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * -* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * -****************************************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - - -namespace { - constexpr const char* _loggerCat = "DiscoveryMethods"; - - static const openspace::properties::Property::PropertyInfo TransitMethodInfo = { - "TransitMethod", - "Show transit method", - "Change the view so that the transit method can be presented." - }; - - static const openspace::properties::Property::PropertyInfo DopplerMethodInfo = { - "DopplerMethod", - "Show doppler method", - "Change the view so that the doppler method can be presented." - }; - - static const openspace::properties::Property::PropertyInfo SolarSystemReferenceInfo = { - "SolarSystemReference", - "Show solar system reference", - "Show the size of the solar system as a reference for size." - }; -} // namespace - -namespace openspace::exoplanets { - -void DiscoveryMethods::addDirectionsMarkers(glm::dvec3 viewDirecionPos, glm::dvec3 northDirectionPos, float starRadius) { - const std::string markerView = "{" - "Identifier = 'markerView'," - "Parent = 'SolarSystemBarycenter'," - "Enabled = true," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadius) + "* 0.5," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'dir'," - "Type = 'SolidColor'," - "BlendMode = 'Normal'," - "Color = {1.0,0.0,0.0}," - "Enabled = true" - "}," - "}" - "}" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(viewDirecionPos) + "," - "}," - "}," - "}"; - std::string script = "openspace.addSceneGraphNode(" + markerView + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - const std::string markerNorth = "{" - "Identifier = 'markerNorth'," - "Parent = 'SolarSystemBarycenter'," - "Enabled = true," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadius) + "* 0.5," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'dir'," - "Type = 'SolidColor'," - "BlendMode = 'Normal'," - "Color = {0.0,0.0,1.0}," - "Enabled = true" - "}," - "}" - "}" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(northDirectionPos) + "," - "}," - "}," - "}"; - script = ""; - script = "openspace.addSceneGraphNode(" + markerNorth + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} -void DiscoveryMethods::removeDirectionsMarkers() { - std::string script = "openspace.removeSceneGraphNode('markerView'); openspace.removeSceneGraphNode('markerNorth');"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -float DiscoveryMethods::getTransitScaleFactor() { - return _transitScaleFactor; -} - -void addDopplerGraphs() { - std::string script = - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'DopplerShift2'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/stripes2.png')," - "EuclideanPosition = {0.0, -0.7}" - "});" - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'DopplerShift1'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/spectrum.jpg')," - "EuclideanPosition = {0.0, -0.7}" - "});"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void addTransitGraphs() { - std::string script = - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'Transit2'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/prick.png')," - "EuclideanPosition = {0.0, 0.0}," - "});" - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'Transit1'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/graph.png')," - "Scale = 0.485," - "EuclideanPosition = {0.0, -0.65}" - "});" - "openspace.addScreenSpaceRenderable(" - "{" - "Identifier = 'Transit3'," - "Type = 'ScreenSpaceImageLocal'," - "TexturePath = openspace.absPath('${BASE}/modules/exoplanets/axes.png')," - "Scale = 0.7," - "EuclideanPosition = {-0.05, -0.65}" - "});"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::scaleNode(std::string nodeName, float scalefactor) { - std::string script = "openspace.setPropertyValueSingle( 'Scene."+ nodeName +".Scale.Scale', " + std::to_string(scalefactor) + ", 1);"; //get name of current star from em - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) { - std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::toggleVisabilityOuterPlanets(std::vector planetNames, std::string visability) { - std::vector planets = global::moduleEngine.module()->planetSystem(); - - if (planetNames.size()>1) - { - //keeping first planet in the list, wich dosn't neccesarily mean the closest one... - for (size_t i = 1; i < planetNames.size(); i++) { - std::string script = ""; - //remove planetglobe - if (!isnan(planets[i].R)) { - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + ".RenderableGlobe.Enabled', " + visability + "); "; - } - //remove trail - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Trail.renderable.Enabled', " + visability + "); "; - //remove disc - if (!isnan(planets[i].AUPPER) && !isnan(planets[i].ALOWER)) { - script += "openspace.setPropertyValueSingle( 'Scene." + planetNames[i] + "Disc.renderable.Enabled', " + visability + "); "; - } - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - } -} - -void DiscoveryMethods::toggleVisabilityPlanet(std::string nodeName, std::string visability) { - std::string script = "openspace.setPropertyValueSingle( 'Scene." +nodeName + ".RenderableGlobe.Enabled', " + visability + "); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::moveCamera(glm::dvec3 pos) { - Camera* cam = global::navigationHandler.camera(); - cam->setPositionVec3(pos); - global::navigationHandler.resetCameraDirection(); -} - -bool DiscoveryMethods::isDoppler() { - return _showDoppler; -} -bool DiscoveryMethods::isTransit() { - return _showTransit; -} -bool DiscoveryMethods::isReference() { - return _showSolarSystemReference; -} - -void DiscoveryMethods::setDopplerImagePos(float value) { - std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.DopplerShift2.EuclideanPosition', {"+std::to_string(value)+", -0.7}); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::setTransitImagePos(float valueX,float valueY) { - std::string script = "openspace.setPropertyValueSingle( 'ScreenSpace.Transit2.EuclideanPosition', {" + std::to_string(valueX) + "," + std::to_string(valueY) + "}); "; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::addDopplerMethodVisualization() { - const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); - std::string starName = global::moduleEngine.module()->getStarName(); // getStarName - glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = global::moduleEngine.module()->planetSystem(); - std::vector planetNames = global::moduleEngine.module()->planetNames(); - - float semiMajorAxis = planets[0].A; // in AU - float starSemiMajorAxis = 0.1 * semiMajorAxis; // 10% of exoplanets semiMajorAxis - float eccentricity = planets[0].ECC; - if (isnan(planets[0].ECC)) { - eccentricity = 0.0; - } - float starRadius = planets[0].RSTAR; // in Solar Radii - - glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); - - // MOVE CAMERA - glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); - glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * faceOnVector); - moveCamera(cameraPosition); - // END CAMERA - - // SCALE STAR AND PLANET - float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU - periapsisDistance *= 149597870700.0; // in m - starRadius *= 6.957E8; // in m - float scale = (0.2 * periapsisDistance) / starRadius; - scaleNode(starName + "Globe", scale); - scaleNode(planetNames[0], scale); // using planetNames[0] because i know that will be the one visible after removing outer planets - // END SCALE - - // MOVE STAR - starSemiMajorAxis *= 149597871.0; // in km - moveStar(starName, starSemiMajorAxis); - - // SHOW ONE PLANET - // for planets found with doppler method, the radius is not always known. - //so this "fake" planet is shown for the sake of the vizualisation - toggleVisabilityPlanet(planetNames[0], "true"); - - // HIDE THE REST OF THE PLANETS - // in some cases there are multiple planets in the system, but for the viz only one can be shown - toggleVisabilityOuterPlanets(planetNames, "false"); - - // SHOW GRAPHS - addDopplerGraphs(); - - - // HELPER MARKERS - glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); - glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); - //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); - // END MARKERS -} - -void DiscoveryMethods::removeDopplerMethodVisualization() { - std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planetNames = global::moduleEngine.module()->planetNames(); - std::vector planets = global::moduleEngine.module()->planetSystem(); - - //SCALE STAR AND PLANET - scaleNode(starName + "Globe", 1.0); - scaleNode(planetNames[0], 1.0); - - // MOVE STAR - moveStar(starName, 0.0); - - //HIDE THE PLANET (if it was hidden from the start) - if (isnan(planets[0].R)) { - toggleVisabilityPlanet(planetNames[0], "false"); - } - - // SHOW THE REST OF THE PLANETS - toggleVisabilityOuterPlanets(planetNames, "true"); - - // HIDE GRAPHS - std::string script = "openspace.removeScreenSpaceRenderable('DopplerShift1'); openspace.removeScreenSpaceRenderable('DopplerShift2');"; - global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - //REMOVE HELP MARKERS - //removeDirectionsMarkers(); -} - -void DiscoveryMethods::addTransitMethodVisualization() { - const SceneGraphNode* focusNode = global::navigationHandler.anchorNode(); - std::string starName = global::moduleEngine.module()->getStarName(); // getStarName - glm::dvec3 starPosition = focusNode->worldPosition(); // can get from Exoplanet.POSITIONX/.POSITIONY/.POSITIONZ (in parsecs) - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - std::vector planets = global::moduleEngine.module()->planetSystem(); - std::vector planetNames = global::moduleEngine.module()->planetNames(); - - float semiMajorAxis = planets[0].A; // in AU (1AU = 149 597 870 700m) - float eccentricity = planets[0].ECC; - if (isnan(planets[0].ECC)) { - eccentricity = 0.0; - } - float starRadius = planets[0].RSTAR; // in Solar Radii - - // MOVE CAMERA - //borde kanske va periapsis distance, men det gÃ¥r bra ändÃ¥ - glm::dvec3 north = global::moduleEngine.module()->getNorthVector(); - //glm::dvec3 faceOnVector = glm::normalize(glm::cross(starToSunVec, north)); - glm::dvec3 cameraPosition = starPosition + ((4.0 * semiMajorAxis * 149597870700.0) * starToSunVec); - //glm::dvec3 cameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700.0) * faceOnVector); - - moveCamera(cameraPosition); - // END CAMERA - toggleVisabilityPlanet(planetNames[0], "true"); - - // SCALE BOTH STAR AND PLANET - // want star to take up 2/3 of the radius, the radius is as smallest at the periapsis - float periapsisDistance = semiMajorAxis * (1.0 - eccentricity); // in AU - periapsisDistance *= 149597870700.0; // in m - starRadius *= 6.957E8; // in m - - float scale = (0.5 * periapsisDistance) / starRadius; // actual radius * scale = wanted radius - scaleNode(starName + "Globe", scale); - scaleNode(planetNames[0], scale); //eller använda getPlna()? - _transitScaleFactor = scale; - // END SCALE - - // ADD THE GRAPH - addTransitGraphs(); - // END GRAPH - - // HELPER MARKERS - - glm::dvec3 northDirectionPos = starPosition + (double(starRadius * scale) * north); - glm::dvec3 viewDirectionPos = starPosition + (double(starRadius * scale) * starToSunVec); - //addDirectionsMarkers(viewDirectionPos, northDirectionPos, starRadius); - // END MARKERS -} - -void DiscoveryMethods::removeTransitMethodVisualization() { - std::vector planetNames = global::moduleEngine.module()->planetNames(); - //SCALE STAR AND PLANET - std::string starName = global::moduleEngine.module()->getStarName(); - scaleNode(starName + "Globe", 1); - scaleNode(planetNames[0], 1); - - // REMOVE GRAPH - std::string script = "openspace.removeScreenSpaceRenderable('Transit3');" - "openspace.removeScreenSpaceRenderable('Transit2');" - "openspace.removeScreenSpaceRenderable('Transit1');"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - //REMOVE HELP MARKERS - //removeDirectionsMarkers(); -} - -void DiscoveryMethods::addSolarSystemReferenceVisualization() { - std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planets = global::moduleEngine.module()->planetSystem(); - std::vector planetNames = global::moduleEngine.module()->planetNames(); - - // SUN - const std::string sunRef = "{" - "Identifier = 'SunReference'," - "Parent = '" + starName + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = 6.957E8," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m - "Billboard = true," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," - "BlendMode = 'Additive'" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {0, 0, 0}," //"+ std::to_string(planets[0].RSTAR) + "* 6.957E8 - "}," - "}," - "}"; - - std::string script = "openspace.addSceneGraphNode(" + sunRef + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - // EARTH - for (int i = 0; i < planetNames.size(); i++) - { - const std::string earthRef = "{" - "Identifier = 'EarthReference" + std::to_string(i) + "'," - "Parent = '" + planetNames[i] + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = 6378137," // in meters - "Billboard = true," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," - "BlendMode = 'Additive'" - "}," - "Transform = {" - "Translation = {" - "Type = 'StaticTranslation'," - "Position = {0, 0, 0}," //Jupiter radii to m " + std::to_string(planets[0].R) + "* 7.1492E7 - "}," - "}," - "}"; - script = ""; - script = "openspace.addSceneGraphNode(" + earthRef + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } - - glm::dmat3 rotation = global::moduleEngine.module()->getRotation(); - - // ORBIT - const std::string orbitRef = "{" - "Identifier = 'OrbitReference'," - "Parent = '" + starName + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = 1.496E11," // earths semi-major axis in m - "Billboard = false," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/target-blue-ring.png')," - "BlendMode = 'Additive'" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rotation) + "," - "}" - "}," - "}"; - script = ""; - script = "openspace.addSceneGraphNode(" + orbitRef + ");"; - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -void DiscoveryMethods::removeSolarSystemReferenceVisualization() { - std::string script = "openspace.removeSceneGraphNode('SunReference');" - "openspace.removeSceneGraphNode('EarthReference');" - "openspace.removeSceneGraphNode('OrbitReference');"; - - openspace::global::scriptEngine.queueScript( - script, - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); -} - -DiscoveryMethods::DiscoveryMethods() - : PropertyOwner({ "DiscoveryMethods" }) - , _showTransit(TransitMethodInfo, false) - , _showDoppler(DopplerMethodInfo, false) - , _showSolarSystemReference(SolarSystemReferenceInfo, false) -{ - _showTransit.onChange([&]() { - if (_showTransit) { //just changed to true - if (_showDoppler) { //only one viz at the time - _showDoppler = false; - removeDopplerMethodVisualization(); - } - addTransitMethodVisualization(); - } - else { //just changed to false - removeTransitMethodVisualization(); - } - }); - addProperty(_showTransit); - - _showDoppler.onChange([&]() { - if (_showDoppler) { //just changed to true - if (_showTransit) { - _showTransit = false; - removeTransitMethodVisualization(); - } - addDopplerMethodVisualization(); - } - else { //just changed to false - removeDopplerMethodVisualization(); - } - }); - addProperty(_showDoppler); - - _showSolarSystemReference.onChange([&]() { - if (_showSolarSystemReference) { - addSolarSystemReferenceVisualization(); - } - else { - removeSolarSystemReferenceVisualization(); - } - }); - addProperty(_showSolarSystemReference); -} - -} // namespce diff --git a/modules/exoplanets/discoverymethods/discoverymethods.h b/modules/exoplanets/discoverymethods/discoverymethods.h deleted file mode 100644 index 958d471188..0000000000 --- a/modules/exoplanets/discoverymethods/discoverymethods.h +++ /dev/null @@ -1,68 +0,0 @@ -/***************************************************************************************** -* * -* OpenSpace * -* * -* Copyright (c) 2014-2018 * -* * -* Permission is hereby granted, free of charge, to any person obtaining a copy of this * -* software and associated documentation files (the "Software"), to deal in the Software * -* without restriction, including without limitation the rights to use, copy, modify, * -* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * -* permit persons to whom the Software is furnished to do so, subject to the following * -* conditions: * -* * -* The above copyright notice and this permission notice shall be included in all copies * -* or substantial portions of the Software. * -* * -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * -* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * -* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * -* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * -* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * -* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * -****************************************************************************************/ - -#ifndef __OPENSPACE_MODULE_EXOPLANETS___DISCOVERY_METHODS___H__ -#define __OPENSPACE_MODULE_EXOPLANETS___DISCOVERY_METHODS___H__ - -#include -#include - -namespace openspace::exoplanets { - -class DiscoveryMethods : public properties::PropertyOwner { -public: - DiscoveryMethods(); - bool isDoppler(); - bool isTransit(); - bool isReference(); - void setDopplerImagePos(float); - void setTransitImagePos(float,float); - float getTransitScaleFactor(); - -private: - properties::BoolProperty _showTransit; - properties::BoolProperty _showDoppler; - properties::BoolProperty _showSolarSystemReference; - - void addSolarSystemReferenceVisualization(); - void removeSolarSystemReferenceVisualization(); - void addTransitMethodVisualization(); - void removeTransitMethodVisualization(); - void addDopplerMethodVisualization(); - void removeDopplerMethodVisualization(); - - void addDirectionsMarkers(glm::dvec3, glm::dvec3, float); - void removeDirectionsMarkers(); - void scaleNode(std::string, float); - void moveStar(std::string, float); - void moveCamera(glm::dvec3); - void toggleVisabilityOuterPlanets(std::vector, std::string); - void toggleVisabilityPlanet(std::string, std::string); - - float _transitScaleFactor; -}; - -} // namespace - -#endif // __OPENSPACE_MODULE_EXOPLANETS___TRANSIT_METHOD___H__ diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 43ecb92890..4d0f40eea5 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -46,54 +46,6 @@ using namespace exoplanets; ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} -void ExoplanetsModule::setClosestExoplanet(Exoplanet closestExo) { - _exo = closestExo; -} - -Exoplanet ExoplanetsModule::closestExoplanet() { - return _exo; -} - -void ExoplanetsModule::setStarName(std::string starName) { - _starName = starName; -} - -std::string ExoplanetsModule::getStarName() { - return _starName; -} - -void ExoplanetsModule::setPlanetSystem(std::vector planets) { - _planetSystem = planets; -} - -std::vector ExoplanetsModule::planetSystem() { - return _planetSystem; -} - -void ExoplanetsModule::setPlanetNames(std::vector names) { - _planetNames = names; -} - -std::vector ExoplanetsModule::planetNames() { - return _planetNames; -} - -void ExoplanetsModule::setRotation(glm::dmat3 rot) { - _rotation = rot; -} - -glm::dmat3 ExoplanetsModule::getRotation() { - return _rotation; -} - -void ExoplanetsModule::setNorthVector(glm::dvec3 vector) { - _north = vector; -} - -glm::dvec3 ExoplanetsModule::getNorthVector() { - return _north; -} - scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { scripting::LuaLibrary res; res.name = "exoplanets"; @@ -123,90 +75,6 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { ghoul_assert(fTask, "No task factory existed"); fTask->registerClass("ExoplanetsCsvToBinTask"); fRenderable->registerClass("RenderableOrbitdisc"); - - global::callback::initializeGL.push_back([&]() { - _discoveryMethods = std::make_unique(); - addPropertySubOwner(*_discoveryMethods); - }); - - // Render - global::callback::render.push_back([&]() { - if (_discoveryMethods->isDoppler()) { - std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planetNames = global::moduleEngine.module()->planetNames(); - SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); - SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); - glm::dvec3 planetPos = planetNode->worldPosition(); - glm::dvec3 starPos = starNode->worldPosition(); - glm::dvec3 starToPosVec = normalize(planetPos - starPos); - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPos); - glm::dvec3 north = glm::dvec3(0.0, 0.0, 1.0); - glm::dvec3 northProjected = glm::normalize( - glm::length(north) * glm::sin(glm::dot(north, starToSunVec)) * glm::cross(starToSunVec, glm::cross(north, starToSunVec)) - ); - float northAngle = glm::acos(glm::dot(starToPosVec, northProjected)) * 57.2957795f; - float viewAngle = glm::acos(glm::dot(starToPosVec, starToSunVec)) * 57.2957795f; - - float imagePos = 0.0f; - if ( viewAngle <= 90.f && northAngle <= 90.f) { - imagePos = viewAngle / -90.f; - } - else if (viewAngle > 90.f && northAngle <= 90.f) { - imagePos = (180.f - viewAngle) / -90.f; - } - else if (viewAngle > 90.f && northAngle > 90.f) { - imagePos = (180.f - viewAngle) / 90.f; - } - else if (viewAngle <= 90.f && northAngle > 90.f) { - imagePos = viewAngle / 90.f; - } - - imagePos *= 0.01f; - _discoveryMethods->setDopplerImagePos(imagePos); - } - - if (_discoveryMethods->isTransit()) { - std::string starName = global::moduleEngine.module()->getStarName(); - std::vector planetNames = global::moduleEngine.module()->planetNames(); - const SceneGraphNode* planetNode = global::renderEngine.scene()->sceneGraphNode(planetNames[0]); - const SceneGraphNode* starNode = global::renderEngine.scene()->sceneGraphNode(starName); - glm::dvec3 planetPosition = planetNode->worldPosition(); - glm::dvec3 starPosition = starNode->worldPosition(); - - glm::dvec3 starToPosVec = planetPosition - starPosition; - glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition); - - std::vector planets = global::moduleEngine.module()->planetSystem(); - float starRadius = planets[0].RSTAR * 6.957E8f * _discoveryMethods->getTransitScaleFactor(); // in m - - float northAngle = glm::acos(glm::dot(normalize(starToPosVec), _north)) * 57.2957795f; - float viewAngle = glm::acos(glm::dot(normalize(starToPosVec), starToSunVec)) * 57.2957795f; - - glm::dvec3 posVecProjected = starToPosVec - (((dot(starToPosVec, starToSunVec)) / (glm::length(starToSunVec)))*starToSunVec); - float l = static_cast(glm::length(posVecProjected)); //in m - float imageYPos = -0.6f; - - if (l < (starRadius * 0.82f) && viewAngle <= 90.f) { - imageYPos = -0.8f; - } - - float imageXPos = 0.f; - if (viewAngle <= 90.f && northAngle <= 90.f) { - imageXPos = (viewAngle / 90.f) * 0.5f; - } - else if (viewAngle > 90.f && northAngle <= 90.f) { - imageXPos = (viewAngle / 90.f) * 0.5f; - } - else if (viewAngle > 90.f && northAngle > 90.f) { - imageXPos = (viewAngle / 90.f) * -0.5f; - } - else if (viewAngle <= 90.f && northAngle > 90.f) { - imageXPos = (viewAngle / 90.f) * -0.5f; - } - imageXPos *= 0.5f; - _discoveryMethods->setTransitImagePos(imageXPos, imageYPos); - } - }); } std::vector ExoplanetsModule::documentations() const { diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index f62271ac3d..f6b7778280 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -25,7 +25,6 @@ #ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ -#include #include #include @@ -83,33 +82,10 @@ public: virtual ~ExoplanetsModule() = default; scripting::LuaLibrary luaLibrary() const override; - std::vector documentations() const override; - void setClosestExoplanet(Exoplanet); - void setStarName(std::string); - void setPlanetSystem(std::vector); - void setPlanetNames(std::vector); - void setRotation(glm::dmat3); - void setNorthVector(glm::dvec3); - - Exoplanet closestExoplanet(); - std::string getStarName(); - std::vector planetSystem(); - std::vector planetNames(); - glm::dmat3 getRotation(); - glm::dvec3 getNorthVector(); - protected: void internalInitialize(const ghoul::Dictionary&) override; - std::unique_ptr _discoveryMethods; - - Exoplanet _exo; - std::string _starName; - std::vector _planetSystem; - std::vector _planetNames; - glm::dmat3 _rotation; - glm::dvec3 _north; }; } // namespace openspace diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index fff404548d..6c88f45af2 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -320,8 +320,6 @@ int addExoplanetSystem(lua_State* L) { std::string starNameSpeck = getSpeckStarname(starName); std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); - global::moduleEngine.module()->setStarName(starNameSpeck); - std::ifstream data( absPath("${MODULE_EXOPLANETS}/expl_data.bin"), std::ios::in | std::ios::binary @@ -367,9 +365,6 @@ int addExoplanetSystem(lua_State* L) { data.close(); lut.close(); - global::moduleEngine.module()->setPlanetNames(planetNames); - global::moduleEngine.module()->setPlanetSystem(planetSystem); - global::moduleEngine.module()->setClosestExoplanet(p); if (!found || isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER)) { // || p.BINARY return ghoul::lua::luaError(L, "No star with that name or not enough data about it."); @@ -397,7 +392,6 @@ int addExoplanetSystem(lua_State* L) { // Earths north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec))) * starToSunVec)); - global::moduleEngine.module()->setNorthVector(northProjected); glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); @@ -638,7 +632,6 @@ int addExoplanetSystem(lua_State* L) { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(planet.I, planet.BIGOM, planet.OM, exoplanetSystemRotation); glm::dmat3 rotation = orbitPlaneRotationMatrix; - global::moduleEngine.module()->setRotation(rotation); const std::string discNode = "{" "Identifier = '" + planetName + "Disc'," "Parent = '" + starNameSpeck + "'," From 99720d95caea3863c5edb35ff4f41e83154f652b Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 28 Aug 2020 11:06:38 +0200 Subject: [PATCH 079/123] Helper file for exoplanet data structure and replace magic numbers with constants --- include/openspace/util/distanceconstants.h | 2 + modules/exoplanets/CMakeLists.txt | 2 + modules/exoplanets/exoplanetshelper.cpp | 217 ++++++++++++++++ modules/exoplanets/exoplanetshelper.h | 83 ++++++ modules/exoplanets/exoplanetsmodule.h | 44 ---- modules/exoplanets/exoplanetsmodule_lua.inl | 243 ++---------------- .../rendering/renderableorbitdisc.cpp | 4 +- .../tasks/exoplanetscsvtobintask.cpp | 99 +------ .../exoplanets/tasks/exoplanetscsvtobintask.h | 46 ---- 9 files changed, 337 insertions(+), 403 deletions(-) create mode 100644 modules/exoplanets/exoplanetshelper.cpp create mode 100644 modules/exoplanets/exoplanetshelper.h diff --git a/include/openspace/util/distanceconstants.h b/include/openspace/util/distanceconstants.h index 8bb599cc04..e488cce1f9 100644 --- a/include/openspace/util/distanceconstants.h +++ b/include/openspace/util/distanceconstants.h @@ -27,6 +27,8 @@ namespace openspace::distanceconstants { constexpr double EarthRadius = 6371; + constexpr double JupiterRadius = 7.1492E7; + constexpr double SolarRadius = 6.95700E8; constexpr double LightYear = 9.4607304725808E15; constexpr double LightMonth = LightYear / 12; constexpr double LightDay = LightYear / 365; diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index 2b34dd0c4f..c69c11e49c 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -25,6 +25,7 @@ include(${OPENSPACE_CMAKE_EXT_DIR}/module_definition.cmake) set(HEADER_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetshelper.h ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.h ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.h ${CMAKE_CURRENT_SOURCE_DIR}/tasks/exoplanetscsvtobintask.h @@ -32,6 +33,7 @@ set(HEADER_FILES source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetshelper.cpp ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule.cpp ${CMAKE_CURRENT_SOURCE_DIR}/exoplanetsmodule_lua.inl ${CMAKE_CURRENT_SOURCE_DIR}/rendering/renderableorbitdisc.cpp diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp new file mode 100644 index 0000000000..67187b76d8 --- /dev/null +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -0,0 +1,217 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +namespace openspace::exoplanets { + +std::string getSpeckStarname(std::string csvName) { + std::string explName = csvName; + if (csvName == "HD 1237") + explName = "GJ 3021"; + else if (csvName == "MOA-2009-BLG-387L") + explName = "MOA 2009-BLG-387L"; + else if (csvName == "HD 126614 A") + explName = "HD 126614"; + else if (csvName == "epsilon Ret") + explName = "HD 27442"; + else if (csvName == "PH-1") + explName = "PH1"; + else if (csvName == "gamma Leo A") + explName = "gam 1 Leo"; + else if (csvName == "OGLE-2007-BLG-368L") + explName = "OGLE 2007-BLG-368L"; + else if (csvName == "alpha Ari") + explName = "alf Ari"; + else if (csvName == "mu Ara") + explName = "HD 160691"; + else if (csvName == "OGLE-05-169L") + explName = "OGLE 2005-BLG-169L"; + else if (csvName == "tau Gru") + explName = "HD 216435"; + else if (csvName == "iota Hor") + explName = "HR 810"; + else if (csvName == "OGLE-05-071L") + explName = "OGLE 2005-BLG-71L"; + else if (csvName == "OGLE235-MOA53") + explName = "OGLE 2003-BLG-235L"; + else if (csvName == "MOA-2008-BLG-310L") + explName = "MOA 2008-BLG-310L"; + else if (csvName == "KIC 11442793") + explName = "KOI-351"; + else if (csvName == "OGLE-2006-BLG-109L") + explName = "OGLE 2006-BLG-109L"; + else if (csvName == "HD 137388") + explName = "HD 137388 A"; + else if (csvName == "kappa CrB") + explName = "kap CrB"; + else if (csvName == "XO-2") + explName = "XO-2 N"; + else if (csvName == "epsilon Tau") + explName = "eps Tau"; + else if (csvName == "epsilon Eri") + explName = "eps Eri"; + else if (csvName == "Kepler-448") + explName = "KOI-12"; + else if (csvName == "omega Ser") + explName = "ome Ser"; + else if (csvName == "MOA-2010-BLG-477L") + explName = "MOA 2010-BLG-477L"; + else if (csvName == "GJ 176") + explName = "HD 285968"; + else if (csvName == "HIP 2247") + explName = "BD-17 63"; + else if (csvName == "MOA-2009-BLG-266L") + explName = "MOA 2009-BLG-266L"; + else if (csvName == "Kepler-89") + explName = "KOI-94"; + else if (csvName == "iota Dra") + explName = "HIP 75458"; + else if (csvName == "MOA-2007-BLG-400L") + explName = "MOA 2007-BLG-400L"; + else if (csvName == "upsilon And") + explName = "ups And"; + else if (csvName == "OGLE-2011-BLG-0251") + explName = "OGLE 2011-BLG-251L"; + else if (csvName == "OGLE-05-390L") + explName = "OGLE 2005-BLG-390L"; + else if (csvName == "Kepler-420") + explName = "KOI-1257"; + else if (csvName == "beta Pic") + explName = "bet Pic"; + else if (csvName == "gamma Cep") + explName = "gam Cep"; + else if (csvName == "MOA-2007-BLG-192L") + explName = "MOA 2007-BLG-192L"; + else if (csvName == "MOA-2009-BLG-319L") + explName = "MOA 2009-BLG-319L"; + else if (csvName == "omicron CrB") + explName = "omi CrB"; + else if (csvName == "beta Gem") + explName = "HD 62509"; + else if (csvName == "epsilon CrB") + explName = "eps CrB"; + else if (csvName == "omicron UMa") + explName = "omi UMa"; + else if (csvName == "HD 142022") + explName = "HD 142022 A"; + + return explName; +} + +std::string getCsvStarname(std::string explName) { + std::string csvName = explName; + if (explName == "GJ 3021") + csvName = "HD 1237"; + else if (explName == "MOA 2009-BLG-387L") + csvName = "MOA-2009-BLG-387L"; + else if (explName == "HD 126614") + csvName = "HD 126614 A"; + else if (explName == "HD 27442") + csvName = "epsilon Ret"; + else if (explName == "PH1") + csvName = "PH-1"; + else if (explName == "gam 1 Leo") + csvName = "gamma Leo A"; + else if (explName == "OGLE 2007-BLG-368L") + csvName = "OGLE-2007-BLG-368L"; + else if (explName == "alf Ari") + csvName = "alpha Ari"; + else if (explName == "HD 160691") + csvName = "mu Ara"; + else if (explName == "OGLE 2005-BLG-169L") + csvName = "OGLE-05-169L"; + else if (explName == "HD 216435") + csvName = "tau Gru"; + else if (explName == "HR 810") + csvName = "iota Hor"; + else if (explName == "OGLE 2005-BLG-71L") + csvName = "OGLE-05-071L"; + else if (explName == "OGLE 2003-BLG-235L") + csvName = "OGLE235-MOA53"; + else if (explName == "MOA 2008-BLG-310L") + csvName = "MOA-2008-BLG-310L"; + else if (explName == "KOI-351") + csvName = "KIC 11442793"; + else if (explName == "OGLE 2006-BLG-109L") + csvName = "OGLE-2006-BLG-109L"; + else if (explName == "HD 137388 A") + csvName = "HD 137388"; + else if (explName == "kap CrB") + csvName = "kappa CrB"; + else if (explName == "XO-2 N") + csvName = "XO-2"; + else if (explName == "eps Tau") + csvName = "epsilon Tau"; + else if (explName == "eps Eri") + csvName = "epsilon Eri"; + else if (explName == "KOI-12") + csvName = "Kepler-448"; + else if (explName == "ome Ser") + csvName = "omega Ser"; + else if (explName == "MOA 2010-BLG-477L") + csvName = "MOA-2010-BLG-477L"; + else if (explName == "HD 285968") + csvName = "GJ 176"; + else if (explName == "BD-17 63") + csvName = "HIP 2247"; + else if (explName == "MOA 2009-BLG-266L") + csvName = "MOA-2009-BLG-266L"; + else if (explName == "KOI-94") + csvName = "Kepler-89"; + else if (explName == "HIP 75458") + csvName = "iota Dra"; + else if (explName == "MOA 2007-BLG-400L") + csvName = "MOA-2007-BLG-400L"; + else if (explName == "ups And") + csvName = "upsilon And"; + else if (explName == "OGLE 2011-BLG-251L") + csvName = "OGLE-2011-BLG-0251"; + else if (explName == "OGLE 2005-BLG-390L") + csvName = "OGLE-05-390L"; + else if (explName == "KOI-1257") + csvName = "Kepler-420"; + else if (explName == "bet Pic") + csvName = "beta Pic"; + else if (explName == "gam Cep") + csvName = "gamma Cep"; + else if (explName == "MOA 2007-BLG-192L") + csvName = "MOA-2007-BLG-192L"; + else if (explName == "MOA 2009-BLG-319L") + csvName = "MOA-2009-BLG-319L"; + else if (explName == "omi CrB") + csvName = "omicron CrB"; + else if (explName == "HD 62509") + csvName = "beta Gem"; + else if (explName == "eps CrB") + csvName = "epsilon CrB"; + else if (explName == "omi UMa") + csvName = "omicron UMa"; + else if (explName == "HD 142022 A") + csvName = "HD 142022"; + + return csvName; +} + +} // namespace openspace::exoplanets diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h new file mode 100644 index 0000000000..6a8061e5e5 --- /dev/null +++ b/modules/exoplanets/exoplanetshelper.h @@ -0,0 +1,83 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2018 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANET_HELPER___H__ +#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANET_HELPER___H__ + +#include + +namespace openspace::exoplanets { + +struct Exoplanet { + float A; // Orbital semi-major axis in AU + double AUPPER; // Upper uncertainty of orbital semi-major axis + double ALOWER; // Lower uncertainty of orbital semi-major axis + double UA; // Uncertainty of orbital semi-major axis + float BIGOM; // Longitude of ascending node in degrees + float BIGOMUPPER; // Upper uncertainty of longitude of ascending node + float BIGOMLOWER; // Lower uncertainty of longitude of ascending node + float UBIGOM; // Uncertainty of longitude of ascending node + bool BINARY; // Star known to be binary? + float BMV; // B − V color + float ECC; // Orbital eccentricity + float ECCUPPER; // Upper uncertainty of orbital eccentricity + float ECCLOWER; // Lower uncertainty of orbital eccentricity + float UECC; // Uncertainty of orbital eccentricity + float I; // Orbital inclination in degrees (for transiting systems only) + float IUPPER; // Upper uncertainty of orbital inclination + float ILOWER; // Lower uncertainty of orbital inclination + float UI; // Uncertainty of orbital inclination + int NCOMP; // Number of planetary companions known + float OM; // Argument of periastron in degrees + float OMUPPER; // Upper uncertainty of argument of periastron + float OMLOWER; // Lower uncertainty of argument of periastron + float UOM; // Uncertainty of argument of periastron + double PER; // Orbital period in days + float PERUPPER; // Upper uncertainty of period + float PERLOWER; // Lower uncertainty of period + float UPER; // Uncertainty of period + double R; // Radius of the planet in Jupiter radii + double RUPPER; // Upper uncertainty of radius of the planet + double RLOWER; // Lower uncertainty of radius of the planet + double UR; // Uncertainty of radius of the planet + float RSTAR; // Estimated radius of the star in solar radii + float RSTARUPPER; // Upper uncertainty of estimated star radius + float RSTARLOWER; // Lower uncertainty of estimated star radius + float URSTAR; // Uncertainty of estimated star radius + double TT; // Epoch of transit center in HJD-2440000 + float TTUPPER; // Upper uncertainty of epoch of transit center + float TTLOWER; // Lower uncertainty of epoch of transit center + float UTT; // Uncertainty of epoch of transit center + float POSITIONX; // Star position's X-coordinate in parsec + float POSITIONY; // Star position's Y-coordinate in parsec + float POSITIONZ; // Star position's Z-coordinate in parsec +}; + +std::string getSpeckStarname(std::string csvName); + +std::string getCsvStarname(std::string explName); + +} // namespace openspace::exoplanets + +#endif // __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index f6b7778280..cf6d4e31ac 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -29,50 +29,6 @@ #include namespace openspace { - struct Exoplanet { - float A; - double AUPPER; - double ALOWER; - double UA; - float BIGOM; - float BIGOMUPPER; - float BIGOMLOWER; - float UBIGOM; - bool BINARY; - float BMV; - float ECC; - float ECCUPPER; - float ECCLOWER; - float UECC; - float I; - float IUPPER; - float ILOWER; - float UI; - int NCOMP; - float OM; - float OMUPPER; - float OMLOWER; - float UOM; - double PER; - float PERUPPER; - float PERLOWER; - float UPER; - double R; - double RUPPER; - double RLOWER; - double UR; - float RSTAR; - float RSTARUPPER; - float RSTARLOWER; - float URSTAR; - double TT; - float TTUPPER; - float TTLOWER; - float UTT; - float POSITIONX; - float POSITIONY; - float POSITIONZ; - }; class ExoplanetsModule : public OpenSpaceModule { public: diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 6c88f45af2..874504b6c4 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -22,10 +22,13 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ +#include #include #include #include +#include #include +#include #include #include #include @@ -83,194 +86,6 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm: return orbitPlaneRotation; } -std::string getSpeckStarname(std::string csvName) { - std::string explName = csvName; - if (csvName == "HD 1237") - explName = "GJ 3021"; - else if (csvName == "MOA-2009-BLG-387L") - explName = "MOA 2009-BLG-387L"; - else if (csvName == "HD 126614 A") - explName = "HD 126614"; - else if (csvName == "epsilon Ret") - explName = "HD 27442"; - else if (csvName == "PH-1") - explName = "PH1"; - else if (csvName == "gamma Leo A") - explName = "gam 1 Leo"; - else if (csvName == "OGLE-2007-BLG-368L") - explName = "OGLE 2007-BLG-368L"; - else if (csvName == "alpha Ari") - explName = "alf Ari"; - else if (csvName == "mu Ara") - explName = "HD 160691"; - else if (csvName == "OGLE-05-169L") - explName = "OGLE 2005-BLG-169L"; - else if (csvName == "tau Gru") - explName = "HD 216435"; - else if (csvName == "iota Hor") - explName = "HR 810"; - else if (csvName == "OGLE-05-071L") - explName = "OGLE 2005-BLG-71L"; - else if (csvName == "OGLE235-MOA53") - explName = "OGLE 2003-BLG-235L"; - else if (csvName == "MOA-2008-BLG-310L") - explName = "MOA 2008-BLG-310L"; - else if (csvName == "KIC 11442793") - explName = "KOI-351"; - else if (csvName == "OGLE-2006-BLG-109L") - explName = "OGLE 2006-BLG-109L"; - else if (csvName == "HD 137388") - explName = "HD 137388 A"; - else if (csvName == "kappa CrB") - explName = "kap CrB"; - else if (csvName == "XO-2") - explName = "XO-2 N"; - else if (csvName == "epsilon Tau") - explName = "eps Tau"; - else if (csvName == "epsilon Eri") - explName = "eps Eri"; - else if (csvName == "Kepler-448") - explName = "KOI-12"; - else if (csvName == "omega Ser") - explName = "ome Ser"; - else if (csvName == "MOA-2010-BLG-477L") - explName = "MOA 2010-BLG-477L"; - else if (csvName == "GJ 176") - explName = "HD 285968"; - else if (csvName == "HIP 2247") - explName = "BD-17 63"; - else if (csvName == "MOA-2009-BLG-266L") - explName = "MOA 2009-BLG-266L"; - else if (csvName == "Kepler-89") - explName = "KOI-94"; - else if (csvName == "iota Dra") - explName = "HIP 75458"; - else if (csvName == "MOA-2007-BLG-400L") - explName = "MOA 2007-BLG-400L"; - else if (csvName == "upsilon And") - explName = "ups And"; - else if (csvName == "OGLE-2011-BLG-0251") - explName = "OGLE 2011-BLG-251L"; - else if (csvName == "OGLE-05-390L") - explName = "OGLE 2005-BLG-390L"; - else if (csvName == "Kepler-420") - explName = "KOI-1257"; - else if (csvName == "beta Pic") - explName = "bet Pic"; - else if (csvName == "gamma Cep") - explName = "gam Cep"; - else if (csvName == "MOA-2007-BLG-192L") - explName = "MOA 2007-BLG-192L"; - else if (csvName == "MOA-2009-BLG-319L") - explName = "MOA 2009-BLG-319L"; - else if (csvName == "omicron CrB") - explName = "omi CrB"; - else if (csvName == "beta Gem") - explName = "HD 62509"; - else if (csvName == "epsilon CrB") - explName = "eps CrB"; - else if (csvName == "omicron UMa") - explName = "omi UMa"; - else if (csvName == "HD 142022") - explName = "HD 142022 A"; - - return explName; -} - -std::string getCsvStarname(std::string explName) { - std::string csvName = explName; - if (explName == "GJ 3021") - csvName = "HD 1237"; - else if (explName == "MOA 2009-BLG-387L") - csvName = "MOA-2009-BLG-387L"; - else if (explName == "HD 126614") - csvName = "HD 126614 A"; - else if (explName == "HD 27442") - csvName = "epsilon Ret"; - else if (explName == "PH1") - csvName = "PH-1"; - else if (explName == "gam 1 Leo") - csvName = "gamma Leo A"; - else if (explName == "OGLE 2007-BLG-368L") - csvName = "OGLE-2007-BLG-368L"; - else if (explName == "alf Ari") - csvName = "alpha Ari"; - else if (explName == "HD 160691") - csvName = "mu Ara"; - else if (explName == "OGLE 2005-BLG-169L") - csvName = "OGLE-05-169L"; - else if (explName == "HD 216435") - csvName = "tau Gru"; - else if (explName == "HR 810") - csvName = "iota Hor"; - else if (explName == "OGLE 2005-BLG-71L") - csvName = "OGLE-05-071L"; - else if (explName == "OGLE 2003-BLG-235L") - csvName = "OGLE235-MOA53"; - else if (explName == "MOA 2008-BLG-310L") - csvName = "MOA-2008-BLG-310L"; - else if (explName == "KOI-351") - csvName = "KIC 11442793"; - else if (explName == "OGLE 2006-BLG-109L") - csvName = "OGLE-2006-BLG-109L"; - else if (explName == "HD 137388 A") - csvName = "HD 137388"; - else if (explName == "kap CrB") - csvName = "kappa CrB"; - else if (explName == "XO-2 N") - csvName = "XO-2"; - else if (explName == "eps Tau") - csvName = "epsilon Tau"; - else if (explName == "eps Eri") - csvName = "epsilon Eri"; - else if (explName == "KOI-12") - csvName = "Kepler-448"; - else if (explName == "ome Ser") - csvName = "omega Ser"; - else if (explName == "MOA 2010-BLG-477L") - csvName = "MOA-2010-BLG-477L"; - else if (explName == "HD 285968") - csvName = "GJ 176"; - else if (explName == "BD-17 63") - csvName = "HIP 2247"; - else if (explName == "MOA 2009-BLG-266L") - csvName = "MOA-2009-BLG-266L"; - else if (explName == "KOI-94") - csvName = "Kepler-89"; - else if (explName == "HIP 75458") - csvName = "iota Dra"; - else if (explName == "MOA 2007-BLG-400L") - csvName = "MOA-2007-BLG-400L"; - else if (explName == "ups And") - csvName = "upsilon And"; - else if (explName == "OGLE 2011-BLG-251L") - csvName = "OGLE-2011-BLG-0251"; - else if (explName == "OGLE 2005-BLG-390L") - csvName = "OGLE-05-390L"; - else if (explName == "KOI-1257") - csvName = "Kepler-420"; - else if (explName == "bet Pic") - csvName = "beta Pic"; - else if (explName == "gam Cep") - csvName = "gamma Cep"; - else if (explName == "MOA 2007-BLG-192L") - csvName = "MOA-2007-BLG-192L"; - else if (explName == "MOA 2009-BLG-319L") - csvName = "MOA-2009-BLG-319L"; - else if (explName == "omi CrB") - csvName = "omicron CrB"; - else if (explName == "HD 62509") - csvName = "beta Gem"; - else if (explName == "eps CrB") - csvName = "epsilon CrB"; - else if (explName == "omi UMa") - csvName = "omicron UMa"; - else if (explName == "HD 142022 A") - csvName = "HD 142022"; - - return csvName; -} - // Rotate the original coordinate system (where x is pointing to First Point of Aries) // so that x is pointing from star to the sun. // Modified from http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-find-the-rotation-between-2-vectors- @@ -355,7 +170,7 @@ int addExoplanetSystem(lua_State* L) { long location = std::stol(location_s.c_str()); data.seekg(location); - data.read((char*)&p, sizeof(struct Exoplanet)); + data.read((char*)&p, sizeof(Exoplanet)); planetNames.push_back(name); planetSystem.push_back(p); @@ -371,12 +186,10 @@ int addExoplanetSystem(lua_State* L) { } Time epoch; - const double parsec = 0.308567756E17; - glm::dvec3 starPosition = glm::dvec3( - p.POSITIONX * parsec, - p.POSITIONY * parsec, - p.POSITIONZ * parsec + p.POSITIONX * distanceconstants::Parsec, + p.POSITIONY * distanceconstants::Parsec, + p.POSITIONZ * distanceconstants::Parsec ); glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); @@ -441,16 +254,16 @@ int addExoplanetSystem(lua_State* L) { Exoplanet firstPlanet = planetSystem[0]; if (isnan(firstPlanet.ECC)) { - firstPlanet.ECC = 0; + firstPlanet.ECC = 0.f; } if (isnan(firstPlanet.I)) { - firstPlanet.I = 90; + firstPlanet.I = 90.f; } if (isnan(firstPlanet.BIGOM)) { - firstPlanet.BIGOM = 180; + firstPlanet.BIGOM = 180.f; } if (isnan(firstPlanet.OM)) { - firstPlanet.OM = 90; + firstPlanet.OM = 90.f; } std::string sEpochStar; if (!isnan(firstPlanet.TT)) { @@ -465,7 +278,7 @@ int addExoplanetSystem(lua_State* L) { "Parent = '" + starNameSpeck + "'," "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadius) + " * 6.957E8," + "Radii = " + std::to_string(starRadius * distanceconstants::SolarRadius) + "," "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" @@ -494,13 +307,13 @@ int addExoplanetSystem(lua_State* L) { "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(firstPlanet.ECC) + "," //ECC - "SemiMajorAxis = 0," // 149 597 871km = 1 AU. A + "SemiMajorAxis = 0," "Inclination = " + std::to_string(firstPlanet.I) + "," //I "AscendingNode = " + std::to_string(firstPlanet.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(firstPlanet.OM) + "," //OM "MeanAnomaly = 180.0," "Epoch = '" + sEpochStar + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(firstPlanet.PER) + "* 86400" //PER. 86 400sec = 1 day. + "Period = " + std::to_string(firstPlanet.PER * static_cast(SecondsPerDay)) + "," "}" "}" "}"; @@ -516,16 +329,16 @@ int addExoplanetSystem(lua_State* L) { std::string planetName = planetNames[i]; if (isnan(planet.ECC)) { - planet.ECC = 0; + planet.ECC = 0.f; } if (isnan(planet.I)) { - planet.I = 90; + planet.I = 90.f; } if (isnan(planet.BIGOM)) { - planet.BIGOM = 180; + planet.BIGOM = 180.f; } if (isnan(planet.OM)) { - planet.OM = 90; + planet.OM = 90.f; } std::string sEpoch; if (!isnan(planet.TT)) { @@ -540,15 +353,15 @@ int addExoplanetSystem(lua_State* L) { if (isnan(planet.R)) { if (isnan(planet.RSTAR)) { - planetRadius = planet.A * 149597870700.f * 0.001f; + planetRadius = planet.A * 0.001f * distanceconstants::AstronomicalUnit; } else { - planetRadius = planet.RSTAR * 6.95700E8f * 0.1f; + planetRadius = planet.RSTAR * distanceconstants::SolarRadius * 0.1f; } enabled = "false"; } else { - planetRadius = planet.R * 7.1492E7; // 1 jupiter radii = 7.1492×10e7 m + planetRadius = planet.R * distanceconstants::JupiterRadius; enabled = "true"; } @@ -580,13 +393,13 @@ int addExoplanetSystem(lua_State* L) { "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(planet.A) + " * 149597871," // 149 597 871km = 1 AU. A + "SemiMajorAxis = " + std::to_string(planet.A * 0.001f * distanceconstants::AstronomicalUnit) + "," // km "Inclination = " + std::to_string(planet.I) + "," //I "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(planet.PER) + "* 86400" //PER. 86 400sec = 1 day. + "Period = " + std::to_string(planet.PER * static_cast(SecondsPerDay)) + "," "}," "}," "}"; @@ -607,13 +420,13 @@ int addExoplanetSystem(lua_State* L) { "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(planet.A) + " * 149597871," // 149 597 871km = 1 AU. A + "SemiMajorAxis = " + std::to_string(planet.A * 0.001f * distanceconstants::AstronomicalUnit) + "," // km "Inclination = " + std::to_string(planet.I) + "," //I "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(planet.PER) + "* 86400" //PER. 86 400sec = 1 day. + "Period = " + std::to_string(planet.PER * static_cast(SecondsPerDay)) + "," "}," "Color = { 1, 1, 1 }" "}," @@ -639,7 +452,7 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," - "Size = " + std::to_string(planet.A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Size = " + std::to_string(planet.A * distanceconstants::AstronomicalUnit) + "," "Eccentricity = " + std::to_string(planet.ECC) + "," "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend "Opacity = 0.5" @@ -673,7 +486,7 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," - "Size = " + std::to_string(planet.A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Size = " + std::to_string(planet.A * distanceconstants::AstronomicalUnit) + "," "Eccentricity = " + std::to_string(lowerEccentricity) + "," "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend "Opacity = 0.98," @@ -703,7 +516,7 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," - "Size = " + std::to_string(planet.A) + " * 149597870700," // 149 597 870 700 m = 1 AU. A + "Size = " + std::to_string(planet.A * distanceconstants::AstronomicalUnit) + "," "Eccentricity = " + std::to_string(upperEccentricity) + "," "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend "Opacity = 0.98," diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index dcc2d80692..bdd85fe8ab 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -30,7 +30,7 @@ #include #include #include - +#include #include #include #include @@ -135,7 +135,7 @@ RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) addProperty(_offset); _size = static_cast(dictionary.value(SizeInfo.identifier)); - _size = _size + (_offset.value().y * 149597870700); + _size = _size + (_offset.value().y * distanceconstants::AstronomicalUnit); setBoundingSphere(_size); _size.onChange([&]() { _planeIsDirty = true; }); addProperty(_size); diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index ab03da3d43..af8fae1c10 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -62,100 +63,6 @@ std::string ExoplanetsCsvToBinTask::description() { " and write as bin to " + _outputBinPath; } -std::string ExoplanetsCsvToBinTask::getExoplanetName(std::string csvName) { - std::string name = csvName; - if (csvName == "HD 1237") - name = "GJ 3021"; - else if (csvName == "MOA-2009-BLG-387L") - name = "MOA 2009-BLG-387L"; - else if (csvName == "HD 126614 A") - name = "HD 126614"; - else if (csvName == "epsilon Ret") - name = "HD 27442"; - else if (csvName == "PH-1") - name = "PH1"; - else if (csvName == "gamma Leo A") - name = "gam 1 Leo"; - else if (csvName == "OGLE-2007-BLG-368L") - name = "OGLE 2007-BLG-368L"; - else if (csvName == "alpha Ari") - name = "alf Ari"; - else if (csvName == "mu Ara") - name = "HD 160691"; - else if (csvName == "OGLE-05-169L") - name = "OGLE 2005-BLG-169L"; - else if (csvName == "tau Gru") - name = "HD 216435"; - else if (csvName == "iota Hor") - name = "HR 810"; - else if (csvName == "OGLE-05-071L") - name = "OGLE 2005-BLG-71L"; - else if (csvName == "OGLE235-MOA53") - name = "OGLE 2003-BLG-235L"; - else if (csvName == "MOA-2008-BLG-310L") - name = "MOA 2008-BLG-310L"; - else if (csvName == "KIC 11442793") - name = "KOI-351"; - else if (csvName == "OGLE-2006-BLG-109L") - name = "OGLE 2006-BLG-109L"; - else if (csvName == "HD 137388") - name = "HD 137388 A"; - else if (csvName == "kappa CrB") - name = "kap CrB"; - else if (csvName == "XO-2") - name = "XO-2 N"; - else if (csvName == "epsilon Tau") - name = "eps Tau"; - else if (csvName == "epsilon Eri") - name = "eps Eri"; - else if (csvName == "Kepler-448") - name = "KOI-12"; - else if (csvName == "omega Ser") - name = "ome Ser"; - else if (csvName == "MOA-2010-BLG-477L") - name = "MOA 2010-BLG-477L"; - else if (csvName == "GJ 176") - name = "HD 285968"; - else if (csvName == "HIP 2247") - name = "BD-17 63"; - else if (csvName == "MOA-2009-BLG-266L") - name = "MOA 2009-BLG-266L"; - else if (csvName == "Kepler-89") - name = "KOI-94"; - else if (csvName == "iota Dra") - name = "HIP 75458"; - else if (csvName == "MOA-2007-BLG-400L") - name = "MOA 2007-BLG-400L"; - else if (csvName == "upsilon And") - name = "ups And"; - else if (csvName == "OGLE-2011-BLG-0251") - name = "OGLE 2011-BLG-251L"; - else if (csvName == "OGLE-05-390L") - name = "OGLE 2005-BLG-390L"; - else if (csvName == "Kepler-420") - name = "KOI-1257"; - else if (csvName == "beta Pic") - name = "bet Pic"; - else if (csvName == "gamma Cep") - name = "gam Cep"; - else if (csvName == "MOA-2007-BLG-192L") - name = "MOA 2007-BLG-192L"; - else if (csvName == "MOA-2009-BLG-319L") - name = "MOA 2009-BLG-319L"; - else if (csvName == "omicron CrB") - name = "omi CrB"; - else if (csvName == "beta Gem") - name = "HD 62509"; - else if (csvName == "epsilon CrB") - name = "eps CrB"; - else if (csvName == "omicron UMa") - name = "omi UMa"; - else if (csvName == "HD 142022") - name = "HD 142022 A"; - - return name; -} - glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { glm::vec3 position; position[0] = NAN; @@ -680,7 +587,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // SPECREF getline(lineStream, data, ','); // SPECURL getline(lineStream, data, ','); // STAR - std::string speckStarname = getExoplanetName(data); + std::string speckStarname = getSpeckStarname(data); glm::vec3 pos = getStarPosition(speckStarname); p.POSITIONX = pos[0]; p.POSITIONY = pos[1]; @@ -804,7 +711,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb long pos = binFile.tellp(); planetname = speckStarname + " " + component; lutFile << planetname << "," << pos << std::endl; - binFile.write((char *)&p, sizeof(struct Exoplanet)); + binFile.write((char *)&p, sizeof(Exoplanet)); } } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 9646f0c6d0..483e4fa045 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -44,53 +44,7 @@ private: std::string _outputBinPath; std::string _outputLutPath; - std::string getExoplanetName(std::string csvName); glm::vec3 getStarPosition(std::string starName); - - struct Exoplanet { - float A; - double AUPPER; - double ALOWER; - double UA; - float BIGOM; - float BIGOMUPPER; - float BIGOMLOWER; - float UBIGOM; - int BINARY; // **one or more stars** - float BMV; - float ECC; - float ECCUPPER; - float ECCLOWER; - float UECC; - float I; - float IUPPER; - float ILOWER; - float UI; - int NCOMP; // **number of planets** - float OM; - float OMUPPER; - float OMLOWER; - float UOM; - double PER; - float PERUPPER; - float PERLOWER; - float UPER; - double R; - double RUPPER; - double RLOWER; - double UR; - float RSTAR; - float RSTARUPPER; - float RSTARLOWER; - float URSTAR; - double TT; - float TTUPPER; - float TTLOWER; - float UTT; - float POSITIONX; - float POSITIONY; - float POSITIONZ; - }; }; } // namespace openspace::exoplanets From cef3fb69f4c0575798fde39e059cabacb9f156aa Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 28 Aug 2020 16:59:23 +0200 Subject: [PATCH 080/123] Some more cleanup --- modules/exoplanets/exoplanetshelper.cpp | 186 +++++++++--------- modules/exoplanets/exoplanetshelper.h | 6 +- modules/exoplanets/exoplanetsmodule_lua.inl | 141 +++++++------ .../tasks/exoplanetscsvtobintask.cpp | 66 ++++--- 4 files changed, 215 insertions(+), 184 deletions(-) diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index 67187b76d8..df8a4003a6 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -26,189 +26,189 @@ namespace openspace::exoplanets { -std::string getSpeckStarname(std::string csvName) { - std::string explName = csvName; +std::string getSpeckStarName(std::string csvName) { + std::string name = csvName; if (csvName == "HD 1237") - explName = "GJ 3021"; + name = "GJ 3021"; else if (csvName == "MOA-2009-BLG-387L") - explName = "MOA 2009-BLG-387L"; + name = "MOA 2009-BLG-387L"; else if (csvName == "HD 126614 A") - explName = "HD 126614"; + name = "HD 126614"; else if (csvName == "epsilon Ret") - explName = "HD 27442"; + name = "HD 27442"; else if (csvName == "PH-1") - explName = "PH1"; + name = "PH1"; else if (csvName == "gamma Leo A") - explName = "gam 1 Leo"; + name = "gam 1 Leo"; else if (csvName == "OGLE-2007-BLG-368L") - explName = "OGLE 2007-BLG-368L"; + name = "OGLE 2007-BLG-368L"; else if (csvName == "alpha Ari") - explName = "alf Ari"; + name = "alf Ari"; else if (csvName == "mu Ara") - explName = "HD 160691"; + name = "HD 160691"; else if (csvName == "OGLE-05-169L") - explName = "OGLE 2005-BLG-169L"; + name = "OGLE 2005-BLG-169L"; else if (csvName == "tau Gru") - explName = "HD 216435"; + name = "HD 216435"; else if (csvName == "iota Hor") - explName = "HR 810"; + name = "HR 810"; else if (csvName == "OGLE-05-071L") - explName = "OGLE 2005-BLG-71L"; + name = "OGLE 2005-BLG-71L"; else if (csvName == "OGLE235-MOA53") - explName = "OGLE 2003-BLG-235L"; + name = "OGLE 2003-BLG-235L"; else if (csvName == "MOA-2008-BLG-310L") - explName = "MOA 2008-BLG-310L"; + name = "MOA 2008-BLG-310L"; else if (csvName == "KIC 11442793") - explName = "KOI-351"; + name = "KOI-351"; else if (csvName == "OGLE-2006-BLG-109L") - explName = "OGLE 2006-BLG-109L"; + name = "OGLE 2006-BLG-109L"; else if (csvName == "HD 137388") - explName = "HD 137388 A"; + name = "HD 137388 A"; else if (csvName == "kappa CrB") - explName = "kap CrB"; + name = "kap CrB"; else if (csvName == "XO-2") - explName = "XO-2 N"; + name = "XO-2 N"; else if (csvName == "epsilon Tau") - explName = "eps Tau"; + name = "eps Tau"; else if (csvName == "epsilon Eri") - explName = "eps Eri"; + name = "eps Eri"; else if (csvName == "Kepler-448") - explName = "KOI-12"; + name = "KOI-12"; else if (csvName == "omega Ser") - explName = "ome Ser"; + name = "ome Ser"; else if (csvName == "MOA-2010-BLG-477L") - explName = "MOA 2010-BLG-477L"; + name = "MOA 2010-BLG-477L"; else if (csvName == "GJ 176") - explName = "HD 285968"; + name = "HD 285968"; else if (csvName == "HIP 2247") - explName = "BD-17 63"; + name = "BD-17 63"; else if (csvName == "MOA-2009-BLG-266L") - explName = "MOA 2009-BLG-266L"; + name = "MOA 2009-BLG-266L"; else if (csvName == "Kepler-89") - explName = "KOI-94"; + name = "KOI-94"; else if (csvName == "iota Dra") - explName = "HIP 75458"; + name = "HIP 75458"; else if (csvName == "MOA-2007-BLG-400L") - explName = "MOA 2007-BLG-400L"; + name = "MOA 2007-BLG-400L"; else if (csvName == "upsilon And") - explName = "ups And"; + name = "ups And"; else if (csvName == "OGLE-2011-BLG-0251") - explName = "OGLE 2011-BLG-251L"; + name = "OGLE 2011-BLG-251L"; else if (csvName == "OGLE-05-390L") - explName = "OGLE 2005-BLG-390L"; + name = "OGLE 2005-BLG-390L"; else if (csvName == "Kepler-420") - explName = "KOI-1257"; + name = "KOI-1257"; else if (csvName == "beta Pic") - explName = "bet Pic"; + name = "bet Pic"; else if (csvName == "gamma Cep") - explName = "gam Cep"; + name = "gam Cep"; else if (csvName == "MOA-2007-BLG-192L") - explName = "MOA 2007-BLG-192L"; + name = "MOA 2007-BLG-192L"; else if (csvName == "MOA-2009-BLG-319L") - explName = "MOA 2009-BLG-319L"; + name = "MOA 2009-BLG-319L"; else if (csvName == "omicron CrB") - explName = "omi CrB"; + name = "omi CrB"; else if (csvName == "beta Gem") - explName = "HD 62509"; + name = "HD 62509"; else if (csvName == "epsilon CrB") - explName = "eps CrB"; + name = "eps CrB"; else if (csvName == "omicron UMa") - explName = "omi UMa"; + name = "omi UMa"; else if (csvName == "HD 142022") - explName = "HD 142022 A"; + name = "HD 142022 A"; - return explName; + return name; } -std::string getCsvStarname(std::string explName) { - std::string csvName = explName; - if (explName == "GJ 3021") +std::string getCsvStarName(std::string name) { + std::string csvName = name; + if (name == "GJ 3021") csvName = "HD 1237"; - else if (explName == "MOA 2009-BLG-387L") + else if (name == "MOA 2009-BLG-387L") csvName = "MOA-2009-BLG-387L"; - else if (explName == "HD 126614") + else if (name == "HD 126614") csvName = "HD 126614 A"; - else if (explName == "HD 27442") + else if (name == "HD 27442") csvName = "epsilon Ret"; - else if (explName == "PH1") + else if (name == "PH1") csvName = "PH-1"; - else if (explName == "gam 1 Leo") + else if (name == "gam 1 Leo") csvName = "gamma Leo A"; - else if (explName == "OGLE 2007-BLG-368L") + else if (name == "OGLE 2007-BLG-368L") csvName = "OGLE-2007-BLG-368L"; - else if (explName == "alf Ari") + else if (name == "alf Ari") csvName = "alpha Ari"; - else if (explName == "HD 160691") + else if (name == "HD 160691") csvName = "mu Ara"; - else if (explName == "OGLE 2005-BLG-169L") + else if (name == "OGLE 2005-BLG-169L") csvName = "OGLE-05-169L"; - else if (explName == "HD 216435") + else if (name == "HD 216435") csvName = "tau Gru"; - else if (explName == "HR 810") + else if (name == "HR 810") csvName = "iota Hor"; - else if (explName == "OGLE 2005-BLG-71L") + else if (name == "OGLE 2005-BLG-71L") csvName = "OGLE-05-071L"; - else if (explName == "OGLE 2003-BLG-235L") + else if (name == "OGLE 2003-BLG-235L") csvName = "OGLE235-MOA53"; - else if (explName == "MOA 2008-BLG-310L") + else if (name == "MOA 2008-BLG-310L") csvName = "MOA-2008-BLG-310L"; - else if (explName == "KOI-351") + else if (name == "KOI-351") csvName = "KIC 11442793"; - else if (explName == "OGLE 2006-BLG-109L") + else if (name == "OGLE 2006-BLG-109L") csvName = "OGLE-2006-BLG-109L"; - else if (explName == "HD 137388 A") + else if (name == "HD 137388 A") csvName = "HD 137388"; - else if (explName == "kap CrB") + else if (name == "kap CrB") csvName = "kappa CrB"; - else if (explName == "XO-2 N") + else if (name == "XO-2 N") csvName = "XO-2"; - else if (explName == "eps Tau") + else if (name == "eps Tau") csvName = "epsilon Tau"; - else if (explName == "eps Eri") + else if (name == "eps Eri") csvName = "epsilon Eri"; - else if (explName == "KOI-12") + else if (name == "KOI-12") csvName = "Kepler-448"; - else if (explName == "ome Ser") + else if (name == "ome Ser") csvName = "omega Ser"; - else if (explName == "MOA 2010-BLG-477L") + else if (name == "MOA 2010-BLG-477L") csvName = "MOA-2010-BLG-477L"; - else if (explName == "HD 285968") + else if (name == "HD 285968") csvName = "GJ 176"; - else if (explName == "BD-17 63") + else if (name == "BD-17 63") csvName = "HIP 2247"; - else if (explName == "MOA 2009-BLG-266L") + else if (name == "MOA 2009-BLG-266L") csvName = "MOA-2009-BLG-266L"; - else if (explName == "KOI-94") + else if (name == "KOI-94") csvName = "Kepler-89"; - else if (explName == "HIP 75458") + else if (name == "HIP 75458") csvName = "iota Dra"; - else if (explName == "MOA 2007-BLG-400L") + else if (name == "MOA 2007-BLG-400L") csvName = "MOA-2007-BLG-400L"; - else if (explName == "ups And") + else if (name == "ups And") csvName = "upsilon And"; - else if (explName == "OGLE 2011-BLG-251L") + else if (name == "OGLE 2011-BLG-251L") csvName = "OGLE-2011-BLG-0251"; - else if (explName == "OGLE 2005-BLG-390L") + else if (name == "OGLE 2005-BLG-390L") csvName = "OGLE-05-390L"; - else if (explName == "KOI-1257") + else if (name == "KOI-1257") csvName = "Kepler-420"; - else if (explName == "bet Pic") + else if (name == "bet Pic") csvName = "beta Pic"; - else if (explName == "gam Cep") + else if (name == "gam Cep") csvName = "gamma Cep"; - else if (explName == "MOA 2007-BLG-192L") + else if (name == "MOA 2007-BLG-192L") csvName = "MOA-2007-BLG-192L"; - else if (explName == "MOA 2009-BLG-319L") + else if (name == "MOA 2009-BLG-319L") csvName = "MOA-2009-BLG-319L"; - else if (explName == "omi CrB") + else if (name == "omi CrB") csvName = "omicron CrB"; - else if (explName == "HD 62509") + else if (name == "HD 62509") csvName = "beta Gem"; - else if (explName == "eps CrB") + else if (name == "eps CrB") csvName = "epsilon CrB"; - else if (explName == "omi UMa") + else if (name == "omi UMa") csvName = "omicron UMa"; - else if (explName == "HD 142022 A") + else if (name == "HD 142022 A") csvName = "HD 142022"; return csvName; diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h index 6a8061e5e5..92bfc82d3e 100644 --- a/modules/exoplanets/exoplanetshelper.h +++ b/modules/exoplanets/exoplanetshelper.h @@ -74,9 +74,11 @@ struct Exoplanet { float POSITIONZ; // Star position's Z-coordinate in parsec }; -std::string getSpeckStarname(std::string csvName); +// Convert csv-file specific names to the corresponding name in the speck data file +std::string getSpeckStarName(std::string name); -std::string getCsvStarname(std::string explName); +// Convert speck-file specific names to the corresponding name in the csv data file +std::string getCsvStarName(std::string name); } // namespace openspace::exoplanets diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 874504b6c4..bbf93a4718 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -42,38 +42,30 @@ namespace openspace::exoplanets::luascriptfunctions { std::string getStarColor(float bv, std::ifstream& colormap) { - std::string colorString; - - int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); - + const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); std::string color; for (size_t i = 0; i < t + 12; i++) { getline(colormap, color); } - - std::istringstream colorstream(color); - std::string r, g, b; - getline(colorstream, r, ' '); - getline(colorstream, g, ' '); - getline(colorstream, b, ' '); - colorString = "{" + r + ", " + g + ", " + b + "}"; - colormap.close(); - return colorString; + std::istringstream colorStream(color); + std::string r, g, b; + getline(colorStream, r, ' '); + getline(colorStream, g, ' '); + getline(colorStream, b, ' '); + + return "{" + r + ", " + g + ", " + b + "}"; } -glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm::dmat3 rot) { +glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, + float om, glm::dmat3 rot) +{ // Exoplanet defined inclination changed to be used as Kepler defined inclination - const glm::dvec3 ascendingNodeAxisRot = rot * glm::dvec3(0.f, 0.f, 1.f); const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); - /*const glm::vec3 ascendingNodeAxisRot = { 0.f, 0.f, 1.f }; - const glm::vec3 inclinationAxisRot = { 1.f, 0.f, 0.f }; - const glm::vec3 argPeriapsisAxisRot = { 0.f, 0.f, 1.f };*/ - const double asc = glm::radians(bigom); const double inc = glm::radians(i); const double per = glm::radians(om); @@ -91,18 +83,16 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om , glm: // Modified from http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-find-the-rotation-between-2-vectors- glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { glm::quat rotationQuat; - //glm::dvec3 oldXVec = glm::dvec3(1.0, 0.0, 0.0); //parent nod x-vec - //glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - end); - - float cosTheta = dot(start, end); glm::dvec3 rotationAxis; + const float cosTheta = dot(start, end); + constexpr float Epsilon = 1E-3f; - if (cosTheta < -1 + 0.001f) { + if (cosTheta < -1.f + Epsilon) { // special case when vectors in opposite directions: // there is no "ideal" rotation axis - // So guess one; any will do as long as it's perpendicular to startvector(oldXVec) + // So guess one; any will do as long as it's perpendicular to start vector rotationAxis = cross(glm::dvec3(0.0, 0.0, 1.0), start); - if (length2(rotationAxis) < 0.01) // bad luck, they were parallel, try again! + if (length2(rotationAxis) < 0.01f) // bad luck, they were parallel, try again! rotationAxis = cross(glm::dvec3(1.0, 0.0, 0.0), start); rotationAxis = normalize(rotationAxis); @@ -112,8 +102,8 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { rotationAxis = cross(start, end); - float s = sqrt((1 + cosTheta) * 2); - float invs = 1 / s; + const float s = sqrt((1.f + cosTheta) * 2.f); + const float invs = 1.f / s; rotationQuat = glm::quat( s * 0.5f, @@ -129,10 +119,8 @@ int addExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); - //change expl-starname to exoplanet.csv-starname - std::string starnameCsv = getCsvStarname(starName); // If user have given name as in EOD, change it to speck-name - std::string starNameSpeck = getSpeckStarname(starName); + std::string starNameSpeck = getSpeckStarName(starName); std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); std::ifstream data( @@ -182,7 +170,10 @@ int addExoplanetSystem(lua_State* L) { lut.close(); if (!found || isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER)) { // || p.BINARY - return ghoul::lua::luaError(L, "No star with that name or not enough data about it."); + return ghoul::lua::luaError( + L, + "No star with that name or not enough data about it." + ); } Time epoch; @@ -203,10 +194,13 @@ int addExoplanetSystem(lua_State* L) { ); glm::dvec3 celestialNorth = normalize(galaxticToCelectialMatrix * galacticNorth); - // Earths north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starTosunVec) - glm::dvec3 northProjected = normalize(celestialNorth - (((dot(celestialNorth, starToSunVec)) / (glm::length(starToSunVec))) * starToSunVec)); + // Earth's north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starToSunVec) + const float celestialAngle = dot(celestialNorth, starToSunVec); + glm::dvec3 northProjected = glm::normalize( + celestialNorth - (celestialAngle / glm::length(starToSunVec)) * starToSunVec + ); - glm::dvec3 beta = normalize(cross(starToSunVec, northProjected)); + glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected)); const glm::dmat3 exoplanetSystemRotation = glm::dmat3( northProjected.x, @@ -243,9 +237,12 @@ int addExoplanetSystem(lua_State* L) { ); float starRadius = p.RSTAR; - if (!isnan(starRadius)) { - std::ifstream colorMap(absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), std::ios::in); + std::ifstream colorMap( + absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), + std::ios::in + ); + if (!colorMap.good()) { ghoul::lua::luaError(L, "Failed to open colormap data file"); } @@ -270,15 +267,19 @@ int addExoplanetSystem(lua_State* L) { epoch.setTime("JD " + std::to_string(firstPlanet.TT)); sEpochStar = epoch.ISO8601(); } - else + else { sEpochStar = "2009-05-19T07:11:34.080"; + } + + const float period = firstPlanet.PER * static_cast(SecondsPerDay); + const float radiusInMeter = starRadius * distanceconstants::SolarRadius; const std::string starGlobeNode = "{" "Identifier = '" + starNameSpeck + "Globe'," "Parent = '" + starNameSpeck + "'," "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadius * distanceconstants::SolarRadius) + "," + "Radii = " + std::to_string(radiusInMeter) + "," "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" @@ -313,7 +314,7 @@ int addExoplanetSystem(lua_State* L) { "ArgumentOfPeriapsis = " + std::to_string(firstPlanet.OM) + "," //OM "MeanAnomaly = 180.0," "Epoch = '" + sEpochStar + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(firstPlanet.PER * static_cast(SecondsPerDay)) + "," + "Period = " + std::to_string(period) + "," "}" "}" "}"; @@ -345,8 +346,9 @@ int addExoplanetSystem(lua_State* L) { epoch.setTime("JD " + std::to_string(planet.TT)); sEpoch = epoch.ISO8601(); } - else + else { sEpoch = "2009-05-19T07:11:34.080"; + } float planetRadius; std::string enabled = ""; @@ -356,7 +358,7 @@ int addExoplanetSystem(lua_State* L) { planetRadius = planet.A * 0.001f * distanceconstants::AstronomicalUnit; } else { - planetRadius = planet.RSTAR * distanceconstants::SolarRadius * 0.1f; + planetRadius = planet.RSTAR * 0.1f * distanceconstants::SolarRadius; } enabled = "false"; } @@ -365,6 +367,10 @@ int addExoplanetSystem(lua_State* L) { enabled = "true"; } + const float period = planet.PER * static_cast(SecondsPerDay); + const float semiMajorAxisInMeter = planet.A * distanceconstants::AstronomicalUnit; + const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; + const std::string planetNode = "{" "Identifier = '" + planetName + "'," "Parent = '" + starNameSpeck + "'," @@ -393,13 +399,13 @@ int addExoplanetSystem(lua_State* L) { "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(planet.A * 0.001f * distanceconstants::AstronomicalUnit) + "," // km + "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," "Inclination = " + std::to_string(planet.I) + "," //I "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(planet.PER * static_cast(SecondsPerDay)) + "," + "Period = " + std::to_string(period) + "," "}," "}," "}"; @@ -420,13 +426,13 @@ int addExoplanetSystem(lua_State* L) { "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(planet.A * 0.001f * distanceconstants::AstronomicalUnit) + "," // km + "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," "Inclination = " + std::to_string(planet.I) + "," //I "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(planet.PER * static_cast(SecondsPerDay)) + "," + "Period = " + std::to_string(period) + "," "}," "Color = { 1, 1, 1 }" "}," @@ -437,13 +443,18 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - bool hasUpperSemiMajor = !isnan(planet.AUPPER); - bool hasLowerSemiMajor = !isnan(planet.ALOWER); + bool hasUpperAUncertainty = !isnan(planet.AUPPER); + bool hasLowerAUncertainty = !isnan(planet.ALOWER); - if (hasUpperSemiMajor && hasLowerSemiMajor) + if (hasUpperAUncertainty && hasLowerAUncertainty) { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation - glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(planet.I, planet.BIGOM, planet.OM, exoplanetSystemRotation); + glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( + planet.I, + planet.BIGOM, + planet.OM, + exoplanetSystemRotation + ); glm::dmat3 rotation = orbitPlaneRotationMatrix; const std::string discNode = "{" "Identifier = '" + planetName + "Disc'," @@ -452,9 +463,12 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," - "Size = " + std::to_string(planet.A * distanceconstants::AstronomicalUnit) + "," + "Size = " + std::to_string(semiMajorAxisInMeter) + "," "Eccentricity = " + std::to_string(planet.ECC) + "," - "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend + "Offset = { " + + std::to_string(planet.ALOWER) + ", " + + std::to_string(planet.AUPPER) + + " }," //min / max extend "Opacity = 0.5" "}," "Transform = {" @@ -470,10 +484,11 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - bool hasLowerUncertainty = !isnan(planet.ECCLOWER) && planet.ECCLOWER > 0.0; - bool hasUpperUncertainty = !isnan(planet.ECCUPPER) && (planet.ECCUPPER > 0.0); + // Eccentricity uncertainty + bool hasLowerEccUncertainty = !isnan(planet.ECCLOWER) && planet.ECCLOWER > 0.0; + bool hasUpperEccUncertainty = !isnan(planet.ECCUPPER) && planet.ECCUPPER > 0.0; - if (hasLowerUncertainty && hasUpperUncertainty) + if (hasLowerEccUncertainty && hasUpperEccUncertainty) { double lowerEccentricity = planet.ECC - planet.ECCLOWER; if (lowerEccentricity < 0.0) { @@ -486,9 +501,12 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," - "Size = " + std::to_string(planet.A * distanceconstants::AstronomicalUnit) + "," + "Size = " + std::to_string(semiMajorAxisInMeter) + "," "Eccentricity = " + std::to_string(lowerEccentricity) + "," - "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend + "Offset = { " + + std::to_string(planet.ALOWER) + ", " + + std::to_string(planet.AUPPER) + + " }," //min / max extend "Opacity = 0.98," "Enabled = false" "}," @@ -516,9 +534,12 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," - "Size = " + std::to_string(planet.A * distanceconstants::AstronomicalUnit) + "," + "Size = " + std::to_string(semiMajorAxisInMeter) + "," "Eccentricity = " + std::to_string(upperEccentricity) + "," - "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend + "Offset = { " + + std::to_string(planet.ALOWER) + ", " + + std::to_string(planet.AUPPER) + + " }," //min / max extend "Opacity = 0.98," "Enabled = false" "}," @@ -544,7 +565,7 @@ int addExoplanetSystem(lua_State* L) { int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); - std::string starNameSpeck = getSpeckStarname(starName); + std::string starNameSpeck = getSpeckStarName(starName); std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); openspace::global::scriptEngine.queueScript( diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index af8fae1c10..567d6d7cad 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -126,12 +126,12 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb Exoplanet p; - std::string planetname; + std::string planetName; std::string component; std::string planetRow; getline(csvFile, planetRow); // The first line, containing the data names - bool iskeplerobject = false; + bool isKeplerObject = false; int total = 0; while (getline(csvFile, planetRow)) { ++total; @@ -587,11 +587,11 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // SPECREF getline(lineStream, data, ','); // SPECURL getline(lineStream, data, ','); // STAR - std::string speckStarname = getSpeckStarname(data); - glm::vec3 pos = getStarPosition(speckStarname); - p.POSITIONX = pos[0]; - p.POSITIONY = pos[1]; - p.POSITIONZ = pos[2]; + std::string speckStarname = getSpeckStarName(data); + glm::vec3 position = getStarPosition(speckStarname); + p.POSITIONX = position[0]; + p.POSITIONY = position[1]; + p.POSITIONZ = position[2]; getline(lineStream, data, ','); // STARDISCMETH getline(lineStream, data, ','); // T0 @@ -660,46 +660,54 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // VSINIURL getline(lineStream, data, ','); // KEPID if (!data.empty()) - iskeplerobject = true; + isKeplerObject = true; getline(lineStream, data); // KDE - if (!iskeplerobject) { + if (!isKeplerObject) { // calculate B-V from Teff if not exsisting if (std::isnan(p.BMV)) { if (!std::isnan(teff)) { - float teff_current, teff_upper, teff_lower, BV, bv_upper, bv_lower = 0; + std::ifstream teffToBvFile( + absPath("${BASE}/modules/exoplanets/teff_bv.txt") + ); - std::ifstream teff_bv(absPath("${BASE}/modules/exoplanets/teff_bv.txt")); - if (!teff_bv.good()) { + if (!teffToBvFile.good()) { LERROR(fmt::format("Failed to open teff_bv.txt file")); return; } - std::string row, teff_string, bv_string; - while (getline(teff_bv, row)) { + float BV = 0.f; + float bvUpper = 0.f; + float bvLower = 0.f; + float teffLower, teffUpper; + std::string row, teffString, bvString; + while (getline(teffToBvFile, row)) { std::istringstream lineStream(row); - getline(lineStream, teff_string, ','); - getline(lineStream, bv_string); + getline(lineStream, teffString, ','); + getline(lineStream, bvString); - teff_current= std::stof(teff_string.c_str(), nullptr); - - if (teff > teff_current) { - teff_lower = teff_current; - bv_lower = std::stof(bv_string.c_str(), nullptr); + float teffCurrent = std::stof(teffString.c_str(), nullptr); + float bvCurrent = std::stof(bvString.c_str(), nullptr); + + if (teff > teffCurrent) { + teffLower = teffCurrent; + bvLower = bvCurrent; } else { - teff_upper = teff_current; - bv_upper = std::stof(bv_string.c_str(), nullptr); - if (bv_lower == 0) { - BV = 2.00; + teffUpper = teffCurrent; + bvUpper = bvCurrent; + if (bvLower == 0.f) { + BV = 2.f; } else { - BV = (((bv_upper - bv_lower) * (teff - teff_lower)) / (teff_upper - teff_lower)) + bv_lower; + float bvDiff = (bvUpper - bvLower); + float teffDiff = (teffUpper - teffLower); + BV = ((bvDiff * (teff - teffLower)) / teffDiff) + bvLower; } break; } } - teff_bv.close(); + teffToBvFile.close(); p.BMV = BV; } else { @@ -709,8 +717,8 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb // crate look-up table long pos = binFile.tellp(); - planetname = speckStarname + " " + component; - lutFile << planetname << "," << pos << std::endl; + planetName = speckStarname + " " + component; + lutFile << planetName << "," << pos << std::endl; binFile.write((char *)&p, sizeof(Exoplanet)); } } From acbf670bc472e0a71189d027d6b6c0068080939c Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 31 Aug 2020 09:18:00 +0200 Subject: [PATCH 081/123] Avoid problems with exoplanets names that include whitespaces --- modules/exoplanets/exoplanetsmodule_lua.inl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index bbf93a4718..2714daeb17 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -121,7 +121,6 @@ int addExoplanetSystem(lua_State* L) { // If user have given name as in EOD, change it to speck-name std::string starNameSpeck = getSpeckStarName(starName); - std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); std::ifstream data( absPath("${MODULE_EXOPLANETS}/expl_data.bin"), @@ -214,6 +213,7 @@ int addExoplanetSystem(lua_State* L) { starToSunVec.z ); + // Avoid whitespaces in identifiers std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); const std::string starParent = "{" @@ -371,6 +371,9 @@ int addExoplanetSystem(lua_State* L) { const float semiMajorAxisInMeter = planet.A * distanceconstants::AstronomicalUnit; const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; + // Avoid whitespace in identifier + std::replace(planetName.begin(), planetName.end(), ' ', '_'); + const std::string planetNode = "{" "Identifier = '" + planetName + "'," "Parent = '" + starNameSpeck + "'," From 3d97585483f6fff20a113dc1f0cdd9cf296b9697 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 31 Aug 2020 10:12:51 +0200 Subject: [PATCH 082/123] Add GUI path and cleanup node indentifiers --- modules/exoplanets/exoplanetsmodule_lua.inl | 67 +++++++++++++++------ 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 2714daeb17..b8b0852943 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -41,6 +41,8 @@ namespace openspace::exoplanets::luascriptfunctions { +constexpr const char* ExoplanetsGUIPath = "/Milky Way/Exoplanets/Exoplanets Systems/"; + std::string getStarColor(float bv, std::ifstream& colormap) { const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); std::string color; @@ -115,6 +117,13 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { return glm::dmat3(toMat4(rotationQuat)); } +// Create an identifier without whitespaces +std::string createIdentifier(const std::string& name) { + std::string res = name; + std::replace(res.begin(), res.end(), ' ', '_'); + return res; +} + int addExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); @@ -213,11 +222,10 @@ int addExoplanetSystem(lua_State* L) { starToSunVec.z ); - // Avoid whitespaces in identifiers - std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); + std::string starIdentifier = createIdentifier(starNameSpeck); const std::string starParent = "{" - "Identifier = '" + starNameSpeck + "'," + "Identifier = '" + starIdentifier + "'," "Parent = 'SolarSystemBarycenter'," "Transform = {" "Rotation = {" @@ -228,6 +236,10 @@ int addExoplanetSystem(lua_State* L) { "Type = 'StaticTranslation'," "Position = " + ghoul::to_string(starPosition) + "" "}" + "}," + "GUI = {" + "Name = '" + starNameSpeck + "'," + "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," "}" "}"; @@ -275,8 +287,8 @@ int addExoplanetSystem(lua_State* L) { const float radiusInMeter = starRadius * distanceconstants::SolarRadius; const std::string starGlobeNode = "{" - "Identifier = '" + starNameSpeck + "Globe'," - "Parent = '" + starNameSpeck + "'," + "Identifier = '" + starIdentifier + "_Globe'," + "Parent = '" + starIdentifier + "'," "Renderable = {" "Type = 'RenderableGlobe'," "Radii = " + std::to_string(radiusInMeter) + "," @@ -316,6 +328,10 @@ int addExoplanetSystem(lua_State* L) { "Epoch = '" + sEpochStar + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(period) + "," "}" + "}," + "GUI = {" + "Name = '" + starNameSpeck + " Globe'," + "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," "}" "}"; @@ -371,12 +387,11 @@ int addExoplanetSystem(lua_State* L) { const float semiMajorAxisInMeter = planet.A * distanceconstants::AstronomicalUnit; const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; - // Avoid whitespace in identifier - std::replace(planetName.begin(), planetName.end(), ' ', '_'); + std::string planetIdentifier = createIdentifier(planetName); const std::string planetNode = "{" - "Identifier = '" + planetName + "'," - "Parent = '" + starNameSpeck + "'," + "Identifier = '" + planetIdentifier + "'," + "Parent = '" + starIdentifier + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableGlobe'," @@ -411,6 +426,10 @@ int addExoplanetSystem(lua_State* L) { "Period = " + std::to_string(period) + "," "}," "}," + "GUI = {" + "Name = '" + planetName + "'," + "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," + "}" "}"; openspace::global::scriptEngine.queueScript( @@ -419,8 +438,8 @@ int addExoplanetSystem(lua_State* L) { ); const std::string planetTrailNode = "{" - "Identifier = '" + planetName + "Trail'," - "Parent = '" + starNameSpeck + "'," + "Identifier = '" + planetIdentifier + "_Trail'," + "Parent = '" + starIdentifier + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableTrailOrbit'," @@ -439,6 +458,10 @@ int addExoplanetSystem(lua_State* L) { "}," "Color = { 1, 1, 1 }" "}," + "GUI = {" + "Name = '" + planetName + " Trail'," + "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," + "}" "}"; openspace::global::scriptEngine.queueScript( @@ -460,8 +483,8 @@ int addExoplanetSystem(lua_State* L) { ); glm::dmat3 rotation = orbitPlaneRotationMatrix; const std::string discNode = "{" - "Identifier = '" + planetName + "Disc'," - "Parent = '" + starNameSpeck + "'," + "Identifier = '" + planetIdentifier + "_Disc'," + "Parent = '" + starIdentifier + "'," "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," @@ -480,6 +503,10 @@ int addExoplanetSystem(lua_State* L) { "Rotation = " + ghoul::to_string(rotation) + "," "}" "}," + "GUI = {" + "Name = '" + planetName + " Disc'," + "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," + "}" "}"; openspace::global::scriptEngine.queueScript( @@ -499,8 +526,8 @@ int addExoplanetSystem(lua_State* L) { } const std::string discLowerEccentricityNode = "{" - "Identifier = '" + planetName + "discECCLOWER'," - "Parent = '" + starNameSpeck + "'," + "Identifier = '" + planetIdentifier + "_Disc_ECC_LOWER'," + "Parent = '" + starIdentifier + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," @@ -519,6 +546,7 @@ int addExoplanetSystem(lua_State* L) { "Rotation = " + ghoul::to_string(rotation) + "," "}" "}," + // @TODO: GUI, if we make it work "}"; openspace::global::scriptEngine.queueScript( @@ -532,8 +560,8 @@ int addExoplanetSystem(lua_State* L) { } const std::string discUpperEccentricityNode = "{" - "Identifier = '" + planetName + "discECCUPPER'," - "Parent = '" + starNameSpeck + "'," + "Identifier = '" + planetIdentifier + "_Disc_ECC_UPPER'," + "Parent = '" + starIdentifier + "'," "Renderable = {" "Type = 'RenderableOrbitdisc'," "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," @@ -552,6 +580,7 @@ int addExoplanetSystem(lua_State* L) { "Rotation = " + ghoul::to_string(rotation) + "," "}" "}," + // @TODO: GUI, if we make it work "}"; openspace::global::scriptEngine.queueScript( @@ -569,10 +598,10 @@ int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); std::string starNameSpeck = getSpeckStarName(starName); - std::replace(starNameSpeck.begin(), starNameSpeck.end(), ' ', '_'); + std::string starIdentifier = createIdentifier(starNameSpeck); openspace::global::scriptEngine.queueScript( - "openspace.removeSceneGraphNode('" + starNameSpeck + "');", + "openspace.removeSceneGraphNode('" + starIdentifier + "');", scripting::ScriptEngine::RemoteScripting::Yes ); From 4b1d8da972f003221517a8b00a473bd88f0bed51 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 31 Aug 2020 11:20:06 +0200 Subject: [PATCH 083/123] Fix problem with parent node's tranformation being applied twice Scene graph nodes inherit their parent's transformation nowadays, but not when this code was implemented. --- modules/exoplanets/exoplanetsmodule_lua.inl | 35 ++++----------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index b8b0852943..147c134b8f 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -60,13 +60,11 @@ std::string getStarColor(float bv, std::ifstream& colormap) { return "{" + r + ", " + g + ", " + b + "}"; } -glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, - float om, glm::dmat3 rot) -{ +glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { // Exoplanet defined inclination changed to be used as Kepler defined inclination - const glm::dvec3 ascendingNodeAxisRot = rot * glm::dvec3(0.f, 0.f, 1.f); - const glm::dvec3 inclinationAxisRot = rot * glm::dvec3(1.f, 0.f, 0.f ); - const glm::vec3 argPeriapsisAxisRot = rot * glm::dvec3( 0.f, 0.f, 1.f ); + const glm::dvec3 ascendingNodeAxisRot = glm::dvec3(0.0, 0.0, 1.0); + const glm::dvec3 inclinationAxisRot = glm::dvec3(1.0, 0.0, 0.0); + const glm::dvec3 argPeriapsisAxisRot = glm::dvec3(0.0, 0.0, 1.0); const double asc = glm::radians(bigom); const double inc = glm::radians(i); @@ -312,23 +310,6 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}," - "Transform = {" - "Scale = {" - "Type = 'StaticScale'," - "Scale = 1.0," - "}," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(firstPlanet.ECC) + "," //ECC - "SemiMajorAxis = 0," - "Inclination = " + std::to_string(firstPlanet.I) + "," //I - "AscendingNode = " + std::to_string(firstPlanet.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(firstPlanet.OM) + "," //OM - "MeanAnomaly = 180.0," - "Epoch = '" + sEpochStar + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(period) + "," - "}" - "}," "GUI = {" "Name = '" + starNameSpeck + " Globe'," "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," @@ -410,10 +391,6 @@ int addExoplanetSystem(lua_State* L) { "}" "}," "Transform = {" - "Scale = {" - "Type = 'StaticScale'," - "Scale = 1.0," - "}," "Translation = {" "Type = 'KeplerTranslation'," "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC @@ -478,10 +455,10 @@ int addExoplanetSystem(lua_State* L) { glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( planet.I, planet.BIGOM, - planet.OM, - exoplanetSystemRotation + planet.OM ); glm::dmat3 rotation = orbitPlaneRotationMatrix; + const std::string discNode = "{" "Identifier = '" + planetIdentifier + "_Disc'," "Parent = '" + starIdentifier + "'," From 12fc3d5ab609ee07eb486fd42e4541586182cba2 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 31 Aug 2020 11:48:55 +0200 Subject: [PATCH 084/123] Combine star parent node with renderable globe --- modules/exoplanets/exoplanetsmodule_lua.inl | 142 ++++++++------------ 1 file changed, 54 insertions(+), 88 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 147c134b8f..6378a0561f 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -41,7 +41,7 @@ namespace openspace::exoplanets::luascriptfunctions { -constexpr const char* ExoplanetsGUIPath = "/Milky Way/Exoplanets/Exoplanets Systems/"; +constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Systems/"; std::string getStarColor(float bv, std::ifstream& colormap) { const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); @@ -220,33 +220,9 @@ int addExoplanetSystem(lua_State* L) { starToSunVec.z ); - std::string starIdentifier = createIdentifier(starNameSpeck); - - const std::string starParent = "{" - "Identifier = '" + starIdentifier + "'," - "Parent = 'SolarSystemBarycenter'," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(exoplanetSystemRotation) + "" - "}," - "Translation = {" - "Type = 'StaticTranslation'," - "Position = " + ghoul::to_string(starPosition) + "" - "}" - "}," - "GUI = {" - "Name = '" + starNameSpeck + "'," - "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," - "}" - "}"; - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + starParent + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - float starRadius = p.RSTAR; + // Star renderable globe, if we have a radius + std::string starGlobeRenderableString = ""; + const float starRadius = p.RSTAR; if (!isnan(starRadius)) { std::ifstream colorMap( absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), @@ -258,70 +234,60 @@ int addExoplanetSystem(lua_State* L) { } std::string color = getStarColor(p.BMV, colorMap); - Exoplanet firstPlanet = planetSystem[0]; - - if (isnan(firstPlanet.ECC)) { - firstPlanet.ECC = 0.f; - } - if (isnan(firstPlanet.I)) { - firstPlanet.I = 90.f; - } - if (isnan(firstPlanet.BIGOM)) { - firstPlanet.BIGOM = 180.f; - } - if (isnan(firstPlanet.OM)) { - firstPlanet.OM = 90.f; - } - std::string sEpochStar; - if (!isnan(firstPlanet.TT)) { - epoch.setTime("JD " + std::to_string(firstPlanet.TT)); - sEpochStar = epoch.ISO8601(); - } - else { - sEpochStar = "2009-05-19T07:11:34.080"; - } - - const float period = firstPlanet.PER * static_cast(SecondsPerDay); const float radiusInMeter = starRadius * distanceconstants::SolarRadius; - const std::string starGlobeNode = "{" - "Identifier = '" + starIdentifier + "_Globe'," - "Parent = '" + starIdentifier + "'," - "Renderable = {" - "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(radiusInMeter) + "," - "SegmentsPerPatch = 64," - "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'StarColor'," - "Type = 'SolidColor'," - "Color = " + color + "," - "BlendMode = 'Normal'," - "Enabled = true" - "}," - "{" - "Identifier = 'StarTexture'," - "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," - "BlendMode = 'Color'," - "Enabled = true" - "}" + starGlobeRenderableString = "Renderable = {" + "Type = 'RenderableGlobe'," + "Radii = " + std::to_string(radiusInMeter) + "," + "SegmentsPerPatch = 64," + "PerformShading = false," + "Layers = {" + "ColorLayers = {" + "{" + "Identifier = 'StarColor'," + "Type = 'SolidColor'," + "Color = " + color + "," + "BlendMode = 'Normal'," + "Enabled = true" + "}," + "{" + "Identifier = 'StarTexture'," + "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," + "BlendMode = 'Color'," + "Enabled = true" "}" "}" - "}," - "GUI = {" - "Name = '" + starNameSpeck + " Globe'," - "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," "}" - "}"; - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + starGlobeNode + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); + "},"; } + std::string starIdentifier = createIdentifier(starNameSpeck); + + const std::string starParent = "{" + "Identifier = '" + starIdentifier + "'," + "Parent = 'SolarSystemBarycenter'," + "" + starGlobeRenderableString + "" + "Transform = {" + "Rotation = {" + "Type = 'StaticRotation'," + "Rotation = " + ghoul::to_string(exoplanetSystemRotation) + "" + "}," + "Translation = {" + "Type = 'StaticTranslation'," + "Position = " + ghoul::to_string(starPosition) + "" + "}" + "}," + "GUI = {" + "Name = '" + starNameSpeck + " (Star)'," + "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," + "}" + "}"; + + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + starParent + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + for (size_t i = 0; i < planetSystem.size(); i++) { Exoplanet planet = planetSystem[i]; std::string planetName = planetNames[i]; @@ -405,7 +371,7 @@ int addExoplanetSystem(lua_State* L) { "}," "GUI = {" "Name = '" + planetName + "'," - "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," + "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," "}" "}"; @@ -437,7 +403,7 @@ int addExoplanetSystem(lua_State* L) { "}," "GUI = {" "Name = '" + planetName + " Trail'," - "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," + "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," "}" "}"; @@ -482,7 +448,7 @@ int addExoplanetSystem(lua_State* L) { "}," "GUI = {" "Name = '" + planetName + " Disc'," - "Path = '" + ExoplanetsGUIPath + starNameSpeck + "'," + "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," "}" "}"; From 01f198bfb0ce11e5be1f25a2d2b038696faec38f Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 31 Aug 2020 12:06:11 +0200 Subject: [PATCH 085/123] Add consts and refactor planet translation --- modules/exoplanets/exoplanetsmodule_lua.inl | 76 +++++++++------------ 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 6378a0561f..890eb9af3f 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -70,7 +70,7 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { const double inc = glm::radians(i); const double per = glm::radians(om); - glm::dmat4 orbitPlaneRotation = + const glm::dmat4 orbitPlaneRotation = glm::rotate(asc, glm::dvec3(ascendingNodeAxisRot)) * glm::rotate(inc, glm::dvec3(inclinationAxisRot)) * glm::rotate(per, glm::dvec3(argPeriapsisAxisRot)); @@ -127,7 +127,7 @@ int addExoplanetSystem(lua_State* L) { const std::string starName = luaL_checkstring(L, StringLocation); // If user have given name as in EOD, change it to speck-name - std::string starNameSpeck = getSpeckStarName(starName); + const std::string starNameSpeck = getSpeckStarName(starName); std::ifstream data( absPath("${MODULE_EXOPLANETS}/expl_data.bin"), @@ -182,23 +182,24 @@ int addExoplanetSystem(lua_State* L) { ); } - Time epoch; - glm::dvec3 starPosition = glm::dvec3( + const glm::dvec3 starPosition = glm::dvec3( p.POSITIONX * distanceconstants::Parsec, p.POSITIONY * distanceconstants::Parsec, p.POSITIONZ * distanceconstants::Parsec ); - glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); - glm::dvec3 starToSunVec = normalize(sunPosition - starPosition); - glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); + const glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); + const glm::dvec3 starToSunVec = normalize(sunPosition - starPosition); + const glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); - glm::dmat3 galaxticToCelectialMatrix = SpiceManager::ref().positionTransformMatrix( // galaxtic north in celectial coordinates, or just celectial north? + const glm::dmat3 galaxticToCelectialMatrix = SpiceManager::ref().positionTransformMatrix( // galaxtic north in celectial coordinates, or just celectial north? "GALACTIC", "J2000", 0.0 ); - glm::dvec3 celestialNorth = normalize(galaxticToCelectialMatrix * galacticNorth); + const glm::dvec3 celestialNorth = normalize( + galaxticToCelectialMatrix * galacticNorth + ); // Earth's north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starToSunVec) const float celestialAngle = dot(celestialNorth, starToSunVec); @@ -206,7 +207,7 @@ int addExoplanetSystem(lua_State* L) { celestialNorth - (celestialAngle / glm::length(starToSunVec)) * starToSunVec ); - glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected)); + const glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected)); const glm::dmat3 exoplanetSystemRotation = glm::dmat3( northProjected.x, @@ -233,7 +234,7 @@ int addExoplanetSystem(lua_State* L) { ghoul::lua::luaError(L, "Failed to open colormap data file"); } - std::string color = getStarColor(p.BMV, colorMap); + const std::string color = getStarColor(p.BMV, colorMap); const float radiusInMeter = starRadius * distanceconstants::SolarRadius; starGlobeRenderableString = "Renderable = {" @@ -261,7 +262,7 @@ int addExoplanetSystem(lua_State* L) { "},"; } - std::string starIdentifier = createIdentifier(starNameSpeck); + const std::string starIdentifier = createIdentifier(starNameSpeck); const std::string starParent = "{" "Identifier = '" + starIdentifier + "'," @@ -290,7 +291,7 @@ int addExoplanetSystem(lua_State* L) { for (size_t i = 0; i < planetSystem.size(); i++) { Exoplanet planet = planetSystem[i]; - std::string planetName = planetNames[i]; + const std::string planetName = planetNames[i]; if (isnan(planet.ECC)) { planet.ECC = 0.f; @@ -304,6 +305,7 @@ int addExoplanetSystem(lua_State* L) { if (isnan(planet.OM)) { planet.OM = 90.f; } + Time epoch; std::string sEpoch; if (!isnan(planet.TT)) { epoch.setTime("JD " + std::to_string(planet.TT)); @@ -334,7 +336,19 @@ int addExoplanetSystem(lua_State* L) { const float semiMajorAxisInMeter = planet.A * distanceconstants::AstronomicalUnit; const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; - std::string planetIdentifier = createIdentifier(planetName); + const std::string planetIdentifier = createIdentifier(planetName); + + const std::string planetKeplerTranslation = "{" + "Type = 'KeplerTranslation'," + "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC + "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," + "Inclination = " + std::to_string(planet.I) + "," //I + "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM + "MeanAnomaly = 0.0," + "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss + "Period = " + std::to_string(period) + "," + "}"; const std::string planetNode = "{" "Identifier = '" + planetIdentifier + "'," @@ -356,19 +370,7 @@ int addExoplanetSystem(lua_State* L) { "}" "}" "}," - "Transform = {" - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," - "Inclination = " + std::to_string(planet.I) + "," //I - "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(period) + "," - "}," - "}," + "Transform = { Translation = " + planetKeplerTranslation + "}," "GUI = {" "Name = '" + planetName + "'," "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," @@ -388,17 +390,7 @@ int addExoplanetSystem(lua_State* L) { "Type = 'RenderableTrailOrbit'," "Period = " + std::to_string(planet.PER) + "," "Resolution = 1000," - "Translation = {" - "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC - "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," - "Inclination = " + std::to_string(planet.I) + "," //I - "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM - "MeanAnomaly = 0.0," - "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(period) + "," - "}," + "Translation = " + planetKeplerTranslation + "," "Color = { 1, 1, 1 }" "}," "GUI = {" @@ -418,12 +410,12 @@ int addExoplanetSystem(lua_State* L) { if (hasUpperAUncertainty && hasLowerAUncertainty) { // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation - glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( + const glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( planet.I, planet.BIGOM, planet.OM ); - glm::dmat3 rotation = orbitPlaneRotationMatrix; + const glm::dmat3 rotation = orbitPlaneRotationMatrix; const std::string discNode = "{" "Identifier = '" + planetIdentifier + "_Disc'," @@ -540,8 +532,8 @@ int addExoplanetSystem(lua_State* L) { int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); - std::string starNameSpeck = getSpeckStarName(starName); - std::string starIdentifier = createIdentifier(starNameSpeck); + const std::string starNameSpeck = getSpeckStarName(starName); + const std::string starIdentifier = createIdentifier(starNameSpeck); openspace::global::scriptEngine.queueScript( "openspace.removeSceneGraphNode('" + starIdentifier + "');", From 15eaea1bc5c401cb960b7464553f08194a928559 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 31 Aug 2020 15:32:08 +0200 Subject: [PATCH 086/123] Remove eccentricity uncertainty discs They can be reimplemented later, if desired. But that requires creating useful textures. --- modules/exoplanets/exoplanetsmodule_lua.inl | 75 --------------------- 1 file changed, 75 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 890eb9af3f..221a00fb4c 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -448,81 +448,6 @@ int addExoplanetSystem(lua_State* L) { "openspace.addSceneGraphNode(" + discNode + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - - // Eccentricity uncertainty - bool hasLowerEccUncertainty = !isnan(planet.ECCLOWER) && planet.ECCLOWER > 0.0; - bool hasUpperEccUncertainty = !isnan(planet.ECCUPPER) && planet.ECCUPPER > 0.0; - - if (hasLowerEccUncertainty && hasUpperEccUncertainty) - { - double lowerEccentricity = planet.ECC - planet.ECCLOWER; - if (lowerEccentricity < 0.0) { - lowerEccentricity = 0.0; - } - - const std::string discLowerEccentricityNode = "{" - "Identifier = '" + planetIdentifier + "_Disc_ECC_LOWER'," - "Parent = '" + starIdentifier + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discL.png')," - "Size = " + std::to_string(semiMajorAxisInMeter) + "," - "Eccentricity = " + std::to_string(lowerEccentricity) + "," - "Offset = { " + - std::to_string(planet.ALOWER) + ", " + - std::to_string(planet.AUPPER) + - " }," //min / max extend - "Opacity = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rotation) + "," - "}" - "}," - // @TODO: GUI, if we make it work - "}"; - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + discLowerEccentricityNode + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - - double upperEccentricity = planet.ECC + planet.ECCUPPER; - if (upperEccentricity > 1.0) { - upperEccentricity = 1.0; - } - - const std::string discUpperEccentricityNode = "{" - "Identifier = '" + planetIdentifier + "_Disc_ECC_UPPER'," - "Parent = '" + starIdentifier + "'," - "Renderable = {" - "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/discU.png')," - "Size = " + std::to_string(semiMajorAxisInMeter) + "," - "Eccentricity = " + std::to_string(upperEccentricity) + "," - "Offset = { " + - std::to_string(planet.ALOWER) + ", " + - std::to_string(planet.AUPPER) + - " }," //min / max extend - "Opacity = 0.98," - "Enabled = false" - "}," - "Transform = {" - "Rotation = {" - "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rotation) + "," - "}" - "}," - // @TODO: GUI, if we make it work - "}"; - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + discUpperEccentricityNode + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - } } } From 1ea486fb1b46a26cc36fc57e3b8ad3296406f644 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 2 Sep 2020 10:55:15 +0200 Subject: [PATCH 087/123] Render disc using blending, to avoid problems with trails being covered by disc --- .../rendering/renderableorbitdisc.cpp | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index bdd85fe8ab..0398a9d1fa 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -222,6 +222,24 @@ void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { _texture->bind(); _shader->setUniform(_uniformCache.texture, unit); + GLboolean blendEnabled = glIsEnabledi(GL_BLEND, 0); + GLenum blendEquationRGB; + GLenum blendEquationAlpha; + GLenum blendDestAlpha; + GLenum blendDestRGB; + GLenum blendSrcAlpha; + GLenum blendSrcRGB; + glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); + glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); + glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); + glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB); + glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha); + glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB); + + glEnablei(GL_BLEND, 0); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthMask(false); + glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glBindVertexArray(_quad); @@ -229,6 +247,16 @@ void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { glEnable(GL_CULL_FACE); _shader->deactivate(); + + // Restores blending state + glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha); + glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha); + + glDepthMask(true); + + if (!blendEnabled) { + glDisablei(GL_BLEND, 0); + } } void RenderableOrbitdisc::update(const UpdateData& data) { From 6e5695b5dd99e87b3261f207aa67a39e53ad9466 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 2 Sep 2020 11:07:31 +0200 Subject: [PATCH 088/123] Rename disc texture and remove debug texture for planets (cat..) --- modules/exoplanets/exoplanetsmodule_lua.inl | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 221a00fb4c..f305f4c967 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -46,7 +46,7 @@ constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Syste std::string getStarColor(float bv, std::ifstream& colormap) { const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); std::string color; - for (size_t i = 0; i < t + 12; i++) { + for (int i = 0; i < t + 12; i++) { getline(colormap, color); } colormap.close(); @@ -360,15 +360,7 @@ int addExoplanetSystem(lua_State* L) { "Radii = " + std::to_string(planetRadius) + "," //R. in meters. "SegmentsPerPatch = 64," "PerformShading = false," - "Layers = {" - "ColorLayers = {" - "{" - "Identifier = 'ExoplanetTexture'," - "FilePath = openspace.absPath('${DATA}/test3.jpg')," - "Enabled = true" - "}" - "}" - "}" + "Layers = {}" "}," "Transform = { Translation = " + planetKeplerTranslation + "}," "GUI = {" @@ -423,7 +415,7 @@ int addExoplanetSystem(lua_State* L) { "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc3.png')," + "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc_texture.png')," "Size = " + std::to_string(semiMajorAxisInMeter) + "," "Eccentricity = " + std::to_string(planet.ECC) + "," "Offset = { " + From bf7695ef69bee7a2a5a293c17b708cf05b26e0b7 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 2 Sep 2020 11:12:18 +0200 Subject: [PATCH 089/123] Reduce disc opacity a bit, so that trails are more visible --- modules/exoplanets/exoplanetsmodule_lua.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index f305f4c967..ffe1a821b1 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -422,7 +422,7 @@ int addExoplanetSystem(lua_State* L) { std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + " }," //min / max extend - "Opacity = 0.5" + "Opacity = 0.3" "}," "Transform = {" "Rotation = {" From 2bc0dd8efd2aae75c418f379b526c54fa140fc22 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 3 Sep 2020 11:29:12 +0200 Subject: [PATCH 090/123] Add a glare to the host star, similar to the sun --- modules/exoplanets/exoplanetsmodule_lua.inl | 35 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index ffe1a821b1..74f755ca41 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -221,9 +221,15 @@ int addExoplanetSystem(lua_State* L) { starToSunVec.z ); + const std::string starIdentifier = createIdentifier(starNameSpeck); + // Star renderable globe, if we have a radius std::string starGlobeRenderableString = ""; const float starRadius = p.RSTAR; + + const float validRadius = isnan(starRadius) ? 1.f : starRadius; + const float starRadiusInMeter = validRadius * distanceconstants::SolarRadius; + if (!isnan(starRadius)) { std::ifstream colorMap( absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), @@ -235,11 +241,10 @@ int addExoplanetSystem(lua_State* L) { } const std::string color = getStarColor(p.BMV, colorMap); - const float radiusInMeter = starRadius * distanceconstants::SolarRadius; starGlobeRenderableString = "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(radiusInMeter) + "," + "Radii = " + std::to_string(starRadiusInMeter) + "," "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" @@ -262,7 +267,6 @@ int addExoplanetSystem(lua_State* L) { "},"; } - const std::string starIdentifier = createIdentifier(starNameSpeck); const std::string starParent = "{" "Identifier = '" + starIdentifier + "'," @@ -284,11 +288,36 @@ int addExoplanetSystem(lua_State* L) { "}" "}"; + openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + starParent + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + const std::string starGlare = "{" + "Identifier = '" + starIdentifier + "_glare'," + "Parent = '" + starIdentifier + "'," + "Renderable = {" + "Type = 'RenderablePlaneImageLocal'," + "Size = " + std::to_string(10.f * starRadiusInMeter) + "," + "Origin = 'Center'," + "Billboard = true," + "Texture = openspace.absPath('${SYNC}/http/sun_textures/4/halo.png')," + "BlendMode = 'Additive'," + "Opacity = 0.65," + "RenderableType = 'PreDeferredTransparency'" + "}," + "GUI = {" + "Name = '" + starNameSpeck + " (Star Glare)'," + "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," + "}" + "}"; + + openspace::global::scriptEngine.queueScript( + "openspace.addSceneGraphNode(" + starGlare + ");", + openspace::scripting::ScriptEngine::RemoteScripting::Yes + ); + for (size_t i = 0; i < planetSystem.size(); i++) { Exoplanet planet = planetSystem[i]; const std::string planetName = planetNames[i]; From 6bbc0342f418d71b9a26c8a19c50b264f0877310 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 3 Sep 2020 11:29:24 +0200 Subject: [PATCH 091/123] Todo comment --- modules/exoplanets/exoplanetsmodule_lua.inl | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 74f755ca41..0f445c45c3 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -294,6 +294,7 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + //@TODO: emmbr (2020-09-03) tint the glare in the same color as the star const std::string starGlare = "{" "Identifier = '" + starIdentifier + "_glare'," "Parent = '" + starIdentifier + "'," From c8e8cf315cd88ac8cc1364ea3e0c5814a31f9da7 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 14 Sep 2020 09:12:28 +0200 Subject: [PATCH 092/123] Revert exoplanet star glare, for now --- modules/exoplanets/exoplanetsmodule_lua.inl | 36 ++------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 0f445c45c3..ffe1a821b1 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -221,15 +221,9 @@ int addExoplanetSystem(lua_State* L) { starToSunVec.z ); - const std::string starIdentifier = createIdentifier(starNameSpeck); - // Star renderable globe, if we have a radius std::string starGlobeRenderableString = ""; const float starRadius = p.RSTAR; - - const float validRadius = isnan(starRadius) ? 1.f : starRadius; - const float starRadiusInMeter = validRadius * distanceconstants::SolarRadius; - if (!isnan(starRadius)) { std::ifstream colorMap( absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), @@ -241,10 +235,11 @@ int addExoplanetSystem(lua_State* L) { } const std::string color = getStarColor(p.BMV, colorMap); + const float radiusInMeter = starRadius * distanceconstants::SolarRadius; starGlobeRenderableString = "Renderable = {" "Type = 'RenderableGlobe'," - "Radii = " + std::to_string(starRadiusInMeter) + "," + "Radii = " + std::to_string(radiusInMeter) + "," "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {" @@ -267,6 +262,7 @@ int addExoplanetSystem(lua_State* L) { "},"; } + const std::string starIdentifier = createIdentifier(starNameSpeck); const std::string starParent = "{" "Identifier = '" + starIdentifier + "'," @@ -288,37 +284,11 @@ int addExoplanetSystem(lua_State* L) { "}" "}"; - openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + starParent + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - //@TODO: emmbr (2020-09-03) tint the glare in the same color as the star - const std::string starGlare = "{" - "Identifier = '" + starIdentifier + "_glare'," - "Parent = '" + starIdentifier + "'," - "Renderable = {" - "Type = 'RenderablePlaneImageLocal'," - "Size = " + std::to_string(10.f * starRadiusInMeter) + "," - "Origin = 'Center'," - "Billboard = true," - "Texture = openspace.absPath('${SYNC}/http/sun_textures/4/halo.png')," - "BlendMode = 'Additive'," - "Opacity = 0.65," - "RenderableType = 'PreDeferredTransparency'" - "}," - "GUI = {" - "Name = '" + starNameSpeck + " (Star Glare)'," - "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," - "}" - "}"; - - openspace::global::scriptEngine.queueScript( - "openspace.addSceneGraphNode(" + starGlare + ");", - openspace::scripting::ScriptEngine::RemoteScripting::Yes - ); - for (size_t i = 0; i < planetSystem.size(); i++) { Exoplanet planet = planetSystem[i]; const std::string planetName = planetNames[i]; From 4e73a1b2ef4d340a1d73560a814c57fface91d88 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 14 Sep 2020 11:27:32 +0200 Subject: [PATCH 093/123] Cleanup csvtobin task slightly --- data/tasks/csvtobin.task | 11 ----------- data/tasks/exoplanets/csvtobin.task | 11 +++++++++++ modules/exoplanets/exoplanetsmodule_lua.inl | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 data/tasks/csvtobin.task create mode 100644 data/tasks/exoplanets/csvtobin.task diff --git a/data/tasks/csvtobin.task b/data/tasks/csvtobin.task deleted file mode 100644 index 70079659f9..0000000000 --- a/data/tasks/csvtobin.task +++ /dev/null @@ -1,11 +0,0 @@ -return { - { - Type = "ExoplanetsCsvToBinTask", - - InputCSV = "${BASE}/modules/exoplanets/exoplanets.csv", - InputSPECK = "${SYNC}/http/digitaluniverse_exoplanets_speck/1/expl.speck", - OutputBIN = "${BASE}/modules/exoplanets/expl_data.bin", - OutputLUT = "${BASE}/modules/exoplanets/lookup.txt" - -- OutputBIN = "${BASE}/sync/http/exoplanets_data/1/expl_data.bin" - } -} diff --git a/data/tasks/exoplanets/csvtobin.task b/data/tasks/exoplanets/csvtobin.task new file mode 100644 index 0000000000..c181496bb3 --- /dev/null +++ b/data/tasks/exoplanets/csvtobin.task @@ -0,0 +1,11 @@ +local dataFolder = "${BASE}/modules/exoplanets" +return { + { + Type = "ExoplanetsCsvToBinTask", + + InputCSV = dataFolder .. "/exoplanets.csv", + InputSPECK = "${SYNC}/http/digitaluniverse_exoplanets_speck/1/expl.speck", + OutputBIN = dataFolder .. "/exoplanets_data.bin", + OutputLUT = dataFolder .. "/lookup.txt" + } +} diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index ffe1a821b1..613fd5d0aa 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -130,7 +130,7 @@ int addExoplanetSystem(lua_State* L) { const std::string starNameSpeck = getSpeckStarName(starName); std::ifstream data( - absPath("${MODULE_EXOPLANETS}/expl_data.bin"), + absPath("${MODULE_EXOPLANETS}/exoplanets_data.bin"), std::ios::in | std::ios::binary ); From 0b4593a194f03951adf607a3ce51802759526514 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 16 Sep 2020 09:32:16 +0200 Subject: [PATCH 094/123] Put exoplanet data files on server and fetch using HttpSynchronization --- data/assets/base.asset | 2 ++ .../milkyway/exoplanets/exoplanets_data.asset | 7 ++++++ .../exoplanets/exoplanets_textures.asset | 7 ++++++ modules/exoplanets/exoplanetsmodule_lua.inl | 25 +++++++++++-------- .../tasks/exoplanetscsvtobintask.cpp | 6 ++--- 5 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 data/assets/scene/milkyway/exoplanets/exoplanets_data.asset create mode 100644 data/assets/scene/milkyway/exoplanets/exoplanets_textures.asset diff --git a/data/assets/base.asset b/data/assets/base.asset index 86bdf3cbd6..f0cb420c35 100644 --- a/data/assets/base.asset +++ b/data/assets/base.asset @@ -23,6 +23,8 @@ asset.require('scene/milkyway/milkyway/volume') asset.require('scene/milkyway/constellations/constellation_art') asset.require('scene/milkyway/constellations/constellation_keybinds') +assetHelper.requireAll(asset, 'scene/milkyway/exoplanets') + assetHelper.requireAll(asset, 'scene/digitaluniverse') -- Load default key bindings applicable to most scenes diff --git a/data/assets/scene/milkyway/exoplanets/exoplanets_data.asset b/data/assets/scene/milkyway/exoplanets/exoplanets_data.asset new file mode 100644 index 0000000000..b49f091844 --- /dev/null +++ b/data/assets/scene/milkyway/exoplanets/exoplanets_data.asset @@ -0,0 +1,7 @@ +local DataPath = asset.syncedResource({ + Name = "Exoplanet Data Files", + Type = "HttpSynchronization", + Identifier = "exoplanets_data", + Version = 1 +}) +asset.export("DataPath", DataPath) diff --git a/data/assets/scene/milkyway/exoplanets/exoplanets_textures.asset b/data/assets/scene/milkyway/exoplanets/exoplanets_textures.asset new file mode 100644 index 0000000000..287b29d61e --- /dev/null +++ b/data/assets/scene/milkyway/exoplanets/exoplanets_textures.asset @@ -0,0 +1,7 @@ +local TexturesPath = asset.syncedResource({ + Name = "Exoplanet Textures", + Type = "HttpSynchronization", + Identifier = "exoplanets_textures", + Version = 1 +}) +asset.export("TexturesPath", TexturesPath) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 613fd5d0aa..b921f46e7b 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -43,6 +43,14 @@ namespace openspace::exoplanets::luascriptfunctions { constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Systems/"; +constexpr const char* ExoplanetsDataPath = "${SYNC}/http/exoplanets_data/1/exoplanets_data.bin"; +constexpr const char* LookUpTablePath = "${SYNC}/http/exoplanets_data/1/lookup.txt"; + +constexpr const char* StarTextureFile = "${SYNC}/http/exoplanets_textures/1/sun.jpg"; +constexpr const char* DiscTextureFile = "${SYNC}/http/exoplanets_textures/1/disc_texture.png"; + +constexpr const char* BvColormapPath = "${SYNC}/http/stars_colormap/2/colorbv.cmap"; + std::string getStarColor(float bv, std::ifstream& colormap) { const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); std::string color; @@ -129,16 +137,13 @@ int addExoplanetSystem(lua_State* L) { // If user have given name as in EOD, change it to speck-name const std::string starNameSpeck = getSpeckStarName(starName); - std::ifstream data( - absPath("${MODULE_EXOPLANETS}/exoplanets_data.bin"), - std::ios::in | std::ios::binary - ); + std::ifstream data(absPath(ExoplanetsDataPath), std::ios::in | std::ios::binary); if (!data.good()) { return ghoul::lua::luaError(L, "Failed to open exoplanets data file"); } - std::ifstream lut(absPath("${MODULE_EXOPLANETS}/lookup.txt")); + std::ifstream lut(absPath(LookUpTablePath)); if (!lut.good()) { return ghoul::lua::luaError(L, "Failed to open exoplanets look-up table file"); } @@ -225,10 +230,7 @@ int addExoplanetSystem(lua_State* L) { std::string starGlobeRenderableString = ""; const float starRadius = p.RSTAR; if (!isnan(starRadius)) { - std::ifstream colorMap( - absPath("${SYNC}/http/stars_colormap/2/colorbv.cmap"), - std::ios::in - ); + std::ifstream colorMap(absPath(BvColormapPath), std::ios::in); if (!colorMap.good()) { ghoul::lua::luaError(L, "Failed to open colormap data file"); @@ -253,7 +255,7 @@ int addExoplanetSystem(lua_State* L) { "}," "{" "Identifier = 'StarTexture'," - "FilePath = openspace.absPath('${MODULE_EXOPLANETS}/sun.jpg')," + "FilePath = openspace.absPath('" + StarTextureFile +"')," "BlendMode = 'Color'," "Enabled = true" "}" @@ -289,6 +291,7 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); + // Planets for (size_t i = 0; i < planetSystem.size(); i++) { Exoplanet planet = planetSystem[i]; const std::string planetName = planetNames[i]; @@ -415,7 +418,7 @@ int addExoplanetSystem(lua_State* L) { "Enabled = true," "Renderable = {" "Type = 'RenderableOrbitdisc'," - "Texture = openspace.absPath('${MODULE_EXOPLANETS}/disc_texture.png')," + "Texture = openspace.absPath('" + DiscTextureFile + "')," "Size = " + std::to_string(semiMajorAxisInMeter) + "," "Eccentricity = " + std::to_string(planet.ECC) + "," "Offset = { " + diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 567d6d7cad..f621239432 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -41,6 +41,8 @@ namespace { const char* KeyOutputLut = "OutputLUT"; constexpr const char* _loggerCat = "CsvToBinTask"; + + constexpr const char* TeffBvPath = "${SYNC}/http/exoplanets_data/1/teff_bv.txt"; } // namespace namespace openspace::exoplanets { @@ -667,9 +669,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb // calculate B-V from Teff if not exsisting if (std::isnan(p.BMV)) { if (!std::isnan(teff)) { - std::ifstream teffToBvFile( - absPath("${BASE}/modules/exoplanets/teff_bv.txt") - ); + std::ifstream teffToBvFile(absPath(TeffBvPath)); if (!teffToBvFile.good()) { LERROR(fmt::format("Failed to open teff_bv.txt file")); From 2483d4a3fb8b412c49b9d8dd5c555efc5d8f3f35 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 16 Sep 2020 11:19:55 +0200 Subject: [PATCH 095/123] Cleanup rendering code --- .../rendering/renderableorbitdisc.cpp | 30 ++++--------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 0398a9d1fa..323789ee71 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -222,41 +223,20 @@ void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { _texture->bind(); _shader->setUniform(_uniformCache.texture, unit); - GLboolean blendEnabled = glIsEnabledi(GL_BLEND, 0); - GLenum blendEquationRGB; - GLenum blendEquationAlpha; - GLenum blendDestAlpha; - GLenum blendDestRGB; - GLenum blendSrcAlpha; - GLenum blendSrcRGB; - glGetIntegerv(GL_BLEND_EQUATION_RGB, &blendEquationRGB); - glGetIntegerv(GL_BLEND_EQUATION_ALPHA, &blendEquationAlpha); - glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDestAlpha); - glGetIntegerv(GL_BLEND_DST_RGB, &blendDestRGB); - glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrcAlpha); - glGetIntegerv(GL_BLEND_SRC_RGB, &blendSrcRGB); - glEnablei(GL_BLEND, 0); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDepthMask(false); - glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glBindVertexArray(_quad); glDrawArrays(GL_TRIANGLES, 0, 6); - glEnable(GL_CULL_FACE); _shader->deactivate(); - // Restores blending state - glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha); - glBlendFuncSeparate(blendSrcRGB, blendDestRGB, blendSrcAlpha, blendDestAlpha); - - glDepthMask(true); - - if (!blendEnabled) { - glDisablei(GL_BLEND, 0); - } + // Restores GL State + global::renderEngine.openglStateCache().resetBlendState(); + global::renderEngine.openglStateCache().resetDepthState(); + global::renderEngine.openglStateCache().resetPolygonAndClippingState(); } void RenderableOrbitdisc::update(const UpdateData& data) { From e0333553cb30e44cb8a9b1e73e997540c1554a03 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 16 Sep 2020 14:33:55 +0200 Subject: [PATCH 096/123] Some final cleanup --- modules/exoplanets/exoplanetsmodule_lua.inl | 51 ++++++++++++--------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index b921f46e7b..06c4fa5107 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -43,11 +44,13 @@ namespace openspace::exoplanets::luascriptfunctions { constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Systems/"; -constexpr const char* ExoplanetsDataPath = "${SYNC}/http/exoplanets_data/1/exoplanets_data.bin"; constexpr const char* LookUpTablePath = "${SYNC}/http/exoplanets_data/1/lookup.txt"; +constexpr const char* ExoplanetsDataPath = + "${SYNC}/http/exoplanets_data/1/exoplanets_data.bin"; constexpr const char* StarTextureFile = "${SYNC}/http/exoplanets_textures/1/sun.jpg"; -constexpr const char* DiscTextureFile = "${SYNC}/http/exoplanets_textures/1/disc_texture.png"; +constexpr const char* DiscTextureFile = + "${SYNC}/http/exoplanets_textures/1/disc_texture.png"; constexpr const char* BvColormapPath = "${SYNC}/http/stars_colormap/2/colorbv.cmap"; @@ -180,7 +183,9 @@ int addExoplanetSystem(lua_State* L) { data.close(); lut.close(); - if (!found || isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER)) { // || p.BINARY + bool notEnoughData = isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER); + + if (!found || notEnoughData) { return ghoul::lua::luaError( L, "No star with that name or not enough data about it." @@ -197,16 +202,15 @@ int addExoplanetSystem(lua_State* L) { const glm::dvec3 starToSunVec = normalize(sunPosition - starPosition); const glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); - const glm::dmat3 galaxticToCelectialMatrix = SpiceManager::ref().positionTransformMatrix( // galaxtic north in celectial coordinates, or just celectial north? - "GALACTIC", - "J2000", - 0.0 - ); + const glm::dmat3 galaxticToCelestialMatrix = + SpiceManager::ref().positionTransformMatrix("GALACTIC", "J2000", 0.0); + const glm::dvec3 celestialNorth = normalize( - galaxticToCelectialMatrix * galacticNorth + galaxticToCelestialMatrix * galacticNorth ); - // Earth's north vector projected onto the skyplane, the plane perpendicular to the viewing vector (starToSunVec) + // Earth's north vector projected onto the skyplane, the plane perpendicular to the + // viewing vector (starToSunVec) const float celestialAngle = dot(celestialNorth, starToSunVec); glm::dvec3 northProjected = glm::normalize( celestialNorth - (celestialAngle / glm::length(starToSunVec)) * starToSunVec @@ -265,6 +269,7 @@ int addExoplanetSystem(lua_State* L) { } const std::string starIdentifier = createIdentifier(starNameSpeck); + const std::string guiPath = ExoplanetsGuiPath + starNameSpeck; const std::string starParent = "{" "Identifier = '" + starIdentifier + "'," @@ -282,7 +287,7 @@ int addExoplanetSystem(lua_State* L) { "}," "GUI = {" "Name = '" + starNameSpeck + " (Star)'," - "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," + "Path = '" + guiPath + "'" "}" "}"; @@ -312,7 +317,7 @@ int addExoplanetSystem(lua_State* L) { std::string sEpoch; if (!isnan(planet.TT)) { epoch.setTime("JD " + std::to_string(planet.TT)); - sEpoch = epoch.ISO8601(); + sEpoch = std::string(epoch.ISO8601()); } else { sEpoch = "2009-05-19T07:11:34.080"; @@ -346,11 +351,11 @@ int addExoplanetSystem(lua_State* L) { "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," "Inclination = " + std::to_string(planet.I) + "," //I - "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM + "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss - "Period = " + std::to_string(period) + "," + "Period = " + std::to_string(period) + "" "}"; const std::string planetNode = "{" @@ -365,10 +370,12 @@ int addExoplanetSystem(lua_State* L) { "PerformShading = false," "Layers = {}" "}," - "Transform = { Translation = " + planetKeplerTranslation + "}," + "Transform = { " + "Translation = " + planetKeplerTranslation + "" + "}," "GUI = {" "Name = '" + planetName + "'," - "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," + "Path = '" + guiPath + "'" "}" "}"; @@ -390,7 +397,7 @@ int addExoplanetSystem(lua_State* L) { "}," "GUI = {" "Name = '" + planetName + " Trail'," - "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," + "Path = '" + guiPath + "'" "}" "}"; @@ -404,7 +411,7 @@ int addExoplanetSystem(lua_State* L) { if (hasUpperAUncertainty && hasLowerAUncertainty) { - // Get the orbit plane that the trail orbit and planet have from the KeplerTranslation + // Get the orbit plane of the planet trail orbit from the KeplerTranslation const glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( planet.I, planet.BIGOM, @@ -424,18 +431,18 @@ int addExoplanetSystem(lua_State* L) { "Offset = { " + std::to_string(planet.ALOWER) + ", " + std::to_string(planet.AUPPER) + - " }," //min / max extend + "}," //min / max extend "Opacity = 0.3" "}," "Transform = {" "Rotation = {" "Type = 'StaticRotation'," - "Rotation = " + ghoul::to_string(rotation) + "," + "Rotation = " + ghoul::to_string(rotation) + "" "}" "}," "GUI = {" "Name = '" + planetName + " Disc'," - "Path = '" + ExoplanetsGuiPath + starNameSpeck + "'," + "Path = '" + guiPath + "'" "}" "}"; From 57e25050e19bc971c7d29b11dad5182b17277a75 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 16 Sep 2020 14:34:37 +0200 Subject: [PATCH 097/123] Abort if trying to add the same system twice --- modules/exoplanets/exoplanetsmodule_lua.inl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 06c4fa5107..3337553eb6 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -140,6 +140,19 @@ int addExoplanetSystem(lua_State* L) { // If user have given name as in EOD, change it to speck-name const std::string starNameSpeck = getSpeckStarName(starName); + const std::string starIdentifier = createIdentifier(starNameSpeck); + const std::string guiPath = ExoplanetsGuiPath + starNameSpeck; + + SceneGraphNode* existingStarNode = + global::renderEngine.scene()->sceneGraphNode(starIdentifier); + + if (existingStarNode) { + return ghoul::lua::luaError( + L, + "Adding of exoplanet system failed. The system has already been added." + ); + } + std::ifstream data(absPath(ExoplanetsDataPath), std::ios::in | std::ios::binary); if (!data.good()) { @@ -268,9 +281,6 @@ int addExoplanetSystem(lua_State* L) { "},"; } - const std::string starIdentifier = createIdentifier(starNameSpeck); - const std::string guiPath = ExoplanetsGuiPath + starNameSpeck; - const std::string starParent = "{" "Identifier = '" + starIdentifier + "'," "Parent = 'SolarSystemBarycenter'," From 0d1e464a6422d25cb5ff864721aabdef37271778 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 16 Sep 2020 15:16:15 +0200 Subject: [PATCH 098/123] Documentation cleanup and capitalize first letter in "Disc" in renderable --- modules/exoplanets/exoplanetsmodule.cpp | 7 +++-- modules/exoplanets/exoplanetsmodule_lua.inl | 2 +- .../rendering/renderableorbitdisc.cpp | 28 +++++++++---------- .../rendering/renderableorbitdisc.h | 4 +-- .../tasks/exoplanetscsvtobintask.cpp | 4 +-- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 4d0f40eea5..60f5579b3b 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -55,14 +55,15 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { &exoplanets::luascriptfunctions::addExoplanetSystem, {}, "string", - "Adds the nodes to the scene graph of the exoplanet system." + "Add the exoplanet system specified by the input string, including " + "information about the host star and planets." }, { "removeExoplanetSystem", &exoplanets::luascriptfunctions::removeExoplanetSystem, {}, "string", - "Removes the nodes from the scene graph of the exoplanet system." + "Removes the nodes of the specified exoplanet system from the scene graph." } }; @@ -74,7 +75,7 @@ void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) { auto fRenderable = FactoryManager::ref().factory(); ghoul_assert(fTask, "No task factory existed"); fTask->registerClass("ExoplanetsCsvToBinTask"); - fRenderable->registerClass("RenderableOrbitdisc"); + fRenderable->registerClass("RenderableOrbitDisc"); } std::vector ExoplanetsModule::documentations() const { diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 3337553eb6..a38e5cd167 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -434,7 +434,7 @@ int addExoplanetSystem(lua_State* L) { "Parent = '" + starIdentifier + "'," "Enabled = true," "Renderable = {" - "Type = 'RenderableOrbitdisc'," + "Type = 'RenderableOrbitDisc'," "Texture = openspace.absPath('" + DiscTextureFile + "')," "Size = " + std::to_string(semiMajorAxisInMeter) + "," "Eccentricity = " + std::to_string(planet.ECC) + "," diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 323789ee71..4ecae7ad63 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -69,15 +69,15 @@ namespace { namespace openspace { -documentation::Documentation RenderableOrbitdisc::Documentation() { +documentation::Documentation RenderableOrbitDisc::Documentation() { using namespace documentation; return { - "Renderable Orbitdisc", - "exoplanets_renderable_orbitdisc", + "Renderable Orbit Disc", + "exoplanets_renderable_orbit_disc", { { "Type", - new StringEqualVerifier("RenderableOrbitdisc"), + new StringEqualVerifier("RenderableOrbitDisc"), Optional::No }, { @@ -108,7 +108,7 @@ documentation::Documentation RenderableOrbitdisc::Documentation() { }; } -RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) +RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary) : Renderable(dictionary) , _texturePath(TextureInfo) , _size(SizeInfo, 1.f, 0.f, 3.0e12f) @@ -127,7 +127,7 @@ RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) documentation::testSpecificationAndThrow( Documentation(), dictionary, - "RenderableOrbitdisc" + "RenderableOrbitDisc" ); if (dictionary.hasKey(OffsetInfo.identifier)) { @@ -158,11 +158,11 @@ RenderableOrbitdisc::RenderableOrbitdisc(const ghoul::Dictionary& dictionary) addProperty(_opacity); } -bool RenderableOrbitdisc::isReady() const { +bool RenderableOrbitDisc::isReady() const { return _shader && _texture; } -void RenderableOrbitdisc::initializeGL() { +void RenderableOrbitDisc::initializeGL() { _shader = global::renderEngine.buildRenderProgram( "OrbitdiscProgram", absPath("${BASE}/modules/exoplanets/shaders/orbitdisc_vs.glsl"), @@ -185,7 +185,7 @@ void RenderableOrbitdisc::initializeGL() { loadTexture(); } -void RenderableOrbitdisc::deinitializeGL() { +void RenderableOrbitDisc::deinitializeGL() { glDeleteVertexArrays(1, &_quad); _quad = 0; @@ -199,7 +199,7 @@ void RenderableOrbitdisc::deinitializeGL() { _shader = nullptr; } -void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { +void RenderableOrbitDisc::render(const RenderData& data, RendererTasks&) { _shader->activate(); glm::dmat4 modelTransform = @@ -239,7 +239,7 @@ void RenderableOrbitdisc::render(const RenderData& data, RendererTasks&) { global::renderEngine.openglStateCache().resetPolygonAndClippingState(); } -void RenderableOrbitdisc::update(const UpdateData& data) { +void RenderableOrbitDisc::update(const UpdateData& data) { if (_shader->isDirty()) { _shader->rebuildFromFile(); _uniformCache.modelViewProjection = _shader->uniformLocation( @@ -263,14 +263,14 @@ void RenderableOrbitdisc::update(const UpdateData& data) { } } -void RenderableOrbitdisc::loadTexture() { +void RenderableOrbitDisc::loadTexture() { if (_texturePath.value() != "") { std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); if (texture) { LDEBUGC( - "RenderableOrbitdisc", + "RenderableOrbitDisc", fmt::format("Loaded texture from '{}'", absPath(_texturePath)) ); _texture = std::move(texture); @@ -286,7 +286,7 @@ void RenderableOrbitdisc::loadTexture() { } } -void RenderableOrbitdisc::createPlane() { +void RenderableOrbitDisc::createPlane() { const GLfloat size = _size.value() * (1.0 + _eccentricity.value()); struct VertexData { diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index d70751ba2b..14c5915736 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -42,9 +42,9 @@ namespace openspace { namespace documentation { struct Documentation; } -class RenderableOrbitdisc : public Renderable { +class RenderableOrbitDisc : public Renderable { public: - RenderableOrbitdisc(const ghoul::Dictionary& dictionary); + RenderableOrbitDisc(const ghoul::Dictionary& dictionary); void initializeGL() override; void deinitializeGL() override; diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index f621239432..73b1dd9b6a 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -740,7 +740,7 @@ documentation::Documentation ExoplanetsCsvToBinTask::documentation() { "Type", new StringEqualVerifier("ExoplanetsCsvToBinTask"), Optional::No, - "The type of this task" + "" }, { KeyInputCsv, @@ -752,7 +752,7 @@ documentation::Documentation ExoplanetsCsvToBinTask::documentation() { KeyInputSpeck, new StringAnnotationVerifier("A file path to a speck file"), Optional::No, - "The speck file with star location" + "The speck file with star locations" }, { KeyOutputBin, From 5671ea1463ccdef287758b0e54242b3272d96f65 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 17 Sep 2020 16:36:02 +0200 Subject: [PATCH 099/123] Update copyright end year (woops) --- modules/exoplanets/CMakeLists.txt | 2 +- modules/exoplanets/exoplanetshelper.cpp | 2 +- modules/exoplanets/exoplanetshelper.h | 2 +- modules/exoplanets/exoplanetsmodule.cpp | 2 +- modules/exoplanets/exoplanetsmodule.h | 2 +- modules/exoplanets/exoplanetsmodule_lua.inl | 2 +- modules/exoplanets/rendering/renderableorbitdisc.cpp | 2 +- modules/exoplanets/rendering/renderableorbitdisc.h | 2 +- modules/exoplanets/shaders/orbitdisc_fs.glsl | 2 +- modules/exoplanets/shaders/orbitdisc_vs.glsl | 2 +- modules/exoplanets/tasks/exoplanetscsvtobintask.cpp | 2 +- modules/exoplanets/tasks/exoplanetscsvtobintask.h | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/exoplanets/CMakeLists.txt b/modules/exoplanets/CMakeLists.txt index c69c11e49c..3a1902cb9f 100644 --- a/modules/exoplanets/CMakeLists.txt +++ b/modules/exoplanets/CMakeLists.txt @@ -2,7 +2,7 @@ # # # OpenSpace # # # -# Copyright (c) 2014-2018 # +# Copyright (c) 2014-2020 # # # # Permission is hereby granted, free of charge, to any person obtaining a copy of this # # software and associated documentation files (the "Software"), to deal in the Software # diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index df8a4003a6..95f13eaeb2 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h index 92bfc82d3e..c9f07b4b17 100644 --- a/modules/exoplanets/exoplanetshelper.h +++ b/modules/exoplanets/exoplanetshelper.h @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 60f5579b3b..7b92e850c9 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index cf6d4e31ac..d4d7dde329 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index a38e5cd167..252b780052 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -2,7 +2,7 @@ * * * OpenSpace * * * -* Copyright (c) 2014-2018 * +* Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 4ecae7ad63..9eed430738 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index 14c5915736..7d68d33d81 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 457395f22a..2bba81566e 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/shaders/orbitdisc_vs.glsl b/modules/exoplanets/shaders/orbitdisc_vs.glsl index 1eebfb5d55..65ff4bdabe 100644 --- a/modules/exoplanets/shaders/orbitdisc_vs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_vs.glsl @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 73b1dd9b6a..bdd54f99c0 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 483e4fa045..2e764eb6b1 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -2,7 +2,7 @@ * * * OpenSpace * * * - * Copyright (c) 2014-2018 * + * Copyright (c) 2014-2020 * * * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * * software and associated documentation files (the "Software"), to deal in the Software * From f2b4909a3202b6f056d30056339296bbcc17df15 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 08:50:06 +0200 Subject: [PATCH 100/123] Some cleanup of helper functions --- modules/exoplanets/exoplanetshelper.cpp | 278 ++++++------------ modules/exoplanets/exoplanetshelper.h | 4 +- modules/exoplanets/exoplanetsmodule_lua.inl | 4 +- .../tasks/exoplanetscsvtobintask.cpp | 2 +- 4 files changed, 98 insertions(+), 190 deletions(-) diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index 95f13eaeb2..1e685ce052 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -26,192 +26,100 @@ namespace openspace::exoplanets { -std::string getSpeckStarName(std::string csvName) { - std::string name = csvName; - if (csvName == "HD 1237") - name = "GJ 3021"; - else if (csvName == "MOA-2009-BLG-387L") - name = "MOA 2009-BLG-387L"; - else if (csvName == "HD 126614 A") - name = "HD 126614"; - else if (csvName == "epsilon Ret") - name = "HD 27442"; - else if (csvName == "PH-1") - name = "PH1"; - else if (csvName == "gamma Leo A") - name = "gam 1 Leo"; - else if (csvName == "OGLE-2007-BLG-368L") - name = "OGLE 2007-BLG-368L"; - else if (csvName == "alpha Ari") - name = "alf Ari"; - else if (csvName == "mu Ara") - name = "HD 160691"; - else if (csvName == "OGLE-05-169L") - name = "OGLE 2005-BLG-169L"; - else if (csvName == "tau Gru") - name = "HD 216435"; - else if (csvName == "iota Hor") - name = "HR 810"; - else if (csvName == "OGLE-05-071L") - name = "OGLE 2005-BLG-71L"; - else if (csvName == "OGLE235-MOA53") - name = "OGLE 2003-BLG-235L"; - else if (csvName == "MOA-2008-BLG-310L") - name = "MOA 2008-BLG-310L"; - else if (csvName == "KIC 11442793") - name = "KOI-351"; - else if (csvName == "OGLE-2006-BLG-109L") - name = "OGLE 2006-BLG-109L"; - else if (csvName == "HD 137388") - name = "HD 137388 A"; - else if (csvName == "kappa CrB") - name = "kap CrB"; - else if (csvName == "XO-2") - name = "XO-2 N"; - else if (csvName == "epsilon Tau") - name = "eps Tau"; - else if (csvName == "epsilon Eri") - name = "eps Eri"; - else if (csvName == "Kepler-448") - name = "KOI-12"; - else if (csvName == "omega Ser") - name = "ome Ser"; - else if (csvName == "MOA-2010-BLG-477L") - name = "MOA 2010-BLG-477L"; - else if (csvName == "GJ 176") - name = "HD 285968"; - else if (csvName == "HIP 2247") - name = "BD-17 63"; - else if (csvName == "MOA-2009-BLG-266L") - name = "MOA 2009-BLG-266L"; - else if (csvName == "Kepler-89") - name = "KOI-94"; - else if (csvName == "iota Dra") - name = "HIP 75458"; - else if (csvName == "MOA-2007-BLG-400L") - name = "MOA 2007-BLG-400L"; - else if (csvName == "upsilon And") - name = "ups And"; - else if (csvName == "OGLE-2011-BLG-0251") - name = "OGLE 2011-BLG-251L"; - else if (csvName == "OGLE-05-390L") - name = "OGLE 2005-BLG-390L"; - else if (csvName == "Kepler-420") - name = "KOI-1257"; - else if (csvName == "beta Pic") - name = "bet Pic"; - else if (csvName == "gamma Cep") - name = "gam Cep"; - else if (csvName == "MOA-2007-BLG-192L") - name = "MOA 2007-BLG-192L"; - else if (csvName == "MOA-2009-BLG-319L") - name = "MOA 2009-BLG-319L"; - else if (csvName == "omicron CrB") - name = "omi CrB"; - else if (csvName == "beta Gem") - name = "HD 62509"; - else if (csvName == "epsilon CrB") - name = "eps CrB"; - else if (csvName == "omicron UMa") - name = "omi UMa"; - else if (csvName == "HD 142022") - name = "HD 142022 A"; - - return name; -} - -std::string getCsvStarName(std::string name) { - std::string csvName = name; - if (name == "GJ 3021") - csvName = "HD 1237"; - else if (name == "MOA 2009-BLG-387L") - csvName = "MOA-2009-BLG-387L"; - else if (name == "HD 126614") - csvName = "HD 126614 A"; - else if (name == "HD 27442") - csvName = "epsilon Ret"; - else if (name == "PH1") - csvName = "PH-1"; - else if (name == "gam 1 Leo") - csvName = "gamma Leo A"; - else if (name == "OGLE 2007-BLG-368L") - csvName = "OGLE-2007-BLG-368L"; - else if (name == "alf Ari") - csvName = "alpha Ari"; - else if (name == "HD 160691") - csvName = "mu Ara"; - else if (name == "OGLE 2005-BLG-169L") - csvName = "OGLE-05-169L"; - else if (name == "HD 216435") - csvName = "tau Gru"; - else if (name == "HR 810") - csvName = "iota Hor"; - else if (name == "OGLE 2005-BLG-71L") - csvName = "OGLE-05-071L"; - else if (name == "OGLE 2003-BLG-235L") - csvName = "OGLE235-MOA53"; - else if (name == "MOA 2008-BLG-310L") - csvName = "MOA-2008-BLG-310L"; - else if (name == "KOI-351") - csvName = "KIC 11442793"; - else if (name == "OGLE 2006-BLG-109L") - csvName = "OGLE-2006-BLG-109L"; - else if (name == "HD 137388 A") - csvName = "HD 137388"; - else if (name == "kap CrB") - csvName = "kappa CrB"; - else if (name == "XO-2 N") - csvName = "XO-2"; - else if (name == "eps Tau") - csvName = "epsilon Tau"; - else if (name == "eps Eri") - csvName = "epsilon Eri"; - else if (name == "KOI-12") - csvName = "Kepler-448"; - else if (name == "ome Ser") - csvName = "omega Ser"; - else if (name == "MOA 2010-BLG-477L") - csvName = "MOA-2010-BLG-477L"; - else if (name == "HD 285968") - csvName = "GJ 176"; - else if (name == "BD-17 63") - csvName = "HIP 2247"; - else if (name == "MOA 2009-BLG-266L") - csvName = "MOA-2009-BLG-266L"; - else if (name == "KOI-94") - csvName = "Kepler-89"; - else if (name == "HIP 75458") - csvName = "iota Dra"; - else if (name == "MOA 2007-BLG-400L") - csvName = "MOA-2007-BLG-400L"; - else if (name == "ups And") - csvName = "upsilon And"; - else if (name == "OGLE 2011-BLG-251L") - csvName = "OGLE-2011-BLG-0251"; - else if (name == "OGLE 2005-BLG-390L") - csvName = "OGLE-05-390L"; - else if (name == "KOI-1257") - csvName = "Kepler-420"; - else if (name == "bet Pic") - csvName = "beta Pic"; - else if (name == "gam Cep") - csvName = "gamma Cep"; - else if (name == "MOA 2007-BLG-192L") - csvName = "MOA-2007-BLG-192L"; - else if (name == "MOA 2009-BLG-319L") - csvName = "MOA-2009-BLG-319L"; - else if (name == "omi CrB") - csvName = "omicron CrB"; - else if (name == "HD 62509") - csvName = "beta Gem"; - else if (name == "eps CrB") - csvName = "epsilon CrB"; - else if (name == "omi UMa") - csvName = "omicron UMa"; - else if (name == "HD 142022 A") - csvName = "HD 142022"; - +std::string speckStarName(std::string csvName) { + if (csvName == "HD 1237") { return "GJ 3021"; } + if (csvName == "MOA-2009-BLG-387L") { return "MOA 2009-BLG-387L"; } + if (csvName == "HD 126614 A") { return "HD 126614"; } + if (csvName == "epsilon Ret") { return "HD 27442"; } + if (csvName == "PH-1") { return "PH1"; } + if (csvName == "gamma Leo A") { return "gam 1 Leo"; } + if (csvName == "OGLE-2007-BLG-368L") { return "OGLE 2007-BLG-368L"; } + if (csvName == "alpha Ari") { return "alf Ari"; } + if (csvName == "mu Ara") { return "HD 160691"; } + if (csvName == "OGLE-05-169L") { return "OGLE 2005-BLG-169L"; } + if (csvName == "tau Gru") { return "HD 216435"; } + if (csvName == "iota Hor") { return "HR 810"; } + if (csvName == "OGLE-05-071L") { return "OGLE 2005-BLG-71L"; } + if (csvName == "OGLE235-MOA53") { return "OGLE 2003-BLG-235L"; } + if (csvName == "MOA-2008-BLG-310L") { return "MOA 2008-BLG-310L"; } + if (csvName == "KIC 11442793") { return "KOI-351"; } + if (csvName == "OGLE-2006-BLG-109L") { return "OGLE 2006-BLG-109L"; } + if (csvName == "HD 137388") { return "HD 137388 A"; } + if (csvName == "kappa CrB") { return "kap CrB"; } + if (csvName == "XO-2") { return "XO-2 N"; } + if (csvName == "epsilon Tau") { return "eps Tau"; } + if (csvName == "epsilon Eri") { return "eps Eri"; } + if (csvName == "Kepler-448") { return "KOI-12"; } + if (csvName == "omega Ser") { return "ome Ser"; } + if (csvName == "MOA-2010-BLG-477L") { return "MOA 2010-BLG-477L"; } + if (csvName == "GJ 176") { return "HD 285968"; } + if (csvName == "HIP 2247") { return "BD-17 63"; } + if (csvName == "MOA-2009-BLG-266L") { return "MOA 2009-BLG-266L"; } + if (csvName == "Kepler-89") { return "KOI-94"; } + if (csvName == "iota Dra") { return "HIP 75458"; } + if (csvName == "MOA-2007-BLG-400L") { return "MOA 2007-BLG-400L"; } + if (csvName == "upsilon And") { return "ups And"; } + if (csvName == "OGLE-2011-BLG-0251") { return "OGLE 2011-BLG-251L"; } + if (csvName == "OGLE-05-390L") { return "OGLE 2005-BLG-390L"; } + if (csvName == "Kepler-420") { return "KOI-1257"; } + if (csvName == "beta Pic") { return "bet Pic"; } + if (csvName == "gamma Cep") { return "gam Cep"; } + if (csvName == "MOA-2007-BLG-192L") { return "MOA 2007-BLG-192L"; } + if (csvName == "MOA-2009-BLG-319L") { return "MOA 2009-BLG-319L"; } + if (csvName == "omicron CrB") { return "omi CrB"; } + if (csvName == "beta Gem") { return "HD 62509"; } + if (csvName == "epsilon CrB") { return "eps CrB"; } + if (csvName == "omicron UMa") { return "omi UMa"; } + if (csvName == "HD 142022") { return "HD 142022 A"; } return csvName; } +std::string csvStarName(std::string name) { + if (name == "GJ 3021") { return "HD 1237"; } + if (name == "MOA 2009-BLG-387L") { return "MOA-2009-BLG-387L"; } + if (name == "HD 126614") { return "HD 126614 A"; } + if (name == "HD 27442") { return "epsilon Ret"; } + if (name == "PH1") { return "PH-1"; } + if (name == "gam 1 Leo") { return "gamma Leo A"; } + if (name == "OGLE 2007-BLG-368L") { return "OGLE-2007-BLG-368L"; } + if (name == "alf Ari") { return "alpha Ari"; } + if (name == "HD 160691") { return "mu Ara"; } + if (name == "OGLE 2005-BLG-169L") { return "OGLE-05-169L"; } + if (name == "HD 216435") { return "tau Gru"; } + if (name == "HR 810") { return "iota Hor"; } + if (name == "OGLE 2005-BLG-71L") { return "OGLE-05-071L"; } + if (name == "OGLE 2003-BLG-235L") { return "OGLE235-MOA53"; } + if (name == "MOA 2008-BLG-310L") { return "MOA-2008-BLG-310L"; } + if (name == "KOI-351") { return "KIC 11442793"; } + if (name == "OGLE 2006-BLG-109L") { return "OGLE-2006-BLG-109L"; } + if (name == "HD 137388 A") { return "HD 137388"; } + if (name == "kap CrB") { return "kappa CrB"; } + if (name == "XO-2 N") { return "XO-2"; } + if (name == "eps Tau") { return "epsilon Tau"; } + if (name == "eps Eri") { return "epsilon Eri"; } + if (name == "KOI-12") { return "Kepler-448"; } + if (name == "ome Ser") { return "omega Ser"; } + if (name == "MOA 2010-BLG-477L") { return "MOA-2010-BLG-477L"; } + if (name == "HD 285968") { return "GJ 176"; } + if (name == "BD-17 63") { return "HIP 2247"; } + if (name == "MOA 2009-BLG-266L") { return "MOA-2009-BLG-266L"; } + if (name == "KOI-94") { return "Kepler-89"; } + if (name == "HIP 75458") { return "iota Dra"; } + if (name == "MOA 2007-BLG-400L") { return "MOA-2007-BLG-400L"; } + if (name == "ups And") { return "upsilon And"; } + if (name == "OGLE 2011-BLG-251L") { return "OGLE-2011-BLG-0251"; } + if (name == "OGLE 2005-BLG-390L") { return "OGLE-05-390L"; } + if (name == "KOI-1257") { return "Kepler-420"; } + if (name == "bet Pic") { return "beta Pic"; } + if (name == "gam Cep") { return "gamma Cep"; } + if (name == "MOA 2007-BLG-192L") { return "MOA-2007-BLG-192L"; } + if (name == "MOA 2009-BLG-319L") { return "MOA-2009-BLG-319L"; } + if (name == "omi CrB") { return "omicron CrB"; } + if (name == "HD 62509") { return "beta Gem"; } + if (name == "eps CrB") { return "epsilon CrB"; } + if (name == "omi UMa") { return "omicron UMa"; } + if (name == "HD 142022 A") { return "HD 142022"; } + return name; +} + } // namespace openspace::exoplanets diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h index c9f07b4b17..1490cb9a0f 100644 --- a/modules/exoplanets/exoplanetshelper.h +++ b/modules/exoplanets/exoplanetshelper.h @@ -75,10 +75,10 @@ struct Exoplanet { }; // Convert csv-file specific names to the corresponding name in the speck data file -std::string getSpeckStarName(std::string name); +std::string speckStarName(std::string name); // Convert speck-file specific names to the corresponding name in the csv data file -std::string getCsvStarName(std::string name); +std::string csvStarName(std::string name); } // namespace openspace::exoplanets diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 252b780052..a08944a5fd 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -138,7 +138,7 @@ int addExoplanetSystem(lua_State* L) { const std::string starName = luaL_checkstring(L, StringLocation); // If user have given name as in EOD, change it to speck-name - const std::string starNameSpeck = getSpeckStarName(starName); + const std::string starNameSpeck = speckStarName(starName); const std::string starIdentifier = createIdentifier(starNameSpeck); const std::string guiPath = ExoplanetsGuiPath + starNameSpeck; @@ -469,7 +469,7 @@ int addExoplanetSystem(lua_State* L) { int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); - const std::string starNameSpeck = getSpeckStarName(starName); + const std::string starNameSpeck = speckStarName(starName); const std::string starIdentifier = createIdentifier(starNameSpeck); openspace::global::scriptEngine.queueScript( diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index bdd54f99c0..f6380826d3 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -589,7 +589,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // SPECREF getline(lineStream, data, ','); // SPECURL getline(lineStream, data, ','); // STAR - std::string speckStarname = getSpeckStarName(data); + std::string speckStarname = speckStarName(data); glm::vec3 position = getStarPosition(speckStarname); p.POSITIONX = position[0]; p.POSITIONY = position[1]; From d0806e0136fd601716f8f908451db42fc631ab54 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 09:33:04 +0200 Subject: [PATCH 101/123] Cleanup --- modules/exoplanets/exoplanetsmodule.cpp | 6 +- modules/exoplanets/exoplanetsmodule.h | 3 +- modules/exoplanets/exoplanetsmodule_lua.inl | 64 ++++++++++--------- .../rendering/renderableorbitdisc.cpp | 3 +- .../tasks/exoplanetscsvtobintask.cpp | 48 +++++++------- .../exoplanets/tasks/exoplanetscsvtobintask.h | 2 +- 6 files changed, 64 insertions(+), 62 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 7b92e850c9..f534572c6a 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -33,14 +33,14 @@ #include #include #include -#include -#include +#include +#include #include "exoplanetsmodule_lua.inl" namespace openspace { -const char* _loggerCat = "exoplanets"; +constexpr const char* _loggerCat = "exoplanets"; using namespace exoplanets; diff --git a/modules/exoplanets/exoplanetsmodule.h b/modules/exoplanets/exoplanetsmodule.h index d4d7dde329..3a9ea264f4 100644 --- a/modules/exoplanets/exoplanetsmodule.h +++ b/modules/exoplanets/exoplanetsmodule.h @@ -25,9 +25,10 @@ #ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ #define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__ -#include #include +#include + namespace openspace { class ExoplanetsModule : public OpenSpaceModule { diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index a08944a5fd..9c9b33fc33 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -54,7 +55,7 @@ constexpr const char* DiscTextureFile = constexpr const char* BvColormapPath = "${SYNC}/http/stars_colormap/2/colorbv.cmap"; -std::string getStarColor(float bv, std::ifstream& colormap) { +std::string starColor(float bv, std::ifstream& colormap) { const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); std::string color; for (int i = 0; i < t + 12; i++) { @@ -68,7 +69,7 @@ std::string getStarColor(float bv, std::ifstream& colormap) { getline(colorStream, g, ' '); getline(colorStream, b, ' '); - return "{" + r + ", " + g + ", " + b + "}"; + return fmt::format("{{ {}, {}, {} }}", r, g, b); } glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { @@ -91,8 +92,9 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { // Rotate the original coordinate system (where x is pointing to First Point of Aries) // so that x is pointing from star to the sun. -// Modified from http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-17-quaternions/#how-do-i-find-the-rotation-between-2-vectors- -glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { +// Modified from "http://www.opengl-tutorial.org/intermediate-tutorials/ +// tutorial-17-quaternions/ #how-do-i-find-the-rotation-between-2-vectors" +glm::dmat3 exoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { glm::quat rotationQuat; glm::dvec3 rotationAxis; const float cosTheta = dot(start, end); @@ -103,8 +105,10 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { // there is no "ideal" rotation axis // So guess one; any will do as long as it's perpendicular to start vector rotationAxis = cross(glm::dvec3(0.0, 0.0, 1.0), start); - if (length2(rotationAxis) < 0.01f) // bad luck, they were parallel, try again! + if (length2(rotationAxis) < 0.01f) { + // bad luck, they were parallel, try again! rotationAxis = cross(glm::dvec3(1.0, 0.0, 0.0), start); + } rotationAxis = normalize(rotationAxis); rotationQuat = glm::quat(glm::radians(180.f), rotationAxis); @@ -127,10 +131,9 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { } // Create an identifier without whitespaces -std::string createIdentifier(const std::string& name) { - std::string res = name; - std::replace(res.begin(), res.end(), ' ', '_'); - return res; +std::string createIdentifier(std::string name) { + std::replace(name.begin(), name.end(), ' ', '_'); + return name; } int addExoplanetSystem(lua_State* L) { @@ -164,9 +167,9 @@ int addExoplanetSystem(lua_State* L) { return ghoul::lua::luaError(L, "Failed to open exoplanets look-up table file"); } - //1. search lut for the starname and return the corresponding location - //2. go to that location in the data file - //3. read sizeof(exoplanet) bytes into an exoplanet object. + // 1. search lut for the starname and return the corresponding location + // 2. go to that location in the data file + // 3. read sizeof(exoplanet) bytes into an exoplanet object. Exoplanet p; std::string line; bool found = false; @@ -185,7 +188,7 @@ int addExoplanetSystem(lua_State* L) { long location = std::stol(location_s.c_str()); data.seekg(location); - data.read((char*)&p, sizeof(Exoplanet)); + data.read(reinterpret_cast(&p), sizeof(Exoplanet)); planetNames.push_back(name); planetSystem.push_back(p); @@ -198,7 +201,7 @@ int addExoplanetSystem(lua_State* L) { bool notEnoughData = isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER); - if (!found || notEnoughData) { + if (!found || notEnoughData) { return ghoul::lua::luaError( L, "No star with that name or not enough data about it." @@ -206,7 +209,7 @@ int addExoplanetSystem(lua_State* L) { } const glm::dvec3 starPosition = glm::dvec3( - p.POSITIONX * distanceconstants::Parsec, + p.POSITIONX * distanceconstants::Parsec, p.POSITIONY * distanceconstants::Parsec, p.POSITIONZ * distanceconstants::Parsec ); @@ -232,19 +235,19 @@ int addExoplanetSystem(lua_State* L) { const glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected)); const glm::dmat3 exoplanetSystemRotation = glm::dmat3( - northProjected.x, - northProjected.y, + northProjected.x, + northProjected.y, northProjected.z, - beta.x, - beta.y, + beta.x, + beta.y, beta.z, - starToSunVec.x, - starToSunVec.y, + starToSunVec.x, + starToSunVec.y, starToSunVec.z ); // Star renderable globe, if we have a radius - std::string starGlobeRenderableString = ""; + std::string starGlobeRenderableString; const float starRadius = p.RSTAR; if (!isnan(starRadius)) { std::ifstream colorMap(absPath(BvColormapPath), std::ios::in); @@ -253,7 +256,7 @@ int addExoplanetSystem(lua_State* L) { ghoul::lua::luaError(L, "Failed to open colormap data file"); } - const std::string color = getStarColor(p.BMV, colorMap); + const std::string color = starColor(p.BMV, colorMap); const float radiusInMeter = starRadius * distanceconstants::SolarRadius; starGlobeRenderableString = "Renderable = {" @@ -327,14 +330,14 @@ int addExoplanetSystem(lua_State* L) { std::string sEpoch; if (!isnan(planet.TT)) { epoch.setTime("JD " + std::to_string(planet.TT)); - sEpoch = std::string(epoch.ISO8601()); + sEpoch = std::string(epoch.ISO8601()); } else { sEpoch = "2009-05-19T07:11:34.080"; } float planetRadius; - std::string enabled = ""; + std::string enabled; if (isnan(planet.R)) { if (isnan(planet.RSTAR)) { @@ -375,7 +378,7 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableGlobe'," "Enabled = " + enabled + "," - "Radii = " + std::to_string(planetRadius) + "," //R. in meters. + "Radii = " + std::to_string(planetRadius) + "," //R. in meters. "SegmentsPerPatch = 64," "PerformShading = false," "Layers = {}" @@ -419,13 +422,12 @@ int addExoplanetSystem(lua_State* L) { bool hasUpperAUncertainty = !isnan(planet.AUPPER); bool hasLowerAUncertainty = !isnan(planet.ALOWER); - if (hasUpperAUncertainty && hasLowerAUncertainty) - { + if (hasUpperAUncertainty && hasLowerAUncertainty) { // Get the orbit plane of the planet trail orbit from the KeplerTranslation const glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( - planet.I, - planet.BIGOM, - planet.OM + planet.I, + planet.BIGOM, + planet.OM ); const glm::dmat3 rotation = orbitPlaneRotationMatrix; diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 9eed430738..9c18d32c36 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -56,7 +56,8 @@ namespace { static const openspace::properties::Property::PropertyInfo EccentricityInfo = { "Eccentricity", "Eccentricity", - "This value determines the eccentricity, that is the deviation from a perfect sphere, for this orbit." + "This value determines the eccentricity, that is the deviation from a perfect " + "sphere, for this orbit." }; static const openspace::properties::Property::PropertyInfo OffsetInfo = { diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index f6380826d3..451c03ac50 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -35,10 +35,10 @@ #include namespace { - const char* KeyInputCsv = "InputCSV"; - const char* KeyInputSpeck = "InputSPECK"; - const char* KeyOutputBin = "OutputBIN"; - const char* KeyOutputLut = "OutputLUT"; + constexpr const char* KeyInputCsv = "InputCSV"; + constexpr const char* KeyInputSpeck = "InputSPECK"; + constexpr const char* KeyOutputBin = "OutputBIN"; + constexpr const char* KeyOutputLut = "OutputLUT"; constexpr const char* _loggerCat = "CsvToBinTask"; @@ -65,7 +65,7 @@ std::string ExoplanetsCsvToBinTask::description() { " and write as bin to " + _outputBinPath; } -glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { +glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) { glm::vec3 position; position[0] = NAN; position[1] = NAN; @@ -76,23 +76,26 @@ glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { } std::string line; - std::string d; - std::string n; - while (getline(exoplanetsFile, line)) - { - if (line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" || line.empty()) { + std::string data; // data + std::string name; + while (getline(exoplanetsFile, line)) { + bool shouldSkipLine = ( + line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" || + line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" + ); + + if (shouldSkipLine) { continue; } std::istringstream linestream(line); - getline(linestream, d, '#'); - getline(linestream, n); - n.erase(0, 1); + getline(linestream, data, '#'); + getline(linestream, name); + name.erase(0, 1); std::string coord; - if (n.compare(starName) == 0) - { - std::stringstream dataStream(d); + if (name == starName) { + std::stringstream dataStream(data); getline(dataStream, coord, ' '); position[0] = std::stof(coord.c_str(), nullptr); getline(dataStream, coord, ' '); @@ -109,7 +112,6 @@ glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) { _transformationMatrix * glm::dvec4(position, 1.0) ); - exoplanetsFile.close(); return transformedPosition; } @@ -124,7 +126,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::ofstream lutFile(_outputLutPath); int version = 1; - binFile.write((char *)&version, sizeof(int)); + binFile.write(reinterpret_cast(&version), sizeof(int)); Exoplanet p; @@ -590,7 +592,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // SPECURL getline(lineStream, data, ','); // STAR std::string speckStarname = speckStarName(data); - glm::vec3 position = getStarPosition(speckStarname); + glm::vec3 position = starPosition(speckStarname); p.POSITIONX = position[0]; p.POSITIONY = position[1]; p.POSITIONZ = position[2]; @@ -719,15 +721,11 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb long pos = binFile.tellp(); planetName = speckStarname + " " + component; lutFile << planetName << "," << pos << std::endl; - binFile.write((char *)&p, sizeof(Exoplanet)); + binFile.write(reinterpret_cast(&p), sizeof(Exoplanet)); } } - csvFile.close(); - binFile.close(); - lutFile.close(); - - progressCallback(1.0f); + progressCallback(1.f); } documentation::Documentation ExoplanetsCsvToBinTask::documentation() { diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 2e764eb6b1..857e4d2bc4 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -44,7 +44,7 @@ private: std::string _outputBinPath; std::string _outputLutPath; - glm::vec3 getStarPosition(std::string starName); + glm::vec3 starPosition(const std::string& starName); }; } // namespace openspace::exoplanets From 614c523c693556dc5d199483473c653bce89a559 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 10:11:32 +0200 Subject: [PATCH 102/123] Cleanup data reading in csvtobintask --- .../tasks/exoplanetscsvtobintask.cpp | 426 +++++++----------- .../exoplanets/tasks/exoplanetscsvtobintask.h | 3 + 2 files changed, 169 insertions(+), 260 deletions(-) diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 451c03ac50..8a41e1618e 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -65,56 +65,6 @@ std::string ExoplanetsCsvToBinTask::description() { " and write as bin to " + _outputBinPath; } -glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) { - glm::vec3 position; - position[0] = NAN; - position[1] = NAN; - position[2] = NAN; - std::ifstream exoplanetsFile(_inputSpeckPath); - if (!exoplanetsFile) { - LERROR(fmt::format("Error opening file expl.speck.")); - } - - std::string line; - std::string data; // data - std::string name; - while (getline(exoplanetsFile, line)) { - bool shouldSkipLine = ( - line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" || - line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" - ); - - if (shouldSkipLine) { - continue; - } - - std::istringstream linestream(line); - getline(linestream, data, '#'); - getline(linestream, name); - name.erase(0, 1); - - std::string coord; - if (name == starName) { - std::stringstream dataStream(data); - getline(dataStream, coord, ' '); - position[0] = std::stof(coord.c_str(), nullptr); - getline(dataStream, coord, ' '); - position[1] = std::stof(coord.c_str(), nullptr); - getline(dataStream, coord, ' '); - position[2] = std::stof(coord.c_str(), nullptr); - break; - } - } - - // Apply transformation matrix to pos - glm::dmat4 _transformationMatrix = glm::dmat4(1.0); - glm::vec3 transformedPosition = glm::vec3( - _transformationMatrix * glm::dvec4(position, 1.0) - ); - - return transformedPosition; -} - void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallback) { std::ifstream csvFile(_inputCsvPath); if (!csvFile.good()) { @@ -145,6 +95,18 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(csvFile, planetRow); // The first line, containing the data names LINFOC("CSVTOBIN", fmt::format("Loading {} stars", total)); + auto readFloatData = [](const std::string& data) -> float { + return !data.empty() ? std::stof(data.c_str(), nullptr) : NAN; + }; + + auto readDoubleData = [](const std::string& data) -> double { + return !data.empty() ? std::stod(data.c_str(), nullptr) : NAN; + }; + + auto readIntegerData = [](const std::string& data) -> int { + return !data.empty() ? std::stoi(data.c_str(), nullptr) : -1; + }; + int count = 0; std::string data; while (getline(csvFile, planetRow)) { @@ -154,25 +116,17 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::istringstream lineStream(planetRow); getline(lineStream, data, ','); // A - if (!data.empty()) - p.A = std::stof(data.c_str(), nullptr); - else - p.A = NAN; + p.A = readFloatData(data); + getline(lineStream, data, ','); // AUPPER - if (!data.empty()) - p.AUPPER = std::stod(data.c_str(), nullptr); - else - p.AUPPER = NAN; + p.AUPPER = readDoubleData(data); + getline(lineStream, data, ','); // ALOWER - if (!data.empty()) - p.ALOWER = std::stod(data.c_str(), nullptr); - else - p.ALOWER = NAN; + p.ALOWER = readDoubleData(data); + getline(lineStream, data, ','); // UA - if (!data.empty()) - p.UA = std::stod(data.c_str(), nullptr); - else - p.UA = NAN; + p.UA = readDoubleData(data); + getline(lineStream, data, ','); // AREF getline(lineStream, data, ','); // AURL getline(lineStream, data, ','); // AR @@ -189,42 +143,31 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // BREF getline(lineStream, data, ','); // BURL getline(lineStream, data, ','); // BIGOM - if (!data.empty()) - p.BIGOM = std::stof(data.c_str(), nullptr); - else - p.BIGOM = NAN; + p.BIGOM = readFloatData(data); + getline(lineStream, data, ','); // BIGOMUPPER - if (!data.empty()) - p.BIGOMUPPER = std::stof(data.c_str(), nullptr); - else - p.BIGOMUPPER = NAN; + p.BIGOMUPPER = readFloatData(data); + getline(lineStream, data, ','); // BIGOMLOWER - if (!data.empty()) - p.BIGOMLOWER = std::stof(data.c_str(), nullptr); - else - p.BIGOMLOWER = NAN; + p.BIGOMLOWER = readFloatData(data); + getline(lineStream, data, ','); // UBIGOM - if (!data.empty()) - p.UBIGOM = std::stof(data.c_str(), nullptr); - else - p.UBIGOM = NAN; + p.UBIGOM = readFloatData(data); + getline(lineStream, data, ','); // BIGOMREF getline(lineStream, data, ','); // BIGOMURL getline(lineStream, data, ','); // BINARY - if (!data.empty()) - p.BINARY = std::stoi(data.c_str(), nullptr); - else - p.BINARY = -1; + p.BINARY = static_cast(readIntegerData(data)); + getline(lineStream, data, ','); // BINARYREF getline(lineStream, data, ','); // BINARYURL getline(lineStream, data, ','); // BMV - if (!data.empty()) - p.BMV = std::stof(data.c_str(), nullptr); - else - p.BMV = NAN; + p.BMV = readFloatData(data); + getline(lineStream, data, ','); // CHI2 getline(lineStream, data, ','); // COMP component = data; + getline(lineStream, data, ','); // DATE getline(lineStream, data, ','); // DEC getline(lineStream, data, ','); // DEC_STRING @@ -261,29 +204,17 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // EANAME getline(lineStream, data, ','); // EAURL getline(lineStream, data, ','); // ECC - if (!data.empty()) - p.ECC = std::stof(data.c_str(), nullptr); - else - p.ECC = NAN; + p.ECC = readFloatData(data); getline(lineStream, data, ','); // ECCUPPER - if (!data.empty()) - p.ECCUPPER = std::stof(data.c_str(), nullptr); - else - p.ECCUPPER = NAN; + p.ECCLOWER = readFloatData(data); getline(lineStream, data, ','); // ECCLOWER - if (!data.empty()) - p.ECCLOWER = std::stof(data.c_str(), nullptr); - else - p.ECCLOWER = NAN; + p.ECCLOWER = readFloatData(data); getline(lineStream, data, ','); // UECC - if (!data.empty()) - p.UECC = std::stof(data.c_str(), nullptr); - else - p.UECC = NAN; - + p.UECC = readFloatData(data); + getline(lineStream, data, ','); // ECCREF getline(lineStream, data, ','); // ECCURL getline(lineStream, data, ','); // EOD @@ -316,28 +247,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // HIPP getline(lineStream, data, ','); // HR getline(lineStream, data, ','); // I - if (!data.empty()) - p.I = std::stof(data.c_str(), nullptr); - else - p.I = NAN; + p.I = readFloatData(data); getline(lineStream, data, ','); // IUPPER - if (!data.empty()) - p.IUPPER = std::stof(data.c_str(), nullptr); - else - p.IUPPER = NAN; + p.IUPPER = readFloatData(data); getline(lineStream, data, ','); // ILOWER - if (!data.empty()) - p.ILOWER = std::stof(data.c_str(), nullptr); - else - p.ILOWER = NAN; - + p.ILOWER = readFloatData(data); + getline(lineStream, data, ','); // UI - if (!data.empty()) - p.UI = std::stof(data.c_str(), nullptr); - else - p.UI = NAN; + p.UI = readFloatData(data); getline(lineStream, data, ','); // IREF getline(lineStream, data, ','); // IURL @@ -388,34 +307,20 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // MULT getline(lineStream, data, ','); // NAME getline(lineStream, data, ','); // NCOMP - if (!data.empty()) - p.NCOMP = std::stoi(data.c_str(), nullptr); - else - p.NCOMP = -1; + p.NCOMP = readIntegerData(data); + getline(lineStream, data, ','); // NOBS getline(lineStream, data, ','); // OM - if (!data.empty()) - p.OM = std::stof(data.c_str(), nullptr); - else - p.OM = NAN; + p.OM = readFloatData(data); getline(lineStream, data, ','); // OMUPPER - if (!data.empty()) - p.OMUPPER = std::stof(data.c_str(), nullptr); - else - p.OMUPPER = NAN; + p.OMUPPER = readFloatData(data); getline(lineStream, data, ','); // OMLOWER - if (!data.empty()) - p.OMLOWER = std::stof(data.c_str(), nullptr); - else - p.OMLOWER = NAN; + p.OMLOWER = readFloatData(data); getline(lineStream, data, ','); // UOM - if (!data.empty()) - p.UOM = std::stof(data.c_str(), nullptr); - else - p.UOM = NAN; + p.UOM = readFloatData(data); getline(lineStream, data, ','); // OMREF getline(lineStream, data, ','); // OMURL @@ -427,55 +332,31 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // PARLOWER getline(lineStream, data, ','); // UPAR getline(lineStream, data, ','); // PER - if (!data.empty()) - p.PER = std::stod(data.c_str(), nullptr); - else - p.PER = NAN; + p.PER = readDoubleData(data); getline(lineStream, data, ','); // PERUPPER - if (!data.empty()) - p.PERUPPER = std::stof(data.c_str(), nullptr); - else - p.PERUPPER = NAN; + p.PERUPPER = readFloatData(data); getline(lineStream, data, ','); // PERLOWER - if (!data.empty()) - p.PERLOWER = std::stof(data.c_str(), nullptr); - else - p.PERLOWER = NAN; + p.PERLOWER = readFloatData(data); getline(lineStream, data, ','); // UPER - if (!data.empty()) - p.UPER = std::stof(data.c_str(), nullptr); - else - p.UPER = NAN; + p.UPER = readFloatData(data); getline(lineStream, data, ','); // PERREF getline(lineStream, data, ','); // PERURL getline(lineStream, data, ','); // PLANETDISCMETH getline(lineStream, data, ','); // R - if (!data.empty()) - p.R = std::stod(data.c_str(), nullptr); - else - p.R = NAN; + p.R = readDoubleData(data); getline(lineStream, data, ','); // RUPPER - if (!data.empty()) - p.RUPPER = std::stod(data.c_str(), nullptr); - else - p.RUPPER = NAN; + p.RUPPER = readDoubleData(data); getline(lineStream, data, ','); // RLOWER - if (!data.empty()) - p.RLOWER = std::stod(data.c_str(), nullptr); - else - p.RLOWER = NAN; + p.RLOWER = readDoubleData(data); getline(lineStream, data, ','); //UR - if (!data.empty()) - p.UR = std::stod(data.c_str(), nullptr); - else - p.UR = NAN; + p.UR = readDoubleData(data); getline(lineStream, data, ','); // RREF getline(lineStream, data, ','); // RURL @@ -496,28 +377,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // RRREF getline(lineStream, data, ','); // RRURL getline(lineStream, data, ','); // RSTAR - if (!data.empty()) - p.RSTAR = std::stof(data.c_str(), nullptr); - else - p.RSTAR = NAN; + p.RSTAR = readFloatData(data); getline(lineStream, data, ','); // RSTARUPPER - if (!data.empty()) - p.RSTARUPPER = std::stof(data.c_str(), nullptr); - else - p.RSTARUPPER = NAN; + p.RSTARUPPER = readFloatData(data); getline(lineStream, data, ','); // RSTARLOWER - if (!data.empty()) - p.RSTARLOWER = std::stof(data.c_str(), nullptr); - else - p.RSTARLOWER = NAN; + p.RSTARLOWER = readFloatData(data); getline(lineStream, data, ','); // URSTAR - if (!data.empty()) - p.URSTAR = std::stof(data.c_str(), nullptr); - else - p.URSTAR = NAN; + p.URSTAR = readFloatData(data); getline(lineStream, data, ','); // RSTARREF getline(lineStream, data, ','); // RSTARURL @@ -611,11 +480,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // T14REF getline(lineStream, data, ','); // T14URL getline(lineStream, data, ','); // TEFF - float teff; - if (!data.empty()) - teff = std::stof(data.c_str(), nullptr); - else - teff = NAN; + float teff = readFloatData(data); getline(lineStream, data, ','); // TEFFUPPER getline(lineStream, data, ','); // TEFFLOWER @@ -628,28 +493,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // TRANSITURL getline(lineStream, data, ','); // TREND getline(lineStream, data, ','); // TT - if (!data.empty()) - p.TT = std::stod(data.c_str(), nullptr); - else - p.TT = NAN; + p.TT = readDoubleData(data); getline(lineStream, data, ','); // TTUPPER - if (!data.empty()) - p.TTUPPER = std::stof(data.c_str(), nullptr); - else - p.TTUPPER = NAN; + p.TTUPPER = readFloatData(data); getline(lineStream, data, ','); // TTLOWER - if (!data.empty()) - p.TTLOWER = std::stof(data.c_str(), nullptr); - else - p.TTLOWER = NAN; + p.TTLOWER = readFloatData(data); getline(lineStream, data, ','); // UTT - if (!data.empty()) - p.UTT = std::stof(data.c_str(), nullptr); - else - p.UTT = NAN; + p.UTT = readFloatData(data); getline(lineStream, data, ','); // TTREF getline(lineStream, data, ','); // TTURL @@ -663,61 +516,18 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // VSINIREF getline(lineStream, data, ','); // VSINIURL getline(lineStream, data, ','); // KEPID - if (!data.empty()) + if (!data.empty()) { isKeplerObject = true; + } getline(lineStream, data); // KDE if (!isKeplerObject) { // calculate B-V from Teff if not exsisting if (std::isnan(p.BMV)) { - if (!std::isnan(teff)) { - std::ifstream teffToBvFile(absPath(TeffBvPath)); - - if (!teffToBvFile.good()) { - LERROR(fmt::format("Failed to open teff_bv.txt file")); - return; - } - - float BV = 0.f; - float bvUpper = 0.f; - float bvLower = 0.f; - float teffLower, teffUpper; - std::string row, teffString, bvString; - while (getline(teffToBvFile, row)) { - std::istringstream lineStream(row); - getline(lineStream, teffString, ','); - getline(lineStream, bvString); - - float teffCurrent = std::stof(teffString.c_str(), nullptr); - float bvCurrent = std::stof(bvString.c_str(), nullptr); - - if (teff > teffCurrent) { - teffLower = teffCurrent; - bvLower = bvCurrent; - } - else { - teffUpper = teffCurrent; - bvUpper = bvCurrent; - if (bvLower == 0.f) { - BV = 2.f; - } - else { - float bvDiff = (bvUpper - bvLower); - float teffDiff = (teffUpper - teffLower); - BV = ((bvDiff * (teff - teffLower)) / teffDiff) + bvLower; - } - break; - } - } - teffToBvFile.close(); - p.BMV = BV; - } - else { - p.BMV = NAN; - } + p.BMV = bvFromTeff(teff); } - // crate look-up table + // create look-up table long pos = binFile.tellp(); planetName = speckStarname + " " + component; lutFile << planetName << "," << pos << std::endl; @@ -728,6 +538,102 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb progressCallback(1.f); } +glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) { + glm::vec3 position; + position[0] = NAN; + position[1] = NAN; + position[2] = NAN; + std::ifstream exoplanetsFile(_inputSpeckPath); + if (!exoplanetsFile) { + LERROR(fmt::format("Error opening file expl.speck.")); + } + + std::string line; + std::string data; // data + std::string name; + while (getline(exoplanetsFile, line)) { + bool shouldSkipLine = ( + line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" || + line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" + ); + + if (shouldSkipLine) { + continue; + } + + std::istringstream linestream(line); + getline(linestream, data, '#'); + getline(linestream, name); + name.erase(0, 1); + + std::string coord; + if (name == starName) { + std::stringstream dataStream(data); + getline(dataStream, coord, ' '); + position[0] = std::stof(coord.c_str(), nullptr); + getline(dataStream, coord, ' '); + position[1] = std::stof(coord.c_str(), nullptr); + getline(dataStream, coord, ' '); + position[2] = std::stof(coord.c_str(), nullptr); + break; + } + } + + // Apply transformation matrix to pos + glm::dmat4 _transformationMatrix = glm::dmat4(1.0); + glm::vec3 transformedPosition = glm::vec3( + _transformationMatrix * glm::dvec4(position, 1.0) + ); + + return transformedPosition; +} + +float ExoplanetsCsvToBinTask::bvFromTeff(const float teff) { + if (std::isnan(teff)) { + return NAN; + } + + std::ifstream teffToBvFile(absPath(TeffBvPath)); + + if (!teffToBvFile.good()) { + LERROR(fmt::format("Failed to open teff_bv.txt file")); + return NAN; + } + + float BV = 0.f; + float bvUpper = 0.f; + float bvLower = 0.f; + float teffLower, teffUpper; + std::string row, teffString, bvString; + while (getline(teffToBvFile, row)) { + std::istringstream lineStream(row); + getline(lineStream, teffString, ','); + getline(lineStream, bvString); + + float teffCurrent = std::stof(teffString.c_str(), nullptr); + float bvCurrent = std::stof(bvString.c_str(), nullptr); + + if (teff > teffCurrent) { + teffLower = teffCurrent; + bvLower = bvCurrent; + } + else { + teffUpper = teffCurrent; + bvUpper = bvCurrent; + if (bvLower == 0.f) { + BV = 2.f; + } + else { + float bvDiff = (bvUpper - bvLower); + float teffDiff = (teffUpper - teffLower); + BV = ((bvDiff * (teff - teffLower)) / teffDiff) + bvLower; + } + break; + } + } + return BV; +} + documentation::Documentation ExoplanetsCsvToBinTask::documentation() { using namespace documentation; return { diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 857e4d2bc4..f76a77ddb1 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -45,6 +45,9 @@ private: std::string _outputLutPath; glm::vec3 starPosition(const std::string& starName); + + // Compute b-v color from teff value using a convertion file + float bvFromTeff(const float teff); }; } // namespace openspace::exoplanets From fe4bb00108eecf2f3a89543f6601e4a15fd9fbd2 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 10:23:47 +0200 Subject: [PATCH 103/123] Even more cleanup --- modules/exoplanets/rendering/renderableorbitdisc.cpp | 9 +-------- modules/exoplanets/rendering/renderableorbitdisc.h | 12 ++++++------ modules/exoplanets/shaders/orbitdisc_fs.glsl | 12 ------------ modules/exoplanets/shaders/orbitdisc_vs.glsl | 2 +- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 9c18d32c36..590dbe74c8 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -115,13 +115,6 @@ RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary) , _size(SizeInfo, 1.f, 0.f, 3.0e12f) , _eccentricity(EccentricityInfo, 0.f, 0.f, 1.f) , _offset(OffsetInfo, glm::vec2(0.f, 1.f), glm::vec2(0.f), glm::vec2(1.f)) - , _shader(nullptr) - , _texture(nullptr) - , _textureFile(nullptr) - , _textureIsDirty(false) - , _quad(0) - , _vertexPositionBuffer(0) - , _planeIsDirty(false) { using ghoul::filesystem::File; @@ -145,7 +138,7 @@ RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary) _texturePath = absPath(dictionary.value(TextureInfo.identifier)); _textureFile = std::make_unique(_texturePath); - _texturePath.onChange([&]() { loadTexture(); }); + _texturePath.onChange([&]() { _textureIsDirty = true; }); addProperty(_texturePath); _textureFile->setCallback([&](const File&) { _textureIsDirty = true; }); diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index 7d68d33d81..3cae6e64c4 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -65,16 +65,16 @@ private: properties::FloatProperty _eccentricity; properties::Vec2Property _offset; - std::unique_ptr _shader; + std::unique_ptr _shader = nullptr; UniformCache(modelViewProjection, textureOffset, opacity, texture, eccentricity, semiMajorAxis) _uniformCache; - std::unique_ptr _texture; + std::unique_ptr _texture = nullptr; std::unique_ptr _textureFile; - bool _textureIsDirty; - bool _planeIsDirty; - GLuint _quad; - GLuint _vertexPositionBuffer; + bool _textureIsDirty = false; + bool _planeIsDirty = false; + GLuint _quad = 0; + GLuint _vertexPositionBuffer = 0; }; } // namespace openspace diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 2bba81566e..758aa7a569 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -107,18 +107,6 @@ Fragment getFragment() { vec4 diffuse = texture(discTexture, textureCoord); diffuse.a *= opacity; - // The normal for the one plane depends on whether we are dealing - // with a front facing or back facing fragment - vec3 normal; - // The plane is oriented on the xz plane - // WARNING: This might not be the case for Uranus - if (gl_FrontFacing) { - normal = vec3(-1.0, 0.0, 0.0); - } - else { - normal = vec3(1.0, 0.0, 0.0); - } - Fragment frag; frag.color = diffuse; frag.depth = vs_position.w; diff --git a/modules/exoplanets/shaders/orbitdisc_vs.glsl b/modules/exoplanets/shaders/orbitdisc_vs.glsl index 65ff4bdabe..e998350ce7 100644 --- a/modules/exoplanets/shaders/orbitdisc_vs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_vs.glsl @@ -37,7 +37,7 @@ uniform mat4 modelViewProjectionTransform; void main() { vs_st = in_st; vs_position = z_normalization( - modelViewProjectionTransform * vec4(in_position.xy, 0.0, 1.0) + modelViewProjectionTransform * vec4(in_position, 0.0, 1.0) ); gl_Position = vs_position; From 32c2e59330fece5ea2f96999afe0616eeebb2205 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 11:10:15 +0200 Subject: [PATCH 104/123] Change uppercase struct variables to camelcase --- modules/exoplanets/exoplanetshelper.h | 84 +++++++++--------- modules/exoplanets/exoplanetsmodule_lua.inl | 72 +++++++-------- .../tasks/exoplanetscsvtobintask.cpp | 88 +++++++++---------- 3 files changed, 122 insertions(+), 122 deletions(-) diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h index 1490cb9a0f..9b0f9d46c3 100644 --- a/modules/exoplanets/exoplanetshelper.h +++ b/modules/exoplanets/exoplanetshelper.h @@ -30,48 +30,48 @@ namespace openspace::exoplanets { struct Exoplanet { - float A; // Orbital semi-major axis in AU - double AUPPER; // Upper uncertainty of orbital semi-major axis - double ALOWER; // Lower uncertainty of orbital semi-major axis - double UA; // Uncertainty of orbital semi-major axis - float BIGOM; // Longitude of ascending node in degrees - float BIGOMUPPER; // Upper uncertainty of longitude of ascending node - float BIGOMLOWER; // Lower uncertainty of longitude of ascending node - float UBIGOM; // Uncertainty of longitude of ascending node - bool BINARY; // Star known to be binary? - float BMV; // B − V color - float ECC; // Orbital eccentricity - float ECCUPPER; // Upper uncertainty of orbital eccentricity - float ECCLOWER; // Lower uncertainty of orbital eccentricity - float UECC; // Uncertainty of orbital eccentricity - float I; // Orbital inclination in degrees (for transiting systems only) - float IUPPER; // Upper uncertainty of orbital inclination - float ILOWER; // Lower uncertainty of orbital inclination - float UI; // Uncertainty of orbital inclination - int NCOMP; // Number of planetary companions known - float OM; // Argument of periastron in degrees - float OMUPPER; // Upper uncertainty of argument of periastron - float OMLOWER; // Lower uncertainty of argument of periastron - float UOM; // Uncertainty of argument of periastron - double PER; // Orbital period in days - float PERUPPER; // Upper uncertainty of period - float PERLOWER; // Lower uncertainty of period - float UPER; // Uncertainty of period - double R; // Radius of the planet in Jupiter radii - double RUPPER; // Upper uncertainty of radius of the planet - double RLOWER; // Lower uncertainty of radius of the planet - double UR; // Uncertainty of radius of the planet - float RSTAR; // Estimated radius of the star in solar radii - float RSTARUPPER; // Upper uncertainty of estimated star radius - float RSTARLOWER; // Lower uncertainty of estimated star radius - float URSTAR; // Uncertainty of estimated star radius - double TT; // Epoch of transit center in HJD-2440000 - float TTUPPER; // Upper uncertainty of epoch of transit center - float TTLOWER; // Lower uncertainty of epoch of transit center - float UTT; // Uncertainty of epoch of transit center - float POSITIONX; // Star position's X-coordinate in parsec - float POSITIONY; // Star position's Y-coordinate in parsec - float POSITIONZ; // Star position's Z-coordinate in parsec + float a; // Orbital semi-major axis in AU + double aUpper; // Upper uncertainty of orbital semi-major axis + double aLower; // Lower uncertainty of orbital semi-major axis + double ua; // Uncertainty of orbital semi-major axis + float bigOm; // Longitude of ascending node in degrees + float bigOmUpper; // Upper uncertainty of longitude of ascending node + float bigOmLower; // Lower uncertainty of longitude of ascending node + float uBigOm; // Uncertainty of longitude of ascending node + bool binary; // Star known to be binary? + float bmv; // B − V color + float ecc; // Orbital eccentricity + float eccUpper; // Upper uncertainty of orbital eccentricity + float eccLower; // Lower uncertainty of orbital eccentricity + float uEcc; // Uncertainty of orbital eccentricity + float i; // Orbital inclination in degrees (for transiting systems only) + float iUpper; // Upper uncertainty of orbital inclination + float iLower; // Lower uncertainty of orbital inclination + float ui; // Uncertainty of orbital inclination + int nComp; // Number of planetary companions known + float om; // Argument of periastron in degrees + float omUpper; // Upper uncertainty of argument of periastron + float omLower; // Lower uncertainty of argument of periastron + float uOm; // Uncertainty of argument of periastron + double per; // Orbital period in days + float perUpper; // Upper uncertainty of period + float perLower; // Lower uncertainty of period + float uPer; // Uncertainty of period + double r; // Radius of the planet in Jupiter radii + double rUpper; // Upper uncertainty of radius of the planet + double rLower; // Lower uncertainty of radius of the planet + double ur; // Uncertainty of radius of the planet + float rStar; // Estimated radius of the star in solar radii + float rStarUpper; // Upper uncertainty of estimated star radius + float rStarLower; // Lower uncertainty of estimated star radius + float urStar; // Uncertainty of estimated star radius + double tt; // Epoch of transit center in HJD-2440000 + float ttUpper; // Upper uncertainty of epoch of transit center + float ttLower; // Lower uncertainty of epoch of transit center + float uTt; // Uncertainty of epoch of transit center + float positionX; // Star position's X-coordinate in parsec + float positionY; // Star position's Y-coordinate in parsec + float positionZ; // Star position's Z-coordinate in parsec }; // Convert csv-file specific names to the corresponding name in the speck data file diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 9c9b33fc33..b40b0dce82 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -199,7 +199,7 @@ int addExoplanetSystem(lua_State* L) { data.close(); lut.close(); - bool notEnoughData = isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER); + bool notEnoughData = isnan(p.positionX) || isnan(p.a) || isnan(p.per); if (!found || notEnoughData) { return ghoul::lua::luaError( @@ -209,9 +209,9 @@ int addExoplanetSystem(lua_State* L) { } const glm::dvec3 starPosition = glm::dvec3( - p.POSITIONX * distanceconstants::Parsec, - p.POSITIONY * distanceconstants::Parsec, - p.POSITIONZ * distanceconstants::Parsec + p.positionX * distanceconstants::Parsec, + p.positionY * distanceconstants::Parsec, + p.positionZ * distanceconstants::Parsec ); const glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); @@ -248,7 +248,7 @@ int addExoplanetSystem(lua_State* L) { // Star renderable globe, if we have a radius std::string starGlobeRenderableString; - const float starRadius = p.RSTAR; + const float starRadius = p.rStar; if (!isnan(starRadius)) { std::ifstream colorMap(absPath(BvColormapPath), std::ios::in); @@ -256,7 +256,7 @@ int addExoplanetSystem(lua_State* L) { ghoul::lua::luaError(L, "Failed to open colormap data file"); } - const std::string color = starColor(p.BMV, colorMap); + const std::string color = starColor(p.bmv, colorMap); const float radiusInMeter = starRadius * distanceconstants::SolarRadius; starGlobeRenderableString = "Renderable = {" @@ -314,22 +314,22 @@ int addExoplanetSystem(lua_State* L) { Exoplanet planet = planetSystem[i]; const std::string planetName = planetNames[i]; - if (isnan(planet.ECC)) { - planet.ECC = 0.f; + if (isnan(planet.ecc)) { + planet.ecc = 0.f; } - if (isnan(planet.I)) { - planet.I = 90.f; + if (isnan(planet.i)) { + planet.i = 90.f; } - if (isnan(planet.BIGOM)) { - planet.BIGOM = 180.f; + if (isnan(planet.bigOm)) { + planet.bigOm = 180.f; } - if (isnan(planet.OM)) { - planet.OM = 90.f; + if (isnan(planet.om)) { + planet.om = 90.f; } Time epoch; std::string sEpoch; - if (!isnan(planet.TT)) { - epoch.setTime("JD " + std::to_string(planet.TT)); + if (!isnan(planet.tt)) { + epoch.setTime("JD " + std::to_string(planet.tt)); sEpoch = std::string(epoch.ISO8601()); } else { @@ -339,33 +339,33 @@ int addExoplanetSystem(lua_State* L) { float planetRadius; std::string enabled; - if (isnan(planet.R)) { - if (isnan(planet.RSTAR)) { - planetRadius = planet.A * 0.001f * distanceconstants::AstronomicalUnit; + if (isnan(planet.r)) { + if (isnan(planet.rStar)) { + planetRadius = planet.a * 0.001f * distanceconstants::AstronomicalUnit; } else { - planetRadius = planet.RSTAR * 0.1f * distanceconstants::SolarRadius; + planetRadius = planet.rStar * 0.1f * distanceconstants::SolarRadius; } enabled = "false"; } else { - planetRadius = planet.R * distanceconstants::JupiterRadius; + planetRadius = planet.r * distanceconstants::JupiterRadius; enabled = "true"; } - const float period = planet.PER * static_cast(SecondsPerDay); - const float semiMajorAxisInMeter = planet.A * distanceconstants::AstronomicalUnit; + const float period = planet.per * static_cast(SecondsPerDay); + const float semiMajorAxisInMeter = planet.a * distanceconstants::AstronomicalUnit; const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; const std::string planetIdentifier = createIdentifier(planetName); const std::string planetKeplerTranslation = "{" "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(planet.ECC) + "," //ECC + "Eccentricity = " + std::to_string(planet.ecc) + "," //ECC "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," - "Inclination = " + std::to_string(planet.I) + "," //I - "AscendingNode = " + std::to_string(planet.BIGOM) + "," //BIGOM - "ArgumentOfPeriapsis = " + std::to_string(planet.OM) + "," //OM + "Inclination = " + std::to_string(planet.i) + "," //I + "AscendingNode = " + std::to_string(planet.bigOm) + "," //BIGOM + "ArgumentOfPeriapsis = " + std::to_string(planet.om) + "," //OM "MeanAnomaly = 0.0," "Epoch = '" + sEpoch + "'," //TT. JD to YYYY MM DD hh:mm:ss "Period = " + std::to_string(period) + "" @@ -403,7 +403,7 @@ int addExoplanetSystem(lua_State* L) { "Enabled = true," "Renderable = {" "Type = 'RenderableTrailOrbit'," - "Period = " + std::to_string(planet.PER) + "," + "Period = " + std::to_string(planet.per) + "," "Resolution = 1000," "Translation = " + planetKeplerTranslation + "," "Color = { 1, 1, 1 }" @@ -419,15 +419,15 @@ int addExoplanetSystem(lua_State* L) { openspace::scripting::ScriptEngine::RemoteScripting::Yes ); - bool hasUpperAUncertainty = !isnan(planet.AUPPER); - bool hasLowerAUncertainty = !isnan(planet.ALOWER); + bool hasUpperAUncertainty = !isnan(planet.aUpper); + bool hasLowerAUncertainty = !isnan(planet.aLower); if (hasUpperAUncertainty && hasLowerAUncertainty) { // Get the orbit plane of the planet trail orbit from the KeplerTranslation const glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix( - planet.I, - planet.BIGOM, - planet.OM + planet.i, + planet.bigOm, + planet.om ); const glm::dmat3 rotation = orbitPlaneRotationMatrix; @@ -439,10 +439,10 @@ int addExoplanetSystem(lua_State* L) { "Type = 'RenderableOrbitDisc'," "Texture = openspace.absPath('" + DiscTextureFile + "')," "Size = " + std::to_string(semiMajorAxisInMeter) + "," - "Eccentricity = " + std::to_string(planet.ECC) + "," + "Eccentricity = " + std::to_string(planet.ecc) + "," "Offset = { " + - std::to_string(planet.ALOWER) + ", " + - std::to_string(planet.AUPPER) + + std::to_string(planet.aLower) + ", " + + std::to_string(planet.aUpper) + "}," //min / max extend "Opacity = 0.3" "}," diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 8a41e1618e..ac40189723 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -116,16 +116,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb std::istringstream lineStream(planetRow); getline(lineStream, data, ','); // A - p.A = readFloatData(data); + p.a = readFloatData(data); getline(lineStream, data, ','); // AUPPER - p.AUPPER = readDoubleData(data); + p.aUpper = readDoubleData(data); getline(lineStream, data, ','); // ALOWER - p.ALOWER = readDoubleData(data); + p.aLower = readDoubleData(data); getline(lineStream, data, ','); // UA - p.UA = readDoubleData(data); + p.ua = readDoubleData(data); getline(lineStream, data, ','); // AREF getline(lineStream, data, ','); // AURL @@ -143,26 +143,26 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // BREF getline(lineStream, data, ','); // BURL getline(lineStream, data, ','); // BIGOM - p.BIGOM = readFloatData(data); + p.bigOm = readFloatData(data); getline(lineStream, data, ','); // BIGOMUPPER - p.BIGOMUPPER = readFloatData(data); + p.bigOmUpper = readFloatData(data); getline(lineStream, data, ','); // BIGOMLOWER - p.BIGOMLOWER = readFloatData(data); + p.bigOmLower = readFloatData(data); getline(lineStream, data, ','); // UBIGOM - p.UBIGOM = readFloatData(data); + p.uBigOm = readFloatData(data); getline(lineStream, data, ','); // BIGOMREF getline(lineStream, data, ','); // BIGOMURL getline(lineStream, data, ','); // BINARY - p.BINARY = static_cast(readIntegerData(data)); + p.binary = static_cast(readIntegerData(data)); getline(lineStream, data, ','); // BINARYREF getline(lineStream, data, ','); // BINARYURL getline(lineStream, data, ','); // BMV - p.BMV = readFloatData(data); + p.bmv = readFloatData(data); getline(lineStream, data, ','); // CHI2 getline(lineStream, data, ','); // COMP @@ -204,16 +204,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // EANAME getline(lineStream, data, ','); // EAURL getline(lineStream, data, ','); // ECC - p.ECC = readFloatData(data); + p.ecc = readFloatData(data); getline(lineStream, data, ','); // ECCUPPER - p.ECCLOWER = readFloatData(data); + p.eccUpper = readFloatData(data); getline(lineStream, data, ','); // ECCLOWER - p.ECCLOWER = readFloatData(data); + p.eccLower = readFloatData(data); getline(lineStream, data, ','); // UECC - p.UECC = readFloatData(data); + p.uEcc = readFloatData(data); getline(lineStream, data, ','); // ECCREF getline(lineStream, data, ','); // ECCURL @@ -247,16 +247,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // HIPP getline(lineStream, data, ','); // HR getline(lineStream, data, ','); // I - p.I = readFloatData(data); + p.i = readFloatData(data); getline(lineStream, data, ','); // IUPPER - p.IUPPER = readFloatData(data); + p.iUpper = readFloatData(data); getline(lineStream, data, ','); // ILOWER - p.ILOWER = readFloatData(data); + p.iLower = readFloatData(data); getline(lineStream, data, ','); // UI - p.UI = readFloatData(data); + p.ui = readFloatData(data); getline(lineStream, data, ','); // IREF getline(lineStream, data, ','); // IURL @@ -307,20 +307,20 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // MULT getline(lineStream, data, ','); // NAME getline(lineStream, data, ','); // NCOMP - p.NCOMP = readIntegerData(data); + p.nComp = readIntegerData(data); getline(lineStream, data, ','); // NOBS getline(lineStream, data, ','); // OM - p.OM = readFloatData(data); + p.om = readFloatData(data); getline(lineStream, data, ','); // OMUPPER - p.OMUPPER = readFloatData(data); + p.omUpper = readFloatData(data); getline(lineStream, data, ','); // OMLOWER - p.OMLOWER = readFloatData(data); + p.omLower = readFloatData(data); getline(lineStream, data, ','); // UOM - p.UOM = readFloatData(data); + p.uOm = readFloatData(data); getline(lineStream, data, ','); // OMREF getline(lineStream, data, ','); // OMURL @@ -332,31 +332,31 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // PARLOWER getline(lineStream, data, ','); // UPAR getline(lineStream, data, ','); // PER - p.PER = readDoubleData(data); + p.per = readDoubleData(data); getline(lineStream, data, ','); // PERUPPER - p.PERUPPER = readFloatData(data); + p.perUpper = readFloatData(data); getline(lineStream, data, ','); // PERLOWER - p.PERLOWER = readFloatData(data); + p.perLower = readFloatData(data); getline(lineStream, data, ','); // UPER - p.UPER = readFloatData(data); + p.uPer = readFloatData(data); getline(lineStream, data, ','); // PERREF getline(lineStream, data, ','); // PERURL getline(lineStream, data, ','); // PLANETDISCMETH getline(lineStream, data, ','); // R - p.R = readDoubleData(data); + p.r = readDoubleData(data); getline(lineStream, data, ','); // RUPPER - p.RUPPER = readDoubleData(data); + p.rUpper = readDoubleData(data); getline(lineStream, data, ','); // RLOWER - p.RLOWER = readDoubleData(data); + p.rLower = readDoubleData(data); getline(lineStream, data, ','); //UR - p.UR = readDoubleData(data); + p.ur = readDoubleData(data); getline(lineStream, data, ','); // RREF getline(lineStream, data, ','); // RURL @@ -377,16 +377,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // RRREF getline(lineStream, data, ','); // RRURL getline(lineStream, data, ','); // RSTAR - p.RSTAR = readFloatData(data); + p.rStar = readFloatData(data); getline(lineStream, data, ','); // RSTARUPPER - p.RSTARUPPER = readFloatData(data); + p.rStarUpper = readFloatData(data); getline(lineStream, data, ','); // RSTARLOWER - p.RSTARLOWER = readFloatData(data); + p.rStarLower = readFloatData(data); getline(lineStream, data, ','); // URSTAR - p.URSTAR = readFloatData(data); + p.urStar = readFloatData(data); getline(lineStream, data, ','); // RSTARREF getline(lineStream, data, ','); // RSTARURL @@ -462,9 +462,9 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // STAR std::string speckStarname = speckStarName(data); glm::vec3 position = starPosition(speckStarname); - p.POSITIONX = position[0]; - p.POSITIONY = position[1]; - p.POSITIONZ = position[2]; + p.positionX = position[0]; + p.positionY = position[1]; + p.positionZ = position[2]; getline(lineStream, data, ','); // STARDISCMETH getline(lineStream, data, ','); // T0 @@ -493,16 +493,16 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // TRANSITURL getline(lineStream, data, ','); // TREND getline(lineStream, data, ','); // TT - p.TT = readDoubleData(data); + p.tt = readDoubleData(data); getline(lineStream, data, ','); // TTUPPER - p.TTUPPER = readFloatData(data); + p.ttUpper = readFloatData(data); getline(lineStream, data, ','); // TTLOWER - p.TTLOWER = readFloatData(data); + p.ttLower = readFloatData(data); getline(lineStream, data, ','); // UTT - p.UTT = readFloatData(data); + p.uTt = readFloatData(data); getline(lineStream, data, ','); // TTREF getline(lineStream, data, ','); // TTURL @@ -523,8 +523,8 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb if (!isKeplerObject) { // calculate B-V from Teff if not exsisting - if (std::isnan(p.BMV)) { - p.BMV = bvFromTeff(teff); + if (std::isnan(p.bmv)) { + p.bmv = bvFromTeff(teff); } // create look-up table From 938fc49f826ed16b523467948af4f775a2bae965 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 11:14:07 +0200 Subject: [PATCH 105/123] Fix spelling mistake --- modules/exoplanets/tasks/exoplanetscsvtobintask.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index f76a77ddb1..38b91b19bd 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -46,7 +46,7 @@ private: glm::vec3 starPosition(const std::string& starName); - // Compute b-v color from teff value using a convertion file + // Compute b-v color from teff value using a conversion file float bvFromTeff(const float teff); }; From 1a5c0d3672e6acea711e6510b424431678b0852e Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 18 Sep 2020 14:34:06 +0200 Subject: [PATCH 106/123] More cleanup string_view and avoid warnings from implicit conversions --- modules/exoplanets/exoplanetshelper.cpp | 6 ++- modules/exoplanets/exoplanetshelper.h | 4 +- modules/exoplanets/exoplanetsmodule_lua.inl | 41 +++++++++++-------- .../tasks/exoplanetscsvtobintask.cpp | 4 +- 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index 1e685ce052..62adafc80d 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -24,9 +24,11 @@ #include +#include + namespace openspace::exoplanets { -std::string speckStarName(std::string csvName) { +std::string_view speckStarName(std::string_view csvName) { if (csvName == "HD 1237") { return "GJ 3021"; } if (csvName == "MOA-2009-BLG-387L") { return "MOA 2009-BLG-387L"; } if (csvName == "HD 126614 A") { return "HD 126614"; } @@ -74,7 +76,7 @@ std::string speckStarName(std::string csvName) { return csvName; } -std::string csvStarName(std::string name) { +std::string_view csvStarName(std::string_view name) { if (name == "GJ 3021") { return "HD 1237"; } if (name == "MOA 2009-BLG-387L") { return "MOA-2009-BLG-387L"; } if (name == "HD 126614") { return "HD 126614 A"; } diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h index 9b0f9d46c3..948e802c41 100644 --- a/modules/exoplanets/exoplanetshelper.h +++ b/modules/exoplanets/exoplanetshelper.h @@ -75,10 +75,10 @@ struct Exoplanet { }; // Convert csv-file specific names to the corresponding name in the speck data file -std::string speckStarName(std::string name); +std::string_view speckStarName(std::string_view name); // Convert speck-file specific names to the corresponding name in the csv data file -std::string csvStarName(std::string name); +std::string_view csvStarName(std::string_view name); } // namespace openspace::exoplanets diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index b40b0dce82..f4042aef18 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -56,7 +56,7 @@ constexpr const char* DiscTextureFile = constexpr const char* BvColormapPath = "${SYNC}/http/stars_colormap/2/colorbv.cmap"; std::string starColor(float bv, std::ifstream& colormap) { - const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255); + const int t = static_cast(round(((bv + 0.4) / (2.0 + 0.4)) * 255)); std::string color; for (int i = 0; i < t + 12; i++) { getline(colormap, color); @@ -97,25 +97,25 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) { glm::dmat3 exoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { glm::quat rotationQuat; glm::dvec3 rotationAxis; - const float cosTheta = dot(start, end); + const float cosTheta = static_cast(glm::dot(start, end)); constexpr float Epsilon = 1E-3f; if (cosTheta < -1.f + Epsilon) { // special case when vectors in opposite directions: // there is no "ideal" rotation axis // So guess one; any will do as long as it's perpendicular to start vector - rotationAxis = cross(glm::dvec3(0.0, 0.0, 1.0), start); + rotationAxis = glm::cross(glm::dvec3(0.0, 0.0, 1.0), start); if (length2(rotationAxis) < 0.01f) { // bad luck, they were parallel, try again! - rotationAxis = cross(glm::dvec3(1.0, 0.0, 0.0), start); + rotationAxis = glm::cross(glm::dvec3(1.0, 0.0, 0.0), start); } - rotationAxis = normalize(rotationAxis); + rotationAxis = glm::normalize(rotationAxis); rotationQuat = glm::quat(glm::radians(180.f), rotationAxis); return glm::dmat3(toMat4(rotationQuat)); } - rotationAxis = cross(start, end); + rotationAxis = glm::cross(start, end); const float s = sqrt((1.f + cosTheta) * 2.f); const float invs = 1.f / s; @@ -127,7 +127,7 @@ glm::dmat3 exoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) { rotationAxis.z * invs ); - return glm::dmat3(toMat4(rotationQuat)); + return glm::dmat3(glm::toMat4(rotationQuat)); } // Create an identifier without whitespaces @@ -141,7 +141,7 @@ int addExoplanetSystem(lua_State* L) { const std::string starName = luaL_checkstring(L, StringLocation); // If user have given name as in EOD, change it to speck-name - const std::string starNameSpeck = speckStarName(starName); + const std::string starNameSpeck = std::string(speckStarName(starName)); const std::string starIdentifier = createIdentifier(starNameSpeck); const std::string guiPath = ExoplanetsGuiPath + starNameSpeck; @@ -215,19 +215,22 @@ int addExoplanetSystem(lua_State* L) { ); const glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); - const glm::dvec3 starToSunVec = normalize(sunPosition - starPosition); + const glm::dvec3 starToSunVec = glm::normalize(sunPosition - starPosition); const glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); const glm::dmat3 galaxticToCelestialMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", "J2000", 0.0); - const glm::dvec3 celestialNorth = normalize( + const glm::dvec3 celestialNorth = glm::normalize( galaxticToCelestialMatrix * galacticNorth ); // Earth's north vector projected onto the skyplane, the plane perpendicular to the // viewing vector (starToSunVec) - const float celestialAngle = dot(celestialNorth, starToSunVec); + const float celestialAngle = static_cast(glm::dot( + celestialNorth, + starToSunVec + )); glm::dvec3 northProjected = glm::normalize( celestialNorth - (celestialAngle / glm::length(starToSunVec)) * starToSunVec ); @@ -257,7 +260,7 @@ int addExoplanetSystem(lua_State* L) { } const std::string color = starColor(p.bmv, colorMap); - const float radiusInMeter = starRadius * distanceconstants::SolarRadius; + const float radiusInMeter = starRadius * static_cast(distanceconstants::SolarRadius); starGlobeRenderableString = "Renderable = {" "Type = 'RenderableGlobe'," @@ -339,22 +342,26 @@ int addExoplanetSystem(lua_State* L) { float planetRadius; std::string enabled; + const float astronomicalUnit = static_cast(distanceconstants::AstronomicalUnit); + const float solarRadius = static_cast(distanceconstants::SolarRadius); + const float jupiterRadius = static_cast(distanceconstants::JupiterRadius); + if (isnan(planet.r)) { if (isnan(planet.rStar)) { - planetRadius = planet.a * 0.001f * distanceconstants::AstronomicalUnit; + planetRadius = planet.a * 0.001f * astronomicalUnit; } else { - planetRadius = planet.rStar * 0.1f * distanceconstants::SolarRadius; + planetRadius = planet.rStar * 0.1f * solarRadius; } enabled = "false"; } else { - planetRadius = planet.r * distanceconstants::JupiterRadius; + planetRadius = planet.r * jupiterRadius; enabled = "true"; } const float period = planet.per * static_cast(SecondsPerDay); - const float semiMajorAxisInMeter = planet.a * distanceconstants::AstronomicalUnit; + const float semiMajorAxisInMeter = planet.a * astronomicalUnit; const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; const std::string planetIdentifier = createIdentifier(planetName); @@ -471,7 +478,7 @@ int addExoplanetSystem(lua_State* L) { int removeExoplanetSystem(lua_State* L) { const int StringLocation = -1; const std::string starName = luaL_checkstring(L, StringLocation); - const std::string starNameSpeck = speckStarName(starName); + const std::string starNameSpeck = std::string(speckStarName(starName)); const std::string starIdentifier = createIdentifier(starNameSpeck); openspace::global::scriptEngine.queueScript( diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index ac40189723..a24b53dda6 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -460,7 +460,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // SPECREF getline(lineStream, data, ','); // SPECURL getline(lineStream, data, ','); // STAR - std::string speckStarname = speckStarName(data); + std::string speckStarname = std::string(speckStarName(data)); glm::vec3 position = starPosition(speckStarname); p.positionX = position[0]; p.positionY = position[1]; @@ -528,7 +528,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb } // create look-up table - long pos = binFile.tellp(); + long pos = static_cast(binFile.tellp()); planetName = speckStarname + " " + component; lutFile << planetName << "," << pos << std::endl; binFile.write(reinterpret_cast(&p), sizeof(Exoplanet)); From 7bd0e0bc00b333ce281a957ada64e616b25ddb3a Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 21 Sep 2020 14:46:42 +0200 Subject: [PATCH 107/123] Tiny refactor --- modules/exoplanets/exoplanetsmodule_lua.inl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index f4042aef18..a879c13a17 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -146,9 +148,7 @@ int addExoplanetSystem(lua_State* L) { const std::string starIdentifier = createIdentifier(starNameSpeck); const std::string guiPath = ExoplanetsGuiPath + starNameSpeck; - SceneGraphNode* existingStarNode = - global::renderEngine.scene()->sceneGraphNode(starIdentifier); - + SceneGraphNode* existingStarNode = sceneGraphNode(starIdentifier); if (existingStarNode) { return ghoul::lua::luaError( L, From e74433b3f094fc9d640f3839fe78e896e8d3e389 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 22 Sep 2020 08:21:57 +0200 Subject: [PATCH 108/123] Add function to print a list of available exoplanet systems to the log --- modules/exoplanets/exoplanetsmodule.cpp | 8 ++++ modules/exoplanets/exoplanetsmodule_lua.inl | 52 +++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index f534572c6a..3e39e4fbcf 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -64,6 +64,14 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { {}, "string", "Removes the nodes of the specified exoplanet system from the scene graph." + }, + { + "listAvailableExoplanetSystems", + &exoplanets::luascriptfunctions::listAvailableExoplanetSystems, + {}, + "", + "Prints a list with the names of all exoplanet systems that can be added to " + "the scene graph to the OpenSpace Log. " } }; diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index a879c13a17..bf53950cbf 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,8 @@ namespace openspace::exoplanets::luascriptfunctions { +constexpr const char* _loggerCat = "ExoplanetsModule"; + constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Systems/"; constexpr const char* LookUpTablePath = "${SYNC}/http/exoplanets_data/1/lookup.txt"; @@ -488,4 +491,53 @@ int removeExoplanetSystem(lua_State* L) { return 0; } + +int listAvailableExoplanetSystems(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 0, "lua::listAvailableExoplanetSystems"); + + std::ifstream file(absPath(LookUpTablePath)); + + if (!file.good()) { + return ghoul::lua::luaError( + L, + fmt::format("Failed to open file '{}'", LookUpTablePath) + ); + } + + std::vector names; + // As of 2020 there are about 4000 confirmed exoplanets, so use this number + // as a guess for the vector size + const int nExoplanetsGuess = 4000; + names.reserve(nExoplanetsGuess); + + std::string line; + while (getline(file, line)) { + std::stringstream ss(line); + std::string name; + getline(ss, name, ','); + // Remove the last two characters, that specify the planet + name = name.substr(0, name.size() - 2); + + names.push_back(name); + } + + // For easier read, sort by names and remove duplicates + std::sort(names.begin(), names.end()); + names.erase(std::unique(names.begin(), names.end()), names.end()); + + std::string output; + for (auto it = names.begin(); it != names.end(); ++it) { + if (it != names.end()) { + output += *it + ", "; + } + } + + LINFO(fmt::format( + "There is data available for the following {} exoplanet systems: {}", + names.size(), + output + )); + + return 0; +} } //namespace openspace::exoplanets::luascriptfunctions From 5d9f6ec5a0966bd6cc064cef5de91414f1f26056 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 22 Sep 2020 10:53:05 +0200 Subject: [PATCH 109/123] Increase trail resolution for highly eccentric orbits --- modules/exoplanets/exoplanetsmodule_lua.inl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index bf53950cbf..6b521cdf36 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -259,7 +259,7 @@ int addExoplanetSystem(lua_State* L) { std::ifstream colorMap(absPath(BvColormapPath), std::ios::in); if (!colorMap.good()) { - ghoul::lua::luaError(L, "Failed to open colormap data file"); + return ghoul::lua::luaError(L, "Failed to open colormap data file"); } const std::string color = starColor(p.bmv, colorMap); @@ -402,6 +402,14 @@ int addExoplanetSystem(lua_State* L) { "}" "}"; + int trailResolution = 1000; + + // increase the resolution for highly eccentric orbits + const float eccentricityThreshold = 0.85f; + if (planet.ecc > eccentricityThreshold) { + trailResolution *= 2; + } + openspace::global::scriptEngine.queueScript( "openspace.addSceneGraphNode(" + planetNode + ");", openspace::scripting::ScriptEngine::RemoteScripting::Yes @@ -414,7 +422,7 @@ int addExoplanetSystem(lua_State* L) { "Renderable = {" "Type = 'RenderableTrailOrbit'," "Period = " + std::to_string(planet.per) + "," - "Resolution = 1000," + "Resolution = " + std::to_string(trailResolution) + "," "Translation = " + planetKeplerTranslation + "," "Color = { 1, 1, 1 }" "}," From 78996bb9d9287b30e41544106841d8f13117ec01 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 22 Sep 2020 11:13:26 +0200 Subject: [PATCH 110/123] Cleanup and avoid using variable that might not have been defined --- modules/exoplanets/exoplanetsmodule_lua.inl | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 6b521cdf36..6c563b9897 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -202,15 +202,22 @@ int addExoplanetSystem(lua_State* L) { data.close(); lut.close(); - bool notEnoughData = isnan(p.positionX) || isnan(p.a) || isnan(p.per); - - if (!found || notEnoughData) { + if (!found) { return ghoul::lua::luaError( L, - "No star with that name or not enough data about it." + "No star with the provided name was found." ); } + bool notEnoughData = isnan(p.positionX) || isnan(p.a) || isnan(p.per); + + if (notEnoughData) { + return ghoul::lua::luaError( + L, + "Insufficient data available for representing the exoplanet system." + ); + } + const glm::dvec3 starPosition = glm::dvec3( p.positionX * distanceconstants::Parsec, p.positionY * distanceconstants::Parsec, @@ -359,11 +366,11 @@ int addExoplanetSystem(lua_State* L) { enabled = "false"; } else { - planetRadius = planet.r * jupiterRadius; + planetRadius = static_cast(planet.r) * jupiterRadius; enabled = "true"; } - const float period = planet.per * static_cast(SecondsPerDay); + const float period = static_cast(planet.per * SecondsPerDay); const float semiMajorAxisInMeter = planet.a * astronomicalUnit; const float semiMajorAxisInKm = semiMajorAxisInMeter * 0.001f; @@ -371,7 +378,7 @@ int addExoplanetSystem(lua_State* L) { const std::string planetKeplerTranslation = "{" "Type = 'KeplerTranslation'," - "Eccentricity = " + std::to_string(planet.ecc) + "," //ECC + "Eccentricity = " + std::to_string(planet.ecc) + "," //ECC "SemiMajorAxis = " + std::to_string(semiMajorAxisInKm) + "," "Inclination = " + std::to_string(planet.i) + "," //I "AscendingNode = " + std::to_string(planet.bigOm) + "," //BIGOM From c32de00bd874cb7a8bce9e53be4fae406aa80146 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 23 Sep 2020 08:41:33 +0200 Subject: [PATCH 111/123] Remvoe trailing whitespaces --- modules/exoplanets/exoplanetsmodule_lua.inl | 26 +++++++++---------- .../rendering/renderableorbitdisc.cpp | 2 +- .../tasks/exoplanetscsvtobintask.cpp | 4 +-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 6c563b9897..95311196ff 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -51,11 +51,11 @@ constexpr const char* _loggerCat = "ExoplanetsModule"; constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Systems/"; constexpr const char* LookUpTablePath = "${SYNC}/http/exoplanets_data/1/lookup.txt"; -constexpr const char* ExoplanetsDataPath = +constexpr const char* ExoplanetsDataPath = "${SYNC}/http/exoplanets_data/1/exoplanets_data.bin"; constexpr const char* StarTextureFile = "${SYNC}/http/exoplanets_textures/1/sun.jpg"; -constexpr const char* DiscTextureFile = +constexpr const char* DiscTextureFile = "${SYNC}/http/exoplanets_textures/1/disc_texture.png"; constexpr const char* BvColormapPath = "${SYNC}/http/stars_colormap/2/colorbv.cmap"; @@ -154,7 +154,7 @@ int addExoplanetSystem(lua_State* L) { SceneGraphNode* existingStarNode = sceneGraphNode(starIdentifier); if (existingStarNode) { return ghoul::lua::luaError( - L, + L, "Adding of exoplanet system failed. The system has already been added." ); } @@ -198,15 +198,15 @@ int addExoplanetSystem(lua_State* L) { found = true; } } - + data.close(); lut.close(); if (!found) { return ghoul::lua::luaError( - L, + L, "No star with the provided name was found." - ); + ); } bool notEnoughData = isnan(p.positionX) || isnan(p.a) || isnan(p.per); @@ -223,22 +223,22 @@ int addExoplanetSystem(lua_State* L) { p.positionY * distanceconstants::Parsec, p.positionZ * distanceconstants::Parsec ); - + const glm::dvec3 sunPosition = glm::dvec3(0.0, 0.0, 0.0); const glm::dvec3 starToSunVec = glm::normalize(sunPosition - starPosition); const glm::dvec3 galacticNorth = glm::dvec3(0.0, 0.0, 1.0); - const glm::dmat3 galaxticToCelestialMatrix = + const glm::dmat3 galaxticToCelestialMatrix = SpiceManager::ref().positionTransformMatrix("GALACTIC", "J2000", 0.0); const glm::dvec3 celestialNorth = glm::normalize( galaxticToCelestialMatrix * galacticNorth ); - // Earth's north vector projected onto the skyplane, the plane perpendicular to the + // Earth's north vector projected onto the skyplane, the plane perpendicular to the // viewing vector (starToSunVec) const float celestialAngle = static_cast(glm::dot( - celestialNorth, + celestialNorth, starToSunVec )); glm::dvec3 northProjected = glm::normalize( @@ -299,7 +299,7 @@ int addExoplanetSystem(lua_State* L) { const std::string starParent = "{" "Identifier = '" + starIdentifier + "'," - "Parent = 'SolarSystemBarycenter'," + "Parent = 'SolarSystemBarycenter'," "" + starGlobeRenderableString + "" "Transform = {" "Rotation = {" @@ -467,7 +467,7 @@ int addExoplanetSystem(lua_State* L) { "Eccentricity = " + std::to_string(planet.ecc) + "," "Offset = { " + std::to_string(planet.aLower) + ", " + - std::to_string(planet.aUpper) + + std::to_string(planet.aUpper) + "}," //min / max extend "Opacity = 0.3" "}," @@ -548,7 +548,7 @@ int listAvailableExoplanetSystems(lua_State* L) { } LINFO(fmt::format( - "There is data available for the following {} exoplanet systems: {}", + "There is data available for the following {} exoplanet systems: {}", names.size(), output )); diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 590dbe74c8..54afc08efc 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -52,7 +52,7 @@ namespace { "Size", "This value specifies the semi-major axis of the orbit in meter." }; - + static const openspace::properties::Property::PropertyInfo EccentricityInfo = { "Eccentricity", "Eccentricity", diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index a24b53dda6..64b59ed0f1 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -214,7 +214,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // UECC p.uEcc = readFloatData(data); - + getline(lineStream, data, ','); // ECCREF getline(lineStream, data, ','); // ECCURL getline(lineStream, data, ','); // EOD @@ -254,7 +254,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // ILOWER p.iLower = readFloatData(data); - + getline(lineStream, data, ','); // UI p.ui = readFloatData(data); From 5860f6fcbfab4d88868b67d75b1c864cfb90ba02 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 23 Sep 2020 10:43:37 +0200 Subject: [PATCH 112/123] Fix problem with extra symbol when returning string_view from format conversion --- src/util/time.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/time.cpp b/src/util/time.cpp index 203abb7778..e0be6096eb 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -108,8 +108,8 @@ std::string_view Time::ISO8601() const { std::memset(b, 0, S); SpiceManager::ref().dateFromEphemerisTime(_time, b, S, Format); - - return std::string_view(b, S); + + return std::string_view(b, S-1); } void Time::ISO8601(char* buffer) const { From eb330fed8f81886f17d1580517dca98662c6f5e9 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 25 Sep 2020 08:55:41 +0200 Subject: [PATCH 113/123] Don't bind texture if nullptr Lead to an exception when enabling the exoplanets renderablebillboardclouds during runtime. Should probably investigate why the renderBillboard function is called with a nullptr texture in the first place... --- .../digitaluniverse/rendering/renderablebillboardscloud.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index dd6095e862..54a9dc6649 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -850,7 +850,7 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, if (_hasPolygon) { glBindTexture(GL_TEXTURE_2D, _pTexture); } - else { + else if (_spriteTexture) { _spriteTexture->bind(); } _program->setUniform(_uniformCache.spriteTexture, textureUnit); @@ -867,7 +867,6 @@ void RenderableBillboardsCloud::renderBillboards(const RenderData& data, global::renderEngine.openglStateCache().resetBlendState(); global::renderEngine.openglStateCache().resetDepthState(); - } void RenderableBillboardsCloud::renderLabels(const RenderData& data, @@ -902,7 +901,7 @@ void RenderableBillboardsCloud::renderLabels(const RenderData& data, } glm::vec4 textColor = glm::vec4( - glm::vec3(_textColor), + glm::vec3(_textColor), _textOpacity * fadeInVariable ); From 754128a9e7898e8dc8ae380172044f21b3775c4b Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 28 Sep 2020 11:37:28 +0200 Subject: [PATCH 114/123] Some final cleanup --- data/tasks/exoplanets/csvtobin.task | 1 + modules/exoplanets/exoplanetsmodule.cpp | 4 +- modules/exoplanets/exoplanetsmodule_lua.inl | 6 +- .../rendering/renderableorbitdisc.cpp | 4 +- modules/exoplanets/shaders/orbitdisc_fs.glsl | 18 ++-- .../tasks/exoplanetscsvtobintask.cpp | 85 ++++++++++++------- .../exoplanets/tasks/exoplanetscsvtobintask.h | 3 +- 7 files changed, 71 insertions(+), 50 deletions(-) diff --git a/data/tasks/exoplanets/csvtobin.task b/data/tasks/exoplanets/csvtobin.task index c181496bb3..1ae7a44c6b 100644 --- a/data/tasks/exoplanets/csvtobin.task +++ b/data/tasks/exoplanets/csvtobin.task @@ -5,6 +5,7 @@ return { InputCSV = dataFolder .. "/exoplanets.csv", InputSPECK = "${SYNC}/http/digitaluniverse_exoplanets_speck/1/expl.speck", + TeffToBvFile = "${SYNC}/http/exoplanets_data/1/teff_bv.txt", OutputBIN = dataFolder .. "/exoplanets_data.bin", OutputLUT = dataFolder .. "/lookup.txt" } diff --git a/modules/exoplanets/exoplanetsmodule.cpp b/modules/exoplanets/exoplanetsmodule.cpp index 3e39e4fbcf..b23e31f7f0 100644 --- a/modules/exoplanets/exoplanetsmodule.cpp +++ b/modules/exoplanets/exoplanetsmodule.cpp @@ -40,8 +40,6 @@ namespace openspace { -constexpr const char* _loggerCat = "exoplanets"; - using namespace exoplanets; ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {} @@ -55,7 +53,7 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const { &exoplanets::luascriptfunctions::addExoplanetSystem, {}, "string", - "Add the exoplanet system specified by the input string, including " + "Add the exoplanet system specified by the input string, including " "information about the host star and planets." }, { diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 95311196ff..dc4efc8345 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -44,9 +44,11 @@ #include #include -namespace openspace::exoplanets::luascriptfunctions { +namespace { + constexpr const char* _loggerCat = "ExoplanetsModule"; +} // namespace -constexpr const char* _loggerCat = "ExoplanetsModule"; +namespace openspace::exoplanets::luascriptfunctions { constexpr const char* ExoplanetsGuiPath = "/Milky Way/Exoplanets/Exoplanet Systems/"; diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 54afc08efc..150a4d0e3d 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -258,7 +258,7 @@ void RenderableOrbitDisc::update(const UpdateData& data) { } void RenderableOrbitDisc::loadTexture() { - if (_texturePath.value() != "") { + if (!_texturePath.value().empty()) { std::unique_ptr texture = ghoul::io::TextureReader::ref().loadTexture(absPath(_texturePath)); @@ -281,7 +281,7 @@ void RenderableOrbitDisc::loadTexture() { } void RenderableOrbitDisc::createPlane() { - const GLfloat size = _size.value() * (1.0 + _eccentricity.value()); + const GLfloat size = _size * (1.f + _eccentricity); struct VertexData { GLfloat x; diff --git a/modules/exoplanets/shaders/orbitdisc_fs.glsl b/modules/exoplanets/shaders/orbitdisc_fs.glsl index 758aa7a569..373ea936dc 100644 --- a/modules/exoplanets/shaders/orbitdisc_fs.glsl +++ b/modules/exoplanets/shaders/orbitdisc_fs.glsl @@ -39,7 +39,7 @@ const float Epsilon = 0.0000001; // Compute semi minor axis from major axis, a, and eccentricity, e float semiMinorAxis(float a, float e) { - return a * sqrt(1.0 - pow(e, 2.0)); + return a * sqrt(1.0 - e * e); } // If returned value <= 1, the point is insdie or on the ellipse specified by the input: @@ -57,18 +57,18 @@ Fragment getFragment() { vec2 st = (vs_st - vec2(0.5)) * 2.0; float AUpper = semiMajorAxis; - float BUpper = semiMinorAxis(AUpper, eccentricity); + float BUpper = semiMinorAxis(AUpper, eccentricity); float CUpper = sqrt(AUpper*AUpper - BUpper*BUpper); - float outerApoapsisDistance = AUpper * (1 + eccentricity); + float outerApoapsisDistance = AUpper * (1 + eccentricity); float ALower = AUpper - AstronomicalUnit * (textureOffset.x + textureOffset.y); float BLower = semiMinorAxis(ALower, eccentricity); float CLower = sqrt(ALower*ALower - BLower*BLower); - float innerApoapsisDistance = ALower * (1 + eccentricity); + float innerApoapsisDistance = ALower * (1 + eccentricity); // Normalize based on outer apoapsis distance (size of plane) float AU_n = AUpper / outerApoapsisDistance; - float BU_n = BUpper / outerApoapsisDistance; + float BU_n = BUpper / outerApoapsisDistance; float CU_n = CUpper / outerApoapsisDistance; float AL_n = ALower / outerApoapsisDistance; float BL_n = BLower / outerApoapsisDistance; @@ -77,11 +77,11 @@ Fragment getFragment() { if (eccentricity <= Epsilon) { CU_n = 0.0; CL_n = 0.0; - } + } - float outer = ellipseTest(st, AU_n, BU_n, -CU_n); + float outer = ellipseTest(st, AU_n, BU_n, -CU_n); float inner = ellipseTest(st, AL_n, BL_n, -CL_n); - if (outer > 1.0 || inner < 1.0) { + if (outer > 1.0 || inner < 1.0) { // point is outside outer ellipse or inside inner eliipse discard; } @@ -96,7 +96,7 @@ Fragment getFragment() { float third = (pow(BU_n * CU_n, 2.0) - pow(AU_n * BU_n, 2.0)) / denominator; float scale = first + sqrt(second - third); - + vec2 max = dir * scale; vec2 min = max * (innerApoapsisDistance / outerApoapsisDistance); diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 64b59ed0f1..373f7a3479 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace { @@ -39,10 +40,9 @@ namespace { constexpr const char* KeyInputSpeck = "InputSPECK"; constexpr const char* KeyOutputBin = "OutputBIN"; constexpr const char* KeyOutputLut = "OutputLUT"; + constexpr const char* KeyTeffToBv = "TeffToBvFile"; constexpr const char* _loggerCat = "CsvToBinTask"; - - constexpr const char* TeffBvPath = "${SYNC}/http/exoplanets_data/1/teff_bv.txt"; } // namespace namespace openspace::exoplanets { @@ -58,11 +58,15 @@ ExoplanetsCsvToBinTask::ExoplanetsCsvToBinTask(const ghoul::Dictionary& dictiona _inputSpeckPath = absPath(dictionary.value(KeyInputSpeck)); _outputBinPath = absPath(dictionary.value(KeyOutputBin)); _outputLutPath = absPath(dictionary.value(KeyOutputLut)); + _teffToBvFilePath = absPath(dictionary.value(KeyTeffToBv)); } std::string ExoplanetsCsvToBinTask::description() { - return "Extract metadata from csv-file " + _inputCsvPath + - " and write as bin to " + _outputBinPath; + return fmt::format( + "Extract metadata from csv-file '{}' and write as bin to '{}'", + _inputCsvPath, + _outputBinPath + ); } void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallback) { @@ -78,14 +82,9 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb int version = 1; binFile.write(reinterpret_cast(&version), sizeof(int)); - Exoplanet p; - - std::string planetName; - std::string component; std::string planetRow; getline(csvFile, planetRow); // The first line, containing the data names - bool isKeplerObject = false; int total = 0; while (getline(csvFile, planetRow)) { ++total; @@ -95,20 +94,36 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(csvFile, planetRow); // The first line, containing the data names LINFOC("CSVTOBIN", fmt::format("Loading {} stars", total)); - auto readFloatData = [](const std::string& data) -> float { - return !data.empty() ? std::stof(data.c_str(), nullptr) : NAN; + auto readFloatData = [](const std::string& str) -> float { + float result; + auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result); + if (ec == std::errc()) { + return result; + } + return NAN; }; - auto readDoubleData = [](const std::string& data) -> double { - return !data.empty() ? std::stod(data.c_str(), nullptr) : NAN; + auto readDoubleData = [](const std::string& str) -> double { + double result; + auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result); + if (ec == std::errc()) { + return result; + } + return NAN; }; - auto readIntegerData = [](const std::string& data) -> int { - return !data.empty() ? std::stoi(data.c_str(), nullptr) : -1; + auto readIntegerData = [](const std::string& str) -> int { + int result; + auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result); + if (ec == std::errc()) { + return result; + } + return -1; }; - int count = 0; + Exoplanet p; std::string data; + int count = 0; while (getline(csvFile, planetRow)) { ++count; progressCallback(static_cast(count) / static_cast(total)); @@ -166,7 +181,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // CHI2 getline(lineStream, data, ','); // COMP - component = data; + std::string component = data; getline(lineStream, data, ','); // DATE getline(lineStream, data, ','); // DEC @@ -516,6 +531,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb getline(lineStream, data, ','); // VSINIREF getline(lineStream, data, ','); // VSINIURL getline(lineStream, data, ','); // KEPID + bool isKeplerObject = false; if (!data.empty()) { isKeplerObject = true; } @@ -529,7 +545,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb // create look-up table long pos = static_cast(binFile.tellp()); - planetName = speckStarname + " " + component; + std::string planetName = speckStarname + " " + component; lutFile << planetName << "," << pos << std::endl; binFile.write(reinterpret_cast(&p), sizeof(Exoplanet)); } @@ -539,28 +555,26 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb } glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) { - glm::vec3 position; - position[0] = NAN; - position[1] = NAN; - position[2] = NAN; std::ifstream exoplanetsFile(_inputSpeckPath); if (!exoplanetsFile) { - LERROR(fmt::format("Error opening file expl.speck.")); + LERROR(fmt::format("Error opening file expl.speck")); } + glm::vec3 position{ NAN }; std::string line; - std::string data; // data - std::string name; + while (getline(exoplanetsFile, line)) { bool shouldSkipLine = ( line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" - ); + ); if (shouldSkipLine) { continue; } + std::string data; + std::string name; std::istringstream linestream(line); getline(linestream, data, '#'); getline(linestream, name); @@ -588,19 +602,18 @@ glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) { return transformedPosition; } -float ExoplanetsCsvToBinTask::bvFromTeff(const float teff) { +float ExoplanetsCsvToBinTask::bvFromTeff(float teff) { if (std::isnan(teff)) { return NAN; } - std::ifstream teffToBvFile(absPath(TeffBvPath)); - + std::ifstream teffToBvFile(_teffToBvFilePath); if (!teffToBvFile.good()) { LERROR(fmt::format("Failed to open teff_bv.txt file")); return NAN; } - float BV = 0.f; + float bv = 0.f; float bvUpper = 0.f; float bvLower = 0.f; float teffLower, teffUpper; @@ -621,17 +634,17 @@ float ExoplanetsCsvToBinTask::bvFromTeff(const float teff) { teffUpper = teffCurrent; bvUpper = bvCurrent; if (bvLower == 0.f) { - BV = 2.f; + bv = 2.f; } else { float bvDiff = (bvUpper - bvLower); float teffDiff = (teffUpper - teffLower); - BV = ((bvDiff * (teff - teffLower)) / teffDiff) + bvLower; + bv = ((bvDiff * (teff - teffLower)) / teffDiff) + bvLower; } break; } } - return BV; + return bv; } documentation::Documentation ExoplanetsCsvToBinTask::documentation() { @@ -669,6 +682,12 @@ documentation::Documentation ExoplanetsCsvToBinTask::documentation() { new StringAnnotationVerifier("A valid filepath"), Optional::No, "The txt file to write look-up table into" + }, + { + KeyTeffToBv, + new StringAnnotationVerifier("A valid filepath"), + Optional::No, + "The path to the teff to a bv conversion file" } } }; diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.h b/modules/exoplanets/tasks/exoplanetscsvtobintask.h index 38b91b19bd..9bbebf74ed 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.h +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.h @@ -43,11 +43,12 @@ private: std::string _inputSpeckPath; std::string _outputBinPath; std::string _outputLutPath; + std::string _teffToBvFilePath; glm::vec3 starPosition(const std::string& starName); // Compute b-v color from teff value using a conversion file - float bvFromTeff(const float teff); + float bvFromTeff(float teff); }; } // namespace openspace::exoplanets From ceb5c85e5c9fb27730828053f547f0fdebcb3442 Mon Sep 17 00:00:00 2001 From: Lovisa Hassler Date: Mon, 28 Sep 2020 16:02:39 +0200 Subject: [PATCH 115/123] Removed duplicated documentation for vec4 color --- modules/base/rendering/renderablelabels.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/modules/base/rendering/renderablelabels.cpp b/modules/base/rendering/renderablelabels.cpp index 9ad0172359..c435137a97 100644 --- a/modules/base/rendering/renderablelabels.cpp +++ b/modules/base/rendering/renderablelabels.cpp @@ -206,12 +206,6 @@ documentation::Documentation RenderableLabels::Documentation() { Optional::Yes, LabelColorInfo.description, }, - { - LabelColorInfo.identifier, - new DoubleVector4Verifier, - Optional::Yes, - LabelColorInfo.description, - }, { LabelTextInfo.identifier, new StringVerifier, @@ -397,7 +391,7 @@ RenderableLabels::RenderableLabels(const ghoul::Dictionary& dictionary) _labelColor.setViewOption(properties::Property::ViewOptions::Color); if (dictionary.hasKey(LabelColorInfo.identifier)) { - _labelColor = dictionary.value(LabelColorInfo.identifier); + _labelColor = dictionary.value(LabelColorInfo.identifier); } addProperty(_labelColor); From 3310d954b35b95496e72348fecf15b74c638bf31 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Mon, 28 Sep 2020 16:14:55 +0200 Subject: [PATCH 116/123] Fix typo --- modules/exoplanets/tasks/exoplanetscsvtobintask.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 373f7a3479..6cb232fb79 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -687,7 +687,7 @@ documentation::Documentation ExoplanetsCsvToBinTask::documentation() { KeyTeffToBv, new StringAnnotationVerifier("A valid filepath"), Optional::No, - "The path to the teff to a bv conversion file" + "The path to a teff to bv conversion file" } } }; From 3cc2d2aedf1371ecaf715da144a1cc8506949c61 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 7 Oct 2020 17:12:06 +0200 Subject: [PATCH 117/123] Fix for compile errors in Linux in exoplanets module --- modules/exoplanets/rendering/renderableorbitdisc.h | 1 + modules/exoplanets/tasks/exoplanetscsvtobintask.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/modules/exoplanets/rendering/renderableorbitdisc.h b/modules/exoplanets/rendering/renderableorbitdisc.h index 3cae6e64c4..3a78546596 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.h +++ b/modules/exoplanets/rendering/renderableorbitdisc.h @@ -30,6 +30,7 @@ #include #include #include +#include #include namespace ghoul::filesystem { class File; } diff --git a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp index 6cb232fb79..8277830923 100644 --- a/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp +++ b/modules/exoplanets/tasks/exoplanetscsvtobintask.cpp @@ -95,21 +95,31 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb LINFOC("CSVTOBIN", fmt::format("Loading {} stars", total)); auto readFloatData = [](const std::string& str) -> float { + #ifdef WIN32 float result; auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result); if (ec == std::errc()) { return result; } return NAN; + #else + // clang is missing float support for std::from_chars + return !str.empty() ? std::stof(str.c_str(), nullptr) : NAN; + #endif }; auto readDoubleData = [](const std::string& str) -> double { + #ifdef WIN32 double result; auto [p, ec] = std::from_chars(str.data(), str.data() + str.size(), result); if (ec == std::errc()) { return result; } return NAN; + #else + // clang is missing double support for std::from_chars + return !str.empty() ? std::stod(str.c_str(), nullptr) : NAN; + #endif }; auto readIntegerData = [](const std::string& str) -> int { From 50a456b87f828701f20200a0b6ecfac794bcd239 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Fri, 9 Oct 2020 17:32:30 +0200 Subject: [PATCH 118/123] Issue/1299 (#1312) Change profile file format from a custom one to JSON --- apps/OpenSpace/ext/sgct | 2 +- .../constellations/constellation_data.csv | 85 -- data/profiles/default.profile | 52 +- ext/ghoul | 2 +- include/openspace/scene/profile.h | 39 +- src/CMakeLists.txt | 2 + src/engine/openspaceengine.cpp | 10 +- src/scene/profile.cpp | 1222 +++++++---------- src/util/time.cpp | 3 +- .../profile/basic/additional_scripts.profile | 8 + tests/profile/basic/assets.profile | 8 + tests/profile/basic/camera_gotogeo.profile | 9 + .../basic/camera_gotogeo_altitude.profile | 10 + .../basic/camera_navstate_full.profile | 13 + .../basic/camera_navstate_no_aim.profile | 12 + .../basic/camera_navstate_no_pitch.profile | 12 + .../basic/camera_navstate_no_up.profile | 12 + .../basic/camera_navstate_no_yaw.profile | 12 + tests/profile/basic/deltatimes.profile | 10 + tests/profile/basic/keybindings.profile | 29 + tests/profile/basic/mark_nodes.profile | 6 + tests/profile/basic/meta_empty.profile | 11 + tests/profile/basic/meta_full.profile | 11 + tests/profile/basic/meta_no_author.profile | 10 + .../profile/basic/meta_no_description.profile | 10 + tests/profile/basic/meta_no_license.profile | 10 + tests/profile/basic/meta_no_name.profile | 10 + tests/profile/basic/meta_no_url.profile | 10 + tests/profile/basic/meta_no_version.profile | 10 + tests/profile/basic/modules.profile | 19 + tests/profile/basic/properties.profile | 35 + tests/profile/basic/time_absolute.profile | 7 + tests/profile/basic/time_relative.profile | 7 + .../profile/basic_additional_scripts.profile | 7 - tests/profile/basic_assets.profile | 7 - tests/profile/basic_camera_gotogeo.profile | 5 - .../basic_camera_gotogeo_altitude.profile | 5 - tests/profile/basic_camera_navstate.profile | 5 - tests/profile/basic_deltatimes.profile | 9 - tests/profile/basic_keybindings.profile | 7 - tests/profile/basic_mark_nodes.profile | 7 - tests/profile/basic_meta.profile | 10 - tests/profile/basic_modules.profile | 7 - tests/profile/basic_properties.profile | 10 - tests/profile/basic_time_absolute.profile | 5 - tests/profile/basic_time_relative.profile | 5 - .../basic_version_one_component.profile | 2 - .../basic_version_two_components.profile | 2 - .../camera/camera_gotogeo_altitude.profile | 10 + .../camera/gotogeo_missing_anchor.profile | 9 + .../camera/gotogeo_missing_latitude.profile | 9 + .../camera/gotogeo_missing_longitude.profile | 9 + .../camera/gotogeo_wrongtype_altitude.profile | 10 + .../camera/gotogeo_wrongtype_anchor.profile | 10 + .../camera/gotogeo_wrongtype_latitude.profile | 10 + .../gotogeo_wrongtype_longitude.profile | 10 + .../camera/navstate_missing_anchor.profile | 12 + .../camera/navstate_missing_frame.profile | 12 + .../camera/navstate_missing_position.profile | 12 + .../navstate_missing_position_x.profile | 13 + .../navstate_missing_position_y.profile | 13 + .../navstate_missing_position_z.profile | 13 + .../camera/navstate_missing_up_x.profile | 13 + .../camera/navstate_missing_up_y.profile | 13 + .../camera/navstate_missing_up_z.profile | 13 + .../camera/navstate_wrongtype_aim.profile | 13 + .../camera/navstate_wrongtype_anchor.profile | 13 + .../camera/navstate_wrongtype_frame.profile | 13 + .../camera/navstate_wrongtype_pitch.profile | 13 + .../navstate_wrongtype_position.profile | 13 + .../navstate_wrongtype_position_x.profile | 13 + .../navstate_wrongtype_position_y.profile | 13 + .../navstate_wrongtype_position_z.profile | 13 + .../camera/navstate_wrongtype_up.profile | 13 + .../camera/navstate_wrongtype_up_x.profile | 13 + .../camera/navstate_wrongtype_up_y.profile | 13 + .../camera/navstate_wrongtype_up_z.profile | 13 + .../camera/navstate_wrongtype_yaw.profile | 13 + .../error/camera/wrongvalue_type.profile | 6 + .../error/deltatimes/wrongtype_value.profile | 6 + .../keybinding/missing_documentation.profile | 12 + .../error/keybinding/missing_guipath.profile | 12 + .../error/keybinding/missing_islocal.profile | 12 + .../error/keybinding/missing_key.profile | 12 + .../error/keybinding/missing_name.profile | 12 + .../keybinding/missing_script - Copy.profile | 13 + .../error/keybinding/missing_script.profile | 12 + .../wrongtype_documentation.profile | 13 + .../keybinding/wrongtype_guipath.profile | 13 + .../keybinding/wrongtype_islocal.profile | 13 + .../error/keybinding/wrongtype_name.profile | 13 + .../error/keybinding/wrongtype_script.profile | 13 + .../error/keybinding/wrongvalue_key.profile | 13 + .../keybinding/wrongvalue_modifier.profile | 29 + .../meta/wrong_parameter_value_type.profile | 6 + .../profile/error/module/missing_name.profile | 8 + .../wrongtype_loadedInstruction.profile | 10 + .../error/module/wrongtype_name.profile | 10 + .../wrongtype_notLoadedInstruction.profile | 10 + .../error/property/missing_name.profile | 9 + .../error/property/missing_name_value.profile | 8 + .../error/property/missing_value.profile | 9 + .../error/property/wrongtype_name.profile | 10 + .../error/property/wrongtype_value.profile | 10 + .../error/property/wrongvalue_type.profile | 10 + .../error/time/absolute_missing_value.profile | 6 + tests/profile/error/time/missing_type.profile | 5 + .../error/time/relative_missing_value.profile | 6 + .../error/time/too_few_parameters.profile | 6 + .../error/time/wrongvalue_type.profile | 7 + .../error/version/missing_major.profile | 3 + .../error/version/missing_minor.profile | 3 + .../error/version/wrongtype_major.profile | 3 + .../version/wrongtype_major_minor.profile | 3 + .../error/version/wrongtype_minor.profile | 3 + .../error_asset_too_few_parameters.profile | 5 - .../error_asset_too_many_parameters.profile | 5 - ..._camera_gotogeo_too_few_parameters.profile | 5 - ...camera_gotogeo_too_many_parameters.profile | 5 - ...camera_navstate_too_few_parameters.profile | 5 - ...amera_navstate_too_many_parameters.profile | 5 - ...ameter_too_few_components_position.profile | 5 - ...ng_parameter_too_few_components_up.profile | 5 - ...meter_too_many_components_position.profile | 5 - ...avstate_wrong_parameter_type_pitch.profile | 5 - ..._navstate_wrong_parameter_type_yaw.profile | 5 - ...eter_wrong_component_type_position.profile | 5 - ..._parameter_wrong_component_type_up.profile | 5 - ..._camera_wrong_parameter_value_type.profile | 5 - ...tatimes_wrong_parameter_value_type.profile | 8 - ...rror_keybinding_too_few_parameters.profile | 5 - ...ror_keybinding_too_many_parameters.profile | 5 - ...binding_wrong_parameter_type_local.profile | 5 - ...ybinding_wrong_parameter_value_key.profile | 7 - ...ing_wrong_parameter_value_modifier.profile | 7 - ...or_meta_wrong_parameter_value_type.profile | 5 - .../error_missing_separator_line.profile | 4 - .../error_module_too_few_parameters.profile | 5 - .../error_module_too_many_parameters.profile | 5 - .../error_property_too_few_parameters.profile | 5 - ...error_property_too_many_parameters.profile | 5 - ...roperty_wrong_parameter_value_type.profile | 5 - .../error_time_too_few_parameters.profile | 5 - .../error_time_too_many_parameters.profile | 5 - ...or_time_wrong_parameter_value_type.profile | 5 - .../profile/error_two_camera_sections.profile | 8 - tests/profile/error_two_meta_sections.profile | 18 - tests/profile/error_two_time_sections.profile | 8 - .../error_two_version_sections.profile | 5 - .../profile/error_unrecognized_header.profile | 7 - .../error_version_malformed_component.profile | 2 - tests/profile/error_version_not_first.profile | 7 - .../error_version_too_many_components.profile | 2 - tests/profile/integration/full_test.profile | 116 ++ tests/profile/integration_full_test.profile | 53 - ...ntegration_full_test_permutation_1.profile | 54 - ...gration_full_test_permutation_base.profile | 53 - tests/profile/minimal.profile | 5 +- tests/test_profile.cpp | 1125 +++++++++------ tests/test_spicemanager.cpp | 1 - tests/test_timequantizer.cpp | 2 +- 161 files changed, 2366 insertions(+), 1766 deletions(-) delete mode 100644 data/assets/scene/milkyway/constellations/constellation_data.csv create mode 100644 tests/profile/basic/additional_scripts.profile create mode 100644 tests/profile/basic/assets.profile create mode 100644 tests/profile/basic/camera_gotogeo.profile create mode 100644 tests/profile/basic/camera_gotogeo_altitude.profile create mode 100644 tests/profile/basic/camera_navstate_full.profile create mode 100644 tests/profile/basic/camera_navstate_no_aim.profile create mode 100644 tests/profile/basic/camera_navstate_no_pitch.profile create mode 100644 tests/profile/basic/camera_navstate_no_up.profile create mode 100644 tests/profile/basic/camera_navstate_no_yaw.profile create mode 100644 tests/profile/basic/deltatimes.profile create mode 100644 tests/profile/basic/keybindings.profile create mode 100644 tests/profile/basic/mark_nodes.profile create mode 100644 tests/profile/basic/meta_empty.profile create mode 100644 tests/profile/basic/meta_full.profile create mode 100644 tests/profile/basic/meta_no_author.profile create mode 100644 tests/profile/basic/meta_no_description.profile create mode 100644 tests/profile/basic/meta_no_license.profile create mode 100644 tests/profile/basic/meta_no_name.profile create mode 100644 tests/profile/basic/meta_no_url.profile create mode 100644 tests/profile/basic/meta_no_version.profile create mode 100644 tests/profile/basic/modules.profile create mode 100644 tests/profile/basic/properties.profile create mode 100644 tests/profile/basic/time_absolute.profile create mode 100644 tests/profile/basic/time_relative.profile delete mode 100644 tests/profile/basic_additional_scripts.profile delete mode 100644 tests/profile/basic_assets.profile delete mode 100644 tests/profile/basic_camera_gotogeo.profile delete mode 100644 tests/profile/basic_camera_gotogeo_altitude.profile delete mode 100644 tests/profile/basic_camera_navstate.profile delete mode 100644 tests/profile/basic_deltatimes.profile delete mode 100644 tests/profile/basic_keybindings.profile delete mode 100644 tests/profile/basic_mark_nodes.profile delete mode 100644 tests/profile/basic_meta.profile delete mode 100644 tests/profile/basic_modules.profile delete mode 100644 tests/profile/basic_properties.profile delete mode 100644 tests/profile/basic_time_absolute.profile delete mode 100644 tests/profile/basic_time_relative.profile delete mode 100644 tests/profile/basic_version_one_component.profile delete mode 100644 tests/profile/basic_version_two_components.profile create mode 100644 tests/profile/error/camera/camera_gotogeo_altitude.profile create mode 100644 tests/profile/error/camera/gotogeo_missing_anchor.profile create mode 100644 tests/profile/error/camera/gotogeo_missing_latitude.profile create mode 100644 tests/profile/error/camera/gotogeo_missing_longitude.profile create mode 100644 tests/profile/error/camera/gotogeo_wrongtype_altitude.profile create mode 100644 tests/profile/error/camera/gotogeo_wrongtype_anchor.profile create mode 100644 tests/profile/error/camera/gotogeo_wrongtype_latitude.profile create mode 100644 tests/profile/error/camera/gotogeo_wrongtype_longitude.profile create mode 100644 tests/profile/error/camera/navstate_missing_anchor.profile create mode 100644 tests/profile/error/camera/navstate_missing_frame.profile create mode 100644 tests/profile/error/camera/navstate_missing_position.profile create mode 100644 tests/profile/error/camera/navstate_missing_position_x.profile create mode 100644 tests/profile/error/camera/navstate_missing_position_y.profile create mode 100644 tests/profile/error/camera/navstate_missing_position_z.profile create mode 100644 tests/profile/error/camera/navstate_missing_up_x.profile create mode 100644 tests/profile/error/camera/navstate_missing_up_y.profile create mode 100644 tests/profile/error/camera/navstate_missing_up_z.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_aim.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_anchor.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_frame.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_pitch.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_position.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_position_x.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_position_y.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_position_z.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_up.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_up_x.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_up_y.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_up_z.profile create mode 100644 tests/profile/error/camera/navstate_wrongtype_yaw.profile create mode 100644 tests/profile/error/camera/wrongvalue_type.profile create mode 100644 tests/profile/error/deltatimes/wrongtype_value.profile create mode 100644 tests/profile/error/keybinding/missing_documentation.profile create mode 100644 tests/profile/error/keybinding/missing_guipath.profile create mode 100644 tests/profile/error/keybinding/missing_islocal.profile create mode 100644 tests/profile/error/keybinding/missing_key.profile create mode 100644 tests/profile/error/keybinding/missing_name.profile create mode 100644 tests/profile/error/keybinding/missing_script - Copy.profile create mode 100644 tests/profile/error/keybinding/missing_script.profile create mode 100644 tests/profile/error/keybinding/wrongtype_documentation.profile create mode 100644 tests/profile/error/keybinding/wrongtype_guipath.profile create mode 100644 tests/profile/error/keybinding/wrongtype_islocal.profile create mode 100644 tests/profile/error/keybinding/wrongtype_name.profile create mode 100644 tests/profile/error/keybinding/wrongtype_script.profile create mode 100644 tests/profile/error/keybinding/wrongvalue_key.profile create mode 100644 tests/profile/error/keybinding/wrongvalue_modifier.profile create mode 100644 tests/profile/error/meta/wrong_parameter_value_type.profile create mode 100644 tests/profile/error/module/missing_name.profile create mode 100644 tests/profile/error/module/wrongtype_loadedInstruction.profile create mode 100644 tests/profile/error/module/wrongtype_name.profile create mode 100644 tests/profile/error/module/wrongtype_notLoadedInstruction.profile create mode 100644 tests/profile/error/property/missing_name.profile create mode 100644 tests/profile/error/property/missing_name_value.profile create mode 100644 tests/profile/error/property/missing_value.profile create mode 100644 tests/profile/error/property/wrongtype_name.profile create mode 100644 tests/profile/error/property/wrongtype_value.profile create mode 100644 tests/profile/error/property/wrongvalue_type.profile create mode 100644 tests/profile/error/time/absolute_missing_value.profile create mode 100644 tests/profile/error/time/missing_type.profile create mode 100644 tests/profile/error/time/relative_missing_value.profile create mode 100644 tests/profile/error/time/too_few_parameters.profile create mode 100644 tests/profile/error/time/wrongvalue_type.profile create mode 100644 tests/profile/error/version/missing_major.profile create mode 100644 tests/profile/error/version/missing_minor.profile create mode 100644 tests/profile/error/version/wrongtype_major.profile create mode 100644 tests/profile/error/version/wrongtype_major_minor.profile create mode 100644 tests/profile/error/version/wrongtype_minor.profile delete mode 100644 tests/profile/error_asset_too_few_parameters.profile delete mode 100644 tests/profile/error_asset_too_many_parameters.profile delete mode 100644 tests/profile/error_camera_gotogeo_too_few_parameters.profile delete mode 100644 tests/profile/error_camera_gotogeo_too_many_parameters.profile delete mode 100644 tests/profile/error_camera_navstate_too_few_parameters.profile delete mode 100644 tests/profile/error_camera_navstate_too_many_parameters.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_too_few_components_position.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_too_few_components_up.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_too_many_components_position.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_type_pitch.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_type_yaw.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_wrong_component_type_position.profile delete mode 100644 tests/profile/error_camera_navstate_wrong_parameter_wrong_component_type_up.profile delete mode 100644 tests/profile/error_camera_wrong_parameter_value_type.profile delete mode 100644 tests/profile/error_deltatimes_wrong_parameter_value_type.profile delete mode 100644 tests/profile/error_keybinding_too_few_parameters.profile delete mode 100644 tests/profile/error_keybinding_too_many_parameters.profile delete mode 100644 tests/profile/error_keybinding_wrong_parameter_type_local.profile delete mode 100644 tests/profile/error_keybinding_wrong_parameter_value_key.profile delete mode 100644 tests/profile/error_keybinding_wrong_parameter_value_modifier.profile delete mode 100644 tests/profile/error_meta_wrong_parameter_value_type.profile delete mode 100644 tests/profile/error_missing_separator_line.profile delete mode 100644 tests/profile/error_module_too_few_parameters.profile delete mode 100644 tests/profile/error_module_too_many_parameters.profile delete mode 100644 tests/profile/error_property_too_few_parameters.profile delete mode 100644 tests/profile/error_property_too_many_parameters.profile delete mode 100644 tests/profile/error_property_wrong_parameter_value_type.profile delete mode 100644 tests/profile/error_time_too_few_parameters.profile delete mode 100644 tests/profile/error_time_too_many_parameters.profile delete mode 100644 tests/profile/error_time_wrong_parameter_value_type.profile delete mode 100644 tests/profile/error_two_camera_sections.profile delete mode 100644 tests/profile/error_two_meta_sections.profile delete mode 100644 tests/profile/error_two_time_sections.profile delete mode 100644 tests/profile/error_two_version_sections.profile delete mode 100644 tests/profile/error_unrecognized_header.profile delete mode 100644 tests/profile/error_version_malformed_component.profile delete mode 100644 tests/profile/error_version_not_first.profile delete mode 100644 tests/profile/error_version_too_many_components.profile create mode 100644 tests/profile/integration/full_test.profile delete mode 100644 tests/profile/integration_full_test.profile delete mode 100644 tests/profile/integration_full_test_permutation_1.profile delete mode 100644 tests/profile/integration_full_test_permutation_base.profile diff --git a/apps/OpenSpace/ext/sgct b/apps/OpenSpace/ext/sgct index 3d3835c38c..f54b2fc6f0 160000 --- a/apps/OpenSpace/ext/sgct +++ b/apps/OpenSpace/ext/sgct @@ -1 +1 @@ -Subproject commit 3d3835c38c8b87972f406ed44af1b5b2d48b1600 +Subproject commit f54b2fc6f01f42bb0158734a3cfc565c3d5cf281 diff --git a/data/assets/scene/milkyway/constellations/constellation_data.csv b/data/assets/scene/milkyway/constellations/constellation_data.csv deleted file mode 100644 index 7c02f310de..0000000000 --- a/data/assets/scene/milkyway/constellations/constellation_data.csv +++ /dev/null @@ -1,85 +0,0 @@ -Data about Constellations columns are: group, name, x, y, z, scale, imageName, rotX, rotY, rotZ, centerStar -normal,Ori,Orion,-550.8742,-259.3621,-188.9620,1.5,Ori.png,1.128407,1.058407,1.668407,HD37128 -zodiac,Tau,Taurus,-18.7277,-0.3175,-6.9092,1.2,Tau.png,1.198407,0.908407,1.378407,Aldebran -zodiac,Ari,Aries,-13.2892,9.4519,-11.9378,0.8,Ari.png,0.668407,0.538407,0.518407,Hamal -zodiac,Gem,Gemini,-362.5493,-102.2245,79.4030,0.85,Gem.png,-0.731593,2.268407,-0.451593,Mekbuda -zodiac,Cnc,Cancer,-30.9209,-16.4584,22.6601,0.8,Cnc.png,-1.151593,1.888407,-1.041593,HD74442 -zodiac,Leo,Leo,-17.9030,-13.2719,31.4196,1.33,Leo.png,-0.131593,2.448407,0.418407,HD89484 -zodiac,Vir,Virgo,36.5809,-35.1877,62.3341,1.5,Vir.png,-0.371593,3.138407,0.518407,HD116658 -zodiac,Lib,Libra,17.5393,-6.2768,14.5916,1.0,Lib.png,-1.011593,3.138407,1.318407,HD130819 -zodiac,Sco,Scorpius,137.4378,-19.4456,37.3606,1.2,Sco.png,1.698407,-1.001593,-1.751593,HD148478 -zodiac,Sgr,Sagittarius,66.2304,11.1498,-14.8095,1.2,Sgr.png,1.728407,-1.321593,-1.751593,HD175191 -zodiac,Cap,Capricornus,32.9799,20.0621,-29.3945,1.3,Cap.png,1.158407,-0.881593,-0.561593,HD200761 -zodiac,Aqr,Aquarius,86.5090,149.4078,-155.8102,1.2,Aqr.png,-2.921593,-2.391593,-2.551593,-2.511593 -zodiac,Psc,Pisces,-28.0235,45.3150,-76.8893,1.6,Psc.png,0.458407,-0.001593,0.618407,HD4656 -northern,Uma,Ursa Major,-12.0503,7.1931,19.8974,1.6,UMa.png,0.748407,2.398407,0.658407,HD95418 -northern,Dra,Draco,-1.4340,20.6566,23.5098,1.9,Dra.png,0.658407,-2.541593,1.058407,HD137759 -southern,Ant,Antila,-0.2233,-103.8908,42.7940,1.3,Ant.png,1.848407,0.198407,-3.141593,HD90610 -southern,Crv,Corvus,8.0442,-16.8858,19.3984,1.1,Crv.png,2.198407,-0.041593,-2.221593,HD108767 -southern,Cet,Cetus,-28.7960,7.2425,-73.6693,1.5,Cet.png,0.238407,0.368407,0.688407,HD11353 -southern,Cha,Chameleon,53.5121,-108.3624,-38.1807,1.1,Cha.png,-1.801593,2.738407,0.448407,HD92305 -northern,Cam,Camelopardalis,-304.8155,179.0620,71.1454,1.7,Cam.png,2.128407,1.228407,1.478407,HD31910 -equatorial,Aql,Aquila,11.7741,9.7467,-1.6418,1.0,Aql.png,-2.601593,-2.511593,-3.141593,HD182640 -southern,Aps,Apus,31.6370,-32.5620,-16.5786,1.1,Aps.png,-1.691593,-2.281593,0.838407,HD149324 -northern,Lyn,Lynx,-98.3174,4.4830,67.2289,1.2,Lyn.png,1.688407,1.768407,1.668407,HD70272 -southern,Phe,Phoenix,5.0172,-4.2096,-22.8088,1.5,Phe.png,-3.141593,3.138407,-3.141593,HD6595 -northern,Cyg,Cygnus,78.7445,375.2440,12.4995,1.4,Cyg.png,1.668407,-0.931593,-0.261593,HD194093 -southern,Cen,Centaurus,20.1398,-33.1830,9.5915,2.7,Cen.png,-1.291593,3.088407,0.458407,HD110304 -northern,Aur,Auriga,-12.3062,3.8595,1.0302,1.5,Aur.png,1.378407,1.108407,1.178407,HD34029 -northern,Peg,Pegasus,0.9791,32.5947,-27.7339,2.42,Peg.png,0.918407,-0.221593,-0.191593,HD218045 -southern,Hya,Hydra,-2.9043,-33.5496,25.8962,3,Hya.png,-0.531593,2.838407,0.368407,HD93813 -southern,Oct,Octans,22.0434,-27.8601,-24.3108,1.0,Oct.png,-0.911593,0.398407,1.198407,HD214846 -southern,Nor,Norma,34.9251,-17.5643,0.0068,1.0,Nor.png,-1.631593,-2.421593,1.298407,HD146686 -southern,Mus,Musca,48.8888,-79.2952,-10.2828,1.25,Mus.png,-1.871593,3.138407,0.358407,HD109668 -southern,Hyi,Hydrus,3.2767,-4.7183,-4.7829,1.1,Hyi.png,2.438407,-3.141593,-2.381593,HD2151 -northern,Lac,Lacerta,-6.0878,30.5794,-3.6064,1.0,Lac.png,-1.521593,-2.391593,3.138407,HD213558 -equatorial,Lep,Lepus,-212.6297,-184.4909,-132.1156,1.0,Lep.png,-1.801593,-2.351593,-0.861593,HD36673 -southern,Lup,Lupus,129.1166,-102.2983,33.3251,1.2,Lup.png,-1.191593,-2.391593,0.798407,HD129056 -southern,Men,Mensa,2.4149,-8.5586,-4.8892,1.0,Men.png,-2.101593,-2.781593,0.828407,HD43834 -southern,Mic,Microscopium,51.0335,11.1671,-44.3692,1.0,Mic.png,0.728407,-0.831593,-0.561593,HD199951 -equatorial,Mon,Monoceros,-93.0725,-66.8909,8.6548,1.2,Mon.png,-1.331593,1.988407,-0.891593,HD55185 -southern,Pav,Pavo,4.4549,-2.5959,-3.2739,1.3,Pav.png,-2.391593,-2.171593,1.648407,HD190248 -southern,Ind,Indus,133.6149,-53.5569,-115.9552,1.5,Ind.png,-2.031593,-1.491593,1.758407,HD198700 -northern,LMi,Leo Minor,-23.3948,-2.5770,38.0756,1.1,LMi.png,-3.141593,0.478407,-2.201593,HD90537 -northern,Lyr,Lyra,2.8086,6.7630,2.5555,1.0,Lyr.png,-1.831593,-2.091593,3.141500,HD172167 -northern,Her,Hercules,14.0526,14.9773,12.5478,1.3,Her.png,-1.511593,-1.811593,2.288407,HD156164 -southern,Gru,Grus,18.6528,-3.2893,-24.6602,1.3,Gru.png,-3.141593,-2.511593,-2.901593,HD209952 -southern,Crt,Crater,1.5886,-43.9831,40.3390,1.3,Crt.png,-0.521593,3.140000,0.588407,HD98430 -northern,Del,Delphinus,14.8599,24.6150,-8.0550,1.2,Del.png,1.308407,-0.951593,-0.241593,HD196524 -southern,Dor,Dorado,-0.6460,-9.3172,-6.9654,1.2,Dor.png,2.118407,1.768407,-2.901593,HD33262 -northern,Equ,Equuleus,27.7363,41.7071,-27.4371,1.2,Equ.png,-1.801593,-2.511593,2.558407,HD202447 -southern,Eri,Eridanus,-37.5153,-23.5231,-65.6368,2.1,Eri.png,0.128407,0.698407,0.998407,HD20720 -southern,For,Fornax,-14.0351,-17.8282,-46.5514,1.4,For.png,3.138407,2.678407,-2.351593,HD17652 -southern,Hor,Horologium,2.1021,-27.1310,-40.5136,1.2,Hor.png,-3.141593,2.468407,-2.191593,HD16920 -southern,Pyx,Pyxis,-66.7424,-248.9639,26.0445,1.2,Pyx.png,1.838407,-1.651593,2.708407,HD74575 -southern,Ret,Reticulum,2.8130,-37.2904,-33.2644,1.5,Ret.png,1.998407,2.188407,-2.591593,HD27256 -northern,Sge,Sagitta,44.3886,70.9446,-7.6264,1.2,Sge.png,-0.741593,-2.231593,2.108407,HD189319 -southern,Scl,Sculptor,21.6545,-6.8861,-166.5240,1.3,Scl.png,-0.071593,-0.221593,0.638407,HD2429 -southern,Sct,Scutum,48.8939,21.5158,-0.1629,1.2,Sct.png,1.188407,-1.271593,-0.971593,HD171443 -southern,Tuc,Tucana,35.3950,-20.2535,-45.2324,1.1,Tuc.png,-0.351593,-0.161593,0.308407,HD211416 -northern,Tri,Triangulum,-26.6263,21.9119,-16.2254,1.2,Tri.png,1.168407,0.218407,0.558407,HD13161 -southern,TrA,Triangulum Australe,96.2283,-76.4459,-33.5257,1.2,TrA.png,-1.991593,-2.491593,1.128407,HD150798 -southern,Tel,Telescopium,72.3444,-14.5016,-20.0248,1.2,Tel.png,-0.461593,-1.731593,0.298407,HD169467 -southern,Ara,Ara,164.9273,-75.6246,-35.3100,1.1,Ara.png,-1.381593,-2.131593,1.048407,HD157244 -southern,Cae,Caelum,-6.0961,-13.7926,-13.3392,1.0,Cae.png,-0.661593,0.948407,0.418407,HD29875 -southern,CMa,Canis Major,-1.7693,-1.9125,-0.4074,1.3,CMa.png,1.128407,1.048407,1.878407,HD48915 -northern,CMi,Canis Minor,-2.8348,-1.8906,0.7881,1.2,CMi.png,2.538407,1.138407,-3.141593,HD61421 -southern,Vol,Volans,37.6000,-182.7856,-62.6559,1.2,Vol.png,-2.441593,1.988407,-0.351593,HD68520 -northern,UMi,Ursa Minor,-11.3527,27.2100,25.1835,1.3,UMi.png,-2.491593,-0.581593,-2.381593,HD131873 -northern,And,Andromdeda,-32.8276,43.3946,-27.8475,1.6,And.png,-2.021593,-3.141593,-2.521593,HD6860 -northern,Boo,Bootes,11.2468,14.9864,30.4945,2.0,Boo.png,-3.141593,-0.601593,-2.361593,HD135722 -northern,Vul,Vulpecula,46.7540,77.7780,5.3953,1.1,Vul.png,-2.301593,-2.061593,-3.141593,HD131873 -northern,CVn,Canes Venatici,-3.1198,5.7935,33.1368,1.3,CVn.png,0.148407,3.138407,0.428407,HD112413 -southern,Cir,Circinus,11.4255,-11.6937,-1.3129,1.0,Cir.png,1.448407,-0.391593,-2.211593,HD128898 -northern,Com,Coma Berenices,1.9257,-1.2062,12.2465,1.4,Com.png,3.138407,-0.051593,-2.711593,HD114378 -southern,CrA,Corona Australis,146.1322,-4.7492,-53.7124,1.0,CrA.png,-3.141593,-2.021593,-3.141593,HD178345 -northern,CrB,Corona Borealis,33.5737,32.0314,52.9729,1.3,CrB.png,-3.141593,-0.601593,-2.271593,HD143107 -northern,Cas,Cassiopeia,-36.3073,59.4424,-7.6926,1.4,Cas.png,-1.431593,3.128407,-2.331593,HD3712 -northern,Cep,Cepheus,-2.8178,14.4985,2.3848,1.7,Cep.png,-1.331593,-2.291593,-2.931593,HD203280 -southern,Car,Carina Vela Puppis,14.1325,-188.6018,-42.2785,2.0,Car.png,2.078407,1.048407,-3.111593,HD71129 -northern,Col,Columba,-11.2568,-20.5973,-11.9895,1.0,Col.png,2.518407,1.358407,-2.981593,HD39425 -northern,Per,Perseus,-139.8202,79.8063,-16.2631,1.3,Per.png,-1.751593,2.428407,-2.411593,HD22928 -northern,Oph,Ophiuchus,127.9419,14.0822,56.2015,3.2,Oph.png,2.178407,-0.781593,-1.681593,HD149757 -southern,PsA,Piscis Austrinus,99.9977,47.6679,-199.6345,1.0,PsA.png,3.138407,-2.541593,-2.881593,HD214748 -southern,Cru,Crux,49.3509,-85.0446,-0.6223,1.1,Cru.png,1.718407,0.048407,-2.741593,HD108248 -southern,Pic,Pictor,-4.5417,-45.5649,-27.1768,1.0,Pic.png,2.568407,2.138407,-2.081593,HD39523 diff --git a/data/profiles/default.profile b/data/profiles/default.profile index cedf4ad6d7..d9cd9a8631 100644 --- a/data/profiles/default.profile +++ b/data/profiles/default.profile @@ -1,22 +1,30 @@ -#Version -1.0 - -#Asset -base -scene/solarsystem/planets/earth/earth earthAsset -scene/solarsystem/planets/earth/satellites/satellites - -#Property -setPropertyValue {earth_satellites}.Renderable.Enabled false - -#Time -relative -1d - -#Camera -goToGeo earthAsset.Earth.Identifier 58.5877 16.1924 20000000 - -#MarkNodes -Earth -Mars -Moon -Sun +{ + "version": { + "major": 1, + "minor": 0 + }, + "assets": [ + "base", + "scene/solarsystem/planets/earth/earth", + "scene/solarsystem/planets/earth/satellites/satellites" + ], + "properties": [ + { + "type": "setPropertyValue", + "name": "{earth_satellites}.Renderable.Enabled", + "value": "false" + } + ], + "time": { + "type": "relative", + "value": "-1d" + }, + "camera": { + "type": "goToGeo", + "anchor": "Earth", + "latitude": 58.5877, + "longitude": 16.1924, + "altitude": 20000000 + }, + "mark_nodes": [ "Earth", "Mars", "Moon", "Sun" ] +} diff --git a/ext/ghoul b/ext/ghoul index f568acc5fe..6e9bb084a1 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit f568acc5fee29a5b0c654f183baddcb7a061e7a6 +Subproject commit 6e9bb084a147d85faf7f28980251752d6dae5f98 diff --git a/include/openspace/scene/profile.h b/include/openspace/scene/profile.h index c70df31be3..eccf6a0dd7 100644 --- a/include/openspace/scene/profile.h +++ b/include/openspace/scene/profile.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -40,6 +41,14 @@ namespace scripting { struct LuaLibrary; } class Profile { public: + struct ParsingError : public ghoul::RuntimeError { + enum class Severity { Info, Warning, Error }; + + explicit ParsingError(Severity severity, std::string msg); + + Severity severity; + }; + // Version struct Version { int major = 0; @@ -47,20 +56,16 @@ public: }; struct Module { std::string name; - std::string loadedInstruction; - std::string notLoadedInstruction; + std::optional loadedInstruction; + std::optional notLoadedInstruction; }; struct Meta { - std::string name; - std::string version; - std::string description; - std::string author; - std::string url; - std::string license; - }; - struct Asset { - std::string path; - std::string name; + std::optional name; + std::optional version; + std::optional description; + std::optional author; + std::optional url; + std::optional license; }; struct Property { enum class SetType { @@ -87,13 +92,13 @@ public: }; Type type; - std::string time; + std::string value; }; struct CameraNavState { static constexpr const char* Type = "setNavigationState"; std::string anchor; - std::string aim; + std::optional aim; std::string referenceFrame; glm::dvec3 position; std::optional up; @@ -109,9 +114,9 @@ public: std::optional altitude; }; using CameraType = std::variant; - + Profile() = default; - Profile(const std::vector& content); + explicit Profile(const std::string& content); std::string serialize() const; std::string convertToScene() const; @@ -147,7 +152,7 @@ private: Version version = CurrentVersion; std::vector modules; std::optional meta; - std::vector assets; + std::vector assets; std::vector properties; std::vector keybindings; std::optional