1 /**
2  * @class   vtkF3DRenderer
3  * @brief   A F3D dedicated renderer
4  *
5  * This renderers all the generic actors added by F3D which includes
6  * axis, grid, edges, timer, filename, metadata and cheatsheet.
7  * It also handles the different rendering passes, including
8  * raytracing, ssao, fxaa, tonemapping.
9  */
10 
11 #ifndef vtkF3DRenderer_h
12 #define vtkF3DRenderer_h
13 
14 #include "F3DOptions.h"
15 
16 #include <vtkOpenGLRenderer.h>
17 #include <vtkOrientationMarkerWidget.h>
18 #include <vtkSkybox.h>
19 
20 class vtkCornerAnnotation;
21 class vtkTextActor;
22 
23 class vtkF3DRenderer : public vtkOpenGLRenderer
24 {
25 public:
26   static vtkF3DRenderer* New();
27   vtkTypeMacro(vtkF3DRenderer, vtkOpenGLRenderer);
28 
29   //@{
30   /**
31    * Set/Get visibility of different actors
32    */
33   void ShowAxis(bool show);
34   void ShowGrid(bool show);
35   void ShowEdge(bool show);
36   void ShowTimer(bool show);
37   void ShowMetaData(bool show);
38   void ShowFilename(bool show);
39   void ShowCheatSheet(bool show);
40   bool IsAxisVisible();
41   bool IsGridVisible();
42   bool IsEdgeVisible();
43   bool IsTimerVisible();
44   bool IsFilenameVisible();
45   bool IsMetaDataVisible();
46   bool IsCheatSheetVisible();
47   //@}
48 
49   //@{
50   /**
51    * Set/Get usages of different render passes
52    */
53   void SetUseRaytracing(bool use);
54   void SetUseRaytracingDenoiser(bool use);
55   void SetUseDepthPeelingPass(bool use);
56   void SetUseSSAOPass(bool use);
57   void SetUseFXAAPass(bool use);
58   void SetUseToneMappingPass(bool use);
59   void SetUseBlurBackground(bool use);
60   void SetUseTrackball(bool use);
61   bool UsingRaytracing();
62   bool UsingRaytracingDenoiser();
63   bool UsingDepthPeelingPass();
64   bool UsingSSAOPass();
65   bool UsingFXAAPass();
66   bool UsingToneMappingPass();
67   bool UsingBlurBackground();
68   bool UsingTrackball();
69   //@}
70 
71   /**
72    * Reimplemented to handle cheat sheet and timer
73    */
74   void Render() override;
75 
76   /**
77    * Initialize the renderer to be used with provided options and file.
78    * Should be called after being added to a vtkRenderWindow.
79    */
80   virtual void Initialize(const F3DOptions& options, const std::string& fileInfo);
81 
82   //@{
83   /**
84    * Set/Get the axis widget
85    */
86   vtkGetSmartPointerMacro(AxisWidget, vtkOrientationMarkerWidget);
87   vtkSetSmartPointerMacro(AxisWidget, vtkOrientationMarkerWidget);
88   //@}
89 
90   /**
91    * Get the OpenGL skybox
92    */
93   vtkGetObjectMacro(Skybox, vtkSkybox);
94 
95   /**
96    * Set the visibility of the different actors
97    * as they were set by the options during the initialization.
98    * Also call UpdateInternalActors
99    */
100   void ShowOptions();
101 
102   /**
103    * Setup the different render passes
104    * as they were set by the options during the initialization.
105    */
106   void SetupRenderPasses();
107 
108   /**
109    * Initialize the camera position, focal point,
110    * view up and view angle according to the options if any
111    */
112   void InitializeCamera();
113 
114   /**
115    * Reset the camera to its initial parameters
116    */
117   void ResetCamera() override;
118 
119   /**
120    * Dump useful scene state. Currently supports only camera state.
121    */
122   void DumpSceneState();
123 
124   //@{
125   /**
126    * Set/Get up vector
127    */
128   vtkGetVector3Macro(UpVector, double);
129   vtkSetVector3Macro(UpVector, double);
130   //@}
131 
132   //@{
133   /**
134    * Set/Get right vector
135    */
136   vtkGetVector3Macro(RightVector, double);
137   vtkSetVector3Macro(RightVector, double);
138   //@}
139 
140   /**
141    * Override to update internal actors that display data
142    * in a specific way
143    */
UpdateInternalActors()144   virtual void UpdateInternalActors(){};
145 
146 protected:
147   vtkF3DRenderer();
148   ~vtkF3DRenderer() override;
149 
150   void ReleaseGraphicsResources(vtkWindow* w) override;
151 
152   bool IsBackgroundDark();
153 
154   /**
155    * Update the text of the cheatsheet and mark it for rendering
156    */
157   void UpdateCheatSheet();
158 
159   /**
160    * Add related hotkeys options to the cheatsheet.
161    * Override to add other hotkeys
162    */
163   virtual void FillCheatSheetHotkeys(std::stringstream& sheet);
164 
165   /**
166    * Override to generate a data description
167    */
168   virtual std::string GenerateMetaDataDescription();
169 
170   F3DOptions Options;
171 
172   vtkNew<vtkActor> GridActor;
173 
174   vtkNew<vtkSkybox> Skybox;
175   vtkNew<vtkCamera> InitialCamera;
176 
177   vtkSmartPointer<vtkOrientationMarkerWidget> AxisWidget;
178 
179   vtkNew<vtkCornerAnnotation> FilenameActor;
180   vtkNew<vtkCornerAnnotation> MetaDataActor;
181   vtkNew<vtkCornerAnnotation> CheatSheetActor;
182   bool CheatSheetNeedUpdate = false;
183 
184   // vtkCornerAnnotation building is too slow for the timer
185   vtkNew<vtkTextActor> TimerActor;
186   unsigned int Timer = 0;
187 
188   bool GridVisible = false;
189   bool AxisVisible = false;
190   bool EdgesVisible = false;
191   bool TimerVisible = false;
192   bool FilenameVisible = false;
193   bool MetaDataVisible = false;
194   bool CheatSheetVisible = false;
195   bool UseRaytracing = false;
196   bool UseRaytracingDenoiser = false;
197   bool UseDepthPeelingPass = false;
198   bool UseFXAAPass = false;
199   bool UseSSAOPass = false;
200   bool UseToneMappingPass = false;
201   bool UseBlurBackground = false;
202   bool UseTrackball = false;
203 
204   double UpVector[3] = { 0.0, 1.0, 0.0 };
205   double RightVector[3] = { 1.0, 0.0, 0.0 };
206   int UpIndex = 1;
207 };
208 
209 #endif
210