Backend support for multiple color tables

This commit is contained in:
Dan Paulat 2021-11-06 08:28:08 -05:00
parent 951710dcfe
commit bcae7d9825
6 changed files with 90 additions and 24 deletions

View file

@ -110,7 +110,7 @@ void RadarProductLayer::initialize()
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(p->radarProductView_.get(),
&view::RadarProductView::ColorTableLoaded, &view::RadarProductView::ColorTableUpdated,
this, this,
&RadarProductLayer::UpdateColorTableNextFrame); &RadarProductLayer::UpdateColorTableNextFrame);
connect(p->radarProductView_.get(), connect(p->radarProductView_.get(),
@ -239,7 +239,7 @@ void RadarProductLayer::deinitialize()
p->texture_ = GL_INVALID_INDEX; p->texture_ = GL_INVALID_INDEX;
disconnect(p->radarProductView_.get(), disconnect(p->radarProductView_.get(),
&view::RadarProductView::ColorTableLoaded, &view::RadarProductView::ColorTableUpdated,
this, this,
&RadarProductLayer::UpdateColorTableNextFrame); &RadarProductLayer::UpdateColorTableNextFrame);
disconnect(p->radarProductView_.get(), disconnect(p->radarProductView_.get(),

View file

@ -45,8 +45,11 @@ public:
std::shared_ptr<manager::RadarProductManager> radarProductManager) : std::shared_ptr<manager::RadarProductManager> radarProductManager) :
product_ {product}, product_ {product},
radarProductManager_ {radarProductManager}, radarProductManager_ {radarProductManager},
latitude_ {},
longitude_ {},
sweepTime_ {}, sweepTime_ {},
colorTable_ {} colorTable_ {},
colorTableLut_ {}
{ {
auto it = blockTypes_.find(product); auto it = blockTypes_.find(product);
@ -67,13 +70,23 @@ public:
wsr88d::rda::DataBlockType dataBlockType_; wsr88d::rda::DataBlockType dataBlockType_;
std::shared_ptr<manager::RadarProductManager> radarProductManager_; std::shared_ptr<manager::RadarProductManager> radarProductManager_;
std::shared_ptr<wsr88d::rda::MomentDataBlock> momentDataBlock0_;
std::vector<float> vertices_; std::vector<float> vertices_;
std::vector<uint8_t> dataMoments8_; std::vector<uint8_t> dataMoments8_;
std::vector<uint16_t> dataMoments16_; std::vector<uint16_t> dataMoments16_;
float latitude_;
float longitude_;
std::chrono::system_clock::time_point sweepTime_; std::chrono::system_clock::time_point sweepTime_;
std::vector<boost::gil::rgba8_pixel_t> colorTable_; std::shared_ptr<common::ColorTable> colorTable_;
std::vector<boost::gil::rgba8_pixel_t> colorTableLut_;
std::shared_ptr<common::ColorTable> savedColorTable_;
float savedScale_;
float savedOffset_;
}; };
Level2ProductView::Level2ProductView( Level2ProductView::Level2ProductView(
@ -91,13 +104,13 @@ Level2ProductView::~Level2ProductView() = default;
const std::vector<boost::gil::rgba8_pixel_t>& const std::vector<boost::gil::rgba8_pixel_t>&
Level2ProductView::color_table() const Level2ProductView::color_table() const
{ {
if (p->colorTable_.size() == 0) if (p->colorTableLut_.size() == 0)
{ {
return RadarProductView::color_table(); return RadarProductView::color_table();
} }
else else
{ {
return p->colorTable_; return p->colorTableLut_;
} }
} }
@ -136,11 +149,31 @@ std::tuple<const void*, size_t, size_t> Level2ProductView::GetMomentData() const
void Level2ProductView::LoadColorTable( void Level2ProductView::LoadColorTable(
std::shared_ptr<common::ColorTable> colorTable) std::shared_ptr<common::ColorTable> colorTable)
{ {
// TODO: Make size, offset and scale dynamic p->colorTable_ = colorTable;
const float offset = 66.0f; UpdateColorTable();
const float scale = 2.0f; }
std::vector<boost::gil::rgba8_pixel_t>& lut = p->colorTable_; void Level2ProductView::UpdateColorTable()
{
if (p->momentDataBlock0_ == nullptr || //
p->colorTable_ == nullptr)
{
// Nothing to update
return;
}
const float offset = p->momentDataBlock0_->offset();
const float scale = p->momentDataBlock0_->scale();
if (p->savedColorTable_ == p->colorTable_ && //
p->savedOffset_ == offset && //
p->savedScale_ == scale)
{
// The color table LUT does not need updated
return;
}
std::vector<boost::gil::rgba8_pixel_t>& lut = p->colorTableLut_;
lut.resize(254); lut.resize(254);
auto dataRange = boost::irange<uint16_t>(2, 255); auto dataRange = boost::irange<uint16_t>(2, 255);
@ -150,10 +183,14 @@ void Level2ProductView::LoadColorTable(
dataRange.end(), dataRange.end(),
[&](uint16_t i) { [&](uint16_t i) {
float f = (i - offset) / scale; float f = (i - offset) / scale;
lut[i - *dataRange.begin()] = colorTable->Color(f); lut[i - *dataRange.begin()] = p->colorTable_->Color(f);
}); });
emit ColorTableLoaded(); p->savedColorTable_ = p->colorTable_;
p->savedOffset_ = offset;
p->savedScale_ = scale;
emit ColorTableUpdated();
} }
void Level2ProductView::ComputeSweep() void Level2ProductView::ComputeSweep()
@ -182,6 +219,7 @@ void Level2ProductView::ComputeSweep()
auto radarData = level2Data->radar_data()[0]; 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;
if (momentData0 == nullptr) if (momentData0 == nullptr)
{ {
@ -190,6 +228,9 @@ void Level2ProductView::ComputeSweep()
return; return;
} }
auto volumeData0 = radarData[0]->volume_data_block();
p->latitude_ = volumeData0->latitude();
p->longitude_ = volumeData0->longitude();
p->sweepTime_ = TimePoint(radarData[0]->modified_julian_date(), p->sweepTime_ = TimePoint(radarData[0]->modified_julian_date(),
radarData[0]->collection_time()); radarData[0]->collection_time());
@ -368,9 +409,8 @@ void Level2ProductView::ComputeSweep()
baseCoord) * baseCoord) *
2; 2;
// TODO: Radar location vertices[vIndex++] = p->latitude_;
vertices[vIndex++] = 38.6986f; vertices[vIndex++] = p->longitude_;
vertices[vIndex++] = -90.6828f;
vertices[vIndex++] = coordinates[offset1]; vertices[vIndex++] = coordinates[offset1];
vertices[vIndex++] = coordinates[offset1 + 1]; vertices[vIndex++] = coordinates[offset1 + 1];
@ -398,6 +438,8 @@ void Level2ProductView::ComputeSweep()
<< logPrefix_ << "Vertices calculated in " << timer.format(6, "%ws"); << logPrefix_ << "Vertices calculated in " << timer.format(6, "%ws");
emit SweepComputed(); emit SweepComputed();
UpdateColorTable();
} }
std::shared_ptr<Level2ProductView> Level2ProductView::Create( std::shared_ptr<Level2ProductView> Level2ProductView::Create(

View file

@ -28,20 +28,23 @@ public:
std::shared_ptr<manager::RadarProductManager> radarProductManager); std::shared_ptr<manager::RadarProductManager> radarProductManager);
~Level2ProductView(); ~Level2ProductView();
const std::vector<boost::gil::rgba8_pixel_t>& color_table() const; const std::vector<boost::gil::rgba8_pixel_t>& color_table() const override;
std::chrono::system_clock::time_point sweep_time() const; std::chrono::system_clock::time_point sweep_time() const override;
const std::vector<float>& vertices() const; const std::vector<float>& vertices() const override;
void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable); void LoadColorTable(std::shared_ptr<common::ColorTable> colorTable) override;
std::tuple<const void*, size_t, size_t> GetMomentData() const; std::tuple<const void*, size_t, size_t> GetMomentData() const override;
static std::shared_ptr<Level2ProductView> static std::shared_ptr<Level2ProductView>
Create(common::Level2Product product, Create(common::Level2Product product,
std::shared_ptr<manager::RadarProductManager> radarProductManager); std::shared_ptr<manager::RadarProductManager> radarProductManager);
protected:
void UpdateColorTable() override;
protected slots: protected slots:
void ComputeSweep(); void ComputeSweep() override;
private: private:
std::unique_ptr<Level2ProductViewImpl> p; std::unique_ptr<Level2ProductViewImpl> p;

