-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptExecutor.h
144 lines (117 loc) · 3.98 KB
/
ScriptExecutor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
File: ScriptExecutor.h
Created on: 15/05/2017
Author: Felix de las Pozas Alvarez
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCRIPTEXECUTOR_H_
#define SCRIPTEXECUTOR_H_
#include <QThread>
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <QList>
#include <QMutex>
#include <QWaitCondition>
class vtkRenderer;
class vtkActor;
class vtkVolume;
class vtkPlane;
class vtkImageData;
class vtkPolyData;
class ResourceLoaderThread;
/** \class ScriptExecutor
* \brief Modifies the scene and creates actors if needed for the frame. Signals for a frame creation once finished modifying the scene.
* This file needs to be modified as the script is pure C++.
*
*/
class ScriptExecutor
: public QThread
{
Q_OBJECT
public:
/** \brief ScriptExecutor class constructor.
* \param[in] renderer scene vtk renderer.
* \param[in] loader resource loader thread.
* \param[in] parent raw pointer of the QObject owner of this one.
*
*/
explicit ScriptExecutor(vtkSmartPointer<vtkRenderer> renderer, ResourceLoaderThread* loader, QObject *parent = nullptr);
/** \brief ScriptExecutor class virtual destructor.
*
*/
virtual ~ScriptExecutor()
{}
/** \brief Returns the error string.
*
*/
const QString getError() const
{ return m_error; }
/** \brief Signals the need to abort the script.
*
*/
void abort()
{ m_abort = true; }
/** \brief Wakes up the executor to create the next frame.
*
*/
void nextFrame()
{ m_waitCondition.wakeOne(); }
/** \brief Resets the initial data.
*
*/
void restart()
{ m_abort = false; }
signals:
void render();
protected:
virtual void run();
private:
/** \brief Helper method to render a given number of still frames.
* \param[in] numFrames number of still frames to render.
*
*/
void waitFrames(const unsigned int numFrames);
/** \brief Helper method to get the resources from the resource loader thread.
*
*/
void getResources(ResourceLoaderThread *loader);
/** \brief Modifies the error string.
* \param[in] message error message.
*
*/
void error(const QString &message)
{ m_error = message; }
/** \brief Signals the need to save the current frame and stops the execution until 'nextFrame()' method is called by the main application.
*
*/
void waitForFrameToRender();
QString m_error; /** error mesasge or empty if everything is good. */
bool m_abort; /** true to abort the current render. */
QMutex m_mutex; /** mutex for the wait condition. */
QWaitCondition m_waitCondition; /** wait condition for waiting for the main thread. */
// script commands
void threesixtynoscope(); // never got to make one in Counter Strike...
void reslice();
void fadeIn();
void fadeOut();
friend class MovieRenderer;
vtkSmartPointer<vtkRenderer> m_renderer; /** vtk renderer. */
// data for the script, depends on the scene.
vtkSmartPointer<vtkPlane> m_plane;
vtkSmartPointer<vtkImageData> m_image;
vtkSmartPointer<vtkImageData> m_mciImage;
vtkSmartPointer<vtkPolyData> m_brainMesh;
vtkSmartPointer<vtkPolyData> m_mciMesh;
vtkSmartPointer<vtkActor> m_brainActor;
vtkSmartPointer<vtkActor> m_mciActor;
};
#endif // SCRIPTEXECUTOR_H_