SPH
|
Main GUI class connection the simulation with UI controls. More...
#include <Controller.h>
Public Member Functions | |
Controller (wxWindow *parent) | |
Initialize the controller. More... | |
~Controller () | |
RawPtr< RunPage > | getPage () const |
bool | isRunning () const |
Returns true if a simulation is running. More... | |
Array< SharedPtr< IColorizer > > | getColorizerList (const Storage &storage) const |
const wxBitmap & | getRenderedBitmap () const |
Renders a bitmap of current view. More... | |
AutoPtr< ICamera > | getCurrentCamera () const |
Returns the camera currently used for the rendering. More... | |
SharedPtr< IColorizer > | getCurrentColorizer () const |
Returns the colorizer currently used for rendering into the window. More... | |
Optional< Size > | getIntersectedParticle (const Pixel position, const float toleranceEps) |
Returns the particle under given image position, or NOTHING if such particle exists. More... | |
Optional< Size > | getSelectedParticle () const |
const Storage & | getStorage () const |
GuiSettings & | getParams () |
Returns the settings object. More... | |
void | update (const Storage &storage, const Statistics &stats) |
Updates the colorizer list, reset the camera and the renderer, etc. More... | |
void | setColorizer (const SharedPtr< IColorizer > &newColorizer) |
Sets a new colorizer to be displayed. More... | |
void | setRenderer (AutoPtr< IRenderer > &&newRenderer) |
Sets a new renderer used to draw particles. More... | |
void | setSelectedParticle (const Optional< Size > &particleIdx) |
Sets a selected particle or changes the current selection. More... | |
void | setPaletteOverride (const Palette palette) |
Modifies the color palette for current colorizer. More... | |
bool | tryRedraw () |
If possible, redraws the particles with data from storage. More... | |
void | redrawOnNextTimeStep () |
Redraws the image on the following timestep. More... | |
void | refresh (AutoPtr< ICamera > &&camera) |
Re-renders the particles with given camera. More... | |
void | start (SharedPtr< INode > run, const RunSettings &globals) |
Sets up and starts a new simulation. More... | |
void | open (const Path &path, const bool sequence=false) |
Opens a simulation snapshot from given file. More... | |
void | restart () |
Starts the simulation with current setup. More... | |
void | pause () |
Pause the current simulation. More... | |
void | stop (const bool waitForFinish=false) |
Stops the current simulation. More... | |
RunStatus | getStatus () const |
Returns the current status of the run. More... | |
void | saveState (const Path &path) |
Saves the state of the current run to the disk. More... | |
void | quit (const bool waitForFinish=false) |
Closes down the model, clears all allocated resources. Must be called only once. More... | |
void | setAutoZoom (const bool enable) |
Enables or disables auto-zoom during the simulation. More... | |
![]() | |
virtual | ~Polymorphic () |
Main GUI class connection the simulation with UI controls.
Definition at line 42 of file Controller.h.
using Controller::TimeStepCallback = Function<void(const Storage& storage, const Statistics& stats)> |
List of callbacks executed on the next timestep (on run thread).
The list is cleared every timestep, only callbacks added between timesteps are executed.
Definition at line 70 of file Controller.h.
NAMESPACE_SPH_BEGIN Controller::Controller | ( | wxWindow * | parent | ) |
Initialize the controller.
Definition at line 26 of file Controller.cpp.
Controller::~Controller | ( | ) |
Definition at line 39 of file Controller.cpp.
Array< SharedPtr< IColorizer > > Controller::getColorizerList | ( | const Storage & | storage | ) | const |
Returns a list of quantities that can be displayed.
storage | Particle storage containing data for the colorizer |
Definition at line 407 of file Controller.cpp.
Returns the camera currently used for the rendering.
Definition at line 437 of file Controller.cpp.
SharedPtr< IColorizer > Controller::getCurrentColorizer | ( | ) | const |
Returns the colorizer currently used for rendering into the window.
Definition at line 432 of file Controller.cpp.
Optional< Size > Controller::getIntersectedParticle | ( | const Pixel | position, |
const float | toleranceEps | ||
) |
Returns the particle under given image position, or NOTHING if such particle exists.
position | Position in image coordinates, corresponding to the latest rendered image. |
toleranceEps | Relative addition to effective radius of a particle; particles are considered to be under the point of they are closer than (displayedRadius * (1+toleranceEps)). |
Definition at line 442 of file Controller.cpp.
Definition at line 43 of file Controller.cpp.
GuiSettings & Controller::getParams | ( | ) |
Returns the settings object.
Definition at line 316 of file Controller.cpp.
const wxBitmap & Controller::getRenderedBitmap | ( | ) | const |
Renders a bitmap of current view.
Can only be called from main thread.
Definition at line 426 of file Controller.cpp.
Definition at line 570 of file Controller.cpp.
RunStatus Controller::getStatus | ( | ) | const |
Returns the current status of the run.
Definition at line 146 of file Controller.cpp.
const Storage & Controller::getStorage | ( | ) | const |
Definition at line 574 of file Controller.cpp.
bool Controller::isRunning | ( | ) | const |
Returns true if a simulation is running.
Definition at line 348 of file Controller.cpp.
void Controller::open | ( | const Path & | path, |
const bool | sequence = false |
||
) |
Opens a simulation snapshot from given file.
Definition at line 92 of file Controller.cpp.
void Controller::pause | ( | ) |
Pause the current simulation.
Can only be paused at the beginning of a timestep. The function is not blocking, it does not wait until the simulation completes the current timestep. Simulation can be continued using start function or stopped with stop.
Definition at line 127 of file Controller.cpp.
void Controller::quit | ( | const bool | waitForFinish = false | ) |
Closes down the model, clears all allocated resources. Must be called only once.
Definition at line 185 of file Controller.cpp.
void Controller::redrawOnNextTimeStep | ( | ) |
Redraws the image on the following timestep.
This function is only needed if parameter REFRESH_ON_TIMESTEP is false, otherwise the image is redrawn every time.
Definition at line 634 of file Controller.cpp.
Re-renders the particles with given camera.
Other input data for the render (particles, colors, ...) remain unchanged. Function is non-blocking, it only flags the current render as "dirty" and exits, the image is later re-rendered from render thread. Can be called from any thread.
Definition at line 638 of file Controller.cpp.
void Controller::restart | ( | ) |
Starts the simulation with current setup.
Function does nothing if the simulation is already running. Can be used to continue paused simulation.
Definition at line 105 of file Controller.cpp.
void Controller::saveState | ( | const Path & | path | ) |
Saves the state of the current run to the disk.
path | Path to the file where the run state is saved (as binary data). |
Definition at line 150 of file Controller.cpp.
void Controller::setAutoZoom | ( | const bool | enable | ) |
Enables or disables auto-zoom during the simulation.
Definition at line 213 of file Controller.cpp.
void Controller::setColorizer | ( | const SharedPtr< IColorizer > & | newColorizer | ) |
Sets a new colorizer to be displayed.
If the run is currently stopped, the colorizer is applied immediately, otherwise it is necessary to wait for the end of the current timestep before repaiting the particles. Must be called from main thread.
newColorizer | Colorizer replacing the current one. |
Definition at line 509 of file Controller.cpp.
void Controller::setPaletteOverride | ( | const Palette | palette | ) |
Modifies the color palette for current colorizer.
Function must be called from main thread.
Definition at line 562 of file Controller.cpp.
Sets a new renderer used to draw particles.
If the run is currently stopped, the renderer is replaced immediately, otherwise it is necessary to wait for the end of the current timestep before repainting the particles. Must be called from main thread.
newRenderer | Renderer replacing the current one. |
Definition at line 520 of file Controller.cpp.
Sets a selected particle or changes the current selection.
The selection only affects the interactive view; it can be used by the renderer to highlight a selected particle, and the window can provide information about the selected particle.
particleIdx | Particle to selected; if NOTHING, the current selection is cleared. |
Definition at line 543 of file Controller.cpp.
void Controller::start | ( | SharedPtr< INode > | run, |
const RunSettings & | globals | ||
) |
Sets up and starts a new simulation.
Must be called before any other run-related functions can be called. If a simulation is currently running, it waits until the simulation stops and then starts the new simulation.
run | New simulation to start |
Definition at line 74 of file Controller.cpp.
void Controller::stop | ( | const bool | waitForFinish = false | ) |
Stops the current simulation.
If no simulation is running, the function does nothing. Next usage of start will start the simulation from the beginning.
waitForFinish | If true, the function will block until the run is finished. Otherwise the function is nonblocking. |
Definition at line 132 of file Controller.cpp.
bool Controller::tryRedraw | ( | ) |
If possible, redraws the particles with data from storage.
This can be done when the run is paused or stopped. Otherwise, it is necessary to wait for the next time step; function does nothing during the run. Needs to be called from main thread.
Definition at line 611 of file Controller.cpp.
void Controller::update | ( | const Storage & | storage, |
const Statistics & | stats | ||
) |
Updates the colorizer list, reset the camera and the renderer, etc.
This does not have to be called manually, unless the run changes parameters in the middle of the simulation (for example handoff in composite run). This also creates a new image sequence, so it is necesary to set up new image path or filename mask prior to calling update, otherwise the previously generated images will be overwritten.
Definition at line 320 of file Controller.cpp.
RunSettings Controller::globals |
Definition at line 57 of file Controller.h.
Locking<Array<TimeStepCallback> > Controller::onTimeStepCallbacks |
Definition at line 71 of file Controller.h.
Path Controller::path |
Path to the loaded file, if used.
Definition at line 62 of file Controller.h.
Root node of the simulation.
Definition at line 55 of file Controller.h.
std::atomic_bool Controller::shouldContinue |
Flag read by the simulation; the run is stopped if this is set to zero.
Definition at line 65 of file Controller.h.
Definition at line 59 of file Controller.h.
std::thread Controller::thread |
Thread running the simulation.
Definition at line 52 of file Controller.h.