mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 08:00:06 +00:00
Load radar data asynchronously
This commit is contained in:
parent
803a25e884
commit
3625515b8a
6 changed files with 71 additions and 13 deletions
|
|
@ -1,5 +1,6 @@
|
|||
#include <scwx/qt/manager/radar_product_manager.hpp>
|
||||
#include <scwx/common/constants.hpp>
|
||||
#include <scwx/util/threads.hpp>
|
||||
|
||||
#include <deque>
|
||||
#include <execution>
|
||||
|
|
@ -182,6 +183,33 @@ void RadarProductManager::LoadLevel2Data(const std::string& filename)
|
|||
emit Level2DataLoaded();
|
||||
}
|
||||
|
||||
std::unordered_map<uint16_t, std::shared_ptr<wsr88d::rda::DigitalRadarData>>
|
||||
RadarProductManager::GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
|
||||
uint8_t elevationIndex,
|
||||
std::chrono::system_clock::time_point time)
|
||||
{
|
||||
std::unordered_map<uint16_t, std::shared_ptr<wsr88d::rda::DigitalRadarData>>
|
||||
radarData;
|
||||
|
||||
if (p->level2Data_.size() > 0)
|
||||
{
|
||||
// TODO: Pull this from the database
|
||||
radarData = p->level2Data_[0]->radar_data()[elevationIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
scwx::util::async([&]() {
|
||||
QString filename = qgetenv("AR2V_FILE");
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
LoadLevel2Data(filename.toUtf8().constData());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return radarData;
|
||||
}
|
||||
|
||||
} // namespace manager
|
||||
} // namespace qt
|
||||
} // namespace scwx
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ public:
|
|||
void Initialize();
|
||||
void LoadLevel2Data(const std::string& filename);
|
||||
|
||||
std::unordered_map<uint16_t, std::shared_ptr<wsr88d::rda::DigitalRadarData>>
|
||||
GetLevel2Data(wsr88d::rda::DataBlockType dataBlockType,
|
||||
uint8_t elevationIndex,
|
||||
std::chrono::system_clock::time_point time = {});
|
||||
|
||||
signals:
|
||||
void Level2DataLoaded();
|
||||
|
||||
|
|
|
|||
|
|
@ -77,11 +77,6 @@ MapWidget::MapWidget(const QMapboxGLSettings& settings) :
|
|||
setFocusPolicy(Qt::StrongFocus);
|
||||
|
||||
p->radarProductManager_->Initialize();
|
||||
QString ar2vFile = qgetenv("AR2V_FILE");
|
||||
if (!ar2vFile.isEmpty())
|
||||
{
|
||||
p->radarProductManager_->LoadLevel2Data(ar2vFile.toUtf8().constData());
|
||||
}
|
||||
|
||||
SelectRadarProduct(common::Level2Product::Reflectivity);
|
||||
}
|
||||
|
|
@ -110,6 +105,19 @@ void MapWidget::SelectRadarProduct(common::Level2Product product)
|
|||
p->radarProductView_->LoadColorTable(colorTable);
|
||||
}
|
||||
|
||||
connect(
|
||||
p->radarProductView_.get(),
|
||||
&view::RadarProductView::ColorTableUpdated,
|
||||
this,
|
||||
[&]() { update(); },
|
||||
Qt::QueuedConnection);
|
||||
connect(
|
||||
p->radarProductView_.get(),
|
||||
&view::RadarProductView::SweepComputed,
|
||||
this,
|
||||
[&]() { update(); },
|
||||
Qt::QueuedConnection);
|
||||
|
||||
if (p->map_ != nullptr)
|
||||
{
|
||||
AddLayers();
|
||||
|
|
|
|||
|
|
@ -236,19 +236,19 @@ void Level2ProductView::ComputeSweep()
|
|||
return;
|
||||
}
|
||||
|
||||
std::shared_ptr<const wsr88d::Ar2vFile> level2Data =
|
||||
p->radarProductManager_->level2_data();
|
||||
if (level2Data == nullptr)
|
||||
// TODO: Pick this based on view settings
|
||||
auto radarData =
|
||||
p->radarProductManager_->GetLevel2Data(p->dataBlockType_, 0);
|
||||
if (radarData.size() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Pick this based on radar data
|
||||
const common::RadialSize radialSize = (radarData.size() == 720) ?
|
||||
common::RadialSize::_0_5Degree :
|
||||
common::RadialSize::_1Degree;
|
||||
const std::vector<float>& coordinates =
|
||||
p->radarProductManager_->coordinates(common::RadialSize::_0_5Degree);
|
||||
|
||||
// TODO: Pick this based on view settings
|
||||
auto radarData = level2Data->radar_data()[0];
|
||||
p->radarProductManager_->coordinates(radialSize);
|
||||
|
||||
auto momentData0 = radarData[0]->moment_data_block(p->dataBlockType_);
|
||||
p->momentDataBlock0_ = momentData0;
|
||||
|
|
|
|||
16
wxdata/include/scwx/util/threads.hpp
Normal file
16
wxdata/include/scwx/util/threads.hpp
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#include <future>
|
||||
|
||||
namespace scwx
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
template<class F>
|
||||
void async(F&& f)
|
||||
{
|
||||
auto future = std::make_shared<std::future<void>>();
|
||||
*future = std::async(std::launch::async, [future, f]() { f(); });
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace scwx
|
||||
|
|
@ -11,6 +11,7 @@ set(SRC_COMMON source/scwx/common/color_table.cpp
|
|||
set(HDR_UTIL include/scwx/util/iterator.hpp
|
||||
include/scwx/util/rangebuf.hpp
|
||||
include/scwx/util/streams.hpp
|
||||
include/scwx/util/threads.hpp
|
||||
include/scwx/util/vectorbuf.hpp)
|
||||
set(SRC_UTIL source/scwx/util/rangebuf.cpp
|
||||
source/scwx/util/streams.cpp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue