Start of discovery method visualization components

This commit is contained in:
KarRei
2018-06-04 13:18:45 -04:00
parent 3defbe6f7f
commit 33f8d30bde
5 changed files with 287 additions and 106 deletions

View File

@@ -28,7 +28,10 @@
#include <openspace/documentation/documentation.h>
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/scene/scenegraphnode.h>
namespace {
constexpr const char* _loggerCat = "DiscoveryMethods";
@@ -48,6 +51,70 @@ namespace {
namespace openspace::exoplanets{
void DiscoveryMethods::addTransitMethodVisualization() {
LINFO("addTransit");
std::string starName = OsEng.moduleEngine().module<ExoplanetsModule>()->getStarName();
scaleStar(starName, 1.5);
moveCamera();
}
void DiscoveryMethods::removeTransitMethodVisualization() {
std::string starName = OsEng.moduleEngine().module<ExoplanetsModule>()->getStarName();
scaleStar(starName, 1.0);
}
void DiscoveryMethods::addDopplerMethodVisualization() {
std::string starName = OsEng.moduleEngine().module<ExoplanetsModule>()->getStarName();
float planetSemiMajorAxis = (OsEng.moduleEngine().module<ExoplanetsModule>()->getClosestExoplanet()).A;
float starSemiMajorAxis = 0.1 * planetSemiMajorAxis * 149597871; // 10% of exoplanets semiMajorAxis (get value from em)
moveStar(starName, starSemiMajorAxis);
}
void DiscoveryMethods::removeDopplerMethodVisualization() {
}
void DiscoveryMethods::scaleStar(std::string starName, float scalefactor) {
std::string script = "openspace.setPropertyValue( 'Scene."+starName+"Globe.Scale.Scale', " + std::to_string(scalefactor) + ", 1, 'single', 'linear');"; //get name of current star from em
OsEng.scriptEngine().queueScript(
script,
openspace::scripting::ScriptEngine::RemoteScripting::Yes
);
}
void DiscoveryMethods::moveStar(std::string starName, float semiMajorAxis) {
std::string script = "openspace.setPropertyValueSingle( 'Scene."+starName+"Globe.Translation.SemiMajorAxis', " + std::to_string(semiMajorAxis) + ", 1); "; //get name of current star from em
script += "openspace.setPropertyValueSingle( 'Scene." + starName + "Globe.Translation.MeanAnomaly', 180, 1);"; //get name of current star from em
OsEng.scriptEngine().queueScript(
script,
openspace::scripting::ScriptEngine::RemoteScripting::Yes
);
}
void DiscoveryMethods::moveCamera() {
//glm::dvec3 originalPosition = _camera->positionVec3();
Camera* cam = OsEng.navigationHandler().camera();
glm::dvec3 originalPosition = cam->positionVec3();
SceneGraphNode* focusNode = OsEng.navigationHandler().focusNode();
std::string id = focusNode->identifier();
glm::dvec3 starPosition = focusNode->worldPosition();
// get the vector between star and the sun
glm::dvec3 starToSunVec = normalize(glm::dvec3(0.0, 0.0, 0.0) - starPosition);
// a position along that vector (twice the semimajor axis away from the sun)
float semiMajorAxis = (OsEng.moduleEngine().module<ExoplanetsModule>()->getClosestExoplanet()).A;
glm::dvec3 newCameraPosition = starPosition + ((3.0 * semiMajorAxis * 149597870700) * starToSunVec);
//move camera to that pos
cam->setPositionVec3(newCameraPosition);
OsEng.navigationHandler().resetCameraDirection();
}
DiscoveryMethods::DiscoveryMethods()
: PropertyOwner({ "DiscoveryMethods" })
, _showTransit(TransitMethodInfo, false)
@@ -55,8 +122,39 @@ namespace openspace::exoplanets{
{
addProperty(_showTransit);
addProperty(_showDoppler);
_showTransit.onChange([&]() { LINFO("transit"); });
_showDoppler.onChange([&]() { LINFO("doppler"); });
_showTransit.onChange([&]() {
if (_showTransit) //just changed to true
{
if (_showDoppler) //only one viz at the time
{
_showDoppler = false;
removeDopplerMethodVisualization();
}
addTransitMethodVisualization();
}
else //just changed to false
{
removeTransitMethodVisualization();
}
});
_showDoppler.onChange([&]() {
if (_showDoppler) //just changed to true
{
if (_showTransit)
{
_showTransit = false;
removeTransitMethodVisualization();
}
addDopplerMethodVisualization();
}
else //just changed to false
{
removeDopplerMethodVisualization();
}
});
}
} // namespce

View File

@@ -39,6 +39,15 @@ private:
properties::BoolProperty _showTransit;
properties::BoolProperty _showDoppler;
void addTransitMethodVisualization();
void removeTransitMethodVisualization();
void addDopplerMethodVisualization();
void removeDopplerMethodVisualization();
void scaleStar(std::string, float);
void moveStar(std::string, float);
void moveCamera();
};
} // namespace

View File

@@ -38,6 +38,22 @@ using namespace exoplanets;
ExoplanetsModule::ExoplanetsModule() : OpenSpaceModule(Name) {}
void ExoplanetsModule::setClosestExoplanet(Exoplanet closestExo) {
_exo = closestExo;
}
Exoplanet ExoplanetsModule::getClosestExoplanet() {
return _exo;
}
void ExoplanetsModule::setStarName(std::string starName) {
_starName = starName;
}
std::string ExoplanetsModule::getStarName() {
return _starName;
}
scripting::LuaLibrary ExoplanetsModule::luaLibrary() const {
scripting::LuaLibrary res;
@@ -64,7 +80,7 @@ scripting::LuaLibrary ExoplanetsModule::luaLibrary() const {
}
void ExoplanetsModule::internalInitialize(const ghoul::Dictionary&) {
auto fTask = FactoryManager::ref().factory<Task>();
auto fRenderable = FactoryManager::ref().factory<Renderable>();
ghoul_assert(fTask, "No task factory existed");

View File

@@ -33,6 +33,50 @@
#include <modules/exoplanets/discoverymethods/discoverymethods.h>
namespace openspace {
struct Exoplanet {
float A;
double AUPPER;
double ALOWER;
double UA;
float BIGOM;
float BIGOMUPPER;
float BIGOMLOWER;
float UBIGOM;
bool BINARY;
float BMV;
float ECC;
float ECCUPPER;
float ECCLOWER;
float UECC;
float I;
float IUPPER;
float ILOWER;
float UI;
int NCOMP;
float OM;
float OMUPPER;
float OMLOWER;
float UOM;
double PER;
float PERUPPER;
float PERLOWER;
float UPER;
double R;
double RUPPER;
double RLOWER;
double UR;
float RSTAR;
float RSTARUPPER;
float RSTARLOWER;
float URSTAR;
double TT;
float TTUPPER;
float TTLOWER;
float UTT;
float POSITIONX;
float POSITIONY;
float POSITIONZ;
};
class ExoplanetsModule : public OpenSpaceModule {
public:
@@ -45,10 +89,17 @@ public:
std::vector<documentation::Documentation> documentations() const override;
void setClosestExoplanet(Exoplanet);
Exoplanet getClosestExoplanet();
void setStarName(std::string);
std::string getStarName();
protected:
void internalInitialize(const ghoul::Dictionary&) override;
std::unique_ptr<openspace::exoplanets::DiscoveryMethods> _discoveryMethods;
Exoplanet _exo;
std::string _starName;
};
} // namespace openspace

View File

@@ -23,6 +23,7 @@
****************************************************************************************/
#include <openspace/engine/openspaceengine.h>
#include <openspace/engine/moduleengine.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/glm.h>
@@ -32,51 +33,6 @@
namespace openspace{
struct Exoplanet {
float A;
double AUPPER;
double ALOWER;
double UA;
float BIGOM;
float BIGOMUPPER;
float BIGOMLOWER;
float UBIGOM;
bool BINARY;
float BMV;
float ECC;
float ECCUPPER;
float ECCLOWER;
float UECC;
float I;
float IUPPER;
float ILOWER;
float UI;
int NCOMP;
float OM;
float OMUPPER;
float OMLOWER;
float UOM;
double PER;
float PERUPPER;
float PERLOWER;
float UPER;
double R;
double RUPPER;
double RLOWER;
double UR;
float RSTAR;
float RSTARUPPER;
float RSTARLOWER;
float URSTAR;
double TT;
float TTUPPER;
float TTLOWER;
float UTT;
float POSITIONX;
float POSITIONY;
float POSITIONZ;
};
std::string getStarColor(float bv) {
std::string colorString;
@@ -224,6 +180,8 @@ int addExoplanetSystem(lua_State* L) {
const int StringLocation = -1;
const std::string starname = luaL_checkstring(L, StringLocation);
OsEng.moduleEngine().module<ExoplanetsModule>()->setStarName(starname);
//change expl-starname to exoplanet.csv-starname
std::string starname_csv = getCsvStarname(starname);
@@ -269,6 +227,7 @@ int addExoplanetSystem(lua_State* L) {
data.close();
lut.close();
OsEng.moduleEngine().module<ExoplanetsModule>()->setClosestExoplanet(p);
if (found && !isnan(p.POSITIONX) && !isnan(p.A) && !isnan(p.PER)) //&& !p.BINARY
{
@@ -280,65 +239,113 @@ int addExoplanetSystem(lua_State* L) {
"Identifier = '" + starname + "',"
"Parent = 'SolarSystemBarycenter',"
"Transform = {"
"Translation = {"
"Type = 'StaticTranslation',"
"Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}"
"Translation = {"
"Type = 'StaticTranslation',"
"Position = {" + std::to_string(p.POSITIONX * parsec) + ", " + std::to_string(p.POSITIONY * parsec) + ", " + std::to_string(p.POSITIONZ * parsec) + "}"
"}"
"}"
"}"
"}";
"}";
script = "openspace.addSceneGraphNode(" + starParent + ");";
if (!isnan(p.RSTAR))
{
std::string color = getStarColor(p.BMV);
if (isnan(p.ECC))
{
p.ECC = 0;
}
if (isnan(p.I))
{
p.I = 90;
}
if (isnan(p.BIGOM))
{
p.BIGOM = 0;
}
if (isnan(p.OM))
{
p.OM = 90;
}
std::string sepoch_star;
if (!isnan(p.TT)) {
epoch.setTime("JD " + std::to_string(p.TT));
sepoch_star = epoch.ISO8601();
}
else
sepoch_star = "2009-05-19T07:11:34.080";
const std::string starGlobe = "{"
"Identifier = '" + starname + "Globe',"
"Parent = '" + starname + "',"
"Renderable = {"
"Type = 'RenderableGlobe',"
"Radii = " + std::to_string(p.RSTAR) + " * 6.957E8,"
"SegmentsPerPatch = 64,"
"PerformShading = false,"
"Layers = {"
"ColorLayers = {"
"{"
"Identifier = 'StarColor',"
"Type = 'SolidColor',"
"Color = " + color + ","
"BlendMode = 'Normal',"
"Enabled = true"
"Type = 'RenderableGlobe',"
"Radii = " + std::to_string(p.RSTAR) + " * 6.957E8,"
"SegmentsPerPatch = 64,"
"PerformShading = false,"
"Layers = {"
"ColorLayers = {"
"{"
"Identifier = 'StarColor',"
"Type = 'SolidColor',"
"Color = " + color + ","
"BlendMode = 'Normal',"
"Enabled = true"
"},"
"{"
"Identifier = 'StarTexture',"
"FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"
"BlendMode = 'Color',"
"Enabled = true"
"}"
"}"
"}"
"},"
"{"
"Identifier = 'StarTexture',"
"FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/sun.jpg',"
"BlendMode = 'Color',"
"Enabled = true"
"Transform = {"
"Scale = {"
"Type = 'StaticScale',"
"Scale = 1.0,"
"},"
"Translation = {"
"Type = 'KeplerTranslation',"
"Eccentricity = " + std::to_string(p.ECC) + "," //ECC
"SemiMajorAxis = 0," // 149 597 871km = 1 AU. A
"Inclination = " + std::to_string(p.I) + "," //I
"AscendingNode = " + std::to_string(p.BIGOM) + "," //BIGOM
"ArgumentOfPeriapsis = " + std::to_string(p.OM) + "," //OM
"MeanAnomaly = 0.0,"
"Epoch = '" + sepoch_star + "'," //TT. JD to YYYY MM DD hh:mm:ss
"Period = " + std::to_string(p.PER) + "* 86400" //PER. 86 400sec = 1 day.
"}"
"}"
"}"
"}"
"},"
"}";
"}";
script += " openspace.addSceneGraphNode(" + starGlobe + ");";
OsEng.scriptEngine().queueScript(
script,
openspace::scripting::ScriptEngine::RemoteScripting::Yes
);
script = "";
const std::string starGlare = "{"
"Identifier = '" + starname + "Glare',"
"Parent = '" + starname + "',"
"Renderable = {"
"Type = 'RenderablePlaneImageLocal',"
"Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m
"Size = " + std::to_string(p.RSTAR) + " * 5E9," //RSTAR. in meters. 1 solar radii = 6.95700×10e8 m
"Billboard = true,"
"Texture = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/halo.png',"
"BlendMode = 'Additive'"
"}"
"}";
script += "openspace.addSceneGraphNode(" + starGlare + "); openspace.addSceneGraphNode(" + starGlobe + ");";
script = "openspace.addSceneGraphNode(" + starGlare + ");";
//OsEng.scriptEngine().queueScript(
// script,
// openspace::scripting::ScriptEngine::RemoteScripting::Yes
// );
}
OsEng.scriptEngine().queueScript(
script,
openspace::scripting::ScriptEngine::RemoteScripting::Yes
);
for (size_t i = 0; i < plsy.size(); i++)
@@ -375,34 +382,34 @@ int addExoplanetSystem(lua_State* L) {
"Identifier = '" + plna[i] + "',"
"Parent = '" + starname + "',"
"Renderable = {"
"Type = 'RenderableGlobe',"
"Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m
"SegmentsPerPatch = 64,"
"PerformShading = false,"
"Layers = {"
"ColorLayers = {"
"{"
"Identifier = 'ExoplanetTexture',"
"FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg',"
"Enabled = true"
"}"
"}"
"}"
"Type = 'RenderableGlobe',"
"Radii = " + std::to_string(plsy[i].R) + " *7.1492E7," //R. in meters. 1 jupiter radii = 7.1492×10e7 m
"SegmentsPerPatch = 64,"
"PerformShading = false,"
"Layers = {"
"ColorLayers = {"
"{"
"Identifier = 'ExoplanetTexture',"
"FilePath = 'C:/Users/Karin/Documents/OpenSpace/modules/exoplanets/test3.jpg',"
"Enabled = true"
"}"
"}"
"}"
"},"
"Transform = {"
"Translation = {"
"Type = 'KeplerTranslation',"
"Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC
"SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A
"Inclination = " + std::to_string(plsy[i].I) + "," //I
"AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM
"ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM
"MeanAnomaly = 0.0,"
"Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss
"Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day.
"}"
"Translation = {"
"Type = 'KeplerTranslation',"
"Eccentricity = " + std::to_string(plsy[i].ECC) + "," //ECC
"SemiMajorAxis = " + std::to_string(plsy[i].A) + " * 149597871," // 149 597 871km = 1 AU. A
"Inclination = " + std::to_string(plsy[i].I) + "," //I
"AscendingNode = " + std::to_string(plsy[i].BIGOM) + "," //BIGOM
"ArgumentOfPeriapsis = " + std::to_string(plsy[i].OM) + "," //OM
"MeanAnomaly = 0.0,"
"Epoch = '" + sepoch + "'," //TT. JD to YYYY MM DD hh:mm:ss
"Period = " + std::to_string(plsy[i].PER) + "* 86400" //PER. 86 400sec = 1 day.
"}"
"},"
"}";
"}";
script = "openspace.addSceneGraphNode(" + planet + ");";
OsEng.scriptEngine().queueScript(
@@ -559,4 +566,4 @@ int removeExoplanetSystem(lua_State* L) {
return 0;
}
} //namespace
} //namespace