SPH
Classes | Public Member Functions | List of all members
Controller Class Reference

Main GUI class connection the simulation with UI controls. More...

#include <Controller.h>

Inheritance diagram for Controller:
IJobCallbacks IRunCallbacks Polymorphic

Public Member Functions

 Controller (wxWindow *parent)
 Initialize the controller. More...
 
 ~Controller ()
 
RawPtr< RunPagegetPage () 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< ICameragetCurrentCamera () const
 Returns the camera currently used for the rendering. More...
 
SharedPtr< IColorizergetCurrentColorizer () const
 Returns the colorizer currently used for rendering into the window. More...
 
Optional< SizegetIntersectedParticle (const Pixel position, const float toleranceEps)
 Returns the particle under given image position, or NOTHING if such particle exists. More...
 
Optional< SizegetSelectedParticle () const
 
const StoragegetStorage () const
 
GuiSettingsgetParams ()
 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...
 
- Public Member Functions inherited from Polymorphic
virtual ~Polymorphic ()
 

Detailed Description

Main GUI class connection the simulation with UI controls.

Definition at line 42 of file Controller.h.

Member Typedef Documentation

◆ TimeStepCallback

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.

Constructor & Destructor Documentation

◆ Controller()

NAMESPACE_SPH_BEGIN Controller::Controller ( wxWindow *  parent)

Initialize the controller.

Definition at line 26 of file Controller.cpp.

◆ ~Controller()

Controller::~Controller ( )

Definition at line 39 of file Controller.cpp.

Member Function Documentation

◆ getColorizerList()

Array< SharedPtr< IColorizer > > Controller::getColorizerList ( const Storage storage) const

Returns a list of quantities that can be displayed.

Parameters
storageParticle storage containing data for the colorizer

Definition at line 407 of file Controller.cpp.

◆ getCurrentCamera()

AutoPtr< ICamera > Controller::getCurrentCamera ( ) const

Returns the camera currently used for the rendering.

Definition at line 437 of file Controller.cpp.

◆ getCurrentColorizer()

SharedPtr< IColorizer > Controller::getCurrentColorizer ( ) const

Returns the colorizer currently used for rendering into the window.

Definition at line 432 of file Controller.cpp.

◆ getIntersectedParticle()

Optional< Size > Controller::getIntersectedParticle ( const Pixel  position,
const float  toleranceEps 
)

Returns the particle under given image position, or NOTHING if such particle exists.

Parameters
positionPosition in image coordinates, corresponding to the latest rendered image.
toleranceEpsRelative addition to effective radius of a particle; particles are considered to be under the point of they are closer than (displayedRadius * (1+toleranceEps)).
Todo:
This is really weird, we are duplicating code of ParticleRenderer in a function that really makes only sense with ParticleRenderer. Needs refactoring.
Todo:
this radius computation is actually renderer-specific ...
Todo:
wait, -INFTY != -inf ?? // (first.t == -INFTY) {

Definition at line 442 of file Controller.cpp.

◆ getPage()

RawPtr< RunPage > Controller::getPage ( ) const

Definition at line 43 of file Controller.cpp.

◆ getParams()

GuiSettings & Controller::getParams ( )

Returns the settings object.

Definition at line 316 of file Controller.cpp.

◆ getRenderedBitmap()

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.

◆ getSelectedParticle()

Optional< Size > Controller::getSelectedParticle ( ) const

Definition at line 570 of file Controller.cpp.

◆ getStatus()

RunStatus Controller::getStatus ( ) const

Returns the current status of the run.

Definition at line 146 of file Controller.cpp.

◆ getStorage()

const Storage & Controller::getStorage ( ) const
Todo:
synchronize

Definition at line 574 of file Controller.cpp.

◆ isRunning()

bool Controller::isRunning ( ) const

Returns true if a simulation is running.

Definition at line 348 of file Controller.cpp.

◆ open()

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.

◆ pause()

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.

◆ quit()

void Controller::quit ( const bool  waitForFinish = false)

Closes down the model, clears all allocated resources. Must be called only once.

Todo:
is this necessary? why not just use status?

Definition at line 185 of file Controller.cpp.

◆ redrawOnNextTimeStep()

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.

◆ refresh()

void Controller::refresh ( AutoPtr< ICamera > &&  camera)

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.

Todo:
generalize

Definition at line 638 of file Controller.cpp.

◆ restart()

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.

◆ saveState()

void Controller::saveState ( const Path path)

Saves the state of the current run to the disk.

Parameters
pathPath to the file where the run state is saved (as binary data).

Definition at line 150 of file Controller.cpp.

◆ setAutoZoom()

void Controller::setAutoZoom ( const bool  enable)

Enables or disables auto-zoom during the simulation.

Definition at line 213 of file Controller.cpp.

◆ setColorizer()

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.

Parameters
newColorizerColorizer replacing the current one.

Definition at line 509 of file Controller.cpp.

◆ setPaletteOverride()

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.

◆ setRenderer()

void Controller::setRenderer ( AutoPtr< IRenderer > &&  newRenderer)

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.

Parameters
newRendererRenderer replacing the current one.

Definition at line 520 of file Controller.cpp.

◆ setSelectedParticle()

void Controller::setSelectedParticle ( const Optional< Size > &  particleIdx)

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.

Parameters
particleIdxParticle to selected; if NOTHING, the current selection is cleared.
Todo:
if the colorizer is not initialized, we should selected the particle after the next timestep

Definition at line 543 of file Controller.cpp.

◆ start()

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.

Parameters
runNew simulation to start

Definition at line 74 of file Controller.cpp.

◆ stop()

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.

Parameters
waitForFinishIf true, the function will block until the run is finished. Otherwise the function is nonblocking.

Definition at line 132 of file Controller.cpp.

◆ tryRedraw()

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.

Returns
true if the image has been redrawn.

Definition at line 611 of file Controller.cpp.

◆ update()

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.

Member Data Documentation

◆ globals

RunSettings Controller::globals

Definition at line 57 of file Controller.h.

◆ onTimeStepCallbacks

Locking<Array<TimeStepCallback> > Controller::onTimeStepCallbacks

Definition at line 71 of file Controller.h.

◆ path

Path Controller::path

Path to the loaded file, if used.

Definition at line 62 of file Controller.h.

◆ run

SharedPtr<INode> Controller::run

Root node of the simulation.

Definition at line 55 of file Controller.h.

◆ shouldContinue

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.

◆ storage

RawPtr<const Storage> Controller::storage

Definition at line 59 of file Controller.h.

◆ thread

std::thread Controller::thread

Thread running the simulation.

Definition at line 52 of file Controller.h.


The documentation for this class was generated from the following files: