Correlation 4.10.0
An Analysis Tool for Liquids and for Amorphous Solids
Loading...
Searching...
No Matches
PlotRenderPipeline.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
13#include <slint.h>
14
15#include <atomic>
16#include <condition_variable>
17#include <functional>
18#include <map>
19#include <memory>
20#include <mutex>
21#include <optional>
22#include <string>
23#include <thread>
24#include <vector>
25
26namespace correlation::app {
27
32struct RenderTask {
33 int index{-1};
34 std::size_t active_frame{0};
36 std::vector<correlation::plotters::LabeledHistogram> comparison_hists;
39 std::map<std::string, real_t> ashcroft_weights;
40 std::map<std::string, bool> curve_visibility;
41 std::map<std::string, std::string> custom_curve_colors;
42 std::size_t pinned_runs_count{0};
43};
44
50public:
51 using ImageRenderedCallback = std::function<void(const slint::Image &)>;
52
59 bool dispatch_to_slint_event_loop = true);
60
65
70
80 [[nodiscard]] bool isCacheHit(int index, const correlation::plotters::PlotConfig &config,
82 std::size_t pinned_runs_count,
83 std::size_t active_frame = 0) const noexcept;
84
88 void invalidateCache() noexcept;
89
94 void submitTask(RenderTask task);
95
99 void stop() noexcept;
100
101private:
102 [[nodiscard]] std::optional<RenderTask> waitForNextTask();
103 [[nodiscard]] static std::string renderSvg(RenderTask &task);
104 void dispatchImage(slint::Image img);
105 void renderLoop();
106
109 std::jthread render_worker_;
110 std::mutex render_mutex_;
111 std::condition_variable render_cv_;
112 std::optional<RenderTask> pending_task_;
114 std::shared_ptr<std::atomic<bool>> alive_{std::make_shared<std::atomic<bool>>(true)};
115
116 mutable std::mutex cache_mutex_;
118 std::size_t last_rendered_frame_{0};
122};
123
124} // namespace correlation::app
Manager for distribution function calculations (RDF, PAD, S(Q), etc.).
Facade header for zero-dependency SVG plotter.
PlotRenderPipeline & operator=(PlotRenderPipeline &&)=delete
std::optional< RenderTask > waitForNextTask()
Definition PlotRenderPipeline.cpp:115
void renderLoop()
Definition PlotRenderPipeline.cpp:165
bool isCacheHit(int index, const correlation::plotters::PlotConfig &config, const correlation::plotters::HoverInfo &hover, std::size_t pinned_runs_count, std::size_t active_frame=0) const noexcept
Evaluates whether a new render request matches previously rendered frame parameters.
Definition PlotRenderPipeline.cpp:86
std::mutex cache_mutex_
Definition PlotRenderPipeline.hpp:116
std::jthread render_worker_
Definition PlotRenderPipeline.hpp:109
void invalidateCache() noexcept
Invalidates cached parameters to force re-rendering on the next request.
Definition PlotRenderPipeline.cpp:77
int last_rendered_index_
Definition PlotRenderPipeline.hpp:117
correlation::plotters::PlotConfig last_config_
Definition PlotRenderPipeline.hpp:119
PlotRenderPipeline(ImageRenderedCallback callback, bool dispatch_to_slint_event_loop=true)
Constructs pipeline and starts background rendering worker thread.
Definition PlotRenderPipeline.cpp:56
std::mutex render_mutex_
Definition PlotRenderPipeline.hpp:110
PlotRenderPipeline & operator=(const PlotRenderPipeline &)=delete
void submitTask(RenderTask task)
Enqueues a render task to the worker queue, discarding superseded tasks.
Definition PlotRenderPipeline.cpp:96
static std::string renderSvg(RenderTask &task)
Definition PlotRenderPipeline.cpp:132
bool stop_render_worker_
Definition PlotRenderPipeline.hpp:113
std::shared_ptr< std::atomic< bool > > alive_
Definition PlotRenderPipeline.hpp:114
correlation::plotters::HoverInfo last_hover_
Definition PlotRenderPipeline.hpp:120
std::condition_variable render_cv_
Definition PlotRenderPipeline.hpp:111
std::size_t last_pinned_runs_count_
Definition PlotRenderPipeline.hpp:121
ImageRenderedCallback callback_
Definition PlotRenderPipeline.hpp:107
void stop() noexcept
Stops worker thread and cancels pending operations.
Definition PlotRenderPipeline.cpp:64
std::optional< RenderTask > pending_task_
Definition PlotRenderPipeline.hpp:112
std::size_t last_rendered_frame_
Definition PlotRenderPipeline.hpp:118
~PlotRenderPipeline()
Destructor. Signals stop condition and joins worker thread safely.
Definition PlotRenderPipeline.cpp:62
PlotRenderPipeline(const PlotRenderPipeline &)=delete
std::function< void(const slint::Image &)> ImageRenderedCallback
Definition PlotRenderPipeline.hpp:51
bool dispatch_to_slint_event_loop_
Definition PlotRenderPipeline.hpp:108
PlotRenderPipeline(PlotRenderPipeline &&)=delete
void dispatchImage(slint::Image img)
Definition PlotRenderPipeline.cpp:148
Definition AppController.hpp:27
Container for a single calculated distribution function.
Definition DistributionFunctions.hpp:226
Self-contained payload consumed by the background SVG render worker.
Definition PlotRenderPipeline.hpp:32
correlation::plotters::PlotConfig config
Output styling config.
Definition PlotRenderPipeline.hpp:37
int index
Target plot index.
Definition PlotRenderPipeline.hpp:33
std::map< std::string, bool > curve_visibility
Curve visibility flags.
Definition PlotRenderPipeline.hpp:40
std::map< std::string, std::string > custom_curve_colors
Custom curve colors.
Definition PlotRenderPipeline.hpp:41
std::map< std::string, real_t > ashcroft_weights
Ashcroft weights.
Definition PlotRenderPipeline.hpp:39
correlation::analysis::Histogram active_hist
Active histogram data.
Definition PlotRenderPipeline.hpp:35
std::size_t pinned_runs_count
Pinned runs count.
Definition PlotRenderPipeline.hpp:42
correlation::plotters::HoverInfo hover
Cursor hover metadata.
Definition PlotRenderPipeline.hpp:38
std::size_t active_frame
Active trajectory frame.
Definition PlotRenderPipeline.hpp:34
std::vector< correlation::plotters::LabeledHistogram > comparison_hists
Comparison histograms.
Definition PlotRenderPipeline.hpp:36
Information about the mouse hover position.
Definition PlotTypes.hpp:176
Theme and layout configuration for the plot.
Definition PlotTypes.hpp:42