iMSTK
Interactive Medical Simulation Toolkit
imstkViewer.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkRenderer.h"
10 #include "imstkModule.h"
11 
12 #include <unordered_map>
13 
14 namespace imstk
15 {
16 class Camera;
17 class Entity;
18 class InteractorStyle;
19 class KeyboardDeviceClient;
20 class MouseDeviceClient;
21 class Scene;
22 class ScreenCaptureUtility;
23 
25 {
26  std::string m_windowName = "imstk";
27 
28  bool m_hideCurzor = false;
29  bool m_hideBorder = true;
30  bool m_fullScreen = false;
31 
32  int m_renderWinWidth = 1000;
33  int m_renderWinHeight = 800;
34 };
35 
43 class Viewer : public Module
44 {
45 protected:
46  Viewer(std::string name);
47 public:
48  ~Viewer() override = default;
49 
53  std::shared_ptr<Scene> getActiveScene() const { return m_activeScene; }
54 
58  void setDebugAxesLength(double x, double y, double z);
59 
63  virtual void setActiveScene(std::shared_ptr<Scene> scene) = 0;
64 
69  virtual void setRenderingMode(const Renderer::Mode mode) = 0;
70 
74  virtual void setSize(int, int) { }
75  void setSize(Vec2i size) { setSize(size[0], size[1]); }
76 
77  virtual const Vec2i getSize() const { return Vec2i::Zero(); }
78 
82  virtual Renderer::Mode getRenderingMode() const { return Renderer::Mode::Empty; }
83 
87  std::shared_ptr<Renderer> getActiveRenderer() const;
88 
92  virtual void setUseVsync(const bool) { }
93 
97  virtual void setWindowTitle(const std::string& title) = 0;
98 
103  virtual void setInfoLevel(const int level);
104 
108  int getInfoLevel() const { return m_infoLevel; }
109 
113  virtual const int getInfoLevelCount() const { return 1; }
114 
118  std::shared_ptr<ScreenCaptureUtility> getScreenCaptureUtility() const { return m_screenCapturer; }
119 
124  virtual void setBackgroundColors(const Color color1, const Color color2 = Color(0.0, 0.0, 0.0), const bool gradientBackground = false) = 0;
125 
126  virtual void processEvents() = 0;
127 
131  virtual std::shared_ptr<KeyboardDeviceClient> getKeyboardDevice() const;
132 
136  virtual std::shared_ptr<MouseDeviceClient> getMouseDevice() const;
137 
138  double getVisualFps() const { return m_visualFps; }
139 
140 protected:
144  void updateFps();
145 
146  void updateModule() override;
147 
148  std::unordered_map<std::shared_ptr<Scene>, std::shared_ptr<Renderer>> m_rendererMap;
149 
150  std::shared_ptr<Scene> m_activeScene;
151  std::shared_ptr<Entity> m_debugEntity;
152  std::shared_ptr<Camera> m_debugCamera;
153  std::shared_ptr<ScreenCaptureUtility> m_screenCapturer;
154 
155  std::shared_ptr<ViewerConfig> m_config;
156  int m_infoLevel = 0;
157 
158  std::chrono::high_resolution_clock::time_point m_pre;
159  std::chrono::high_resolution_clock::time_point m_post;
160  std::chrono::high_resolution_clock::time_point m_lastFpsUpdate;
161 
162  double m_visualFps = 0.0;
163  double m_lastFps = 0.0;
164 };
165 } // namespace imstk
std::chrono::high_resolution_clock::time_point m_pre
time point pre-rendering
Definition: imstkViewer.h:158
std::chrono::high_resolution_clock::time_point m_lastFpsUpdate
time point for last framerate display update
Definition: imstkViewer.h:160
virtual void setUseVsync(const bool)
Set whether to sync frames to the refresh of the monitor.
Definition: imstkViewer.h:92
virtual const int getInfoLevelCount() const
Get the number of info levels for a viewer, varies on implementation.
Definition: imstkViewer.h:113
Compound Geometry.
std::shared_ptr< Scene > getActiveScene() const
Get scene currently being rendered.
Definition: imstkViewer.h:53
std::shared_ptr< ScreenCaptureUtility > getScreenCaptureUtility() const
access screen shot utility
Definition: imstkViewer.h:118
Base class for viewer that manages render window and the renderers Creates backend-specific renderers...
Definition: imstkViewer.h:43
int getInfoLevel() const
Get the current info level.
Definition: imstkViewer.h:108
virtual Renderer::Mode getRenderingMode() const
Get the current renderer&#39;s mode.
Definition: imstkViewer.h:82
std::shared_ptr< ScreenCaptureUtility > m_screenCapturer
Screen shot utility.
Definition: imstkViewer.h:153
Color in RGB space.
Definition: imstkColor.h:24
virtual void setSize(int, int)
Set the render window size.
Definition: imstkViewer.h:74
Mode
Enumerations for the render mode.
Definition: imstkRenderer.h:47
Base class for imstk module system. A module defines something that is updated, and can be paused/res...
Definition: imstkModule.h:21
std::chrono::high_resolution_clock::time_point m_post
time point post-rendering
Definition: imstkViewer.h:159