From 9e5251630aff80ea12f0ee01e58305e867e29241 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Tue, 25 Aug 2020 16:57:41 +0200 Subject: [PATCH] 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__