9 #include "imstkAccumulationBuffer.h" 10 #include "imstkEventObject.h" 11 #include "imstkMath.h" 16 #include <unordered_map> 17 #include <unordered_set> 23 class CameraController;
29 class TaskGraphController;
30 class TrackingDeviceControl;
32 namespace ParallelUtils {
class SpinLock; }
37 bool trackFPS =
false;
40 bool taskParallelizationEnabled =
false;
43 bool taskTimingEnabled =
false;
46 bool writeTaskGraph =
false;
49 bool graphReductionEnabled =
true;
52 bool debugCamBoundingBox =
true;
64 using NamedMap = std::unordered_map<std::string, std::shared_ptr<T>>;
66 Scene(
const std::string& name, std::shared_ptr<SceneConfig> config = std::make_shared<SceneConfig>());
67 ~
Scene()
override =
default;
70 SIGNAL(
Scene, configureTaskGraph);
75 SIGNAL(
Scene, modified);
81 virtual bool initialize();
86 void computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner,
const double paddingPercent = 0.0);
91 void buildTaskGraph();
106 void resetSceneObjects();
111 virtual void advance(
const double dt);
116 virtual void updateVisuals(
const double dt);
122 void setEnableTaskTiming(
const bool enabled);
127 const std::unordered_set<std::shared_ptr<Entity>>&
getSceneObjects()
const {
return m_sceneEntities; }
132 std::shared_ptr<Entity> getSceneObject(
const std::string& name)
const;
137 void addInteraction(std::shared_ptr<Entity> interaction);
142 bool hasEntity(std::shared_ptr<Entity> entity) {
return m_sceneEntities.find(entity) != m_sceneEntities.end(); }
147 void addSceneObject(std::shared_ptr<Entity> entity);
152 void removeSceneObject(
const std::string& name);
157 void removeSceneObject(std::shared_ptr<Entity> sceneObject);
162 const std::vector<std::shared_ptr<Light>> getLights()
const;
167 std::shared_ptr<Light> getLight(
const std::string& lightName)
const;
172 const std::unordered_map<std::string, std::shared_ptr<Camera>>&
getCameras()
const {
return m_cameras; }
177 void addLight(
const std::string& name, std::shared_ptr<Light> newLight);
182 void removeLight(
const std::string& lightName);
187 void setGlobalIBLProbe(std::shared_ptr<IblProbe> newIBLProbe) { m_globalIBLProbe = newIBLProbe; }
197 const std::string&
getName()
const {
return m_name; }
204 std::string getUniqueName(
const std::string& name)
const;
209 std::shared_ptr<TaskGraph>
getTaskGraph()
const {
return m_taskGraph; }
219 std::string getCameraName(
const std::shared_ptr<Camera> cam)
const;
224 std::shared_ptr<Camera> getCamera(
const std::string name)
const;
229 void addCamera(
const std::string& name, std::shared_ptr<Camera> cam);
235 void setActiveCamera(
const std::string name);
240 void removeCamera(
const std::string name);
245 void addControl(std::shared_ptr<DeviceControl> control);
252 double getFrameTime()
const {
return m_frameTimes.getAverage(); }
267 void lockComputeTimes();
268 void unlockComputeTimes();
274 std::shared_ptr<SceneConfig>
getConfig()
const {
return m_config; };
277 std::shared_ptr<SceneConfig> m_config;
280 std::unordered_set<std::shared_ptr<Entity>> m_sceneEntities;
281 std::unordered_map<std::string, std::shared_ptr<Light>> m_lightsMap;
282 std::shared_ptr<IblProbe> m_globalIBLProbe =
nullptr;
284 std::unordered_map<std::string, std::shared_ptr<Camera>> m_cameras;
285 std::shared_ptr<Camera> m_activeCamera;
288 std::shared_ptr<TaskGraphController> m_taskGraphController =
nullptr;
289 std::function<void(Scene*)> m_postTaskGraphConfigureCallback =
nullptr;
291 std::shared_ptr<ParallelUtils::SpinLock> m_computeTimesLock;
296 double m_sceneTime = 0.0;
298 std::atomic<bool> m_resetRequested = ATOMIC_VAR_INIT(
false);
bool hasEntity(std::shared_ptr< Entity > entity)
Check if Entity exists in scene.
std::unordered_map< std::string, double > m_nodeComputeTimes
Map of ComputeNode names to elapsed times for benchmarking.
void setGlobalIBLProbe(std::shared_ptr< IblProbe > newIBLProbe)
Set global IBL probe.
const std::string & getName() const
Get the name of the scene.
const std::unordered_map< std::string, double > & getTaskComputeTimes() const
Get the map of elapsed times.
std::shared_ptr< TaskGraph > m_taskGraph
Computational graph.
std::shared_ptr< TaskGraph > getTaskGraph() const
Get the computational graph of the scene.
std::shared_ptr< Camera > getActiveCamera() const
Get the active camera for the scene.
std::shared_ptr< IblProbe > getGlobalIBLProbe()
Return global IBL probe.
std::string m_name
Name of the scene.
A collection of SceneObjects and interactions.
EventObject is the base class for all objects in iMSTK that can receive and emit events. It supports direct and queued observer functions. Direct observers receive events immediately on the same thread This can either be posted on an object or be a function pointer Queued observers receive events within their queue which they can process whenever they like. These can be connected with the connect/queuedConnect/disconnect functions Lambda recievers cannot be disconnected unless all receivers to a signal are removed.
double getFPS() const
Set/Get the frames per second (FPS)
std::shared_ptr< SceneConfig > getConfig() const
Get the configuration.
const std::unordered_map< std::string, std::shared_ptr< Camera > > & getCameras() const
Get and unordered map of cameras with names.
const std::unordered_set< std::shared_ptr< Entity > > & getSceneObjects() const
Return the SceneObjects of the scene.
double getSceneTime() const
Get the total scene time passed (accumulated deltatime)