SPH
RenderJobs.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/Settings.h"
5 
7 
8 class IRenderOutput;
9 class IRenderer;
10 class IColorizer;
11 class RenderParams;
12 class JobNode;
13 
14 enum class ColorizerFlag {
15  VELOCITY = 1 << 0,
16  ENERGY = 1 << 1,
17  BOUND_COMPONENT_ID = 1 << 2,
18  MASS = 1 << 3,
19  BEAUTY = 1 << 4,
20  GRAVITY = 1 << 5,
21  DAMAGE = 1 << 6,
22 };
23 
24 enum class AnimationType {
26  ORBIT,
28 };
29 
30 class IRenderPreview : public Polymorphic {
31 public:
32  virtual void render(const Pixel resolution, IRenderOutput& output) = 0;
33 
34  virtual void update(RenderParams&& params) = 0;
35 
36  virtual void update(AutoPtr<ICamera>&& newCamera) = 0;
37 
38  virtual void update(AutoPtr<IColorizer>&& colorizer) = 0;
39 
40  virtual void update(AutoPtr<IRenderer>&& renderer) = 0;
41 
42  virtual void cancel() = 0;
43 };
44 
45 class AnimationJob : public INullJob {
46 private:
47  GuiSettings gui;
49  bool addSurfaceGravity = true;
50 
52 
53  bool transparentBackground = false;
54 
55  struct {
56  Float step = 10._f * DEG_TO_RAD;
58  } orbit;
59 
60  struct {
61  Path firstFile = Path("out_0000.ssf");
62  } sequence;
63 
64 public:
65  explicit AnimationJob(const std::string& name);
66 
67  virtual std::string className() const override {
68  return "render animation";
69  }
70 
72  return {
73  { "particles", JobType::PARTICLES },
74  { "camera", GuiJobType::CAMERA },
75  };
76  }
77 
79  requires() const override {
80  if (AnimationType(animationType) == AnimationType::FILE_SEQUENCE) {
81  return { { "camera", GuiJobType::CAMERA } };
82  } else {
83  return this->getSlots();
84  }
85  }
86 
87  virtual VirtualSettings getSettings() override;
88 
89  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
90 
92 
93  // needed for interactive rendering
94  AutoPtr<IRenderer> getRenderer(const RunSettings& global) const;
95  AutoPtr<IColorizer> getColorizer(const RunSettings& global) const;
97 };
98 
99 class VdbJob : public INullJob {
100 private:
101  Vector gridStart = Vector(-1.e5_f);
102  Vector gridEnd = Vector(1.e5_f);
103  int dimPower = 10;
104  Float surfaceLevel = 0.13_f;
105 
106  struct {
107  bool enabled = false;
108  Path firstFile = Path("out_0000.ssf");
109  } sequence;
110 
111  Path path = Path("grid.vdb");
112 
113 public:
114  VdbJob(const std::string& name)
115  : INullJob(name) {}
116 
117  virtual std::string className() const override {
118  return "save VDB grid";
119  }
120 
122  return { { "particles", JobType::PARTICLES } };
123  }
124 
126  requires() const override {
127  if (sequence.enabled) {
128  return {};
129  } else {
130  return { { "particles", JobType::PARTICLES } };
131  }
132  }
133 
134  virtual VirtualSettings getSettings() override;
135 
136  virtual void evaluate(const RunSettings& global, IRunCallbacks& UNUSED(callbacks)) override;
137 
138 private:
139  void generate(Storage& storage, const RunSettings& global, const Path& outputPath);
140 };
141 
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
@ BOUND_COMPONENT_ID
Color assigned to each group of gravitationally bound particles.
@ BEAUTY
Attempts to show the real-world look.
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
@ PARTICLES
Job providing particles.
constexpr Float DEG_TO_RAD
Definition: MathUtils.h:369
#define UNUSED(x)
Definition: Object.h:37
#define NAMESPACE_SPH_END
Definition: Object.h:12
@ VELOCITY
Current velocities of particles, always a vector quantity.
@ DAMAGE
Damage, reducing the pressure and deviatoric stress.
@ ENERGY
Specific internal energy, always a scalar quantity.
@ MASS
Particle masses, always a scalar quantity.
ColorizerFlag
Definition: RenderJobs.h:14
AnimationType
Definition: RenderJobs.h:24
BasicVector< Float > Vector
Definition: Vector.h:539
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: RenderJobs.h:67
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
Definition: RenderJobs.cpp:250
virtual UnorderedMap< std::string, ExtJobType > requires() const override
List of slots that need to be connected to evaluate the job.
Definition: RenderJobs.h:79
AutoPtr< IRenderPreview > getRenderPreview(const RunSettings &global) const
Definition: RenderJobs.cpp:415
Float step
Definition: RenderJobs.h:56
AnimationJob(const std::string &name)
Definition: RenderJobs.cpp:42
Float finalAngle
Definition: RenderJobs.h:57
AutoPtr< IRenderer > getRenderer(const RunSettings &global) const
Definition: RenderJobs.cpp:454
Path firstFile
Definition: RenderJobs.h:61
AutoPtr< IColorizer > getColorizer(const RunSettings &global) const
Definition: RenderJobs.cpp:443
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Definition: RenderJobs.cpp:48
RenderParams getRenderParams() const
Definition: RenderJobs.cpp:239
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: RenderJobs.h:71
Interface for objects assigning colors to particles.
Definition: Colorizer.h:34
Base class for jobs providing no data.
Definition: Job.h:322
virtual void update(AutoPtr< IRenderer > &&renderer)=0
virtual void update(AutoPtr< IColorizer > &&colorizer)=0
virtual void update(AutoPtr< ICamera > &&newCamera)=0
virtual void update(RenderParams &&params)=0
virtual void render(const Pixel resolution, IRenderOutput &output)=0
virtual void cancel()=0
Interface used to implement renderers.
Definition: IRenderer.h:166
Callbacks executed by the simulation to provide feedback to the user.
Definition: IRun.h:27
Building block of a simulation hierarchy.
Definition: Node.h:88
Object representing a path on a filesystem.
Definition: Path.h:17
Container storing all quantities used within the simulations.
Definition: Storage.h:230
virtual UnorderedMap< std::string, ExtJobType > getSlots() const override
Lists all potential inputs of the job.
Definition: RenderJobs.h:121
VdbJob(const std::string &name)
Definition: RenderJobs.h:114
virtual std::string className() const override
Name representing the type of the job (e.e. "SPH").
Definition: RenderJobs.h:117
bool enabled
Definition: RenderJobs.h:107
virtual UnorderedMap< std::string, ExtJobType > requires() const override
List of slots that need to be connected to evaluate the job.
Definition: RenderJobs.h:126
Path firstFile
Definition: RenderJobs.h:108
virtual void evaluate(const RunSettings &global, IRunCallbacks &UNUSED(callbacks)) override
virtual VirtualSettings getSettings() override
Returns a settings object which allows to query and modify the state of the job.
Holds a map of virtual entries, associated with a unique name.
Wrapper of an enum.
Definition: Settings.h:37
Definition: Point.h:101
Base class for all polymorphic objects.
Definition: Object.h:88
Parameters of the rendered image.
Definition: IRenderer.h:60