From e81c6c909f2e487d1f0e21bc624e3f0e921b93e8 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Wed, 9 Jun 2021 17:09:07 +0200 Subject: [PATCH 01/44] Switch the ra dec conversion to the "Math" version --- src/util/coordinateconversion.cpp | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 65cba42a33..8716bdcc4f 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -26,22 +26,34 @@ namespace openspace { +// Convert Equatorial coordinates ICRS right ascension and declination (a, d) +// into Galactic coordinates (l, b) glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance) { - // Convert to Galactic Coordinates from ICRS right ascension and declination - // https://gea.esac.esa.int/archive/documentation/GDR2/Data_processing/ - // chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1 - const glm::dmat3 conversionMatrix = glm::dmat3({ - -0.0548755604162154, 0.4941094278755837, -0.8676661490190047, // col 0 - -0.8734370902348850, -0.4448296299600112, -0.1980763734312015, // col 1 - -0.4838350155487132, 0.7469822444972189, 0.4559837761750669 // col 2 - }); + // Reference: + // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, - glm::dvec3 rICRS = glm::dvec3( - cos(glm::radians(ra)) * cos(glm::radians(dec)), - sin(glm::radians(ra)) * cos(glm::radians(dec)), - sin(glm::radians(dec)) + // (Ra, Dec) -> (a, d) + float a = glm::radians(ra); + float d = glm::radians(dec); + + // J2000 Galactic reference frame + constexpr float a0 = glm::radians(192.8595f); // Equatorial coordinates of the Galactic north pole + constexpr float d0 = glm::radians(27.1284f); + constexpr float l0 = glm::radians(122.9320f); // Galactic longitude of the equatorial north pole + + // Convert to galactic reference frame + float l = l0 - atan2( + cos(d) * sin(a - a0), + sin(d) * cos(d0) - cos(d) * sin(d0) * cos(a - a0) + ); + float b = asin(sin(d) * sin(d0) + cos(d) * cos(d0) * cos(a - a0)); + + // Convert to cartesian + glm::dvec3 rGalactic = glm::dvec3( + cos(b) * cos(l), + cos(b) * sin(l), + sin(b) ); - glm::dvec3 rGalactic = conversionMatrix * rICRS; // on the unit sphere return distance * rGalactic; } From 9043f7d3cd690145d283b54d6ae15df26187edc3 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Tue, 15 Jun 2021 09:18:33 +0200 Subject: [PATCH 02/44] Add initial version of lua ra dec conversion function --- include/openspace/util/coordinateconversion.h | 9 ++++ src/scene/scene.cpp | 7 +++ src/scene/scene_lua.inl | 19 ++++++++ src/util/coordinateconversion.cpp | 43 +++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h index b6ba2ec7d5..e413412a24 100644 --- a/include/openspace/util/coordinateconversion.h +++ b/include/openspace/util/coordinateconversion.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___COORDINATECONVERSION___H__ #include +#include namespace openspace { @@ -39,6 +40,14 @@ namespace openspace { */ glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance); +/** + * Converts from ICRS (hms and dms) coordinates to decimal degrees. + * \param ra Right ascension, given as a string in format "XXhYYmZZs" + * \param dec Declination, given as a string in format "+XXdYYmZZs" or "-XXdYYmZZs" + * \return The decimal degrees coordinate + */ +glm::dvec2 icrsToDecimalDegrees(std::string ra, std::string dec); + } // namespace openspace #endif // __OPENSPACE_CORE___COORDINATECONVERSION___H__ diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index d39208d1a1..a88f98037e 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -731,6 +731,13 @@ scripting::LuaLibrary Scene::luaLibrary() { {}, "string", "Returns the world rotation matrix of the scene graph node with the given string as identifier" + }, + { + "convertRaDec", + &luascriptfunctions::convertRaDec, + {}, + "string, string, float", + "Returns the cartesian world position of a ra dec coordinate with distance" } } }; diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index cb1d33fd52..c2c2293d17 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -28,6 +28,8 @@ #include #include +#include + namespace openspace { namespace { @@ -948,4 +950,21 @@ int worldRotation(lua_State* L) { return 1; } +int convertRaDec(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertRaDec"); + + std::string ra = ghoul::lua::value(L, 1); + std::string dec = ghoul::lua::value(L, 2); + float distance = ghoul::lua::value(L, 3); + lua_settop(L, 0); + + glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec); + glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance); + + ghoul::lua::push(L, pos); + + ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); + return 1; +} + } // namespace openspace::luascriptfunctions diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 8716bdcc4f..9d0290cb24 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -58,4 +58,47 @@ glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance) { return distance * rGalactic; } +// ra format "XXhYYmZZs" or "XhYmZs" +// dec format "+XXdYYmZZs", "-XXdYYmZZs" or "-XdYmZs" +glm::dvec2 icrsToDecimalDegrees(std::string ra, std::string dec) { + if (ra.size() > 9 || ra.size() < 6 || dec.size() > 10 || dec.size() < 7) { + // Stirngs too big or small + } + + // Parse right ascension + size_t ra_h_index = ra.find('h'); + size_t ra_m_index = ra.find('m'); + size_t ra_s_index = ra.find('s'); + if (ra_h_index == std::string::npos || ra_m_index == std::string::npos || + ra_s_index == std::string::npos) + { + // Format not correct + } + + float ra_hours = std::stof(ra.substr(0, ra_h_index)); + float ra_minutes = std::stof(ra.substr(ra_h_index + 1, ra_m_index - ra_h_index - 1)); + float ra_seconds = std::stof(ra.substr(ra_m_index + 1, ra_s_index - ra_m_index - 1)); + + // Parse declination + size_t dec_d_index = dec.find('d'); + size_t dec_m_index = dec.find('m'); + size_t dec_s_index = dec.find('s'); + if (dec_d_index == std::string::npos || dec_m_index == std::string::npos || + dec_s_index == std::string::npos) + { + // Format not correct + } + + float dec_degrees = std::stof(dec.substr(0, dec_d_index)); + float dec_minutes = std::stof(dec.substr(dec_d_index + 1, dec_m_index - dec_d_index - 1)); + float dec_seconds = std::stof(dec.substr(dec_m_index + 1, dec_s_index - dec_m_index - 1)); + + // Convert from hours, minutes, sewconds to degrees + float sign = signbit(dec_degrees) ? -1.f : 1.f; + float ra_deg = (ra_hours * 15.0) + (ra_minutes * 15 / 60.0) + (ra_seconds * 15 / 3600.0); + float dec_deg = (abs(dec_degrees) + (dec_minutes / 60.0) + (dec_seconds / 3600.0)) * sign; + + return glm::dvec2(ra_deg, dec_deg); +} + } // namespace openspace From 660ff65baf6492c3c5cfe35fe183515ad4f1d852 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Wed, 16 Jun 2021 10:56:46 +0200 Subject: [PATCH 03/44] Rause code for the conversion for ra and dec * float -> double * Add error handling --- include/openspace/util/coordinateconversion.h | 7 +- src/scene/scene.cpp | 2 +- src/scene/scene_lua.inl | 2 +- src/util/coordinateconversion.cpp | 215 +++++++++++++++--- 4 files changed, 184 insertions(+), 42 deletions(-) diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h index e413412a24..b0e8ba0f46 100644 --- a/include/openspace/util/coordinateconversion.h +++ b/include/openspace/util/coordinateconversion.h @@ -38,15 +38,16 @@ namespace openspace { * \return A position in galactic cartesian coordinates, given in the same unit as the * distance parameter. */ -glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance); +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance); /** * Converts from ICRS (hms and dms) coordinates to decimal degrees. * \param ra Right ascension, given as a string in format "XXhYYmZZs" - * \param dec Declination, given as a string in format "+XXdYYmZZs" or "-XXdYYmZZs" + * \param dec Declination, given as a string in format "XXdYYmZZs", "-XXdYYmZZs", + * "XdYmZs" or "-XdYmZs" * \return The decimal degrees coordinate */ -glm::dvec2 icrsToDecimalDegrees(std::string ra, std::string dec); +glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec); } // namespace openspace diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index a88f98037e..75506d0acb 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -736,7 +736,7 @@ scripting::LuaLibrary Scene::luaLibrary() { "convertRaDec", &luascriptfunctions::convertRaDec, {}, - "string, string, float", + "string, string, double", "Returns the cartesian world position of a ra dec coordinate with distance" } } diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index c2c2293d17..036bdf5b9a 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -955,7 +955,7 @@ int convertRaDec(lua_State* L) { std::string ra = ghoul::lua::value(L, 1); std::string dec = ghoul::lua::value(L, 2); - float distance = ghoul::lua::value(L, 3); + double distance = ghoul::lua::value(L, 3); lua_settop(L, 0); glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec); diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 9d0290cb24..2d3ce2db52 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -24,29 +24,173 @@ #include +#include +#include +#include + +namespace { + constexpr const char* _loggerCat = "Coordinateconversion"; + + bool isStringNumber(const std::string& str) { + for (size_t i = 0; i < str.size(); ++i) { + if (!isdigit(str[i])) { + if (i == 0 && str.size() > 1) { + if (str[i] == '-' || str[i] == '+') { + continue; + } + else { + return false; + } + } + else { + return false; + } + } + } + return true; + } + + void parseString(const std::string& str, double& hours_or_degrees, double& minutes, + double& seconds) + { + // Find hms or dms indicies + size_t h_or_d_index; + if (str.find('h') != std::string::npos) { + h_or_d_index = str.find('h'); + } + else { + h_or_d_index = str.find('d'); + } + size_t m_index = str.find('m'); + size_t s_index = str.find('s'); + if (h_or_d_index == std::string::npos || m_index == std::string::npos || + s_index == std::string::npos) + { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " + "or 'XhYmZs', and Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", + str) + )); + } + + // Construct the number strings + std::string s_hours_or_degrees = str.substr(0, h_or_d_index); + std::string s_minutes = str.substr(h_or_d_index + 1, m_index - h_or_d_index - 1); + std::string s_seconds = str.substr(m_index + 1, s_index - m_index - 1); + if (!isStringNumber(s_hours_or_degrees) || !isStringNumber(s_minutes) || + !isStringNumber(s_seconds)) + { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " + "or 'XhYmZs', and Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", + str) + )); + } + + // Convert the strings to numbers + hours_or_degrees = std::stod(s_hours_or_degrees); + minutes = std::stod(s_minutes); + seconds = std::stod(s_seconds); + } + + void parseRa(const std::string& ra, double& hours, double& minutes, double& seconds) { + if (ra.find('d') != std::string::npos) { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' or " + "'XhYmZs'", ra) + )); + } + parseString(ra, hours, minutes, seconds); + } + + void parseDec(const std::string& dec, double& degrees, double& minutes, + double& seconds) + { + if (dec.find('h') != std::string::npos) { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Dec '{}' format is incorrect. Correct format is: " + "Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", dec) + )); + } + parseString(dec, degrees, minutes, seconds); + } + + bool isRaDecValid(double ra_h, double ra_m, double ra_s, double dec_d, + double dec_m, double dec_s) + { + // Ra + if (ra_h < 0.0 || ra_h >= 24.0) { + LWARNING(fmt::format("Right ascension hours '{}' is outside the allowed " + "range of 0 to 24 hours (exclusive)", ra_h) + ); + return false; + } + if (ra_m < 0.0 || ra_m >= 60.0) { + LWARNING(fmt::format("Right ascension minutes '{}' is outside the allowed " + "range of 0 to 60 minutes (exclusive)", ra_m) + ); + return false; + } + if (ra_s < 0.0 || ra_s >= 60.0) { + LWARNING(fmt::format("Right ascension seconds '{}' is outside the allowed " + "range of 0 to 60 seconds (exclusive)", ra_s) + ); + return false; + } + + // Dec + if (dec_d < -90.0 || dec_d > 90.0) { + LWARNING(fmt::format("Declination degrees '{}' is outside the allowed range " + "of -90 to 90 degrees (inclusive)", dec_d) + ); + return false; + } + else if ((dec_d == -90.0 || dec_d == 90.0) && (dec_m != 0 || dec_s != 0)) { + LWARNING("Total declination is outside the allowed range of -90 to 90 " + "degrees (inclusive)" + ); + return false; + } + if (dec_m < 0.0 || dec_m >= 60.0) { + LWARNING(fmt::format("Declination minutes '{}' is outside the allowed range " + "of 0 to 60 minutes (exclusive)", dec_m) + ); + return false; + } + if (dec_s < 0.0 || dec_s >= 60.0) { + LWARNING(fmt::format("Declination seconds '{}' is outside the allowed range " + "of 0 to 60 seconds (exclusive)", dec_s) + ); + return false; + } + + return true; + } +} // namespace + namespace openspace { // Convert Equatorial coordinates ICRS right ascension and declination (a, d) // into Galactic coordinates (l, b) -glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance) { +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { // Reference: // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, // (Ra, Dec) -> (a, d) - float a = glm::radians(ra); - float d = glm::radians(dec); + double a = glm::radians(ra); + double d = glm::radians(dec); // J2000 Galactic reference frame - constexpr float a0 = glm::radians(192.8595f); // Equatorial coordinates of the Galactic north pole - constexpr float d0 = glm::radians(27.1284f); - constexpr float l0 = glm::radians(122.9320f); // Galactic longitude of the equatorial north pole + constexpr double a0 = glm::radians(192.8595); // Equatorial coordinates of the Galactic north pole + constexpr double d0 = glm::radians(27.1284); + constexpr double l0 = glm::radians(122.9320); // Galactic longitude of the equatorial north pole // Convert to galactic reference frame - float l = l0 - atan2( + double l = l0 - atan2( cos(d) * sin(a - a0), sin(d) * cos(d0) - cos(d) * sin(d0) * cos(a - a0) ); - float b = asin(sin(d) * sin(d0) + cos(d) * cos(d0) * cos(a - a0)); + double b = asin(sin(d) * sin(d0) + cos(d) * cos(d0) * cos(a - a0)); // Convert to cartesian glm::dvec3 rGalactic = glm::dvec3( @@ -59,44 +203,41 @@ glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance) { } // ra format "XXhYYmZZs" or "XhYmZs" -// dec format "+XXdYYmZZs", "-XXdYYmZZs" or "-XdYmZs" -glm::dvec2 icrsToDecimalDegrees(std::string ra, std::string dec) { - if (ra.size() > 9 || ra.size() < 6 || dec.size() > 10 || dec.size() < 7) { - // Stirngs too big or small +// dec format "XXdYYmZZs", "-XXdYYmZZs", "XdYmZs" or "-XdYmZs" +glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { + if (ra.size() > 9 || ra.size() < 6 || dec.size() > 10 || dec.size() < 6) { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra '{}' or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " + "or 'XhYmZs', and Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", + ra, dec) + )); } // Parse right ascension - size_t ra_h_index = ra.find('h'); - size_t ra_m_index = ra.find('m'); - size_t ra_s_index = ra.find('s'); - if (ra_h_index == std::string::npos || ra_m_index == std::string::npos || - ra_s_index == std::string::npos) - { - // Format not correct - } - - float ra_hours = std::stof(ra.substr(0, ra_h_index)); - float ra_minutes = std::stof(ra.substr(ra_h_index + 1, ra_m_index - ra_h_index - 1)); - float ra_seconds = std::stof(ra.substr(ra_m_index + 1, ra_s_index - ra_m_index - 1)); + double ra_hours, ra_minutes, ra_seconds; + parseRa(ra, ra_hours, ra_minutes, ra_seconds); // Parse declination - size_t dec_d_index = dec.find('d'); - size_t dec_m_index = dec.find('m'); - size_t dec_s_index = dec.find('s'); - if (dec_d_index == std::string::npos || dec_m_index == std::string::npos || - dec_s_index == std::string::npos) + double dec_degrees, dec_minutes, dec_seconds; + parseDec(dec, dec_degrees, dec_minutes, dec_seconds); + + if (!isRaDecValid(ra_hours, ra_minutes, ra_seconds, dec_degrees, dec_minutes, + dec_seconds)) { - // Format not correct + LWARNING(fmt::format("Ra '{}' or Dec '{}' is outside the allowed range", + ra, dec) + ); } - float dec_degrees = std::stof(dec.substr(0, dec_d_index)); - float dec_minutes = std::stof(dec.substr(dec_d_index + 1, dec_m_index - dec_d_index - 1)); - float dec_seconds = std::stof(dec.substr(dec_m_index + 1, dec_s_index - dec_m_index - 1)); + // Convert from hours, minutes, seconds to decimal degrees + double sign = signbit(dec_degrees) ? -1.0 : 1.0; + double ra_deg = (ra_hours * 15.0) + + (ra_minutes * 15.0 / 60.0) + + (ra_seconds * 15.0 / 3600.0); - // Convert from hours, minutes, sewconds to degrees - float sign = signbit(dec_degrees) ? -1.f : 1.f; - float ra_deg = (ra_hours * 15.0) + (ra_minutes * 15 / 60.0) + (ra_seconds * 15 / 3600.0); - float dec_deg = (abs(dec_degrees) + (dec_minutes / 60.0) + (dec_seconds / 3600.0)) * sign; + double dec_deg = (abs(dec_degrees) + + (dec_minutes / 60.0) + + (dec_seconds / 3600.0)) * sign; return glm::dvec2(ra_deg, dec_deg); } From c39baac3a86a97d8eba8d7137ea83b21ef55e79a Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Mon, 21 Jun 2021 13:43:31 +0200 Subject: [PATCH 04/44] Add functions to convert a cartesian coordinate to a ra dec distance --- include/openspace/util/coordinateconversion.h | 18 ++++ src/scene/scene.cpp | 11 ++- src/scene/scene_lua.inl | 23 ++++- src/util/coordinateconversion.cpp | 97 ++++++++++++++++++- 4 files changed, 140 insertions(+), 9 deletions(-) diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h index b0e8ba0f46..d33a46c2ae 100644 --- a/include/openspace/util/coordinateconversion.h +++ b/include/openspace/util/coordinateconversion.h @@ -49,6 +49,24 @@ glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance); */ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec); +/** + * Converts from galactic cartesian coordinates to ICRS coordinates in decimal degrees + * and distance. + * \param x X coordinate + * \param y Y coordinate + * \param z Z coordinate + * \return A vector with the ra and dec decimal degrees and distance. + */ +glm::dvec3 galacticCartesianToIcrs(double x, double y, double z); + +/** + * Converts from ICRS (decimal degrees) coordinates to ICRS (hms and dms) coordinates. + * \param ra Right ascension, given in decimal degrees + * \param dec Declination, given in decimal degrees + * \return A pair with the ra and dec strings in hms and dms format. + */ +std::pair decimalDegreesToIcrs(double ra, double dec); + } // namespace openspace #endif // __OPENSPACE_CORE___COORDINATECONVERSION___H__ diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 75506d0acb..c8e23f9573 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -733,11 +733,18 @@ scripting::LuaLibrary Scene::luaLibrary() { "Returns the world rotation matrix of the scene graph node with the given string as identifier" }, { - "convertRaDec", - &luascriptfunctions::convertRaDec, + "convertFromRaDec", + &luascriptfunctions::convertFromRaDec, {}, "string, string, double", "Returns the cartesian world position of a ra dec coordinate with distance" + }, + { + "convertToRaDec", + &luascriptfunctions::convertToRaDec, + {}, + "double, double, double", + "Returns the ra, dec strings and distance for a given cartesian world coordinate" } } }; diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index 036bdf5b9a..bdaf0c1f7c 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -950,8 +950,8 @@ int worldRotation(lua_State* L) { return 1; } -int convertRaDec(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertRaDec"); +int convertFromRaDec(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec"); std::string ra = ghoul::lua::value(L, 1); std::string dec = ghoul::lua::value(L, 2); @@ -967,4 +967,23 @@ int convertRaDec(lua_State* L) { return 1; } +int convertToRaDec(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertToRaDec"); + + double x = ghoul::lua::value(L, 1); + double y = ghoul::lua::value(L, 2); + double z = ghoul::lua::value(L, 3); + lua_settop(L, 0); + + glm::dvec3 degrees = galacticCartesianToIcrs(x, y, z); + std::pair raDecPair = decimalDegreesToIcrs(degrees.x, degrees.y); + + ghoul::lua::push(L, raDecPair.first); // Ra + ghoul::lua::push(L, raDecPair.second); // Dec + ghoul::lua::push(L, degrees.z); // Distance + + ghoul_assert(lua_gettop(L) == 3, "Incorrect number of items left on stack"); + return 3; +} + } // namespace openspace::luascriptfunctions diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 2d3ce2db52..ea64bf374b 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -174,7 +174,7 @@ namespace openspace { // into Galactic coordinates (l, b) glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { // Reference: - // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, + // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php // (Ra, Dec) -> (a, d) double a = glm::radians(ra); @@ -202,9 +202,11 @@ glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { return distance * rGalactic; } -// ra format "XXhYYmZZs" or "XhYmZs" -// dec format "XXdYYmZZs", "-XXdYYmZZs", "XdYmZs" or "-XdYmZs" +// Ra format "XXhYYmZZs" or "XhYmZs" +// Dec format "XXdYYmZZs", "-XXdYYmZZs", "XdYmZs" or "-XdYmZs" glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { + // Reference: + // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars if (ra.size() > 9 || ra.size() < 6 || dec.size() > 10 || dec.size() < 6) { throw(ghoul::lua::LuaRuntimeException(fmt::format( "Ra '{}' or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " @@ -224,8 +226,8 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { if (!isRaDecValid(ra_hours, ra_minutes, ra_seconds, dec_degrees, dec_minutes, dec_seconds)) { - LWARNING(fmt::format("Ra '{}' or Dec '{}' is outside the allowed range", - ra, dec) + LWARNING(fmt::format("Ra '{}' or Dec '{}' is outside the allowed range, " + "result may be incorrect", ra, dec) ); } @@ -242,4 +244,89 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { return glm::dvec2(ra_deg, dec_deg); } +// Convert Galactic coordinates (x, y, z) or (l, b) into +// Equatorial coordinates ICRS right ascension and declination (a, d) plus distance +glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { + // References: + // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, + // https://en.wikipedia.org/wiki/Celestial_coordinate_system + + // Normalize + double distance = sqrt(x * x + y * y + z * z); + double n_x = x / distance; + double n_y = y / distance; + double n_z = z / distance; + + // Convert from cartesian + // (x, y, z) -> (l, b) + double l = atan2(n_y, n_x); + double b = asin(n_z); + + // J2000 Galactic reference frame + constexpr double a0 = glm::radians(192.8595); // Equatorial coordinates of the Galactic north pole + constexpr double d0 = glm::radians(27.1284); + constexpr double l0 = glm::radians(122.9320); // Galactic longitude of the equatorial north pole + + // Convert to equatorial reference frame + double a = atan2( + cos(b) * sin(l0 - l), + sin(b) * cos(d0) - cos(b) * sin(d0) * cos(l0 - l) + ) + a0; + double d = asin(sin(b) * sin(d0) + cos(b) * cos(d0) * cos(l0 - l)); + + glm::dvec3 rEquatorial = glm::dvec3(a, d, distance); + + return rEquatorial; +} + +// Return a pair with two formatted strings from the decimal degrees ra and dec +std::pair decimalDegreesToIcrs(double ra, double dec) { + // References: + // https://www.rapidtables.com/convert/number/degrees-to-degrees-minutes-seconds.html, + // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars + + // Radians to degrees + double ra_deg = glm::degrees(ra); + double dec_deg = glm::degrees(dec); + + // Check input + if (ra_deg < 0 || ra_deg > 360 || dec_deg < -90 || dec_deg > 90) { + LWARNING(fmt::format("Given Ra '{}' or Dec '{}' is outside the allowed range, " + "result may be incorrect", ra, dec) + ); + } + + // Calculate Ra + int ra_hours = std::trunc(ra_deg) / 15.0; + double ra_minutes_full = (ra_deg - ra_hours * 15.0) * 60.0 / 15.0; + int ra_minutes = std::trunc(ra_minutes_full); + double ra_seconds = (ra_minutes_full - ra_minutes) * 60.0; + + // Calculate Dec + int dec_degrees = std::trunc(dec_deg); + double dec_minutes_full = (abs(dec_deg) - abs(dec_degrees)) * 60.0; + int dec_minutes = std::trunc(dec_minutes_full); + double dec_seconds = (dec_minutes_full - dec_minutes) * 60.0; + + // Construct strings + std::pair result; + result.first = std::to_string(ra_hours) + 'h' + + std::to_string(ra_minutes) + 'm' + + std::to_string(ra_seconds) + 's'; + + result.second = std::to_string(dec_degrees) + 'd' + + std::to_string(dec_minutes) + 'm' + + std::to_string(dec_seconds) + 's'; + + // Check results + if (!isRaDecValid(ra_hours, ra_minutes, ra_seconds, dec_degrees, dec_minutes, + dec_seconds)) + { + LWARNING(fmt::format("Resulting Ra '{}' or Dec '{}' is outside the allowed range, " + "result may be incorrect", result.first, result.second) + ); + } + return result; +} + } // namespace openspace From ef0b1fe4f4173b6c9fdc8e9f435d198d9d2915e5 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Wed, 23 Jun 2021 15:45:04 +0200 Subject: [PATCH 05/44] Improve Ra Dec string conversions --- src/util/coordinateconversion.cpp | 103 +++++++++++++++--------------- 1 file changed, 51 insertions(+), 52 deletions(-) diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index ea64bf374b..e6885339bd 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -31,26 +31,7 @@ namespace { constexpr const char* _loggerCat = "Coordinateconversion"; - bool isStringNumber(const std::string& str) { - for (size_t i = 0; i < str.size(); ++i) { - if (!isdigit(str[i])) { - if (i == 0 && str.size() > 1) { - if (str[i] == '-' || str[i] == '+') { - continue; - } - else { - return false; - } - } - else { - return false; - } - } - } - return true; - } - - void parseString(const std::string& str, double& hours_or_degrees, double& minutes, + void parseString(const std::string& str, int& hours_or_degrees, int& minutes, double& seconds) { // Find hms or dms indicies @@ -67,56 +48,73 @@ namespace { s_index == std::string::npos) { throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " - "or 'XhYmZs', and Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", - str) - )); + "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " + "and Dec 'XdYmZs'", str)) + ); } // Construct the number strings std::string s_hours_or_degrees = str.substr(0, h_or_d_index); std::string s_minutes = str.substr(h_or_d_index + 1, m_index - h_or_d_index - 1); std::string s_seconds = str.substr(m_index + 1, s_index - m_index - 1); - if (!isStringNumber(s_hours_or_degrees) || !isStringNumber(s_minutes) || - !isStringNumber(s_seconds)) - { - throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " - "or 'XhYmZs', and Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", - str) - )); - } // Convert the strings to numbers - hours_or_degrees = std::stod(s_hours_or_degrees); - minutes = std::stod(s_minutes); - seconds = std::stod(s_seconds); + try { + // Hours or degrees must be an integer + double temp = std::stod(s_hours_or_degrees); + std::cout << "double h: " << temp << std::endl; + if (std::floor(temp) != temp) { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " + "and Dec 'XdYmZs', where X must be an integer", str)) + ); + } + hours_or_degrees = std::stoi(s_hours_or_degrees); + + // Minutes must be an integer + temp = std::stod(s_minutes); + std::cout << "double m: " << temp << std::endl; + if (std::floor(temp) != temp) { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " + "and Dec 'XdYmZs', where Y must be an integer", str)) + ); + } + minutes = std::stoi(s_minutes); + + // Seconds is a double + seconds = std::stod(s_seconds); + } catch (const std::invalid_argument& ia) { + throw(ghoul::lua::LuaRuntimeException(fmt::format( + "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " + "and Dec 'XdYmZs'", str)) + ); + } } - void parseRa(const std::string& ra, double& hours, double& minutes, double& seconds) { + void parseRa(const std::string& ra, int& hours, int& minutes, double& seconds) { if (ra.find('d') != std::string::npos) { throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Ra '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' or " - "'XhYmZs'", ra) - )); + "Ra '{}' format is incorrect. Correct format is: 'XhYmZs'", ra)) + ); } parseString(ra, hours, minutes, seconds); } - void parseDec(const std::string& dec, double& degrees, double& minutes, + void parseDec(const std::string& dec, int& degrees, int& minutes, double& seconds) { if (dec.find('h') != std::string::npos) { throw(ghoul::lua::LuaRuntimeException(fmt::format( "Dec '{}' format is incorrect. Correct format is: " - "Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", dec) - )); + "Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", dec)) + ); } parseString(dec, degrees, minutes, seconds); } - bool isRaDecValid(double ra_h, double ra_m, double ra_s, double dec_d, - double dec_m, double dec_s) + bool isRaDecValid(int ra_h, int ra_m, double ra_s, int dec_d, + int dec_m, double dec_s) { // Ra if (ra_h < 0.0 || ra_h >= 24.0) { @@ -207,20 +205,21 @@ glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { // Reference: // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars - if (ra.size() > 9 || ra.size() < 6 || dec.size() > 10 || dec.size() < 6) { + if (ra.size() < 6 || dec.size() < 6) { throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Ra '{}' or Dec '{}' format is incorrect. Correct format is: Ra 'XXhYYmZZs' " - "or 'XhYmZs', and Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", - ra, dec) + "Ra '{}' or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " + "and Dec 'XdYmZs'", ra, dec) )); } // Parse right ascension - double ra_hours, ra_minutes, ra_seconds; + int ra_hours, ra_minutes; + double ra_seconds; parseRa(ra, ra_hours, ra_minutes, ra_seconds); // Parse declination - double dec_degrees, dec_minutes, dec_seconds; + int dec_degrees, dec_minutes; + double dec_seconds; parseDec(dec, dec_degrees, dec_minutes, dec_seconds); if (!isRaDecValid(ra_hours, ra_minutes, ra_seconds, dec_degrees, dec_minutes, @@ -232,7 +231,7 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { } // Convert from hours, minutes, seconds to decimal degrees - double sign = signbit(dec_degrees) ? -1.0 : 1.0; + double sign = signbit(static_cast(dec_degrees)) ? -1.0 : 1.0; double ra_deg = (ra_hours * 15.0) + (ra_minutes * 15.0 / 60.0) + (ra_seconds * 15.0 / 3600.0); From 3d4c83cd9a8604fd72263090c79389c88142590a Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 24 Jun 2021 13:51:22 +0200 Subject: [PATCH 06/44] Prevent NaN values in StaticTranslation by limiting min and max size Also disable exponential slider for now, as they are not working well with this kind of range --- modules/base/translation/statictranslation.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/modules/base/translation/statictranslation.cpp b/modules/base/translation/statictranslation.cpp index 228d6a7d62..ad72c2ae49 100644 --- a/modules/base/translation/statictranslation.cpp +++ b/modules/base/translation/statictranslation.cpp @@ -49,14 +49,11 @@ documentation::Documentation StaticTranslation::Documentation() { } StaticTranslation::StaticTranslation() - : _position( - PositionInfo, - glm::dvec3(0.0), - glm::dvec3(-std::numeric_limits::max()), - glm::dvec3(std::numeric_limits::max()) - ) + : _position(PositionInfo, glm::dvec3(0.0), glm::dvec3(-1e35), glm::dvec3(1e35)) { - _position.setExponent(20.f); + // @TODO (2021-06-24, emmbr) The exponential sliders do not handle ranges with + // negative values very well. When they do, this line can be uncommented + //_position.setExponent(20.f); addProperty(_position); _position.onChange([this]() { From d2a4d3201b5688ebc19aaa1fe5154fe33d64564d Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 24 Jun 2021 13:55:25 +0200 Subject: [PATCH 07/44] Add exponent to GlobeTranslation altitude slider --- modules/globebrowsing/src/globetranslation.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/globebrowsing/src/globetranslation.cpp b/modules/globebrowsing/src/globetranslation.cpp index d1097c35de..c6599dd5cc 100644 --- a/modules/globebrowsing/src/globetranslation.cpp +++ b/modules/globebrowsing/src/globetranslation.cpp @@ -125,6 +125,7 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary) addProperty(_latitude); _altitude = p.altitude.value_or(_altitude); + _altitude.setExponent(10.f); _altitude.onChange([this]() { _positionIsDirty = true; }); addProperty(_altitude); From 44080b2f94b7555bbd7ab8380cb9333209a1fe73 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Thu, 24 Jun 2021 14:05:38 +0200 Subject: [PATCH 08/44] On second though, use a slightly lower exponent... --- modules/globebrowsing/src/globetranslation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/globebrowsing/src/globetranslation.cpp b/modules/globebrowsing/src/globetranslation.cpp index c6599dd5cc..ff902b8f67 100644 --- a/modules/globebrowsing/src/globetranslation.cpp +++ b/modules/globebrowsing/src/globetranslation.cpp @@ -125,7 +125,7 @@ GlobeTranslation::GlobeTranslation(const ghoul::Dictionary& dictionary) addProperty(_latitude); _altitude = p.altitude.value_or(_altitude); - _altitude.setExponent(10.f); + _altitude.setExponent(8.f); _altitude.onChange([this]() { _positionIsDirty = true; }); addProperty(_altitude); From cd7bd0fc4b0e3da85f201966867d0efd8f807fec Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Mon, 28 Jun 2021 09:20:27 +0200 Subject: [PATCH 09/44] Move ra dec conversion lua function to the space module --- modules/space/CMakeLists.txt | 1 + modules/space/spacemodule.cpp | 26 ++++++++++++ modules/space/spacemodule.h | 2 + modules/space/spacemodule_lua.inl | 70 +++++++++++++++++++++++++++++++ src/scene/scene.cpp | 14 ------- src/scene/scene_lua.inl | 38 ----------------- 6 files changed, 99 insertions(+), 52 deletions(-) create mode 100644 modules/space/spacemodule_lua.inl diff --git a/modules/space/CMakeLists.txt b/modules/space/CMakeLists.txt index 09e56ed641..a6ce4f383c 100644 --- a/modules/space/CMakeLists.txt +++ b/modules/space/CMakeLists.txt @@ -44,6 +44,7 @@ set(HEADER_FILES source_group("Header Files" FILES ${HEADER_FILES}) set(SOURCE_FILES + spacemodule_lua.inl speckloader.cpp rendering/planetgeometry.cpp rendering/renderableconstellationbounds.cpp diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 0ebba746cd..98d4a88be4 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -39,11 +39,14 @@ #include #include #include +#include #include #include #include #include +#include "spacemodule_lua.inl" + namespace { constexpr openspace::properties::Property::PropertyInfo SpiceExceptionInfo = { "ShowExceptions", @@ -133,4 +136,27 @@ std::vector SpaceModule::documentations() const { }; } +scripting::LuaLibrary SpaceModule::luaLibrary() const { + scripting::LuaLibrary res; + res.name = "space"; + res.functions = { + { + "convertFromRaDec", + &space::luascriptfunctions::convertFromRaDec, + {}, + "string, string, double", + "Returns the cartesian world position of a ra dec coordinate with distance" + }, + { + "convertToRaDec", + &space::luascriptfunctions::convertToRaDec, + {}, + "double, double, double", + "Returns the ra, dec strings and distance for a given cartesian world coordinate" + } + }; + + return res; +} + } // namespace openspace diff --git a/modules/space/spacemodule.h b/modules/space/spacemodule.h index b2630b6277..bfa65f22b4 100644 --- a/modules/space/spacemodule.h +++ b/modules/space/spacemodule.h @@ -42,6 +42,8 @@ public: static ghoul::opengl::ProgramObjectManager ProgramObjectManager; + scripting::LuaLibrary luaLibrary() const override; + private: void internalInitialize(const ghoul::Dictionary&) override; void internalDeinitializeGL() override; diff --git a/modules/space/spacemodule_lua.inl b/modules/space/spacemodule_lua.inl new file mode 100644 index 0000000000..44ac4ae9a9 --- /dev/null +++ b/modules/space/spacemodule_lua.inl @@ -0,0 +1,70 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2021 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include +#include +#include +#include +#include +#include + +namespace openspace::space::luascriptfunctions { + +int convertFromRaDec(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec"); + + std::string ra = ghoul::lua::value(L, 1); + std::string dec = ghoul::lua::value(L, 2); + double distance = ghoul::lua::value(L, 3); + lua_settop(L, 0); + + glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec); + glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance); + + ghoul::lua::push(L, pos); + + ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); + return 1; +} + +int convertToRaDec(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertToRaDec"); + + double x = ghoul::lua::value(L, 1); + double y = ghoul::lua::value(L, 2); + double z = ghoul::lua::value(L, 3); + lua_settop(L, 0); + + glm::dvec3 degrees = galacticCartesianToIcrs(x, y, z); + std::pair raDecPair = decimalDegreesToIcrs(degrees.x, degrees.y); + + ghoul::lua::push(L, raDecPair.first); // Ra + ghoul::lua::push(L, raDecPair.second); // Dec + ghoul::lua::push(L, degrees.z); // Distance + + ghoul_assert(lua_gettop(L) == 3, "Incorrect number of items left on stack"); + return 3; +} + +} // namespace openspace::space::luascriptfunctions diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index c8e23f9573..d39208d1a1 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -731,20 +731,6 @@ scripting::LuaLibrary Scene::luaLibrary() { {}, "string", "Returns the world rotation matrix of the scene graph node with the given string as identifier" - }, - { - "convertFromRaDec", - &luascriptfunctions::convertFromRaDec, - {}, - "string, string, double", - "Returns the cartesian world position of a ra dec coordinate with distance" - }, - { - "convertToRaDec", - &luascriptfunctions::convertToRaDec, - {}, - "double, double, double", - "Returns the ra, dec strings and distance for a given cartesian world coordinate" } } }; diff --git a/src/scene/scene_lua.inl b/src/scene/scene_lua.inl index bdaf0c1f7c..cb1d33fd52 100644 --- a/src/scene/scene_lua.inl +++ b/src/scene/scene_lua.inl @@ -28,8 +28,6 @@ #include #include -#include - namespace openspace { namespace { @@ -950,40 +948,4 @@ int worldRotation(lua_State* L) { return 1; } -int convertFromRaDec(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec"); - - std::string ra = ghoul::lua::value(L, 1); - std::string dec = ghoul::lua::value(L, 2); - double distance = ghoul::lua::value(L, 3); - lua_settop(L, 0); - - glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec); - glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance); - - ghoul::lua::push(L, pos); - - ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); - return 1; -} - -int convertToRaDec(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertToRaDec"); - - double x = ghoul::lua::value(L, 1); - double y = ghoul::lua::value(L, 2); - double z = ghoul::lua::value(L, 3); - lua_settop(L, 0); - - glm::dvec3 degrees = galacticCartesianToIcrs(x, y, z); - std::pair raDecPair = decimalDegreesToIcrs(degrees.x, degrees.y); - - ghoul::lua::push(L, raDecPair.first); // Ra - ghoul::lua::push(L, raDecPair.second); // Dec - ghoul::lua::push(L, degrees.z); // Distance - - ghoul_assert(lua_gettop(L) == 3, "Incorrect number of items left on stack"); - return 3; -} - } // namespace openspace::luascriptfunctions From d5a12f813e2ca03023b07e65594c6cfb21be45d5 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Mon, 28 Jun 2021 12:05:21 +0200 Subject: [PATCH 10/44] Enable both strings and numbers to lua ra dec conversion function --- include/openspace/util/coordinateconversion.h | 10 +++--- modules/space/spacemodule_lua.inl | 31 ++++++++++++++----- src/util/coordinateconversion.cpp | 21 +++++++------ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h index d33a46c2ae..009fd3c562 100644 --- a/include/openspace/util/coordinateconversion.h +++ b/include/openspace/util/coordinateconversion.h @@ -35,17 +35,18 @@ namespace openspace { * \param ra Right ascension, given in decimal degrees * \param dec Declination, given in decimal degrees * \param distance The distance, or radius, to the position given in any unit. + * \param boolean to say if the incoming ra and dec are in degrees or radians * \return A position in galactic cartesian coordinates, given in the same unit as the * distance parameter. */ -glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance); +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, bool isDegrees = true); /** * Converts from ICRS (hms and dms) coordinates to decimal degrees. * \param ra Right ascension, given as a string in format "XXhYYmZZs" * \param dec Declination, given as a string in format "XXdYYmZZs", "-XXdYYmZZs", * "XdYmZs" or "-XdYmZs" - * \return The decimal degrees coordinate + * \return The decimal degrees coordinate in degrees */ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec); @@ -55,7 +56,7 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec); * \param x X coordinate * \param y Y coordinate * \param z Z coordinate - * \return A vector with the ra and dec decimal degrees and distance. + * \return A vector with the ra and dec decimal degrees in degrees and distance. */ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z); @@ -63,9 +64,10 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z); * Converts from ICRS (decimal degrees) coordinates to ICRS (hms and dms) coordinates. * \param ra Right ascension, given in decimal degrees * \param dec Declination, given in decimal degrees + * \param boolean to say if the incoming ra and dec are in degrees or radians * \return A pair with the ra and dec strings in hms and dms format. */ -std::pair decimalDegreesToIcrs(double ra, double dec); +std::pair decimalDegreesToIcrs(double ra, double dec, bool isDegrees = true); } // namespace openspace diff --git a/modules/space/spacemodule_lua.inl b/modules/space/spacemodule_lua.inl index 44ac4ae9a9..696b9dd344 100644 --- a/modules/space/spacemodule_lua.inl +++ b/modules/space/spacemodule_lua.inl @@ -32,16 +32,32 @@ namespace openspace::space::luascriptfunctions { int convertFromRaDec(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec"); + ghoul::lua::checkArgumentsAndThrow(L, { 3, 4 }, "lua::convertFromRaDec"); + + glm::dvec2 degrees = glm::dvec2(0.0); + bool isDegrees = true; + if (lua_type(L, 1) == LUA_TSTRING && lua_type(L, 2) == LUA_TSTRING) { + std::string s_ra = ghoul::lua::value(L, 1); + std::string s_dec = ghoul::lua::value(L, 2); + degrees = icrsToDecimalDegrees(s_ra, s_dec); + } + else if (lua_type(L, 1) == LUA_TNUMBER && lua_type(L, 2) == LUA_TNUMBER) { + degrees.x = ghoul::lua::value(L, 1); + degrees.y = ghoul::lua::value(L, 2); + if (lua_gettop(L) >= 4) { + isDegrees = ghoul::lua::value(L, 4); + } + } + else { + throw ghoul::lua::LuaRuntimeException("lua::convertFromRaDec: Ra and Dec have to " + "be of the same type, either String or Number" + ); + } - std::string ra = ghoul::lua::value(L, 1); - std::string dec = ghoul::lua::value(L, 2); double distance = ghoul::lua::value(L, 3); lua_settop(L, 0); - glm::dvec2 degrees = icrsToDecimalDegrees(ra, dec); - glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance); - + glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance, isDegrees); ghoul::lua::push(L, pos); ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); @@ -57,7 +73,8 @@ int convertToRaDec(lua_State* L) { lua_settop(L, 0); glm::dvec3 degrees = galacticCartesianToIcrs(x, y, z); - std::pair raDecPair = decimalDegreesToIcrs(degrees.x, degrees.y); + std::pair raDecPair + = decimalDegreesToIcrs(degrees.x, degrees.y); ghoul::lua::push(L, raDecPair.first); // Ra ghoul::lua::push(L, raDecPair.second); // Dec diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index e6885339bd..9428119d76 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -62,7 +62,6 @@ namespace { try { // Hours or degrees must be an integer double temp = std::stod(s_hours_or_degrees); - std::cout << "double h: " << temp << std::endl; if (std::floor(temp) != temp) { throw(ghoul::lua::LuaRuntimeException(fmt::format( "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " @@ -73,7 +72,6 @@ namespace { // Minutes must be an integer temp = std::stod(s_minutes); - std::cout << "double m: " << temp << std::endl; if (std::floor(temp) != temp) { throw(ghoul::lua::LuaRuntimeException(fmt::format( "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " @@ -170,13 +168,15 @@ namespace openspace { // Convert Equatorial coordinates ICRS right ascension and declination (a, d) // into Galactic coordinates (l, b) -glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, + bool isDegrees) +{ // Reference: // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php // (Ra, Dec) -> (a, d) - double a = glm::radians(ra); - double d = glm::radians(dec); + double a = isDegrees ? glm::radians(ra) : ra; + double d = isDegrees ? glm::radians(dec) : dec; // J2000 Galactic reference frame constexpr double a0 = glm::radians(192.8595); // Equatorial coordinates of the Galactic north pole @@ -273,20 +273,21 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { ) + a0; double d = asin(sin(b) * sin(d0) + cos(b) * cos(d0) * cos(l0 - l)); - glm::dvec3 rEquatorial = glm::dvec3(a, d, distance); - + glm::dvec3 rEquatorial = glm::dvec3(glm::degrees(a), glm::degrees(d), distance); return rEquatorial; } // Return a pair with two formatted strings from the decimal degrees ra and dec -std::pair decimalDegreesToIcrs(double ra, double dec) { +std::pair decimalDegreesToIcrs(double ra, double dec, + bool isDegrees) +{ // References: // https://www.rapidtables.com/convert/number/degrees-to-degrees-minutes-seconds.html, // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars // Radians to degrees - double ra_deg = glm::degrees(ra); - double dec_deg = glm::degrees(dec); + double ra_deg = isDegrees ? ra : glm::degrees(ra); + double dec_deg = isDegrees ? dec : glm::degrees(dec); // Check input if (ra_deg < 0 || ra_deg > 360 || dec_deg < -90 || dec_deg > 90) { From 55ffbf0bcedc8875a751ac58270dfc2528587964 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 27 Jun 2021 16:49:20 +0200 Subject: [PATCH 11/44] Increase the number of objects and windows that are extracted from SPK and CK files --- src/util/spicemanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index a2a69b9eb1..a55b6d1485 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -1011,8 +1011,8 @@ void SpiceManager::findCkCoverage(const std::string& path) { fmt::format("File '{}' does not exist", path) ); - constexpr unsigned int MaxObj = 256; - constexpr unsigned int WinSiz = 10000; + constexpr unsigned int MaxObj = 1024; + constexpr unsigned int WinSiz = 16384; #if defined __clang__ #pragma clang diagnostic push @@ -1070,8 +1070,8 @@ void SpiceManager::findSpkCoverage(const std::string& path) { fmt::format("File '{}' does not exist", path) ); - constexpr unsigned int MaxObj = 256; - constexpr unsigned int WinSiz = 10000; + constexpr unsigned int MaxObj = 1024; + constexpr unsigned int WinSiz = 16384; #if defined __clang__ #pragma clang diagnostic push From 773585565e1436416d275694ffc0012365b1f234 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 28 Jun 2021 13:10:42 +0200 Subject: [PATCH 12/44] Update SPICE library to N0066, build spice as static library to improve performance slightly --- ext/CMakeLists.txt | 1 + ext/spice | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 0010d35d22..797f419d56 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -54,6 +54,7 @@ set_folder_location(GhoulTest "Unit Tests") # Spice begin_dependency("Spice") +set(SPICE_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE) add_subdirectory(spice) set_folder_location(spice "External") end_dependency() diff --git a/ext/spice b/ext/spice index ba40ad2c25..e8a1cbeacc 160000 --- a/ext/spice +++ b/ext/spice @@ -1 +1 @@ -Subproject commit ba40ad2c25fe81e152a733b4a6afe53868388206 +Subproject commit e8a1cbeacc25a60fbed2f0958951a012ef6ba8e3 From 7aafe395830e9ff672bc6c25f0606df77390950f Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Mon, 28 Jun 2021 15:28:08 +0200 Subject: [PATCH 13/44] Add base texture or color to ModelProjection --- ext/ghoul | 2 +- .../rendering/renderablemodelprojection.cpp | 4 ++-- .../shaders/renderableModel_fs.glsl | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index c3c9b88e52..07b79ab570 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit c3c9b88e524228fb8613c310605cc2126ed9c5bd +Subproject commit 07b79ab57062077b624e190a109ff749fb242181 diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index aa54052e7c..d165d8da9e 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -344,7 +344,7 @@ void RenderableModelProjection::imageProjectGPU( _transform ); - _geometry->render(*_fboProgramObject, false); + _geometry->render(*_fboProgramObject, false, true); _depthFboProgramObject->deactivate(); _projectionComponent.depthMapRenderEnd(); @@ -374,7 +374,7 @@ void RenderableModelProjection::imageProjectGPU( _fboProgramObject->setUniform(_fboUniformCache.ModelTransform, _transform); _fboProgramObject->setUniform(_fboUniformCache.boresight, _boresight); - _geometry->render(*_fboProgramObject, false); + _geometry->render(*_fboProgramObject, false, true); _fboProgramObject->deactivate(); _projectionComponent.imageProjectEnd(); diff --git a/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl b/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl index 7e8b2e1f55..4b993d0366 100644 --- a/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl +++ b/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl @@ -30,7 +30,9 @@ in vec3 vs_normalViewSpace; in float vs_depth; in vec4 vs_positionCameraSpace; +uniform bool has_texture_diffuse; uniform sampler2D baseTexture; +uniform vec3 baseColor; uniform sampler2D projectionTexture; uniform bool performShading; uniform float projectionFading; @@ -44,7 +46,13 @@ const float specularIntensity = 0.0; const float specularPower = 100.0; Fragment getFragment() { - vec4 textureColor = texture(baseTexture, vs_st); + vec4 textureColor; + if (has_texture_diffuse) { + textureColor = texture(baseTexture, vs_st); + } + else { + textureColor.rgb = baseColor; + } vec4 projectionColor = texture(projectionTexture, vs_st); if (projectionColor.a > 0.0) { textureColor.rgb = mix( From 92c4837c6c908ff027a4a35a25a9f2ead400c260 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Mon, 28 Jun 2021 15:47:18 +0200 Subject: [PATCH 14/44] Correctly pass in the irradianceFactor into the inscatter radiance for atmosphere (closes #1660) --- modules/atmosphere/shaders/atmosphere_deferred_fs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl index 9be329d940..625769bdf4 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl @@ -244,7 +244,7 @@ Ray calculateRayRenderableGlobe(vec2 st) { * attenuation := out of transmittance T(x,x0). This will be used later when calculating * the reflectance R[L] */ -vec3 inscatterRadiance(vec3 x, inout float t, out float irradianceFactor, vec3 v, vec3 s, +vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 v, vec3 s, out float r, out float mu, out vec3 attenuation, vec3 fragPosObj, out bool groundHit, double maxLength, double pixelDepth, vec4 spaceColor, float sunIntensity) From 9dc2b3348b9afb27c463338019369a0975f9a17d Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Tue, 29 Jun 2021 10:06:19 +0200 Subject: [PATCH 15/44] Clean up --- include/openspace/util/coordinateconversion.h | 21 +++---- src/util/coordinateconversion.cpp | 59 ++++++++----------- 2 files changed, 35 insertions(+), 45 deletions(-) diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h index 009fd3c562..3df8c5af02 100644 --- a/include/openspace/util/coordinateconversion.h +++ b/include/openspace/util/coordinateconversion.h @@ -31,27 +31,27 @@ namespace openspace { /** - * Converts from ICRS coordinates to galactic cartesian coordinates. + * Converts from ICRS decimal degrees coordinates to galactic cartesian coordinates. * \param ra Right ascension, given in decimal degrees * \param dec Declination, given in decimal degrees * \param distance The distance, or radius, to the position given in any unit. - * \param boolean to say if the incoming ra and dec are in degrees or radians + * \param isDegrees Boolean to say if the incoming ra and dec are in degrees or radians * \return A position in galactic cartesian coordinates, given in the same unit as the * distance parameter. */ -glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, bool isDegrees = true); +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, + bool isDegrees = true); /** * Converts from ICRS (hms and dms) coordinates to decimal degrees. - * \param ra Right ascension, given as a string in format "XXhYYmZZs" - * \param dec Declination, given as a string in format "XXdYYmZZs", "-XXdYYmZZs", - * "XdYmZs" or "-XdYmZs" + * \param ra Right ascension, given as a string in format 'XhYmZs' + * \param dec Declination, given as a string in format 'XdYmZs' * \return The decimal degrees coordinate in degrees */ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec); /** - * Converts from galactic cartesian coordinates to ICRS coordinates in decimal degrees + * Converts from galactic cartesian coordinates to ICRS decimal degrees coordinates * and distance. * \param x X coordinate * \param y Y coordinate @@ -61,13 +61,14 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec); glm::dvec3 galacticCartesianToIcrs(double x, double y, double z); /** - * Converts from ICRS (decimal degrees) coordinates to ICRS (hms and dms) coordinates. + * Converts from ICRS decimal degrees coordinates to ICRS hms and dms coordinates. * \param ra Right ascension, given in decimal degrees * \param dec Declination, given in decimal degrees - * \param boolean to say if the incoming ra and dec are in degrees or radians + * \param isDegrees Boolean to say if the incoming ra and dec are in degrees or radians * \return A pair with the ra and dec strings in hms and dms format. */ -std::pair decimalDegreesToIcrs(double ra, double dec, bool isDegrees = true); +std::pair decimalDegreesToIcrs(double ra, double dec, + bool isDegrees = true); } // namespace openspace diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 9428119d76..5a90ccaf41 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -31,17 +31,17 @@ namespace { constexpr const char* _loggerCat = "Coordinateconversion"; + // J2000 Galactic reference frame + constexpr double A0 = glm::radians(192.8595); // Equatorial coordinates of the Galactic north pole + constexpr double D0 = glm::radians(27.1284); + constexpr double L0 = glm::radians(122.9320); // Galactic longitude of the equatorial north pole + void parseString(const std::string& str, int& hours_or_degrees, int& minutes, double& seconds) { // Find hms or dms indicies - size_t h_or_d_index; - if (str.find('h') != std::string::npos) { - h_or_d_index = str.find('h'); - } - else { - h_or_d_index = str.find('d'); - } + size_t h_or_d_index = + (str.find('h') != std::string::npos) ? str.find('h') : str.find('d'); size_t m_index = str.find('m'); size_t s_index = str.find('s'); if (h_or_d_index == std::string::npos || m_index == std::string::npos || @@ -104,8 +104,7 @@ namespace { { if (dec.find('h') != std::string::npos) { throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Dec '{}' format is incorrect. Correct format is: " - "Dec 'XXdYYmZZs', '-XXdYYmZZs', 'XdYmZs' or '-XdYmZs'", dec)) + "Dec '{}' format is incorrect. Correct format is: 'XdYmZs'", dec)) ); } parseString(dec, degrees, minutes, seconds); @@ -178,17 +177,12 @@ glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, double a = isDegrees ? glm::radians(ra) : ra; double d = isDegrees ? glm::radians(dec) : dec; - // J2000 Galactic reference frame - constexpr double a0 = glm::radians(192.8595); // Equatorial coordinates of the Galactic north pole - constexpr double d0 = glm::radians(27.1284); - constexpr double l0 = glm::radians(122.9320); // Galactic longitude of the equatorial north pole - // Convert to galactic reference frame - double l = l0 - atan2( - cos(d) * sin(a - a0), - sin(d) * cos(d0) - cos(d) * sin(d0) * cos(a - a0) + double l = L0 - atan2( + cos(d) * sin(a - A0), + sin(d) * cos(D0) - cos(d) * sin(D0) * cos(a - A0) ); - double b = asin(sin(d) * sin(d0) + cos(d) * cos(d0) * cos(a - a0)); + double b = asin(sin(d) * sin(D0) + cos(d) * cos(D0) * cos(a - A0)); // Convert to cartesian glm::dvec3 rGalactic = glm::dvec3( @@ -200,8 +194,9 @@ glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, return distance * rGalactic; } -// Ra format "XXhYYmZZs" or "XhYmZs" -// Dec format "XXdYYmZZs", "-XXdYYmZZs", "XdYmZs" or "-XdYmZs" +// Ra format 'XhYmZs', where X and Y are positive integers and Z is a positive double +// Dec format 'XdYmZs', where X is a signed integer, Y is a positive integer and Z is a +// positive double glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { // Reference: // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars @@ -230,7 +225,7 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { ); } - // Convert from hours, minutes, seconds to decimal degrees + // Convert from hours/degrees, minutes, seconds to decimal degrees double sign = signbit(static_cast(dec_degrees)) ? -1.0 : 1.0; double ra_deg = (ra_hours * 15.0) + (ra_minutes * 15.0 / 60.0) + @@ -243,15 +238,15 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { return glm::dvec2(ra_deg, dec_deg); } -// Convert Galactic coordinates (x, y, z) or (l, b) into -// Equatorial coordinates ICRS right ascension and declination (a, d) plus distance +// Convert Galactic coordinates (x, y, z) or (l, b) into Equatorial coordinates ICRS +// right ascension and declination in decimal degrees (a, d) plus distance glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { // References: // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, // https://en.wikipedia.org/wiki/Celestial_coordinate_system // Normalize - double distance = sqrt(x * x + y * y + z * z); + double distance = sqrt(x*x + y*y + z*z); double n_x = x / distance; double n_y = y / distance; double n_z = z / distance; @@ -261,20 +256,14 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { double l = atan2(n_y, n_x); double b = asin(n_z); - // J2000 Galactic reference frame - constexpr double a0 = glm::radians(192.8595); // Equatorial coordinates of the Galactic north pole - constexpr double d0 = glm::radians(27.1284); - constexpr double l0 = glm::radians(122.9320); // Galactic longitude of the equatorial north pole - // Convert to equatorial reference frame double a = atan2( - cos(b) * sin(l0 - l), - sin(b) * cos(d0) - cos(b) * sin(d0) * cos(l0 - l) - ) + a0; - double d = asin(sin(b) * sin(d0) + cos(b) * cos(d0) * cos(l0 - l)); + cos(b) * sin(L0 - l), + sin(b) * cos(D0) - cos(b) * sin(D0) * cos(L0 - l) + ) + A0; + double d = asin(sin(b) * sin(D0) + cos(b) * cos(D0) * cos(L0 - l)); - glm::dvec3 rEquatorial = glm::dvec3(glm::degrees(a), glm::degrees(d), distance); - return rEquatorial; + return glm::dvec3(glm::degrees(a), glm::degrees(d), distance); } // Return a pair with two formatted strings from the decimal degrees ra and dec From 9ef67d30c8e2247109d813537ec6d5a25af30b73 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Tue, 29 Jun 2021 10:42:12 +0200 Subject: [PATCH 16/44] Remove redundant includes --- modules/space/spacemodule_lua.inl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/space/spacemodule_lua.inl b/modules/space/spacemodule_lua.inl index 696b9dd344..e9e25c8513 100644 --- a/modules/space/spacemodule_lua.inl +++ b/modules/space/spacemodule_lua.inl @@ -22,11 +22,6 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include -#include -#include -#include -#include #include namespace openspace::space::luascriptfunctions { From 0d259b195c252bca03c2bf736d41263b3f2cafc3 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Tue, 29 Jun 2021 10:48:22 +0200 Subject: [PATCH 17/44] Update Ra Dec conversion lua function documentation --- modules/space/spacemodule.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 98d4a88be4..99810f9d8d 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -144,7 +144,7 @@ scripting::LuaLibrary SpaceModule::luaLibrary() const { "convertFromRaDec", &space::luascriptfunctions::convertFromRaDec, {}, - "string, string, double", + "string, string, double [, bool]", "Returns the cartesian world position of a ra dec coordinate with distance" }, { @@ -152,7 +152,7 @@ scripting::LuaLibrary SpaceModule::luaLibrary() const { &space::luascriptfunctions::convertToRaDec, {}, "double, double, double", - "Returns the ra, dec strings and distance for a given cartesian world coordinate" + "Returns the formatted ra, dec strings and distance for a given cartesian world coordinate" } }; From 20aa307ece1bfbff1e79de76c2a4b9ac89cf389e Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 1 Jul 2021 15:27:09 +0200 Subject: [PATCH 18/44] Feature/sun position atmosphere (#1673) * General atmosphere cleanup * Make sun projection originate from Sun position instead of SSB (closes #1695) --- .../rendering/atmospheredeferredcaster.cpp | 51 ++++---- .../rendering/atmospheredeferredcaster.h | 6 +- .../shaders/atmosphere_deferred_fs.glsl | 118 +++++++++--------- 3 files changed, 85 insertions(+), 90 deletions(-) diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 33bb35fab1..1cf0fc71ce 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -74,8 +74,8 @@ namespace { "cullAtmosphere", "Rg", "Rt", "groundRadianceEmission", "HR", "betaRayleigh", "HM", "betaMieExtinction", "mieG", "sunRadiance", "ozoneLayerEnabled", "HO", "betaOzoneExtinction", "SAMPLES_R", "SAMPLES_MU", "SAMPLES_MU_S", "SAMPLES_NU", - "dInverseModelTransformMatrix", "dModelTransformMatrix", - "dSgctProjectionToModelTransformMatrix", "dSGCTViewToWorldMatrix", "dCamPosObj", + "inverseModelTransformMatrix", "modelTransformMatrix", + "projectionToModelTransformMatrix", "viewToWorldMatrix", "camPosObj", "sunDirectionObj", "hardShadows", "transmittanceTexture", "irradianceTexture", "inscatterTexture" }; @@ -309,53 +309,38 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, // Object Space glm::dmat4 inverseModelMatrix = glm::inverse(_modelTransform); program.setUniform( - _uniformCache.dInverseModelTransformMatrix, - inverseModelMatrix + _uniformCache.inverseModelTransformMatrix, inverseModelMatrix ); - program.setUniform(_uniformCache.dModelTransformMatrix, _modelTransform); + program.setUniform(_uniformCache.modelTransformMatrix, _modelTransform); - // Eye Space in SGCT to Eye Space in OS (SGCT View to OS Camera Rig) -// glm::dmat4 dSgctEye2OSEye = glm::inverse( -// glm::dmat4(renderData.camera.viewMatrix())); - - glm::dmat4 dSGCTViewToWorldMatrix = glm::inverse( + glm::dmat4 viewToWorldMatrix = glm::inverse( renderData.camera.combinedViewMatrix() ); - // Eye Space in SGCT to OS World Space - program.setUniform( - _uniformCache.dSGCTViewToWorldMatrix, - dSGCTViewToWorldMatrix - ); + // Eye Space to World Space + program.setUniform(_uniformCache.viewToWorldMatrix, viewToWorldMatrix); - // SGCT Projection to SGCT Eye Space + // Projection to Eye Space glm::dmat4 dInverseProjection = glm::inverse( glm::dmat4(renderData.camera.projectionMatrix()) ); glm::dmat4 inverseWholeMatrixPipeline = - inverseModelMatrix * dSGCTViewToWorldMatrix * dInverseProjection; + inverseModelMatrix * viewToWorldMatrix * dInverseProjection; program.setUniform( - _uniformCache.dSgctProjectionToModelTransformMatrix, + _uniformCache.projectionToModelTransformMatrix, inverseWholeMatrixPipeline ); glm::dvec4 camPosObjCoords = inverseModelMatrix * glm::dvec4(renderData.camera.eyePositionVec3(), 1.0); - program.setUniform(_uniformCache.dCamPosObj, camPosObjCoords); + program.setUniform(_uniformCache.camPosObj, glm::dvec3(camPosObjCoords)); + + SceneGraphNode* node = sceneGraph()->sceneGraphNode("Sun"); + glm::dvec3 sunPosWorld = node ? node->worldPosition() : glm::dvec3(0.0); - double lt; - glm::dvec3 sunPosWorld = SpiceManager::ref().targetPosition( - "SUN", - "SSB", - "GALACTIC", - {}, - _time, - lt - ); glm::dvec4 sunPosObj; - // Sun following camera position if (_sunFollowingCameraEnabled) { sunPosObj = inverseModelMatrix * glm::dvec4( @@ -365,7 +350,10 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, } else { sunPosObj = inverseModelMatrix * - glm::dvec4(sunPosWorld - renderData.modelTransform.translation, 1.0); + glm::dvec4( + (sunPosWorld - renderData.modelTransform.translation) * 1000.0, + 1.0 + ); } // Sun Position in Object Space @@ -374,6 +362,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, glm::normalize(glm::dvec3(sunPosObj)) ); + ghoul::opengl::updateUniformLocations(program, _uniformCache, UniformNames); + // Shadow calculations.. if (!_shadowConfArray.empty()) { ZoneScopedN("Shadow Configuration") @@ -384,6 +374,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, // TO REMEMBER: all distances and lengths in world coordinates are in // meters!!! We need to move this to view space... // Getting source and caster: + double lt; glm::dvec3 sourcePos = SpiceManager::ref().targetPosition( shadowConf.source.first, "SSB", diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.h b/modules/atmosphere/rendering/atmospheredeferredcaster.h index dd8ce176a9..589d2479c7 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.h +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.h @@ -126,9 +126,9 @@ private: UniformCache(cullAtmosphere, Rg, Rt, groundRadianceEmission, HR, betaRayleigh, HM, betaMieExtinction, mieG, sunRadiance, ozoneLayerEnabled, HO, betaOzoneExtinction, - SAMPLES_R, SAMPLES_MU, SAMPLES_MU_S, SAMPLES_NU, dInverseModelTransformMatrix, - dModelTransformMatrix, dSgctProjectionToModelTransformMatrix, - dSGCTViewToWorldMatrix, dCamPosObj, sunDirectionObj, hardShadows, + SAMPLES_R, SAMPLES_MU, SAMPLES_MU_S, SAMPLES_NU, inverseModelTransformMatrix, + modelTransformMatrix, projectionToModelTransformMatrix, + viewToWorldMatrix, camPosObj, sunDirectionObj, hardShadows, transmittanceTexture, irradianceTexture, inscatterTexture) _uniformCache; GLuint _transmittanceTableTexture = 0; diff --git a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl index 625769bdf4..f0f97c8de1 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl @@ -62,7 +62,6 @@ in vec2 texCoord; out vec4 renderTarget; -uniform int nAaSamples; uniform int cullAtmosphere; uniform sampler2D irradianceTexture; @@ -71,17 +70,21 @@ uniform sampler2D mainPositionTexture; uniform sampler2D mainNormalTexture; uniform sampler2D mainColorTexture; -uniform dmat4 dInverseModelTransformMatrix; -uniform dmat4 dModelTransformMatrix; -uniform dmat4 dSGCTViewToWorldMatrix; -uniform dmat4 dSgctProjectionToModelTransformMatrix; +uniform dmat4 inverseModelTransformMatrix; +uniform dmat4 modelTransformMatrix; +uniform dmat4 viewToWorldMatrix; +uniform dmat4 projectionToModelTransformMatrix; uniform vec4 viewport; uniform vec2 resolution; -uniform dvec4 dCamPosObj; +uniform dvec3 camPosObj; uniform dvec3 sunDirectionObj; +uniform dvec3 sunWorld; +uniform dvec3 viewDirWorld; +uniform dvec3 sunModel; + /******************************************************************************* ***** ALL CALCULATIONS FOR ECLIPSE ARE IN METERS AND IN WORLD SPACE SYSTEM **** *******************************************************************************/ @@ -215,13 +218,13 @@ Ray calculateRayRenderableGlobe(vec2 st) { dvec4 clipCoords = dvec4(interpolatedNDCPos, 1.0, 1.0); // Clip to Object Coords - dvec4 objectCoords = dSgctProjectionToModelTransformMatrix * clipCoords; - objectCoords /= objectCoords.w; + dvec4 objectCoords = projectionToModelTransformMatrix * clipCoords; + objectCoords.xyz /= objectCoords.w; // Building Ray // Ray in object space (in KM) Ray ray; - ray.origin = dvec3(dCamPosObj * dvec4(0.001, 0.001, 0.001, 1.0)); + ray.origin = camPosObj * 0.001; ray.direction = normalize(objectCoords.xyz * dvec3(0.001) - ray.origin); return ray; } @@ -245,15 +248,14 @@ Ray calculateRayRenderableGlobe(vec2 st) { * the reflectance R[L] */ vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 v, vec3 s, - out float r, out float mu, out vec3 attenuation, vec3 fragPosObj, + float r, out float mu, out vec3 attenuation, vec3 fragPosObj, out bool groundHit, double maxLength, double pixelDepth, - vec4 spaceColor, float sunIntensity) + vec3 spaceColor, float sunIntensity) { const float INTERPOLATION_EPS = 0.004; // precision const from Brunetton vec3 radiance; - r = length(x); mu = dot(x, v) / r; float r2 = r * r; @@ -303,16 +305,15 @@ vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 } // cos(PI-thetaH) = dist/r - // cos(thetaH) = - dist/r + // cos(thetaH) = -dist/r // muHorizon = -sqrt(r^2-Rg^2)/r = -sqrt(1-(Rg/r)^2) float muHorizon = -sqrt(1.0 - Rg2 / r2); - // In order to avoid imprecision problems near horizon, we interpolate between two + // In order to avoid precision problems near horizon, we interpolate between two // points: above and below horizon if (abs(mu - muHorizon) < INTERPOLATION_EPS) { // We want an interpolation value close to 1/2, so the contribution of each radiance - // value is almost the same or it has a heavy weight if from above or - // below horizon + // value is almost the same or it has a heavy weight if from above or below horizon float interpolationValue = (mu - muHorizon + INTERPOLATION_EPS) / (2.0 * INTERPOLATION_EPS); // Above Horizon @@ -321,9 +322,9 @@ vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 // From cosine law where t = distance between x and x0 // r0^2 = r^2 + t^2 - 2 * r * t * cos(PI-theta) // r0 = sqrt(r2 + t2 + 2.0f * r * t * mu); - float halfCossineLaw1 = r2 + (t * t); - float halfCossineLaw2 = 2.0 * r * t; - r0 = sqrt(halfCossineLaw1 + halfCossineLaw2 * mu); + float halfCosineLaw1 = r2 + (t * t); + float halfCosineLaw2 = 2.0 * r * t; + r0 = sqrt(halfCosineLaw1 + halfCosineLaw2 * mu); // From the dot product: cos(theta0) = (x0 dot v)/(||ro||*||v||) // mu0 = ((x + t) dot v) / r0 @@ -339,7 +340,7 @@ vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 // Below Horizon mu = muHorizon + INTERPOLATION_EPS; //r0 = sqrt(r2 + t2 + 2.0f * r * t * mu); - r0 = sqrt(halfCossineLaw1 + halfCossineLaw2 * mu); + r0 = sqrt(halfCosineLaw1 + halfCosineLaw2 * mu); mu0 = (r * mu + t) * (1.0 / r0); @@ -374,7 +375,7 @@ vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 return finalScatteringRadiance; } else { - return spaceColor.rgb + finalScatteringRadiance; + return spaceColor + finalScatteringRadiance; } } @@ -457,16 +458,23 @@ vec3 groundColor(vec3 x, float t, vec3 v, vec3 s, vec3 attenuationXtoX0, vec3 gr * attenuation := transmittance T(x,x0) */ vec3 sunColor(vec3 v, vec3 s, float r, float mu, float irradianceFactor) { - vec3 tm = vec3(1.0); - if (r <= Rt) { - tm = mu < -sqrt(1.0 - Rg2 / (r * r)) ? vec3(0.0) : transmittance(r, mu); - } - // JCC: Change this function to a impostor texture with gaussian decay color weighted - // by the sunRadiance, transmittance and irradianceColor (11/03/2017) - float sunFinalColor = smoothstep(cos(M_PI / 500.0), cos(M_PI / 900.0), dot(v, s)) * - sunRadiance * (1.0 - irradianceFactor); + // v = normalize(vec3(inverseModelTransformMatrix * dvec4(sunWorld, 1.0))); + float angle = dot(v, s); - return tm * sunFinalColor; + // JCC: Change this function to a impostor texture with gaussian decay color weighted + // by the sunRadiance, transmittance and irradianceColor (11/03/2017) + + // @TODO (abock, 2021-07-01) This value is hard-coded to our sun right now + // Convert 0.3 degrees -> radians + const float SunAngularSize = (0.3 * M_PI / 180.0); + const float FuzzyFactor = 0.5; // How fuzzy should the edges be + + const float p1 = cos(SunAngularSize); + const float p2 = cos(SunAngularSize * FuzzyFactor); + + float t = (angle - p1) / (p2 - p1); + float scale = clamp(t, 0.0, 1.0); + return scale * transmittance(r, mu) * sunRadiance * (1.0 - irradianceFactor); } void main() { @@ -481,17 +489,13 @@ void main() { st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); + // Color from G-Buffer + vec3 color = texture(mainColorTexture, st).rgb; if (cullAtmosphere == 1) { - renderTarget = texture(mainColorTexture, st); + renderTarget.rgb = color; return; } - vec4 atmosphereFinalColor = vec4(0.0); - int nSamples = 1; - - // Color from G-Buffer - vec4 color = texture(mainColorTexture, st); - // Get the ray from camera to atm in object space Ray ray = calculateRayRenderableGlobe(texCoord); @@ -499,7 +503,7 @@ void main() { double maxLength = 0.0; // in KM bool intersect = atmosphereIntersection(ray, Rt - (ATM_EPSILON * 0.001), offset, maxLength); if (!intersect) { - renderTarget = color; + renderTarget.rgb = color; return; } @@ -509,14 +513,11 @@ void main() { // Space (View plus Camera Rig Coords) when using their positions later, one must // convert them to the planet's coords - // - // Get data from G-Buffer - - // Normal is stored in SGCT View Space and transformed to the current object space + // Normal is stored in view space and transformed to the current object space vec4 normalViewSpaceAndWaterReflectance = texture(mainNormalTexture, st); dvec4 normalViewSpace = vec4(normalViewSpaceAndWaterReflectance.xyz, 0.0); - dvec4 normalWorldSpace = dSGCTViewToWorldMatrix * normalViewSpace; - vec4 normal = vec4(dInverseModelTransformMatrix * normalWorldSpace); + dvec4 normalWorldSpace = viewToWorldMatrix * normalViewSpace; + vec4 normal = vec4(inverseModelTransformMatrix * normalWorldSpace); normal.xyz = normalize(normal.xyz); normal.w = normalViewSpaceAndWaterReflectance.w; @@ -524,19 +525,20 @@ void main() { vec4 position = texture(mainPositionTexture, st); // OS Eye to World coords - dvec4 positionWorldCoords = dSGCTViewToWorldMatrix * position; + dvec4 positionWorldCoords = viewToWorldMatrix * position; // World to Object (Normal and Position in meters) - dvec4 positionObjectsCoords = dInverseModelTransformMatrix * positionWorldCoords; + dvec3 positionObjectsCoords = (inverseModelTransformMatrix * positionWorldCoords).xyz; // Distance of the pixel in the gBuffer to the observer // JCC (12/12/2017): AMD distance function is buggy. //double pixelDepth = distance(cameraPositionInObject.xyz, positionObjectsCoords.xyz); - double pixelDepth = length(dCamPosObj.xyz - positionObjectsCoords.xyz); + double pixelDepth = length(camPosObj - positionObjectsCoords); // JCC (12/13/2017): Trick to remove floating error in texture. // We see a squared noise on planet's surface when seeing the planet from far away - float dC = float(length(dCamPosObj.xyz)); + // @TODO (abock, 2021-07-01) I don't think this does anything. Remove? + float dC = float(length(camPosObj)); const float x1 = 1e8; if (dC > x1) { pixelDepth += 1000.0; @@ -552,22 +554,21 @@ void main() { // All calculations are done in KM: pixelDepth *= 0.001; - positionObjectsCoords.xyz *= 0.001; + positionObjectsCoords *= 0.001; if (pixelDepth < offset) { // ATM Occluded - Something in front of ATM - renderTarget = color; + renderTarget.rgb = color; return; } // Following paper nomenclature double t = offset; - vec3 attenuation; // Moving observer from camera location to top atmosphere. If the observer is already // inside the atm, offset = 0.0 and no changes at all vec3 x = vec3(ray.origin + t * ray.direction); - float r = 0.0; // length(x); + float r = length(x); vec3 v = vec3(ray.direction); float mu = 0.0; // dot(x, v) / r; vec3 s = vec3(sunDirectionObj); @@ -578,27 +579,30 @@ void main() { // comparison with the planet's ground make sense: pixelDepth -= offset; - dvec3 onATMPos = (dModelTransformMatrix * dvec4(x * 1000.0, 1.0)).xyz; + dvec3 onATMPos = (modelTransformMatrix * dvec4(x * 1000.0, 1.0)).xyz; float eclipseShadowATM = calcShadow(shadowDataArray, onATMPos, false); float sunIntensityInscatter = sunRadiance * eclipseShadowATM; float irradianceFactor = 0.0; bool groundHit = false; + vec3 attenuation; + vec3 inscatterColor = inscatterRadiance(x, tF, irradianceFactor, v, s, r, mu, - attenuation, vec3(positionObjectsCoords.xyz), groundHit, maxLength, pixelDepth, - color, sunIntensityInscatter); + attenuation, vec3(positionObjectsCoords), groundHit, maxLength, pixelDepth, + color, sunIntensityInscatter); vec3 atmColor = vec3(0.0); if (groundHit) { float eclipseShadowPlanet = calcShadow(shadowDataArray, positionWorldCoords.xyz, true); float sunIntensityGround = sunRadiance * eclipseShadowPlanet; - atmColor = groundColor(x, tF, v, s, attenuation, color.rgb, normal.xyz, + atmColor = groundColor(x, tF, v, s, attenuation, color, normal.xyz, irradianceFactor, normal.w, sunIntensityGround); } else { // In order to get better performance, we are not tracing multiple rays per pixel // when the ray doesn't intersect the ground - atmColor = sunColor(v, s, r, mu, irradianceFactor); + + atmColor = sunColor(v, s, r, mu, irradianceFactor); } // Final Color of ATM plus terrain: From 21204e83674bc27c04bc61d4115a72119e6b1e41 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Thu, 1 Jul 2021 17:38:28 +0200 Subject: [PATCH 19/44] Address PR comments --- include/openspace/util/coordinateconversion.h | 8 +- modules/space/spacemodule.cpp | 10 +- modules/space/spacemodule_lua.inl | 14 +- src/util/coordinateconversion.cpp | 199 +++++++++--------- 4 files changed, 115 insertions(+), 116 deletions(-) diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h index 3df8c5af02..798f45e6e2 100644 --- a/include/openspace/util/coordinateconversion.h +++ b/include/openspace/util/coordinateconversion.h @@ -35,12 +35,10 @@ namespace openspace { * \param ra Right ascension, given in decimal degrees * \param dec Declination, given in decimal degrees * \param distance The distance, or radius, to the position given in any unit. - * \param isDegrees Boolean to say if the incoming ra and dec are in degrees or radians * \return A position in galactic cartesian coordinates, given in the same unit as the * distance parameter. */ -glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, - bool isDegrees = true); +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance); /** * Converts from ICRS (hms and dms) coordinates to decimal degrees. @@ -64,11 +62,9 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z); * Converts from ICRS decimal degrees coordinates to ICRS hms and dms coordinates. * \param ra Right ascension, given in decimal degrees * \param dec Declination, given in decimal degrees - * \param isDegrees Boolean to say if the incoming ra and dec are in degrees or radians * \return A pair with the ra and dec strings in hms and dms format. */ -std::pair decimalDegreesToIcrs(double ra, double dec, - bool isDegrees = true); +std::pair decimalDegreesToIcrs(double ra, double dec); } // namespace openspace diff --git a/modules/space/spacemodule.cpp b/modules/space/spacemodule.cpp index 99810f9d8d..bac8d687b9 100644 --- a/modules/space/spacemodule.cpp +++ b/modules/space/spacemodule.cpp @@ -144,15 +144,19 @@ scripting::LuaLibrary SpaceModule::luaLibrary() const { "convertFromRaDec", &space::luascriptfunctions::convertFromRaDec, {}, - "string, string, double [, bool]", - "Returns the cartesian world position of a ra dec coordinate with distance" + "string/double, string/double, double", + "Returns the cartesian world position of a ra dec coordinate with distance. " + "If the coordinate is given as strings the format should be ra 'XhYmZs' and " + "dec 'XdYmZs'. If the coordinate is given as numbers the values should be " + "in degrees." }, { "convertToRaDec", &space::luascriptfunctions::convertToRaDec, {}, "double, double, double", - "Returns the formatted ra, dec strings and distance for a given cartesian world coordinate" + "Returns the formatted ra, dec strings and distance for a given cartesian " + "world coordinate." } }; diff --git a/modules/space/spacemodule_lua.inl b/modules/space/spacemodule_lua.inl index e9e25c8513..881a191afe 100644 --- a/modules/space/spacemodule_lua.inl +++ b/modules/space/spacemodule_lua.inl @@ -27,21 +27,17 @@ namespace openspace::space::luascriptfunctions { int convertFromRaDec(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, { 3, 4 }, "lua::convertFromRaDec"); + ghoul::lua::checkArgumentsAndThrow(L, 3, "lua::convertFromRaDec"); glm::dvec2 degrees = glm::dvec2(0.0); - bool isDegrees = true; if (lua_type(L, 1) == LUA_TSTRING && lua_type(L, 2) == LUA_TSTRING) { - std::string s_ra = ghoul::lua::value(L, 1); - std::string s_dec = ghoul::lua::value(L, 2); - degrees = icrsToDecimalDegrees(s_ra, s_dec); + std::string ra = ghoul::lua::value(L, 1); + std::string dec = ghoul::lua::value(L, 2); + degrees = icrsToDecimalDegrees(ra, dec); } else if (lua_type(L, 1) == LUA_TNUMBER && lua_type(L, 2) == LUA_TNUMBER) { degrees.x = ghoul::lua::value(L, 1); degrees.y = ghoul::lua::value(L, 2); - if (lua_gettop(L) >= 4) { - isDegrees = ghoul::lua::value(L, 4); - } } else { throw ghoul::lua::LuaRuntimeException("lua::convertFromRaDec: Ra and Dec have to " @@ -52,7 +48,7 @@ int convertFromRaDec(lua_State* L) { double distance = ghoul::lua::value(L, 3); lua_settop(L, 0); - glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance, isDegrees); + glm::dvec3 pos = icrsToGalacticCartesian(degrees.x, degrees.y, distance); ghoul::lua::push(L, pos); ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 5a90ccaf41..b2d65f47e1 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -36,65 +36,60 @@ namespace { constexpr double D0 = glm::radians(27.1284); constexpr double L0 = glm::radians(122.9320); // Galactic longitude of the equatorial north pole - void parseString(const std::string& str, int& hours_or_degrees, int& minutes, + void parseString(const std::string& str, int& hoursOrDegrees, int& minutes, double& seconds) { // Find hms or dms indicies - size_t h_or_d_index = + size_t hOrDIndex = (str.find('h') != std::string::npos) ? str.find('h') : str.find('d'); - size_t m_index = str.find('m'); - size_t s_index = str.find('s'); - if (h_or_d_index == std::string::npos || m_index == std::string::npos || - s_index == std::string::npos) + size_t mIndex = str.find('m'); + size_t sIndex = str.find('s'); + if (hOrDIndex == std::string::npos || mIndex == std::string::npos || + sIndex == std::string::npos) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( + throw ghoul::lua::LuaRuntimeException(fmt::format( "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " - "and Dec 'XdYmZs'", str)) - ); + "and Dec 'XdYmZs'", str)); } // Construct the number strings - std::string s_hours_or_degrees = str.substr(0, h_or_d_index); - std::string s_minutes = str.substr(h_or_d_index + 1, m_index - h_or_d_index - 1); - std::string s_seconds = str.substr(m_index + 1, s_index - m_index - 1); + std::string sHoursOrDegrees = str.substr(0, hOrDIndex); + std::string sMinutes = str.substr(hOrDIndex + 1, mIndex - hOrDIndex - 1); + std::string sSeconds = str.substr(mIndex + 1, sIndex - mIndex - 1); // Convert the strings to numbers try { // Hours or degrees must be an integer - double temp = std::stod(s_hours_or_degrees); + double temp = std::stod(sHoursOrDegrees); if (std::floor(temp) != temp) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( + throw ghoul::lua::LuaRuntimeException(fmt::format( "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " - "and Dec 'XdYmZs', where X must be an integer", str)) - ); + "and Dec 'XdYmZs', where X must be an integer", str)); } - hours_or_degrees = std::stoi(s_hours_or_degrees); + hoursOrDegrees = std::stoi(sHoursOrDegrees); // Minutes must be an integer - temp = std::stod(s_minutes); + temp = std::stod(sMinutes); if (std::floor(temp) != temp) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( + throw ghoul::lua::LuaRuntimeException(fmt::format( "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " - "and Dec 'XdYmZs', where Y must be an integer", str)) - ); + "and Dec 'XdYmZs', where Y must be an integer", str)); } - minutes = std::stoi(s_minutes); + minutes = std::stoi(sMinutes); // Seconds is a double - seconds = std::stod(s_seconds); + seconds = std::stod(sSeconds); } catch (const std::invalid_argument& ia) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( + throw ghoul::lua::LuaRuntimeException(fmt::format( "Ra or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " - "and Dec 'XdYmZs'", str)) - ); + "and Dec 'XdYmZs'", str)); } } void parseRa(const std::string& ra, int& hours, int& minutes, double& seconds) { if (ra.find('d') != std::string::npos) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Ra '{}' format is incorrect. Correct format is: 'XhYmZs'", ra)) - ); + throw ghoul::lua::LuaRuntimeException(fmt::format( + "Ra '{}' format is incorrect. Correct format is: 'XhYmZs'", ra)); } parseString(ra, hours, minutes, seconds); } @@ -103,58 +98,57 @@ namespace { double& seconds) { if (dec.find('h') != std::string::npos) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( - "Dec '{}' format is incorrect. Correct format is: 'XdYmZs'", dec)) - ); + throw ghoul::lua::LuaRuntimeException(fmt::format( + "Dec '{}' format is incorrect. Correct format is: 'XdYmZs'", dec)); } parseString(dec, degrees, minutes, seconds); } - bool isRaDecValid(int ra_h, int ra_m, double ra_s, int dec_d, - int dec_m, double dec_s) + bool isRaDecValid(int raH, int raM, double raS, int decD, + int decM, double decS) { // Ra - if (ra_h < 0.0 || ra_h >= 24.0) { + if (raH < 0.0 || raH >= 24.0) { LWARNING(fmt::format("Right ascension hours '{}' is outside the allowed " - "range of 0 to 24 hours (exclusive)", ra_h) + "range of 0 to 24 hours (exclusive)", raH) ); return false; } - if (ra_m < 0.0 || ra_m >= 60.0) { + if (raM < 0.0 || raM >= 60.0) { LWARNING(fmt::format("Right ascension minutes '{}' is outside the allowed " - "range of 0 to 60 minutes (exclusive)", ra_m) + "range of 0 to 60 minutes (exclusive)", raM) ); return false; } - if (ra_s < 0.0 || ra_s >= 60.0) { + if (raS < 0.0 || raS >= 60.0) { LWARNING(fmt::format("Right ascension seconds '{}' is outside the allowed " - "range of 0 to 60 seconds (exclusive)", ra_s) + "range of 0 to 60 seconds (exclusive)", raS) ); return false; } // Dec - if (dec_d < -90.0 || dec_d > 90.0) { + if (decD < -90.0 || decD > 90.0) { LWARNING(fmt::format("Declination degrees '{}' is outside the allowed range " - "of -90 to 90 degrees (inclusive)", dec_d) + "of -90 to 90 degrees (inclusive)", decD) ); return false; } - else if ((dec_d == -90.0 || dec_d == 90.0) && (dec_m != 0 || dec_s != 0)) { + else if ((decD == -90.0 || decD == 90.0) && (decM != 0 || decS != 0)) { LWARNING("Total declination is outside the allowed range of -90 to 90 " "degrees (inclusive)" ); return false; } - if (dec_m < 0.0 || dec_m >= 60.0) { + if (decM < 0.0 || decM >= 60.0) { LWARNING(fmt::format("Declination minutes '{}' is outside the allowed range " - "of 0 to 60 minutes (exclusive)", dec_m) + "of 0 to 60 minutes (exclusive)", decM) ); return false; } - if (dec_s < 0.0 || dec_s >= 60.0) { + if (decS < 0.0 || decS >= 60.0) { LWARNING(fmt::format("Declination seconds '{}' is outside the allowed range " - "of 0 to 60 seconds (exclusive)", dec_s) + "of 0 to 60 seconds (exclusive)", decS) ); return false; } @@ -167,15 +161,14 @@ namespace openspace { // Convert Equatorial coordinates ICRS right ascension and declination (a, d) // into Galactic coordinates (l, b) -glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance, - bool isDegrees) +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { // Reference: // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php // (Ra, Dec) -> (a, d) - double a = isDegrees ? glm::radians(ra) : ra; - double d = isDegrees ? glm::radians(dec) : dec; + double a = glm::radians(ra); + double d = glm::radians(dec); // Convert to galactic reference frame double l = L0 - atan2( @@ -201,41 +194,46 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { // Reference: // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars if (ra.size() < 6 || dec.size() < 6) { - throw(ghoul::lua::LuaRuntimeException(fmt::format( + throw ghoul::lua::LuaRuntimeException(fmt::format( "Ra '{}' or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " - "and Dec 'XdYmZs'", ra, dec) - )); + "and Dec 'XdYmZs'", ra, dec)); } // Parse right ascension - int ra_hours, ra_minutes; - double ra_seconds; - parseRa(ra, ra_hours, ra_minutes, ra_seconds); + int raHours, raMinutes; + double raSeconds; + parseRa(ra, raHours, raMinutes, raSeconds); // Parse declination - int dec_degrees, dec_minutes; - double dec_seconds; - parseDec(dec, dec_degrees, dec_minutes, dec_seconds); + int decDegrees, decMinutes; + double decSeconds; + parseDec(dec, decDegrees, decMinutes, decSeconds); - if (!isRaDecValid(ra_hours, ra_minutes, ra_seconds, dec_degrees, dec_minutes, - dec_seconds)) - { + const bool isValid = isRaDecValid(raHours, + raMinutes, + raSeconds, + decDegrees, + decMinutes, + decSeconds + ); + + if (!isValid) { LWARNING(fmt::format("Ra '{}' or Dec '{}' is outside the allowed range, " "result may be incorrect", ra, dec) ); } // Convert from hours/degrees, minutes, seconds to decimal degrees - double sign = signbit(static_cast(dec_degrees)) ? -1.0 : 1.0; - double ra_deg = (ra_hours * 15.0) + - (ra_minutes * 15.0 / 60.0) + - (ra_seconds * 15.0 / 3600.0); + double sign = signbit(static_cast(decDegrees)) ? -1.0 : 1.0; + double raDeg = (raHours * 15.0) + + (raMinutes * 15.0 / 60.0) + + (raSeconds * 15.0 / 3600.0); - double dec_deg = (abs(dec_degrees) + - (dec_minutes / 60.0) + - (dec_seconds / 3600.0)) * sign; + double decDeg = (abs(decDegrees) + + (decMinutes / 60.0) + + (decSeconds / 3600.0)) * sign; - return glm::dvec2(ra_deg, dec_deg); + return glm::dvec2(raDeg, decDeg); } // Convert Galactic coordinates (x, y, z) or (l, b) into Equatorial coordinates ICRS @@ -247,14 +245,14 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { // Normalize double distance = sqrt(x*x + y*y + z*z); - double n_x = x / distance; - double n_y = y / distance; - double n_z = z / distance; + double nX = x / distance; + double nY = y / distance; + double nZ = z / distance; // Convert from cartesian // (x, y, z) -> (l, b) - double l = atan2(n_y, n_x); - double b = asin(n_z); + double l = atan2(nY, nX); + double b = asin(nZ); // Convert to equatorial reference frame double a = atan2( @@ -267,50 +265,55 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { } // Return a pair with two formatted strings from the decimal degrees ra and dec -std::pair decimalDegreesToIcrs(double ra, double dec, - bool isDegrees) +std::pair decimalDegreesToIcrs(double ra, double dec) { // References: // https://www.rapidtables.com/convert/number/degrees-to-degrees-minutes-seconds.html, // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars // Radians to degrees - double ra_deg = isDegrees ? ra : glm::degrees(ra); - double dec_deg = isDegrees ? dec : glm::degrees(dec); + double raDeg = ra; + double decDeg = dec; // Check input - if (ra_deg < 0 || ra_deg > 360 || dec_deg < -90 || dec_deg > 90) { + if (raDeg < 0 || raDeg > 360 || decDeg < -90 || decDeg > 90) { LWARNING(fmt::format("Given Ra '{}' or Dec '{}' is outside the allowed range, " "result may be incorrect", ra, dec) ); } // Calculate Ra - int ra_hours = std::trunc(ra_deg) / 15.0; - double ra_minutes_full = (ra_deg - ra_hours * 15.0) * 60.0 / 15.0; - int ra_minutes = std::trunc(ra_minutes_full); - double ra_seconds = (ra_minutes_full - ra_minutes) * 60.0; + int raHours = std::trunc(raDeg) / 15.0; + double raMinutesFull = (raDeg - raHours * 15.0) * 60.0 / 15.0; + int raMinutes = std::trunc(raMinutesFull); + double raSeconds = (raMinutesFull - raMinutes) * 60.0; // Calculate Dec - int dec_degrees = std::trunc(dec_deg); - double dec_minutes_full = (abs(dec_deg) - abs(dec_degrees)) * 60.0; - int dec_minutes = std::trunc(dec_minutes_full); - double dec_seconds = (dec_minutes_full - dec_minutes) * 60.0; + int decDegrees = std::trunc(decDeg); + double decMinutesFull = (abs(decDeg) - abs(decDegrees)) * 60.0; + int decMinutes = std::trunc(decMinutesFull); + double decSeconds = (decMinutesFull - decMinutes) * 60.0; // Construct strings std::pair result; - result.first = std::to_string(ra_hours) + 'h' + - std::to_string(ra_minutes) + 'm' + - std::to_string(ra_seconds) + 's'; + result.first = std::to_string(raHours) + 'h' + + std::to_string(raMinutes) + 'm' + + std::to_string(raSeconds) + 's'; - result.second = std::to_string(dec_degrees) + 'd' + - std::to_string(dec_minutes) + 'm' + - std::to_string(dec_seconds) + 's'; + result.second = std::to_string(decDegrees) + 'd' + + std::to_string(decMinutes) + 'm' + + std::to_string(decSeconds) + 's'; // Check results - if (!isRaDecValid(ra_hours, ra_minutes, ra_seconds, dec_degrees, dec_minutes, - dec_seconds)) - { + const bool isValid = isRaDecValid(raHours, + raMinutes, + raSeconds, + decDegrees, + decMinutes, + decSeconds + ); + + if (!isValid) { LWARNING(fmt::format("Resulting Ra '{}' or Dec '{}' is outside the allowed range, " "result may be incorrect", result.first, result.second) ); From dbffe34395cbbf3de3b34f35a3a5a73be694691f Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Thu, 1 Jul 2021 17:45:28 +0200 Subject: [PATCH 20/44] Address PR comments --- modules/spacecraftinstruments/shaders/renderableModel_fs.glsl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl b/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl index 4b993d0366..04684b086b 100644 --- a/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl +++ b/modules/spacecraftinstruments/shaders/renderableModel_fs.glsl @@ -51,7 +51,7 @@ Fragment getFragment() { textureColor = texture(baseTexture, vs_st); } else { - textureColor.rgb = baseColor; + textureColor = vec4(baseColor, 1.0); } vec4 projectionColor = texture(projectionTexture, vs_st); if (projectionColor.a > 0.0) { From 87da9a27abb3b43a26260a176574fe907fb4b544 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Thu, 1 Jul 2021 23:46:22 +0200 Subject: [PATCH 21/44] Feature/path normalization (#1674) * Path normalization (making sure there are fewer cases of '"..."' * Using more std::filesystem::path instead of std::string * Update Ghoul --- ext/ghoul | 2 +- include/openspace/scripting/scriptengine.h | 5 +- modules/base/basemodule.cpp | 1 + .../rendering/renderableplaneimagelocal.cpp | 2 +- .../rendering/renderableplaneimageonline.cpp | 76 ++++++++++--------- modules/base/rendering/renderableprism.cpp | 8 +- modules/base/rendering/renderablesphere.cpp | 2 +- modules/base/rotation/luarotation.cpp | 6 +- modules/base/scale/luascale.cpp | 6 +- modules/base/translation/luatranslation.cpp | 6 +- .../rendering/renderablebillboardscloud.cpp | 2 +- .../rendering/renderabledumeshes.cpp | 6 +- .../rendering/renderableplanescloud.cpp | 12 +-- .../rendering/renderableplanescloud.h | 9 +-- .../rendering/renderablepoints.cpp | 14 ++-- .../rendering/renderablepoints.h | 5 +- modules/exoplanets/exoplanetshelper.cpp | 3 +- modules/exoplanets/exoplanetsmodule_lua.inl | 4 +- .../util/kameleonfieldlinehelper.cpp | 10 +-- .../fitsfilereader/include/fitsfilereader.h | 10 ++- modules/fitsfilereader/src/fitsfilereader.cpp | 18 +++-- .../gaia/rendering/renderablegaiastars.cpp | 41 +++++----- modules/gaia/rendering/renderablegaiastars.h | 10 +-- modules/gaia/tasks/readfilejob.cpp | 6 +- modules/galaxy/rendering/renderablegalaxy.cpp | 19 +++-- modules/galaxy/rendering/renderablegalaxy.h | 2 +- .../src/globelabelscomponent.cpp | 24 +++--- .../globebrowsing/src/globelabelscomponent.h | 8 +- modules/globebrowsing/src/ringscomponent.cpp | 21 ++--- modules/imgui/src/gui.cpp | 6 +- .../rendering/renderablekameleonvolume.cpp | 6 +- .../rendering/renderablekameleonvolume.h | 4 +- .../rendering/errorhistogrammanager.cpp | 4 +- .../rendering/errorhistogrammanager.h | 5 +- .../rendering/histogrammanager.cpp | 4 +- .../rendering/histogrammanager.h | 5 +- .../rendering/localerrorhistogrammanager.cpp | 4 +- .../rendering/localerrorhistogrammanager.h | 5 +- .../rendering/renderablemultiresvolume.cpp | 42 +++++----- modules/multiresvolume/rendering/tsp.cpp | 4 +- modules/space/rendering/renderablestars.cpp | 9 +-- modules/space/speckloader.cpp | 24 +++--- .../space/translation/horizonstranslation.cpp | 29 ++++--- .../space/translation/horizonstranslation.h | 4 +- .../util/labelparser.cpp | 4 +- modules/volume/rawvolumereader.h | 9 ++- modules/volume/rawvolumereader.inl | 11 ++- modules/volume/rawvolumewriter.h | 7 +- modules/volume/rawvolumewriter.inl | 5 +- src/engine/openspaceengine.cpp | 2 +- src/engine/openspaceengine_lua.inl | 5 +- src/rendering/luaconsole.cpp | 10 ++- src/rendering/texturecomponent.cpp | 2 +- src/scene/asset.cpp | 4 +- src/scripting/scriptengine.cpp | 15 ++-- src/util/spicemanager.cpp | 14 ++-- 56 files changed, 299 insertions(+), 282 deletions(-) diff --git a/ext/ghoul b/ext/ghoul index c3c9b88e52..3bc645938a 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit c3c9b88e524228fb8613c310605cc2126ed9c5bd +Subproject commit 3bc645938a9c8a7a804ebf53e65cd374cc5bef25 diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 94a187e1ca..e6c0c23607 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -31,9 +31,10 @@ #include #include #include +#include #include -#include #include +#include #include namespace openspace { class SyncBuffer; } @@ -82,7 +83,7 @@ public: bool hasLibrary(const std::string& name); bool runScript(const std::string& script, ScriptCallback callback = ScriptCallback()); - bool runScriptFile(const std::string& filename); + bool runScriptFile(const std::filesystem::path& filename); bool writeLog(const std::string& script); diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 67f2332629..048bbc0d45 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -213,6 +213,7 @@ std::vector BaseModule::documentations() const { ScreenSpaceImageLocal::Documentation(), ScreenSpaceImageOnline::Documentation(), + ConstantRotation::Documentation(), FixedRotation::Documentation(), LuaRotation::Documentation(), StaticRotation::Documentation(), diff --git a/modules/base/rendering/renderableplaneimagelocal.cpp b/modules/base/rendering/renderableplaneimagelocal.cpp index 7b48b72bb5..6f6d88cacd 100644 --- a/modules/base/rendering/renderableplaneimagelocal.cpp +++ b/modules/base/rendering/renderableplaneimagelocal.cpp @@ -196,7 +196,7 @@ void RenderablePlaneImageLocal::loadTexture() { LDEBUGC( "RenderablePlaneImageLocal", - fmt::format("Loaded texture from '{}'", absPath(path)) + fmt::format("Loaded texture from {}", absPath(path)) ); texture->uploadTexture(); texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); diff --git a/modules/base/rendering/renderableplaneimageonline.cpp b/modules/base/rendering/renderableplaneimageonline.cpp index 8ce7be472e..998790b581 100644 --- a/modules/base/rendering/renderableplaneimageonline.cpp +++ b/modules/base/rendering/renderableplaneimageonline.cpp @@ -96,53 +96,55 @@ void RenderablePlaneImageOnline::bindTexture() { } void RenderablePlaneImageOnline::update(const UpdateData&) { - if (_textureIsDirty) { - if (!_imageFuture.valid()) { - std::future future = downloadImageToMemory( - _texturePath + if (!_textureIsDirty) { + return; + } + + if (!_imageFuture.valid()) { + std::future future = downloadImageToMemory( + _texturePath + ); + if (future.valid()) { + _imageFuture = std::move(future); + } + } + + if (_imageFuture.valid() && DownloadManager::futureReady(_imageFuture)) { + DownloadManager::MemoryFile imageFile = _imageFuture.get(); + + if (imageFile.corrupted) { + LERRORC( + "ScreenSpaceImageOnline", + fmt::format("Error loading image from URL '{}'", _texturePath) ); - if (future.valid()) { - _imageFuture = std::move(future); - } + return; } - if (_imageFuture.valid() && DownloadManager::futureReady(_imageFuture)) { - DownloadManager::MemoryFile imageFile = _imageFuture.get(); - - if (imageFile.corrupted) { - LERRORC( - "ScreenSpaceImageOnline", - fmt::format("Error loading image from URL '{}'", _texturePath) + try { + std::unique_ptr texture = + ghoul::io::TextureReader::ref().loadTexture( + reinterpret_cast(imageFile.buffer), + imageFile.size, + imageFile.format ); - return; - } - try { - std::unique_ptr texture = - ghoul::io::TextureReader::ref().loadTexture( - reinterpret_cast(imageFile.buffer), - imageFile.size, - imageFile.format - ); + if (texture) { + // Images don't need to start on 4-byte boundaries, for example if the + // image is only RGB + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (texture) { - // Images don't need to start on 4-byte boundaries, for example if the - // image is only RGB - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + texture->uploadTexture(); + texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); + texture->purgeFromRAM(); - texture->uploadTexture(); - texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - texture->purgeFromRAM(); - - _texture = std::move(texture); - _textureIsDirty = false; - } - } - catch (const ghoul::io::TextureReader::InvalidLoadException& e) { + _texture = std::move(texture); _textureIsDirty = false; - LERRORC(e.component, e.message); } } + catch (const ghoul::io::TextureReader::InvalidLoadException& e) { + _textureIsDirty = false; + LERRORC(e.component, e.message); + } } } diff --git a/modules/base/rendering/renderableprism.cpp b/modules/base/rendering/renderableprism.cpp index 7c96247b21..20f610d3c8 100644 --- a/modules/base/rendering/renderableprism.cpp +++ b/modules/base/rendering/renderableprism.cpp @@ -268,8 +268,8 @@ void RenderablePrism::updateVertexData() { _indexArray.push_back(255); // Indices for Top shape - for (uint8_t i = _nShapeSegments; i < 2 * _nShapeSegments; ++i) { - _indexArray.push_back(i); + for (int i = _nShapeSegments; i < 2 * _nShapeSegments; ++i) { + _indexArray.push_back(static_cast(i)); } // Indices for connecting lines @@ -277,8 +277,8 @@ void RenderablePrism::updateVertexData() { // Reset _indexArray.push_back(255); - _indexArray.push_back(2 * _nShapeSegments + k); - _indexArray.push_back(2 * _nShapeSegments + k + 1); + _indexArray.push_back(static_cast(2 * _nShapeSegments + k)); + _indexArray.push_back(static_cast(2 * _nShapeSegments + k + 1)); } } diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index e6b32389be..4d05f81f3d 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -452,7 +452,7 @@ void RenderableSphere::loadTexture() { if (texture) { LDEBUGC( "RenderableSphere", - fmt::format("Loaded texture from '{}'", absPath(_texturePath)) + fmt::format("Loaded texture from {}", absPath(_texturePath)) ); texture->uploadTexture(); texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); diff --git a/modules/base/rotation/luarotation.cpp b/modules/base/rotation/luarotation.cpp index 86d9e8d619..b2d019e305 100644 --- a/modules/base/rotation/luarotation.cpp +++ b/modules/base/rotation/luarotation.cpp @@ -79,7 +79,7 @@ LuaRotation::LuaRotation(const ghoul::Dictionary& dictionary) : LuaRotation() { } glm::dmat3 LuaRotation::matrix(const UpdateData& data) const { - ghoul::lua::runScriptFile(_state, _luaScriptFile); + ghoul::lua::runScriptFile(_state, _luaScriptFile.value()); // Get the scaling function lua_getglobal(_state, "rotation"); @@ -87,7 +87,9 @@ glm::dmat3 LuaRotation::matrix(const UpdateData& data) const { if (!isFunction) { LERRORC( "LuaRotation", - fmt::format("Script '{}' does nto have a function 'rotation'", _luaScriptFile) + fmt::format( + "Script '{}' does not have a function 'rotation'", _luaScriptFile.value() + ) ); return glm::dmat3(1.0); } diff --git a/modules/base/scale/luascale.cpp b/modules/base/scale/luascale.cpp index f99600595e..8eb44f4b47 100644 --- a/modules/base/scale/luascale.cpp +++ b/modules/base/scale/luascale.cpp @@ -77,7 +77,7 @@ LuaScale::LuaScale(const ghoul::Dictionary& dictionary) : LuaScale() { } glm::dvec3 LuaScale::scaleValue(const UpdateData& data) const { - ghoul::lua::runScriptFile(_state, _luaScriptFile); + ghoul::lua::runScriptFile(_state, _luaScriptFile.value()); // Get the scaling function lua_getglobal(_state, "scale"); @@ -85,7 +85,9 @@ glm::dvec3 LuaScale::scaleValue(const UpdateData& data) const { if (!isFunction) { LERRORC( "LuaScale", - fmt::format("Script '{}' does not have a function 'scale'", _luaScriptFile) + fmt::format( + "Script '{}' does not have a function 'scale'", _luaScriptFile.value() + ) ); return glm::dvec3(1.0); } diff --git a/modules/base/translation/luatranslation.cpp b/modules/base/translation/luatranslation.cpp index 2f853e8394..d0873b550a 100644 --- a/modules/base/translation/luatranslation.cpp +++ b/modules/base/translation/luatranslation.cpp @@ -81,7 +81,7 @@ LuaTranslation::LuaTranslation(const ghoul::Dictionary& dictionary) : LuaTransla } glm::dvec3 LuaTranslation::position(const UpdateData& data) const { - ghoul::lua::runScriptFile(_state, _luaScriptFile); + ghoul::lua::runScriptFile(_state, _luaScriptFile.value()); // Get the scaling function lua_getglobal(_state, "translation"); @@ -91,7 +91,7 @@ glm::dvec3 LuaTranslation::position(const UpdateData& data) const { "LuaScale", fmt::format( "Script '{}' does not have a function 'translation'", - _luaScriptFile + _luaScriptFile.value() ) ); return glm::dvec3(0.0); @@ -119,7 +119,7 @@ glm::dvec3 LuaTranslation::position(const UpdateData& data) const { double values[3]; for (int i = 1; i <= 3; ++i) { - values[i] = ghoul::lua::value(_state, i); + values[i - 1] = ghoul::lua::value(_state, i); } return glm::make_vec3(values); diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 4113d606ff..8b334a02e6 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -970,7 +970,7 @@ void RenderableBillboardsCloud::update(const UpdateData&) { _spriteTexture = DigitalUniverseModule::TextureManager.request( std::to_string(hash), [path = _spriteTexturePath]() -> std::unique_ptr { - LINFO(fmt::format("Loaded texture from '{}'", absPath(path))); + LINFO(fmt::format("Loaded texture from {}", absPath(path))); std::unique_ptr t = ghoul::io::TextureReader::ref().loadTexture(absPath(path).string()); t->uploadTexture(); diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index b7e0a708df..9fc7d78962 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -484,7 +484,7 @@ void RenderableDUMeshes::update(const UpdateData&) { bool RenderableDUMeshes::loadData() { bool success = false; if (_hasSpeckFile) { - LINFO(fmt::format("Loading Speck file '{}'", _speckFile)); + LINFO(fmt::format("Loading Speck file {}", std::filesystem::path(_speckFile))); success = readSpeckFile(); if (!success) { return false; @@ -502,7 +502,9 @@ bool RenderableDUMeshes::loadData() { bool RenderableDUMeshes::readSpeckFile() { std::ifstream file(_speckFile); if (!file.good()) { - LERROR(fmt::format("Failed to open Speck file '{}'", _speckFile)); + LERROR(fmt::format( + "Failed to open Speck file {}", std::filesystem::path(_speckFile) + )); return false; } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 1e54b6a7c7..18d0117607 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -272,7 +272,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary addProperty(_opacity); if (p.file.has_value()) { - _speckFile = absPath(*p.file).string(); + _speckFile = absPath(*p.file); _hasSpeckFile = true; _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); addProperty(_drawElements); @@ -320,7 +320,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _scaleFactor.onChange([&]() { _dataIsDirty = true; }); if (p.labelFile.has_value()) { - _labelFile = absPath(*p.labelFile).string(); + _labelFile = absPath(*p.labelFile); _hasLabel = true; _textColor = p.textColor.value_or(_textColor); @@ -368,7 +368,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary } } - _texturesPath = absPath(p.texturePath).string(); + _texturesPath = absPath(p.texturePath); _luminosityVar = p.luminosity.value_or(_luminosityVar); _sluminosity = p.scaleLuminosity.value_or(_sluminosity); @@ -403,7 +403,7 @@ void RenderablePlanesCloud::initialize() { } if (!_labelFile.empty()) { - LINFO(fmt::format("Loading Label file '{}'", _labelFile)); + LINFO(fmt::format("Loading Label file {}", _labelFile)); _labelset = speck::label::loadFileWithCache(_labelFile); for (speck::Labelset::Entry& e : _labelset.entries) { e.position = glm::vec3(_transformationMatrix * glm::dvec4(e.position, 1.0)); @@ -612,7 +612,7 @@ void RenderablePlanesCloud::update(const UpdateData&) { void RenderablePlanesCloud::loadTextures() { for (const speck::Dataset::Texture& tex : _dataset.textures) { - std::filesystem::path fullPath = absPath(_texturesPath + '/' + tex.file); + std::filesystem::path fullPath = absPath(_texturesPath.string() + '/' + tex.file); std::filesystem::path pngPath = fullPath; pngPath.replace_extension(".png"); @@ -634,7 +634,7 @@ void RenderablePlanesCloud::loadTextures() { ghoul::io::TextureReader::ref().loadTexture(path.string()); if (t) { - LINFOC("RenderablePlanesCloud", fmt::format("Loaded texture '{}'", path)); + LINFOC("RenderablePlanesCloud", fmt::format("Loaded texture {}", path)); t->uploadTexture(); t->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); t->purgeFromRAM(); diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index de2d2386cd..b669e1e168 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -34,10 +34,9 @@ #include #include #include - #include #include - +#include #include #include @@ -129,9 +128,9 @@ private: std::unordered_map _textureFileMap; std::unordered_map _planesMap; - std::string _speckFile; - std::string _labelFile; - std::string _texturesPath; + std::filesystem::path _speckFile; + std::filesystem::path _labelFile; + std::filesystem::path _texturesPath; std::string _luminosityVar; Unit _unit = Parsec; diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index 286e247d96..e3449d0095 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -135,7 +135,7 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) addProperty(_opacity); registerUpdateRenderBinFromOpacity(); - _speckFile = absPath(p.file).string(); + _speckFile = absPath(p.file); if (p.unit.has_value()) { switch (*p.unit) { @@ -185,7 +185,7 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) } if (p.colorMap.has_value()) { - _colorMapFile = absPath(*p.colorMap).string(); + _colorMapFile = absPath(*p.colorMap); _hasColorMapFile = true; } @@ -347,9 +347,9 @@ void RenderablePoints::update(const UpdateData&) { absPath(_spriteTexturePath).string() ); if (_spriteTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'",absPath(_spriteTexturePath) - )); + LDEBUG( + fmt::format("Loaded texture from {}", absPath(_spriteTexturePath)) + ); _spriteTexture->uploadTexture(); } _spriteTexture->setFilter( @@ -369,7 +369,7 @@ void RenderablePoints::readColorMapFile() { std::ifstream file(_colorMapFile); if (!file.good()) { throw ghoul::RuntimeError(fmt::format( - "Failed to open Color Map file '{}'", _colorMapFile + "Failed to open Color Map file {}", _colorMapFile )); } @@ -396,7 +396,7 @@ void RenderablePoints::readColorMapFile() { } else if (file.eof()) { throw ghoul::RuntimeError(fmt::format( - "Failed to load colors from Color Map file '{}'", _colorMapFile + "Failed to load colors from Color Map file {}", _colorMapFile )); } } diff --git a/modules/digitaluniverse/rendering/renderablepoints.h b/modules/digitaluniverse/rendering/renderablepoints.h index 0f7c4f1361..2f8d3047b0 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.h +++ b/modules/digitaluniverse/rendering/renderablepoints.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace ghoul::filesystem { class File; } @@ -95,8 +96,8 @@ private: spriteTexture, hasColorMap ) _uniformCache; - std::string _speckFile; - std::string _colorMapFile; + std::filesystem::path _speckFile; + std::filesystem::path _colorMapFile; Unit _unit = Parsec; diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index f538f73f6f..6ec7f2866c 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -65,8 +65,7 @@ glm::vec3 computeStarColor(float bv) { if (!colorMap.good()) { LERROR(fmt::format( - "Failed to open colormap data file: '{}'", - absPath(bvColormapPath) + "Failed to open colormap data file: {}", absPath(bvColormapPath) )); return glm::vec3(0.f); } diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 6ee47f1d7a..f5359e9dbe 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -158,8 +158,8 @@ void createExoplanetSystem(const std::string& starName) { const glm::vec3 starPosInParsec = system.starData.position; if (!isValidPosition(starPosInParsec)) { LERROR(fmt::format( - "Insufficient data available for exoplanet system: '{}'. " - "Could not determine star position", starName + "Insufficient data available for exoplanet system: '{}'. Could not determine " + "star position", starName )); return; } diff --git a/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp b/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp index 7b18d0579d..6646797433 100644 --- a/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp +++ b/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp @@ -303,8 +303,10 @@ void prepareStateAndKameleonForExtras(ccmc::Kameleon* kameleon, if (!success && (model == fls::Model::Batsrus && (str == TAsPOverRho || str == "T"))) { - LDEBUG("BATSRUS doesn't contain variable T for temperature. Trying to " - "calculate it using the ideal gas law: T = pressure/density"); + LDEBUG( + "BATSRUS doesn't contain variable T for temperature. Trying to calculate " + "it using the ideal gas law: T = pressure/density" + ); constexpr const char* p = "p"; constexpr const char* r = "rho"; success = kameleon->doesVariableExist(p) && kameleon->loadVariable(p) && @@ -312,9 +314,7 @@ void prepareStateAndKameleonForExtras(ccmc::Kameleon* kameleon, str = TAsPOverRho; } if (!success) { - LWARNING(fmt::format( - "Failed to load extra variable: '{}'. Ignoring", str - )); + LWARNING(fmt::format("Failed to load extra variable: '{}'. Ignoring", str)); extraScalarVars.erase(extraScalarVars.begin() + i); --i; } diff --git a/modules/fitsfilereader/include/fitsfilereader.h b/modules/fitsfilereader/include/fitsfilereader.h index 9418fc42fb..e3909d5f93 100644 --- a/modules/fitsfilereader/include/fitsfilereader.h +++ b/modules/fitsfilereader/include/fitsfilereader.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_MODULE_FITSFILEREADER___FITSFILEREADER___H__ #define __OPENSPACE_MODULE_FITSFILEREADER___FITSFILEREADER___H__ +#include #include #include #include @@ -63,7 +64,7 @@ public: ~FitsFileReader(); template - std::shared_ptr> readImage(const std::string& path); + std::shared_ptr> readImage(const std::filesystem::path& path); template std::shared_ptr> readHeader( @@ -78,7 +79,7 @@ public: * If no HDU index is given the current Extension HDU will be read from. */ template - std::shared_ptr> readTable(std::string& path, + std::shared_ptr> readTable(const std::filesystem::path& path, const std::vector& columnNames, int startRow = 1, int endRow = 10, int hduIdx = 1, bool readAll = false); @@ -88,7 +89,7 @@ public: * If additional columns are given by filterColumnNames, they will be * read but it will slow doen the reading tremendously. */ - std::vector readFitsFile(std::string filePath, int& nValuesPerStar, + std::vector readFitsFile(std::filesystem::path filePath, int& nValuesPerStar, int firstRow, int lastRow, std::vector filterColumnNames, int multiplier = 1); @@ -96,7 +97,8 @@ public: * Reads a single SPECK file and returns a vector with nRenderValues * per star. Reads data in pre-defined order based on AMNH's star data files. */ - std::vector readSpeckFile(const std::string& filePath, int& nRenderValues); + std::vector readSpeckFile(const std::filesystem::path& filePath, + int& nRenderValues); private: std::unique_ptr _infile; diff --git a/modules/fitsfilereader/src/fitsfilereader.cpp b/modules/fitsfilereader/src/fitsfilereader.cpp index 26e945fad3..f273326e82 100644 --- a/modules/fitsfilereader/src/fitsfilereader.cpp +++ b/modules/fitsfilereader/src/fitsfilereader.cpp @@ -69,7 +69,8 @@ bool FitsFileReader::isPrimaryHDU() { } template -std::shared_ptr> FitsFileReader::readImage(const std::string& path) { +std::shared_ptr> FitsFileReader::readImage(const std::filesystem::path& path) +{ try { _infile = std::make_unique(path, Read, true); // Primary HDU Object @@ -136,7 +137,7 @@ std::shared_ptr FitsFileReader::readHeaderValue(const std::string key) { } template -std::shared_ptr> FitsFileReader::readTable(std::string& path, +std::shared_ptr> FitsFileReader::readTable(const std::filesystem::path& path, const std::vector& columnNames, int startRow, int endRow, @@ -148,7 +149,7 @@ std::shared_ptr> FitsFileReader::readTable(std::string& path, std::lock_guard g(_mutex); try { - _infile = std::make_unique(path, Read, readAll); + _infile = std::make_unique(path.string(), Read, readAll); // Make sure FITS file is not a Primary HDU Object (aka an image). if (!isPrimaryHDU()) { @@ -191,8 +192,9 @@ std::shared_ptr> FitsFileReader::readTable(std::string& path, return nullptr; } -std::vector FitsFileReader::readFitsFile(std::string filePath, int& nValuesPerStar, - int firstRow, int lastRow, +std::vector FitsFileReader::readFitsFile(std::filesystem::path filePath, + int& nValuesPerStar, int firstRow, + int lastRow, std::vector filterColumnNames, int multiplier) { @@ -245,7 +247,7 @@ std::vector FitsFileReader::readFitsFile(std::string filePath, int& nValu ); if (!table) { - throw ghoul::RuntimeError(fmt::format("Failed to open Fits file '{}'", filePath)); + throw ghoul::RuntimeError(fmt::format("Failed to open Fits file {}", filePath)); } int nStars = table->readRows - firstRow + 1; @@ -520,7 +522,7 @@ std::vector FitsFileReader::readFitsFile(std::string filePath, int& nValu return fullData; } -std::vector FitsFileReader::readSpeckFile(const std::string& filePath, +std::vector FitsFileReader::readSpeckFile(const std::filesystem::path& filePath, int& nRenderValues) { std::vector fullData; @@ -528,7 +530,7 @@ std::vector FitsFileReader::readSpeckFile(const std::string& filePath, std::ifstream fileStream(filePath); if (!fileStream.good()) { - LERROR(fmt::format("Failed to open Speck file '{}'", filePath)); + LERROR(fmt::format("Failed to open Speck file {}", filePath)); return fullData; } diff --git a/modules/gaia/rendering/renderablegaiastars.cpp b/modules/gaia/rendering/renderablegaiastars.cpp index 2971318b53..44e8d3f579 100644 --- a/modules/gaia/rendering/renderablegaiastars.cpp +++ b/modules/gaia/rendering/renderablegaiastars.cpp @@ -2131,9 +2131,7 @@ void RenderableGaiaStars::update(const UpdateData&) { absPath(_colorTexturePath).string() ); if (_colorTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'", absPath(_colorTexturePath) - )); + LDEBUG(fmt::format("Loaded texture from {}", absPath(_colorTexturePath))); _colorTexture->uploadTexture(); } @@ -2188,28 +2186,29 @@ bool RenderableGaiaStars::readDataFile() { _octreeManager.initOctree(_cpuRamBudgetInBytes); - LINFO("Loading data file: " + _filePath.value()); + std::filesystem::path file = absPath(_filePath.value()); + LINFO(fmt::format("Loading data file: {}", file)); switch (fileReaderOption) { case gaia::FileReaderOption::Fits: // Read raw fits file and construct Octree. - nReadStars = readFitsFile(_filePath); + nReadStars = readFitsFile(file); break; case gaia::FileReaderOption::Speck: // Read raw speck file and construct Octree. - nReadStars = readSpeckFile(_filePath); + nReadStars = readSpeckFile(file); break; case gaia::FileReaderOption::BinaryRaw: // Stars are stored in an ordered binary file. - nReadStars = readBinaryRawFile(_filePath); + nReadStars = readBinaryRawFile(file); break; case gaia::FileReaderOption::BinaryOctree: // Octree already constructed and stored as a binary file. - nReadStars = readBinaryOctreeFile(_filePath); + nReadStars = readBinaryOctreeFile(file); break; case gaia::FileReaderOption::StreamOctree: // Read Octree structure from file, without data. - nReadStars = readBinaryOctreeStructureFile(_filePath); + nReadStars = readBinaryOctreeStructureFile(file.string()); break; default: LERROR("Wrong FileReaderOption - no data file loaded!"); @@ -2218,13 +2217,13 @@ bool RenderableGaiaStars::readDataFile() { //_octreeManager->printStarsPerNode(); _nRenderedStars.setMaxValue(nReadStars); - LINFO("Dataset contains a total of " + std::to_string(nReadStars) + " stars."); + LINFO(fmt::format("Dataset contains a total of {} stars", nReadStars)); _totalDatasetSizeInBytes = nReadStars * (PositionSize + ColorSize + VelocitySize) * 4; return nReadStars > 0; } -int RenderableGaiaStars::readFitsFile(const std::string& filePath) { +int RenderableGaiaStars::readFitsFile(const std::filesystem::path& filePath) { int nReadValuesPerStar = 0; FitsFileReader fitsFileReader(false); @@ -2248,7 +2247,7 @@ int RenderableGaiaStars::readFitsFile(const std::string& filePath) { return static_cast(fullData.size() / nReadValuesPerStar); } -int RenderableGaiaStars::readSpeckFile(const std::string& filePath) { +int RenderableGaiaStars::readSpeckFile(const std::filesystem::path& filePath) { int nReadValuesPerStar = 0; FitsFileReader fileReader(false); @@ -2266,7 +2265,7 @@ int RenderableGaiaStars::readSpeckFile(const std::string& filePath) { return static_cast(fullData.size() / nReadValuesPerStar); } -int RenderableGaiaStars::readBinaryRawFile(const std::string& filePath) { +int RenderableGaiaStars::readBinaryRawFile(const std::filesystem::path& filePath) { std::vector fullData; int nReadStars = 0; @@ -2299,14 +2298,14 @@ int RenderableGaiaStars::readBinaryRawFile(const std::string& filePath) { } else { LERROR(fmt::format( - "Error opening file '{}' for loading raw binary file!", filePath + "Error opening file '{}' for loading raw binary file", filePath )); return nReadStars; } return nReadStars; } -int RenderableGaiaStars::readBinaryOctreeFile(const std::string& filePath) { +int RenderableGaiaStars::readBinaryOctreeFile(const std::filesystem::path& filePath) { int nReadStars = 0; std::ifstream fileStream(filePath, std::ifstream::binary); @@ -2317,26 +2316,28 @@ int RenderableGaiaStars::readBinaryOctreeFile(const std::string& filePath) { } else { LERROR(fmt::format( - "Error opening file '{}' for loading binary Octree file!", filePath + "Error opening file '{}' for loading binary Octree file", filePath )); return nReadStars; } return nReadStars; } -int RenderableGaiaStars::readBinaryOctreeStructureFile(const std::string& folderPath) { +int RenderableGaiaStars::readBinaryOctreeStructureFile( + const std::filesystem::path& folderPath) +{ int nReadStars = 0; - std::string indexFile = folderPath + "index.bin"; + std::string indexFile = folderPath.string() + "index.bin"; std::ifstream fileStream(indexFile, std::ifstream::binary); if (fileStream.good()) { - nReadStars = _octreeManager.readFromFile(fileStream, false, folderPath); + nReadStars = _octreeManager.readFromFile(fileStream, false, folderPath.string()); fileStream.close(); } else { LERROR(fmt::format( - "Error opening file '{}' for loading binary Octree file!", indexFile + "Error opening file '{}' for loading binary Octree file", indexFile )); return nReadStars; } diff --git a/modules/gaia/rendering/renderablegaiastars.h b/modules/gaia/rendering/renderablegaiastars.h index 09508f0e94..cda54a9772 100644 --- a/modules/gaia/rendering/renderablegaiastars.h +++ b/modules/gaia/rendering/renderablegaiastars.h @@ -78,28 +78,28 @@ private: * * \return the number of stars read. */ - int readFitsFile(const std::string& filePath); + int readFitsFile(const std::filesystem::path& filePath); /** * Read a SPECK file by using FitsFileReader.readSpeckFile() and constructs an octree. * * \return the number of stars read. */ - int readSpeckFile(const std::string& filePath); + int readSpeckFile(const std::filesystem::path& filePath); /** * Reads a preprocessed binary file and constructs an octree. * * \return the number of stars read. */ - int readBinaryRawFile(const std::string& filePath); + int readBinaryRawFile(const std::filesystem::path& filePath); /** * Reads a pre-constructed octree, with all data, from a binary file. * * \return the number of stars read. */ - int readBinaryOctreeFile(const std::string& filePath); + int readBinaryOctreeFile(const std::filesystem::path& filePath); /** * Reads the structure of a pre-constructed octree from a binary file, without any @@ -107,7 +107,7 @@ private: * * \return the number of stars read. */ - int readBinaryOctreeStructureFile(const std::string& folderPath); + int readBinaryOctreeStructureFile(const std::filesystem::path& folderPath); /** * Checks for any OpenGL errors and reports these to the log if _reportGlErrors is diff --git a/modules/gaia/tasks/readfilejob.cpp b/modules/gaia/tasks/readfilejob.cpp index 12e0ea1b08..b2cb6030fa 100644 --- a/modules/gaia/tasks/readfilejob.cpp +++ b/modules/gaia/tasks/readfilejob.cpp @@ -68,8 +68,10 @@ void ReadFileJob::execute() { int nNullArr = 0; size_t nColumnsRead = _allColumns.size(); if (nColumnsRead != _nDefaultCols) { - LINFO("Additional columns will be read! Consider add column in code for " - "significant speedup!"); + LINFO( + "Additional columns will be read! Consider add column in code for " + "significant speedup" + ); } // Copy columns to local variables. diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 6cb9da54ee..062cab243d 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -182,14 +182,15 @@ namespace { #include "renderablegalaxy_codegen.cpp" - void saveCachedFile(const std::string& file, const std::vector& positions, + void saveCachedFile(const std::filesystem::path& file, + const std::vector& positions, const std::vector& colors, int64_t nPoints, float pointsRatio) { std::ofstream fileStream(file, std::ofstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for save cache file", file)); + LERROR(fmt::format("Error opening file {} for save cache file", file)); return; } @@ -321,13 +322,13 @@ void RenderableGalaxy::initialize() { ); _volume = reader.read(); - std::string cachedPointsFile = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cachedPointsFile = FileSys.cacheManager()->cachedFilename( _pointsFilename ); const bool hasCachedFile = std::filesystem::is_regular_file(cachedPointsFile); if (hasCachedFile) { - LINFO(fmt::format("Cached file '{}' used for galaxy point file '{}'", - cachedPointsFile, _pointsFilename + LINFO(fmt::format("Cached file {} used for galaxy point file {}", + cachedPointsFile, std::filesystem::path(_pointsFilename) )); Result res = loadCachedFile(cachedPointsFile); @@ -730,17 +731,19 @@ RenderableGalaxy::Result RenderableGalaxy::loadPointFile() { return res; } -RenderableGalaxy::Result RenderableGalaxy::loadCachedFile(const std::string& file) { +RenderableGalaxy::Result RenderableGalaxy::loadCachedFile( + const std::filesystem::path& file) +{ std::ifstream fileStream(file, std::ifstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for loading cache file", file)); + LERROR(fmt::format("Error opening file {} for loading cache file", file)); return { false, {}, {} }; } int8_t cacheVersion; fileStream.read(reinterpret_cast(&cacheVersion), sizeof(int8_t)); if (cacheVersion != CurrentCacheVersion) { - LINFO(fmt::format("Removing cache file '{}' as the version changed")); + LINFO(fmt::format("Removing cache file {} as the version changed", file)); return { false, {}, {} }; } diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 45dbcd1df7..55c3b4cbba 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -64,7 +64,7 @@ private: std::vector color; }; Result loadPointFile(); - Result loadCachedFile(const std::string& file); + Result loadCachedFile(const std::filesystem::path& file); glm::vec3 _volumeSize = glm::vec3(0.f); glm::vec3 _pointScaling = glm::vec3(0.f); diff --git a/modules/globebrowsing/src/globelabelscomponent.cpp b/modules/globebrowsing/src/globelabelscomponent.cpp index 5a8da230fd..ed3548ba9d 100644 --- a/modules/globebrowsing/src/globelabelscomponent.cpp +++ b/modules/globebrowsing/src/globelabelscomponent.cpp @@ -306,15 +306,15 @@ void GlobeLabelsComponent::initializeFonts() { ); } -bool GlobeLabelsComponent::loadLabelsData(const std::string& file) { - std::string cachedFile = FileSys.cacheManager()->cachedFilename( +bool GlobeLabelsComponent::loadLabelsData(const std::filesystem::path& file) { + std::filesystem::path cachedFile = FileSys.cacheManager()->cachedFilename( file, "GlobeLabelsComponent|" + identifier() ); bool hasCachedFile = std::filesystem::is_regular_file(cachedFile); if (hasCachedFile) { - LINFO(fmt::format("Cached file '{}' used for labels file: {}", cachedFile, file)); + LINFO(fmt::format("Cached file {} used for labels file {}", cachedFile, file)); const bool hasCache = loadCachedFile(cachedFile); if (hasCache) { @@ -327,9 +327,9 @@ bool GlobeLabelsComponent::loadLabelsData(const std::string& file) { } } else { - LINFO(fmt::format("Cache for labels file '{}' not found", file)); + LINFO(fmt::format("Cache for labels file {} not found", file)); } - LINFO(fmt::format("Loading labels file '{}'", file)); + LINFO(fmt::format("Loading labels file {}", file)); bool success = readLabelsFile(file); if (success) { @@ -338,11 +338,11 @@ bool GlobeLabelsComponent::loadLabelsData(const std::string& file) { return success; } -bool GlobeLabelsComponent::readLabelsFile(const std::string& file) { +bool GlobeLabelsComponent::readLabelsFile(const std::filesystem::path& file) { try { std::fstream csvLabelFile(file); if (!csvLabelFile.good()) { - LERROR(fmt::format("Failed to open labels file '{}'", file)); + LERROR(fmt::format("Failed to open labels file {}", file)); return false; } if (!csvLabelFile.is_open()) { @@ -427,16 +427,16 @@ bool GlobeLabelsComponent::readLabelsFile(const std::string& file) { return true; } catch (const std::fstream::failure& e) { - LERROR(fmt::format("Failed reading labels file '{}'", file)); + LERROR(fmt::format("Failed reading labels file {}", file)); LERROR(e.what()); return false; } } -bool GlobeLabelsComponent::loadCachedFile(const std::string& file) { +bool GlobeLabelsComponent::loadCachedFile(const std::filesystem::path& file) { std::ifstream fileStream(file, std::ifstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for loading cache file", file)); + LERROR(fmt::format("Error opening file {} for loading cache file", file)); return false; } @@ -463,10 +463,10 @@ bool GlobeLabelsComponent::loadCachedFile(const std::string& file) { return fileStream.good(); } -bool GlobeLabelsComponent::saveCachedFile(const std::string& file) const { +bool GlobeLabelsComponent::saveCachedFile(const std::filesystem::path& file) const { std::ofstream fileStream(file, std::ofstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for save cache file", file)); + LERROR(fmt::format("Error opening file {} for save cache file", file)); return false; } fileStream.write(reinterpret_cast(&CurrentCacheVersion), sizeof(int8_t)); diff --git a/modules/globebrowsing/src/globelabelscomponent.h b/modules/globebrowsing/src/globelabelscomponent.h index a14ede7078..0cfa277558 100644 --- a/modules/globebrowsing/src/globelabelscomponent.h +++ b/modules/globebrowsing/src/globelabelscomponent.h @@ -62,10 +62,10 @@ public: void draw(const RenderData& data); private: - bool loadLabelsData(const std::string& file); - bool readLabelsFile(const std::string& file); - bool loadCachedFile(const std::string& file); - bool saveCachedFile(const std::string& file) const; + bool loadLabelsData(const std::filesystem::path& file); + bool readLabelsFile(const std::filesystem::path& file); + bool loadCachedFile(const std::filesystem::path& file); + bool saveCachedFile(const std::filesystem::path& file) const; void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, float distToCamera, float fadeInVariable); bool isLabelInFrustum(const glm::dmat4& MVMatrix, const glm::dvec3& position) const; diff --git a/modules/globebrowsing/src/ringscomponent.cpp b/modules/globebrowsing/src/ringscomponent.cpp index 129fd9bf76..b04cf026ca 100644 --- a/modules/globebrowsing/src/ringscomponent.cpp +++ b/modules/globebrowsing/src/ringscomponent.cpp @@ -620,7 +620,7 @@ void RingsComponent::loadTexture() { if (texture) { LDEBUGC( "RingsComponent", - fmt::format("Loaded texture from '{}'", absPath(_texturePath)) + fmt::format("Loaded texture from {}", absPath(_texturePath)) ); _texture = std::move(texture); @@ -643,7 +643,7 @@ void RingsComponent::loadTexture() { LDEBUGC( "RingsComponent", fmt::format( - "Loaded forwards scattering texture from '{}'", + "Loaded forwards scattering texture from {}", absPath(_textureFwrdPath) ) ); @@ -669,7 +669,7 @@ void RingsComponent::loadTexture() { LDEBUGC( "RingsComponent", fmt::format( - "Loaded backwards scattering texture from '{}'", + "Loaded backwards scattering texture from {}", absPath(_textureBckwrdPath) ) ); @@ -694,10 +694,7 @@ void RingsComponent::loadTexture() { if (textureUnlit) { LDEBUGC( "RingsComponent", - fmt::format( - "Loaded unlit texture from '{}'", - absPath(_textureUnlitPath) - ) + fmt::format("Loaded unlit texture from {}", absPath(_textureUnlitPath)) ); _textureUnlit = std::move(textureUnlit); @@ -719,10 +716,7 @@ void RingsComponent::loadTexture() { if (textureColor) { LDEBUGC( "RingsComponent", - fmt::format( - "Loaded color texture from '{}'", - absPath(_textureColorPath) - ) + fmt::format("Loaded color texture from {}", absPath(_textureColorPath)) ); _textureColor = std::move(textureColor); @@ -744,10 +738,7 @@ void RingsComponent::loadTexture() { if (textureTransparency) { LDEBUGC( "RingsComponent", - fmt::format( - "Loaded unlit texture from '{}'", - absPath(_textureUnlitPath) - ) + fmt::format("Loaded unlit texture from {}", absPath(_textureUnlitPath)) ); _textureTransparency = std::move(textureTransparency); diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index 1329d52063..ff6e488acc 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -204,17 +204,17 @@ void GUI::deinitialize() { } void GUI::initializeGL() { - std::string cachedFile = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cachedFile = FileSys.cacheManager()->cachedFilename( configurationFile, "" ); LDEBUG(fmt::format("Using {} as ImGUI cache location", cachedFile)); - iniFileBuffer = new char[cachedFile.size() + 1]; + iniFileBuffer = new char[cachedFile.string().size() + 1]; #ifdef WIN32 - strcpy_s(iniFileBuffer, cachedFile.size() + 1, cachedFile.c_str()); + strcpy_s(iniFileBuffer, cachedFile.string().size() + 1, cachedFile.string().c_str()); #else strcpy(iniFileBuffer, cachedFile.c_str()); #endif diff --git a/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp b/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp index 2e8ad45922..dde78c643c 100644 --- a/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp +++ b/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp @@ -332,7 +332,7 @@ void RenderableKameleonVolume::load() { loadFromPath(_sourcePath); return; } - std::string cachePath = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cachePath = FileSys.cacheManager()->cachedFilename( std::filesystem::path(_sourcePath.value()).stem(), cacheSuffix() ); @@ -360,7 +360,7 @@ void RenderableKameleonVolume::loadFromPath(const std::string& path) { } } -void RenderableKameleonVolume::loadRaw(const std::string& path) { +void RenderableKameleonVolume::loadRaw(const std::filesystem::path& path) { volume::RawVolumeReader reader(path, _dimensions); _rawVolume = reader.read(); updateTextureFromVolume(); @@ -433,7 +433,7 @@ void RenderableKameleonVolume::updateTextureFromVolume() { _volumeTexture->setPixelData(data, ghoul::opengl::Texture::TakeOwnership::No); } -void RenderableKameleonVolume::storeRaw(const std::string& path) { +void RenderableKameleonVolume::storeRaw(const std::filesystem::path& path) { volume::RawVolumeWriter writer(path); writer.write(*_rawVolume); } diff --git a/modules/kameleonvolume/rendering/renderablekameleonvolume.h b/modules/kameleonvolume/rendering/renderablekameleonvolume.h index e4eacd4647..700559c688 100644 --- a/modules/kameleonvolume/rendering/renderablekameleonvolume.h +++ b/modules/kameleonvolume/rendering/renderablekameleonvolume.h @@ -62,9 +62,9 @@ public: private: void load(); void loadFromPath(const std::string& path); - void loadRaw(const std::string& path); + void loadRaw(const std::filesystem::path& path); void loadCdf(const std::string& path); - void storeRaw(const std::string& path); + void storeRaw(const std::filesystem::path& path); std::string cacheSuffix() const; void updateTextureFromVolume(); diff --git a/modules/multiresvolume/rendering/errorhistogrammanager.cpp b/modules/multiresvolume/rendering/errorhistogrammanager.cpp index 3f4824ba65..d7517e797c 100644 --- a/modules/multiresvolume/rendering/errorhistogrammanager.cpp +++ b/modules/multiresvolume/rendering/errorhistogrammanager.cpp @@ -179,7 +179,7 @@ bool ErrorHistogramManager::buildFromLeaf(unsigned int bstOffset, return true; } -bool ErrorHistogramManager::loadFromFile(const std::string& filename) { +bool ErrorHistogramManager::loadFromFile(const std::filesystem::path& filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.is_open()) { return false; @@ -210,7 +210,7 @@ bool ErrorHistogramManager::loadFromFile(const std::string& filename) { } -bool ErrorHistogramManager::saveToFile(const std::string& filename) { +bool ErrorHistogramManager::saveToFile(const std::filesystem::path& filename) { std::ofstream file(filename, std::ios::out | std::ios::binary); if (!file.is_open()) { return false; diff --git a/modules/multiresvolume/rendering/errorhistogrammanager.h b/modules/multiresvolume/rendering/errorhistogrammanager.h index 31dc829bf5..00ec8af043 100644 --- a/modules/multiresvolume/rendering/errorhistogrammanager.h +++ b/modules/multiresvolume/rendering/errorhistogrammanager.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -42,8 +43,8 @@ public: bool buildHistograms(int numBins); const Histogram* histogram(unsigned int brickIndex) const; - bool loadFromFile(const std::string& filename); - bool saveToFile(const std::string& filename); + bool loadFromFile(const std::filesystem::path& filename); + bool saveToFile(const std::filesystem::path& filename); private: TSP* _tsp; diff --git a/modules/multiresvolume/rendering/histogrammanager.cpp b/modules/multiresvolume/rendering/histogrammanager.cpp index cc3293e253..e32383669e 100644 --- a/modules/multiresvolume/rendering/histogrammanager.cpp +++ b/modules/multiresvolume/rendering/histogrammanager.cpp @@ -121,7 +121,7 @@ std::vector HistogramManager::readValues(TSP* tsp, unsigned int brickInde return voxelValues; } -bool HistogramManager::loadFromFile(const std::string& filename) { +bool HistogramManager::loadFromFile(const std::filesystem::path& filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.is_open()) { return false; @@ -151,7 +151,7 @@ bool HistogramManager::loadFromFile(const std::string& filename) { return true; } -bool HistogramManager::saveToFile(const std::string& filename) { +bool HistogramManager::saveToFile(const std::filesystem::path& filename) { std::ofstream file(filename, std::ios::out | std::ios::binary); if (!file.is_open()) { return false; diff --git a/modules/multiresvolume/rendering/histogrammanager.h b/modules/multiresvolume/rendering/histogrammanager.h index 2cda97e5e7..ab7aefbee7 100644 --- a/modules/multiresvolume/rendering/histogrammanager.h +++ b/modules/multiresvolume/rendering/histogrammanager.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_MULTIRESVOLUME___HISTOGRAMMANAGER___H__ #include +#include #include namespace openspace { @@ -36,8 +37,8 @@ class HistogramManager { public: bool buildHistograms(TSP* tsp, int numBins); Histogram* histogram(unsigned int brickIndex); - bool loadFromFile(const std::string& filename); - bool saveToFile(const std::string& filename); + bool loadFromFile(const std::filesystem::path& filename); + bool saveToFile(const std::filesystem::path& filename); private: bool buildHistogram(TSP* tsp, unsigned int brickIndex); diff --git a/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp b/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp index c13500c7fd..461fd4f983 100644 --- a/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp +++ b/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp @@ -305,7 +305,7 @@ bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset, return true; } -bool LocalErrorHistogramManager::loadFromFile(const std::string& filename) { +bool LocalErrorHistogramManager::loadFromFile(const std::filesystem::path& filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.is_open()) { return false; @@ -344,7 +344,7 @@ bool LocalErrorHistogramManager::loadFromFile(const std::string& filename) { } -bool LocalErrorHistogramManager::saveToFile(const std::string& filename) { +bool LocalErrorHistogramManager::saveToFile(const std::filesystem::path& filename) { std::ofstream file(filename, std::ios::out | std::ios::binary); if (!file.is_open()) { return false; diff --git a/modules/multiresvolume/rendering/localerrorhistogrammanager.h b/modules/multiresvolume/rendering/localerrorhistogrammanager.h index b6f54177c4..da4dd0833b 100644 --- a/modules/multiresvolume/rendering/localerrorhistogrammanager.h +++ b/modules/multiresvolume/rendering/localerrorhistogrammanager.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -42,8 +43,8 @@ public: const Histogram* spatialHistogram(unsigned int brickIndex) const; const Histogram* temporalHistogram(unsigned int brickIndex) const; - bool loadFromFile(const std::string& filename); - bool saveToFile(const std::string& filename); + bool loadFromFile(const std::filesystem::path& filename); + bool saveToFile(const std::filesystem::path& filename); private: TSP* _tsp = nullptr; diff --git a/modules/multiresvolume/rendering/renderablemultiresvolume.cpp b/modules/multiresvolume/rendering/renderablemultiresvolume.cpp index 97d542348a..6ddb02345f 100644 --- a/modules/multiresvolume/rendering/renderablemultiresvolume.cpp +++ b/modules/multiresvolume/rendering/renderablemultiresvolume.cpp @@ -455,21 +455,21 @@ bool RenderableMultiresVolume::initializeSelector() { switch (_selector) { case Selector::TF: if (_errorHistogramManager) { - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename( fmt::format( "{}_{}_errorHistograms", std::filesystem::path(_filename).stem().string(), nHistograms ), "" ); - std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary); + std::ifstream cacheFile(cached, std::ios::in | std::ios::binary); if (cacheFile.is_open()) { // Read histograms from cache. cacheFile.close(); LINFO( - fmt::format("Loading histograms from cache: {}", cacheFilename) + fmt::format("Loading histograms from cache: {}", cached) ); - success &= _errorHistogramManager->loadFromFile(cacheFilename); + success &= _errorHistogramManager->loadFromFile(cached); } else if (!_errorHistogramsPath.empty()) { // Read histograms from scene data. @@ -482,11 +482,11 @@ bool RenderableMultiresVolume::initializeSelector() { } else { // Build histograms from tsp file. - LWARNING(fmt::format("Failed to open {}", cacheFilename)); + LWARNING(fmt::format("Failed to open {}", cached)); success &= _errorHistogramManager->buildHistograms(nHistograms); if (success) { - LINFO(fmt::format("Writing cache to {}", cacheFilename)); - _errorHistogramManager->saveToFile(cacheFilename); + LINFO(fmt::format("Writing cache to {}", cached)); + _errorHistogramManager->saveToFile(cached); } } success &= _tfBrickSelector && _tfBrickSelector->initialize(); @@ -495,29 +495,29 @@ bool RenderableMultiresVolume::initializeSelector() { case Selector::SIMPLE: if (_histogramManager) { - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename( fmt::format("{}_{}_histogram", std::filesystem::path(_filename).stem().string(), nHistograms ), "" ); - std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary); + std::ifstream cacheFile(cached, std::ios::in | std::ios::binary); if (cacheFile.is_open()) { // Read histograms from cache. cacheFile.close(); - LINFO(fmt::format("Loading histograms from {}", cacheFilename)); - success &= _histogramManager->loadFromFile(cacheFilename); + LINFO(fmt::format("Loading histograms from {}", cached)); + success &= _histogramManager->loadFromFile(cached); } else { // Build histograms from tsp file. - LWARNING(fmt::format("Failed to open '{}'", cacheFilename)); + LWARNING(fmt::format("Failed to open {}", cached)); success &= _histogramManager->buildHistograms( _tsp.get(), nHistograms ); if (success) { - LINFO(fmt::format("Writing cache to {}", cacheFilename)); - _histogramManager->saveToFile(cacheFilename); + LINFO(fmt::format("Writing cache to {}", cached)); + _histogramManager->saveToFile(cached); } } success &= _simpleTfBrickSelector && _simpleTfBrickSelector->initialize(); @@ -526,27 +526,27 @@ bool RenderableMultiresVolume::initializeSelector() { case Selector::LOCAL: if (_localErrorHistogramManager) { - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename( fmt::format( "{}_{}_localErrorHistograms", std::filesystem::path(_filename).stem().string(), nHistograms ), "" ); - std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary); + std::ifstream cacheFile(cached, std::ios::in | std::ios::binary); if (cacheFile.is_open()) { // Read histograms from cache. cacheFile.close(); - LINFO(fmt::format("Loading histograms from {}", cacheFilename)); - success &= _localErrorHistogramManager->loadFromFile(cacheFilename); + LINFO(fmt::format("Loading histograms from {}", cached)); + success &= _localErrorHistogramManager->loadFromFile(cached); } else { // Build histograms from tsp file. - LWARNING(fmt::format("Failed to open {}", cacheFilename)); + LWARNING(fmt::format("Failed to open {}", cached)); success &= _localErrorHistogramManager->buildHistograms(nHistograms); if (success) { - LINFO(fmt::format("Writing cache to {}", cacheFilename)); - _localErrorHistogramManager->saveToFile(cacheFilename); + LINFO(fmt::format("Writing cache to {}", cached)); + _localErrorHistogramManager->saveToFile(cached); } } success &= _localTfBrickSelector && _localTfBrickSelector->initialize(); diff --git a/modules/multiresvolume/rendering/tsp.cpp b/modules/multiresvolume/rendering/tsp.cpp index 124d1cea24..8ad76a06d3 100644 --- a/modules/multiresvolume/rendering/tsp.cpp +++ b/modules/multiresvolume/rendering/tsp.cpp @@ -507,7 +507,7 @@ bool TSP::readCache() { if (!FileSys.cacheManager()) return false; - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cacheFilename = FileSys.cacheManager()->cachedFilename( std::filesystem::path(_filename).stem(), "" ); @@ -545,7 +545,7 @@ bool TSP::writeCache() { return false; } - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cacheFilename = FileSys.cacheManager()->cachedFilename( std::filesystem::path(_filename).stem(), "" ); diff --git a/modules/space/rendering/renderablestars.cpp b/modules/space/rendering/renderablestars.cpp index 89b4fdf9a5..3b42e10193 100644 --- a/modules/space/rendering/renderablestars.cpp +++ b/modules/space/rendering/renderablestars.cpp @@ -865,7 +865,7 @@ void RenderableStars::loadPSFTexture() { if (_pointSpreadFunctionTexture) { LDEBUG(fmt::format( - "Loaded texture from '{}'", absPath(_pointSpreadFunctionTexturePath) + "Loaded texture from {}", absPath(_pointSpreadFunctionTexturePath) )); _pointSpreadFunctionTexture->uploadTexture(); } @@ -1267,10 +1267,7 @@ void RenderableStars::update(const UpdateData&) { absPath(_colorTexturePath).string() ); if (_colorTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'", - absPath(_colorTexturePath) - )); + LDEBUG(fmt::format("Loaded texture from {}", absPath(_colorTexturePath))); _colorTexture->uploadTexture(); } @@ -1293,7 +1290,7 @@ void RenderableStars::update(const UpdateData&) { ); if (_otherDataColorMapTexture) { LDEBUG(fmt::format( - "Loaded texture from '{}'", + "Loaded texture from {}", absPath(_otherDataColorMapPath) )); _otherDataColorMapTexture->uploadTexture(); diff --git a/modules/space/speckloader.cpp b/modules/space/speckloader.cpp index 996ba3ab73..649e3f9aff 100644 --- a/modules/space/speckloader.cpp +++ b/modules/space/speckloader.cpp @@ -99,23 +99,21 @@ namespace { std::is_same_v ); - std::string cachePath = FileSys.cacheManager()->cachedFilename(speckPath); + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename(speckPath); - if (std::filesystem::exists(cachePath)) { + if (std::filesystem::exists(cached)) { LINFOC( "SpeckLoader", - fmt::format( - "Cached file '{}' used for file {}", cachePath, speckPath - ) + fmt::format("Cached file {} used for file {}", cached, speckPath) ); - std::optional dataset = loadCacheFunction(cachePath); + std::optional dataset = loadCacheFunction(cached); if (dataset.has_value()) { // We could load the cache file and we are now done with this return *dataset; } else { - FileSys.cacheManager()->removeCacheFile(cachePath); + FileSys.cacheManager()->removeCacheFile(cached); } } LINFOC("SpeckLoader", fmt::format("Loading file {}", speckPath)); @@ -123,7 +121,7 @@ namespace { if (!dataset.entries.empty()) { LINFOC("SpeckLoader", "Saving cache"); - saveCacheFunction(dataset, cachePath); + saveCacheFunction(dataset, cached); } return dataset; } @@ -547,7 +545,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { std::ifstream file(path); if (!file.good()) { - throw ghoul::RuntimeError(fmt::format("Failed to open speck file '{}'", path)); + throw ghoul::RuntimeError(fmt::format("Failed to open speck file {}", path)); } Labelset res; @@ -582,7 +580,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { // included in the speck file) if (res.textColorIndex != -1) { throw ghoul::RuntimeError(fmt::format( - "Error loading label file '{}': Textcolor defined twice", path + "Error loading label file {}: Textcolor defined twice", path )); } @@ -621,7 +619,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { // data section of the file if (!std::isdigit(line[0]) && line[0] != '-') { throw ghoul::RuntimeError(fmt::format( - "Error loading label file '{}': Header information and datasegment " + "Error loading label file {}: Header information and datasegment " "intermixed", path )); } @@ -640,7 +638,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { if (!startsWith(rest, "text")) { throw ghoul::RuntimeError(fmt::format( - "Error loading label file '{}': File contains some value between " + "Error loading label file {}: File contains some value between " "positions and text label, which is unsupported", path )); } @@ -755,7 +753,7 @@ ColorMap loadFile(std::filesystem::path path, SkipAllZeroLines) { std::ifstream file(path); if (!file.good()) { - throw ghoul::RuntimeError(fmt::format("Failed to open speck file '{}'", path)); + throw ghoul::RuntimeError(fmt::format("Failed to open speck file {}", path)); } ColorMap res; diff --git a/modules/space/translation/horizonstranslation.cpp b/modules/space/translation/horizonstranslation.cpp index 1f13bdf6cc..47fc033f1a 100644 --- a/modules/space/translation/horizonstranslation.cpp +++ b/modules/space/translation/horizonstranslation.cpp @@ -113,17 +113,15 @@ glm::dvec3 HorizonsTranslation::position(const UpdateData& data) const { } void HorizonsTranslation::loadData() { - std::string file = _horizonsTextFile; - if (!std::filesystem::is_regular_file(absPath(file))) { + std::filesystem::path file = absPath(_horizonsTextFile.value()); + if (!std::filesystem::is_regular_file(file)) { return; } - std::string cachedFile = FileSys.cacheManager()->cachedFilename(file); + std::filesystem::path cachedFile = FileSys.cacheManager()->cachedFilename(file); bool hasCachedFile = std::filesystem::is_regular_file(cachedFile); if (hasCachedFile) { - LINFO(fmt::format( - "Cached file '{}' used for Horizon file '{}'", cachedFile, file - )); + LINFO(fmt::format("Cached file {} used for Horizon file {}", cachedFile, file)); bool success = loadCachedFile(cachedFile); if (success) { @@ -136,9 +134,9 @@ void HorizonsTranslation::loadData() { } } else { - LINFO(fmt::format("Cache for Horizon file '{}' not found", file)); + LINFO(fmt::format("Cache for Horizon file {} not found", file)); } - LINFO(fmt::format("Loading Horizon file '{}'", file)); + LINFO(fmt::format("Loading Horizon file {}", file)); readHorizonsTextFile(); @@ -147,12 +145,11 @@ void HorizonsTranslation::loadData() { } void HorizonsTranslation::readHorizonsTextFile() { - std::ifstream fileStream(_horizonsTextFile); + std::filesystem::path f = absPath(_horizonsTextFile); + std::ifstream fileStream(f); if (!fileStream.good()) { - LERROR(fmt::format( - "Failed to open Horizons text file '{}'", _horizonsTextFile - )); + LERROR(fmt::format("Failed to open Horizons text file {}", f)); return; } @@ -202,11 +199,11 @@ void HorizonsTranslation::readHorizonsTextFile() { fileStream.close(); } -bool HorizonsTranslation::loadCachedFile(const std::string& file) { +bool HorizonsTranslation::loadCachedFile(const std::filesystem::path& file) { std::ifstream fileStream(file, std::ifstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for loading cache file", file)); + LERROR(fmt::format("Error opening file {} for loading cache file", file)); return false; } @@ -241,10 +238,10 @@ bool HorizonsTranslation::loadCachedFile(const std::string& file) { return fileStream.good(); } -void HorizonsTranslation::saveCachedFile(const std::string& file) const { +void HorizonsTranslation::saveCachedFile(const std::filesystem::path& file) const { std::ofstream fileStream(file, std::ofstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for save cache file", file)); + LERROR(fmt::format("Error opening file {} for save cache file", file)); return; } diff --git a/modules/space/translation/horizonstranslation.h b/modules/space/translation/horizonstranslation.h index e002c3f8ed..625faa29d9 100644 --- a/modules/space/translation/horizonstranslation.h +++ b/modules/space/translation/horizonstranslation.h @@ -61,8 +61,8 @@ public: private: void loadData(); void readHorizonsTextFile(); - bool loadCachedFile(const std::string& file); - void saveCachedFile(const std::string& file) const; + bool loadCachedFile(const std::filesystem::path& file); + void saveCachedFile(const std::filesystem::path& file) const; properties::StringProperty _horizonsTextFile; std::unique_ptr _fileHandle; diff --git a/modules/spacecraftinstruments/util/labelparser.cpp b/modules/spacecraftinstruments/util/labelparser.cpp index e9469306c1..4baf2c41df 100644 --- a/modules/spacecraftinstruments/util/labelparser.cpp +++ b/modules/spacecraftinstruments/util/labelparser.cpp @@ -166,7 +166,9 @@ bool LabelParser::create() { std::ifstream file(path); if (!file.good()) { - LERROR(fmt::format("Failed to open label file '{}'", path)); + LERROR(fmt::format( + "Failed to open label file {}", std::filesystem::path(path) + )); return false; } diff --git a/modules/volume/rawvolumereader.h b/modules/volume/rawvolumereader.h index 1d2833cf32..519411a68f 100644 --- a/modules/volume/rawvolumereader.h +++ b/modules/volume/rawvolumereader.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_VOLUME___RAWVOLUMEREADER___H__ #include +#include #include namespace openspace::volume { @@ -37,11 +38,11 @@ class RawVolumeReader { public: using VoxelType = Type; - RawVolumeReader(const std::string& path, const glm::uvec3& dimensions); + RawVolumeReader(const std::filesystem::path& path, const glm::uvec3& dimensions); glm::uvec3 dimensions() const; - std::string path() const; - void setPath(const std::string& path); + std::filesystem::path path() const; + void setPath(std::filesystem::path path); void setDimensions(const glm::uvec3& dimensions); //VoxelType get(const glm::ivec3& coordinates) const; // TODO: Implement this //VoxelType get(const size_t index) const; // TODO: Implement this @@ -51,7 +52,7 @@ private: size_t coordsToIndex(const glm::uvec3& cartesian) const; glm::uvec3 indexToCoords(size_t linear) const; glm::uvec3 _dimensions; - std::string _path; + std::filesystem::path _path; }; } // namespace openspace::volume diff --git a/modules/volume/rawvolumereader.inl b/modules/volume/rawvolumereader.inl index b54f643c0b..642ffbbe6e 100644 --- a/modules/volume/rawvolumereader.inl +++ b/modules/volume/rawvolumereader.inl @@ -28,10 +28,10 @@ namespace openspace::volume { template -RawVolumeReader::RawVolumeReader(const std::string& path, +RawVolumeReader::RawVolumeReader(const std::filesystem::path& path, const glm::uvec3& dimensions) : _dimensions(dimensions) - , _path(path) + , _path(std::move(path)) {} template @@ -45,16 +45,15 @@ void RawVolumeReader::setDimensions(const glm::uvec3& dimensions) { } template -std::string RawVolumeReader::path() const { +std::filesystem::path RawVolumeReader::path() const { return _path; } template -void RawVolumeReader::setPath(const std::string& path) { - _path = path; +void RawVolumeReader::setPath(std::filesystem::path path) { + _path = std::move(path); } - /* TODO: Implement these methods for random access in raw volume file template diff --git a/modules/volume/rawvolumewriter.h b/modules/volume/rawvolumewriter.h index bfae4a9bc4..38918b2e77 100644 --- a/modules/volume/rawvolumewriter.h +++ b/modules/volume/rawvolumewriter.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__ #define __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__ +#include #include #include @@ -35,9 +36,9 @@ template class RawVolume; template class RawVolumeWriter { public: - RawVolumeWriter(std::string path, size_t bufferSize = 1024); + RawVolumeWriter(std::filesystem::path path, size_t bufferSize = 1024); - void setPath(const std::string& path); + void setPath(std::filesystem::path path); glm::uvec3 dimensions() const; void setDimensions(glm::uvec3 dimensions); void write(const std::function& fn, @@ -49,7 +50,7 @@ public: private: glm::ivec3 _dimensions = glm::ivec3(0); - std::string _path; + std::filesystem::path _path; size_t _bufferSize = 0; }; diff --git a/modules/volume/rawvolumewriter.inl b/modules/volume/rawvolumewriter.inl index d9318f9b15..7a96b1ce1b 100644 --- a/modules/volume/rawvolumewriter.inl +++ b/modules/volume/rawvolumewriter.inl @@ -25,12 +25,13 @@ #include #include #include +#include #include namespace openspace::volume { template -RawVolumeWriter::RawVolumeWriter(std::string path, size_t bufferSize) +RawVolumeWriter::RawVolumeWriter(std::filesystem::path path, size_t bufferSize) : _path(std::move(path)) , _bufferSize(bufferSize) {} @@ -99,7 +100,7 @@ void RawVolumeWriter::write(const RawVolume& volume) { std::ofstream file(_path, std::ios::binary); if (!file.good()) { - throw ghoul::RuntimeError("Could not create file '" + _path + "'"); + throw ghoul::RuntimeError(fmt::format("Could not create file {}", _path)); } file.write(buffer, length); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index d063cea529..be72b1076b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1092,7 +1092,7 @@ void OpenSpaceEngine::preSynchronization() { global::memoryManager->TemporaryMemory.reset(); if (_hasScheduledAssetLoading) { - LINFO(fmt::format("Loading asset: {}", _scheduledAssetPathToLoad)); + LINFO(fmt::format("Loading asset: {}", absPath(_scheduledAssetPathToLoad))); global::profile->setIgnoreUpdates(true); loadSingleAsset(_scheduledAssetPathToLoad); global::profile->setIgnoreUpdates(false); diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index 7b86f41e8d..275300606a 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -332,7 +332,10 @@ int createSingleColorImage(lua_State* L) { const glm::dvec3 color = colorDict.value(key); - std::string fileName = FileSys.cacheManager()->cachedFilename(name + ".ppm", ""); + std::filesystem::path fileName = FileSys.cacheManager()->cachedFilename( + name + ".ppm", + "" + ); const bool hasCachedFile = std::filesystem::is_regular_file(fileName); if (hasCachedFile) { LDEBUGC("OpenSpaceEngine", fmt::format("Cached file '{}' used", fileName)); diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 2d953ac33b..4cd4c49f48 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -170,7 +170,10 @@ LuaConsole::~LuaConsole() {} // NOLINT void LuaConsole::initialize() { ZoneScoped - const std::string filename = FileSys.cacheManager()->cachedFilename(HistoryFile, ""); + const std::filesystem::path filename = FileSys.cacheManager()->cachedFilename( + HistoryFile, + "" + ); if (std::filesystem::is_regular_file(filename)) { std::ifstream file(filename, std::ios::binary | std::ios::in); @@ -230,7 +233,10 @@ void LuaConsole::initialize() { void LuaConsole::deinitialize() { ZoneScoped - const std::string filename = FileSys.cacheManager()->cachedFilename(HistoryFile, ""); + const std::filesystem::path filename = FileSys.cacheManager()->cachedFilename( + HistoryFile, + "" + ); // We want to limit the command history to a realistic value, so that it doesn't // grow without bounds diff --git a/src/rendering/texturecomponent.cpp b/src/rendering/texturecomponent.cpp index a49200073a..1b06a99ea0 100644 --- a/src/rendering/texturecomponent.cpp +++ b/src/rendering/texturecomponent.cpp @@ -86,7 +86,7 @@ void TextureComponent::loadFromFile(const std::filesystem::path& path) { ); if (texture) { - LDEBUG(fmt::format("Loaded texture from '{}'", absPath(path.string()))); + LDEBUG(fmt::format("Loaded texture from {}", absPath(path.string()))); _texture = std::move(texture); _textureFile = std::make_unique(path); diff --git a/src/scene/asset.cpp b/src/scene/asset.cpp index dc03a46118..6e1737bd7e 100644 --- a/src/scene/asset.cpp +++ b/src/scene/asset.cpp @@ -502,7 +502,7 @@ bool Asset::initialize() { LERROR(fmt::format("Cannot initialize unsynchronized asset {}", id())); return false; } - LDEBUG(fmt::format("Initializing asset {}", id())); + LDEBUG(fmt::format("Initializing asset '{}'", id())); // 1. Initialize requirements for (const std::shared_ptr& child : _requiredAssets) { @@ -593,7 +593,7 @@ void Asset::deinitialize() { if (!isInitialized()) { return; } - LDEBUG(fmt::format("Deintializing asset {}", id())); + LDEBUG(fmt::format("Deintializing asset '{}'", id())); // Perform inverse actions as in initialize, in reverse order (7 - 1) diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 0c7a16a7ae..3e6941c354 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -214,15 +214,11 @@ bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback) return true; } -bool ScriptEngine::runScriptFile(const std::string& filename) { +bool ScriptEngine::runScriptFile(const std::filesystem::path& filename) { ZoneScoped - if (filename.empty()) { - LWARNING("Filename was empty"); - return false; - } if (!std::filesystem::is_regular_file(filename)) { - LERROR(fmt::format("Script with name '{}' did not exist", filename)); + LERROR(fmt::format("Script with name {} did not exist", filename)); return false; } @@ -649,14 +645,17 @@ bool ScriptEngine::writeLog(const std::string& script) { _logFilename = absPath(global::configuration->scriptLog).string(); _logFileExists = true; - LDEBUG(fmt::format("Using script log file '{}'", _logFilename)); + LDEBUG(fmt::format( + "Using script log file {}", std::filesystem::path(_logFilename) + )); // Test file and clear previous input std::ofstream file(_logFilename, std::ofstream::out | std::ofstream::trunc); if (!file.good()) { LERROR(fmt::format( - "Could not open file '{}' for logging scripts", _logFilename + "Could not open file {} for logging scripts", + std::filesystem::path(_logFilename) )); return false; diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index a55b6d1485..0f4897ac31 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -204,13 +204,13 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { ghoul_assert(!filePath.empty(), "Empty file path"); ghoul_assert( std::filesystem::is_regular_file(filePath), - fmt::format("File '{}' ('{}') does not exist", filePath, absPath(filePath)) + fmt::format("File '{}' ({}) does not exist", filePath, absPath(filePath)) ); ghoul_assert( std::filesystem::is_directory(std::filesystem::path(filePath).parent_path()), fmt::format( - "File '{}' exists, but directory '{}' doesn't", - absPath(filePath), std::filesystem::path(filePath).parent_path().string() + "File {} exists, but directory {} does not", + absPath(filePath), std::filesystem::path(filePath).parent_path() ) ); @@ -234,7 +234,7 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { std::filesystem::path p = std::filesystem::path(path).parent_path(); std::filesystem::current_path(p); - LINFO(fmt::format("Loading SPICE kernel '{}'", path)); + LINFO(fmt::format("Loading SPICE kernel {}", path)); // Load the kernel furnsh_c(path.string().c_str()); @@ -273,7 +273,7 @@ void SpiceManager::unloadKernel(KernelHandle kernelId) { // If there was only one part interested in the kernel, we can unload it if (it->refCount == 1) { // No need to check for errors as we do not allow empty path names - LINFO(fmt::format("Unloading SPICE kernel '{}'", it->path)); + LINFO(fmt::format("Unloading SPICE kernel {}", it->path)); unload_c(it->path.c_str()); _loadedKernels.erase(it); } @@ -299,7 +299,7 @@ void SpiceManager::unloadKernel(std::string filePath) { if (it == _loadedKernels.end()) { if (_useExceptions) { throw SpiceException( - fmt::format("'{}' did not correspond to a loaded kernel", path) + fmt::format("{} did not correspond to a loaded kernel", path) ); } else { @@ -309,7 +309,7 @@ void SpiceManager::unloadKernel(std::string filePath) { else { // If there was only one part interested in the kernel, we can unload it if (it->refCount == 1) { - LINFO(fmt::format("Unloading SPICE kernel '{}'", path)); + LINFO(fmt::format("Unloading SPICE kernel {}", path)); unload_c(path.string().c_str()); _loadedKernels.erase(it); } From 1912f8f08ba227f69cb1d1acd65fd9e8b8819b50 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 2 Jul 2021 08:11:37 +0200 Subject: [PATCH 22/44] Avoid non-supported ranges for exponential slider (#1672) * Warn if setExponent is called with an invalid minmax range * Disable bounding and interaction sphere exponent, to suppress warning --- .../properties/numericalproperty.inl | 31 +++++++++++++++++++ src/scene/scenegraphnode.cpp | 12 ++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/include/openspace/properties/numericalproperty.inl b/include/openspace/properties/numericalproperty.inl index 3f5696f17a..23adef27f5 100644 --- a/include/openspace/properties/numericalproperty.inl +++ b/include/openspace/properties/numericalproperty.inl @@ -23,9 +23,11 @@ ****************************************************************************************/ #include +#include #include #include #include +#include namespace openspace::properties { @@ -90,6 +92,35 @@ float NumericalProperty::exponent() const { template void NumericalProperty::setExponent(float exponent) { ghoul_assert(std::abs(exponent) > 0.f, "Exponent for property input cannot be zero"); + + auto isValidRange = [](const T& minValue, const T& maxValue) { + if constexpr (ghoul::isGlmVector() || ghoul::isGlmMatrix()) { + return glm::all(glm::greaterThanEqual(minValue, T(0))) && + glm::all(glm::greaterThanEqual(maxValue, T(0))); + } + else { + return (minValue >= T(0) && maxValue >= T(0)); + } + }; + + // While the exponential slider does not support ranges with negative values, + // prevent setting the exponent for such ranges + // @ TODO (2021-06-30, emmbr), remove this check when no longer needed + if (!std::is_unsigned::value) { + if (!isValidRange(_minimumValue, _maximumValue)) { + LWARNINGC( + "NumericalProperty: setExponent", + fmt::format( + "Setting exponent for properties with negative values in " + "[min, max] range is not yet supported. Property: {}", + this->fullyQualifiedIdentifier() + ) + ); + _exponent = 1.f; + return; + } + } + _exponent = exponent; } diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 0611b4cdd1..6ce162c4fa 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -229,7 +229,7 @@ namespace { // A user-facing description about this scene graph node std::optional description; - // If this value is specified, GUI applications are incouraged to ignore this + // If this value is specified, GUI applications are incouraged to ignore this // scenegraph node. This is most useful to trim collective lists of nodes and // not display, for example, barycenters std::optional hidden; @@ -447,7 +447,9 @@ SceneGraphNode::SceneGraphNode() _overrideBoundingSphere = std::nullopt; } }); - _boundingSphere.setExponent(10.f); + // @TODO (2021-06-30, emmbr) Uncomment this when exponential sliders support + // negative values + //_boundingSphere.setExponent(10.f); addProperty(_boundingSphere); _interactionSphere.onChange([this]() { if (_interactionSphere >= 0.0) { @@ -456,8 +458,10 @@ SceneGraphNode::SceneGraphNode() else { _overrideInteractionSphere = std::nullopt; } - }); - _interactionSphere.setExponent(10.f); + }); + // @TODO (2021-06-30, emmbr) Uncomment this when exponential sliders support + // negative values + //_interactionSphere.setExponent(10.f); addProperty(_interactionSphere); addProperty(_showDebugSphere); } From 0f0812ea1534badeaadad1ac50371a88c80d0111 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Fri, 2 Jul 2021 09:05:01 +0200 Subject: [PATCH 23/44] Address further PR comments --- src/util/coordinateconversion.cpp | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index b2d65f47e1..041a126271 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -161,11 +161,9 @@ namespace openspace { // Convert Equatorial coordinates ICRS right ascension and declination (a, d) // into Galactic coordinates (l, b) -glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) -{ - // Reference: - // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php - +// Reference: +// https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php +glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) { // (Ra, Dec) -> (a, d) double a = glm::radians(ra); double d = glm::radians(dec); @@ -190,9 +188,9 @@ glm::dvec3 icrsToGalacticCartesian(double ra, double dec, double distance) // Ra format 'XhYmZs', where X and Y are positive integers and Z is a positive double // Dec format 'XdYmZs', where X is a signed integer, Y is a positive integer and Z is a // positive double +// Reference: +// https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { - // Reference: - // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars if (ra.size() < 6 || dec.size() < 6) { throw ghoul::lua::LuaRuntimeException(fmt::format( "Ra '{}' or Dec '{}' format is incorrect. Correct format is: Ra 'XhYmZs', " @@ -238,11 +236,10 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { // Convert Galactic coordinates (x, y, z) or (l, b) into Equatorial coordinates ICRS // right ascension and declination in decimal degrees (a, d) plus distance +// References: +// https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, +// https://en.wikipedia.org/wiki/Celestial_coordinate_system glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { - // References: - // https://www.atnf.csiro.au/people/Tobias.Westmeier/tools_coords.php, - // https://en.wikipedia.org/wiki/Celestial_coordinate_system - // Normalize double distance = sqrt(x*x + y*y + z*z); double nX = x / distance; @@ -265,12 +262,10 @@ glm::dvec3 galacticCartesianToIcrs(double x, double y, double z) { } // Return a pair with two formatted strings from the decimal degrees ra and dec -std::pair decimalDegreesToIcrs(double ra, double dec) -{ - // References: - // https://www.rapidtables.com/convert/number/degrees-to-degrees-minutes-seconds.html, - // https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars - +// References: +// https://www.rapidtables.com/convert/number/degrees-to-degrees-minutes-seconds.html, +// https://math.stackexchange.com/questions/15323/how-do-i-calculate-the-cartesian-coordinates-of-stars +std::pair decimalDegreesToIcrs(double ra, double dec) { // Radians to degrees double raDeg = ra; double decDeg = dec; From 505601b1c9b130a179f2a745636ac84de55c59e9 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Fri, 2 Jul 2021 09:35:16 +0200 Subject: [PATCH 24/44] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 07b79ab570..c5add410f3 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 07b79ab57062077b624e190a109ff749fb242181 +Subproject commit c5add410f3367890e2a2f91f6087001baf8f2152 From bec5274ff0148c232862c2728dedbdadbab0612d Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Fri, 2 Jul 2021 09:53:53 +0200 Subject: [PATCH 25/44] Merge in master --- ext/CMakeLists.txt | 1 + ext/spice | 2 +- .../properties/numericalproperty.inl | 31 +++++ include/openspace/scripting/scriptengine.h | 5 +- .../rendering/atmospheredeferredcaster.cpp | 51 +++----- .../rendering/atmospheredeferredcaster.h | 6 +- .../shaders/atmosphere_deferred_fs.glsl | 120 +++++++++--------- modules/base/basemodule.cpp | 1 + .../rendering/renderableplaneimagelocal.cpp | 2 +- .../rendering/renderableplaneimageonline.cpp | 76 +++++------ modules/base/rendering/renderableprism.cpp | 8 +- modules/base/rendering/renderablesphere.cpp | 2 +- modules/base/rotation/luarotation.cpp | 6 +- modules/base/scale/luascale.cpp | 6 +- modules/base/translation/luatranslation.cpp | 6 +- .../rendering/renderablebillboardscloud.cpp | 2 +- .../rendering/renderabledumeshes.cpp | 6 +- .../rendering/renderableplanescloud.cpp | 12 +- .../rendering/renderableplanescloud.h | 9 +- .../rendering/renderablepoints.cpp | 14 +- .../rendering/renderablepoints.h | 5 +- modules/exoplanets/exoplanetshelper.cpp | 3 +- modules/exoplanets/exoplanetsmodule_lua.inl | 4 +- .../util/kameleonfieldlinehelper.cpp | 10 +- .../fitsfilereader/include/fitsfilereader.h | 10 +- modules/fitsfilereader/src/fitsfilereader.cpp | 18 +-- .../gaia/rendering/renderablegaiastars.cpp | 41 +++--- modules/gaia/rendering/renderablegaiastars.h | 10 +- modules/gaia/tasks/readfilejob.cpp | 6 +- modules/galaxy/rendering/renderablegalaxy.cpp | 19 +-- modules/galaxy/rendering/renderablegalaxy.h | 2 +- .../src/globelabelscomponent.cpp | 24 ++-- .../globebrowsing/src/globelabelscomponent.h | 8 +- modules/globebrowsing/src/ringscomponent.cpp | 21 +-- modules/imgui/src/gui.cpp | 6 +- .../rendering/renderablekameleonvolume.cpp | 6 +- .../rendering/renderablekameleonvolume.h | 4 +- .../rendering/errorhistogrammanager.cpp | 4 +- .../rendering/errorhistogrammanager.h | 5 +- .../rendering/histogrammanager.cpp | 4 +- .../rendering/histogrammanager.h | 5 +- .../rendering/localerrorhistogrammanager.cpp | 4 +- .../rendering/localerrorhistogrammanager.h | 5 +- .../rendering/renderablemultiresvolume.cpp | 42 +++--- modules/multiresvolume/rendering/tsp.cpp | 4 +- modules/space/rendering/renderablestars.cpp | 9 +- modules/space/speckloader.cpp | 24 ++-- .../space/translation/horizonstranslation.cpp | 29 ++--- .../space/translation/horizonstranslation.h | 4 +- .../util/labelparser.cpp | 4 +- modules/volume/rawvolumereader.h | 9 +- modules/volume/rawvolumereader.inl | 11 +- modules/volume/rawvolumewriter.h | 7 +- modules/volume/rawvolumewriter.inl | 5 +- src/engine/openspaceengine.cpp | 2 +- src/engine/openspaceengine_lua.inl | 5 +- src/rendering/luaconsole.cpp | 10 +- src/rendering/texturecomponent.cpp | 2 +- src/scene/asset.cpp | 4 +- src/scene/scenegraphnode.cpp | 12 +- src/scripting/scriptengine.cpp | 15 +-- src/util/spicemanager.cpp | 22 ++-- 62 files changed, 429 insertions(+), 381 deletions(-) diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 0010d35d22..797f419d56 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -54,6 +54,7 @@ set_folder_location(GhoulTest "Unit Tests") # Spice begin_dependency("Spice") +set(SPICE_BUILD_SHARED_LIBRARY OFF CACHE BOOL "" FORCE) add_subdirectory(spice) set_folder_location(spice "External") end_dependency() diff --git a/ext/spice b/ext/spice index ba40ad2c25..e8a1cbeacc 160000 --- a/ext/spice +++ b/ext/spice @@ -1 +1 @@ -Subproject commit ba40ad2c25fe81e152a733b4a6afe53868388206 +Subproject commit e8a1cbeacc25a60fbed2f0958951a012ef6ba8e3 diff --git a/include/openspace/properties/numericalproperty.inl b/include/openspace/properties/numericalproperty.inl index 3f5696f17a..23adef27f5 100644 --- a/include/openspace/properties/numericalproperty.inl +++ b/include/openspace/properties/numericalproperty.inl @@ -23,9 +23,11 @@ ****************************************************************************************/ #include +#include #include #include #include +#include namespace openspace::properties { @@ -90,6 +92,35 @@ float NumericalProperty::exponent() const { template void NumericalProperty::setExponent(float exponent) { ghoul_assert(std::abs(exponent) > 0.f, "Exponent for property input cannot be zero"); + + auto isValidRange = [](const T& minValue, const T& maxValue) { + if constexpr (ghoul::isGlmVector() || ghoul::isGlmMatrix()) { + return glm::all(glm::greaterThanEqual(minValue, T(0))) && + glm::all(glm::greaterThanEqual(maxValue, T(0))); + } + else { + return (minValue >= T(0) && maxValue >= T(0)); + } + }; + + // While the exponential slider does not support ranges with negative values, + // prevent setting the exponent for such ranges + // @ TODO (2021-06-30, emmbr), remove this check when no longer needed + if (!std::is_unsigned::value) { + if (!isValidRange(_minimumValue, _maximumValue)) { + LWARNINGC( + "NumericalProperty: setExponent", + fmt::format( + "Setting exponent for properties with negative values in " + "[min, max] range is not yet supported. Property: {}", + this->fullyQualifiedIdentifier() + ) + ); + _exponent = 1.f; + return; + } + } + _exponent = exponent; } diff --git a/include/openspace/scripting/scriptengine.h b/include/openspace/scripting/scriptengine.h index 94a187e1ca..e6c0c23607 100644 --- a/include/openspace/scripting/scriptengine.h +++ b/include/openspace/scripting/scriptengine.h @@ -31,9 +31,10 @@ #include #include #include +#include #include -#include #include +#include #include namespace openspace { class SyncBuffer; } @@ -82,7 +83,7 @@ public: bool hasLibrary(const std::string& name); bool runScript(const std::string& script, ScriptCallback callback = ScriptCallback()); - bool runScriptFile(const std::string& filename); + bool runScriptFile(const std::filesystem::path& filename); bool writeLog(const std::string& script); diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 33bb35fab1..1cf0fc71ce 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -74,8 +74,8 @@ namespace { "cullAtmosphere", "Rg", "Rt", "groundRadianceEmission", "HR", "betaRayleigh", "HM", "betaMieExtinction", "mieG", "sunRadiance", "ozoneLayerEnabled", "HO", "betaOzoneExtinction", "SAMPLES_R", "SAMPLES_MU", "SAMPLES_MU_S", "SAMPLES_NU", - "dInverseModelTransformMatrix", "dModelTransformMatrix", - "dSgctProjectionToModelTransformMatrix", "dSGCTViewToWorldMatrix", "dCamPosObj", + "inverseModelTransformMatrix", "modelTransformMatrix", + "projectionToModelTransformMatrix", "viewToWorldMatrix", "camPosObj", "sunDirectionObj", "hardShadows", "transmittanceTexture", "irradianceTexture", "inscatterTexture" }; @@ -309,53 +309,38 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, // Object Space glm::dmat4 inverseModelMatrix = glm::inverse(_modelTransform); program.setUniform( - _uniformCache.dInverseModelTransformMatrix, - inverseModelMatrix + _uniformCache.inverseModelTransformMatrix, inverseModelMatrix ); - program.setUniform(_uniformCache.dModelTransformMatrix, _modelTransform); + program.setUniform(_uniformCache.modelTransformMatrix, _modelTransform); - // Eye Space in SGCT to Eye Space in OS (SGCT View to OS Camera Rig) -// glm::dmat4 dSgctEye2OSEye = glm::inverse( -// glm::dmat4(renderData.camera.viewMatrix())); - - glm::dmat4 dSGCTViewToWorldMatrix = glm::inverse( + glm::dmat4 viewToWorldMatrix = glm::inverse( renderData.camera.combinedViewMatrix() ); - // Eye Space in SGCT to OS World Space - program.setUniform( - _uniformCache.dSGCTViewToWorldMatrix, - dSGCTViewToWorldMatrix - ); + // Eye Space to World Space + program.setUniform(_uniformCache.viewToWorldMatrix, viewToWorldMatrix); - // SGCT Projection to SGCT Eye Space + // Projection to Eye Space glm::dmat4 dInverseProjection = glm::inverse( glm::dmat4(renderData.camera.projectionMatrix()) ); glm::dmat4 inverseWholeMatrixPipeline = - inverseModelMatrix * dSGCTViewToWorldMatrix * dInverseProjection; + inverseModelMatrix * viewToWorldMatrix * dInverseProjection; program.setUniform( - _uniformCache.dSgctProjectionToModelTransformMatrix, + _uniformCache.projectionToModelTransformMatrix, inverseWholeMatrixPipeline ); glm::dvec4 camPosObjCoords = inverseModelMatrix * glm::dvec4(renderData.camera.eyePositionVec3(), 1.0); - program.setUniform(_uniformCache.dCamPosObj, camPosObjCoords); + program.setUniform(_uniformCache.camPosObj, glm::dvec3(camPosObjCoords)); + + SceneGraphNode* node = sceneGraph()->sceneGraphNode("Sun"); + glm::dvec3 sunPosWorld = node ? node->worldPosition() : glm::dvec3(0.0); - double lt; - glm::dvec3 sunPosWorld = SpiceManager::ref().targetPosition( - "SUN", - "SSB", - "GALACTIC", - {}, - _time, - lt - ); glm::dvec4 sunPosObj; - // Sun following camera position if (_sunFollowingCameraEnabled) { sunPosObj = inverseModelMatrix * glm::dvec4( @@ -365,7 +350,10 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, } else { sunPosObj = inverseModelMatrix * - glm::dvec4(sunPosWorld - renderData.modelTransform.translation, 1.0); + glm::dvec4( + (sunPosWorld - renderData.modelTransform.translation) * 1000.0, + 1.0 + ); } // Sun Position in Object Space @@ -374,6 +362,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, glm::normalize(glm::dvec3(sunPosObj)) ); + ghoul::opengl::updateUniformLocations(program, _uniformCache, UniformNames); + // Shadow calculations.. if (!_shadowConfArray.empty()) { ZoneScopedN("Shadow Configuration") @@ -384,6 +374,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData, // TO REMEMBER: all distances and lengths in world coordinates are in // meters!!! We need to move this to view space... // Getting source and caster: + double lt; glm::dvec3 sourcePos = SpiceManager::ref().targetPosition( shadowConf.source.first, "SSB", diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.h b/modules/atmosphere/rendering/atmospheredeferredcaster.h index dd8ce176a9..589d2479c7 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.h +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.h @@ -126,9 +126,9 @@ private: UniformCache(cullAtmosphere, Rg, Rt, groundRadianceEmission, HR, betaRayleigh, HM, betaMieExtinction, mieG, sunRadiance, ozoneLayerEnabled, HO, betaOzoneExtinction, - SAMPLES_R, SAMPLES_MU, SAMPLES_MU_S, SAMPLES_NU, dInverseModelTransformMatrix, - dModelTransformMatrix, dSgctProjectionToModelTransformMatrix, - dSGCTViewToWorldMatrix, dCamPosObj, sunDirectionObj, hardShadows, + SAMPLES_R, SAMPLES_MU, SAMPLES_MU_S, SAMPLES_NU, inverseModelTransformMatrix, + modelTransformMatrix, projectionToModelTransformMatrix, + viewToWorldMatrix, camPosObj, sunDirectionObj, hardShadows, transmittanceTexture, irradianceTexture, inscatterTexture) _uniformCache; GLuint _transmittanceTableTexture = 0; diff --git a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl index 9be329d940..f0f97c8de1 100644 --- a/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl +++ b/modules/atmosphere/shaders/atmosphere_deferred_fs.glsl @@ -62,7 +62,6 @@ in vec2 texCoord; out vec4 renderTarget; -uniform int nAaSamples; uniform int cullAtmosphere; uniform sampler2D irradianceTexture; @@ -71,17 +70,21 @@ uniform sampler2D mainPositionTexture; uniform sampler2D mainNormalTexture; uniform sampler2D mainColorTexture; -uniform dmat4 dInverseModelTransformMatrix; -uniform dmat4 dModelTransformMatrix; -uniform dmat4 dSGCTViewToWorldMatrix; -uniform dmat4 dSgctProjectionToModelTransformMatrix; +uniform dmat4 inverseModelTransformMatrix; +uniform dmat4 modelTransformMatrix; +uniform dmat4 viewToWorldMatrix; +uniform dmat4 projectionToModelTransformMatrix; uniform vec4 viewport; uniform vec2 resolution; -uniform dvec4 dCamPosObj; +uniform dvec3 camPosObj; uniform dvec3 sunDirectionObj; +uniform dvec3 sunWorld; +uniform dvec3 viewDirWorld; +uniform dvec3 sunModel; + /******************************************************************************* ***** ALL CALCULATIONS FOR ECLIPSE ARE IN METERS AND IN WORLD SPACE SYSTEM **** *******************************************************************************/ @@ -215,13 +218,13 @@ Ray calculateRayRenderableGlobe(vec2 st) { dvec4 clipCoords = dvec4(interpolatedNDCPos, 1.0, 1.0); // Clip to Object Coords - dvec4 objectCoords = dSgctProjectionToModelTransformMatrix * clipCoords; - objectCoords /= objectCoords.w; + dvec4 objectCoords = projectionToModelTransformMatrix * clipCoords; + objectCoords.xyz /= objectCoords.w; // Building Ray // Ray in object space (in KM) Ray ray; - ray.origin = dvec3(dCamPosObj * dvec4(0.001, 0.001, 0.001, 1.0)); + ray.origin = camPosObj * 0.001; ray.direction = normalize(objectCoords.xyz * dvec3(0.001) - ray.origin); return ray; } @@ -244,16 +247,15 @@ Ray calculateRayRenderableGlobe(vec2 st) { * attenuation := out of transmittance T(x,x0). This will be used later when calculating * the reflectance R[L] */ -vec3 inscatterRadiance(vec3 x, inout float t, out float irradianceFactor, vec3 v, vec3 s, - out float r, out float mu, out vec3 attenuation, vec3 fragPosObj, +vec3 inscatterRadiance(vec3 x, inout float t, inout float irradianceFactor, vec3 v, vec3 s, + float r, out float mu, out vec3 attenuation, vec3 fragPosObj, out bool groundHit, double maxLength, double pixelDepth, - vec4 spaceColor, float sunIntensity) + vec3 spaceColor, float sunIntensity) { const float INTERPOLATION_EPS = 0.004; // precision const from Brunetton vec3 radiance; - r = length(x); mu = dot(x, v) / r; float r2 = r * r; @@ -303,16 +305,15 @@ vec3 inscatterRadiance(vec3 x, inout float t, out float irradianceFactor, vec3 v } // cos(PI-thetaH) = dist/r - // cos(thetaH) = - dist/r + // cos(thetaH) = -dist/r // muHorizon = -sqrt(r^2-Rg^2)/r = -sqrt(1-(Rg/r)^2) float muHorizon = -sqrt(1.0 - Rg2 / r2); - // In order to avoid imprecision problems near horizon, we interpolate between two + // In order to avoid precision problems near horizon, we interpolate between two // points: above and below horizon if (abs(mu - muHorizon) < INTERPOLATION_EPS) { // We want an interpolation value close to 1/2, so the contribution of each radiance - // value is almost the same or it has a heavy weight if from above or - // below horizon + // value is almost the same or it has a heavy weight if from above or below horizon float interpolationValue = (mu - muHorizon + INTERPOLATION_EPS) / (2.0 * INTERPOLATION_EPS); // Above Horizon @@ -321,9 +322,9 @@ vec3 inscatterRadiance(vec3 x, inout float t, out float irradianceFactor, vec3 v // From cosine law where t = distance between x and x0 // r0^2 = r^2 + t^2 - 2 * r * t * cos(PI-theta) // r0 = sqrt(r2 + t2 + 2.0f * r * t * mu); - float halfCossineLaw1 = r2 + (t * t); - float halfCossineLaw2 = 2.0 * r * t; - r0 = sqrt(halfCossineLaw1 + halfCossineLaw2 * mu); + float halfCosineLaw1 = r2 + (t * t); + float halfCosineLaw2 = 2.0 * r * t; + r0 = sqrt(halfCosineLaw1 + halfCosineLaw2 * mu); // From the dot product: cos(theta0) = (x0 dot v)/(||ro||*||v||) // mu0 = ((x + t) dot v) / r0 @@ -339,7 +340,7 @@ vec3 inscatterRadiance(vec3 x, inout float t, out float irradianceFactor, vec3 v // Below Horizon mu = muHorizon + INTERPOLATION_EPS; //r0 = sqrt(r2 + t2 + 2.0f * r * t * mu); - r0 = sqrt(halfCossineLaw1 + halfCossineLaw2 * mu); + r0 = sqrt(halfCosineLaw1 + halfCosineLaw2 * mu); mu0 = (r * mu + t) * (1.0 / r0); @@ -374,7 +375,7 @@ vec3 inscatterRadiance(vec3 x, inout float t, out float irradianceFactor, vec3 v return finalScatteringRadiance; } else { - return spaceColor.rgb + finalScatteringRadiance; + return spaceColor + finalScatteringRadiance; } } @@ -457,16 +458,23 @@ vec3 groundColor(vec3 x, float t, vec3 v, vec3 s, vec3 attenuationXtoX0, vec3 gr * attenuation := transmittance T(x,x0) */ vec3 sunColor(vec3 v, vec3 s, float r, float mu, float irradianceFactor) { - vec3 tm = vec3(1.0); - if (r <= Rt) { - tm = mu < -sqrt(1.0 - Rg2 / (r * r)) ? vec3(0.0) : transmittance(r, mu); - } - // JCC: Change this function to a impostor texture with gaussian decay color weighted - // by the sunRadiance, transmittance and irradianceColor (11/03/2017) - float sunFinalColor = smoothstep(cos(M_PI / 500.0), cos(M_PI / 900.0), dot(v, s)) * - sunRadiance * (1.0 - irradianceFactor); + // v = normalize(vec3(inverseModelTransformMatrix * dvec4(sunWorld, 1.0))); + float angle = dot(v, s); - return tm * sunFinalColor; + // JCC: Change this function to a impostor texture with gaussian decay color weighted + // by the sunRadiance, transmittance and irradianceColor (11/03/2017) + + // @TODO (abock, 2021-07-01) This value is hard-coded to our sun right now + // Convert 0.3 degrees -> radians + const float SunAngularSize = (0.3 * M_PI / 180.0); + const float FuzzyFactor = 0.5; // How fuzzy should the edges be + + const float p1 = cos(SunAngularSize); + const float p2 = cos(SunAngularSize * FuzzyFactor); + + float t = (angle - p1) / (p2 - p1); + float scale = clamp(t, 0.0, 1.0); + return scale * transmittance(r, mu) * sunRadiance * (1.0 - irradianceFactor); } void main() { @@ -481,17 +489,13 @@ void main() { st.x = st.x / (resolution.x / viewport[2]) + (viewport[0] / resolution.x); st.y = st.y / (resolution.y / viewport[3]) + (viewport[1] / resolution.y); + // Color from G-Buffer + vec3 color = texture(mainColorTexture, st).rgb; if (cullAtmosphere == 1) { - renderTarget = texture(mainColorTexture, st); + renderTarget.rgb = color; return; } - vec4 atmosphereFinalColor = vec4(0.0); - int nSamples = 1; - - // Color from G-Buffer - vec4 color = texture(mainColorTexture, st); - // Get the ray from camera to atm in object space Ray ray = calculateRayRenderableGlobe(texCoord); @@ -499,7 +503,7 @@ void main() { double maxLength = 0.0; // in KM bool intersect = atmosphereIntersection(ray, Rt - (ATM_EPSILON * 0.001), offset, maxLength); if (!intersect) { - renderTarget = color; + renderTarget.rgb = color; return; } @@ -509,14 +513,11 @@ void main() { // Space (View plus Camera Rig Coords) when using their positions later, one must // convert them to the planet's coords - // - // Get data from G-Buffer - - // Normal is stored in SGCT View Space and transformed to the current object space + // Normal is stored in view space and transformed to the current object space vec4 normalViewSpaceAndWaterReflectance = texture(mainNormalTexture, st); dvec4 normalViewSpace = vec4(normalViewSpaceAndWaterReflectance.xyz, 0.0); - dvec4 normalWorldSpace = dSGCTViewToWorldMatrix * normalViewSpace; - vec4 normal = vec4(dInverseModelTransformMatrix * normalWorldSpace); + dvec4 normalWorldSpace = viewToWorldMatrix * normalViewSpace; + vec4 normal = vec4(inverseModelTransformMatrix * normalWorldSpace); normal.xyz = normalize(normal.xyz); normal.w = normalViewSpaceAndWaterReflectance.w; @@ -524,19 +525,20 @@ void main() { vec4 position = texture(mainPositionTexture, st); // OS Eye to World coords - dvec4 positionWorldCoords = dSGCTViewToWorldMatrix * position; + dvec4 positionWorldCoords = viewToWorldMatrix * position; // World to Object (Normal and Position in meters) - dvec4 positionObjectsCoords = dInverseModelTransformMatrix * positionWorldCoords; + dvec3 positionObjectsCoords = (inverseModelTransformMatrix * positionWorldCoords).xyz; // Distance of the pixel in the gBuffer to the observer // JCC (12/12/2017): AMD distance function is buggy. //double pixelDepth = distance(cameraPositionInObject.xyz, positionObjectsCoords.xyz); - double pixelDepth = length(dCamPosObj.xyz - positionObjectsCoords.xyz); + double pixelDepth = length(camPosObj - positionObjectsCoords); // JCC (12/13/2017): Trick to remove floating error in texture. // We see a squared noise on planet's surface when seeing the planet from far away - float dC = float(length(dCamPosObj.xyz)); + // @TODO (abock, 2021-07-01) I don't think this does anything. Remove? + float dC = float(length(camPosObj)); const float x1 = 1e8; if (dC > x1) { pixelDepth += 1000.0; @@ -552,22 +554,21 @@ void main() { // All calculations are done in KM: pixelDepth *= 0.001; - positionObjectsCoords.xyz *= 0.001; + positionObjectsCoords *= 0.001; if (pixelDepth < offset) { // ATM Occluded - Something in front of ATM - renderTarget = color; + renderTarget.rgb = color; return; } // Following paper nomenclature double t = offset; - vec3 attenuation; // Moving observer from camera location to top atmosphere. If the observer is already // inside the atm, offset = 0.0 and no changes at all vec3 x = vec3(ray.origin + t * ray.direction); - float r = 0.0; // length(x); + float r = length(x); vec3 v = vec3(ray.direction); float mu = 0.0; // dot(x, v) / r; vec3 s = vec3(sunDirectionObj); @@ -578,27 +579,30 @@ void main() { // comparison with the planet's ground make sense: pixelDepth -= offset; - dvec3 onATMPos = (dModelTransformMatrix * dvec4(x * 1000.0, 1.0)).xyz; + dvec3 onATMPos = (modelTransformMatrix * dvec4(x * 1000.0, 1.0)).xyz; float eclipseShadowATM = calcShadow(shadowDataArray, onATMPos, false); float sunIntensityInscatter = sunRadiance * eclipseShadowATM; float irradianceFactor = 0.0; bool groundHit = false; + vec3 attenuation; + vec3 inscatterColor = inscatterRadiance(x, tF, irradianceFactor, v, s, r, mu, - attenuation, vec3(positionObjectsCoords.xyz), groundHit, maxLength, pixelDepth, - color, sunIntensityInscatter); + attenuation, vec3(positionObjectsCoords), groundHit, maxLength, pixelDepth, + color, sunIntensityInscatter); vec3 atmColor = vec3(0.0); if (groundHit) { float eclipseShadowPlanet = calcShadow(shadowDataArray, positionWorldCoords.xyz, true); float sunIntensityGround = sunRadiance * eclipseShadowPlanet; - atmColor = groundColor(x, tF, v, s, attenuation, color.rgb, normal.xyz, + atmColor = groundColor(x, tF, v, s, attenuation, color, normal.xyz, irradianceFactor, normal.w, sunIntensityGround); } else { // In order to get better performance, we are not tracing multiple rays per pixel // when the ray doesn't intersect the ground - atmColor = sunColor(v, s, r, mu, irradianceFactor); + + atmColor = sunColor(v, s, r, mu, irradianceFactor); } // Final Color of ATM plus terrain: diff --git a/modules/base/basemodule.cpp b/modules/base/basemodule.cpp index 67f2332629..048bbc0d45 100644 --- a/modules/base/basemodule.cpp +++ b/modules/base/basemodule.cpp @@ -213,6 +213,7 @@ std::vector BaseModule::documentations() const { ScreenSpaceImageLocal::Documentation(), ScreenSpaceImageOnline::Documentation(), + ConstantRotation::Documentation(), FixedRotation::Documentation(), LuaRotation::Documentation(), StaticRotation::Documentation(), diff --git a/modules/base/rendering/renderableplaneimagelocal.cpp b/modules/base/rendering/renderableplaneimagelocal.cpp index 7b48b72bb5..6f6d88cacd 100644 --- a/modules/base/rendering/renderableplaneimagelocal.cpp +++ b/modules/base/rendering/renderableplaneimagelocal.cpp @@ -196,7 +196,7 @@ void RenderablePlaneImageLocal::loadTexture() { LDEBUGC( "RenderablePlaneImageLocal", - fmt::format("Loaded texture from '{}'", absPath(path)) + fmt::format("Loaded texture from {}", absPath(path)) ); texture->uploadTexture(); texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); diff --git a/modules/base/rendering/renderableplaneimageonline.cpp b/modules/base/rendering/renderableplaneimageonline.cpp index 8ce7be472e..998790b581 100644 --- a/modules/base/rendering/renderableplaneimageonline.cpp +++ b/modules/base/rendering/renderableplaneimageonline.cpp @@ -96,53 +96,55 @@ void RenderablePlaneImageOnline::bindTexture() { } void RenderablePlaneImageOnline::update(const UpdateData&) { - if (_textureIsDirty) { - if (!_imageFuture.valid()) { - std::future future = downloadImageToMemory( - _texturePath + if (!_textureIsDirty) { + return; + } + + if (!_imageFuture.valid()) { + std::future future = downloadImageToMemory( + _texturePath + ); + if (future.valid()) { + _imageFuture = std::move(future); + } + } + + if (_imageFuture.valid() && DownloadManager::futureReady(_imageFuture)) { + DownloadManager::MemoryFile imageFile = _imageFuture.get(); + + if (imageFile.corrupted) { + LERRORC( + "ScreenSpaceImageOnline", + fmt::format("Error loading image from URL '{}'", _texturePath) ); - if (future.valid()) { - _imageFuture = std::move(future); - } + return; } - if (_imageFuture.valid() && DownloadManager::futureReady(_imageFuture)) { - DownloadManager::MemoryFile imageFile = _imageFuture.get(); - - if (imageFile.corrupted) { - LERRORC( - "ScreenSpaceImageOnline", - fmt::format("Error loading image from URL '{}'", _texturePath) + try { + std::unique_ptr texture = + ghoul::io::TextureReader::ref().loadTexture( + reinterpret_cast(imageFile.buffer), + imageFile.size, + imageFile.format ); - return; - } - try { - std::unique_ptr texture = - ghoul::io::TextureReader::ref().loadTexture( - reinterpret_cast(imageFile.buffer), - imageFile.size, - imageFile.format - ); + if (texture) { + // Images don't need to start on 4-byte boundaries, for example if the + // image is only RGB + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - if (texture) { - // Images don't need to start on 4-byte boundaries, for example if the - // image is only RGB - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + texture->uploadTexture(); + texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); + texture->purgeFromRAM(); - texture->uploadTexture(); - texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); - texture->purgeFromRAM(); - - _texture = std::move(texture); - _textureIsDirty = false; - } - } - catch (const ghoul::io::TextureReader::InvalidLoadException& e) { + _texture = std::move(texture); _textureIsDirty = false; - LERRORC(e.component, e.message); } } + catch (const ghoul::io::TextureReader::InvalidLoadException& e) { + _textureIsDirty = false; + LERRORC(e.component, e.message); + } } } diff --git a/modules/base/rendering/renderableprism.cpp b/modules/base/rendering/renderableprism.cpp index 7c96247b21..20f610d3c8 100644 --- a/modules/base/rendering/renderableprism.cpp +++ b/modules/base/rendering/renderableprism.cpp @@ -268,8 +268,8 @@ void RenderablePrism::updateVertexData() { _indexArray.push_back(255); // Indices for Top shape - for (uint8_t i = _nShapeSegments; i < 2 * _nShapeSegments; ++i) { - _indexArray.push_back(i); + for (int i = _nShapeSegments; i < 2 * _nShapeSegments; ++i) { + _indexArray.push_back(static_cast(i)); } // Indices for connecting lines @@ -277,8 +277,8 @@ void RenderablePrism::updateVertexData() { // Reset _indexArray.push_back(255); - _indexArray.push_back(2 * _nShapeSegments + k); - _indexArray.push_back(2 * _nShapeSegments + k + 1); + _indexArray.push_back(static_cast(2 * _nShapeSegments + k)); + _indexArray.push_back(static_cast(2 * _nShapeSegments + k + 1)); } } diff --git a/modules/base/rendering/renderablesphere.cpp b/modules/base/rendering/renderablesphere.cpp index e6b32389be..4d05f81f3d 100644 --- a/modules/base/rendering/renderablesphere.cpp +++ b/modules/base/rendering/renderablesphere.cpp @@ -452,7 +452,7 @@ void RenderableSphere::loadTexture() { if (texture) { LDEBUGC( "RenderableSphere", - fmt::format("Loaded texture from '{}'", absPath(_texturePath)) + fmt::format("Loaded texture from {}", absPath(_texturePath)) ); texture->uploadTexture(); texture->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); diff --git a/modules/base/rotation/luarotation.cpp b/modules/base/rotation/luarotation.cpp index 86d9e8d619..b2d019e305 100644 --- a/modules/base/rotation/luarotation.cpp +++ b/modules/base/rotation/luarotation.cpp @@ -79,7 +79,7 @@ LuaRotation::LuaRotation(const ghoul::Dictionary& dictionary) : LuaRotation() { } glm::dmat3 LuaRotation::matrix(const UpdateData& data) const { - ghoul::lua::runScriptFile(_state, _luaScriptFile); + ghoul::lua::runScriptFile(_state, _luaScriptFile.value()); // Get the scaling function lua_getglobal(_state, "rotation"); @@ -87,7 +87,9 @@ glm::dmat3 LuaRotation::matrix(const UpdateData& data) const { if (!isFunction) { LERRORC( "LuaRotation", - fmt::format("Script '{}' does nto have a function 'rotation'", _luaScriptFile) + fmt::format( + "Script '{}' does not have a function 'rotation'", _luaScriptFile.value() + ) ); return glm::dmat3(1.0); } diff --git a/modules/base/scale/luascale.cpp b/modules/base/scale/luascale.cpp index f99600595e..8eb44f4b47 100644 --- a/modules/base/scale/luascale.cpp +++ b/modules/base/scale/luascale.cpp @@ -77,7 +77,7 @@ LuaScale::LuaScale(const ghoul::Dictionary& dictionary) : LuaScale() { } glm::dvec3 LuaScale::scaleValue(const UpdateData& data) const { - ghoul::lua::runScriptFile(_state, _luaScriptFile); + ghoul::lua::runScriptFile(_state, _luaScriptFile.value()); // Get the scaling function lua_getglobal(_state, "scale"); @@ -85,7 +85,9 @@ glm::dvec3 LuaScale::scaleValue(const UpdateData& data) const { if (!isFunction) { LERRORC( "LuaScale", - fmt::format("Script '{}' does not have a function 'scale'", _luaScriptFile) + fmt::format( + "Script '{}' does not have a function 'scale'", _luaScriptFile.value() + ) ); return glm::dvec3(1.0); } diff --git a/modules/base/translation/luatranslation.cpp b/modules/base/translation/luatranslation.cpp index 2f853e8394..d0873b550a 100644 --- a/modules/base/translation/luatranslation.cpp +++ b/modules/base/translation/luatranslation.cpp @@ -81,7 +81,7 @@ LuaTranslation::LuaTranslation(const ghoul::Dictionary& dictionary) : LuaTransla } glm::dvec3 LuaTranslation::position(const UpdateData& data) const { - ghoul::lua::runScriptFile(_state, _luaScriptFile); + ghoul::lua::runScriptFile(_state, _luaScriptFile.value()); // Get the scaling function lua_getglobal(_state, "translation"); @@ -91,7 +91,7 @@ glm::dvec3 LuaTranslation::position(const UpdateData& data) const { "LuaScale", fmt::format( "Script '{}' does not have a function 'translation'", - _luaScriptFile + _luaScriptFile.value() ) ); return glm::dvec3(0.0); @@ -119,7 +119,7 @@ glm::dvec3 LuaTranslation::position(const UpdateData& data) const { double values[3]; for (int i = 1; i <= 3; ++i) { - values[i] = ghoul::lua::value(_state, i); + values[i - 1] = ghoul::lua::value(_state, i); } return glm::make_vec3(values); diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 4113d606ff..8b334a02e6 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -970,7 +970,7 @@ void RenderableBillboardsCloud::update(const UpdateData&) { _spriteTexture = DigitalUniverseModule::TextureManager.request( std::to_string(hash), [path = _spriteTexturePath]() -> std::unique_ptr { - LINFO(fmt::format("Loaded texture from '{}'", absPath(path))); + LINFO(fmt::format("Loaded texture from {}", absPath(path))); std::unique_ptr t = ghoul::io::TextureReader::ref().loadTexture(absPath(path).string()); t->uploadTexture(); diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index b7e0a708df..9fc7d78962 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -484,7 +484,7 @@ void RenderableDUMeshes::update(const UpdateData&) { bool RenderableDUMeshes::loadData() { bool success = false; if (_hasSpeckFile) { - LINFO(fmt::format("Loading Speck file '{}'", _speckFile)); + LINFO(fmt::format("Loading Speck file {}", std::filesystem::path(_speckFile))); success = readSpeckFile(); if (!success) { return false; @@ -502,7 +502,9 @@ bool RenderableDUMeshes::loadData() { bool RenderableDUMeshes::readSpeckFile() { std::ifstream file(_speckFile); if (!file.good()) { - LERROR(fmt::format("Failed to open Speck file '{}'", _speckFile)); + LERROR(fmt::format( + "Failed to open Speck file {}", std::filesystem::path(_speckFile) + )); return false; } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 1e54b6a7c7..18d0117607 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -272,7 +272,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary addProperty(_opacity); if (p.file.has_value()) { - _speckFile = absPath(*p.file).string(); + _speckFile = absPath(*p.file); _hasSpeckFile = true; _drawElements.onChange([&]() { _hasSpeckFile = !_hasSpeckFile; }); addProperty(_drawElements); @@ -320,7 +320,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary _scaleFactor.onChange([&]() { _dataIsDirty = true; }); if (p.labelFile.has_value()) { - _labelFile = absPath(*p.labelFile).string(); + _labelFile = absPath(*p.labelFile); _hasLabel = true; _textColor = p.textColor.value_or(_textColor); @@ -368,7 +368,7 @@ RenderablePlanesCloud::RenderablePlanesCloud(const ghoul::Dictionary& dictionary } } - _texturesPath = absPath(p.texturePath).string(); + _texturesPath = absPath(p.texturePath); _luminosityVar = p.luminosity.value_or(_luminosityVar); _sluminosity = p.scaleLuminosity.value_or(_sluminosity); @@ -403,7 +403,7 @@ void RenderablePlanesCloud::initialize() { } if (!_labelFile.empty()) { - LINFO(fmt::format("Loading Label file '{}'", _labelFile)); + LINFO(fmt::format("Loading Label file {}", _labelFile)); _labelset = speck::label::loadFileWithCache(_labelFile); for (speck::Labelset::Entry& e : _labelset.entries) { e.position = glm::vec3(_transformationMatrix * glm::dvec4(e.position, 1.0)); @@ -612,7 +612,7 @@ void RenderablePlanesCloud::update(const UpdateData&) { void RenderablePlanesCloud::loadTextures() { for (const speck::Dataset::Texture& tex : _dataset.textures) { - std::filesystem::path fullPath = absPath(_texturesPath + '/' + tex.file); + std::filesystem::path fullPath = absPath(_texturesPath.string() + '/' + tex.file); std::filesystem::path pngPath = fullPath; pngPath.replace_extension(".png"); @@ -634,7 +634,7 @@ void RenderablePlanesCloud::loadTextures() { ghoul::io::TextureReader::ref().loadTexture(path.string()); if (t) { - LINFOC("RenderablePlanesCloud", fmt::format("Loaded texture '{}'", path)); + LINFOC("RenderablePlanesCloud", fmt::format("Loaded texture {}", path)); t->uploadTexture(); t->setFilter(ghoul::opengl::Texture::FilterMode::LinearMipMap); t->purgeFromRAM(); diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.h b/modules/digitaluniverse/rendering/renderableplanescloud.h index de2d2386cd..b669e1e168 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.h +++ b/modules/digitaluniverse/rendering/renderableplanescloud.h @@ -34,10 +34,9 @@ #include #include #include - #include #include - +#include #include #include @@ -129,9 +128,9 @@ private: std::unordered_map _textureFileMap; std::unordered_map _planesMap; - std::string _speckFile; - std::string _labelFile; - std::string _texturesPath; + std::filesystem::path _speckFile; + std::filesystem::path _labelFile; + std::filesystem::path _texturesPath; std::string _luminosityVar; Unit _unit = Parsec; diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index 286e247d96..e3449d0095 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -135,7 +135,7 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) addProperty(_opacity); registerUpdateRenderBinFromOpacity(); - _speckFile = absPath(p.file).string(); + _speckFile = absPath(p.file); if (p.unit.has_value()) { switch (*p.unit) { @@ -185,7 +185,7 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) } if (p.colorMap.has_value()) { - _colorMapFile = absPath(*p.colorMap).string(); + _colorMapFile = absPath(*p.colorMap); _hasColorMapFile = true; } @@ -347,9 +347,9 @@ void RenderablePoints::update(const UpdateData&) { absPath(_spriteTexturePath).string() ); if (_spriteTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'",absPath(_spriteTexturePath) - )); + LDEBUG( + fmt::format("Loaded texture from {}", absPath(_spriteTexturePath)) + ); _spriteTexture->uploadTexture(); } _spriteTexture->setFilter( @@ -369,7 +369,7 @@ void RenderablePoints::readColorMapFile() { std::ifstream file(_colorMapFile); if (!file.good()) { throw ghoul::RuntimeError(fmt::format( - "Failed to open Color Map file '{}'", _colorMapFile + "Failed to open Color Map file {}", _colorMapFile )); } @@ -396,7 +396,7 @@ void RenderablePoints::readColorMapFile() { } else if (file.eof()) { throw ghoul::RuntimeError(fmt::format( - "Failed to load colors from Color Map file '{}'", _colorMapFile + "Failed to load colors from Color Map file {}", _colorMapFile )); } } diff --git a/modules/digitaluniverse/rendering/renderablepoints.h b/modules/digitaluniverse/rendering/renderablepoints.h index 0f7c4f1361..2f8d3047b0 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.h +++ b/modules/digitaluniverse/rendering/renderablepoints.h @@ -35,6 +35,7 @@ #include #include #include +#include namespace ghoul::filesystem { class File; } @@ -95,8 +96,8 @@ private: spriteTexture, hasColorMap ) _uniformCache; - std::string _speckFile; - std::string _colorMapFile; + std::filesystem::path _speckFile; + std::filesystem::path _colorMapFile; Unit _unit = Parsec; diff --git a/modules/exoplanets/exoplanetshelper.cpp b/modules/exoplanets/exoplanetshelper.cpp index f538f73f6f..6ec7f2866c 100644 --- a/modules/exoplanets/exoplanetshelper.cpp +++ b/modules/exoplanets/exoplanetshelper.cpp @@ -65,8 +65,7 @@ glm::vec3 computeStarColor(float bv) { if (!colorMap.good()) { LERROR(fmt::format( - "Failed to open colormap data file: '{}'", - absPath(bvColormapPath) + "Failed to open colormap data file: {}", absPath(bvColormapPath) )); return glm::vec3(0.f); } diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 6ee47f1d7a..f5359e9dbe 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -158,8 +158,8 @@ void createExoplanetSystem(const std::string& starName) { const glm::vec3 starPosInParsec = system.starData.position; if (!isValidPosition(starPosInParsec)) { LERROR(fmt::format( - "Insufficient data available for exoplanet system: '{}'. " - "Could not determine star position", starName + "Insufficient data available for exoplanet system: '{}'. Could not determine " + "star position", starName )); return; } diff --git a/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp b/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp index 7b18d0579d..6646797433 100644 --- a/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp +++ b/modules/fieldlinessequence/util/kameleonfieldlinehelper.cpp @@ -303,8 +303,10 @@ void prepareStateAndKameleonForExtras(ccmc::Kameleon* kameleon, if (!success && (model == fls::Model::Batsrus && (str == TAsPOverRho || str == "T"))) { - LDEBUG("BATSRUS doesn't contain variable T for temperature. Trying to " - "calculate it using the ideal gas law: T = pressure/density"); + LDEBUG( + "BATSRUS doesn't contain variable T for temperature. Trying to calculate " + "it using the ideal gas law: T = pressure/density" + ); constexpr const char* p = "p"; constexpr const char* r = "rho"; success = kameleon->doesVariableExist(p) && kameleon->loadVariable(p) && @@ -312,9 +314,7 @@ void prepareStateAndKameleonForExtras(ccmc::Kameleon* kameleon, str = TAsPOverRho; } if (!success) { - LWARNING(fmt::format( - "Failed to load extra variable: '{}'. Ignoring", str - )); + LWARNING(fmt::format("Failed to load extra variable: '{}'. Ignoring", str)); extraScalarVars.erase(extraScalarVars.begin() + i); --i; } diff --git a/modules/fitsfilereader/include/fitsfilereader.h b/modules/fitsfilereader/include/fitsfilereader.h index 9418fc42fb..e3909d5f93 100644 --- a/modules/fitsfilereader/include/fitsfilereader.h +++ b/modules/fitsfilereader/include/fitsfilereader.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_MODULE_FITSFILEREADER___FITSFILEREADER___H__ #define __OPENSPACE_MODULE_FITSFILEREADER___FITSFILEREADER___H__ +#include #include #include #include @@ -63,7 +64,7 @@ public: ~FitsFileReader(); template - std::shared_ptr> readImage(const std::string& path); + std::shared_ptr> readImage(const std::filesystem::path& path); template std::shared_ptr> readHeader( @@ -78,7 +79,7 @@ public: * If no HDU index is given the current Extension HDU will be read from. */ template - std::shared_ptr> readTable(std::string& path, + std::shared_ptr> readTable(const std::filesystem::path& path, const std::vector& columnNames, int startRow = 1, int endRow = 10, int hduIdx = 1, bool readAll = false); @@ -88,7 +89,7 @@ public: * If additional columns are given by filterColumnNames, they will be * read but it will slow doen the reading tremendously. */ - std::vector readFitsFile(std::string filePath, int& nValuesPerStar, + std::vector readFitsFile(std::filesystem::path filePath, int& nValuesPerStar, int firstRow, int lastRow, std::vector filterColumnNames, int multiplier = 1); @@ -96,7 +97,8 @@ public: * Reads a single SPECK file and returns a vector with nRenderValues * per star. Reads data in pre-defined order based on AMNH's star data files. */ - std::vector readSpeckFile(const std::string& filePath, int& nRenderValues); + std::vector readSpeckFile(const std::filesystem::path& filePath, + int& nRenderValues); private: std::unique_ptr _infile; diff --git a/modules/fitsfilereader/src/fitsfilereader.cpp b/modules/fitsfilereader/src/fitsfilereader.cpp index 26e945fad3..f273326e82 100644 --- a/modules/fitsfilereader/src/fitsfilereader.cpp +++ b/modules/fitsfilereader/src/fitsfilereader.cpp @@ -69,7 +69,8 @@ bool FitsFileReader::isPrimaryHDU() { } template -std::shared_ptr> FitsFileReader::readImage(const std::string& path) { +std::shared_ptr> FitsFileReader::readImage(const std::filesystem::path& path) +{ try { _infile = std::make_unique(path, Read, true); // Primary HDU Object @@ -136,7 +137,7 @@ std::shared_ptr FitsFileReader::readHeaderValue(const std::string key) { } template -std::shared_ptr> FitsFileReader::readTable(std::string& path, +std::shared_ptr> FitsFileReader::readTable(const std::filesystem::path& path, const std::vector& columnNames, int startRow, int endRow, @@ -148,7 +149,7 @@ std::shared_ptr> FitsFileReader::readTable(std::string& path, std::lock_guard g(_mutex); try { - _infile = std::make_unique(path, Read, readAll); + _infile = std::make_unique(path.string(), Read, readAll); // Make sure FITS file is not a Primary HDU Object (aka an image). if (!isPrimaryHDU()) { @@ -191,8 +192,9 @@ std::shared_ptr> FitsFileReader::readTable(std::string& path, return nullptr; } -std::vector FitsFileReader::readFitsFile(std::string filePath, int& nValuesPerStar, - int firstRow, int lastRow, +std::vector FitsFileReader::readFitsFile(std::filesystem::path filePath, + int& nValuesPerStar, int firstRow, + int lastRow, std::vector filterColumnNames, int multiplier) { @@ -245,7 +247,7 @@ std::vector FitsFileReader::readFitsFile(std::string filePath, int& nValu ); if (!table) { - throw ghoul::RuntimeError(fmt::format("Failed to open Fits file '{}'", filePath)); + throw ghoul::RuntimeError(fmt::format("Failed to open Fits file {}", filePath)); } int nStars = table->readRows - firstRow + 1; @@ -520,7 +522,7 @@ std::vector FitsFileReader::readFitsFile(std::string filePath, int& nValu return fullData; } -std::vector FitsFileReader::readSpeckFile(const std::string& filePath, +std::vector FitsFileReader::readSpeckFile(const std::filesystem::path& filePath, int& nRenderValues) { std::vector fullData; @@ -528,7 +530,7 @@ std::vector FitsFileReader::readSpeckFile(const std::string& filePath, std::ifstream fileStream(filePath); if (!fileStream.good()) { - LERROR(fmt::format("Failed to open Speck file '{}'", filePath)); + LERROR(fmt::format("Failed to open Speck file {}", filePath)); return fullData; } diff --git a/modules/gaia/rendering/renderablegaiastars.cpp b/modules/gaia/rendering/renderablegaiastars.cpp index 2971318b53..44e8d3f579 100644 --- a/modules/gaia/rendering/renderablegaiastars.cpp +++ b/modules/gaia/rendering/renderablegaiastars.cpp @@ -2131,9 +2131,7 @@ void RenderableGaiaStars::update(const UpdateData&) { absPath(_colorTexturePath).string() ); if (_colorTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'", absPath(_colorTexturePath) - )); + LDEBUG(fmt::format("Loaded texture from {}", absPath(_colorTexturePath))); _colorTexture->uploadTexture(); } @@ -2188,28 +2186,29 @@ bool RenderableGaiaStars::readDataFile() { _octreeManager.initOctree(_cpuRamBudgetInBytes); - LINFO("Loading data file: " + _filePath.value()); + std::filesystem::path file = absPath(_filePath.value()); + LINFO(fmt::format("Loading data file: {}", file)); switch (fileReaderOption) { case gaia::FileReaderOption::Fits: // Read raw fits file and construct Octree. - nReadStars = readFitsFile(_filePath); + nReadStars = readFitsFile(file); break; case gaia::FileReaderOption::Speck: // Read raw speck file and construct Octree. - nReadStars = readSpeckFile(_filePath); + nReadStars = readSpeckFile(file); break; case gaia::FileReaderOption::BinaryRaw: // Stars are stored in an ordered binary file. - nReadStars = readBinaryRawFile(_filePath); + nReadStars = readBinaryRawFile(file); break; case gaia::FileReaderOption::BinaryOctree: // Octree already constructed and stored as a binary file. - nReadStars = readBinaryOctreeFile(_filePath); + nReadStars = readBinaryOctreeFile(file); break; case gaia::FileReaderOption::StreamOctree: // Read Octree structure from file, without data. - nReadStars = readBinaryOctreeStructureFile(_filePath); + nReadStars = readBinaryOctreeStructureFile(file.string()); break; default: LERROR("Wrong FileReaderOption - no data file loaded!"); @@ -2218,13 +2217,13 @@ bool RenderableGaiaStars::readDataFile() { //_octreeManager->printStarsPerNode(); _nRenderedStars.setMaxValue(nReadStars); - LINFO("Dataset contains a total of " + std::to_string(nReadStars) + " stars."); + LINFO(fmt::format("Dataset contains a total of {} stars", nReadStars)); _totalDatasetSizeInBytes = nReadStars * (PositionSize + ColorSize + VelocitySize) * 4; return nReadStars > 0; } -int RenderableGaiaStars::readFitsFile(const std::string& filePath) { +int RenderableGaiaStars::readFitsFile(const std::filesystem::path& filePath) { int nReadValuesPerStar = 0; FitsFileReader fitsFileReader(false); @@ -2248,7 +2247,7 @@ int RenderableGaiaStars::readFitsFile(const std::string& filePath) { return static_cast(fullData.size() / nReadValuesPerStar); } -int RenderableGaiaStars::readSpeckFile(const std::string& filePath) { +int RenderableGaiaStars::readSpeckFile(const std::filesystem::path& filePath) { int nReadValuesPerStar = 0; FitsFileReader fileReader(false); @@ -2266,7 +2265,7 @@ int RenderableGaiaStars::readSpeckFile(const std::string& filePath) { return static_cast(fullData.size() / nReadValuesPerStar); } -int RenderableGaiaStars::readBinaryRawFile(const std::string& filePath) { +int RenderableGaiaStars::readBinaryRawFile(const std::filesystem::path& filePath) { std::vector fullData; int nReadStars = 0; @@ -2299,14 +2298,14 @@ int RenderableGaiaStars::readBinaryRawFile(const std::string& filePath) { } else { LERROR(fmt::format( - "Error opening file '{}' for loading raw binary file!", filePath + "Error opening file '{}' for loading raw binary file", filePath )); return nReadStars; } return nReadStars; } -int RenderableGaiaStars::readBinaryOctreeFile(const std::string& filePath) { +int RenderableGaiaStars::readBinaryOctreeFile(const std::filesystem::path& filePath) { int nReadStars = 0; std::ifstream fileStream(filePath, std::ifstream::binary); @@ -2317,26 +2316,28 @@ int RenderableGaiaStars::readBinaryOctreeFile(const std::string& filePath) { } else { LERROR(fmt::format( - "Error opening file '{}' for loading binary Octree file!", filePath + "Error opening file '{}' for loading binary Octree file", filePath )); return nReadStars; } return nReadStars; } -int RenderableGaiaStars::readBinaryOctreeStructureFile(const std::string& folderPath) { +int RenderableGaiaStars::readBinaryOctreeStructureFile( + const std::filesystem::path& folderPath) +{ int nReadStars = 0; - std::string indexFile = folderPath + "index.bin"; + std::string indexFile = folderPath.string() + "index.bin"; std::ifstream fileStream(indexFile, std::ifstream::binary); if (fileStream.good()) { - nReadStars = _octreeManager.readFromFile(fileStream, false, folderPath); + nReadStars = _octreeManager.readFromFile(fileStream, false, folderPath.string()); fileStream.close(); } else { LERROR(fmt::format( - "Error opening file '{}' for loading binary Octree file!", indexFile + "Error opening file '{}' for loading binary Octree file", indexFile )); return nReadStars; } diff --git a/modules/gaia/rendering/renderablegaiastars.h b/modules/gaia/rendering/renderablegaiastars.h index 09508f0e94..cda54a9772 100644 --- a/modules/gaia/rendering/renderablegaiastars.h +++ b/modules/gaia/rendering/renderablegaiastars.h @@ -78,28 +78,28 @@ private: * * \return the number of stars read. */ - int readFitsFile(const std::string& filePath); + int readFitsFile(const std::filesystem::path& filePath); /** * Read a SPECK file by using FitsFileReader.readSpeckFile() and constructs an octree. * * \return the number of stars read. */ - int readSpeckFile(const std::string& filePath); + int readSpeckFile(const std::filesystem::path& filePath); /** * Reads a preprocessed binary file and constructs an octree. * * \return the number of stars read. */ - int readBinaryRawFile(const std::string& filePath); + int readBinaryRawFile(const std::filesystem::path& filePath); /** * Reads a pre-constructed octree, with all data, from a binary file. * * \return the number of stars read. */ - int readBinaryOctreeFile(const std::string& filePath); + int readBinaryOctreeFile(const std::filesystem::path& filePath); /** * Reads the structure of a pre-constructed octree from a binary file, without any @@ -107,7 +107,7 @@ private: * * \return the number of stars read. */ - int readBinaryOctreeStructureFile(const std::string& folderPath); + int readBinaryOctreeStructureFile(const std::filesystem::path& folderPath); /** * Checks for any OpenGL errors and reports these to the log if _reportGlErrors is diff --git a/modules/gaia/tasks/readfilejob.cpp b/modules/gaia/tasks/readfilejob.cpp index 12e0ea1b08..b2cb6030fa 100644 --- a/modules/gaia/tasks/readfilejob.cpp +++ b/modules/gaia/tasks/readfilejob.cpp @@ -68,8 +68,10 @@ void ReadFileJob::execute() { int nNullArr = 0; size_t nColumnsRead = _allColumns.size(); if (nColumnsRead != _nDefaultCols) { - LINFO("Additional columns will be read! Consider add column in code for " - "significant speedup!"); + LINFO( + "Additional columns will be read! Consider add column in code for " + "significant speedup" + ); } // Copy columns to local variables. diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 6cb9da54ee..062cab243d 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -182,14 +182,15 @@ namespace { #include "renderablegalaxy_codegen.cpp" - void saveCachedFile(const std::string& file, const std::vector& positions, + void saveCachedFile(const std::filesystem::path& file, + const std::vector& positions, const std::vector& colors, int64_t nPoints, float pointsRatio) { std::ofstream fileStream(file, std::ofstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for save cache file", file)); + LERROR(fmt::format("Error opening file {} for save cache file", file)); return; } @@ -321,13 +322,13 @@ void RenderableGalaxy::initialize() { ); _volume = reader.read(); - std::string cachedPointsFile = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cachedPointsFile = FileSys.cacheManager()->cachedFilename( _pointsFilename ); const bool hasCachedFile = std::filesystem::is_regular_file(cachedPointsFile); if (hasCachedFile) { - LINFO(fmt::format("Cached file '{}' used for galaxy point file '{}'", - cachedPointsFile, _pointsFilename + LINFO(fmt::format("Cached file {} used for galaxy point file {}", + cachedPointsFile, std::filesystem::path(_pointsFilename) )); Result res = loadCachedFile(cachedPointsFile); @@ -730,17 +731,19 @@ RenderableGalaxy::Result RenderableGalaxy::loadPointFile() { return res; } -RenderableGalaxy::Result RenderableGalaxy::loadCachedFile(const std::string& file) { +RenderableGalaxy::Result RenderableGalaxy::loadCachedFile( + const std::filesystem::path& file) +{ std::ifstream fileStream(file, std::ifstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for loading cache file", file)); + LERROR(fmt::format("Error opening file {} for loading cache file", file)); return { false, {}, {} }; } int8_t cacheVersion; fileStream.read(reinterpret_cast(&cacheVersion), sizeof(int8_t)); if (cacheVersion != CurrentCacheVersion) { - LINFO(fmt::format("Removing cache file '{}' as the version changed")); + LINFO(fmt::format("Removing cache file {} as the version changed", file)); return { false, {}, {} }; } diff --git a/modules/galaxy/rendering/renderablegalaxy.h b/modules/galaxy/rendering/renderablegalaxy.h index 45dbcd1df7..55c3b4cbba 100644 --- a/modules/galaxy/rendering/renderablegalaxy.h +++ b/modules/galaxy/rendering/renderablegalaxy.h @@ -64,7 +64,7 @@ private: std::vector color; }; Result loadPointFile(); - Result loadCachedFile(const std::string& file); + Result loadCachedFile(const std::filesystem::path& file); glm::vec3 _volumeSize = glm::vec3(0.f); glm::vec3 _pointScaling = glm::vec3(0.f); diff --git a/modules/globebrowsing/src/globelabelscomponent.cpp b/modules/globebrowsing/src/globelabelscomponent.cpp index 5a8da230fd..ed3548ba9d 100644 --- a/modules/globebrowsing/src/globelabelscomponent.cpp +++ b/modules/globebrowsing/src/globelabelscomponent.cpp @@ -306,15 +306,15 @@ void GlobeLabelsComponent::initializeFonts() { ); } -bool GlobeLabelsComponent::loadLabelsData(const std::string& file) { - std::string cachedFile = FileSys.cacheManager()->cachedFilename( +bool GlobeLabelsComponent::loadLabelsData(const std::filesystem::path& file) { + std::filesystem::path cachedFile = FileSys.cacheManager()->cachedFilename( file, "GlobeLabelsComponent|" + identifier() ); bool hasCachedFile = std::filesystem::is_regular_file(cachedFile); if (hasCachedFile) { - LINFO(fmt::format("Cached file '{}' used for labels file: {}", cachedFile, file)); + LINFO(fmt::format("Cached file {} used for labels file {}", cachedFile, file)); const bool hasCache = loadCachedFile(cachedFile); if (hasCache) { @@ -327,9 +327,9 @@ bool GlobeLabelsComponent::loadLabelsData(const std::string& file) { } } else { - LINFO(fmt::format("Cache for labels file '{}' not found", file)); + LINFO(fmt::format("Cache for labels file {} not found", file)); } - LINFO(fmt::format("Loading labels file '{}'", file)); + LINFO(fmt::format("Loading labels file {}", file)); bool success = readLabelsFile(file); if (success) { @@ -338,11 +338,11 @@ bool GlobeLabelsComponent::loadLabelsData(const std::string& file) { return success; } -bool GlobeLabelsComponent::readLabelsFile(const std::string& file) { +bool GlobeLabelsComponent::readLabelsFile(const std::filesystem::path& file) { try { std::fstream csvLabelFile(file); if (!csvLabelFile.good()) { - LERROR(fmt::format("Failed to open labels file '{}'", file)); + LERROR(fmt::format("Failed to open labels file {}", file)); return false; } if (!csvLabelFile.is_open()) { @@ -427,16 +427,16 @@ bool GlobeLabelsComponent::readLabelsFile(const std::string& file) { return true; } catch (const std::fstream::failure& e) { - LERROR(fmt::format("Failed reading labels file '{}'", file)); + LERROR(fmt::format("Failed reading labels file {}", file)); LERROR(e.what()); return false; } } -bool GlobeLabelsComponent::loadCachedFile(const std::string& file) { +bool GlobeLabelsComponent::loadCachedFile(const std::filesystem::path& file) { std::ifstream fileStream(file, std::ifstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for loading cache file", file)); + LERROR(fmt::format("Error opening file {} for loading cache file", file)); return false; } @@ -463,10 +463,10 @@ bool GlobeLabelsComponent::loadCachedFile(const std::string& file) { return fileStream.good(); } -bool GlobeLabelsComponent::saveCachedFile(const std::string& file) const { +bool GlobeLabelsComponent::saveCachedFile(const std::filesystem::path& file) const { std::ofstream fileStream(file, std::ofstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for save cache file", file)); + LERROR(fmt::format("Error opening file {} for save cache file", file)); return false; } fileStream.write(reinterpret_cast(&CurrentCacheVersion), sizeof(int8_t)); diff --git a/modules/globebrowsing/src/globelabelscomponent.h b/modules/globebrowsing/src/globelabelscomponent.h index a14ede7078..0cfa277558 100644 --- a/modules/globebrowsing/src/globelabelscomponent.h +++ b/modules/globebrowsing/src/globelabelscomponent.h @@ -62,10 +62,10 @@ public: void draw(const RenderData& data); private: - bool loadLabelsData(const std::string& file); - bool readLabelsFile(const std::string& file); - bool loadCachedFile(const std::string& file); - bool saveCachedFile(const std::string& file) const; + bool loadLabelsData(const std::filesystem::path& file); + bool readLabelsFile(const std::filesystem::path& file); + bool loadCachedFile(const std::filesystem::path& file); + bool saveCachedFile(const std::filesystem::path& file) const; void renderLabels(const RenderData& data, const glm::dmat4& modelViewProjectionMatrix, float distToCamera, float fadeInVariable); bool isLabelInFrustum(const glm::dmat4& MVMatrix, const glm::dvec3& position) const; diff --git a/modules/globebrowsing/src/ringscomponent.cpp b/modules/globebrowsing/src/ringscomponent.cpp index 129fd9bf76..b04cf026ca 100644 --- a/modules/globebrowsing/src/ringscomponent.cpp +++ b/modules/globebrowsing/src/ringscomponent.cpp @@ -620,7 +620,7 @@ void RingsComponent::loadTexture() { if (texture) { LDEBUGC( "RingsComponent", - fmt::format("Loaded texture from '{}'", absPath(_texturePath)) + fmt::format("Loaded texture from {}", absPath(_texturePath)) ); _texture = std::move(texture); @@ -643,7 +643,7 @@ void RingsComponent::loadTexture() { LDEBUGC( "RingsComponent", fmt::format( - "Loaded forwards scattering texture from '{}'", + "Loaded forwards scattering texture from {}", absPath(_textureFwrdPath) ) ); @@ -669,7 +669,7 @@ void RingsComponent::loadTexture() { LDEBUGC( "RingsComponent", fmt::format( - "Loaded backwards scattering texture from '{}'", + "Loaded backwards scattering texture from {}", absPath(_textureBckwrdPath) ) ); @@ -694,10 +694,7 @@ void RingsComponent::loadTexture() { if (textureUnlit) { LDEBUGC( "RingsComponent", - fmt::format( - "Loaded unlit texture from '{}'", - absPath(_textureUnlitPath) - ) + fmt::format("Loaded unlit texture from {}", absPath(_textureUnlitPath)) ); _textureUnlit = std::move(textureUnlit); @@ -719,10 +716,7 @@ void RingsComponent::loadTexture() { if (textureColor) { LDEBUGC( "RingsComponent", - fmt::format( - "Loaded color texture from '{}'", - absPath(_textureColorPath) - ) + fmt::format("Loaded color texture from {}", absPath(_textureColorPath)) ); _textureColor = std::move(textureColor); @@ -744,10 +738,7 @@ void RingsComponent::loadTexture() { if (textureTransparency) { LDEBUGC( "RingsComponent", - fmt::format( - "Loaded unlit texture from '{}'", - absPath(_textureUnlitPath) - ) + fmt::format("Loaded unlit texture from {}", absPath(_textureUnlitPath)) ); _textureTransparency = std::move(textureTransparency); diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index 1329d52063..ff6e488acc 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -204,17 +204,17 @@ void GUI::deinitialize() { } void GUI::initializeGL() { - std::string cachedFile = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cachedFile = FileSys.cacheManager()->cachedFilename( configurationFile, "" ); LDEBUG(fmt::format("Using {} as ImGUI cache location", cachedFile)); - iniFileBuffer = new char[cachedFile.size() + 1]; + iniFileBuffer = new char[cachedFile.string().size() + 1]; #ifdef WIN32 - strcpy_s(iniFileBuffer, cachedFile.size() + 1, cachedFile.c_str()); + strcpy_s(iniFileBuffer, cachedFile.string().size() + 1, cachedFile.string().c_str()); #else strcpy(iniFileBuffer, cachedFile.c_str()); #endif diff --git a/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp b/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp index 2e8ad45922..dde78c643c 100644 --- a/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp +++ b/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp @@ -332,7 +332,7 @@ void RenderableKameleonVolume::load() { loadFromPath(_sourcePath); return; } - std::string cachePath = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cachePath = FileSys.cacheManager()->cachedFilename( std::filesystem::path(_sourcePath.value()).stem(), cacheSuffix() ); @@ -360,7 +360,7 @@ void RenderableKameleonVolume::loadFromPath(const std::string& path) { } } -void RenderableKameleonVolume::loadRaw(const std::string& path) { +void RenderableKameleonVolume::loadRaw(const std::filesystem::path& path) { volume::RawVolumeReader reader(path, _dimensions); _rawVolume = reader.read(); updateTextureFromVolume(); @@ -433,7 +433,7 @@ void RenderableKameleonVolume::updateTextureFromVolume() { _volumeTexture->setPixelData(data, ghoul::opengl::Texture::TakeOwnership::No); } -void RenderableKameleonVolume::storeRaw(const std::string& path) { +void RenderableKameleonVolume::storeRaw(const std::filesystem::path& path) { volume::RawVolumeWriter writer(path); writer.write(*_rawVolume); } diff --git a/modules/kameleonvolume/rendering/renderablekameleonvolume.h b/modules/kameleonvolume/rendering/renderablekameleonvolume.h index e4eacd4647..700559c688 100644 --- a/modules/kameleonvolume/rendering/renderablekameleonvolume.h +++ b/modules/kameleonvolume/rendering/renderablekameleonvolume.h @@ -62,9 +62,9 @@ public: private: void load(); void loadFromPath(const std::string& path); - void loadRaw(const std::string& path); + void loadRaw(const std::filesystem::path& path); void loadCdf(const std::string& path); - void storeRaw(const std::string& path); + void storeRaw(const std::filesystem::path& path); std::string cacheSuffix() const; void updateTextureFromVolume(); diff --git a/modules/multiresvolume/rendering/errorhistogrammanager.cpp b/modules/multiresvolume/rendering/errorhistogrammanager.cpp index 3f4824ba65..d7517e797c 100644 --- a/modules/multiresvolume/rendering/errorhistogrammanager.cpp +++ b/modules/multiresvolume/rendering/errorhistogrammanager.cpp @@ -179,7 +179,7 @@ bool ErrorHistogramManager::buildFromLeaf(unsigned int bstOffset, return true; } -bool ErrorHistogramManager::loadFromFile(const std::string& filename) { +bool ErrorHistogramManager::loadFromFile(const std::filesystem::path& filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.is_open()) { return false; @@ -210,7 +210,7 @@ bool ErrorHistogramManager::loadFromFile(const std::string& filename) { } -bool ErrorHistogramManager::saveToFile(const std::string& filename) { +bool ErrorHistogramManager::saveToFile(const std::filesystem::path& filename) { std::ofstream file(filename, std::ios::out | std::ios::binary); if (!file.is_open()) { return false; diff --git a/modules/multiresvolume/rendering/errorhistogrammanager.h b/modules/multiresvolume/rendering/errorhistogrammanager.h index 31dc829bf5..00ec8af043 100644 --- a/modules/multiresvolume/rendering/errorhistogrammanager.h +++ b/modules/multiresvolume/rendering/errorhistogrammanager.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -42,8 +43,8 @@ public: bool buildHistograms(int numBins); const Histogram* histogram(unsigned int brickIndex) const; - bool loadFromFile(const std::string& filename); - bool saveToFile(const std::string& filename); + bool loadFromFile(const std::filesystem::path& filename); + bool saveToFile(const std::filesystem::path& filename); private: TSP* _tsp; diff --git a/modules/multiresvolume/rendering/histogrammanager.cpp b/modules/multiresvolume/rendering/histogrammanager.cpp index cc3293e253..e32383669e 100644 --- a/modules/multiresvolume/rendering/histogrammanager.cpp +++ b/modules/multiresvolume/rendering/histogrammanager.cpp @@ -121,7 +121,7 @@ std::vector HistogramManager::readValues(TSP* tsp, unsigned int brickInde return voxelValues; } -bool HistogramManager::loadFromFile(const std::string& filename) { +bool HistogramManager::loadFromFile(const std::filesystem::path& filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.is_open()) { return false; @@ -151,7 +151,7 @@ bool HistogramManager::loadFromFile(const std::string& filename) { return true; } -bool HistogramManager::saveToFile(const std::string& filename) { +bool HistogramManager::saveToFile(const std::filesystem::path& filename) { std::ofstream file(filename, std::ios::out | std::ios::binary); if (!file.is_open()) { return false; diff --git a/modules/multiresvolume/rendering/histogrammanager.h b/modules/multiresvolume/rendering/histogrammanager.h index 2cda97e5e7..ab7aefbee7 100644 --- a/modules/multiresvolume/rendering/histogrammanager.h +++ b/modules/multiresvolume/rendering/histogrammanager.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_MULTIRESVOLUME___HISTOGRAMMANAGER___H__ #include +#include #include namespace openspace { @@ -36,8 +37,8 @@ class HistogramManager { public: bool buildHistograms(TSP* tsp, int numBins); Histogram* histogram(unsigned int brickIndex); - bool loadFromFile(const std::string& filename); - bool saveToFile(const std::string& filename); + bool loadFromFile(const std::filesystem::path& filename); + bool saveToFile(const std::filesystem::path& filename); private: bool buildHistogram(TSP* tsp, unsigned int brickIndex); diff --git a/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp b/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp index c13500c7fd..461fd4f983 100644 --- a/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp +++ b/modules/multiresvolume/rendering/localerrorhistogrammanager.cpp @@ -305,7 +305,7 @@ bool LocalErrorHistogramManager::buildFromBstChild(unsigned int bstOffset, return true; } -bool LocalErrorHistogramManager::loadFromFile(const std::string& filename) { +bool LocalErrorHistogramManager::loadFromFile(const std::filesystem::path& filename) { std::ifstream file(filename, std::ios::in | std::ios::binary); if (!file.is_open()) { return false; @@ -344,7 +344,7 @@ bool LocalErrorHistogramManager::loadFromFile(const std::string& filename) { } -bool LocalErrorHistogramManager::saveToFile(const std::string& filename) { +bool LocalErrorHistogramManager::saveToFile(const std::filesystem::path& filename) { std::ofstream file(filename, std::ios::out | std::ios::binary); if (!file.is_open()) { return false; diff --git a/modules/multiresvolume/rendering/localerrorhistogrammanager.h b/modules/multiresvolume/rendering/localerrorhistogrammanager.h index b6f54177c4..da4dd0833b 100644 --- a/modules/multiresvolume/rendering/localerrorhistogrammanager.h +++ b/modules/multiresvolume/rendering/localerrorhistogrammanager.h @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -42,8 +43,8 @@ public: const Histogram* spatialHistogram(unsigned int brickIndex) const; const Histogram* temporalHistogram(unsigned int brickIndex) const; - bool loadFromFile(const std::string& filename); - bool saveToFile(const std::string& filename); + bool loadFromFile(const std::filesystem::path& filename); + bool saveToFile(const std::filesystem::path& filename); private: TSP* _tsp = nullptr; diff --git a/modules/multiresvolume/rendering/renderablemultiresvolume.cpp b/modules/multiresvolume/rendering/renderablemultiresvolume.cpp index 97d542348a..6ddb02345f 100644 --- a/modules/multiresvolume/rendering/renderablemultiresvolume.cpp +++ b/modules/multiresvolume/rendering/renderablemultiresvolume.cpp @@ -455,21 +455,21 @@ bool RenderableMultiresVolume::initializeSelector() { switch (_selector) { case Selector::TF: if (_errorHistogramManager) { - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename( fmt::format( "{}_{}_errorHistograms", std::filesystem::path(_filename).stem().string(), nHistograms ), "" ); - std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary); + std::ifstream cacheFile(cached, std::ios::in | std::ios::binary); if (cacheFile.is_open()) { // Read histograms from cache. cacheFile.close(); LINFO( - fmt::format("Loading histograms from cache: {}", cacheFilename) + fmt::format("Loading histograms from cache: {}", cached) ); - success &= _errorHistogramManager->loadFromFile(cacheFilename); + success &= _errorHistogramManager->loadFromFile(cached); } else if (!_errorHistogramsPath.empty()) { // Read histograms from scene data. @@ -482,11 +482,11 @@ bool RenderableMultiresVolume::initializeSelector() { } else { // Build histograms from tsp file. - LWARNING(fmt::format("Failed to open {}", cacheFilename)); + LWARNING(fmt::format("Failed to open {}", cached)); success &= _errorHistogramManager->buildHistograms(nHistograms); if (success) { - LINFO(fmt::format("Writing cache to {}", cacheFilename)); - _errorHistogramManager->saveToFile(cacheFilename); + LINFO(fmt::format("Writing cache to {}", cached)); + _errorHistogramManager->saveToFile(cached); } } success &= _tfBrickSelector && _tfBrickSelector->initialize(); @@ -495,29 +495,29 @@ bool RenderableMultiresVolume::initializeSelector() { case Selector::SIMPLE: if (_histogramManager) { - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename( fmt::format("{}_{}_histogram", std::filesystem::path(_filename).stem().string(), nHistograms ), "" ); - std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary); + std::ifstream cacheFile(cached, std::ios::in | std::ios::binary); if (cacheFile.is_open()) { // Read histograms from cache. cacheFile.close(); - LINFO(fmt::format("Loading histograms from {}", cacheFilename)); - success &= _histogramManager->loadFromFile(cacheFilename); + LINFO(fmt::format("Loading histograms from {}", cached)); + success &= _histogramManager->loadFromFile(cached); } else { // Build histograms from tsp file. - LWARNING(fmt::format("Failed to open '{}'", cacheFilename)); + LWARNING(fmt::format("Failed to open {}", cached)); success &= _histogramManager->buildHistograms( _tsp.get(), nHistograms ); if (success) { - LINFO(fmt::format("Writing cache to {}", cacheFilename)); - _histogramManager->saveToFile(cacheFilename); + LINFO(fmt::format("Writing cache to {}", cached)); + _histogramManager->saveToFile(cached); } } success &= _simpleTfBrickSelector && _simpleTfBrickSelector->initialize(); @@ -526,27 +526,27 @@ bool RenderableMultiresVolume::initializeSelector() { case Selector::LOCAL: if (_localErrorHistogramManager) { - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename( fmt::format( "{}_{}_localErrorHistograms", std::filesystem::path(_filename).stem().string(), nHistograms ), "" ); - std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary); + std::ifstream cacheFile(cached, std::ios::in | std::ios::binary); if (cacheFile.is_open()) { // Read histograms from cache. cacheFile.close(); - LINFO(fmt::format("Loading histograms from {}", cacheFilename)); - success &= _localErrorHistogramManager->loadFromFile(cacheFilename); + LINFO(fmt::format("Loading histograms from {}", cached)); + success &= _localErrorHistogramManager->loadFromFile(cached); } else { // Build histograms from tsp file. - LWARNING(fmt::format("Failed to open {}", cacheFilename)); + LWARNING(fmt::format("Failed to open {}", cached)); success &= _localErrorHistogramManager->buildHistograms(nHistograms); if (success) { - LINFO(fmt::format("Writing cache to {}", cacheFilename)); - _localErrorHistogramManager->saveToFile(cacheFilename); + LINFO(fmt::format("Writing cache to {}", cached)); + _localErrorHistogramManager->saveToFile(cached); } } success &= _localTfBrickSelector && _localTfBrickSelector->initialize(); diff --git a/modules/multiresvolume/rendering/tsp.cpp b/modules/multiresvolume/rendering/tsp.cpp index 124d1cea24..8ad76a06d3 100644 --- a/modules/multiresvolume/rendering/tsp.cpp +++ b/modules/multiresvolume/rendering/tsp.cpp @@ -507,7 +507,7 @@ bool TSP::readCache() { if (!FileSys.cacheManager()) return false; - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cacheFilename = FileSys.cacheManager()->cachedFilename( std::filesystem::path(_filename).stem(), "" ); @@ -545,7 +545,7 @@ bool TSP::writeCache() { return false; } - std::string cacheFilename = FileSys.cacheManager()->cachedFilename( + std::filesystem::path cacheFilename = FileSys.cacheManager()->cachedFilename( std::filesystem::path(_filename).stem(), "" ); diff --git a/modules/space/rendering/renderablestars.cpp b/modules/space/rendering/renderablestars.cpp index 89b4fdf9a5..3b42e10193 100644 --- a/modules/space/rendering/renderablestars.cpp +++ b/modules/space/rendering/renderablestars.cpp @@ -865,7 +865,7 @@ void RenderableStars::loadPSFTexture() { if (_pointSpreadFunctionTexture) { LDEBUG(fmt::format( - "Loaded texture from '{}'", absPath(_pointSpreadFunctionTexturePath) + "Loaded texture from {}", absPath(_pointSpreadFunctionTexturePath) )); _pointSpreadFunctionTexture->uploadTexture(); } @@ -1267,10 +1267,7 @@ void RenderableStars::update(const UpdateData&) { absPath(_colorTexturePath).string() ); if (_colorTexture) { - LDEBUG(fmt::format( - "Loaded texture from '{}'", - absPath(_colorTexturePath) - )); + LDEBUG(fmt::format("Loaded texture from {}", absPath(_colorTexturePath))); _colorTexture->uploadTexture(); } @@ -1293,7 +1290,7 @@ void RenderableStars::update(const UpdateData&) { ); if (_otherDataColorMapTexture) { LDEBUG(fmt::format( - "Loaded texture from '{}'", + "Loaded texture from {}", absPath(_otherDataColorMapPath) )); _otherDataColorMapTexture->uploadTexture(); diff --git a/modules/space/speckloader.cpp b/modules/space/speckloader.cpp index 996ba3ab73..649e3f9aff 100644 --- a/modules/space/speckloader.cpp +++ b/modules/space/speckloader.cpp @@ -99,23 +99,21 @@ namespace { std::is_same_v ); - std::string cachePath = FileSys.cacheManager()->cachedFilename(speckPath); + std::filesystem::path cached = FileSys.cacheManager()->cachedFilename(speckPath); - if (std::filesystem::exists(cachePath)) { + if (std::filesystem::exists(cached)) { LINFOC( "SpeckLoader", - fmt::format( - "Cached file '{}' used for file {}", cachePath, speckPath - ) + fmt::format("Cached file {} used for file {}", cached, speckPath) ); - std::optional dataset = loadCacheFunction(cachePath); + std::optional dataset = loadCacheFunction(cached); if (dataset.has_value()) { // We could load the cache file and we are now done with this return *dataset; } else { - FileSys.cacheManager()->removeCacheFile(cachePath); + FileSys.cacheManager()->removeCacheFile(cached); } } LINFOC("SpeckLoader", fmt::format("Loading file {}", speckPath)); @@ -123,7 +121,7 @@ namespace { if (!dataset.entries.empty()) { LINFOC("SpeckLoader", "Saving cache"); - saveCacheFunction(dataset, cachePath); + saveCacheFunction(dataset, cached); } return dataset; } @@ -547,7 +545,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { std::ifstream file(path); if (!file.good()) { - throw ghoul::RuntimeError(fmt::format("Failed to open speck file '{}'", path)); + throw ghoul::RuntimeError(fmt::format("Failed to open speck file {}", path)); } Labelset res; @@ -582,7 +580,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { // included in the speck file) if (res.textColorIndex != -1) { throw ghoul::RuntimeError(fmt::format( - "Error loading label file '{}': Textcolor defined twice", path + "Error loading label file {}: Textcolor defined twice", path )); } @@ -621,7 +619,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { // data section of the file if (!std::isdigit(line[0]) && line[0] != '-') { throw ghoul::RuntimeError(fmt::format( - "Error loading label file '{}': Header information and datasegment " + "Error loading label file {}: Header information and datasegment " "intermixed", path )); } @@ -640,7 +638,7 @@ Labelset loadFile(std::filesystem::path path, SkipAllZeroLines) { if (!startsWith(rest, "text")) { throw ghoul::RuntimeError(fmt::format( - "Error loading label file '{}': File contains some value between " + "Error loading label file {}: File contains some value between " "positions and text label, which is unsupported", path )); } @@ -755,7 +753,7 @@ ColorMap loadFile(std::filesystem::path path, SkipAllZeroLines) { std::ifstream file(path); if (!file.good()) { - throw ghoul::RuntimeError(fmt::format("Failed to open speck file '{}'", path)); + throw ghoul::RuntimeError(fmt::format("Failed to open speck file {}", path)); } ColorMap res; diff --git a/modules/space/translation/horizonstranslation.cpp b/modules/space/translation/horizonstranslation.cpp index 1f13bdf6cc..47fc033f1a 100644 --- a/modules/space/translation/horizonstranslation.cpp +++ b/modules/space/translation/horizonstranslation.cpp @@ -113,17 +113,15 @@ glm::dvec3 HorizonsTranslation::position(const UpdateData& data) const { } void HorizonsTranslation::loadData() { - std::string file = _horizonsTextFile; - if (!std::filesystem::is_regular_file(absPath(file))) { + std::filesystem::path file = absPath(_horizonsTextFile.value()); + if (!std::filesystem::is_regular_file(file)) { return; } - std::string cachedFile = FileSys.cacheManager()->cachedFilename(file); + std::filesystem::path cachedFile = FileSys.cacheManager()->cachedFilename(file); bool hasCachedFile = std::filesystem::is_regular_file(cachedFile); if (hasCachedFile) { - LINFO(fmt::format( - "Cached file '{}' used for Horizon file '{}'", cachedFile, file - )); + LINFO(fmt::format("Cached file {} used for Horizon file {}", cachedFile, file)); bool success = loadCachedFile(cachedFile); if (success) { @@ -136,9 +134,9 @@ void HorizonsTranslation::loadData() { } } else { - LINFO(fmt::format("Cache for Horizon file '{}' not found", file)); + LINFO(fmt::format("Cache for Horizon file {} not found", file)); } - LINFO(fmt::format("Loading Horizon file '{}'", file)); + LINFO(fmt::format("Loading Horizon file {}", file)); readHorizonsTextFile(); @@ -147,12 +145,11 @@ void HorizonsTranslation::loadData() { } void HorizonsTranslation::readHorizonsTextFile() { - std::ifstream fileStream(_horizonsTextFile); + std::filesystem::path f = absPath(_horizonsTextFile); + std::ifstream fileStream(f); if (!fileStream.good()) { - LERROR(fmt::format( - "Failed to open Horizons text file '{}'", _horizonsTextFile - )); + LERROR(fmt::format("Failed to open Horizons text file {}", f)); return; } @@ -202,11 +199,11 @@ void HorizonsTranslation::readHorizonsTextFile() { fileStream.close(); } -bool HorizonsTranslation::loadCachedFile(const std::string& file) { +bool HorizonsTranslation::loadCachedFile(const std::filesystem::path& file) { std::ifstream fileStream(file, std::ifstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for loading cache file", file)); + LERROR(fmt::format("Error opening file {} for loading cache file", file)); return false; } @@ -241,10 +238,10 @@ bool HorizonsTranslation::loadCachedFile(const std::string& file) { return fileStream.good(); } -void HorizonsTranslation::saveCachedFile(const std::string& file) const { +void HorizonsTranslation::saveCachedFile(const std::filesystem::path& file) const { std::ofstream fileStream(file, std::ofstream::binary); if (!fileStream.good()) { - LERROR(fmt::format("Error opening file '{}' for save cache file", file)); + LERROR(fmt::format("Error opening file {} for save cache file", file)); return; } diff --git a/modules/space/translation/horizonstranslation.h b/modules/space/translation/horizonstranslation.h index e002c3f8ed..625faa29d9 100644 --- a/modules/space/translation/horizonstranslation.h +++ b/modules/space/translation/horizonstranslation.h @@ -61,8 +61,8 @@ public: private: void loadData(); void readHorizonsTextFile(); - bool loadCachedFile(const std::string& file); - void saveCachedFile(const std::string& file) const; + bool loadCachedFile(const std::filesystem::path& file); + void saveCachedFile(const std::filesystem::path& file) const; properties::StringProperty _horizonsTextFile; std::unique_ptr _fileHandle; diff --git a/modules/spacecraftinstruments/util/labelparser.cpp b/modules/spacecraftinstruments/util/labelparser.cpp index e9469306c1..4baf2c41df 100644 --- a/modules/spacecraftinstruments/util/labelparser.cpp +++ b/modules/spacecraftinstruments/util/labelparser.cpp @@ -166,7 +166,9 @@ bool LabelParser::create() { std::ifstream file(path); if (!file.good()) { - LERROR(fmt::format("Failed to open label file '{}'", path)); + LERROR(fmt::format( + "Failed to open label file {}", std::filesystem::path(path) + )); return false; } diff --git a/modules/volume/rawvolumereader.h b/modules/volume/rawvolumereader.h index 1d2833cf32..519411a68f 100644 --- a/modules/volume/rawvolumereader.h +++ b/modules/volume/rawvolumereader.h @@ -26,6 +26,7 @@ #define __OPENSPACE_MODULE_VOLUME___RAWVOLUMEREADER___H__ #include +#include #include namespace openspace::volume { @@ -37,11 +38,11 @@ class RawVolumeReader { public: using VoxelType = Type; - RawVolumeReader(const std::string& path, const glm::uvec3& dimensions); + RawVolumeReader(const std::filesystem::path& path, const glm::uvec3& dimensions); glm::uvec3 dimensions() const; - std::string path() const; - void setPath(const std::string& path); + std::filesystem::path path() const; + void setPath(std::filesystem::path path); void setDimensions(const glm::uvec3& dimensions); //VoxelType get(const glm::ivec3& coordinates) const; // TODO: Implement this //VoxelType get(const size_t index) const; // TODO: Implement this @@ -51,7 +52,7 @@ private: size_t coordsToIndex(const glm::uvec3& cartesian) const; glm::uvec3 indexToCoords(size_t linear) const; glm::uvec3 _dimensions; - std::string _path; + std::filesystem::path _path; }; } // namespace openspace::volume diff --git a/modules/volume/rawvolumereader.inl b/modules/volume/rawvolumereader.inl index b54f643c0b..642ffbbe6e 100644 --- a/modules/volume/rawvolumereader.inl +++ b/modules/volume/rawvolumereader.inl @@ -28,10 +28,10 @@ namespace openspace::volume { template -RawVolumeReader::RawVolumeReader(const std::string& path, +RawVolumeReader::RawVolumeReader(const std::filesystem::path& path, const glm::uvec3& dimensions) : _dimensions(dimensions) - , _path(path) + , _path(std::move(path)) {} template @@ -45,16 +45,15 @@ void RawVolumeReader::setDimensions(const glm::uvec3& dimensions) { } template -std::string RawVolumeReader::path() const { +std::filesystem::path RawVolumeReader::path() const { return _path; } template -void RawVolumeReader::setPath(const std::string& path) { - _path = path; +void RawVolumeReader::setPath(std::filesystem::path path) { + _path = std::move(path); } - /* TODO: Implement these methods for random access in raw volume file template diff --git a/modules/volume/rawvolumewriter.h b/modules/volume/rawvolumewriter.h index bfae4a9bc4..38918b2e77 100644 --- a/modules/volume/rawvolumewriter.h +++ b/modules/volume/rawvolumewriter.h @@ -25,6 +25,7 @@ #ifndef __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__ #define __OPENSPACE_MODULE_VOLUME___RAWVOLUMEWRITER___H__ +#include #include #include @@ -35,9 +36,9 @@ template class RawVolume; template class RawVolumeWriter { public: - RawVolumeWriter(std::string path, size_t bufferSize = 1024); + RawVolumeWriter(std::filesystem::path path, size_t bufferSize = 1024); - void setPath(const std::string& path); + void setPath(std::filesystem::path path); glm::uvec3 dimensions() const; void setDimensions(glm::uvec3 dimensions); void write(const std::function& fn, @@ -49,7 +50,7 @@ public: private: glm::ivec3 _dimensions = glm::ivec3(0); - std::string _path; + std::filesystem::path _path; size_t _bufferSize = 0; }; diff --git a/modules/volume/rawvolumewriter.inl b/modules/volume/rawvolumewriter.inl index d9318f9b15..7a96b1ce1b 100644 --- a/modules/volume/rawvolumewriter.inl +++ b/modules/volume/rawvolumewriter.inl @@ -25,12 +25,13 @@ #include #include #include +#include #include namespace openspace::volume { template -RawVolumeWriter::RawVolumeWriter(std::string path, size_t bufferSize) +RawVolumeWriter::RawVolumeWriter(std::filesystem::path path, size_t bufferSize) : _path(std::move(path)) , _bufferSize(bufferSize) {} @@ -99,7 +100,7 @@ void RawVolumeWriter::write(const RawVolume& volume) { std::ofstream file(_path, std::ios::binary); if (!file.good()) { - throw ghoul::RuntimeError("Could not create file '" + _path + "'"); + throw ghoul::RuntimeError(fmt::format("Could not create file {}", _path)); } file.write(buffer, length); diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index d063cea529..be72b1076b 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1092,7 +1092,7 @@ void OpenSpaceEngine::preSynchronization() { global::memoryManager->TemporaryMemory.reset(); if (_hasScheduledAssetLoading) { - LINFO(fmt::format("Loading asset: {}", _scheduledAssetPathToLoad)); + LINFO(fmt::format("Loading asset: {}", absPath(_scheduledAssetPathToLoad))); global::profile->setIgnoreUpdates(true); loadSingleAsset(_scheduledAssetPathToLoad); global::profile->setIgnoreUpdates(false); diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index 7b86f41e8d..275300606a 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -332,7 +332,10 @@ int createSingleColorImage(lua_State* L) { const glm::dvec3 color = colorDict.value(key); - std::string fileName = FileSys.cacheManager()->cachedFilename(name + ".ppm", ""); + std::filesystem::path fileName = FileSys.cacheManager()->cachedFilename( + name + ".ppm", + "" + ); const bool hasCachedFile = std::filesystem::is_regular_file(fileName); if (hasCachedFile) { LDEBUGC("OpenSpaceEngine", fmt::format("Cached file '{}' used", fileName)); diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index 2d953ac33b..4cd4c49f48 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -170,7 +170,10 @@ LuaConsole::~LuaConsole() {} // NOLINT void LuaConsole::initialize() { ZoneScoped - const std::string filename = FileSys.cacheManager()->cachedFilename(HistoryFile, ""); + const std::filesystem::path filename = FileSys.cacheManager()->cachedFilename( + HistoryFile, + "" + ); if (std::filesystem::is_regular_file(filename)) { std::ifstream file(filename, std::ios::binary | std::ios::in); @@ -230,7 +233,10 @@ void LuaConsole::initialize() { void LuaConsole::deinitialize() { ZoneScoped - const std::string filename = FileSys.cacheManager()->cachedFilename(HistoryFile, ""); + const std::filesystem::path filename = FileSys.cacheManager()->cachedFilename( + HistoryFile, + "" + ); // We want to limit the command history to a realistic value, so that it doesn't // grow without bounds diff --git a/src/rendering/texturecomponent.cpp b/src/rendering/texturecomponent.cpp index a49200073a..1b06a99ea0 100644 --- a/src/rendering/texturecomponent.cpp +++ b/src/rendering/texturecomponent.cpp @@ -86,7 +86,7 @@ void TextureComponent::loadFromFile(const std::filesystem::path& path) { ); if (texture) { - LDEBUG(fmt::format("Loaded texture from '{}'", absPath(path.string()))); + LDEBUG(fmt::format("Loaded texture from {}", absPath(path.string()))); _texture = std::move(texture); _textureFile = std::make_unique(path); diff --git a/src/scene/asset.cpp b/src/scene/asset.cpp index dc03a46118..6e1737bd7e 100644 --- a/src/scene/asset.cpp +++ b/src/scene/asset.cpp @@ -502,7 +502,7 @@ bool Asset::initialize() { LERROR(fmt::format("Cannot initialize unsynchronized asset {}", id())); return false; } - LDEBUG(fmt::format("Initializing asset {}", id())); + LDEBUG(fmt::format("Initializing asset '{}'", id())); // 1. Initialize requirements for (const std::shared_ptr& child : _requiredAssets) { @@ -593,7 +593,7 @@ void Asset::deinitialize() { if (!isInitialized()) { return; } - LDEBUG(fmt::format("Deintializing asset {}", id())); + LDEBUG(fmt::format("Deintializing asset '{}'", id())); // Perform inverse actions as in initialize, in reverse order (7 - 1) diff --git a/src/scene/scenegraphnode.cpp b/src/scene/scenegraphnode.cpp index 0611b4cdd1..6ce162c4fa 100644 --- a/src/scene/scenegraphnode.cpp +++ b/src/scene/scenegraphnode.cpp @@ -229,7 +229,7 @@ namespace { // A user-facing description about this scene graph node std::optional description; - // If this value is specified, GUI applications are incouraged to ignore this + // If this value is specified, GUI applications are incouraged to ignore this // scenegraph node. This is most useful to trim collective lists of nodes and // not display, for example, barycenters std::optional hidden; @@ -447,7 +447,9 @@ SceneGraphNode::SceneGraphNode() _overrideBoundingSphere = std::nullopt; } }); - _boundingSphere.setExponent(10.f); + // @TODO (2021-06-30, emmbr) Uncomment this when exponential sliders support + // negative values + //_boundingSphere.setExponent(10.f); addProperty(_boundingSphere); _interactionSphere.onChange([this]() { if (_interactionSphere >= 0.0) { @@ -456,8 +458,10 @@ SceneGraphNode::SceneGraphNode() else { _overrideInteractionSphere = std::nullopt; } - }); - _interactionSphere.setExponent(10.f); + }); + // @TODO (2021-06-30, emmbr) Uncomment this when exponential sliders support + // negative values + //_interactionSphere.setExponent(10.f); addProperty(_interactionSphere); addProperty(_showDebugSphere); } diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 0c7a16a7ae..3e6941c354 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -214,15 +214,11 @@ bool ScriptEngine::runScript(const std::string& script, ScriptCallback callback) return true; } -bool ScriptEngine::runScriptFile(const std::string& filename) { +bool ScriptEngine::runScriptFile(const std::filesystem::path& filename) { ZoneScoped - if (filename.empty()) { - LWARNING("Filename was empty"); - return false; - } if (!std::filesystem::is_regular_file(filename)) { - LERROR(fmt::format("Script with name '{}' did not exist", filename)); + LERROR(fmt::format("Script with name {} did not exist", filename)); return false; } @@ -649,14 +645,17 @@ bool ScriptEngine::writeLog(const std::string& script) { _logFilename = absPath(global::configuration->scriptLog).string(); _logFileExists = true; - LDEBUG(fmt::format("Using script log file '{}'", _logFilename)); + LDEBUG(fmt::format( + "Using script log file {}", std::filesystem::path(_logFilename) + )); // Test file and clear previous input std::ofstream file(_logFilename, std::ofstream::out | std::ofstream::trunc); if (!file.good()) { LERROR(fmt::format( - "Could not open file '{}' for logging scripts", _logFilename + "Could not open file {} for logging scripts", + std::filesystem::path(_logFilename) )); return false; diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index a2a69b9eb1..0f4897ac31 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -204,13 +204,13 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { ghoul_assert(!filePath.empty(), "Empty file path"); ghoul_assert( std::filesystem::is_regular_file(filePath), - fmt::format("File '{}' ('{}') does not exist", filePath, absPath(filePath)) + fmt::format("File '{}' ({}) does not exist", filePath, absPath(filePath)) ); ghoul_assert( std::filesystem::is_directory(std::filesystem::path(filePath).parent_path()), fmt::format( - "File '{}' exists, but directory '{}' doesn't", - absPath(filePath), std::filesystem::path(filePath).parent_path().string() + "File {} exists, but directory {} does not", + absPath(filePath), std::filesystem::path(filePath).parent_path() ) ); @@ -234,7 +234,7 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { std::filesystem::path p = std::filesystem::path(path).parent_path(); std::filesystem::current_path(p); - LINFO(fmt::format("Loading SPICE kernel '{}'", path)); + LINFO(fmt::format("Loading SPICE kernel {}", path)); // Load the kernel furnsh_c(path.string().c_str()); @@ -273,7 +273,7 @@ void SpiceManager::unloadKernel(KernelHandle kernelId) { // If there was only one part interested in the kernel, we can unload it if (it->refCount == 1) { // No need to check for errors as we do not allow empty path names - LINFO(fmt::format("Unloading SPICE kernel '{}'", it->path)); + LINFO(fmt::format("Unloading SPICE kernel {}", it->path)); unload_c(it->path.c_str()); _loadedKernels.erase(it); } @@ -299,7 +299,7 @@ void SpiceManager::unloadKernel(std::string filePath) { if (it == _loadedKernels.end()) { if (_useExceptions) { throw SpiceException( - fmt::format("'{}' did not correspond to a loaded kernel", path) + fmt::format("{} did not correspond to a loaded kernel", path) ); } else { @@ -309,7 +309,7 @@ void SpiceManager::unloadKernel(std::string filePath) { else { // If there was only one part interested in the kernel, we can unload it if (it->refCount == 1) { - LINFO(fmt::format("Unloading SPICE kernel '{}'", path)); + LINFO(fmt::format("Unloading SPICE kernel {}", path)); unload_c(path.string().c_str()); _loadedKernels.erase(it); } @@ -1011,8 +1011,8 @@ void SpiceManager::findCkCoverage(const std::string& path) { fmt::format("File '{}' does not exist", path) ); - constexpr unsigned int MaxObj = 256; - constexpr unsigned int WinSiz = 10000; + constexpr unsigned int MaxObj = 1024; + constexpr unsigned int WinSiz = 16384; #if defined __clang__ #pragma clang diagnostic push @@ -1070,8 +1070,8 @@ void SpiceManager::findSpkCoverage(const std::string& path) { fmt::format("File '{}' does not exist", path) ); - constexpr unsigned int MaxObj = 256; - constexpr unsigned int WinSiz = 10000; + constexpr unsigned int MaxObj = 1024; + constexpr unsigned int WinSiz = 16384; #if defined __clang__ #pragma clang diagnostic push From 9d7d8686eaeab7ffd0ba43fd9ef6d65c03e3b98f Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Fri, 2 Jul 2021 10:00:42 +0200 Subject: [PATCH 26/44] Merge master --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index c5add410f3..3bc645938a 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit c5add410f3367890e2a2f91f6087001baf8f2152 +Subproject commit 3bc645938a9c8a7a804ebf53e65cd374cc5bef25 From 36393c10784a9d8fde362f611a4b4464e78844f0 Mon Sep 17 00:00:00 2001 From: Malin Ejdbo Date: Fri, 2 Jul 2021 10:01:57 +0200 Subject: [PATCH 27/44] Update Ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index 3bc645938a..c5add410f3 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 3bc645938a9c8a7a804ebf53e65cd374cc5bef25 +Subproject commit c5add410f3367890e2a2f91f6087001baf8f2152 From 724ad5b55346bb2d16d0a1a051b028bd216689aa Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 3 Jul 2021 19:00:12 +0200 Subject: [PATCH 28/44] Reduce fontsize of shutdown warning and center it instead with a dimming of the rendering (#1675) * Reduce fontsize of shutdown warning and center it instead with a dimming of the rendering --- openspace.cfg | 2 +- src/engine/openspaceengine.cpp | 1 - src/rendering/renderengine.cpp | 59 ++++++++++++++++++++-------------- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/openspace.cfg b/openspace.cfg index 3e4332c32a..3a5e56d9e0 100644 --- a/openspace.cfg +++ b/openspace.cfg @@ -190,7 +190,7 @@ Fonts = { } FontSize = { FrameInfo = 32.0, - Shutdown = 30.0, + Shutdown = 14.0, Log = 8.0, CameraInfo = 12.0, VersionInfo = 12.0 diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index be72b1076b..b75e828183 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -1270,7 +1270,6 @@ void OpenSpaceEngine::drawOverlays() { for (const std::function& func : *global::callback::draw2D) { ZoneScopedN("[Module] draw2D") - func(); } diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index 212321d0d9..21d63a2c28 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ #ifdef GHOUL_USE_DEVIL #include -#endif //GHOUL_USE_DEVIL +#endif // GHOUL_USE_DEVIL #ifdef GHOUL_USE_FREEIMAGE #include #endif // GHOUL_USE_FREEIMAGE @@ -74,7 +75,7 @@ #include #include #include -#endif //GHOUL_USE_SOIL +#endif // GHOUL_USE_SOIL #ifdef GHOUL_USE_STB_IMAGE #include @@ -863,14 +864,9 @@ void RenderEngine::renderOverlays(const ShutdownInformation& shutdownInfo) { renderScreenLog(); renderVersionInformation(); renderDashboard(); + renderCameraInformation(); - if (!shutdownInfo.inShutdown) { - // We render the camera information in the same location as the shutdown info - // and we won't need this if we are shutting down - renderCameraInformation(); - } - else { - // If we are in shutdown mode, we can display the remaining time + if (shutdownInfo.inShutdown) { renderShutdownInformation(shutdownInfo.timer, shutdownInfo.waitTime); } } @@ -890,12 +886,13 @@ void RenderEngine::renderEndscreen() { glm::vec2(global::windowDelegate->currentSubwindowSize()) / dpiScaling; glViewport(0, 0, res.x, res.y); - const glm::vec2 size = _fontShutdown->boundingBox("Shutting down"); + constexpr const std::string_view Text = "Shutting down"; + const glm::vec2 size = _fontShutdown->boundingBox(Text); glm::vec2 penPosition = glm::vec2( fontResolution().x / 2 - size.x / 2, fontResolution().y / 2 - size.y / 2 ); - RenderFont(*_fontShutdown, penPosition, "Shutting down"); + RenderFont(*_fontShutdown, penPosition, Text); } void RenderEngine::renderShutdownInformation(float timer, float fullTime) { @@ -903,30 +900,42 @@ void RenderEngine::renderShutdownInformation(float timer, float fullTime) { timer = std::max(timer, 0.f); - const glm::vec2 size = _fontShutdown->boundingBox( - fmt::format("Shutdown in: {:.2f}s/{:.2f}s", timer, fullTime) + // Render progressive overlay + glEnable(GL_BLEND); + + // t = 1.f -> start of shutdown counter t = 0.f -> timer has reached shutdown + float t = 1.f - (timer / fullTime); + + rendering::helper::renderBox( + glm::vec2(0.f), + glm::vec2(1.f), + glm::vec4(0.f, 0.f, 0.f, ghoul::circularEaseOut(t)) + ); + + // No need to print the text if we are just about to finish since otherwise we'll be + // overplotting the actual "shutdown in progress" text + if (timer == 0.f) { + return; + } + + constexpr const std::string_view FirstLine = "Shutdown in: {:.2f}s/{:.2f}s"; + const glm::vec2 size1 = _fontShutdown->boundingBox( + fmt::format(FirstLine, timer, fullTime) ); glm::vec2 penPosition = glm::vec2( - fontResolution().x - size.x - 10, - fontResolution().y - size.y + fontResolution().x / 2 - size1.x / 2, + fontResolution().y / 2 - size1.y / 2 ); RenderFont( *_fontShutdown, penPosition, - fmt::format("Shutdown in: {:.2f}s/{:.2f}s", timer, fullTime), - ghoul::fontrendering::CrDirection::Down - ); - - RenderFont( - *_fontShutdown, - penPosition, - // Important: length of this string is the same as the shutdown time text - // to make them align - "Press ESC again to abort", + fmt::format(FirstLine, timer, fullTime), ghoul::fontrendering::CrDirection::Down ); + // Important: Length of this string is the same as the first line to make them align + RenderFont(*_fontShutdown, penPosition, "Press ESC again to abort"); } void RenderEngine::renderDashboard() { From a8fd08efef0260d3f3626d2c838fa64082c1e253 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Sat, 3 Jul 2021 14:06:11 -0400 Subject: [PATCH 29/44] Feature/render at distance (#1665) Adding option to disable distance check for globes Co-authored-by: Alexander Bock --- modules/globebrowsing/src/renderableglobe.cpp | 17 ++++++++++++++++- modules/globebrowsing/src/renderableglobe.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/globebrowsing/src/renderableglobe.cpp b/modules/globebrowsing/src/renderableglobe.cpp index fdfef77894..b36fab95eb 100644 --- a/modules/globebrowsing/src/renderableglobe.cpp +++ b/modules/globebrowsing/src/renderableglobe.cpp @@ -179,6 +179,14 @@ namespace { "Enables shadow mapping algorithm. Used by renderable rings too." }; + constexpr openspace::properties::Property::PropertyInfo RenderAtDistanceInfo = { + "RenderAtDistance", + "Render at Distance", + "Tells the rendering engine not to perform distance based performance culling " + "for this globe. Turning this property on will let the globe to be seen at far " + "away distances when normally it would be hidden." + }; + constexpr openspace::properties::Property::PropertyInfo ZFightingPercentageInfo = { "ZFightingPercentage", "Z-Fighting Percentage", @@ -230,6 +238,9 @@ namespace { // not. If it is disabled, all parts of the planet are illuminated std::optional performShading; + // Specifies if distance culling should be disabled. + std::optional renderAtDistance; + // A list of all the layers that should be added std::map layers [[codegen::reference("globebrowsing_layermanager")]]; @@ -508,6 +519,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) BoolProperty(EclipseInfo, false), BoolProperty(EclipseHardShadowsInfo, false), BoolProperty(ShadowMappingInfo, false), + BoolProperty(RenderAtDistanceInfo, false), FloatProperty(ZFightingPercentageInfo, 0.995f, 0.000001f, 1.f), IntProperty(NumberShadowSamplesInfo, 5, 1, 7), FloatProperty(TargetLodScaleFactorInfo, 15.f, 1.f, 50.f), @@ -549,6 +561,8 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) _generalProperties.performShading = p.performShading.value_or(_generalProperties.performShading); + _generalProperties.renderAtDistance = + p.renderAtDistance.value_or(_generalProperties.renderAtDistance); // Init layer manager // @TODO (abock, 2021-03-25) The layermanager should be changed to take a @@ -560,6 +574,7 @@ RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) addProperty(_opacity); addProperty(_generalProperties.performShading); addProperty(_generalProperties.useAccurateNormals); + addProperty(_generalProperties.renderAtDistance); if (p.shadowGroup.has_value()) { std::vector shadowConfArray; @@ -711,7 +726,7 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& rendererTask constexpr int res = 2880; const double distance = res * boundingSphere() / tfov; - if (distanceToCamera < distance) { + if ((distanceToCamera < distance) || (_generalProperties.renderAtDistance)) { try { // Before Shadows _globeLabelsComponent.draw(data); diff --git a/modules/globebrowsing/src/renderableglobe.h b/modules/globebrowsing/src/renderableglobe.h index 35247cefe7..0c0e16a63a 100644 --- a/modules/globebrowsing/src/renderableglobe.h +++ b/modules/globebrowsing/src/renderableglobe.h @@ -135,6 +135,7 @@ private: properties::BoolProperty eclipseShadowsEnabled; properties::BoolProperty eclipseHardShadows; properties::BoolProperty shadowMapping; + properties::BoolProperty renderAtDistance; properties::FloatProperty zFightingPercentage; properties::IntProperty nShadowSamples; properties::FloatProperty targetLodScaleFactor; From 82b7c4e8235cd070768b125f0fc985e58e387145 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 3 Jul 2021 23:27:06 +0200 Subject: [PATCH 30/44] Fix issue with interrupted fisheye rendering between cube maps (closes #1275) --- src/rendering/framebufferrenderer.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/rendering/framebufferrenderer.cpp b/src/rendering/framebufferrenderer.cpp index f25d3aa4e2..7c93764d9f 100644 --- a/src/rendering/framebufferrenderer.cpp +++ b/src/rendering/framebufferrenderer.cpp @@ -738,6 +738,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (HasGLDebugInfo) { @@ -756,6 +758,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (HasGLDebugInfo) { @@ -774,6 +778,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (HasGLDebugInfo) { @@ -792,6 +798,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (HasGLDebugInfo) { @@ -810,6 +818,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { @@ -834,6 +844,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { @@ -853,6 +865,8 @@ void FramebufferRenderer::updateResolution() { GL_UNSIGNED_BYTE, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { @@ -876,9 +890,12 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - float volumeBorderColor[] = { 0.0f, 0.0f, 0.0f, 1.0f }; + + float volumeBorderColor[] = { 0.f, 0.f, 0.f, 1.f }; glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, volumeBorderColor); if (glbinding::Binding::ObjectLabel.isResolved()) { glObjectLabel( @@ -905,6 +922,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { @@ -929,6 +948,8 @@ void FramebufferRenderer::updateResolution() { GL_UNSIGNED_SHORT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { @@ -947,6 +968,8 @@ void FramebufferRenderer::updateResolution() { GL_FLOAT, nullptr ); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if (glbinding::Binding::ObjectLabel.isResolved()) { From 8e5a7034eeee94f315ee8f61872651afa6836018 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 4 Jul 2021 19:45:54 +0200 Subject: [PATCH 31/44] Add the ability to optionally ignore the scale value read from session recordings --- .../openspace/interaction/sessionrecording.h | 1 + src/interaction/sessionrecording.cpp | 26 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/openspace/interaction/sessionrecording.h b/include/openspace/interaction/sessionrecording.h index 749f7badfe..6e7167e8b3 100644 --- a/include/openspace/interaction/sessionrecording.h +++ b/include/openspace/interaction/sessionrecording.h @@ -575,6 +575,7 @@ public: protected: properties::BoolProperty _renderPlaybackInformation; + properties::BoolProperty _ignoreRecordedScale; enum class RecordedType { Camera = 0, diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 052f10c90c..59ec80a20b 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -65,6 +65,13 @@ namespace { "recording is rendering to screen" }; + constexpr openspace::properties::Property::PropertyInfo IgnoreRecordedScaleInfo = { + "IgnoreRecordedScale", + "Ignore Recorded Scale", + "If this value is enabled, the scale value from a recording is ignored and the " + "computed values are used instead" + }; + constexpr const bool UsingTimeKeyframes = false; } // namespace @@ -80,11 +87,13 @@ ConversionError::ConversionError(std::string msg) SessionRecording::SessionRecording() : properties::PropertyOwner({ "SessionRecording", "Session Recording" }) , _renderPlaybackInformation(RenderPlaybackInfo, false) + , _ignoreRecordedScale(IgnoreRecordedScaleInfo, false) {} SessionRecording::SessionRecording(bool isGlobal) : properties::PropertyOwner({ "SessionRecording", "Session Recording" }) , _renderPlaybackInformation(RenderPlaybackInfo, false) + , _ignoreRecordedScale(IgnoreRecordedScaleInfo, false) { if (isGlobal) { auto fTask = FactoryManager::ref().factory(); @@ -92,6 +101,7 @@ SessionRecording::SessionRecording(bool isGlobal) fTask->registerClass("ConvertRecFormatTask"); fTask->registerClass("ConvertRecFileVersionTask"); addProperty(_renderPlaybackInformation); + addProperty(_ignoreRecordedScale); } } @@ -980,8 +990,18 @@ void SessionRecording::render() { res.x / 2 - 150.f, res.y / 4 ); - std::string text = std::to_string(currentTime()); - ghoul::fontrendering::RenderFont(*font, penPosition, text, glm::vec4(1.f)); + std::string text1 = std::to_string(currentTime()); + ghoul::fontrendering::RenderFont( + *font, + penPosition, + text1, + glm::vec4(1.f), + ghoul::fontrendering::CrDirection::Down + ); + std::string text2 = fmt::format( + "Scale: {}", global::navigationHandler->camera()->scaling() + ); + ghoul::fontrendering::RenderFont(*font, penPosition, text2, glm::vec4(1.f)); } bool SessionRecording::isRecording() const { @@ -1968,7 +1988,7 @@ bool SessionRecording::processCameraKeyframe(double now) { prevPose, nextPose, t, - false + _ignoreRecordedScale ); } From 04ab698120f7298549cd2cb4fb01ea8d3ac0901b Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Mon, 5 Jul 2021 14:47:04 -0400 Subject: [PATCH 32/44] config file fixes --- config/fullscreen1080.xml | 2 +- config/spout_output.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fullscreen1080.xml b/config/fullscreen1080.xml index 3b7f94c4cc..52d703f435 100644 --- a/config/fullscreen1080.xml +++ b/config/fullscreen1080.xml @@ -4,7 +4,7 @@ - + diff --git a/config/spout_output.xml b/config/spout_output.xml index bac296112f..da4efdc48f 100644 --- a/config/spout_output.xml +++ b/config/spout_output.xml @@ -7,7 +7,7 @@ - + From 4a51eec75a4015e6aabb601333361fad7b19b274 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Mon, 5 Jul 2021 15:06:53 -0400 Subject: [PATCH 33/44] update gui hash --- data/assets/util/webgui.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/assets/util/webgui.asset b/data/assets/util/webgui.asset index 15195ee953..e03c216905 100644 --- a/data/assets/util/webgui.asset +++ b/data/assets/util/webgui.asset @@ -3,7 +3,7 @@ asset.require('./static_server') local guiCustomization = asset.require('customization/gui') -- Select which commit hashes to use for the frontend and backend -local frontendHash = "96b88e6c760e59d143bd29da6f06011eaafce4b1" +local frontendHash = "829260614bb95e236d23cb500f6ec0fb2e3bdf51" local dataProvider = "data.openspaceproject.com/files/webgui" local frontend = asset.syncedResource({ From 5370b9190e68e1c649713b9dee1f2ab604358840 Mon Sep 17 00:00:00 2001 From: GPayne Date: Tue, 6 Jul 2021 17:10:52 -0600 Subject: [PATCH 34/44] Fix for new hi-res Bennu projection model --- .../scene/solarsystem/missions/osirisrex/bennu_projection.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/assets/scene/solarsystem/missions/osirisrex/bennu_projection.asset b/data/assets/scene/solarsystem/missions/osirisrex/bennu_projection.asset index afcfb529a7..c78fbef4b2 100644 --- a/data/assets/scene/solarsystem/missions/osirisrex/bennu_projection.asset +++ b/data/assets/scene/solarsystem/missions/osirisrex/bennu_projection.asset @@ -34,7 +34,7 @@ local BennuProjection = { Enabled = true, Type = "RenderableModelProjection", Body = BENNU_BODY, - GeometryFile = models .. "/BennuTextured.obj", + GeometryFile = models .. "/Bennu_v20_200k_an.obj", Projection = { Sequence = { images, imagesA }, SequenceType = "image-sequence", From d4c06951da2af132b92ec970e469439baa5963b1 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 7 Jul 2021 05:37:53 +0200 Subject: [PATCH 35/44] Update faulty docs and function name for getGeoPosition (#1662) (#1677) New name: getLocalPositionFromGeo --- modules/globebrowsing/globebrowsingmodule.cpp | 14 ++++++++------ modules/globebrowsing/globebrowsingmodule_lua.inl | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/globebrowsing/globebrowsingmodule.cpp b/modules/globebrowsing/globebrowsingmodule.cpp index 89b7fe275b..b9253986b4 100644 --- a/modules/globebrowsing/globebrowsingmodule.cpp +++ b/modules/globebrowsing/globebrowsingmodule.cpp @@ -398,20 +398,22 @@ scripting::LuaLibrary GlobeBrowsingModule::luaLibrary() const { "the surface of the specified globe." }, { - "getGeoPosition", - &globebrowsing::luascriptfunctions::getGeoPosition, + "getLocalPositionFromGeo", + &globebrowsing::luascriptfunctions::getLocalPositionFromGeo, {}, "string, number, number, number", - "Returns the specified surface position on the globe identified by the first " - "argument, as three floating point values - latitude, longitude and altitude " - "(degrees and meters)." + "Returns a position in the local Cartesian coordinate system of the globe " + "identified by the first argument, that corresponds to the given geographic " + "coordinates: latitude, longitude and altitude (in degrees and meters). In " + "the local coordinate system, the position (0,0,0) corresponds to the " + "globe's center." }, { "getGeoPositionForCamera", &globebrowsing::luascriptfunctions::getGeoPositionForCamera, {}, "void", - "Get geographic coordinates of the camera poosition in latitude, " + "Get geographic coordinates of the camera position in latitude, " "longitude, and altitude (degrees and meters)." }, { diff --git a/modules/globebrowsing/globebrowsingmodule_lua.inl b/modules/globebrowsing/globebrowsingmodule_lua.inl index 4ed196188c..ec5d2d9374 100644 --- a/modules/globebrowsing/globebrowsingmodule_lua.inl +++ b/modules/globebrowsing/globebrowsingmodule_lua.inl @@ -287,8 +287,8 @@ int goToGeo(lua_State* L) { return 0; } -int getGeoPosition(lua_State* L) { - ghoul::lua::checkArgumentsAndThrow(L, 4, "lua::getGeoPosition"); +int getLocalPositionFromGeo(lua_State* L) { + ghoul::lua::checkArgumentsAndThrow(L, 4, "lua::getLocalPositionFromGeo"); const std::string& globeIdentifier = ghoul::lua::value(L, 1); const double latitude = ghoul::lua::value(L, 2); From c35ff0e8f211c8b58fafcd289d3f7d81e9b6c065 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Tue, 6 Jul 2021 23:38:36 -0400 Subject: [PATCH 36/44] adapt addFocusNodes for GlobeTranslation --- .../globebrowsing/scripts/layer_support.lua | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/modules/globebrowsing/scripts/layer_support.lua b/modules/globebrowsing/scripts/layer_support.lua index 82678d901c..0d3b94cc85 100644 --- a/modules/globebrowsing/scripts/layer_support.lua +++ b/modules/globebrowsing/scripts/layer_support.lua @@ -315,24 +315,25 @@ openspace.globebrowsing.addFocusNodesFromDirectory = function (dir, node_name) if file and file:find('.info') then local t = openspace.globebrowsing.parseInfoFile(file) - if t.Node and t.Location then - openspace.printInfo("Creating focus node for '" .. n .. "'") + if node_name and t.Location then + openspace.printInfo("Creating focus node for '" .. node_name .. "'") - local lat = t.Location.Center[2] - local long = t.Location.Center[1] - local a, b, c = openspace.globebrowsing.getGeoPosition(node_name, lat, long, 0.0) - local p = { a, b, c } + local lat = t.Location.Center[1] + local long = t.Location.Center[2] local identifier = node_name .. " - " .. t.Identifier - local name = node_name .. " - " .. t.Node + local name = node_name .. " - " .. t.Name openspace.addSceneGraphNode({ Identifier = identifier, Parent = node_name, Transform = { Translation = { - Type = "StaticTranslation", - Position = { p[1], p[2], p[3] } + Type = "GlobeTranslation", + Globe = node_name, + Latitude = lat, + Longitude = long, + UseHeightmap = true } }, GUI = { @@ -348,8 +349,6 @@ end openspace.globebrowsing.addFocusNodeFromLatLong = function (name, globe_identifier, lat, long, altitude) altitude = altitude or 0; - local a, b, c = openspace.globebrowsing.getGeoPosition(globe_identifier, lat, long, altitude) - local p = { a, b, c } local identifier = globe_identifier .. "-" .. name openspace.addSceneGraphNode({ From 85e7c6a1467bb05207de40254be51ef453f72261 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Wed, 7 Jul 2021 14:28:24 +0200 Subject: [PATCH 37/44] A few exponential slider updates * Add exponent to RenderableTrail period and resolution * Lower exponent of stereoscopic depth slider, to give better control --- modules/base/rendering/renderabletrailorbit.cpp | 2 ++ src/interaction/orbitalnavigator.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/base/rendering/renderabletrailorbit.cpp b/modules/base/rendering/renderabletrailorbit.cpp index a80152e3eb..fffd3effd8 100644 --- a/modules/base/rendering/renderabletrailorbit.cpp +++ b/modules/base/rendering/renderabletrailorbit.cpp @@ -158,10 +158,12 @@ RenderableTrailOrbit::RenderableTrailOrbit(const ghoul::Dictionary& dictionary) using namespace std::chrono; _period = p.period * duration_cast(hours(24)).count(); _period.onChange([&] { _needsFullSweep = true; _indexBufferDirty = true; }); + _period.setExponent(5.f); addProperty(_period); _resolution = p.resolution; _resolution.onChange([&] { _needsFullSweep = true; _indexBufferDirty = true; }); + _resolution.setExponent(3.5f); addProperty(_resolution); // We store the vertices with (excluding the wrapping) decending temporal order diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index 2e54fce454..7c91528ecd 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -391,7 +391,7 @@ OrbitalNavigator::OrbitalNavigator() addProperty(_useAdaptiveStereoscopicDepth); addProperty(_staticViewScaleExponent); - _stereoscopicDepthOfFocusSurface.setExponent(10.f); + _stereoscopicDepthOfFocusSurface.setExponent(3.f); addProperty(_stereoscopicDepthOfFocusSurface); addProperty(_retargetInterpolationTime); From 018207b718919cb8851d78f2c96cca149b1881bb Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Wed, 7 Jul 2021 08:33:44 -0600 Subject: [PATCH 38/44] Issue/1669 (#1678) * Potential fix for pause during playback-with-screenshots * Fixed a typo that slipped in * Added code from Emma to allow pausing during playback-with-frames --- src/interaction/sessionrecording.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index 59ec80a20b..6a0a80064f 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -1771,7 +1771,8 @@ void SessionRecording::moveAheadInTime() { using namespace std::chrono; bool paused = global::timeManager->isPaused(); - if (_state == SessionState::PlaybackPaused) { + bool playbackPaused = (_state == SessionState::PlaybackPaused); + if (playbackPaused) { _playbackPauseOffset += global::windowDelegate->applicationTime() - _previousTime; } @@ -1793,10 +1794,10 @@ void SessionRecording::moveAheadInTime() { global::navigationHandler->orbitalNavigator().anchorNode(); const Renderable* focusRenderable = focusNode->renderable(); if (!focusRenderable || focusRenderable->renderedWithDesiredData()) { - if (!paused) { + if (!playbackPaused) { _saveRenderingCurrentRecordedTime_interpolation += _saveRenderingDeltaTime_interpolation_usec; - _saveRenderingCurrentRecordedTime += _saveRenderingDeltaTime; + _saveRenderingCurrentRecordedTime += _saveRenderingDeltaTime; global::renderEngine->takeScreenshot(); } } From 5a29f1a27659d115244665f67a6c6d462b36ad59 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Wed, 7 Jul 2021 10:39:53 -0400 Subject: [PATCH 39/44] smaller value for adaptaive stereo hack --- src/interaction/orbitalnavigator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interaction/orbitalnavigator.cpp b/src/interaction/orbitalnavigator.cpp index 7c91528ecd..cbb2908a6d 100644 --- a/src/interaction/orbitalnavigator.cpp +++ b/src/interaction/orbitalnavigator.cpp @@ -256,7 +256,7 @@ OrbitalNavigator::OrbitalNavigator() , _useAdaptiveStereoscopicDepth(UseAdaptiveStereoscopicDepthInfo, true) , _stereoscopicDepthOfFocusSurface( StereoscopicDepthOfFocusSurfaceInfo, - 200000, + 21500, 0.25, 500000 ) From 95d008f69e8e3f92ab7ad73f12c8d2757f033a2c Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Wed, 7 Jul 2021 11:16:15 -0400 Subject: [PATCH 40/44] update ghoul --- ext/ghoul | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/ghoul b/ext/ghoul index c5add410f3..2ffa7b7f7a 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit c5add410f3367890e2a2f91f6087001baf8f2152 +Subproject commit 2ffa7b7f7a9582f191e51d4f7b030ea764f86a4c From f067cfa63b00b33a6ed61ff96ba7cc906c22c725 Mon Sep 17 00:00:00 2001 From: Micah Acinapura Date: Wed, 7 Jul 2021 12:19:15 -0400 Subject: [PATCH 41/44] adding renderable type back to renderables --- src/rendering/renderable.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rendering/renderable.cpp b/src/rendering/renderable.cpp index c9704ec821..53cb1b2f45 100644 --- a/src/rendering/renderable.cpp +++ b/src/rendering/renderable.cpp @@ -92,9 +92,6 @@ ghoul::mm_unique_ptr Renderable::createFromDictionary( documentation::testSpecificationAndThrow(Documentation(), dictionary, "Renderable"); std::string renderableType = dictionary.value(KeyType); - // Now we no longer need the type variable - dictionary.removeValue(KeyType); - auto factory = FactoryManager::ref().factory(); ghoul_assert(factory, "Renderable factory did not exist"); Renderable* result = factory->create( From 4493726aae4c0c66a4955c3794af8c198e588407 Mon Sep 17 00:00:00 2001 From: Micah Date: Thu, 8 Jul 2021 07:46:48 -0400 Subject: [PATCH 42/44] update sbs stereo config --- config/single_sbs_stereo.xml | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/config/single_sbs_stereo.xml b/config/single_sbs_stereo.xml index 595d92cafb..e0707559c1 100644 --- a/config/single_sbs_stereo.xml +++ b/config/single_sbs_stereo.xml @@ -1,22 +1,16 @@ - + + + + - - - - - - + + + + + - - - - - - - - - + @@ -24,7 +18,7 @@ - + From e00ae8a34d6a0c14fa3907bf10b72c69e8386b78 Mon Sep 17 00:00:00 2001 From: Micah Date: Thu, 8 Jul 2021 07:49:22 -0400 Subject: [PATCH 43/44] update version number for 0.17.0 release --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81d0833e7c..b4b73947d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,8 @@ project(OpenSpace) set(OPENSPACE_VERSION_MAJOR 0) set(OPENSPACE_VERSION_MINOR 17) -set(OPENSPACE_VERSION_PATCH -1) -set(OPENSPACE_VERSION_STRING "Beta-10 [RC1]") +set(OPENSPACE_VERSION_PATCH 0) +set(OPENSPACE_VERSION_STRING "Beta-10") set(OPENSPACE_BASE_DIR "${PROJECT_SOURCE_DIR}") set(OPENSPACE_CMAKE_EXT_DIR "${OPENSPACE_BASE_DIR}/support/cmake") From 5da4f104e884f7ad620efde8c3285f3ded9facd9 Mon Sep 17 00:00:00 2001 From: Gene Payne Date: Thu, 8 Jul 2021 13:43:09 -0600 Subject: [PATCH 44/44] Small fix for linux gcc build error --- src/util/coordinateconversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp index 041a126271..cc5e28aae4 100644 --- a/src/util/coordinateconversion.cpp +++ b/src/util/coordinateconversion.cpp @@ -222,7 +222,7 @@ glm::dvec2 icrsToDecimalDegrees(const std::string& ra, const std::string& dec) { } // Convert from hours/degrees, minutes, seconds to decimal degrees - double sign = signbit(static_cast(decDegrees)) ? -1.0 : 1.0; + double sign = std::signbit(static_cast(decDegrees)) ? -1.0 : 1.0; double raDeg = (raHours * 15.0) + (raMinutes * 15.0 / 60.0) + (raSeconds * 15.0 / 3600.0);