mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-05 11:09:37 -06:00
Cleanup
This commit is contained in:
@@ -33,14 +33,14 @@
|
||||
#include <openspace/scene/scenegraphnode.h>
|
||||
#include <openspace/scene/scene.h>
|
||||
#include <openspace/util/factorymanager.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "exoplanetsmodule_lua.inl"
|
||||
|
||||
namespace openspace {
|
||||
|
||||
const char* _loggerCat = "exoplanets";
|
||||
constexpr const char* _loggerCat = "exoplanets";
|
||||
|
||||
using namespace exoplanets;
|
||||
|
||||
|
||||
@@ -25,9 +25,10 @@
|
||||
#ifndef __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__
|
||||
#define __OPENSPACE_MODULE_EXOPLANETS___EXOPLANETSMODULE___H__
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
#include <openspace/util/openspacemodule.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
class ExoplanetsModule : public OpenSpaceModule {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <openspace/util/timeconversion.h>
|
||||
#include <openspace/util/timemanager.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/fmt.h>
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/assert.h>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
@@ -54,7 +55,7 @@ constexpr const char* DiscTextureFile =
|
||||
|
||||
constexpr const char* BvColormapPath = "${SYNC}/http/stars_colormap/2/colorbv.cmap";
|
||||
|
||||
std::string getStarColor(float bv, std::ifstream& colormap) {
|
||||
std::string starColor(float bv, std::ifstream& colormap) {
|
||||
const int t = round(((bv + 0.4) / (2.0 + 0.4)) * 255);
|
||||
std::string color;
|
||||
for (int i = 0; i < t + 12; i++) {
|
||||
@@ -68,7 +69,7 @@ std::string getStarColor(float bv, std::ifstream& colormap) {
|
||||
getline(colorStream, g, ' ');
|
||||
getline(colorStream, b, ' ');
|
||||
|
||||
return "{" + r + ", " + g + ", " + b + "}";
|
||||
return fmt::format("{{ {}, {}, {} }}", r, g, b);
|
||||
}
|
||||
|
||||
glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) {
|
||||
@@ -91,8 +92,9 @@ glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom, float om) {
|
||||
|
||||
// Rotate the original coordinate system (where x is pointing to First Point of Aries)
|
||||
// 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) {
|
||||
// Modified from "http://www.opengl-tutorial.org/intermediate-tutorials/
|
||||
// tutorial-17-quaternions/ #how-do-i-find-the-rotation-between-2-vectors"
|
||||
glm::dmat3 exoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) {
|
||||
glm::quat rotationQuat;
|
||||
glm::dvec3 rotationAxis;
|
||||
const float cosTheta = dot(start, end);
|
||||
@@ -103,8 +105,10 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) {
|
||||
// there is no "ideal" rotation axis
|
||||
// So guess one; any will do as long as it's perpendicular to start vector
|
||||
rotationAxis = cross(glm::dvec3(0.0, 0.0, 1.0), start);
|
||||
if (length2(rotationAxis) < 0.01f) // bad luck, they were parallel, try again!
|
||||
if (length2(rotationAxis) < 0.01f) {
|
||||
// bad luck, they were parallel, try again!
|
||||
rotationAxis = cross(glm::dvec3(1.0, 0.0, 0.0), start);
|
||||
}
|
||||
|
||||
rotationAxis = normalize(rotationAxis);
|
||||
rotationQuat = glm::quat(glm::radians(180.f), rotationAxis);
|
||||
@@ -127,10 +131,9 @@ glm::dmat3 getExoplanetSystemRotation(glm::dvec3 start, glm::dvec3 end) {
|
||||
}
|
||||
|
||||
// Create an identifier without whitespaces
|
||||
std::string createIdentifier(const std::string& name) {
|
||||
std::string res = name;
|
||||
std::replace(res.begin(), res.end(), ' ', '_');
|
||||
return res;
|
||||
std::string createIdentifier(std::string name) {
|
||||
std::replace(name.begin(), name.end(), ' ', '_');
|
||||
return name;
|
||||
}
|
||||
|
||||
int addExoplanetSystem(lua_State* L) {
|
||||
@@ -164,9 +167,9 @@ int addExoplanetSystem(lua_State* L) {
|
||||
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.
|
||||
// 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.
|
||||
Exoplanet p;
|
||||
std::string line;
|
||||
bool found = false;
|
||||
@@ -185,7 +188,7 @@ int addExoplanetSystem(lua_State* L) {
|
||||
long location = std::stol(location_s.c_str());
|
||||
|
||||
data.seekg(location);
|
||||
data.read((char*)&p, sizeof(Exoplanet));
|
||||
data.read(reinterpret_cast<char*>(&p), sizeof(Exoplanet));
|
||||
|
||||
planetNames.push_back(name);
|
||||
planetSystem.push_back(p);
|
||||
@@ -198,7 +201,7 @@ int addExoplanetSystem(lua_State* L) {
|
||||
|
||||
bool notEnoughData = isnan(p.POSITIONX) || isnan(p.A) || isnan(p.PER);
|
||||
|
||||
if (!found || notEnoughData) {
|
||||
if (!found || notEnoughData) {
|
||||
return ghoul::lua::luaError(
|
||||
L,
|
||||
"No star with that name or not enough data about it."
|
||||
@@ -206,7 +209,7 @@ int addExoplanetSystem(lua_State* L) {
|
||||
}
|
||||
|
||||
const glm::dvec3 starPosition = glm::dvec3(
|
||||
p.POSITIONX * distanceconstants::Parsec,
|
||||
p.POSITIONX * distanceconstants::Parsec,
|
||||
p.POSITIONY * distanceconstants::Parsec,
|
||||
p.POSITIONZ * distanceconstants::Parsec
|
||||
);
|
||||
@@ -232,19 +235,19 @@ int addExoplanetSystem(lua_State* L) {
|
||||
const glm::dvec3 beta = glm::normalize(glm::cross(starToSunVec, northProjected));
|
||||
|
||||
const glm::dmat3 exoplanetSystemRotation = glm::dmat3(
|
||||
northProjected.x,
|
||||
northProjected.y,
|
||||
northProjected.x,
|
||||
northProjected.y,
|
||||
northProjected.z,
|
||||
beta.x,
|
||||
beta.y,
|
||||
beta.x,
|
||||
beta.y,
|
||||
beta.z,
|
||||
starToSunVec.x,
|
||||
starToSunVec.y,
|
||||
starToSunVec.x,
|
||||
starToSunVec.y,
|
||||
starToSunVec.z
|
||||
);
|
||||
|
||||
// Star renderable globe, if we have a radius
|
||||
std::string starGlobeRenderableString = "";
|
||||
std::string starGlobeRenderableString;
|
||||
const float starRadius = p.RSTAR;
|
||||
if (!isnan(starRadius)) {
|
||||
std::ifstream colorMap(absPath(BvColormapPath), std::ios::in);
|
||||
@@ -253,7 +256,7 @@ int addExoplanetSystem(lua_State* L) {
|
||||
ghoul::lua::luaError(L, "Failed to open colormap data file");
|
||||
}
|
||||
|
||||
const std::string color = getStarColor(p.BMV, colorMap);
|
||||
const std::string color = starColor(p.BMV, colorMap);
|
||||
const float radiusInMeter = starRadius * distanceconstants::SolarRadius;
|
||||
|
||||
starGlobeRenderableString = "Renderable = {"
|
||||
@@ -327,14 +330,14 @@ int addExoplanetSystem(lua_State* L) {
|
||||
std::string sEpoch;
|
||||
if (!isnan(planet.TT)) {
|
||||
epoch.setTime("JD " + std::to_string(planet.TT));
|
||||
sEpoch = std::string(epoch.ISO8601());
|
||||
sEpoch = std::string(epoch.ISO8601());
|
||||
}
|
||||
else {
|
||||
sEpoch = "2009-05-19T07:11:34.080";
|
||||
}
|
||||
|
||||
float planetRadius;
|
||||
std::string enabled = "";
|
||||
std::string enabled;
|
||||
|
||||
if (isnan(planet.R)) {
|
||||
if (isnan(planet.RSTAR)) {
|
||||
@@ -375,7 +378,7 @@ int addExoplanetSystem(lua_State* L) {
|
||||
"Renderable = {"
|
||||
"Type = 'RenderableGlobe',"
|
||||
"Enabled = " + enabled + ","
|
||||
"Radii = " + std::to_string(planetRadius) + "," //R. in meters.
|
||||
"Radii = " + std::to_string(planetRadius) + "," //R. in meters.
|
||||
"SegmentsPerPatch = 64,"
|
||||
"PerformShading = false,"
|
||||
"Layers = {}"
|
||||
@@ -419,13 +422,12 @@ int addExoplanetSystem(lua_State* L) {
|
||||
bool hasUpperAUncertainty = !isnan(planet.AUPPER);
|
||||
bool hasLowerAUncertainty = !isnan(planet.ALOWER);
|
||||
|
||||
if (hasUpperAUncertainty && hasLowerAUncertainty)
|
||||
{
|
||||
if (hasUpperAUncertainty && hasLowerAUncertainty) {
|
||||
// Get the orbit plane of the planet trail orbit from the KeplerTranslation
|
||||
const glm::dmat4 orbitPlaneRotationMatrix = computeOrbitPlaneRotationMatrix(
|
||||
planet.I,
|
||||
planet.BIGOM,
|
||||
planet.OM
|
||||
planet.I,
|
||||
planet.BIGOM,
|
||||
planet.OM
|
||||
);
|
||||
const glm::dmat3 rotation = orbitPlaneRotationMatrix;
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ namespace {
|
||||
static const openspace::properties::Property::PropertyInfo EccentricityInfo = {
|
||||
"Eccentricity",
|
||||
"Eccentricity",
|
||||
"This value determines the eccentricity, that is the deviation from a perfect sphere, for this orbit."
|
||||
"This value determines the eccentricity, that is the deviation from a perfect "
|
||||
"sphere, for this orbit."
|
||||
};
|
||||
|
||||
static const openspace::properties::Property::PropertyInfo OffsetInfo = {
|
||||
|
||||
@@ -35,10 +35,10 @@
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
const char* KeyInputCsv = "InputCSV";
|
||||
const char* KeyInputSpeck = "InputSPECK";
|
||||
const char* KeyOutputBin = "OutputBIN";
|
||||
const char* KeyOutputLut = "OutputLUT";
|
||||
constexpr const char* KeyInputCsv = "InputCSV";
|
||||
constexpr const char* KeyInputSpeck = "InputSPECK";
|
||||
constexpr const char* KeyOutputBin = "OutputBIN";
|
||||
constexpr const char* KeyOutputLut = "OutputLUT";
|
||||
|
||||
constexpr const char* _loggerCat = "CsvToBinTask";
|
||||
|
||||
@@ -65,7 +65,7 @@ std::string ExoplanetsCsvToBinTask::description() {
|
||||
" and write as bin to " + _outputBinPath;
|
||||
}
|
||||
|
||||
glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) {
|
||||
glm::vec3 ExoplanetsCsvToBinTask::starPosition(const std::string& starName) {
|
||||
glm::vec3 position;
|
||||
position[0] = NAN;
|
||||
position[1] = NAN;
|
||||
@@ -76,23 +76,26 @@ glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) {
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::string d;
|
||||
std::string n;
|
||||
while (getline(exoplanetsFile, line))
|
||||
{
|
||||
if (line[0] == '#' || line.substr(0, 7) == "datavar" || line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture" || line.empty()) {
|
||||
std::string data; // data
|
||||
std::string name;
|
||||
while (getline(exoplanetsFile, line)) {
|
||||
bool shouldSkipLine = (
|
||||
line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" ||
|
||||
line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture"
|
||||
);
|
||||
|
||||
if (shouldSkipLine) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::istringstream linestream(line);
|
||||
getline(linestream, d, '#');
|
||||
getline(linestream, n);
|
||||
n.erase(0, 1);
|
||||
getline(linestream, data, '#');
|
||||
getline(linestream, name);
|
||||
name.erase(0, 1);
|
||||
|
||||
std::string coord;
|
||||
if (n.compare(starName) == 0)
|
||||
{
|
||||
std::stringstream dataStream(d);
|
||||
if (name == starName) {
|
||||
std::stringstream dataStream(data);
|
||||
getline(dataStream, coord, ' ');
|
||||
position[0] = std::stof(coord.c_str(), nullptr);
|
||||
getline(dataStream, coord, ' ');
|
||||
@@ -109,7 +112,6 @@ glm::vec3 ExoplanetsCsvToBinTask::getStarPosition(std::string starName) {
|
||||
_transformationMatrix * glm::dvec4(position, 1.0)
|
||||
);
|
||||
|
||||
exoplanetsFile.close();
|
||||
return transformedPosition;
|
||||
}
|
||||
|
||||
@@ -124,7 +126,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
|
||||
std::ofstream lutFile(_outputLutPath);
|
||||
|
||||
int version = 1;
|
||||
binFile.write((char *)&version, sizeof(int));
|
||||
binFile.write(reinterpret_cast<char*>(&version), sizeof(int));
|
||||
|
||||
Exoplanet p;
|
||||
|
||||
@@ -590,7 +592,7 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
|
||||
getline(lineStream, data, ','); // SPECURL
|
||||
getline(lineStream, data, ','); // STAR
|
||||
std::string speckStarname = speckStarName(data);
|
||||
glm::vec3 position = getStarPosition(speckStarname);
|
||||
glm::vec3 position = starPosition(speckStarname);
|
||||
p.POSITIONX = position[0];
|
||||
p.POSITIONY = position[1];
|
||||
p.POSITIONZ = position[2];
|
||||
@@ -719,15 +721,11 @@ void ExoplanetsCsvToBinTask::perform(const Task::ProgressCallback& progressCallb
|
||||
long pos = binFile.tellp();
|
||||
planetName = speckStarname + " " + component;
|
||||
lutFile << planetName << "," << pos << std::endl;
|
||||
binFile.write((char *)&p, sizeof(Exoplanet));
|
||||
binFile.write(reinterpret_cast<char*>(&p), sizeof(Exoplanet));
|
||||
}
|
||||
}
|
||||
|
||||
csvFile.close();
|
||||
binFile.close();
|
||||
lutFile.close();
|
||||
|
||||
progressCallback(1.0f);
|
||||
progressCallback(1.f);
|
||||
}
|
||||
|
||||
documentation::Documentation ExoplanetsCsvToBinTask::documentation() {
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
std::string _outputBinPath;
|
||||
std::string _outputLutPath;
|
||||
|
||||
glm::vec3 getStarPosition(std::string starName);
|
||||
glm::vec3 starPosition(const std::string& starName);
|
||||
};
|
||||
|
||||
} // namespace openspace::exoplanets
|
||||
|
||||
Reference in New Issue
Block a user