改造一些
This commit is contained in:
@@ -29,14 +29,14 @@ std::size_t Afterglow_Control::latest_spectrum_point_count() const {
|
||||
std::size_t Afterglow_Control::rendered_cell_count() const {
|
||||
const auto state = properties();
|
||||
const auto history = impl_->history.snapshot();
|
||||
if(history.empty())
|
||||
if (history.empty())
|
||||
return 0;
|
||||
const int width = std::min(state.frequency_point_size.get(), static_cast<int>(history.back().size()));
|
||||
const int height = state.power_point_size.get() > 0 ? state.power_point_size.get() : std::max(1, static_cast<int>(impl_->power_axis->pixel_length()));
|
||||
return width > 0 && height > 0 ? static_cast<std::size_t>(width) * static_cast<std::size_t>(height) : 0;
|
||||
}
|
||||
void Afterglow_Control::append_spectrum(std::span<const double> values) {
|
||||
if(get<&Afterglow_Properties::frequency_point_size>() <= 0)
|
||||
if (get<&Afterglow_Properties::frequency_point_size>() <= 0)
|
||||
set<&Afterglow_Properties::frequency_point_size>(static_cast<int>(values.size()));
|
||||
impl_->history.update({values.begin(), values.end()}, 64);
|
||||
changed();
|
||||
@@ -50,31 +50,31 @@ void Afterglow_Control::publish() {
|
||||
void Afterglow_Control::paint(Painter& painter) {
|
||||
const auto state = render_properties();
|
||||
const auto history = impl_->history.snapshot();
|
||||
if(history.empty())
|
||||
if (history.empty())
|
||||
return;
|
||||
const int width = std::min(state.frequency_point_size.get(), static_cast<int>(history.back().size()));
|
||||
const int height = state.power_point_size.get() > 0 ? state.power_point_size.get() : std::max(1, static_cast<int>(impl_->power_axis->pixel_length()));
|
||||
if(width <= 0 || height <= 0)
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
std::vector<double> intensity(static_cast<std::size_t>(width) * height);
|
||||
double weight = 1.0;
|
||||
const double decay = 1.0 - state.attenuation_rate.get();
|
||||
for(auto iterator = history.rbegin(); iterator != history.rend(); ++iterator) {
|
||||
for (auto iterator = history.rbegin(); iterator != history.rend(); ++iterator) {
|
||||
const int count = std::min(width, static_cast<int>(iterator->size()));
|
||||
for(int x = 0; x < count; ++x) {
|
||||
for (int x = 0; x < count; ++x) {
|
||||
const double normalized = normalized_value((*iterator)[static_cast<std::size_t>(x)], state.power_range);
|
||||
const int y = std::clamp(height - 1 - static_cast<int>(normalized * (height - 1)), 0, height - 1);
|
||||
intensity[static_cast<std::size_t>(y) * width + x] += weight;
|
||||
if(state.interpolate && y + 1 < height)
|
||||
if (state.interpolate && y + 1 < height)
|
||||
intensity[static_cast<std::size_t>(y + 1) * width + x] += weight * 0.35;
|
||||
}
|
||||
weight *= decay;
|
||||
if(weight < 0.01)
|
||||
if (weight < 0.01)
|
||||
break;
|
||||
}
|
||||
const double maximum = std::max(1.0, *std::max_element(intensity.begin(), intensity.end()));
|
||||
std::vector<Pixel> pixels(intensity.size());
|
||||
for(std::size_t index = 0; index < pixels.size(); ++index)
|
||||
for (std::size_t index = 0; index < pixels.size(); ++index)
|
||||
pixels[index] = state.color_map.at_normalized(intensity[index] / maximum);
|
||||
painter.heatmap(mapped_rect(impl_->frequency_axis->transform(), impl_->power_axis->transform(), state.frequency_range, state.power_range), width, height, pixels, Image_Interpolation_Mode::Bilinear);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
#pragma once
|
||||
#include "../renderable/Renderable_Builder.h"
|
||||
#include <renderive/base/property/Attach_Builder.hpp>
|
||||
#include <renderive/scene/base/Scene_Base.hpp>
|
||||
#include <renderive/state/Double_State_Strategy.hpp>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
namespace renderive {
|
||||
class Abs_Axis;
|
||||
|
||||
template <std::totally_ordered Value_Type, Value_Type Minimum, Value_Type Maximum, Value_Type Default>
|
||||
class Clamped_Property {
|
||||
public:
|
||||
@@ -46,6 +49,8 @@ private:
|
||||
double value{};
|
||||
};
|
||||
namespace detail {
|
||||
class Paint_Overlay {};
|
||||
|
||||
template <Property_Set Properties_Type>
|
||||
class Plottable_State : public Double_State_Strategy<Renderable, Properties_Type> {
|
||||
public:
|
||||
@@ -82,5 +87,27 @@ private:
|
||||
};
|
||||
template <class Control, class Properties>
|
||||
using Attach_Plottable = Attach_Builder<Control, Properties, Renderable_Builder>;
|
||||
|
||||
template <class Renderable_Type, class Axis_Type>
|
||||
requires std::derived_from<Renderable_Type, Renderable> && std::derived_from<Axis_Type, Abs_Axis>
|
||||
void attach_renderable_dependency(Renderable_Type& renderable, const std::shared_ptr<Axis_Type>& axis) {
|
||||
if (axis) {
|
||||
renderable.scene().add_dependency_parent(renderable, *axis);
|
||||
if constexpr (std::derived_from<Renderable_Type, Paint_Overlay>) {
|
||||
renderable.scene().add_display_parent(renderable, *axis);
|
||||
} else {
|
||||
renderable.scene().add_display_parent(*axis, renderable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class Renderable_Type, class Value>
|
||||
void attach_renderable_dependency(Renderable_Type&, const Value&) {}
|
||||
|
||||
template <class Control, class... Args>
|
||||
requires std::derived_from<Control, Renderable>
|
||||
void attach_renderable_dependencies(Control& renderable, const Args&... args) {
|
||||
(attach_renderable_dependency(renderable, args), ...);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ struct Selection_Rectangle_Overlay_Properties {
|
||||
Pen selection_border_pen{Color::white(), 1.0, Line_Style::Dash};
|
||||
};
|
||||
namespace detail {
|
||||
class LIB_DECL Selection_Rectangle_Overlay_Control : public Plottable_State<Selection_Rectangle_Overlay_Properties>, public Event_Handler {
|
||||
class LIB_DECL Selection_Rectangle_Overlay_Control : public Plottable_State<Selection_Rectangle_Overlay_Properties>, public Paint_Overlay, public Event_Handler {
|
||||
public:
|
||||
Selection_Rectangle_Overlay_Control(Plot_Core& plot, const Selection_Rectangle_Overlay_Properties& properties, std::shared_ptr<Abs_Axis> horizontal_axis, std::shared_ptr<Abs_Axis> vertical_axis);
|
||||
~Selection_Rectangle_Overlay_Control() override;
|
||||
|
||||
Reference in New Issue
Block a user