From 33f8d30bde46fb8e6fdc992ed76ac3fdbb0d0aa8 Mon Sep 17 00:00:00 2001 From: KarRei Date: Mon, 4 Jun 2018 13:18:45 -0400 Subject: [PATCH] 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