CAD Viewer
VRRenderThread.h
Go to the documentation of this file.
1 
9 #ifndef VR_RENDER_THREAD_H
10 #define VR_RENDER_THREAD_H
11 
12  /* Project headers */
13 
14  /* Qt headers */
15 #include <QThread>
16 #include <QMutex>
17 #include <QWaitCondition>
18 
19 /* Vtk headers */
20 #include <vtkActor.h>
21 #include <vtkOpenVRRenderWindow.h>
22 #include <vtkOpenVRRenderWindowInteractor.h>
23 #include <vtkOpenVRRenderer.h>
24 #include <vtkOpenVRCamera.h>
25 #include <vtkActorCollection.h>
26 #include <vtkCommand.h>
27 #include <openvr.h>
28 
29 
30 
31 /* Note that this class inherits from the Qt class QThread which allows it to be a parallel thread
32  * to the main() thread.
33  */
34 class VRRenderThread : public QThread {
35  Q_OBJECT
36 
37 public:
39  enum {
43  ROTATE_Z
45 
46 
49  VRRenderThread(QObject* parent = nullptr);
50 
54 
58  void addActorOffline(vtkActor* actor);
59 
60 
65  void issueCommand(int cmd, double value);
66 
67 
68 protected:
71  void run() override;
72 
73 private:
74  /* Standard VTK VR Classes */
75  vtkSmartPointer<vtkOpenVRRenderWindow> window;
76  vtkSmartPointer<vtkOpenVRRenderWindowInteractor> interactor;
77  vtkSmartPointer<vtkOpenVRRenderer> renderer;
78  vtkSmartPointer<vtkOpenVRCamera> camera;
79 
80  /* Use to synchronise passing of data to VR thread */
81  QMutex mutex;
82  QWaitCondition condition;
83 
85  vtkSmartPointer<vtkActorCollection> actors;
86 
88  std::chrono::time_point<std::chrono::steady_clock> t_last;
89 
93  bool endRender;
94 
95  /* Some variables to indicate animation actions to apply.
96  *
97  */
98  double rotateX; /*< Degrees to rotate around X axis (per time-step) */
99  double rotateY; /*< Degrees to rotate around Y axis (per time-step) */
100  double rotateZ; /*< Degrees to rotate around Z axis (per time-step) */
101 };
102 
103 
104 
105 #endif
106 #pragma once
Definition: VRRenderThread.h:34
std::chrono::time_point< std::chrono::steady_clock > t_last
Definition: VRRenderThread.h:88
void addActorOffline(vtkActor *actor)
Definition: VRRenderThread.cpp:53
vtkSmartPointer< vtkOpenVRCamera > camera
Definition: VRRenderThread.h:78
double rotateY
Definition: VRRenderThread.h:99
~VRRenderThread()
Definition: VRRenderThread.cpp:49
VRRenderThread(QObject *parent=nullptr)
Definition: VRRenderThread.cpp:33
vtkSmartPointer< vtkActorCollection > actors
Definition: VRRenderThread.h:85
double rotateZ
Definition: VRRenderThread.h:100
double rotateX
Definition: VRRenderThread.h:98
vtkSmartPointer< vtkOpenVRRenderWindowInteractor > interactor
Definition: VRRenderThread.h:76
enum VRRenderThread::@0 Command
vtkSmartPointer< vtkOpenVRRenderWindow > window
Definition: VRRenderThread.h:75
QMutex mutex
Definition: VRRenderThread.h:81
void issueCommand(int cmd, double value)
Definition: VRRenderThread.cpp:71
QWaitCondition condition
Definition: VRRenderThread.h:82
bool endRender
Definition: VRRenderThread.h:93
vtkSmartPointer< vtkOpenVRRenderer > renderer
Definition: VRRenderThread.h:77
@ END_RENDER
Definition: VRRenderThread.h:40
@ ROTATE_Z
Definition: VRRenderThread.h:43
@ ROTATE_Y
Definition: VRRenderThread.h:42
@ ROTATE_X
Definition: VRRenderThread.h:41
void run() override
Definition: VRRenderThread.cpp:100