mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 04:50:06 +00:00 
			
		
		
		
	Color radar image using a color table
This commit is contained in:
		
							parent
							
								
									f004c7aee0
								
							
						
					
					
						commit
						c06230ed6c
					
				
					 6 changed files with 81 additions and 14 deletions
				
			
		|  | @ -106,6 +106,14 @@ void MapWidget::AddLayers() | |||
| 
 | ||||
|    radarView->Initialize(); | ||||
| 
 | ||||
|    QString colorTableFile = qgetenv("COLOR_TABLE"); | ||||
|    if (!colorTableFile.isEmpty()) | ||||
|    { | ||||
|       std::shared_ptr<common::ColorTable> colorTable = | ||||
|          common::ColorTable::Load(colorTableFile.toUtf8().constData()); | ||||
|       radarView->LoadColorTable(colorTable); | ||||
|    } | ||||
| 
 | ||||
|    // QMapboxGL::addCustomLayer will take ownership of the QScopedPointer
 | ||||
|    QScopedPointer<QMapbox::CustomLayerHostInterface> pHost( | ||||
|       new RadarLayer(radarView, p->gl_)); | ||||
|  |  | |||
|  | @ -36,6 +36,7 @@ public: | |||
|        uMapScreenCoordLocation_(GL_INVALID_INDEX), | ||||
|        vbo_ {GL_INVALID_INDEX}, | ||||
|        vao_ {GL_INVALID_INDEX}, | ||||
|        texture_ {GL_INVALID_INDEX}, | ||||
|        numVertices_ {0} | ||||
|    { | ||||
|    } | ||||
|  | @ -49,6 +50,7 @@ public: | |||
|    GLint                 uMapScreenCoordLocation_; | ||||
|    std::array<GLuint, 2> vbo_; | ||||
|    GLuint                vao_; | ||||
|    GLuint                texture_; | ||||
| 
 | ||||
|    GLsizeiptr numVertices_; | ||||
| }; | ||||
|  | @ -143,6 +145,11 @@ 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) | ||||
|  | @ -170,6 +177,8 @@ void RadarLayer::render(const QMapbox::CustomLayerRenderParameters& params) | |||
|    gl.glUniformMatrix4fv( | ||||
|       p->uMVPMatrixLocation_, 1, GL_FALSE, glm::value_ptr(uMVPMatrix)); | ||||
| 
 | ||||
|    gl.glActiveTexture(GL_TEXTURE0); | ||||
|    gl.glBindTexture(GL_TEXTURE_1D, p->texture_); | ||||
|    gl.glBindVertexArray(p->vao_); | ||||
|    gl.glDrawArrays(GL_TRIANGLES, 0, p->numVertices_); | ||||
| } | ||||
|  | @ -186,6 +195,27 @@ void RadarLayer::deinitialize() | |||
|    p->uMVPMatrixLocation_ = GL_INVALID_INDEX; | ||||
|    p->vao_                = GL_INVALID_INDEX; | ||||
|    p->vbo_                = {GL_INVALID_INDEX}; | ||||
|    p->texture_            = GL_INVALID_INDEX; | ||||
| } | ||||
| 
 | ||||
| void RadarLayer::UpdateColorTable() | ||||
| { | ||||
|    OpenGLFunctions& gl = p->gl_; | ||||
| 
 | ||||
|    const std::vector<boost::gil::rgba8_pixel_t>& colorTable = | ||||
|       p->radarView_->color_table(); | ||||
| 
 | ||||
|    gl.glActiveTexture(GL_TEXTURE0); | ||||
|    gl.glBindTexture(GL_TEXTURE_1D, p->texture_); | ||||
|    gl.glTexImage1D(GL_TEXTURE_1D, | ||||
|                    0, | ||||
|                    GL_RGBA, | ||||
|                    (GLsizei) colorTable.size(), | ||||
|                    0, | ||||
|                    GL_RGBA, | ||||
|                    GL_UNSIGNED_BYTE, | ||||
|                    colorTable.data()); | ||||
|    gl.glGenerateMipmap(GL_TEXTURE_1D); | ||||
| } | ||||
| 
 | ||||
| static glm::vec2 | ||||
|  |  | |||
|  | @ -28,6 +28,8 @@ public: | |||
|    void render(const QMapbox::CustomLayerRenderParameters&) override final; | ||||
|    void deinitialize() override final; | ||||
| 
 | ||||
|    void UpdateColorTable(); | ||||
| 
 | ||||
| private: | ||||
|    std::unique_ptr<RadarLayerImpl> p; | ||||
| }; | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ | |||
| #include <scwx/common/constants.hpp> | ||||
| 
 | ||||
| #include <boost/log/trivial.hpp> | ||||
| #include <boost/range/irange.hpp> | ||||
| #include <boost/timer/timer.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
|  | @ -21,7 +22,11 @@ class RadarViewImpl | |||
| public: | ||||
|    explicit RadarViewImpl(std::shared_ptr<manager::RadarManager> radarManager, | ||||
|                           std::shared_ptr<QMapboxGL>             map) : | ||||
|        radarManager_(radarManager), map_(map) | ||||
|        radarManager_(radarManager), | ||||
|        map_(map), | ||||
|        colorTable_ {boost::gil::rgba8_pixel_t(0, 128, 0, 255), | ||||
|                     boost::gil::rgba8_pixel_t(255, 192, 0, 255), | ||||
|                     boost::gil::rgba8_pixel_t(255, 0, 0, 255)} | ||||
|    { | ||||
|    } | ||||
|    ~RadarViewImpl() = default; | ||||
|  | @ -32,6 +37,8 @@ public: | |||
|    std::vector<float>    vertices_; | ||||
|    std::vector<uint8_t>  dataMoments8_; | ||||
|    std::vector<uint16_t> dataMoments16_; | ||||
| 
 | ||||
|    std::vector<boost::gil::rgba8_pixel_t> colorTable_; | ||||
| }; | ||||
| 
 | ||||
| RadarView::RadarView(std::shared_ptr<manager::RadarManager> radarManager, | ||||
|  | @ -69,6 +76,11 @@ const std::vector<float>& RadarView::vertices() const | |||
|    return p->vertices_; | ||||
| } | ||||
| 
 | ||||
| const std::vector<boost::gil::rgba8_pixel_t>& RadarView::color_table() const | ||||
| { | ||||
|    return p->colorTable_; | ||||
| } | ||||
| 
 | ||||
| void RadarView::Initialize() | ||||
| { | ||||
|    BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Initialize()"; | ||||
|  | @ -297,6 +309,26 @@ void RadarView::Initialize() | |||
|       << logPrefix_ << "Vertices calculated in " << timer.format(6, "%ws"); | ||||
| } | ||||
| 
 | ||||
| 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); | ||||
|                  }); | ||||
| } | ||||
| 
 | ||||
| } // namespace view
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
|  | @ -1,5 +1,6 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <scwx/common/color_table.hpp> | ||||
| #include <scwx/qt/manager/radar_manager.hpp> | ||||
| 
 | ||||
| #include <memory> | ||||
|  | @ -35,7 +36,10 @@ public: | |||
|    const std::vector<uint16_t>& data_moments16() const; | ||||
|    const std::vector<float>&    vertices() const; | ||||
| 
 | ||||
|    const std::vector<boost::gil::rgba8_pixel_t>& color_table() const; | ||||
| 
 | ||||
|    void Initialize(); | ||||
|    void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable); | ||||
| 
 | ||||
| private: | ||||
|    std::unique_ptr<RadarViewImpl> p; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat