SPH
RenderPane.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/objects/Bitmap.h"
5 #include "run/Node.h"
6 #include <condition_variable>
7 #include <mutex>
8 #include <thread>
9 #include <wx/panel.h>
10 
12 
13 class AnimationJob;
14 class IRenderPreview;
15 
16 class BitmapOutput : public IRenderOutput {
17 private:
18  wxPanel* panel;
19 
20  Bitmap<Rgba> render;
21  std::mutex mutex;
22 
23 public:
24  explicit BitmapOutput(wxPanel* panel)
25  : panel(panel) {}
26 
27  virtual void update(const Bitmap<Rgba>& bitmap, Array<Label>&& labels, const bool isFinal) override;
28 
29  virtual void update(Bitmap<Rgba>&& bitmap, Array<Label>&& labels, const bool isFinal) override;
30 
31  wxPanel* getPanel() const {
32  return panel;
33  }
34 
35  wxBitmap getBitmap();
36 };
37 
38 class InteractiveRenderer : public ShareFromThis<InteractiveRenderer> {
39  SharedPtr<JobNode> node;
42  Pixel resolution;
43 
45  struct {
51  SharedPtr<JobNode> node;
52  bool resolution = false;
53 
54  bool pending() const {
55  return camera || parameters || colorizer || renderer || node || resolution;
56  }
57  } changed;
58 
59  struct Status {
60  bool notInitialized = true;
61  bool colorizerMissing = true;
62  bool particlesMissing = true;
63  bool cameraMissing = true;
64  std::string otherReason;
65 
66  void clear() {
67  notInitialized = colorizerMissing = particlesMissing = cameraMissing = false;
68  otherReason.clear();
69  }
70 
71  Outcome isValid() const;
72  } status;
73 
75  std::thread thread;
76  std::condition_variable cv;
77  std::mutex mutex;
78 
79  std::atomic_bool quitting;
80 
81  BitmapOutput output;
82 
83 public:
84  InteractiveRenderer(const SharedPtr<JobNode>& node, wxPanel* panel);
85 
87 
88  void start(const RunSettings& globals);
89 
90  wxBitmap getBitmap() {
91  return output.getBitmap();
92  }
93 
94  Outcome isValid() const {
95  return status.isValid();
96  }
97 
98  void resize(const Pixel newResolution);
99 
100 private:
101  AutoPtr<ICamera> getNewCamera(const SharedPtr<JobNode>& cameraNode, const RunSettings& globals) const;
102 
103  void setCameraAccessor(const RunSettings& globals, const SharedPtr<JobNode>& cameraNode);
104 
105  void setRendererAccessor(const RunSettings& globals);
106 
107  void setNodeAccessor(const SharedPtr<JobNode>& particleNode);
108 
109  void renderLoop(const RunSettings& globals);
110 
111  void update();
112 
113  void stop();
114 };
115 
116 class RenderPane : public wxPanel {
117 private:
119 
120 public:
121  RenderPane(wxWindow* parent,
122  const wxSize size,
123  const SharedPtr<JobNode>& node,
124  const RunSettings& globals);
125 
126  ~RenderPane() = default;
127 
128 private:
129  void onPaint(wxPaintEvent& evt);
130 };
131 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Wrapper of wxBitmap, will be possibly replaced by custom implementation.
Interface for renderers.
#define NAMESPACE_SPH_END
Definition: Object.h:12
Generic dynamically allocated resizable storage.
Definition: Array.h:43
virtual void update(Bitmap< Rgba > &&bitmap, Array< Label > &&labels, const bool isFinal) override
May be called once after render finishes or multiple times for progressive renderers.
wxBitmap getBitmap()
Definition: RenderPane.cpp:37
virtual void update(const Bitmap< Rgba > &bitmap, Array< Label > &&labels, const bool isFinal) override
May be called once after render finishes or multiple times for progressive renderers.
Definition: RenderPane.cpp:25
BitmapOutput(wxPanel *panel)
Definition: RenderPane.h:24
wxPanel * getPanel() const
Definition: RenderPane.h:31
void resize(const Pixel newResolution)
Definition: RenderPane.cpp:125
Outcome isValid() const
Definition: RenderPane.h:94
AutoPtr< IColorizer > colorizer
Definition: RenderPane.h:49
AutoPtr< ICamera > camera
Definition: RenderPane.h:47
Optional< RenderParams > parameters
Definition: RenderPane.h:48
void start(const RunSettings &globals)
Definition: RenderPane.cpp:91
wxBitmap getBitmap()
Definition: RenderPane.h:90
AutoPtr< IRenderer > renderer
Definition: RenderPane.h:50
InteractiveRenderer(const SharedPtr< JobNode > &node, wxPanel *panel)
Definition: RenderPane.cpp:86
RenderPane(wxWindow *parent, const wxSize size, const SharedPtr< JobNode > &node, const RunSettings &globals)
Definition: RenderPane.cpp:339
~RenderPane()=default
Definition: Point.h:101