From 1c39464228aa72b647a3909bbe9aaa57492b835c Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Thu, 20 Jul 2023 23:12:36 -0500 Subject: [PATCH] Extract utility geographic and maplibre functions --- scwx-qt/scwx-qt.cmake | 2 ++ .../scwx/qt/map/radar_product_layer.cpp | 22 ++----------- .../source/scwx/qt/util/geographic_lib.cpp | 11 +++++++ .../source/scwx/qt/util/geographic_lib.hpp | 17 +++++++++- scwx-qt/source/scwx/qt/util/maplibre.cpp | 32 +++++++++++++++++++ scwx-qt/source/scwx/qt/util/maplibre.hpp | 20 ++++++++++++ 6 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 scwx-qt/source/scwx/qt/util/maplibre.cpp create mode 100644 scwx-qt/source/scwx/qt/util/maplibre.hpp diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 01ba5517..3856117f 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -192,6 +192,7 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp source/scwx/qt/util/font_buffer.hpp source/scwx/qt/util/geographic_lib.hpp source/scwx/qt/util/json.hpp + source/scwx/qt/util/maplibre.hpp source/scwx/qt/util/streams.hpp source/scwx/qt/util/texture_atlas.hpp source/scwx/qt/util/q_file_buffer.hpp @@ -203,6 +204,7 @@ set(SRC_UTIL source/scwx/qt/util/color.cpp source/scwx/qt/util/font_buffer.cpp source/scwx/qt/util/geographic_lib.cpp source/scwx/qt/util/json.cpp + source/scwx/qt/util/maplibre.cpp source/scwx/qt/util/texture_atlas.cpp source/scwx/qt/util/q_file_buffer.cpp source/scwx/qt/util/q_file_input_stream.cpp diff --git a/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp index 710ca3d6..be3218c5 100644 --- a/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_product_layer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include @@ -31,9 +32,6 @@ static constexpr uint32_t MAX_DATA_MOMENT_GATES = 1840; static const std::string logPrefix_ = "scwx::qt::map::radar_product_layer"; static const auto logger_ = scwx::util::Logger::Create(logPrefix_); -static glm::vec2 -LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate); - class RadarProductLayerImpl { public: @@ -287,7 +285,7 @@ void RadarProductLayer::Render( gl.glUniform2fv(p->uMapScreenCoordLocation_, 1, - glm::value_ptr(LatLongToScreenCoordinate( + glm::value_ptr(util::maplibre::LatLongToScreenCoordinate( {params.latitude, params.longitude}))); gl.glUniformMatrix4fv( @@ -355,22 +353,6 @@ void RadarProductLayer::UpdateColorTable() gl.glUniform1f(p->uDataMomentScaleLocation_, scale); } -static glm::vec2 -LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate) -{ - static constexpr double RAD2DEG_D = 180.0 / M_PI; - - double latitude = std::clamp( - coordinate.first, -mbgl::util::LATITUDE_MAX, mbgl::util::LATITUDE_MAX); - glm::vec2 screen { - mbgl::util::LONGITUDE_MAX + coordinate.second, - -(mbgl::util::LONGITUDE_MAX - - RAD2DEG_D * - std::log(std::tan(M_PI / 4.0 + - latitude * M_PI / mbgl::util::DEGREES_MAX)))}; - return screen; -} - } // namespace map } // namespace qt } // namespace scwx diff --git a/scwx-qt/source/scwx/qt/util/geographic_lib.cpp b/scwx-qt/source/scwx/qt/util/geographic_lib.cpp index 5c55b9e2..84ae9e66 100644 --- a/scwx-qt/source/scwx/qt/util/geographic_lib.cpp +++ b/scwx-qt/source/scwx/qt/util/geographic_lib.cpp @@ -18,6 +18,17 @@ const ::GeographicLib::Geodesic& DefaultGeodesic() return geodesic_; } +boost::units::quantity +GetDistance(double lat1, double lon1, double lat2, double lon2) +{ + double distance; + util::GeographicLib::DefaultGeodesic().Inverse( + lat1, lon1, lat2, lon2, distance); + + return static_cast>( + distance * boost::units::si::meter_base_unit::unit_type()); +} + } // namespace GeographicLib } // namespace util } // namespace qt diff --git a/scwx-qt/source/scwx/qt/util/geographic_lib.hpp b/scwx-qt/source/scwx/qt/util/geographic_lib.hpp index 3fe3c187..c3e74ef9 100644 --- a/scwx-qt/source/scwx/qt/util/geographic_lib.hpp +++ b/scwx-qt/source/scwx/qt/util/geographic_lib.hpp @@ -1,6 +1,8 @@ #pragma once #include +#include +#include namespace scwx { @@ -14,10 +16,23 @@ namespace GeographicLib /** * Get the default geodesic for the WGS84 ellipsoid. * - * return WGS84 ellipsoid geodesic + * @return WGS84 ellipsoid geodesic */ const ::GeographicLib::Geodesic& DefaultGeodesic(); +/** + * Get the distance between two points. + * + * @param [in] lat1 latitude of point 1 (degrees) + * @param [in] lon1 longitude of point 1 (degrees) + * @param [in] lat2 latitude of point 2 (degrees) + * @param [in] lon2 longitude of point 2 (degrees) + * + * @return distance between point 1 and point 2 + */ +boost::units::quantity +GetDistance(double lat1, double lon1, double lat2, double lon2); + } // namespace GeographicLib } // namespace util } // namespace qt diff --git a/scwx-qt/source/scwx/qt/util/maplibre.cpp b/scwx-qt/source/scwx/qt/util/maplibre.cpp new file mode 100644 index 00000000..c2170425 --- /dev/null +++ b/scwx-qt/source/scwx/qt/util/maplibre.cpp @@ -0,0 +1,32 @@ +#include + +#include + +namespace scwx +{ +namespace qt +{ +namespace util +{ +namespace maplibre +{ + +glm::vec2 LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate) +{ + static constexpr double RAD2DEG_D = 180.0 / M_PI; + + double latitude = std::clamp( + coordinate.first, -mbgl::util::LATITUDE_MAX, mbgl::util::LATITUDE_MAX); + glm::vec2 screen { + mbgl::util::LONGITUDE_MAX + coordinate.second, + -(mbgl::util::LONGITUDE_MAX - + RAD2DEG_D * + std::log(std::tan(M_PI / 4.0 + + latitude * M_PI / mbgl::util::DEGREES_MAX)))}; + return screen; +} + +} // namespace maplibre +} // namespace util +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/util/maplibre.hpp b/scwx-qt/source/scwx/qt/util/maplibre.hpp new file mode 100644 index 00000000..03d548de --- /dev/null +++ b/scwx-qt/source/scwx/qt/util/maplibre.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace util +{ +namespace maplibre +{ + +glm::vec2 LatLongToScreenCoordinate(const QMapLibreGL::Coordinate& coordinate); + +} // namespace maplibre +} // namespace util +} // namespace qt +} // namespace scwx