diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index 5d2acdc2ef..87f0c51217 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -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 diff --git a/modules/exoplanets/exoplanetshelper.h b/modules/exoplanets/exoplanetshelper.h index 378afd2979..1b3e4bccc8 100644 --- a/modules/exoplanets/exoplanetshelper.h +++ b/modules/exoplanets/exoplanetshelper.h @@ -80,10 +80,10 @@ struct ExoplanetDataEntry { struct StarData { glm::vec3 position = glm::vec3(std::numeric_limits::quiet_NaN()); // In parsec - float radius = std::numeric_limits::quiet_NaN(); // In solar radii - float bv = std::numeric_limits::quiet_NaN(); - float teff = std::numeric_limits::quiet_NaN(); // In Kelvin - float luminosity = std::numeric_limits::quiet_NaN(); // In solar luminosities + float radius = std::numeric_limits::quiet_NaN(); // In solar radii + float bv = std::numeric_limits::quiet_NaN(); + float teff = std::numeric_limits::quiet_NaN(); // In Kelvin + float luminosity = std::numeric_limits::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. diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 0f7de105c4..48574d54f0 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -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(distanceconstants::AstronomicalUnit); -const float SolarRadius = static_cast(distanceconstants::SolarRadius); -const float JupiterRadius = static_cast(distanceconstants::JupiterRadius); +constexpr const float AU = static_cast(distanceconstants::AstronomicalUnit); +constexpr const float SolarRadius = static_cast(distanceconstants::SolarRadius); +constexpr const float JupiterRadius = static_cast(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 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 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); diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 4e74e8526c..57e5486e49 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -40,6 +40,11 @@ #include namespace { + constexpr const std::array 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) { diff --git a/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp b/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp index 369dea2b4a..181b4aa323 100644 --- a/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp +++ b/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp @@ -89,7 +89,7 @@ void ExoplanetsDataPreparationTask::perform( binFile.write(reinterpret_cast(&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 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(exoplanetCount) / static_cast(total)); std::string component; std::string starName; - float ra = std::numeric_limits::quiet_NaN(); // decimal degrees - float dec = std::numeric_limits::quiet_NaN(); // decimal degrees + float ra = std::numeric_limits::quiet_NaN(); // decimal degrees + float dec = std::numeric_limits::quiet_NaN(); // decimal degrees float distanceInParsec = std::numeric_limits::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(std::pow(10, dataInLogSolar)); } else if (column == "st_lumerr1") { float dataInLogSolar = readFloatData(data); - p.luminosityUpper = std::pow(10, dataInLogSolar); + p.luminosityUpper = static_cast(std::pow(10, dataInLogSolar)); } else if (column == "st_lumerr2") { float dataInLogSolar = readFloatData(data); - p.luminosityLower = -std::pow(10, dataInLogSolar); + p.luminosityLower = static_cast(-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::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); diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index 19cf96a6f7..03fb68b151 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -303,13 +303,16 @@ int createPixelImage(lua_State* L) { const std::string& name = ghoul::lua::value(L, 1); const ghoul::Dictionary& d = ghoul::lua::value(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" ); }