mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 01:00:05 +00:00 
			
		
		
		
	Adding map context to simplify parameter passing
This commit is contained in:
		
							parent
							
								
									afb174a8fe
								
							
						
					
					
						commit
						f7f86ec24a
					
				
					 12 changed files with 140 additions and 124 deletions
				
			
		|  | @ -67,6 +67,7 @@ set(SRC_MANAGER source/scwx/qt/manager/radar_product_manager.cpp | ||||||
| set(HDR_MAP source/scwx/qt/map/color_table_layer.hpp | set(HDR_MAP source/scwx/qt/map/color_table_layer.hpp | ||||||
|             source/scwx/qt/map/generic_layer.hpp |             source/scwx/qt/map/generic_layer.hpp | ||||||
|             source/scwx/qt/map/layer_wrapper.hpp |             source/scwx/qt/map/layer_wrapper.hpp | ||||||
|  |             source/scwx/qt/map/map_context.hpp | ||||||
|             source/scwx/qt/map/map_widget.hpp |             source/scwx/qt/map/map_widget.hpp | ||||||
|             source/scwx/qt/map/overlay_layer.hpp |             source/scwx/qt/map/overlay_layer.hpp | ||||||
|             source/scwx/qt/map/radar_product_layer.hpp |             source/scwx/qt/map/radar_product_layer.hpp | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ | ||||||
| #define SCWX_GL_CHECK_ERROR()                                                  \ | #define SCWX_GL_CHECK_ERROR()                                                  \ | ||||||
|    {                                                                           \ |    {                                                                           \ | ||||||
|       GLenum err;                                                              \ |       GLenum err;                                                              \ | ||||||
|       while ((err = p->gl_.glGetError()) != GL_NO_ERROR)                       \ |       while ((err = gl.glGetError()) != GL_NO_ERROR)                           \ | ||||||
|       {                                                                        \ |       {                                                                        \ | ||||||
|          BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "GL Error: " << err       \ |          BOOST_LOG_TRIVIAL(warning) << logPrefix_ << "GL Error: " << err       \ | ||||||
|                                     << ", " __FILE__ << ":" << __LINE__;       \ |                                     << ", " __FILE__ << ":" << __LINE__;       \ | ||||||
|  |  | ||||||
|  | @ -17,12 +17,8 @@ static const std::string logPrefix_ = "[scwx::qt::map::color_table_layer] "; | ||||||
| class ColorTableLayerImpl | class ColorTableLayerImpl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit ColorTableLayerImpl( |    explicit ColorTableLayerImpl(std::shared_ptr<MapContext> context) : | ||||||
|       std::shared_ptr<view::RadarProductView> radarProductView, |        shaderProgram_(context->gl_), | ||||||
|       gl::OpenGLFunctions&                    gl) : |  | ||||||
|        radarProductView_(radarProductView), |  | ||||||
|        gl_(gl), |  | ||||||
|        shaderProgram_(gl), |  | ||||||
|        uMVPMatrixLocation_(GL_INVALID_INDEX), |        uMVPMatrixLocation_(GL_INVALID_INDEX), | ||||||
|        vbo_ {GL_INVALID_INDEX}, |        vbo_ {GL_INVALID_INDEX}, | ||||||
|        vao_ {GL_INVALID_INDEX}, |        vao_ {GL_INVALID_INDEX}, | ||||||
|  | @ -32,9 +28,6 @@ public: | ||||||
|    } |    } | ||||||
|    ~ColorTableLayerImpl() = default; |    ~ColorTableLayerImpl() = default; | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; |  | ||||||
|    gl::OpenGLFunctions&                    gl_; |  | ||||||
| 
 |  | ||||||
|    gl::ShaderProgram     shaderProgram_; |    gl::ShaderProgram     shaderProgram_; | ||||||
|    GLint                 uMVPMatrixLocation_; |    GLint                 uMVPMatrixLocation_; | ||||||
|    std::array<GLuint, 2> vbo_; |    std::array<GLuint, 2> vbo_; | ||||||
|  | @ -46,19 +39,17 @@ public: | ||||||
|    bool colorTableNeedsUpdate_; |    bool colorTableNeedsUpdate_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| ColorTableLayer::ColorTableLayer( | ColorTableLayer::ColorTableLayer(std::shared_ptr<MapContext> context) : | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView, |     GenericLayer(context), p(std::make_unique<ColorTableLayerImpl>(context)) | ||||||
|    gl::OpenGLFunctions&                    gl) : |  | ||||||
|     p(std::make_unique<ColorTableLayerImpl>(radarProductView, gl)) |  | ||||||
| { | { | ||||||
| } | } | ||||||
| ColorTableLayer::~ColorTableLayer() = default; | ColorTableLayer::~ColorTableLayer() = default; | ||||||
| 
 | 
 | ||||||
| void ColorTableLayer::Initialize() | void ColorTableLayer::Initialize() | ||||||
| { | { | ||||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; |    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||||
| 
 | 
 | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    // Load and configure overlay shader
 |    // Load and configure overlay shader
 | ||||||
|    p->shaderProgram_.Load(":/gl/texture1d.vert", ":/gl/texture1d.frag"); |    p->shaderProgram_.Load(":/gl/texture1d.vert", ":/gl/texture1d.frag"); | ||||||
|  | @ -105,7 +96,7 @@ void ColorTableLayer::Initialize() | ||||||
|    gl.glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, static_cast<void*>(0)); |    gl.glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, 0, static_cast<void*>(0)); | ||||||
|    gl.glEnableVertexAttribArray(1); |    gl.glEnableVertexAttribArray(1); | ||||||
| 
 | 
 | ||||||
|    connect(p->radarProductView_.get(), |    connect(context()->radarProductView_.get(), | ||||||
|            &view::RadarProductView::ColorTableUpdated, |            &view::RadarProductView::ColorTableUpdated, | ||||||
|            this, |            this, | ||||||
|            [=]() { p->colorTableNeedsUpdate_ = true; }); |            [=]() { p->colorTableNeedsUpdate_ = true; }); | ||||||
|  | @ -113,7 +104,7 @@ void ColorTableLayer::Initialize() | ||||||
| 
 | 
 | ||||||
| void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
| { | { | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    glm::mat4 projection = glm::ortho(0.0f, |    glm::mat4 projection = glm::ortho(0.0f, | ||||||
|                                      static_cast<float>(params.width), |                                      static_cast<float>(params.width), | ||||||
|  | @ -127,7 +118,7 @@ void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
| 
 | 
 | ||||||
|    if (p->colorTableNeedsUpdate_) |    if (p->colorTableNeedsUpdate_) | ||||||
|    { |    { | ||||||
|       p->colorTable_ = p->radarProductView_->color_table(); |       p->colorTable_ = context()->radarProductView_->color_table(); | ||||||
| 
 | 
 | ||||||
|       gl.glActiveTexture(GL_TEXTURE0); |       gl.glActiveTexture(GL_TEXTURE0); | ||||||
|       gl.glBindTexture(GL_TEXTURE_1D, p->texture_); |       gl.glBindTexture(GL_TEXTURE_1D, p->texture_); | ||||||
|  | @ -144,7 +135,8 @@ void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
|       gl.glGenerateMipmap(GL_TEXTURE_1D); |       gl.glGenerateMipmap(GL_TEXTURE_1D); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    if (p->colorTable_.size() > 0 && p->radarProductView_->sweep_time() != |    if (p->colorTable_.size() > 0 && | ||||||
|  |        context()->radarProductView_->sweep_time() != | ||||||
|           std::chrono::system_clock::time_point()) |           std::chrono::system_clock::time_point()) | ||||||
|    { |    { | ||||||
|       // Color table panel vertices
 |       // Color table panel vertices
 | ||||||
|  | @ -172,9 +164,9 @@ void ColorTableLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
| 
 | 
 | ||||||
| void ColorTableLayer::Deinitialize() | void ColorTableLayer::Deinitialize() | ||||||
| { | { | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Deinitialize()"; | ||||||
| 
 | 
 | ||||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "deinitialize()"; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    gl.glDeleteVertexArrays(1, &p->vao_); |    gl.glDeleteVertexArrays(1, &p->vao_); | ||||||
|    gl.glDeleteBuffers(2, p->vbo_.data()); |    gl.glDeleteBuffers(2, p->vbo_.data()); | ||||||
|  |  | ||||||
|  | @ -1,8 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <scwx/qt/gl/gl.hpp> |  | ||||||
| #include <scwx/qt/map/generic_layer.hpp> | #include <scwx/qt/map/generic_layer.hpp> | ||||||
| #include <scwx/qt/view/radar_product_view.hpp> |  | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -16,9 +14,7 @@ class ColorTableLayerImpl; | ||||||
| class ColorTableLayer : public GenericLayer | class ColorTableLayer : public GenericLayer | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit ColorTableLayer( |    explicit ColorTableLayer(std::shared_ptr<MapContext> context); | ||||||
|       std::shared_ptr<view::RadarProductView> radarProductView, |  | ||||||
|       gl::OpenGLFunctions&                    gl); |  | ||||||
|    ~ColorTableLayer(); |    ~ColorTableLayer(); | ||||||
| 
 | 
 | ||||||
|    void Initialize() override final; |    void Initialize() override final; | ||||||
|  |  | ||||||
|  | @ -10,14 +10,27 @@ namespace map | ||||||
| class GenericLayerImpl | class GenericLayerImpl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit GenericLayerImpl() {} |    explicit GenericLayerImpl(std::shared_ptr<MapContext> context) : | ||||||
|  |        context_ {context} | ||||||
|  |    { | ||||||
|  |    } | ||||||
| 
 | 
 | ||||||
|    ~GenericLayerImpl() {} |    ~GenericLayerImpl() {} | ||||||
|  | 
 | ||||||
|  |    std::shared_ptr<MapContext> context_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| GenericLayer::GenericLayer() : p(std::make_unique<GenericLayerImpl>()) {} | GenericLayer::GenericLayer(std::shared_ptr<MapContext> context) : | ||||||
|  |     p(std::make_unique<GenericLayerImpl>(context)) | ||||||
|  | { | ||||||
|  | } | ||||||
| GenericLayer::~GenericLayer() = default; | GenericLayer::~GenericLayer() = default; | ||||||
| 
 | 
 | ||||||
|  | std::shared_ptr<MapContext> GenericLayer::context() const | ||||||
|  | { | ||||||
|  |    return p->context_; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace map
 | } // namespace map
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -1,5 +1,7 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
|  | #include <scwx/qt/map/map_context.hpp> | ||||||
|  | 
 | ||||||
| #include <memory> | #include <memory> | ||||||
| 
 | 
 | ||||||
| #include <QObject> | #include <QObject> | ||||||
|  | @ -19,13 +21,16 @@ class GenericLayer : public QObject | ||||||
|    Q_OBJECT |    Q_OBJECT | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
|    explicit GenericLayer(); |    explicit GenericLayer(std::shared_ptr<MapContext> context); | ||||||
|    virtual ~GenericLayer(); |    virtual ~GenericLayer(); | ||||||
| 
 | 
 | ||||||
|    virtual void Initialize()                                        = 0; |    virtual void Initialize()                                        = 0; | ||||||
|    virtual void Render(const QMapbox::CustomLayerRenderParameters&) = 0; |    virtual void Render(const QMapbox::CustomLayerRenderParameters&) = 0; | ||||||
|    virtual void Deinitialize()                                      = 0; |    virtual void Deinitialize()                                      = 0; | ||||||
| 
 | 
 | ||||||
|  | protected: | ||||||
|  |    std::shared_ptr<MapContext> context() const; | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
|    std::unique_ptr<GenericLayerImpl> p; |    std::unique_ptr<GenericLayerImpl> p; | ||||||
| }; | }; | ||||||
|  |  | ||||||
							
								
								
									
										34
									
								
								scwx-qt/source/scwx/qt/map/map_context.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								scwx-qt/source/scwx/qt/map/map_context.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,34 @@ | ||||||
|  | #pragma once | ||||||
|  | 
 | ||||||
|  | #include <scwx/qt/gl/gl.hpp> | ||||||
|  | #include <scwx/qt/view/radar_product_view.hpp> | ||||||
|  | 
 | ||||||
|  | namespace scwx | ||||||
|  | { | ||||||
|  | namespace qt | ||||||
|  | { | ||||||
|  | namespace map | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | struct MapContext | ||||||
|  | { | ||||||
|  |    explicit MapContext( | ||||||
|  |       std::shared_ptr<view::RadarProductView> radarProductView = nullptr) : | ||||||
|  |        gl_ {}, radarProductView_ {radarProductView} | ||||||
|  |    { | ||||||
|  |    } | ||||||
|  |    ~MapContext() = default; | ||||||
|  | 
 | ||||||
|  |    MapContext(const MapContext&) = delete; | ||||||
|  |    MapContext& operator=(const MapContext&) = delete; | ||||||
|  | 
 | ||||||
|  |    MapContext(MapContext&&) noexcept = default; | ||||||
|  |    MapContext& operator=(MapContext&&) noexcept = default; | ||||||
|  | 
 | ||||||
|  |    gl::OpenGLFunctions                     gl_; | ||||||
|  |    std::shared_ptr<view::RadarProductView> radarProductView_; | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } // namespace map
 | ||||||
|  | } // namespace qt
 | ||||||
|  | } // namespace scwx
 | ||||||
|  | @ -50,13 +50,12 @@ class MapWidgetImpl : public QObject | ||||||
| public: | public: | ||||||
|    explicit MapWidgetImpl(MapWidget*               widget, |    explicit MapWidgetImpl(MapWidget*               widget, | ||||||
|                           const QMapboxGLSettings& settings) : |                           const QMapboxGLSettings& settings) : | ||||||
|        gl_(), |        context_ {std::make_shared<MapContext>()}, | ||||||
|        widget_ {widget}, |        widget_ {widget}, | ||||||
|        settings_(settings), |        settings_(settings), | ||||||
|        map_(), |        map_(), | ||||||
|        radarProductManager_ {manager::RadarProductManager::Instance("KLSX")}, |        radarProductManager_ {manager::RadarProductManager::Instance("KLSX")}, | ||||||
|        radarProductLayer_ {nullptr}, |        radarProductLayer_ {nullptr}, | ||||||
|        radarProductView_ {nullptr}, |  | ||||||
|        overlayLayer_ {nullptr}, |        overlayLayer_ {nullptr}, | ||||||
|        colorTableLayer_ {nullptr}, |        colorTableLayer_ {nullptr}, | ||||||
|        isActive_ {false}, |        isActive_ {false}, | ||||||
|  | @ -74,7 +73,7 @@ public: | ||||||
| 
 | 
 | ||||||
|    bool UpdateStoredMapParameters(); |    bool UpdateStoredMapParameters(); | ||||||
| 
 | 
 | ||||||
|    gl::OpenGLFunctions gl_; |    std::shared_ptr<MapContext> context_; | ||||||
| 
 | 
 | ||||||
|    MapWidget*                 widget_; |    MapWidget*                 widget_; | ||||||
|    QMapboxGLSettings          settings_; |    QMapboxGLSettings          settings_; | ||||||
|  | @ -83,7 +82,6 @@ public: | ||||||
|    std::shared_ptr<manager::RadarProductManager> radarProductManager_; |    std::shared_ptr<manager::RadarProductManager> radarProductManager_; | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<common::ColorTable> colorTable_; |    std::shared_ptr<common::ColorTable> colorTable_; | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; |  | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<RadarProductLayer> radarProductLayer_; |    std::shared_ptr<RadarProductLayer> radarProductLayer_; | ||||||
|    std::shared_ptr<OverlayLayer>      overlayLayer_; |    std::shared_ptr<OverlayLayer>      overlayLayer_; | ||||||
|  | @ -120,50 +118,53 @@ MapWidget::~MapWidget() | ||||||
| 
 | 
 | ||||||
| float MapWidget::GetElevation() const | float MapWidget::GetElevation() const | ||||||
| { | { | ||||||
|    return p->radarProductView_->elevation(); |    return p->context_->radarProductView_->elevation(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<float> MapWidget::GetElevationCuts() const | std::vector<float> MapWidget::GetElevationCuts() const | ||||||
| { | { | ||||||
|    return p->radarProductView_->GetElevationCuts(); |    return p->context_->radarProductView_->GetElevationCuts(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MapWidget::SelectElevation(float elevation) | void MapWidget::SelectElevation(float elevation) | ||||||
| { | { | ||||||
|    p->radarProductView_->SelectElevation(elevation); |    p->context_->radarProductView_->SelectElevation(elevation); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MapWidget::SelectRadarProduct(common::Level2Product product) | void MapWidget::SelectRadarProduct(common::Level2Product product) | ||||||
| { | { | ||||||
|    float currentElevation = 0.0f; |    float currentElevation = 0.0f; | ||||||
| 
 | 
 | ||||||
|    if (p->radarProductView_ != nullptr) |    std::shared_ptr<view::RadarProductView>& radarProductView = | ||||||
|  |       p->context_->radarProductView_; | ||||||
|  | 
 | ||||||
|  |    if (p->context_->radarProductView_ != nullptr) | ||||||
|    { |    { | ||||||
|       currentElevation = p->radarProductView_->elevation(); |       currentElevation = p->context_->radarProductView_->elevation(); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    p->radarProductView_ = view::RadarProductViewFactory::Create( |    radarProductView = view::RadarProductViewFactory::Create( | ||||||
|       product, currentElevation, p->radarProductManager_); |       product, currentElevation, p->radarProductManager_); | ||||||
|    p->radarProductView_->SetActive(p->isActive_); |    radarProductView->SetActive(p->isActive_); | ||||||
| 
 | 
 | ||||||
|    connect( |    connect( | ||||||
|       p->radarProductView_.get(), |       radarProductView.get(), | ||||||
|       &view::RadarProductView::ColorTableUpdated, |       &view::RadarProductView::ColorTableUpdated, | ||||||
|       this, |       this, | ||||||
|       [&]() { update(); }, |       [&]() { update(); }, | ||||||
|       Qt::QueuedConnection); |       Qt::QueuedConnection); | ||||||
|    connect( |    connect( | ||||||
|       p->radarProductView_.get(), |       radarProductView.get(), | ||||||
|       &view::RadarProductView::SweepComputed, |       &view::RadarProductView::SweepComputed, | ||||||
|       this, |       this, | ||||||
|       [&]() { |       [&]() { | ||||||
|          RadarRangeLayer::Update(p->map_, p->radarProductView_->range()); |          RadarRangeLayer::Update(p->map_, radarProductView->range()); | ||||||
|          update(); |          update(); | ||||||
|          emit RadarSweepUpdated(); |          emit RadarSweepUpdated(); | ||||||
|       }, |       }, | ||||||
|       Qt::QueuedConnection); |       Qt::QueuedConnection); | ||||||
| 
 | 
 | ||||||
|    p->radarProductView_->Initialize(); |    radarProductView->Initialize(); | ||||||
| 
 | 
 | ||||||
|    std::string colorTableFile = |    std::string colorTableFile = | ||||||
|       manager::SettingsManager::palette_settings()->palette( |       manager::SettingsManager::palette_settings()->palette( | ||||||
|  | @ -172,7 +173,7 @@ void MapWidget::SelectRadarProduct(common::Level2Product product) | ||||||
|    { |    { | ||||||
|       std::shared_ptr<common::ColorTable> colorTable = |       std::shared_ptr<common::ColorTable> colorTable = | ||||||
|          common::ColorTable::Load(colorTableFile); |          common::ColorTable::Load(colorTableFile); | ||||||
|       p->radarProductView_->LoadColorTable(colorTable); |       radarProductView->LoadColorTable(colorTable); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    if (p->map_ != nullptr) |    if (p->map_ != nullptr) | ||||||
|  | @ -185,9 +186,9 @@ void MapWidget::SetActive(bool isActive) | ||||||
| { | { | ||||||
|    p->isActive_ = isActive; |    p->isActive_ = isActive; | ||||||
| 
 | 
 | ||||||
|    if (p->radarProductView_ != nullptr) |    if (p->context_->radarProductView_ != nullptr) | ||||||
|    { |    { | ||||||
|       p->radarProductView_->SetActive(isActive); |       p->context_->radarProductView_->SetActive(isActive); | ||||||
|       update(); |       update(); | ||||||
|    } |    } | ||||||
| } | } | ||||||
|  | @ -221,7 +222,7 @@ void MapWidget::changeStyle() | ||||||
| 
 | 
 | ||||||
| void MapWidget::AddLayers() | void MapWidget::AddLayers() | ||||||
| { | { | ||||||
|    if (p->radarProductView_ == nullptr) |    if (p->context_->radarProductView_ == nullptr) | ||||||
|    { |    { | ||||||
|       return; |       return; | ||||||
|    } |    } | ||||||
|  | @ -240,12 +241,9 @@ void MapWidget::AddLayers() | ||||||
|       p->map_->removeLayer("colorTable"); |       p->map_->removeLayer("colorTable"); | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    p->radarProductLayer_ = |    p->radarProductLayer_ = std::make_shared<RadarProductLayer>(p->context_); | ||||||
|       std::make_shared<RadarProductLayer>(p->radarProductView_, p->gl_); |    p->overlayLayer_      = std::make_shared<OverlayLayer>(p->context_); | ||||||
|    p->overlayLayer_ = |    p->colorTableLayer_   = std::make_shared<ColorTableLayer>(p->context_); | ||||||
|       std::make_shared<OverlayLayer>(p->radarProductView_, p->gl_); |  | ||||||
|    p->colorTableLayer_ = |  | ||||||
|       std::make_shared<ColorTableLayer>(p->radarProductView_, p->gl_); |  | ||||||
| 
 | 
 | ||||||
|    // QMapboxGL::addCustomLayer will take ownership of the QScopedPointer
 |    // QMapboxGL::addCustomLayer will take ownership of the QScopedPointer
 | ||||||
|    QScopedPointer<QMapbox::CustomLayerHostInterface> pHost( |    QScopedPointer<QMapbox::CustomLayerHostInterface> pHost( | ||||||
|  | @ -269,7 +267,8 @@ void MapWidget::AddLayers() | ||||||
|    } |    } | ||||||
| 
 | 
 | ||||||
|    p->map_->addCustomLayer("radar", pHost, before); |    p->map_->addCustomLayer("radar", pHost, before); | ||||||
|    RadarRangeLayer::Add(p->map_, p->radarProductView_->range(), before); |    RadarRangeLayer::Add( | ||||||
|  |       p->map_, p->context_->radarProductView_->range(), before); | ||||||
|    p->map_->addCustomLayer("overlay", pOverlayHost); |    p->map_->addCustomLayer("overlay", pOverlayHost); | ||||||
|    p->map_->addCustomLayer("colorTable", pColorTableHost); |    p->map_->addCustomLayer("colorTable", pColorTableHost); | ||||||
| } | } | ||||||
|  | @ -366,7 +365,7 @@ void MapWidget::wheelEvent(QWheelEvent* ev) | ||||||
| void MapWidget::initializeGL() | void MapWidget::initializeGL() | ||||||
| { | { | ||||||
|    makeCurrent(); |    makeCurrent(); | ||||||
|    p->gl_.initializeOpenGLFunctions(); |    p->context_->gl_.initializeOpenGLFunctions(); | ||||||
| 
 | 
 | ||||||
|    p->map_.reset(new QMapboxGL(nullptr, p->settings_, size(), pixelRatio())); |    p->map_.reset(new QMapboxGL(nullptr, p->settings_, size(), pixelRatio())); | ||||||
|    connect(p->map_.get(), |    connect(p->map_.get(), | ||||||
|  |  | ||||||
|  | @ -28,14 +28,10 @@ static const std::string logPrefix_ = "[scwx::qt::map::overlay_layer] "; | ||||||
| class OverlayLayerImpl | class OverlayLayerImpl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit OverlayLayerImpl( |    explicit OverlayLayerImpl(std::shared_ptr<MapContext> context) : | ||||||
|       std::shared_ptr<view::RadarProductView> radarProductView, |        textShader_(context->gl_), | ||||||
|       gl::OpenGLFunctions&                    gl) : |  | ||||||
|        radarProductView_(radarProductView), |  | ||||||
|        gl_(gl), |  | ||||||
|        textShader_(gl), |  | ||||||
|        font_(util::Font::Create(":/res/fonts/din1451alt.ttf")), |        font_(util::Font::Create(":/res/fonts/din1451alt.ttf")), | ||||||
|        shaderProgram_(gl), |        shaderProgram_(context->gl_), | ||||||
|        uMVPMatrixLocation_(GL_INVALID_INDEX), |        uMVPMatrixLocation_(GL_INVALID_INDEX), | ||||||
|        uColorLocation_(GL_INVALID_INDEX), |        uColorLocation_(GL_INVALID_INDEX), | ||||||
|        vbo_ {GL_INVALID_INDEX}, |        vbo_ {GL_INVALID_INDEX}, | ||||||
|  | @ -48,9 +44,6 @@ public: | ||||||
|    } |    } | ||||||
|    ~OverlayLayerImpl() = default; |    ~OverlayLayerImpl() = default; | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; |  | ||||||
|    gl::OpenGLFunctions&                    gl_; |  | ||||||
| 
 |  | ||||||
|    gl::TextShader              textShader_; |    gl::TextShader              textShader_; | ||||||
|    std::shared_ptr<util::Font> font_; |    std::shared_ptr<util::Font> font_; | ||||||
|    gl::ShaderProgram           shaderProgram_; |    gl::ShaderProgram           shaderProgram_; | ||||||
|  | @ -64,19 +57,17 @@ public: | ||||||
|    bool        sweepTimeNeedsUpdate_; |    bool        sweepTimeNeedsUpdate_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| OverlayLayer::OverlayLayer( | OverlayLayer::OverlayLayer(std::shared_ptr<MapContext> context) : | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView, |     GenericLayer(context), p(std::make_unique<OverlayLayerImpl>(context)) | ||||||
|    gl::OpenGLFunctions&                    gl) : |  | ||||||
|     p(std::make_unique<OverlayLayerImpl>(radarProductView, gl)) |  | ||||||
| { | { | ||||||
| } | } | ||||||
| OverlayLayer::~OverlayLayer() = default; | OverlayLayer::~OverlayLayer() = default; | ||||||
| 
 | 
 | ||||||
| void OverlayLayer::Initialize() | void OverlayLayer::Initialize() | ||||||
| { | { | ||||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; |    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||||
| 
 | 
 | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    p->textShader_.Initialize(); |    p->textShader_.Initialize(); | ||||||
| 
 | 
 | ||||||
|  | @ -131,7 +122,7 @@ void OverlayLayer::Initialize() | ||||||
|    // Upper right panel color
 |    // Upper right panel color
 | ||||||
|    gl.glUniform4f(p->uColorLocation_, 0.0f, 0.0f, 0.0f, 0.75f); |    gl.glUniform4f(p->uColorLocation_, 0.0f, 0.0f, 0.0f, 0.75f); | ||||||
| 
 | 
 | ||||||
|    connect(p->radarProductView_.get(), |    connect(context()->radarProductView_.get(), | ||||||
|            &view::RadarProductView::SweepComputed, |            &view::RadarProductView::SweepComputed, | ||||||
|            this, |            this, | ||||||
|            &OverlayLayer::UpdateSweepTimeNextFrame); |            &OverlayLayer::UpdateSweepTimeNextFrame); | ||||||
|  | @ -139,13 +130,13 @@ void OverlayLayer::Initialize() | ||||||
| 
 | 
 | ||||||
| void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
| { | { | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    if (p->sweepTimeNeedsUpdate_) |    if (p->sweepTimeNeedsUpdate_) | ||||||
|    { |    { | ||||||
|       using namespace std::chrono; |       using namespace std::chrono; | ||||||
|       auto sweepTime = |       auto sweepTime = | ||||||
|          time_point_cast<seconds>(p->radarProductView_->sweep_time()); |          time_point_cast<seconds>(context()->radarProductView_->sweep_time()); | ||||||
| 
 | 
 | ||||||
|       if (sweepTime.time_since_epoch().count() != 0) |       if (sweepTime.time_since_epoch().count() != 0) | ||||||
|       { |       { | ||||||
|  | @ -168,7 +159,7 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
|    gl.glUniformMatrix4fv( |    gl.glUniformMatrix4fv( | ||||||
|       p->uMVPMatrixLocation_, 1, GL_FALSE, glm::value_ptr(projection)); |       p->uMVPMatrixLocation_, 1, GL_FALSE, glm::value_ptr(projection)); | ||||||
| 
 | 
 | ||||||
|    if (p->radarProductView_->IsActive()) |    if (context()->radarProductView_->IsActive()) | ||||||
|    { |    { | ||||||
|       const float vertexLX       = 1.0f; |       const float vertexLX       = 1.0f; | ||||||
|       const float vertexRX       = static_cast<float>(params.width) - 1.0f; |       const float vertexRX       = static_cast<float>(params.width) - 1.0f; | ||||||
|  | @ -220,8 +211,7 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
|       // Render time
 |       // Render time
 | ||||||
|       p->textShader_.RenderText(p->sweepTimeString_, |       p->textShader_.RenderText(p->sweepTimeString_, | ||||||
|                                 params.width - 7.0f, |                                 params.width - 7.0f, | ||||||
|                                 static_cast<float>(params.height) - |                                 static_cast<float>(params.height) - 16.0f, | ||||||
|                                    16.0f, // 7.0f,
 |  | ||||||
|                                 fontSize, |                                 fontSize, | ||||||
|                                 projection, |                                 projection, | ||||||
|                                 boost::gil::rgba8_pixel_t(255, 255, 255, 204), |                                 boost::gil::rgba8_pixel_t(255, 255, 255, 204), | ||||||
|  | @ -235,9 +225,9 @@ void OverlayLayer::Render(const QMapbox::CustomLayerRenderParameters& params) | ||||||
| 
 | 
 | ||||||
| void OverlayLayer::Deinitialize() | void OverlayLayer::Deinitialize() | ||||||
| { | { | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Deinitialize()"; | ||||||
| 
 | 
 | ||||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "deinitialize()"; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    gl.glDeleteVertexArrays(1, &p->vao_); |    gl.glDeleteVertexArrays(1, &p->vao_); | ||||||
|    gl.glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); |    gl.glDeleteBuffers(static_cast<GLsizei>(p->vbo_.size()), p->vbo_.data()); | ||||||
|  | @ -249,7 +239,7 @@ void OverlayLayer::Deinitialize() | ||||||
|    p->vbo_                = {GL_INVALID_INDEX}; |    p->vbo_                = {GL_INVALID_INDEX}; | ||||||
|    p->texture_            = GL_INVALID_INDEX; |    p->texture_            = GL_INVALID_INDEX; | ||||||
| 
 | 
 | ||||||
|    disconnect(p->radarProductView_.get(), |    disconnect(context()->radarProductView_.get(), | ||||||
|               &view::RadarProductView::SweepComputed, |               &view::RadarProductView::SweepComputed, | ||||||
|               this, |               this, | ||||||
|               &OverlayLayer::UpdateSweepTimeNextFrame); |               &OverlayLayer::UpdateSweepTimeNextFrame); | ||||||
|  |  | ||||||
|  | @ -1,8 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <scwx/qt/gl/gl.hpp> |  | ||||||
| #include <scwx/qt/map/generic_layer.hpp> | #include <scwx/qt/map/generic_layer.hpp> | ||||||
| #include <scwx/qt/view/radar_product_view.hpp> |  | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -16,9 +14,7 @@ class OverlayLayerImpl; | ||||||
| class OverlayLayer : public GenericLayer | class OverlayLayer : public GenericLayer | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit OverlayLayer( |    explicit OverlayLayer(std::shared_ptr<MapContext> context); | ||||||
|       std::shared_ptr<view::RadarProductView> radarProductView, |  | ||||||
|       gl::OpenGLFunctions&                    gl); |  | ||||||
|    ~OverlayLayer(); |    ~OverlayLayer(); | ||||||
| 
 | 
 | ||||||
|    void Initialize() override final; |    void Initialize() override final; | ||||||
|  |  | ||||||
|  | @ -29,12 +29,8 @@ LatLongToScreenCoordinate(const QMapbox::Coordinate& coordinate); | ||||||
| class RadarProductLayerImpl | class RadarProductLayerImpl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit RadarProductLayerImpl( |    explicit RadarProductLayerImpl(std::shared_ptr<MapContext> context) : | ||||||
|       std::shared_ptr<view::RadarProductView> radarProductView, |        shaderProgram_(context->gl_), | ||||||
|       gl::OpenGLFunctions&                    gl) : |  | ||||||
|        radarProductView_(radarProductView), |  | ||||||
|        gl_(gl), |  | ||||||
|        shaderProgram_(gl), |  | ||||||
|        uMVPMatrixLocation_(GL_INVALID_INDEX), |        uMVPMatrixLocation_(GL_INVALID_INDEX), | ||||||
|        uMapScreenCoordLocation_(GL_INVALID_INDEX), |        uMapScreenCoordLocation_(GL_INVALID_INDEX), | ||||||
|        uDataMomentOffsetLocation_(GL_INVALID_INDEX), |        uDataMomentOffsetLocation_(GL_INVALID_INDEX), | ||||||
|  | @ -51,9 +47,6 @@ public: | ||||||
|    } |    } | ||||||
|    ~RadarProductLayerImpl() = default; |    ~RadarProductLayerImpl() = default; | ||||||
| 
 | 
 | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView_; |  | ||||||
|    gl::OpenGLFunctions&                    gl_; |  | ||||||
| 
 |  | ||||||
|    gl::ShaderProgram     shaderProgram_; |    gl::ShaderProgram     shaderProgram_; | ||||||
|    GLint                 uMVPMatrixLocation_; |    GLint                 uMVPMatrixLocation_; | ||||||
|    GLint                 uMapScreenCoordLocation_; |    GLint                 uMapScreenCoordLocation_; | ||||||
|  | @ -72,19 +65,17 @@ public: | ||||||
|    bool sweepNeedsUpdate_; |    bool sweepNeedsUpdate_; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| RadarProductLayer::RadarProductLayer( | RadarProductLayer::RadarProductLayer(std::shared_ptr<MapContext> context) : | ||||||
|    std::shared_ptr<view::RadarProductView> radarProductView, |     GenericLayer(context), p(std::make_unique<RadarProductLayerImpl>(context)) | ||||||
|    gl::OpenGLFunctions&                    gl) : |  | ||||||
|     p(std::make_unique<RadarProductLayerImpl>(radarProductView, gl)) |  | ||||||
| { | { | ||||||
| } | } | ||||||
| RadarProductLayer::~RadarProductLayer() = default; | RadarProductLayer::~RadarProductLayer() = default; | ||||||
| 
 | 
 | ||||||
| void RadarProductLayer::Initialize() | void RadarProductLayer::Initialize() | ||||||
| { | { | ||||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; |    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||||
| 
 | 
 | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    // Load and configure radar shader
 |    // Load and configure radar shader
 | ||||||
|    p->shaderProgram_.Load(":/gl/radar.vert", ":/gl/radar.frag"); |    p->shaderProgram_.Load(":/gl/radar.vert", ":/gl/radar.frag"); | ||||||
|  | @ -143,11 +134,11 @@ void RadarProductLayer::Initialize() | ||||||
|    UpdateColorTable(); |    UpdateColorTable(); | ||||||
|    gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |    gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); | ||||||
| 
 | 
 | ||||||
|    connect(p->radarProductView_.get(), |    connect(context()->radarProductView_.get(), | ||||||
|            &view::RadarProductView::ColorTableUpdated, |            &view::RadarProductView::ColorTableUpdated, | ||||||
|            this, |            this, | ||||||
|            [=]() { p->colorTableNeedsUpdate_ = true; }); |            [=]() { p->colorTableNeedsUpdate_ = true; }); | ||||||
|    connect(p->radarProductView_.get(), |    connect(context()->radarProductView_.get(), | ||||||
|            &view::RadarProductView::SweepComputed, |            &view::RadarProductView::SweepComputed, | ||||||
|            this, |            this, | ||||||
|            [=]() { p->sweepNeedsUpdate_ = true; }); |            [=]() { p->sweepNeedsUpdate_ = true; }); | ||||||
|  | @ -159,11 +150,12 @@ void RadarProductLayer::UpdateSweep() | ||||||
| 
 | 
 | ||||||
|    p->sweepNeedsUpdate_ = false; |    p->sweepNeedsUpdate_ = false; | ||||||
| 
 | 
 | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    boost::timer::cpu_timer timer; |    boost::timer::cpu_timer timer; | ||||||
| 
 | 
 | ||||||
|    const std::vector<float>& vertices = p->radarProductView_->vertices(); |    const std::vector<float>& vertices = | ||||||
|  |       context()->radarProductView_->vertices(); | ||||||
| 
 | 
 | ||||||
|    // Bind a vertex array object
 |    // Bind a vertex array object
 | ||||||
|    gl.glBindVertexArray(p->vao_); |    gl.glBindVertexArray(p->vao_); | ||||||
|  | @ -192,7 +184,7 @@ void RadarProductLayer::UpdateSweep() | ||||||
|    GLenum        type; |    GLenum        type; | ||||||
| 
 | 
 | ||||||
|    std::tie(data, dataSize, componentSize) = |    std::tie(data, dataSize, componentSize) = | ||||||
|       p->radarProductView_->GetMomentData(); |       context()->radarProductView_->GetMomentData(); | ||||||
| 
 | 
 | ||||||
|    if (componentSize == 1) |    if (componentSize == 1) | ||||||
|    { |    { | ||||||
|  | @ -220,7 +212,7 @@ void RadarProductLayer::UpdateSweep() | ||||||
|    GLenum        cfpType; |    GLenum        cfpType; | ||||||
| 
 | 
 | ||||||
|    std::tie(cfpData, cfpDataSize, cfpComponentSize) = |    std::tie(cfpData, cfpDataSize, cfpComponentSize) = | ||||||
|       p->radarProductView_->GetCfpMomentData(); |       context()->radarProductView_->GetCfpMomentData(); | ||||||
| 
 | 
 | ||||||
|    if (cfpData != nullptr) |    if (cfpData != nullptr) | ||||||
|    { |    { | ||||||
|  | @ -254,7 +246,7 @@ void RadarProductLayer::UpdateSweep() | ||||||
| void RadarProductLayer::Render( | void RadarProductLayer::Render( | ||||||
|    const QMapbox::CustomLayerRenderParameters& params) |    const QMapbox::CustomLayerRenderParameters& params) | ||||||
| { | { | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    p->shaderProgram_.Use(); |    p->shaderProgram_.Use(); | ||||||
| 
 | 
 | ||||||
|  | @ -297,9 +289,9 @@ void RadarProductLayer::Render( | ||||||
| 
 | 
 | ||||||
| void RadarProductLayer::Deinitialize() | void RadarProductLayer::Deinitialize() | ||||||
| { | { | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Deinitialize()"; | ||||||
| 
 | 
 | ||||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "deinitialize()"; |    gl::OpenGLFunctions& gl = context()->gl_; | ||||||
| 
 | 
 | ||||||
|    gl.glDeleteVertexArrays(1, &p->vao_); |    gl.glDeleteVertexArrays(1, &p->vao_); | ||||||
|    gl.glDeleteBuffers(3, p->vbo_.data()); |    gl.glDeleteBuffers(3, p->vbo_.data()); | ||||||
|  | @ -320,12 +312,14 @@ void RadarProductLayer::UpdateColorTable() | ||||||
| 
 | 
 | ||||||
|    p->colorTableNeedsUpdate_ = false; |    p->colorTableNeedsUpdate_ = false; | ||||||
| 
 | 
 | ||||||
|    gl::OpenGLFunctions& gl = p->gl_; |    gl::OpenGLFunctions&                    gl = context()->gl_; | ||||||
|  |    std::shared_ptr<view::RadarProductView> radarProductView = | ||||||
|  |       context()->radarProductView_; | ||||||
| 
 | 
 | ||||||
|    const std::vector<boost::gil::rgba8_pixel_t>& colorTable = |    const std::vector<boost::gil::rgba8_pixel_t>& colorTable = | ||||||
|       p->radarProductView_->color_table(); |       radarProductView->color_table(); | ||||||
|    const uint16_t rangeMin = p->radarProductView_->color_table_min(); |    const uint16_t rangeMin = radarProductView->color_table_min(); | ||||||
|    const uint16_t rangeMax = p->radarProductView_->color_table_max(); |    const uint16_t rangeMax = radarProductView->color_table_max(); | ||||||
| 
 | 
 | ||||||
|    const float scale = rangeMax - rangeMin; |    const float scale = rangeMax - rangeMin; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,8 +1,6 @@ | ||||||
| #pragma once | #pragma once | ||||||
| 
 | 
 | ||||||
| #include <scwx/qt/gl/gl.hpp> |  | ||||||
| #include <scwx/qt/map/generic_layer.hpp> | #include <scwx/qt/map/generic_layer.hpp> | ||||||
| #include <scwx/qt/view/radar_product_view.hpp> |  | ||||||
| 
 | 
 | ||||||
| namespace scwx | namespace scwx | ||||||
| { | { | ||||||
|  | @ -16,9 +14,7 @@ class RadarProductLayerImpl; | ||||||
| class RadarProductLayer : public GenericLayer | class RadarProductLayer : public GenericLayer | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit RadarProductLayer( |    explicit RadarProductLayer(std::shared_ptr<MapContext> context); | ||||||
|       std::shared_ptr<view::RadarProductView> radarProductView, |  | ||||||
|       gl::OpenGLFunctions&                    gl); |  | ||||||
|    ~RadarProductLayer(); |    ~RadarProductLayer(); | ||||||
| 
 | 
 | ||||||
|    void Initialize() override final; |    void Initialize() override final; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat