Clean up code and get it to run (using correct data files)

This commit is contained in:
Emma Broman
2020-08-25 16:57:41 +02:00
parent 9fac7fbd83
commit 9e5251630a
11 changed files with 1458 additions and 1547 deletions
+5 -4
View File
@@ -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})
File diff suppressed because it is too large Load Diff
+63 -59
View File
@@ -23,18 +23,16 @@
****************************************************************************************/
#include <modules/exoplanets/exoplanetsmodule.h>
#include <modules/exoplanets/tasks/exoplanetscsvtobintask.h>
#include <modules/exoplanets/rendering/renderableorbitdisc.h>
#include <modules/exoplanets/rendering/renderableorbitdisc.h>
#include <modules/exoplanets/tasks/exoplanetscsvtobintask.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/globalscallbacks.h>
#include <openspace/interaction/navigationhandler.h>
#include <openspace/rendering/renderengine.h>
#include <openspace/scene/scenegraphnode.h>
#include <openspace/scene/scene.h>
#include <openspace/util/factorymanager.h>
#include <openspace/interaction/navigationhandler.h>
#include <thread>
#include <chrono>
@@ -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<Exoplanet> plsy) {
_plsy = plsy;
void ExoplanetsModule::setPlanetSystem(std::vector<Exoplanet> planets) {
_planetSystem = planets;
}
std::vector<Exoplanet> ExoplanetsModule::getPlsy() {
return _plsy;
std::vector<Exoplanet> ExoplanetsModule::planetSystem() {
return _planetSystem;
}
void ExoplanetsModule::setPlna(std::vector<std::string> plna) {
_plna = plna;
void ExoplanetsModule::setPlanetNames(std::vector<std::string> names) {
_planetNames = names;
}
std::vector<std::string> ExoplanetsModule::getPlna() {
return _plna;
std::vector<std::string> 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<ExoplanetsModule>()->getStarName();
std::vector<std::string> planetNames = global::moduleEngine.module<ExoplanetsModule>()->getPlna();
std::vector<std::string> planetNames = global::moduleEngine.module<ExoplanetsModule>()->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<ExoplanetsModule>()->getStarName();
std::vector<std::string> planetNames = global::moduleEngine.module<ExoplanetsModule>()->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<std::string> planetNames = global::moduleEngine.module<ExoplanetsModule>()->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<Exoplanet> planets = global::moduleEngine.module<ExoplanetsModule>()->getPlsy();
float starRadius = planets[0].RSTAR * 6.957E8 * _discoveryMethods->getTransitScaleFactor(); // in m
std::vector<Exoplanet> planets = global::moduleEngine.module<ExoplanetsModule>()->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<float>(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);
}
});
+12 -14
View File
@@ -25,12 +25,9 @@
#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__
#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__
#include <openspace/util/openspacemodule.h>
#include <openspace/documentation/documentation.h>
#include <modules/exoplanets/discoverymethods/discoverymethods.h>
#include <openspace/documentation/documentation.h>
#include <openspace/util/openspacemodule.h>
namespace openspace {
struct Exoplanet {
@@ -90,16 +87,17 @@ public:
std::vector<documentation::Documentation> documentations() const override;
void setClosestExoplanet(Exoplanet);
Exoplanet getClosestExoplanet();
void setStarName(std::string);
std::string getStarName();
void setPlsy(std::vector<Exoplanet>);
std::vector<Exoplanet> getPlsy();
void setPlna(std::vector<std::string>);
std::vector<std::string> getPlna();
void setPlanetSystem(std::vector<Exoplanet>);
void setPlanetNames(std::vector<std::string>);
void setRotation(glm::dmat3);
glm::dmat3 getRotation();
void setNorthVector(glm::dvec3);
Exoplanet closestExoplanet();
std::string getStarName();
std::vector<Exoplanet> planetSystem();
std::vector<std::string> planetNames();
glm::dmat3 getRotation();
glm::dvec3 getNorthVector();
protected:
@@ -108,8 +106,8 @@ protected:
Exoplanet _exo;
std::string _starName;
std::vector<Exoplanet> _plsy;
std::vector<std::string> _plna;
std::vector<Exoplanet> _planetSystem;
std::vector<std::string> _planetNames;
glm::dmat3 _rotation;
glm::dvec3 _north;
};
+338 -375
View File
@@ -22,37 +22,29 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/engine/moduleengine.h>
#include <openspace/util/spicemanager.h>
#include <openspace/engine/globals.h>
#include <openspace/engine/moduleengine.h>
#include <openspace/scripting/scriptengine.h>
#include <openspace/util/spicemanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/glm.h>
#include <ghoul/misc/assert.h>
#include <glm/gtx/transform.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include <glm/gtx/transform.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
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<ExoplanetsModule>()->setStarName(starname_speck);
global::moduleEngine.module<ExoplanetsModule>()->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<Exoplanet> plsy;
std::vector<std::string> plna;
std::vector<Exoplanet> planetSystem;
std::vector<std::string> 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<ExoplanetsModule>()->setPlna(plna);
global::moduleEngine.module<ExoplanetsModule>()->setPlsy(plsy);
global::moduleEngine.module<ExoplanetsModule>()->setPlanetNames(planetNames);
global::moduleEngine.module<ExoplanetsModule>()->setPlanetSystem(planetSystem);
global::moduleEngine.module<ExoplanetsModule>()->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<ExoplanetsModule>()->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<ExoplanetsModule>()->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<ExoplanetsModule>()->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<ExoplanetsModule>()->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
@@ -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<float>(
dictionary.value<double>(TransparencyInfo.identifier)
);
}
addProperty(_transparency);
_eccentricity = static_cast<float>(dictionary.value<double>(EccentricityInfo.identifier));
_eccentricity = static_cast<float>(
dictionary.value<double>(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() {
@@ -25,13 +25,11 @@
#ifndef __OPENSPACE_MODULE_EXOPLENETS___RENDERABLEORBITDISC___H__
#define __OPENSPACE_MODULE_EXOPLANETS___RENDERABLEORBITDISC___H__
#include <openspace/rendering/renderable.h>
#include <openspace/properties/stringproperty.h>
#include <openspace/properties/scalar/floatproperty.h>
#include <openspace/properties/vector/vec2property.h>
#include <openspace/rendering/renderable.h>
#include <openspace/util/updatestructures.h>
#include <ghoul/opengl/uniformcache.h>
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<ghoul::opengl::ProgramObject> _shader;
UniformCache(modelViewProjection, textureOffset, transparency,
UniformCache(modelViewProjection, textureOffset, opacity,
texture, eccentricity, semiMajorAxis) _uniformCache;
std::unique_ptr<ghoul::opengl::Texture> _texture;
std::unique_ptr<ghoul::filesystem::File> _textureFile;
bool _textureIsDirty;
bool _planeIsDirty;
GLuint _quad;
GLuint _vertexPositionBuffer;
bool _planeIsDirty;
};
} // namespace openspace
+18 -35
View File
@@ -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;
}
+1 -3
View File
@@ -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;
}
File diff suppressed because it is too large Load Diff
@@ -25,13 +25,11 @@
#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__
#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSCSVTOBINTASK___H__
#include <openspace/util/task.h>
#include <openspace/properties/vector/vec3property.h>
#include <openspace/util/task.h>
#include <string>
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__