VTK  9.1.0
vtkVRRenderWindow.h
Go to the documentation of this file.
1/*=========================================================================
2
3Program: Visualization Toolkit
4Module: vtkVRRenderWindow.h
5
6Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7All rights reserved.
8See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10This software is distributed WITHOUT ANY WARRANTY; without even
11the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
36#ifndef vtkVRRenderWindow_h
37#define vtkVRRenderWindow_h
38
39#include "vtkEventData.h" // for enums
40#include "vtkOpenGLHelper.h" // used for ivars
42#include "vtkRenderingVRModule.h" // For export macro
43#include "vtk_glew.h" // used for methods
44
45#include <vector> // ivars
46
47class vtkCamera;
48class vtkMatrix4x4;
49class vtkVRModel;
51class vtkTransform;
52
53class VTKRENDERINGVR_EXPORT vtkVRRenderWindow : public vtkOpenGLRenderWindow
54{
55public:
56 enum
57 {
58 PhysicalToWorldMatrixModified = vtkCommand::UserEvent + 200
59 };
60
61 enum
62 {
63 LeftEye = 0,
64 RightEye
65 };
66
68 void PrintSelf(ostream& os, vtkIndent indent) override;
69
75
77
80 GLuint GetLeftResolveBufferId() { return this->FramebufferDescs[LeftEye].ResolveFramebufferId; }
81 GLuint GetRightResolveBufferId() { return this->FramebufferDescs[RightEye].ResolveFramebufferId; }
82 void GetRenderBufferSize(int& width, int& height)
83 {
84 width = this->Size[0];
85 height = this->Size[1];
86 }
88
93 {
94 return this->GetTrackedDeviceModel(idx, 0);
95 }
96 vtkVRModel* GetTrackedDeviceModel(uint32_t idx) { return this->TrackedDeviceToRenderModel[idx]; }
97 virtual vtkVRModel* GetTrackedDeviceModel(vtkEventDataDevice idx, uint32_t index) = 0;
98
108
110
118 virtual void SetPhysicalViewDirection(double, double, double);
119 virtual void SetPhysicalViewDirection(double[3]);
120 vtkGetVector3Macro(PhysicalViewDirection, double);
122
124
132 virtual void SetPhysicalViewUp(double, double, double);
133 virtual void SetPhysicalViewUp(double[3]);
134 vtkGetVector3Macro(PhysicalViewUp, double);
136
138
146 virtual void SetPhysicalTranslation(double, double, double);
147 virtual void SetPhysicalTranslation(double[3]);
148 vtkGetVector3Macro(PhysicalTranslation, double);
150
152
161 virtual void SetPhysicalScale(double);
162 vtkGetMacro(PhysicalScale, double);
164
176
180 virtual void AddRenderer(vtkRenderer*) override;
181
185 virtual void Start() override;
186
190 virtual void Initialize() override;
191
197 virtual void Finalize() override;
198
202 void MakeCurrent() override;
203
207 void ReleaseCurrent() override;
208
212 virtual bool IsCurrent() override;
213
217 const char* ReportCapabilities() override { return "VR System"; }
218
222 vtkTypeBool IsDirect() override { return 1; }
223
229 virtual vtkTypeBool GetEventPending() override { return 0; }
230
234 virtual int* GetScreenSize() override;
235
237
244 void SetSize(int width, int height) override;
245 void SetSize(int a[2]) override { this->SetSize(a[0], a[1]); }
247
248 // implement required virtual functions
249 virtual void* GetGenericDisplayId() override
250 {
251 return (void*)this->HelperWindow->GetGenericDisplayId();
252 }
253 virtual void* GetGenericWindowId() override
254 {
255 return (void*)this->HelperWindow->GetGenericWindowId();
256 }
257 virtual void* GetGenericParentId() override { return (void*)nullptr; }
258 virtual void* GetGenericContext() override
259 {
260 return (void*)this->HelperWindow->GetGenericContext();
261 }
262 virtual void* GetGenericDrawable() override
263 {
264 return (void*)this->HelperWindow->GetGenericDrawable();
265 }
266
270 virtual int SupportsOpenGL() override { return 1; }
271
276 virtual void Render() override;
277
281 vtkGetObjectMacro(HelperWindow, vtkOpenGLRenderWindow);
283
284 // Get the state object used to keep track of
285 // OpenGL state
287
293
297 virtual void RenderModels() = 0;
298
305 vtkEventDataDevice device, vtkMatrix4x4* poseMatrixWorld) = 0;
306
308
312 vtkSetMacro(TrackHMD, bool);
313 vtkGetMacro(TrackHMD, bool);
315
316 virtual void UpdateHMDMatrixPose(){};
317
318protected:
321
322 virtual void CreateAWindow() override {}
323 virtual void DestroyWindow() override {}
324
330 virtual bool GetSizeFromAPI() = 0;
331
332 virtual std::string GetWindowTitleFromAPI() { return "VTK - VR"; }
333
335 {
336 GLuint ResolveFramebufferId = 0;
337 GLuint ResolveColorTextureId = 0;
338 GLuint ResolveDepthTextureId = 0;
339 };
340
341 // One per view (typically one per eye)
342 std::vector<FramebufferDesc> FramebufferDescs;
343
344 virtual bool CreateFramebuffers() = 0;
345
346 void RenderFramebuffer(FramebufferDesc& framebufferDesc);
347
349
350 std::vector<vtkVRModel*> VTKRenderModels;
351 // This vector must be resized in subclass with the maximum number of devices
352 std::vector<vtkVRModel*> TrackedDeviceToRenderModel;
353
354 // used in computing the pose
357 double PhysicalViewDirection[3];
359 double PhysicalViewUp[3];
361 double PhysicalTranslation[3];
364
366
367private:
368 vtkVRRenderWindow(const vtkVRRenderWindow&) = delete;
369 void operator=(const vtkVRRenderWindow&) = delete;
370};
371
372#endif
a virtual camera for 3D rendering
Definition: vtkCamera.h:155
a simple class to control print indentation
Definition: vtkIndent.h:113
represent and manipulate 4x4 transformation matrices
Definition: vtkMatrix4x4.h:145
OpenGL rendering window.
OpenGL state storage.
platform-independent render window interaction including picking and frame rate control.
abstract specification for renderers
Definition: vtkRenderer.h:182
describes linear transformations via a 4x4 matrix
Definition: vtkTransform.h:164
VR device model.
Definition: vtkVRModel.h:41
VR rendering window.
vtkVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx)
Get the VRModel corresponding to the tracked device.
virtual bool IsCurrent() override
Tells if this window is the current OpenGL context for the calling thread.
virtual void SetPhysicalTranslation(double, double, double)
Set/get physical coordinate system in world coordinate system.
virtual void Initialize() override
Initialize the rendering window.
virtual vtkVRModel * GetTrackedDeviceModel(vtkEventDataDevice idx, uint32_t index)=0
void MakeCurrent() override
Make this windows OpenGL context the current context.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void ReleaseGraphicsResources(vtkWindow *) override
Free up any graphics resources associated with this window a value of nullptr means the context may a...
virtual void Start() override
Begin the rendering process.
virtual void Render() override
Overridden to not release resources that would interfere with an external application's rendering.
virtual void SetPhysicalViewUp(double[3])
const char * ReportCapabilities() override
Get report of capabilities for the render window.
virtual void RenderModels()=0
Render the controller and base station models.
vtkOpenGLRenderWindow * HelperWindow
virtual void CreateAWindow() override
Create a not-off-screen window.
virtual void Finalize() override
Finalize the rendering window.
std::vector< vtkVRModel * > VTKRenderModels
void RenderFramebuffer(FramebufferDesc &framebufferDesc)
virtual void SetPhysicalScale(double)
Set/get physical coordinate system in world coordinate system.
virtual void SetPhysicalViewDirection(double[3])
virtual bool CreateFramebuffers()=0
~vtkVRRenderWindow() override
virtual void UpdateHMDMatrixPose()
virtual void * GetGenericDrawable() override
Dummy stubs for vtkWindow API.
virtual bool GetSizeFromAPI()=0
Attempt to get the size of the display from the API and store it in this->Size.
GLuint GetLeftResolveBufferId()
Get the frame buffers used for rendering.
std::vector< vtkVRModel * > TrackedDeviceToRenderModel
void SetSize(int width, int height) override
Set the size of the window in screen coordinates in pixels.
virtual int * GetScreenSize() override
Get the current size of the screen in pixels.
virtual vtkTypeBool GetEventPending() override
Check to see if a mouse button has been pressed or mouse wheel activated.
virtual int SupportsOpenGL() override
Does this render window support OpenGL? 0-false, 1-true.
vtkTransform * HMDTransform
virtual void * GetGenericDisplayId() override
Dummy stubs for vtkWindow API.
virtual void SetPhysicalViewDirection(double, double, double)
Set/get physical coordinate system in world coordinate system.
virtual void SetPhysicalTranslation(double[3])
virtual void * GetGenericParentId() override
Dummy stubs for vtkWindow API.
vtkOpenGLState * GetState() override
void GetRenderBufferSize(int &width, int &height)
GLuint GetRightResolveBufferId()
vtkVRModel * GetTrackedDeviceModel(uint32_t idx)
void SetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Set physical to world transform matrix.
vtkTypeBool IsDirect() override
Is this render window using hardware acceleration? 0-false, 1-true.
virtual void * GetGenericContext() override
Dummy stubs for vtkWindow API.
virtual void InitializeViewFromCamera(vtkCamera *cam)
Initialize the HMD to World setting and camera settings so that the VR world view most closely matche...
virtual void * GetGenericWindowId() override
Dummy stubs for vtkWindow API.
std::vector< FramebufferDesc > FramebufferDescs
virtual void AddRenderer(vtkRenderer *) override
Add a renderer to the list of renderers.
void SetHelperWindow(vtkOpenGLRenderWindow *val)
double PhysicalScale
Scale of the Physical to World matrix.
virtual std::string GetWindowTitleFromAPI()
virtual bool GetPoseMatrixWorldFromDevice(vtkEventDataDevice device, vtkMatrix4x4 *poseMatrixWorld)=0
Store in poseMatrixWorld the pose matrix in world coordinate from an event data device.
void SetSize(int a[2]) override
Set the size of the window in screen coordinates in pixels.
virtual void DestroyWindow() override
Destroy a not-off-screen window.
vtkRenderWindowInteractor * MakeRenderWindowInteractor() override=0
Create an interactor to control renderers in this window.
void ReleaseCurrent() override
Release the current context.
virtual void SetPhysicalViewUp(double, double, double)
Set/get physical coordinate system in world coordinate system.
void GetPhysicalToWorldMatrix(vtkMatrix4x4 *matrix)
Get physical to world transform matrix.
window superclass for vtkRenderWindow
Definition: vtkWindow.h:39
int vtkTypeBool
Definition: vtkABI.h:69
vtkEventDataDevice
platform-independent event data structures
Definition: vtkEventData.h:26