From 08e5c42d24110833623996d8f7c2ed5a33dcfb04 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 28 Aug 2020 08:29:18 +0200 Subject: [PATCH] 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 + "',"