13 #include <condition_variable>
15 #include <wx/dcmemory.h>
26 : renderer(
std::move(renderer))
27 , colorizers(
std::move(colorizers))
28 , params(
std::move(params)) {
38 paths =
OutputFile(directory / name, firstIndex);
41 animationPath = directory / animationName;
43 std::call_once(
initFlag, wxInitAllImageHandlers);
44 nextOutput = outputStep;
50 std::string escaped =
replaceAll(name,
" ",
"");
57 std::condition_variable waitVar;
75 this->updateMainThread(bitmap, std::move(labels));
77 std::unique_lock<std::mutex> lock(waitMutex);
79 std::unique_lock<std::mutex> lock(waitMutex);
80 this->updateMainThread(bitmap, std::move(labels));
88 update(bitmap, std::move(labels), isFinal);
98 dc.SelectObject(wxNullBitmap);
108 this->
save(storage, stats);
109 nextOutput += outputStep;
114 const Float dt = time - lastFrame;
118 Vector dir = cameraPos - target;
120 if (cameraOrbit != 0._f) {
123 dir = rotation * dir;
127 if (params.
tracker !=
nullptr) {
128 Vector trackedPos, trackedVel;
142 for (
const auto& e : colorizers) {
153 renderer->
render(params, stats, output);
158 params.
camera = std::move(camera);
162 if (!makeAnimation) {
166 for (
auto& e : colorizers) {
168 std::string outPath = animationPath.
native();
void saveToFile(const wxBitmap &wx, const Path &path)
NAMESPACE_SPH_BEGIN void toWxBitmap(const Bitmap< Rgba > &bitmap, wxBitmap &wx)
Wrapper of wxBitmap, will be possibly replaced by custom implementation.
Defines projection transforming 3D particles onto 2D screen.
bool isMainThread()
Checks if the calling thread is the main thred.
Helper functions to check the internal consistency of the code.
@ MAIN_THREAD
Function can only be executed from main thread.
#define CHECK_FUNCTION(flags)
Object converting quantity values of particles into colors.
uint32_t Size
Integral type used to index arrays (by default).
double Float
Precision used withing the code. Use Float instead of float or double where precision is important.
NAMESPACE_SPH_BEGIN void executeOnMainThread(const Function< void()> &function)
Posts a callback to be executed on main thread.
Posting events to be executed on main thread.
NAMESPACE_SPH_BEGIN std::once_flag initFlag
INLINE std::string escapeColorizerName(const std::string &name)
Periodically saves rendered images to disk.
#define INLINE
Macros for conditional compilation based on selected compiler.
#define NAMESPACE_SPH_END
Creating and managing processes.
StaticArray< T0 &, sizeof...(TArgs)+1 > tie(T0 &t0, TArgs &... rest)
Creates a static array from a list of l-value references.
Statistics gathered and periodically displayed during the run.
@ RUN_TIME
Current time of the simulation in code units. Does not necessarily have to be 0 when run starts.
std::string replaceAll(const std::string &source, const std::string &old, const std::string &s)
Replaces all occurences of string with a new string.
std::string lowercase(const std::string &s)
Converts all uppercase characters to their lowercase variants. Other characters are unchanged.
void printLabels(wxDC &dc, ArrayView< const IRenderOutput::Label > labels)
Random utility functions for drawing stuff to DC.
INLINE Vector translation() const
static AffineMatrix rotateAxis(const Vector &axis, const Float angle)
Generic dynamically allocated resizable storage.
INLINE TValue get(const GuiSettingsId id) const
virtual AffineMatrix getFrame() const =0
Returns the transformation matrix converting camera space to world space.
virtual Vector getTarget() const =0
Returns the current target point of the camera.
virtual void setTarget(const Vector &newTarget)=0
virtual void setPosition(const Vector &newPosition)=0
Moves the camera to new position in world space.
virtual Vector getUpVector() const =0
Returns the reference "up" direction of the camera.
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 ¶ms, Statistics &stats, IRenderOutput &output) const =0
Draws particles into the bitmap, given the data provided in initialize.
virtual Pair< Vector > getTrackedPoint(const Storage &storage) const =0
void setPath(const Path &path)
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.
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.
Movie(const GuiSettings &settings, AutoPtr< IRenderer > &&renderer, Array< AutoPtr< IColorizer >> &&colorizers, RenderParams &¶ms)
void onTimeStep(const Storage &storage, Statistics &stats)
Called every time step, saves the images every IMAGES_TIMESTEP.
void save(const Storage &storage, Statistics &stats)
Manually saves the images.
void setEnabled(const bool enable=true)
void finalize()
Creates the animations from generated images.
void setCamera(AutoPtr< ICamera > &&camera)
Helper file generating file names for output files.
Path getNextPath(const Statistics &stats) const
Returns path to the next output file.
Path getMask() const
Returns the file mask as given in constructor.
Object representing a path on a filesystem.
std::string native() const
Returns the native version of the path.
Path parentPath() const
Returns the parent directory. If the path is empty or root, return empty path.
Holds a handle to a created process.
void wait()
Blocks the calling thread until the managed process exits. The function may block indefinitely.
Object holding various statistics about current run.
TValue get(const StatisticsId idx) const
Returns value of a statistic.
TValue getOr(const StatisticsId idx, const TValue &other) const
Returns value of a statistic, or a given value if the statistic is not stored.
Container storing all quantities used within the simulations.
@ IMAGES_NAME
Mask of the image names, having d where the output number will be placed.
@ IMAGES_PATH
Path of directory where the rendered images will be saved.
@ IMAGES_SAVE
If true, rendered images are saved to disk.
Outcome createDirectory(const Path &path, const Flags< CreateDirectoryFlag > flags=CreateDirectoryFlag::ALLOW_EXISTING)
Creates a directory with given path. Creates all parent directories as well.
Overload of std::swap for Sph::Array.
Parameters of the rendered image.
AutoPtr< ICamera > camera
Camera used for rendering.
AutoPtr< ITracker > tracker
Tracker used for camera motion.