SPH
IRenderer.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 #include "gui/objects/Color.h"
9 #include "gui/objects/Point.h"
10 #include "gui/objects/Texture.h"
11 #include "objects/wrappers/Any.h"
12 #include "objects/wrappers/Flags.h"
13 #include "quantities/Particle.h"
14 #include "thread/ThreadLocal.h"
15 #include <atomic>
16 
18 
19 class ICamera;
20 struct CameraRay;
21 class ITracker;
22 class IColorizer;
23 class IColorMap;
24 class FrameBuffer;
25 class Statistics;
26 class GuiSettings;
27 
28 enum class TextAlign {
29  LEFT = 1 << 0,
30  RIGHT = 1 << 1,
31  HORIZONTAL_CENTER = 1 << 2,
32  TOP = 1 << 3,
33  BOTTOM = 1 << 4,
34  VERTICAL_CENTER = 1 << 5,
35 };
36 
37 class IRenderOutput : public Polymorphic {
38 public:
40  struct Label {
41  std::wstring text;
43  int fontSize;
46  };
47 
49  virtual void update(const Bitmap<Rgba>& bitmap, Array<Label>&& labels, const bool isFinal) = 0;
50 
52  virtual void update(Bitmap<Rgba>&& bitmap, Array<Label>&& labels, const bool isFinal) = 0;
53 };
54 
55 
60 struct RenderParams {
61 
64 
69 
72 
74  bool showKey = true;
75 
77  struct {
81  float scale = 1.f;
82 
87 
89  bool grayScale = false;
90 
94  bool doAntialiasing = false;
95 
99  bool smoothed = false;
100 
102  bool renderGhosts = true;
103 
105 
107  struct {
108 
110  float length = 100.f;
111 
113 
115  struct {
116 
118  float level = 0.15f;
119 
121  float ambientLight = 0.3f;
122 
124  float sunLight = 0.7f;
125 
127  float emission = 1.f;
128 
130  float filterWidth = 2.f;
131 
133 
135  struct {
137  float emission = 1.f;
138 
140  float absorption = 0.f;
141 
143  float compressionFactor = 2.f;
145 
146  struct {
147 
149  float isoStep = 30.f;
150 
152  Size gridSize = 100;
153 
155  bool showLabels = true;
156 
158 
162  void initialize(const GuiSettings& gui);
163 };
164 
166 class IRenderer : public Polymorphic {
167 public:
175  virtual void initialize(const Storage& storage, const IColorizer& colorizer, const ICamera& camera) = 0;
176 
178  virtual bool isInitialized() const = 0;
179 
189  virtual void render(const RenderParams& params, Statistics& stats, IRenderOutput& output) const = 0;
190 
192  virtual void cancelRender() = 0;
193 };
194 
196 class IRaytracer : public IRenderer {
197 protected:
199 
200  struct ThreadData {
203 
206 
207  ThreadData(int seed);
208  };
209 
211 
212  mutable std::atomic_bool shouldContinue;
213 
214 private:
218  struct {
219 
222 
223  struct {
224 
226 
229 
231 
234 
237 
238  } fixed;
239 
240 public:
242 
243  virtual void render(const RenderParams& params, Statistics& stats, IRenderOutput& output) const final;
244 
245  virtual void cancelRender() override {
246  shouldContinue = false;
247  }
248 
249 protected:
250  virtual Rgba shade(const RenderParams& params, const CameraRay& ray, ThreadData& data) const = 0;
251 
252  Rgba getEnviroColor(const CameraRay& ray) const;
253 
254 private:
255  void refine(const RenderParams& params, const Size iteration, FrameBuffer& fb) const;
256 };
257 
Object that can store value of any type.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Wrapper over enum allowing setting (and querying) individual bits of the stored value.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
TextAlign
Definition: IRenderer.h:28
@ HORIZONTAL_CENTER
#define NAMESPACE_SPH_END
Definition: Object.h:12
const NothingType NOTHING
Definition: Optional.h:16
Template for thread-local storage.
Type-safe object that can store value of any type, similar to std::any.
Definition: Any.h:15
Generic dynamically allocated resizable storage.
Definition: Array.h:43
Interface defining a camera or view, used by a renderer.
Definition: Camera.h:62
Interface for objects assigning colors to particles.
Definition: Colorizer.h:34
Base class for renderers based on raytracing.
Definition: IRenderer.h:196
virtual void render(const RenderParams &params, Statistics &stats, IRenderOutput &output) const final
Draws particles into the bitmap, given the data provided in initialize.
Definition: IRenderer.cpp:54
virtual Rgba shade(const RenderParams &params, const CameraRay &ray, ThreadData &data) const =0
Rgba getEnviroColor(const CameraRay &ray) const
Definition: IRenderer.cpp:149
virtual void cancelRender() override
Stops the rendering if it is currently in progress.
Definition: IRenderer.h:245
ThreadLocal< ThreadData > threadData
Definition: IRenderer.h:210
SharedPtr< IScheduler > scheduler
Definition: IRenderer.h:198
Rgba color
Definition: IRenderer.h:225
Texture hdri
HDRI for the background. Can be empty.
Definition: IRenderer.h:228
IRaytracer(SharedPtr< IScheduler > scheduler, const GuiSettings &gui)
Definition: IRenderer.cpp:38
AutoPtr< IColorMap > colorMap
Color mapping operator.
Definition: IRenderer.h:221
struct IRaytracer::@38::@39 enviro
Size subsampling
Number of subsampled iterations.
Definition: IRenderer.h:236
std::atomic_bool shouldContinue
Definition: IRenderer.h:212
Size iterationLimit
Number of iterations of the progressive renderer.
Definition: IRenderer.h:233
virtual void update(const Bitmap< Rgba > &bitmap, Array< Label > &&labels, const bool isFinal)=0
May be called once after render finishes or multiple times for progressive renderers.
virtual void update(Bitmap< Rgba > &&bitmap, Array< Label > &&labels, const bool isFinal)=0
May be called once after render finishes or multiple times for progressive renderers.
Interface used to implement renderers.
Definition: IRenderer.h:166
virtual void initialize(const Storage &storage, const IColorizer &colorizer, const ICamera &camera)=0
Prepares the objects for rendering and updates its data.
virtual void render(const RenderParams &params, Statistics &stats, IRenderOutput &output) const =0
Draws particles into the bitmap, given the data provided in initialize.
virtual void cancelRender()=0
Stops the rendering if it is currently in progress.
virtual bool isInitialized() const =0
Checks if the renderer has been initialized.
Definition: Color.h:8
static Rgba black()
Definition: Color.h:190
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
Random number generator with uniform distribution.
Definition: Rng.h:16
Simple 2D vector with integer coordinates. Provides conversion from and to wxPoint.
Ray given by origin and target point.
Definition: Camera.h:56
UniformRng rng
Random-number generator for this thread.
Definition: IRenderer.h:202
Any data
Additional data used by the implementation.
Definition: IRenderer.h:205
std::wstring text
Definition: IRenderer.h:41
Flags< TextAlign > align
Definition: IRenderer.h:44
Definition: Point.h:101
Base class for all polymorphic objects.
Definition: Object.h:88
Parameters of the rendered image.
Definition: IRenderer.h:60
Optional< Size > selected
Highlighted particle (only for interactive view).
Definition: IRenderer.h:86
float sunLight
Intensity of the sunlight.
Definition: IRenderer.h:124
bool showLabels
Show numerical values of iso-lines.
Definition: IRenderer.h:155
struct RenderParams::@36 volume
Parameters of volumetric renderer.
Rgba background
Background color of the rendered image.
Definition: IRenderer.h:71
struct RenderParams::@33 particles
Parameters of the particle renderer.
float length
Length of the drawn vectors in pixels;.
Definition: IRenderer.h:110
AutoPtr< ICamera > camera
Camera used for rendering.
Definition: IRenderer.h:63
float level
Value of the iso-surface defining the rendered surface.
Definition: IRenderer.h:118
bool showKey
If true, a color palette and a distance scale is included in the image.
Definition: IRenderer.h:74
float isoStep
Step between subsequent iso-lines.
Definition: IRenderer.h:149
struct RenderParams::@35 surface
Parameters of rendered surface.
Size gridSize
Horizontal resolution of the grid.
Definition: IRenderer.h:152
struct RenderParams::@37 contours
AutoPtr< ITracker > tracker
Tracker used for camera motion.
Definition: IRenderer.h:68
float absorption
Absorption coefficient [m^-1].
Definition: IRenderer.h:140
bool doAntialiasing
If true, the particles will be drawn with antialiasing.
Definition: IRenderer.h:94
void initialize(const GuiSettings &gui)
Sets up parameters using values stored in settings.
Definition: IRenderer.cpp:11
float emission
Emission multiplier.
Definition: IRenderer.h:127
bool renderGhosts
If true, ghost particles (if present) will be rendered as empty circles.
Definition: IRenderer.h:102
struct RenderParams::@34 vectors
Parameters of rendered vectors.
float ambientLight
Intensity of the ambient light, illuminating every point unconditionally.
Definition: IRenderer.h:121
float compressionFactor
Compression factor of the logarithmic tonemapper.
Definition: IRenderer.h:143
float filterWidth
Width of the image reconstruction filter.
Definition: IRenderer.h:130
bool grayScale
If true, the palette is converted to grayscale.
Definition: IRenderer.h:89
bool smoothed
If true, particles will be smoothed using cubic spline.
Definition: IRenderer.h:99
float scale
Scaling factor of drawn particles relative to 1.
Definition: IRenderer.h:81