iMSTK
Interactive Medical Simulation Toolkit
Public Types | Public Member Functions | Protected Attributes | List of all members
imstk::Scene Class Reference

A collection of SceneObjects and interactions. More...

#include <imstkScene.h>

Inheritance diagram for imstk::Scene:
Inheritance graph
[legend]
Collaboration diagram for imstk::Scene:
Collaboration graph
[legend]

Public Types

template<class T >
using NamedMap = std::unordered_map< std::string, std::shared_ptr< T > >
 
- Public Types inherited from imstk::EventObject
using Observer = std::tuple< bool, std::weak_ptr< EventObject >, std::function< void(Event *)> >
 

Public Member Functions

 Scene (const std::string &name, std::shared_ptr< SceneConfig > config=std::make_shared< SceneConfig >())
 
 SIGNAL (Scene, configureTaskGraph)
 
 SIGNAL (Scene, modified)
 Called when scene is modified, when scene objects or interactions are added/removed.
 
virtual bool initialize ()
 Initialize the scene.
 
void computeBoundingBox (Vec3d &lowerCorner, Vec3d &upperCorner, const double paddingPercent=0.0)
 Compute the bounding box of the scene as an union of bounding boxes of its objects.
 
void buildTaskGraph ()
 Setup the task graph, this completely rebuilds the graph.
 
void initTaskGraph ()
 Initializes the graph after its in a built state.
 
void reset ()
 Async reset the scene, will reset next update.
 
void resetSceneObjects ()
 Sync reset, resets immediately.
 
virtual void advance (const double dt)
 Advance the scene from current to next frame with specified timestep.
 
virtual void updateVisuals (const double dt)
 Update visuals of all scene objects.
 
void setEnableTaskTiming (const bool enabled)
 If true, tasks will be time and a table produced every scene advance of the times.
 
const std::unordered_set< std::shared_ptr< Entity > > & getSceneObjects () const
 Return the SceneObjects of the scene.
 
std::shared_ptr< EntitygetSceneObject (const std::string &name) const
 Get SceneObject by name, returns nullptr if doesn't exist.
 
void addInteraction (std::shared_ptr< Entity > interaction)
 Add an interaction.
 
bool hasEntity (std::shared_ptr< Entity > entity)
 Check if Entity exists in scene.
 
void addSceneObject (std::shared_ptr< Entity > entity)
 Add a scene object.
 
void removeSceneObject (const std::string &name)
 Remove scene object by name.
 
void removeSceneObject (std::shared_ptr< Entity > sceneObject)
 Remove scene object.
 
const std::vector< std::shared_ptr< Light > > getLights () const
 Return a vector of lights in the scene.
 
std::shared_ptr< LightgetLight (const std::string &lightName) const
 Get a light with a given name.
 
const std::unordered_map< std::string, std::shared_ptr< Camera > > & getCameras () const
 Get and unordered map of cameras with names.
 
void addLight (const std::string &name, std::shared_ptr< Light > newLight)
 Add light from the scene.
 
void removeLight (const std::string &lightName)
 Remove light with a given name from the scene.
 
void setGlobalIBLProbe (std::shared_ptr< IblProbe > newIBLProbe)
 Set global IBL probe.
 
std::shared_ptr< IblProbegetGlobalIBLProbe ()
 Return global IBL probe.
 
const std::string & getName () const
 Get the name of the scene.
 
std::string getUniqueName (const std::string &name) const
 Given a desired name, produce a unique one. This name would be iterated with a postfix # should one already exist.
 
std::shared_ptr< TaskGraphgetTaskGraph () const
 Get the computational graph of the scene.
 
std::shared_ptr< CameragetActiveCamera () const
 Get the active camera for the scene.
 
std::string getCameraName (const std::shared_ptr< Camera > cam) const
 Get the name of the camera given the object (if it exists)
 
std::shared_ptr< CameragetCamera (const std::string name) const
 Get camera object given the name.
 
void addCamera (const std::string &name, std::shared_ptr< Camera > cam)
 Set the camera for the scene.
 
void setActiveCamera (const std::string name)
 Switch the active camera to the one requested by name. If the requested on doesn't exist, previous on remains.
 
void removeCamera (const std::string name)
 Remove the camera with a given name.
 
void addControl (std::shared_ptr< DeviceControl > control)
 Adds a device control to a newly created SceneObject.
 
double getFPS () const
 Set/Get the frames per second (FPS)
 
double getFrameTime () const
 
double getSceneTime () const
 Get the total scene time passed (accumulated deltatime)
 
const std::unordered_map< std::string, double > & getTaskComputeTimes () const
 Get the map of elapsed times.
 
std::shared_ptr< SceneConfiggetConfig () const
 Get the configuration.
 
void lockComputeTimes ()
 Lock/Unlock the compute times resource.
 
void unlockComputeTimes ()
 
- Public Member Functions inherited from imstk::EventObject
template<typename T >
void postEvent (const T &e)
 Emits the event Direct observers will be immediately called, in sync Queued observers will receive the Command in their queue for later execution, reciever must implement doEvent.
 
template<typename T >
void queueEvent (const T &e)
 Queues event directly to this.
 
void doEvent ()
 Do an event, if none exists return.
 
void doAllEvents ()
 Do all the events in the event queue.
 
void foreachEvent (std::function< void(Command cmd)> func)
 Thread safe loop over all event commands, one can implement a custom handler.
 
void rforeachEvent (std::function< void(Command cmd)> func)
 thread safe reverse loop over all event commands, one can implement a custom handler
 
void clearEvents ()
 Removes all events from queue cleans up copies of the event.
 

Protected Attributes

std::shared_ptr< SceneConfigm_config
 
std::string m_name
 Name of the scene.
 
std::unordered_set< std::shared_ptr< Entity > > m_sceneEntities
 
std::unordered_map< std::string, std::shared_ptr< Light > > m_lightsMap
 
std::shared_ptr< IblProbem_globalIBLProbe = nullptr
 
std::unordered_map< std::string, std::shared_ptr< Camera > > m_cameras
 
std::shared_ptr< Cameram_activeCamera
 
std::shared_ptr< TaskGraphm_taskGraph
 Computational graph.
 
std::shared_ptr< TaskGraphControllerm_taskGraphController = nullptr
 Controller for the computational graph.
 
std::function< void(Scene *)> m_postTaskGraphConfigureCallback = nullptr
 
std::shared_ptr< ParallelUtils::SpinLockm_computeTimesLock
 
std::unordered_map< std::string, double > m_nodeComputeTimes
 Map of ComputeNode names to elapsed times for benchmarking.
 
AccumulationBuffer< double > m_frameTimes = AccumulationBuffer<double>(1024)
 
double m_fps = 0.0
 
double m_sceneTime = 0.0
 Scene time/simulation total time, updated at the end of scene update.
 
std::atomic< bool > m_resetRequested = ATOMIC_VAR_INIT(false)
 
- Protected Attributes inherited from imstk::EventObject
ParallelUtils::SpinLock eventQueueLock
 
std::deque< CommandeventQueue
 
std::vector< std::pair< std::string, std::vector< Observer > > > queuedObservers
 
std::vector< std::pair< std::string, std::vector< Observer > > > directObservers
 

Detailed Description

A collection of SceneObjects and interactions.

Definition at line 60 of file imstkScene.h.


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