Address review comments

This commit is contained in:
Emma Broman
2020-12-18 11:39:33 +01:00
parent a79363fdd8
commit 4370b26a68
6 changed files with 53 additions and 60 deletions
+7 -4
View File
@@ -143,19 +143,22 @@ glm::vec2 computeHabitableZone(float teff, float luminosity) {
if (teff > 8000.f || teff < 2000.f) {
// For the other stars, use a method by Tom E. Morris:
// https://www.planetarybiology.com/calculating_habitable_zone.html
float inner = sqrtf(luminosity / 1.1f);
float outer = sqrtf(luminosity / 0.53f);
float inner = std::sqrt(luminosity / 1.1f);
float outer = std::sqrt(luminosity / 0.53f);
return glm::vec2(inner, outer);
}
struct Coefficients {
float seffSun;
float a, b, c, d;
float a;
float b;
float c;
float d;
};
// Coefficients for planets of 1 Earth mass. Received from:
// https://depts.washington.edu/naivpl/sites/default/files/HZ_coefficients.dat
constexpr Coefficients coefficients[] = {
constexpr const Coefficients coefficients[] = {
// Inner boundary - Runaway greenhouse
{1.10700E+00f, 1.33200E-04f, 1.58000E-08f, -8.30800E-12f, -1.93100E-15f},
// Outer boundary - Maximum greenhouse
+5 -5
View File
@@ -80,10 +80,10 @@ struct ExoplanetDataEntry {
struct StarData {
glm::vec3 position = glm::vec3(std::numeric_limits<float>::quiet_NaN()); // In parsec
float radius = std::numeric_limits<float>::quiet_NaN(); // In solar radii
float bv = std::numeric_limits<float>::quiet_NaN();
float teff = std::numeric_limits<float>::quiet_NaN(); // In Kelvin
float luminosity = std::numeric_limits<float>::quiet_NaN(); // In solar luminosities
float radius = std::numeric_limits<float>::quiet_NaN(); // In solar radii
float bv = std::numeric_limits<float>::quiet_NaN();
float teff = std::numeric_limits<float>::quiet_NaN(); // In Kelvin
float luminosity = std::numeric_limits<float>::quiet_NaN(); // In solar luminosities
};
struct ExoplanetSystem {
@@ -102,7 +102,7 @@ bool hasSufficientData(const ExoplanetDataEntry& p);
glm::vec3 starColor(float bv);
glm::dmat4 computeOrbitPlaneRotationMatrix(float i, float bigom = 180.f,
float omega = 90.f);
float omega = 90.f);
// Rotate the original coordinate system (where x is pointing to First Point of Aries)
// so that x is pointing from star to the sun.
+11 -15
View File
@@ -56,9 +56,9 @@ constexpr const char* NoDataTextureFile =
constexpr const char* DiscTextureFile =
"${SYNC}/http/exoplanets_textures/1/disc_texture.png";
const float AU = static_cast<float>(distanceconstants::AstronomicalUnit);
const float SolarRadius = static_cast<float>(distanceconstants::SolarRadius);
const float JupiterRadius = static_cast<float>(distanceconstants::JupiterRadius);
constexpr const float AU = static_cast<float>(distanceconstants::AstronomicalUnit);
constexpr const float SolarRadius = static_cast<float>(distanceconstants::SolarRadius);
constexpr const float JupiterRadius = static_cast<float>(distanceconstants::JupiterRadius);
ExoplanetSystem findExoplanetSystemInData(std::string_view starName) {
ExoplanetSystem system;
@@ -84,14 +84,14 @@ ExoplanetSystem findExoplanetSystemInData(std::string_view starName) {
// 3. read sizeof(exoplanet) bytes into an exoplanet object.
ExoplanetDataEntry p;
std::string line;
while (getline(lut, line)) {
while (std::getline(lut, line)) {
std::istringstream ss(line);
std::string name;
getline(ss, name, ',');
std::getline(ss, name, ',');
if (name.substr(0, name.length() - 2) == starName) {
std::string location_s;
getline(ss, location_s);
std::getline(ss, location_s);
long location = std::stol(location_s.c_str());
data.seekg(location);
@@ -151,7 +151,7 @@ void createExoplanetSystem(const std::string& starName) {
}
ExoplanetSystem system = findExoplanetSystemInData(starName);
if (system.planetNames.empty()) {
if (system.planetsData.empty()) {
LERROR(fmt::format("Exoplanet system '{}' could not be found", starName));
return;
}
@@ -447,10 +447,6 @@ void createExoplanetSystem(const std::string& starName) {
"Enabled = true,"
"Renderable = {"
"Type = 'RenderableOrbitDisc',"
"Rotation = {"
"Type = 'StaticRotation',"
"Rotation = " + ghoul::to_string(rotationMat3) + ""
"},"
"Texture = openspace.absPath("
"openspace.createPixelImage('exo_habitable_zone', {0, 0.92, 0.81})"
"),"
@@ -549,7 +545,7 @@ std::vector<std::string> hostStarsWithSufficientData() {
// Read number of lines
int nExoplanets = 0;
while (getline(lookupTableFile, line)) {
while (std::getline(lookupTableFile, line)) {
++nExoplanets;
}
lookupTableFile.clear();
@@ -557,17 +553,17 @@ std::vector<std::string> hostStarsWithSufficientData() {
names.reserve(nExoplanets);
ExoplanetDataEntry p;
while (getline(lookupTableFile, line)) {
while (std::getline(lookupTableFile, line)) {
std::stringstream ss(line);
std::string name;
getline(ss, name, ',');
std::getline(ss, name, ',');
// Remove the last two characters, that specify the planet
name = name.substr(0, name.size() - 2);
// Don't want to list systems where there is not enough data to visualize.
// So, test if there is before adding the name to the list.
std::string location_s;
getline(ss, location_s);
std::getline(ss, location_s);
long location = std::stol(location_s.c_str());
data.seekg(location);
@@ -40,6 +40,11 @@
#include <ghoul/opengl/textureunit.h>
namespace {
constexpr const std::array<const char*, 6> UniformNames = {
"modelViewProjectionTransform", "offset", "opacity",
"discTexture", "eccentricity", "semiMajorAxis"
};
static const openspace::properties::Property::PropertyInfo TextureInfo = {
"Texture",
"Texture",
@@ -166,14 +171,7 @@ void RenderableOrbitDisc::initializeGL() {
absPath("${BASE}/modules/exoplanets/shaders/orbitdisc_fs.glsl")
);
_uniformCache.modelViewProjection = _shader->uniformLocation(
"modelViewProjectionTransform"
);
_uniformCache.offset = _shader->uniformLocation("offset");
_uniformCache.opacity = _shader->uniformLocation("opacity");
_uniformCache.texture = _shader->uniformLocation("discTexture");
_uniformCache.eccentricity = _shader->uniformLocation("eccentricity");
_uniformCache.semiMajorAxis = _shader->uniformLocation("semiMajorAxis");
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
glGenVertexArrays(1, &_quad);
glGenBuffers(1, &_vertexPositionBuffer);
@@ -239,14 +237,7 @@ void RenderableOrbitDisc::render(const RenderData& data, RendererTasks&) {
void RenderableOrbitDisc::update(const UpdateData&) {
if (_shader->isDirty()) {
_shader->rebuildFromFile();
_uniformCache.modelViewProjection = _shader->uniformLocation(
"modelViewProjectionTransform"
);
_uniformCache.offset = _shader->uniformLocation("offset");
_uniformCache.opacity = _shader->uniformLocation("opacity");
_uniformCache.texture = _shader->uniformLocation("discTexture");
_uniformCache.eccentricity = _shader->uniformLocation("eccentricity");
_uniformCache.semiMajorAxis = _shader->uniformLocation("semiMajorAxis");
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
}
if (_planeIsDirty) {
@@ -89,7 +89,7 @@ void ExoplanetsDataPreparationTask::perform(
binFile.write(reinterpret_cast<char*>(&version), sizeof(int));
auto readFirstDataRow = [](std::ifstream& file, std::string& line) -> void {
while (getline(file, line)) {
while (std::getline(file, line)) {
bool shouldSkip = line[0] == '#' || line.empty();
if (!shouldSkip) break;
}
@@ -103,14 +103,14 @@ void ExoplanetsDataPreparationTask::perform(
std::vector<std::string> columnNames;
std::stringstream sStream(columnNamesRow);
std::string colName;
while (getline(sStream, colName, ',')) {
while (std::getline(sStream, colName, ',')) {
columnNames.push_back(colName);
}
// Read total number of items
int total = 0;
std::string row;
while (getline(inputDataFile, row)) {
while (std::getline(inputDataFile, row)) {
++total;
}
inputDataFile.clear();
@@ -167,20 +167,20 @@ void ExoplanetsDataPreparationTask::perform(
ExoplanetDataEntry p;
std::string data;
int exoplanetCount = 0;
while (getline(inputDataFile, row)) {
while (std::getline(inputDataFile, row)) {
++exoplanetCount;
progressCallback(static_cast<float>(exoplanetCount) / static_cast<float>(total));
std::string component;
std::string starName;
float ra = std::numeric_limits<float>::quiet_NaN(); // decimal degrees
float dec = std::numeric_limits<float>::quiet_NaN(); // decimal degrees
float ra = std::numeric_limits<float>::quiet_NaN(); // decimal degrees
float dec = std::numeric_limits<float>::quiet_NaN(); // decimal degrees
float distanceInParsec = std::numeric_limits<float>::quiet_NaN();
std::istringstream lineStream(row);
int columnIndex = 0;
while (getline(lineStream, data, ',')) {
while (std::getline(lineStream, data, ',')) {
const std::string& column = columnNames[columnIndex];
columnIndex++;
@@ -299,15 +299,15 @@ void ExoplanetsDataPreparationTask::perform(
// Star luminosity
else if (column == "st_lum") {
float dataInLogSolar = readFloatData(data);
p.luminosity = std::pow(10, dataInLogSolar);
p.luminosity = static_cast<float>(std::pow(10, dataInLogSolar));
}
else if (column == "st_lumerr1") {
float dataInLogSolar = readFloatData(data);
p.luminosityUpper = std::pow(10, dataInLogSolar);
p.luminosityUpper = static_cast<float>(std::pow(10, dataInLogSolar));
}
else if (column == "st_lumerr2") {
float dataInLogSolar = readFloatData(data);
p.luminosityLower = -std::pow(10, dataInLogSolar);
p.luminosityLower = static_cast<float>(-std::pow(10, dataInLogSolar));
}
// Is the planet orbiting a binary system?
else if (column == "cb_flag") {
@@ -360,7 +360,7 @@ glm::vec3 ExoplanetsDataPreparationTask::starPosition(const std::string& starNam
glm::vec3 position{ std::numeric_limits<float>::quiet_NaN() };
std::string line;
while (getline(exoplanetsFile, line)) {
while (std::getline(exoplanetsFile, line)) {
bool shouldSkipLine = (
line.empty() || line[0] == '#' || line.substr(0, 7) == "datavar" ||
line.substr(0, 10) == "texturevar" || line.substr(0, 7) == "texture"
@@ -373,18 +373,18 @@ glm::vec3 ExoplanetsDataPreparationTask::starPosition(const std::string& starNam
std::string data;
std::string name;
std::istringstream linestream(line);
getline(linestream, data, '#');
getline(linestream, name);
std::getline(linestream, data, '#');
std::getline(linestream, name);
name.erase(0, 1);
std::string coord;
if (name == starName) {
std::stringstream dataStream(data);
getline(dataStream, coord, ' ');
std::getline(dataStream, coord, ' ');
position[0] = std::stof(coord.c_str(), nullptr);
getline(dataStream, coord, ' ');
std::getline(dataStream, coord, ' ');
position[1] = std::stof(coord.c_str(), nullptr);
getline(dataStream, coord, ' ');
std::getline(dataStream, coord, ' ');
position[2] = std::stof(coord.c_str(), nullptr);
break;
}
@@ -410,12 +410,12 @@ float ExoplanetsDataPreparationTask::bvFromTeff(float teff) {
float teffLower;
float teffUpper;
std::string row;
while (getline(teffToBvFile, row)) {
while (std::getline(teffToBvFile, row)) {
std::istringstream lineStream(row);
std::string teffString;
getline(lineStream, teffString, ',');
std::getline(lineStream, teffString, ',');
std::string bvString;
getline(lineStream, bvString);
std::getline(lineStream, bvString);
float teffCurrent = std::stof(teffString.c_str(), nullptr);
float bvCurrent = std::stof(bvString.c_str(), nullptr);
+4 -1
View File
@@ -303,13 +303,16 @@ int createPixelImage(lua_State* L) {
const std::string& name = ghoul::lua::value<std::string>(L, 1);
const ghoul::Dictionary& d = ghoul::lua::value<ghoul::Dictionary>(L, 2);
// @TODO (emmbr 2020-12-18) Verify that the input dictionary is a vec3
// Would like to clean this up with a more direct use of the Verifier in the future
using namespace openspace::documentation;
const std::string& key = "color";
ghoul::Dictionary colorDict = {{ key, d }};
TestResult res = DoubleVector3Verifier()(colorDict, key);
if (!res.success) {
return ghoul::lua::luaError(L,
return ghoul::lua::luaError(
L,
"Invalid color. Expected three double values {r, g, b} in range 0 to 1"
);
}