From 817a59f7419ed0576b8719db640a610f70defb96 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Fri, 30 Jul 2021 22:01:18 -0500 Subject: [PATCH] Connecting signals and slots for radar updates --- .../source/scwx/qt/manager/radar_manager.cpp | 5 +- .../source/scwx/qt/manager/radar_manager.hpp | 15 ++-- scwx-qt/source/scwx/qt/map/radar_layer.cpp | 87 ++++++++++++++++--- scwx-qt/source/scwx/qt/map/radar_layer.hpp | 18 ++-- scwx-qt/source/scwx/qt/view/radar_view.cpp | 56 +++++++----- scwx-qt/source/scwx/qt/view/radar_view.hpp | 17 ++-- 6 files changed, 137 insertions(+), 61 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/radar_manager.cpp b/scwx-qt/source/scwx/qt/manager/radar_manager.cpp index 0be6b87c..79fdabd5 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/radar_manager.cpp @@ -46,9 +46,6 @@ public: RadarManager::RadarManager() : p(std::make_unique()) {} RadarManager::~RadarManager() = default; -RadarManager::RadarManager(RadarManager&&) noexcept = default; -RadarManager& RadarManager::operator=(RadarManager&&) noexcept = default; - const std::vector& RadarManager::coordinates(common::RadialSize radialSize) const { @@ -177,6 +174,8 @@ void RadarManager::LoadLevel2Data(const std::string& filename) p->level2Data_.pop_front(); } p->level2Data_.push_back(ar2vFile); + + emit Level2DataLoaded(); } } // namespace manager diff --git a/scwx-qt/source/scwx/qt/manager/radar_manager.hpp b/scwx-qt/source/scwx/qt/manager/radar_manager.hpp index b5eab8bf..80c7a418 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/radar_manager.hpp @@ -6,6 +6,8 @@ #include #include +#include + namespace scwx { namespace qt @@ -15,18 +17,14 @@ namespace manager class RadarManagerImpl; -class RadarManager +class RadarManager : public QObject { + Q_OBJECT + public: explicit RadarManager(); ~RadarManager(); - RadarManager(const RadarManager&) = delete; - RadarManager& operator=(const RadarManager&) = delete; - - RadarManager(RadarManager&&) noexcept; - RadarManager& operator=(RadarManager&&) noexcept; - const std::vector& coordinates(common::RadialSize radialSize) const; // TODO: Improve this interface @@ -35,6 +33,9 @@ public: void Initialize(); void LoadLevel2Data(const std::string& filename); +signals: + void Level2DataLoaded(); + private: std::unique_ptr p; }; diff --git a/scwx-qt/source/scwx/qt/map/radar_layer.cpp b/scwx-qt/source/scwx/qt/map/radar_layer.cpp index aa273491..d8b6b098 100644 --- a/scwx-qt/source/scwx/qt/map/radar_layer.cpp +++ b/scwx-qt/source/scwx/qt/map/radar_layer.cpp @@ -37,7 +37,9 @@ public: vbo_ {GL_INVALID_INDEX}, vao_ {GL_INVALID_INDEX}, texture_ {GL_INVALID_INDEX}, - numVertices_ {0} + numVertices_ {0}, + colorTableUpdated_(false), + plotUpdated_(false) { } ~RadarLayerImpl() = default; @@ -53,6 +55,9 @@ public: GLuint texture_; GLsizeiptr numVertices_; + + bool colorTableUpdated_; + bool plotUpdated_; }; RadarLayer::RadarLayer(std::shared_ptr radarView, @@ -62,17 +67,12 @@ RadarLayer::RadarLayer(std::shared_ptr radarView, } RadarLayer::~RadarLayer() = default; -RadarLayer::RadarLayer(RadarLayer&&) noexcept = default; -RadarLayer& RadarLayer::operator=(RadarLayer&&) noexcept = default; - void RadarLayer::initialize() { BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; OpenGLFunctions& gl = p->gl_; - boost::timer::cpu_timer timer; - // Load and configure radar shader p->shaderProgram_.Load(":/gl/radar.vert", ":/gl/radar.frag"); @@ -91,12 +91,45 @@ void RadarLayer::initialize() << logPrefix_ << "Could not find uMapScreenCoord"; } + // Generate a vertex array object + gl.glGenVertexArrays(1, &p->vao_); + + // Generate vertex buffer objects + gl.glGenBuffers(2, p->vbo_.data()); + + // Update radar plot + UpdatePlot(); + + // Create color table + gl.glGenTextures(1, &p->texture_); + UpdateColorTable(); + gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + + connect(p->radarView_.get(), + &view::RadarView::ColorTableLoaded, + this, + &RadarLayer::ReceiveColorTableUpdate); + connect(p->radarView_.get(), + &view::RadarView::PlotUpdated, + this, + &RadarLayer::ReceivePlotUpdate); +} + +void RadarLayer::UpdatePlot() +{ + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "UpdatePlot()"; + + p->plotUpdated_ = false; + + OpenGLFunctions& gl = p->gl_; + + boost::timer::cpu_timer timer; + const std::vector& vertices = p->radarView_->vertices(); const std::vector& dataMoments8 = p->radarView_->data_moments8(); const std::vector& dataMoments16 = p->radarView_->data_moments16(); - // Generate and bind a vertex array object - gl.glGenVertexArrays(1, &p->vao_); + // Bind a vertex array object gl.glBindVertexArray(p->vao_); // Generate vertex buffer objects @@ -145,17 +178,22 @@ void RadarLayer::initialize() gl.glEnableVertexAttribArray(1); p->numVertices_ = vertices.size() / 2; - - // Create color table - gl.glGenTextures(1, &p->texture_); - UpdateColorTable(); - gl.glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); } void RadarLayer::render(const QMapbox::CustomLayerRenderParameters& params) { OpenGLFunctions& gl = p->gl_; + if (p->colorTableUpdated_) + { + UpdateColorTable(); + } + + if (p->plotUpdated_) + { + UpdatePlot(); + } + p->shaderProgram_.Use(); const float scale = p->radarView_->scale() * 2.0f * mbgl::util::tileSize / @@ -196,10 +234,23 @@ void RadarLayer::deinitialize() p->vao_ = GL_INVALID_INDEX; p->vbo_ = {GL_INVALID_INDEX}; p->texture_ = GL_INVALID_INDEX; + + disconnect(p->radarView_.get(), + &view::RadarView::ColorTableLoaded, + this, + &RadarLayer::ReceiveColorTableUpdate); + disconnect(p->radarView_.get(), + &view::RadarView::PlotUpdated, + this, + &RadarLayer::ReceivePlotUpdate); } void RadarLayer::UpdateColorTable() { + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "UpdateColorTable()"; + + p->colorTableUpdated_ = false; + OpenGLFunctions& gl = p->gl_; const std::vector& colorTable = @@ -218,6 +269,16 @@ void RadarLayer::UpdateColorTable() gl.glGenerateMipmap(GL_TEXTURE_1D); } +void RadarLayer::ReceiveColorTableUpdate() +{ + p->colorTableUpdated_ = true; +} + +void RadarLayer::ReceivePlotUpdate() +{ + p->plotUpdated_ = true; +} + static glm::vec2 LatLongToScreenCoordinate(const QMapbox::Coordinate& coordinate) { diff --git a/scwx-qt/source/scwx/qt/map/radar_layer.hpp b/scwx-qt/source/scwx/qt/map/radar_layer.hpp index 3a8e3088..ea2d32fe 100644 --- a/scwx-qt/source/scwx/qt/map/radar_layer.hpp +++ b/scwx-qt/source/scwx/qt/map/radar_layer.hpp @@ -12,23 +12,25 @@ namespace qt class RadarLayerImpl; -class RadarLayer : public QMapbox::CustomLayerHostInterface +class RadarLayer : public QObject, public QMapbox::CustomLayerHostInterface { + Q_OBJECT + public: - explicit RadarLayer(std::shared_ptr radarView, OpenGLFunctions& gl); + explicit RadarLayer(std::shared_ptr radarView, + OpenGLFunctions& gl); ~RadarLayer(); - RadarLayer(const RadarLayer&) = delete; - RadarLayer& operator=(const RadarLayer&) = delete; - - RadarLayer(RadarLayer&&) noexcept; - RadarLayer& operator=(RadarLayer&&) noexcept; - void initialize() override final; void render(const QMapbox::CustomLayerRenderParameters&) override final; void deinitialize() override final; void UpdateColorTable(); + void UpdatePlot(); + +public slots: + void ReceiveColorTableUpdate(); + void ReceivePlotUpdate(); private: std::unique_ptr p; diff --git a/scwx-qt/source/scwx/qt/view/radar_view.cpp b/scwx-qt/source/scwx/qt/view/radar_view.cpp index f441f51b..ac403f90 100644 --- a/scwx-qt/source/scwx/qt/view/radar_view.cpp +++ b/scwx-qt/source/scwx/qt/view/radar_view.cpp @@ -45,12 +45,13 @@ RadarView::RadarView(std::shared_ptr radarManager, std::shared_ptr map) : p(std::make_unique(radarManager, map)) { + connect(radarManager.get(), + &manager::RadarManager::Level2DataLoaded, + this, + &RadarView::UpdatePlot); } RadarView::~RadarView() = default; -RadarView::RadarView(RadarView&&) noexcept = default; -RadarView& RadarView::operator=(RadarView&&) noexcept = default; - double RadarView::bearing() const { return p->map_->bearing(); @@ -83,7 +84,34 @@ const std::vector& RadarView::color_table() const void RadarView::Initialize() { - BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; + UpdatePlot(); +} + +void RadarView::LoadColorTable(std::shared_ptr colorTable) +{ + // TODO: Make size, offset and scale dynamic + const float offset = 66.0f; + const float scale = 2.0f; + + std::vector& lut = p->colorTable_; + lut.resize(254); + + auto dataRange = boost::irange(2, 255); + + std::for_each(std::execution::par_unseq, + dataRange.begin(), + dataRange.end(), + [&](uint16_t i) { + float f = (i - offset) / scale; + lut[i - *dataRange.begin()] = colorTable->Color(f); + }); + + emit ColorTableLoaded(); +} + +void RadarView::UpdatePlot() +{ + BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "UpdatePlot()"; boost::timer::cpu_timer timer; @@ -307,26 +335,8 @@ void RadarView::Initialize() timer.stop(); BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Vertices calculated in " << timer.format(6, "%ws"); -} -void RadarView::LoadColorTable(std::shared_ptr colorTable) -{ - // TODO: Make size, offset and scale dynamic - const float offset = 66.0f; - const float scale = 2.0f; - - std::vector& lut = p->colorTable_; - lut.resize(254); - - auto dataRange = boost::irange(2, 255); - - std::for_each(std::execution::par_unseq, - dataRange.begin(), - dataRange.end(), - [&](uint16_t i) { - float f = (i - offset) / scale; - lut[i - *dataRange.begin()] = colorTable->Color(f); - }); + emit PlotUpdated(); } } // namespace view diff --git a/scwx-qt/source/scwx/qt/view/radar_view.hpp b/scwx-qt/source/scwx/qt/view/radar_view.hpp index 51b5b4ce..34c606a8 100644 --- a/scwx-qt/source/scwx/qt/view/radar_view.hpp +++ b/scwx-qt/source/scwx/qt/view/radar_view.hpp @@ -17,19 +17,15 @@ namespace view class RadarViewImpl; -class RadarView +class RadarView : public QObject { + Q_OBJECT + public: explicit RadarView(std::shared_ptr radarManager, std::shared_ptr map); ~RadarView(); - RadarView(const RadarView&) = delete; - RadarView& operator=(const RadarView&) = delete; - - RadarView(RadarView&&) noexcept; - RadarView& operator=(RadarView&&) noexcept; - double bearing() const; double scale() const; const std::vector& data_moments8() const; @@ -41,6 +37,13 @@ public: void Initialize(); void LoadColorTable(std::shared_ptr colorTable); +public slots: + void UpdatePlot(); + +signals: + void ColorTableLoaded(); + void PlotUpdated(); + private: std::unique_ptr p; };