View file

@ -35,11 +35,14 @@ public:
virtual std::tuple<const void*, size_t, size_t> GetMomentData() const = 0; virtual std::tuple<const void*, size_t, size_t> GetMomentData() const = 0;
protected:
virtual void UpdateColorTable() = 0;
protected slots: protected slots:
virtual void ComputeSweep(); virtual void ComputeSweep();
signals: signals:
void ColorTableLoaded(); void ColorTableUpdated();
void SweepComputed(); void SweepComputed();
private: private:

View file

@ -146,6 +146,9 @@ public:
VolumeDataBlock(VolumeDataBlock&&) noexcept; VolumeDataBlock(VolumeDataBlock&&) noexcept;
VolumeDataBlock& operator=(VolumeDataBlock&&) noexcept; VolumeDataBlock& operator=(VolumeDataBlock&&) noexcept;
float latitude() const;
float longitude() const;
static std::shared_ptr<VolumeDataBlock> static std::shared_ptr<VolumeDataBlock>
Create(const std::string& dataBlockType, Create(const std::string& dataBlockType,
const std::string& dataName, const std::string& dataName,
@ -185,6 +188,7 @@ public:
uint8_t azimuth_indexing_mode() const; uint8_t azimuth_indexing_mode() const;
uint16_t data_block_count() const; uint16_t data_block_count() const;
std::shared_ptr<VolumeDataBlock> volume_data_block() const;
std::shared_ptr<MomentDataBlock> moment_data_block(DataBlockType type) const; std::shared_ptr<MomentDataBlock> moment_data_block(DataBlockType type) const;
bool Parse(std::istream& is); bool Parse(std::istream& is);

View file

@ -275,6 +275,16 @@ VolumeDataBlock::VolumeDataBlock(VolumeDataBlock&&) noexcept = default;
VolumeDataBlock& VolumeDataBlock&
VolumeDataBlock::operator=(VolumeDataBlock&&) noexcept = default; VolumeDataBlock::operator=(VolumeDataBlock&&) noexcept = default;
float VolumeDataBlock::latitude() const
{
return p->latitude_;
}
float VolumeDataBlock::longitude() const
{
return p->longitude_;
}
std::shared_ptr<VolumeDataBlock> std::shared_ptr<VolumeDataBlock>
VolumeDataBlock::Create(const std::string& dataBlockType, VolumeDataBlock::Create(const std::string& dataBlockType,
const std::string& dataName, const std::string& dataName,
@ -603,6 +613,10 @@ uint16_t DigitalRadarData::data_block_count() const
{ {
return p->dataBlockCount_; return p->dataBlockCount_;
} }
std::shared_ptr<VolumeDataBlock> DigitalRadarData::volume_data_block() const
{
return p->volumeDataBlock_;
}
std::shared_ptr<MomentDataBlock> std::shared_ptr<MomentDataBlock>
DigitalRadarData::moment_data_block(DataBlockType type) const DigitalRadarData::moment_data_block(DataBlockType type) const