-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqquickvtkrenderitem.h
50 lines (45 loc) · 1.45 KB
/
qquickvtkrenderitem.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
#ifndef MyQQuickVTKRenderItem_H
#define MyQQuickVTKRenderItem_H
// Qt includes
#include <QObject>
#include <QOpenGLFunctions> // For QOpenGLFunctions
#include <QQuickItem>
// vtk includes
#include <vtkWeakPointer.h> // For vtkWeakPointer
#include <vtkGUISupportQtQuickModule.h> // for export macro
#include <vtkNew.h> // For vtkNew
#include <vtkRenderer.h> // For vtkRenderer
#include <vtkImageData.h>
#include <QQuickVTKRenderItem.h>
#include "CommandModel.h"
#include <queue>
#include <future>
#include "qtvtkitem.h"
class qtVtkItem;
class MyQQuickVTKRenderItem :
public QQuickVTKRenderItem
{
public:
void sync() override;
void setqtvtkItem(qtVtkItem *item){qtvtkItem = item;};
//template<class F, class... Args>
//std::future<void>& pushCommandToQueue(F&& f, Args&&... args);
private:
qtVtkItem *qtvtkItem;
std::queue<std::function<void()>> CommandQueue;
public:
template<class F, class... Args>
std::future<void>& pushCommandToQueue(F&& f, Args&&... args)
{
using return_type = typename std::result_of<F(Args...)>::type;
auto task = std::make_shared< std::packaged_task<return_type()> >(
std::bind(std::forward<F>(f), std::forward<Args>(args)...)
);
std::future<return_type> res = task->get_future();
{
CommandQueue.emplace([task]() { (*task)(); });
}
return res;
}
};
#endif // MyQQuickVTKRenderItem_H