Connecting signals and slots for radar updates

This commit is contained in:
Dan Paulat 2021-07-30 22:01:18 -05:00
parent c06230ed6c
commit 817a59f741
6 changed files with 137 additions and 61 deletions

View file

@ -46,9 +46,6 @@ public:
RadarManager::RadarManager() : p(std::make_unique<RadarManagerImpl>()) {} RadarManager::RadarManager() : p(std::make_unique<RadarManagerImpl>()) {}
RadarManager::~RadarManager() = default; RadarManager::~RadarManager() = default;
RadarManager::RadarManager(RadarManager&&) noexcept = default;
RadarManager& RadarManager::operator=(RadarManager&&) noexcept = default;
const std::vector<float>& const std::vector<float>&
RadarManager::coordinates(common::RadialSize radialSize) const RadarManager::coordinates(common::RadialSize radialSize) const
{ {
@ -177,6 +174,8 @@ void RadarManager::LoadLevel2Data(const std::string& filename)
p->level2Data_.pop_front(); p->level2Data_.pop_front();
} }
p->level2Data_.push_back(ar2vFile); p->level2Data_.push_back(ar2vFile);
emit Level2DataLoaded();
} }
} // namespace manager } // namespace manager

View file

@ -6,6 +6,8 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include <QObject>
namespace scwx namespace scwx
{ {
namespace qt namespace qt
@ -15,18 +17,14 @@ namespace manager
class RadarManagerImpl; class RadarManagerImpl;
class RadarManager class RadarManager : public QObject
{ {
Q_OBJECT
public: public:
explicit RadarManager(); explicit RadarManager();
~RadarManager(); ~RadarManager();
RadarManager(const RadarManager&) = delete;
RadarManager& operator=(const RadarManager&) = delete;
RadarManager(RadarManager&&) noexcept;
RadarManager& operator=(RadarManager&&) noexcept;
const std::vector<float>& coordinates(common::RadialSize radialSize) const; const std::vector<float>& coordinates(common::RadialSize radialSize) const;
// TODO: Improve this interface // TODO: Improve this interface
@ -35,6 +33,9 @@ public:
void Initialize(); void Initialize();
void LoadLevel2Data(const std::string& filename); void LoadLevel2Data(const std::string& filename);
signals:
void Level2DataLoaded();
private: private:
std::unique_ptr<RadarManagerImpl> p; std::unique_ptr<RadarManagerImpl> p;
}; };

View file

@ -37,7 +37,9 @@ public:
vbo_ {GL_INVALID_INDEX}, vbo_ {GL_INVALID_INDEX},
vao_ {GL_INVALID_INDEX}, vao_ {GL_INVALID_INDEX},
texture_ {GL_INVALID_INDEX}, texture_ {GL_INVALID_INDEX},
numVertices_ {0} numVertices_ {0},
colorTableUpdated_(false),
plotUpdated_(false)
{ {
} }
~RadarLayerImpl() = default; ~RadarLayerImpl() = default;
@ -53,6 +55,9 @@ public:
GLuint texture_; GLuint texture_;
GLsizeiptr numVertices_; GLsizeiptr numVertices_;
bool colorTableUpdated_;
bool plotUpdated_;
}; };
RadarLayer::RadarLayer(std::shared_ptr<view::RadarView> radarView, RadarLayer::RadarLayer(std::shared_ptr<view::RadarView> radarView,
@ -62,17 +67,12 @@ RadarLayer::RadarLayer(std::shared_ptr<view::RadarView> radarView,
} }
RadarLayer::~RadarLayer() = default; RadarLayer::~RadarLayer() = default;
RadarLayer::RadarLayer(RadarLayer&&) noexcept = default;
RadarLayer& RadarLayer::operator=(RadarLayer&&) noexcept = default;
void RadarLayer::initialize() void RadarLayer::initialize()
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()"; BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "initialize()";
OpenGLFunctions& gl = p->gl_; OpenGLFunctions& gl = p->gl_;
boost::timer::cpu_timer timer;
// 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");
@ -91,12 +91,45 @@ void RadarLayer::initialize()
<< logPrefix_ << "Could not find uMapScreenCoord"; << 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<float>& vertices = p->radarView_->vertices(); const std::vector<float>& vertices = p->radarView_->vertices();
const std::vector<uint8_t>& dataMoments8 = p->radarView_->data_moments8(); const std::vector<uint8_t>& dataMoments8 = p->radarView_->data_moments8();
const std::vector<uint16_t>& dataMoments16 = p->radarView_->data_moments16(); const std::vector<uint16_t>& dataMoments16 = p->radarView_->data_moments16();
// Generate and bind a vertex array object // Bind a vertex array object
gl.glGenVertexArrays(1, &p->vao_);
gl.glBindVertexArray(p->vao_); gl.glBindVertexArray(p->vao_);
// Generate vertex buffer objects // Generate vertex buffer objects
@ -145,17 +178,22 @@ void RadarLayer::initialize()
gl.glEnableVertexAttribArray(1); gl.glEnableVertexAttribArray(1);
p->numVertices_ = vertices.size() / 2; 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) void RadarLayer::render(const QMapbox::CustomLayerRenderParameters& params)
{ {
OpenGLFunctions& gl = p->gl_; OpenGLFunctions& gl = p->gl_;
if (p->colorTableUpdated_)
{
UpdateColorTable();
}
if (p->plotUpdated_)
{
UpdatePlot();
}
p->shaderProgram_.Use(); p->shaderProgram_.Use();
const float scale = p->radarView_->scale() * 2.0f * mbgl::util::tileSize / const float scale = p->radarView_->scale() * 2.0f * mbgl::util::tileSize /
@ -196,10 +234,23 @@ void RadarLayer::deinitialize()
p->vao_ = GL_INVALID_INDEX; p->vao_ = GL_INVALID_INDEX;
p->vbo_ = {GL_INVALID_INDEX}; p->vbo_ = {GL_INVALID_INDEX};
p->texture_ = 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() void RadarLayer::UpdateColorTable()
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "UpdateColorTable()";
p->colorTableUpdated_ = false;
OpenGLFunctions& gl = p->gl_; OpenGLFunctions& gl = p->gl_;
const std::vector<boost::gil::rgba8_pixel_t>& colorTable = const std::vector<boost::gil::rgba8_pixel_t>& colorTable =
@ -218,6 +269,16 @@ void RadarLayer::UpdateColorTable()
gl.glGenerateMipmap(GL_TEXTURE_1D); gl.glGenerateMipmap(GL_TEXTURE_1D);
} }
void RadarLayer::ReceiveColorTableUpdate()
{
p->colorTableUpdated_ = true;
}
void RadarLayer::ReceivePlotUpdate()
{
p->plotUpdated_ = true;
}
static glm::vec2 static glm::vec2
LatLongToScreenCoordinate(const QMapbox::Coordinate& coordinate) LatLongToScreenCoordinate(const QMapbox::Coordinate& coordinate)
{ {

View file

@ -12,23 +12,25 @@ namespace qt
class RadarLayerImpl; class RadarLayerImpl;
class RadarLayer : public QMapbox::CustomLayerHostInterface class RadarLayer : public QObject, public QMapbox::CustomLayerHostInterface
{ {
Q_OBJECT
public: public:
explicit RadarLayer(std::shared_ptr<view::RadarView> radarView, OpenGLFunctions& gl); explicit RadarLayer(std::shared_ptr<view::RadarView> radarView,
OpenGLFunctions& gl);
~RadarLayer(); ~RadarLayer();
RadarLayer(const RadarLayer&) = delete;
RadarLayer& operator=(const RadarLayer&) = delete;
RadarLayer(RadarLayer&&) noexcept;
RadarLayer& operator=(RadarLayer&&) noexcept;
void initialize() override final; void initialize() override final;
void render(const QMapbox::CustomLayerRenderParameters&) override final; void render(const QMapbox::CustomLayerRenderParameters&) override final;
void deinitialize() override final; void deinitialize() override final;
void UpdateColorTable(); void UpdateColorTable();
void UpdatePlot();
public slots:
void ReceiveColorTableUpdate();
void ReceivePlotUpdate();
private: private:
std::unique_ptr<RadarLayerImpl> p; std::unique_ptr<RadarLayerImpl> p;

View file

@ -45,12 +45,13 @@ RadarView::RadarView(std::shared_ptr<manager::RadarManager> radarManager,
std::shared_ptr<QMapboxGL> map) : std::shared_ptr<QMapboxGL> map) :
p(std::make_unique<RadarViewImpl>(radarManager, map)) p(std::make_unique<RadarViewImpl>(radarManager, map))
{ {
connect(radarManager.get(),
&manager::RadarManager::Level2DataLoaded,
this,
&RadarView::UpdatePlot);
} }
RadarView::~RadarView() = default; RadarView::~RadarView() = default;
RadarView::RadarView(RadarView&&) noexcept = default;
RadarView& RadarView::operator=(RadarView&&) noexcept = default;
double RadarView::bearing() const double RadarView::bearing() const
{ {
return p->map_->bearing(); return p->map_->bearing();
@ -83,7 +84,34 @@ const std::vector<boost::gil::rgba8_pixel_t>& RadarView::color_table() const
void RadarView::Initialize() void RadarView::Initialize()
{ {
BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; UpdatePlot();
}
void RadarView::LoadColorTable(std::shared_ptr<common::ColorTable> colorTable)
{
// TODO: Make size, offset and scale dynamic
const float offset = 66.0f;
const float scale = 2.0f;
std::vector<boost::gil::rgba8_pixel_t>& lut = p->colorTable_;
lut.resize(254);
auto dataRange = boost::irange<uint16_t>(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; boost::timer::cpu_timer timer;
@ -307,26 +335,8 @@ void RadarView::Initialize()
timer.stop(); timer.stop();
BOOST_LOG_TRIVIAL(debug) BOOST_LOG_TRIVIAL(debug)
<< logPrefix_ << "Vertices calculated in " << timer.format(6, "%ws"); << logPrefix_ << "Vertices calculated in " << timer.format(6, "%ws");
}
void RadarView::LoadColorTable(std::shared_ptr<common::ColorTable> colorTable) emit PlotUpdated();
{
// TODO: Make size, offset and scale dynamic
const float offset = 66.0f;
const float scale = 2.0f;
std::vector<boost::gil::rgba8_pixel_t>& lut = p->colorTable_;
lut.resize(254);
auto dataRange = boost::irange<uint16_t>(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);
});
} }
} // namespace view } // namespace view

View file

@ -17,19 +17,15 @@ namespace view
class RadarViewImpl; class RadarViewImpl;
class RadarView class RadarView : public QObject
{ {
Q_OBJECT
public: public:
explicit RadarView(std::shared_ptr<manager::RadarManager> radarManager, explicit RadarView(std::shared_ptr<manager::RadarManager> radarManager,
std::shared_ptr<QMapboxGL> map); std::shared_ptr<QMapboxGL> map);
~RadarView(); ~RadarView();
RadarView(const RadarView&) = delete;
RadarView& operator=(const RadarView&) = delete;
RadarView(RadarView&&) noexcept;
RadarView& operator=(RadarView&&) noexcept;
double bearing() const; double bearing() const;
double scale() const; double scale() const;
const std::vector<uint8_t>& data_moments8() const; const std::vector<uint8_t>& data_moments8() const;
@ -41,6 +37,13 @@ public:
void Initialize(); void Initialize();
void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable); void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable);
public slots:
void UpdatePlot();
signals:
void ColorTableLoaded();
void PlotUpdated();
private: private:
std::unique_ptr<RadarViewImpl> p; std::unique_ptr<RadarViewImpl> p;
}; };