mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 10:10:05 +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/qt/manager/radar_product_manager.hpp> | ||||||
| #include <scwx/common/constants.hpp> | #include <scwx/common/constants.hpp> | ||||||
|  | #include <scwx/util/threads.hpp> | ||||||
| 
 | 
 | ||||||
| #include <deque> | #include <deque> | ||||||
| #include <execution> | #include <execution> | ||||||
|  | @ -182,6 +183,33 @@ void RadarProductManager::LoadLevel2Data(const std::string& filename) | ||||||
|    emit Level2DataLoaded(); |    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 manager
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -33,6 +33,11 @@ public: | ||||||
|    void Initialize(); |    void Initialize(); | ||||||
|    void LoadLevel2Data(const std::string& filename); |    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: | signals: | ||||||
|    void Level2DataLoaded(); |    void Level2DataLoaded(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -77,11 +77,6 @@ MapWidget::MapWidget(const QMapboxGLSettings& settings) : | ||||||
|    setFocusPolicy(Qt::StrongFocus); |    setFocusPolicy(Qt::StrongFocus); | ||||||
| 
 | 
 | ||||||
|    p->radarProductManager_->Initialize(); |    p->radarProductManager_->Initialize(); | ||||||
|    QString ar2vFile = qgetenv("AR2V_FILE"); |  | ||||||
|    if (!ar2vFile.isEmpty()) |  | ||||||
|    { |  | ||||||
|       p->radarProductManager_->LoadLevel2Data(ar2vFile.toUtf8().constData()); |  | ||||||
|    } |  | ||||||
| 
 | 
 | ||||||
|    SelectRadarProduct(common::Level2Product::Reflectivity); |    SelectRadarProduct(common::Level2Product::Reflectivity); | ||||||
| } | } | ||||||
|  | @ -110,6 +105,19 @@ void MapWidget::SelectRadarProduct(common::Level2Product product) | ||||||
|       p->radarProductView_->LoadColorTable(colorTable); |       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) |    if (p->map_ != nullptr) | ||||||
|    { |    { | ||||||
|       AddLayers(); |       AddLayers(); | ||||||
|  |  | ||||||
|  | @ -236,19 +236,19 @@ void Level2ProductView::ComputeSweep() | ||||||
|       return; |       return; | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<const wsr88d::Ar2vFile> level2Data = |    // TODO: Pick this based on view settings
 | ||||||
|       p->radarProductManager_->level2_data(); |    auto radarData = | ||||||
|    if (level2Data == nullptr) |       p->radarProductManager_->GetLevel2Data(p->dataBlockType_, 0); | ||||||
|  |    if (radarData.size() == 0) | ||||||
|    { |    { | ||||||
|       return; |       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 = |    const std::vector<float>& coordinates = | ||||||
|       p->radarProductManager_->coordinates(common::RadialSize::_0_5Degree); |       p->radarProductManager_->coordinates(radialSize); | ||||||
| 
 |  | ||||||
|    // TODO: Pick this based on view settings
 |  | ||||||
|    auto radarData = level2Data->radar_data()[0]; |  | ||||||
| 
 | 
 | ||||||
|    auto momentData0     = radarData[0]->moment_data_block(p->dataBlockType_); |    auto momentData0     = radarData[0]->moment_data_block(p->dataBlockType_); | ||||||
|    p->momentDataBlock0_ = momentData0; |    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 | set(HDR_UTIL include/scwx/util/iterator.hpp | ||||||
|              include/scwx/util/rangebuf.hpp |              include/scwx/util/rangebuf.hpp | ||||||
|              include/scwx/util/streams.hpp |              include/scwx/util/streams.hpp | ||||||
|  |              include/scwx/util/threads.hpp | ||||||
|              include/scwx/util/vectorbuf.hpp) |              include/scwx/util/vectorbuf.hpp) | ||||||
| set(SRC_UTIL source/scwx/util/rangebuf.cpp | set(SRC_UTIL source/scwx/util/rangebuf.cpp | ||||||
|              source/scwx/util/streams.cpp |              source/scwx/util/streams.cpp | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat