SPH
SsfToPng.cpp
Go to the documentation of this file.
1 #include "SsfToPng.h"
2 #include "Sph.h"
3 #include "gui/Factory.h"
4 #include "gui/Project.h"
5 #include "gui/Settings.h"
6 #include "gui/objects/Camera.h"
8 #include "gui/objects/Movie.h"
9 #include "thread/Tbb.h"
10 #include <iostream>
11 
13 
14 using namespace Sph;
15 
16 bool SsfToPngApp::OnInit() {
17  if (wxTheApp->argc < 2) {
18  std::cout << "Usage: ssftopng file.ssf" << std::endl;
19  return 0;
20  }
21 
22  GuiSettings gui;
23  gui.set(GuiSettingsId::ORTHO_FOV, 0._f)
24  .set(GuiSettingsId::ORTHO_VIEW_CENTER, 0.5_f * Vector(1024, 768, 0))
38  .set(GuiSettingsId::RENDERER, RendererEnum::RAYTRACER)
41  .set(GuiSettingsId::CAMERA, CameraEnum::PERSPECTIVE)
42  .set(GuiSettingsId::PERSPECTIVE_TARGET, Vector(-4.e4, -3.8e4_f, 0._f))
43  .set(GuiSettingsId::PERSPECTIVE_POSITION, Vector(-4.e4, -3.8e4_f, 6.e5_f))
44  .set(GuiSettingsId::ORTHO_PROJECTION, OrthoEnum::XY)
45  .set(GuiSettingsId::ORTHO_CUTOFF, 0._f)
46  .set(GuiSettingsId::ORTHO_ZOFFSET, -1.e8_f)
48  .set(GuiSettingsId::IMAGES_NAME, std::string("img_%e_%d.png"))
49  .set(GuiSettingsId::IMAGES_MOVIE_NAME, std::string("img_%e.avi"))
51 
52 
53 #if 0
54 
56 
57  Array<SharedPtr<IColorizer>> colorizers;
58  colorizers.push(Factory::getColorizer(gui, ColorizerId(QuantityId::BEAUTY)));
59 
60  RenderParams params;
61  params.size = Pixel(1024, 768);
62  params.camera = Factory::getCamera(gui, params.size);
63 
64  Movie movie(gui, std::move(renderer), std::move(colorizers), std::move(params));
65 
66  const Float totalRotation = 4._f * PI;
67  const Float step = 0.02_f;
68  try {
69  Storage storage;
70  Statistics stats;
71  BinaryInput input;
72  std::string file(wxTheApp->argv[1]);
73  Outcome result = input.load(Path(file), storage, stats);
74  if (!result) {
75  throw IoError(result.error());
76  }
77 
78  const Vector target = gui.get<Vector>(GuiSettingsId::PERSPECTIVE_TARGET);
79  const Float radius = getLength(gui.get<Vector>(GuiSettingsId::PERSPECTIVE_POSITION) - target);
80  for (Float phi = 0._f; phi < totalRotation; phi += step) {
81  const Vector position =
82  target + radius * (cos(phi) * Vector(0._f, 0._f, 1._f) + sin(phi) * Vector(1._f, 0._f, 0._f));
83  gui.set(GuiSettingsId::PERSPECTIVE_POSITION, position);
84 
85  movie.setCamera(Factory::getCamera(gui, params.size));
86  movie.save(storage, stats);
87  std::cout << int(phi * 100 / totalRotation) << std::endl;
88  }
89  } catch (const std::exception& e) {
90  std::cout << "Failed: " << e.what() << std::endl;
91  return -1;
92  }
93 #else
94 
95  gui.set(GuiSettingsId::PERSPECTIVE_TARGET, Vector(0._f))
96  .set(GuiSettingsId::PERSPECTIVE_POSITION, Vector(0._f, 0._f, -6.5e5_f))
97  .set(GuiSettingsId::PERSPECTIVE_TRACKED_PARTICLE, 201717);
98 
99  const Path dir(std::string(wxTheApp->argv[1]));
100  for (Path path : FileSystem::iterateDirectory(dir)) {
101  if (!OutputFile::getDumpIdx(path)) {
102  continue;
103  }
104 
105  Path ssf = dir / path;
106  Path png = Path(ssf).replaceExtension("png");
107 
108  std::cout << "Processing " << ssf.native() << std::endl;
110 
112 
113  Array<SharedPtr<IColorizer>> colorizers;
114  Project project;
115  project.getGuiSettings() = gui;
117 
118  RenderParams params;
119  params.size = Pixel(800, 800);
120  params.camera = Factory::getCamera(gui, params.size);
121 
122  Movie movie(gui, std::move(renderer), std::move(colorizers), std::move(params));
123 
124  try {
125  Storage storage;
126  Statistics stats;
127  BinaryInput input;
128  Outcome result = input.load(ssf, storage, stats);
129  if (!result) {
130  throw IoError(result.error());
131  }
132 
133  movie.save(storage, stats);
134 
135  } catch (const std::exception& e) {
136  std::cout << "Failed: " << e.what() << std::endl;
137  return -1;
138  }
139  }
140 #endif
141  return 0;
142 }
Defines projection transforming 3D particles onto 2D screen.
Object converting quantity values of particles into colors.
ColorizerId
Special colorizers that do not directly correspond to quantities.
Definition: Colorizer.h:136
const float radius
Definition: CurveDialog.cpp:18
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
Definition: Globals.h:13
INLINE T sin(const T f)
Definition: MathUtils.h:296
INLINE T cos(const T f)
Definition: MathUtils.h:291
constexpr Float PI
Mathematical constants.
Definition: MathUtils.h:361
Periodically saves rendered images to disk.
@ MASS
Paricles masses, always a scalar quantity.
Includes common headers.
IMPLEMENT_APP(SsfToPngApp)
Implements IScheduler interface using TBB.
INLINE Float getLength(const Vector &v)
Returns the length of the vector. Enabled only for vectors of floating-point precision.
Definition: Vector.h:579
BasicVector< Float > Vector
Definition: Vector.h:539
INLINE Vector getNormalized(const Vector &v)
Definition: Vector.h:590
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE void push(U &&u)
Adds new element to the end of the array, resizing the array if necessary.
Definition: Array.h:306
INLINE const TError & error() const
Returns the error message.
Definition: Outcome.h:88
Input for the binary file, generated by BinaryOutput.
Definition: Output.h:352
virtual Outcome load(const Path &path, Storage &storage, Statistics &stats) override
Loads data from the file into the storage.
Definition: Output.cpp:718
INLINE TValue get(const GuiSettingsId id) const
Definition: Settings.h:245
INLINE GuiSettings & set(const GuiSettingsId id, const TValue &value)
Definition: Settings.h:250
Exception thrown when file cannot be read, it has invalid format, etc.
Definition: Exceptions.h:31
Object managing periodic rendering of images and saving them to given paths.
Definition: Movie.h:22
static Optional< Size > getDumpIdx(const Path &path)
Extracts the dump index from given path generated by OutputFile.
Definition: Output.cpp:49
Object representing a path on a filesystem.
Definition: Path.h:17
Path & replaceExtension(const std::string &newExtension)
Changes the extension of the file.
Definition: Path.cpp:76
std::string native() const
Returns the native version of the path.
Definition: Path.cpp:71
GuiSettings & getGuiSettings()
Definition: Project.h:51
Object holding various statistics about current run.
Definition: Statistics.h:22
Container storing all quantities used within the simulations.
Definition: Storage.h:230
static SharedPtr< Tbb > getGlobalInstance()
@ RAYTRACE_ITERATION_LIMIT
@ IMAGES_NAME
Mask of the image names, having d where the output number will be placed.
@ PARTICLE_RADIUS
Displayed radius of particle in units of smoothing length.
@ SURFACE_RESOLUTION
Size of the grid used in MarchingCubes (in code units, not h).
@ RENDERER
Selected renderer.
@ SURFACE_LEVEL
Value of iso-surface being constructed; lower value means larget bodies.
@ SURFACE_SUN_INTENSITY
Intentity of the sun.
@ IMAGES_SAVE
If true, rendered images are saved to disk.
@ SURFACE_SUN_POSITION
Direction to the sun used for shading.
@ SURFACE_AMBIENT
Ambient color for surface renderer.
AutoPtr< IColorizer > getColorizer(const Project &project, const ExtColorizerId id)
Definition: Factory.cpp:198
AutoPtr< IRenderer > getRenderer(const GuiSettings &settings)
Definition: Factory.cpp:58
AutoPtr< ICamera > getCamera(const GuiSettings &settings, const Pixel size)
Definition: Factory.cpp:28
DirectoryAdapter iterateDirectory(const Path &directory)
Definition: FileSystem.cpp:338
Vector position(const Float a, const Float e, const Float u)
Computes the position on the elliptic trajectory.
Definition: TwoBody.cpp:82
Definition: MemoryPool.h:5
Definition: Point.h:101
Parameters of the rendered image.
Definition: IRenderer.h:60
AutoPtr< ICamera > camera
Camera used for rendering.
Definition: IRenderer.h:63