mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 19:10:06 +00:00
USe a common default geodesic object instead of duplicate copies.
All used functions are constant, and don't require unique instantiations for thread safety.
This commit is contained in:
parent
4a31cf6d3e
commit
90c8c0183a
10 changed files with 89 additions and 47 deletions
|
|
@ -163,6 +163,7 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp
|
|||
source/scwx/qt/util/file.hpp
|
||||
source/scwx/qt/util/font.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/streams.hpp
|
||||
source/scwx/qt/util/texture_atlas.hpp
|
||||
|
|
@ -172,6 +173,7 @@ set(SRC_UTIL source/scwx/qt/util/color.cpp
|
|||
source/scwx/qt/util/file.cpp
|
||||
source/scwx/qt/util/font.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/texture_atlas.cpp
|
||||
source/scwx/qt/util/q_file_buffer.cpp
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <scwx/qt/config/radar_site.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/qt/util/json.hpp>
|
||||
#include <scwx/common/sites.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
|
@ -8,7 +9,6 @@
|
|||
#include <unordered_map>
|
||||
|
||||
#include <boost/json.hpp>
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -31,9 +31,6 @@ static std::unordered_map<std::string, std::shared_ptr<RadarSite>>
|
|||
static std::unordered_map<std::string, std::string> siteIdMap_;
|
||||
static std::shared_mutex siteMutex_;
|
||||
|
||||
static GeographicLib::Geodesic geodesic_ {GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f()};
|
||||
|
||||
static bool ValidateJsonEntry(const boost::json::object& o);
|
||||
|
||||
class RadarSiteImpl
|
||||
|
|
@ -187,11 +184,11 @@ std::shared_ptr<RadarSite> RadarSite::FindNearest(
|
|||
}
|
||||
|
||||
// Calculate distance to radar site
|
||||
geodesic_.Inverse(latitude,
|
||||
longitude,
|
||||
radarSite->latitude(),
|
||||
radarSite->longitude(),
|
||||
distanceInMeters);
|
||||
util::GeographicLib::DefaultGeodesic().Inverse(latitude,
|
||||
longitude,
|
||||
radarSite->latitude(),
|
||||
radarSite->longitude(),
|
||||
distanceInMeters);
|
||||
|
||||
// If the radar site is the closer, record it as the closest
|
||||
if (nearestRadarSite == nullptr || distanceInMeters < nearestDistance)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include <scwx/qt/gl/draw/geo_line.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/qt/util/texture_atlas.hpp>
|
||||
#include <scwx/common/geographic.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
|
@ -6,8 +7,6 @@
|
|||
#include <numbers>
|
||||
#include <optional>
|
||||
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
|
|
@ -33,8 +32,7 @@ class GeoLine::Impl
|
|||
public:
|
||||
explicit Impl(std::shared_ptr<GlContext> context) :
|
||||
context_ {context},
|
||||
geodesic_(GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f()),
|
||||
geodesic_ {util::GeographicLib::DefaultGeodesic()},
|
||||
dirty_ {false},
|
||||
visible_ {true},
|
||||
points_ {},
|
||||
|
|
@ -55,7 +53,7 @@ public:
|
|||
|
||||
std::shared_ptr<GlContext> context_;
|
||||
|
||||
GeographicLib::Geodesic geodesic_;
|
||||
const GeographicLib::Geodesic& geodesic_;
|
||||
|
||||
bool dirty_;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include <scwx/qt/manager/radar_product_manager.hpp>
|
||||
#include <scwx/qt/manager/radar_product_manager_notifier.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/common/constants.hpp>
|
||||
#include <scwx/provider/nexrad_data_provider_factory.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
|
@ -18,7 +19,6 @@
|
|||
#include <boost/range/irange.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <fmt/chrono.h>
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
#include <QMapLibreGL/QMapLibreGL>
|
||||
#pragma warning(pop)
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ public:
|
|||
group_ {group},
|
||||
product_ {product},
|
||||
refreshEnabled_ {false},
|
||||
refreshTimer_ {util::io_context()},
|
||||
refreshTimer_ {scwx::util::io_context()},
|
||||
refreshTimerMutex_ {},
|
||||
provider_ {nullptr}
|
||||
{
|
||||
|
|
@ -303,8 +303,8 @@ void RadarProductManager::Initialize()
|
|||
|
||||
boost::timer::cpu_timer timer;
|
||||
|
||||
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f());
|
||||
const GeographicLib::Geodesic& geodesic(
|
||||
util::GeographicLib::DefaultGeodesic());
|
||||
|
||||
const QMapLibreGL::Coordinate radar(p->radarSite_->latitude(),
|
||||
p->radarSite_->longitude());
|
||||
|
|
@ -425,7 +425,7 @@ void RadarProductManager::EnableRefresh(common::RadarProductGroup group,
|
|||
p->GetLevel3ProviderManager(product);
|
||||
|
||||
// Only enable refresh on available products
|
||||
util::async(
|
||||
scwx::util::async(
|
||||
[=]()
|
||||
{
|
||||
providerManager->provider_->RequestAvailableProducts();
|
||||
|
|
@ -467,7 +467,7 @@ void RadarProductManagerImpl::RefreshData(
|
|||
providerManager->refreshTimer_.cancel();
|
||||
}
|
||||
|
||||
util::async(
|
||||
scwx::util::async(
|
||||
[=]()
|
||||
{
|
||||
auto [newObjects, totalObjects] =
|
||||
|
|
@ -547,7 +547,7 @@ void RadarProductManagerImpl::LoadProviderData(
|
|||
{
|
||||
logger_->debug("LoadProviderData: {}, {}",
|
||||
providerManager->name(),
|
||||
util::TimeString(time));
|
||||
scwx::util::TimeString(time));
|
||||
|
||||
RadarProductManagerImpl::LoadNexradFile(
|
||||
[=, &recordMap, &recordMutex, &loadDataMutex]()
|
||||
|
|
@ -589,7 +589,7 @@ void RadarProductManager::LoadLevel2Data(
|
|||
std::chrono::system_clock::time_point time,
|
||||
std::shared_ptr<request::NexradFileRequest> request)
|
||||
{
|
||||
logger_->debug("LoadLevel2Data: {}", util::TimeString(time));
|
||||
logger_->debug("LoadLevel2Data: {}", scwx::util::TimeString(time));
|
||||
|
||||
p->LoadProviderData(time,
|
||||
p->level2ProviderManager_,
|
||||
|
|
@ -604,7 +604,7 @@ void RadarProductManager::LoadLevel3Data(
|
|||
std::chrono::system_clock::time_point time,
|
||||
std::shared_ptr<request::NexradFileRequest> request)
|
||||
{
|
||||
logger_->debug("LoadLevel3Data: {}", util::TimeString(time));
|
||||
logger_->debug("LoadLevel3Data: {}", scwx::util::TimeString(time));
|
||||
|
||||
// Look up provider manager
|
||||
std::shared_lock providerManagerLock(p->level3ProviderManagerMutex_);
|
||||
|
|
@ -742,7 +742,7 @@ RadarProductManagerImpl::GetLevel2ProductRecord(
|
|||
else
|
||||
{
|
||||
// TODO: Round to minutes
|
||||
record = util::GetBoundedElementValue(level2ProductRecords_, time);
|
||||
record = scwx::util::GetBoundedElementValue(level2ProductRecords_, time);
|
||||
|
||||
// Does the record contain the time we are looking for?
|
||||
if (record != nullptr && (time < record->level2_file()->start_time()))
|
||||
|
|
@ -774,7 +774,7 @@ RadarProductManagerImpl::GetLevel3ProductRecord(
|
|||
}
|
||||
else
|
||||
{
|
||||
record = util::GetBoundedElementValue(it->second, time);
|
||||
record = scwx::util::GetBoundedElementValue(it->second, time);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -904,7 +904,7 @@ void RadarProductManager::UpdateAvailableProducts()
|
|||
|
||||
logger_->debug("UpdateAvailableProducts()");
|
||||
|
||||
util::async(
|
||||
scwx::util::async(
|
||||
[=]()
|
||||
{
|
||||
auto level3ProviderManager =
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include <scwx/qt/map/radar_range_layer.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace scwx
|
||||
|
|
@ -61,8 +61,8 @@ void RadarRangeLayer::Update(std::shared_ptr<QMapLibreGL::Map> map,
|
|||
static std::shared_ptr<QMapLibreGL::Feature>
|
||||
GetRangeCircle(float range, QMapLibreGL::Coordinate center)
|
||||
{
|
||||
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f());
|
||||
const GeographicLib::Geodesic& geodesic(
|
||||
util::GeographicLib::DefaultGeodesic());
|
||||
|
||||
constexpr float angleDelta = 0.5f;
|
||||
constexpr float angleDeltaH = angleDelta / 2.0f;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <scwx/qt/config/county_database.hpp>
|
||||
#include <scwx/qt/manager/text_event_manager.hpp>
|
||||
#include <scwx/qt/types/qt_types.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/common/geographic.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
#include <scwx/util/strings.hpp>
|
||||
|
|
@ -9,7 +10,6 @@
|
|||
|
||||
#include <format>
|
||||
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
QList<types::TextEventKey> textEventKeys_;
|
||||
|
||||
GeographicLib::Geodesic geodesic_;
|
||||
const GeographicLib::Geodesic& geodesic_;
|
||||
|
||||
std::unordered_map<types::TextEventKey,
|
||||
common::Coordinate,
|
||||
|
|
@ -357,8 +357,7 @@ void AlertModel::HandleMapUpdate(double latitude, double longitude)
|
|||
AlertModelImpl::AlertModelImpl() :
|
||||
textEventManager_ {manager::TextEventManager::Instance()},
|
||||
textEventKeys_ {},
|
||||
geodesic_(GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f()),
|
||||
geodesic_(util::GeographicLib::DefaultGeodesic()),
|
||||
distanceMap_ {},
|
||||
distanceDisplay_ {scwx::common::DistanceType::Miles},
|
||||
previousPosition_ {}
|
||||
|
|
@ -381,7 +380,7 @@ std::string AlertModelImpl::GetCounties(const types::TextEventKey& key)
|
|||
}
|
||||
std::sort(counties.begin(), counties.end());
|
||||
|
||||
return util::ToString(counties);
|
||||
return scwx::util::ToString(counties);
|
||||
}
|
||||
|
||||
std::string AlertModelImpl::GetState(const types::TextEventKey& key)
|
||||
|
|
@ -390,7 +389,7 @@ std::string AlertModelImpl::GetState(const types::TextEventKey& key)
|
|||
auto& lastMessage = messageList.back();
|
||||
size_t segmentCount = lastMessage->segment_count();
|
||||
auto lastSegment = lastMessage->segment(segmentCount - 1);
|
||||
return util::ToString(lastSegment->header_->ugc_.states());
|
||||
return scwx::util::ToString(lastSegment->header_->ugc_.states());
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
|
|
@ -404,7 +403,7 @@ AlertModelImpl::GetStartTime(const types::TextEventKey& key)
|
|||
|
||||
std::string AlertModelImpl::GetStartTimeString(const types::TextEventKey& key)
|
||||
{
|
||||
return util::TimeString(GetStartTime(key));
|
||||
return scwx::util::TimeString(GetStartTime(key));
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point
|
||||
|
|
@ -419,7 +418,7 @@ AlertModelImpl::GetEndTime(const types::TextEventKey& key)
|
|||
|
||||
std::string AlertModelImpl::GetEndTimeString(const types::TextEventKey& key)
|
||||
{
|
||||
return util::TimeString(GetEndTime(key));
|
||||
return scwx::util::TimeString(GetEndTime(key));
|
||||
}
|
||||
|
||||
} // namespace model
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
#include <scwx/qt/model/radar_site_model.hpp>
|
||||
#include <scwx/qt/config/radar_site.hpp>
|
||||
#include <scwx/qt/types/qt_types.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/common/geographic.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
|
||||
#include <format>
|
||||
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
|
|
@ -36,7 +35,7 @@ public:
|
|||
|
||||
QList<std::shared_ptr<config::RadarSite>> radarSites_;
|
||||
|
||||
GeographicLib::Geodesic geodesic_;
|
||||
const GeographicLib::Geodesic& geodesic_;
|
||||
|
||||
std::unordered_map<std::string, double> distanceMap_;
|
||||
scwx::common::DistanceType distanceDisplay_;
|
||||
|
|
@ -186,8 +185,7 @@ void RadarSiteModel::HandleMapUpdate(double latitude, double longitude)
|
|||
|
||||
RadarSiteModelImpl::RadarSiteModelImpl() :
|
||||
radarSites_ {},
|
||||
geodesic_(GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f()),
|
||||
geodesic_(util::GeographicLib::DefaultGeodesic()),
|
||||
distanceMap_ {},
|
||||
distanceDisplay_ {scwx::common::DistanceType::Miles},
|
||||
previousPosition_ {}
|
||||
|
|
|
|||
24
scwx-qt/source/scwx/qt/util/geographic_lib.cpp
Normal file
24
scwx-qt/source/scwx/qt/util/geographic_lib.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace GeographicLib
|
||||
{
|
||||
|
||||
const ::GeographicLib::Geodesic& DefaultGeodesic()
|
||||
{
|
||||
static const ::GeographicLib::Geodesic geodesic_ {
|
||||
::GeographicLib::Constants::WGS84_a(),
|
||||
::GeographicLib::Constants::WGS84_f()};
|
||||
|
||||
return geodesic_;
|
||||
}
|
||||
|
||||
} // namespace GeographicLib
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
24
scwx-qt/source/scwx/qt/util/geographic_lib.hpp
Normal file
24
scwx-qt/source/scwx/qt/util/geographic_lib.hpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace qt
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
namespace GeographicLib
|
||||
{
|
||||
|
||||
/**
|
||||
* Get the default geodesic for the WGS84 ellipsoid.
|
||||
*
|
||||
* return WGS84 ellipsoid geodesic
|
||||
*/
|
||||
const ::GeographicLib::Geodesic& DefaultGeodesic();
|
||||
|
||||
} // namespace GeographicLib
|
||||
} // namespace util
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#include <scwx/qt/view/level3_raster_view.hpp>
|
||||
#include <scwx/qt/util/geographic_lib.hpp>
|
||||
#include <scwx/common/constants.hpp>
|
||||
#include <scwx/util/logger.hpp>
|
||||
#include <scwx/util/threads.hpp>
|
||||
|
|
@ -7,7 +8,6 @@
|
|||
|
||||
#include <boost/range/irange.hpp>
|
||||
#include <boost/timer/timer.hpp>
|
||||
#include <GeographicLib/Geodesic.hpp>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
|
|
@ -202,12 +202,12 @@ void Level3RasterView::ComputeSweep()
|
|||
p->longitude_ = descriptionBlock->longitude_of_radar();
|
||||
p->range_ = descriptionBlock->range();
|
||||
p->sweepTime_ =
|
||||
util::TimePoint(descriptionBlock->volume_scan_date(),
|
||||
descriptionBlock->volume_scan_start_time() * 1000);
|
||||
scwx::util::TimePoint(descriptionBlock->volume_scan_date(),
|
||||
descriptionBlock->volume_scan_start_time() * 1000);
|
||||
p->vcp_ = descriptionBlock->volume_coverage_pattern();
|
||||
|
||||
GeographicLib::Geodesic geodesic(GeographicLib::Constants::WGS84_a(),
|
||||
GeographicLib::Constants::WGS84_f());
|
||||
const GeographicLib::Geodesic& geodesic =
|
||||
util::GeographicLib::DefaultGeodesic();
|
||||
|
||||
const uint16_t xResolution = descriptionBlock->x_resolution_raw();
|
||||
const uint16_t yResolution = descriptionBlock->y_resolution_raw();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue