-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwxVTKWidget.hpp
122 lines (102 loc) · 4.07 KB
/
wxVTKWidget.hpp
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
/*
Copyright 2019 Balázs Ludmány
This file is part of contours-viewer.
contours-viewer 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.
contours-viewer 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 contours-viewer. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WXVTKWIDGET_HPP
#define WXVTKWIDGET_HPP
#include <unordered_map>
#include <memory>
#include <dependencies.hpp>
#include <vtkGenericRenderWindowInteractor.h>
#include <vtkNew.h>
#include <vtkSmartPointer.h>
#include <vtkCallbackCommand.h>
#ifdef GD_FOUND
# include <gdpp.h>
#endif //GD_FOUND
#include <wx/timer.h>
#include <wx/glcanvas.h>
#include <vector>
#undef TrueColor
class wxVTKWidget : public wxGLCanvas {
wxGLContext *m_context;
vtkSmartPointer<vtkGenericRenderWindowInteractor> m_interactor;
public:
template<typename... Args>
explicit wxVTKWidget(Args&&... args) :
wxGLCanvas(std::forward<Args>(args)...) {
//wxGLContextAttrs attrs;
//attrs.PlatformDefaults().CoreProfile().OGLVersion(3, 2).EndList();
m_context = new wxGLContext(this);
m_create_timer_callback->SetClientData(this);
m_create_timer_callback->SetCallback(&wxVTKWidget::CreateTimer);
m_destroy_timer_callback->SetClientData(this);
m_destroy_timer_callback->SetCallback(&wxVTKWidget::DestroyTimer);
m_render_callback->SetClientData(this);
m_render_callback->SetCallback(&wxVTKWidget::RenderCallback);
m_make_current_callback->SetClientData(this);
m_make_current_callback->SetCallback(&wxVTKWidget::MakeCurrentCallback);
m_swap_buffers_callback->SetClientData(this);
m_swap_buffers_callback->SetCallback(&wxVTKWidget::SwapBuffersCallback);
}
void SetRenderWindowInteractor(vtkGenericRenderWindowInteractor *interactor);
void ResetCamera();
#ifdef GD_FOUND
GD::Image Screenshot();
#endif //GD_FOUND
private:
// Window events
void Resize(wxSizeEvent &event);
// Rendering events
bool m_init_window = false;
static void RenderCallback(vtkObject* source, unsigned long eid, void* clientData, void* callData);
static void MakeCurrentCallback(vtkObject* source, unsigned long eid, void* clientData, void* callData);
static void SwapBuffersCallback(vtkObject* source, unsigned long eid, void* clientData, void* callData);
void Render(wxPaintEvent &event);
int m_rotation = 0;
inline void SetButtonInformation(const wxMouseEvent &event);
void LeftDown(wxMouseEvent &event);
void LeftUp(wxMouseEvent &event);
void MiddleDown(wxMouseEvent &event);
void MiddleUp(wxMouseEvent &event);
void RightDown(wxMouseEvent &event);
void RightUp(wxMouseEvent &event);
void Motion(wxMouseEvent &event);
void Enter(wxMouseEvent &event);
void Leave(wxMouseEvent &event);
void Wheel(wxMouseEvent &event);
class CustomTimer final : public wxTimer {
wxVTKWidget *m_target;
int m_platformId;
public:
CustomTimer(wxVTKWidget *target, int platformId) :
m_target(target), m_platformId(platformId) {
}
void Notify() final {
m_target->Timer(m_platformId);
}
};
std::unordered_map<int, std::unique_ptr<CustomTimer> > m_timers;
int m_next_timer = 1;
static void CreateTimer(vtkObject* source, unsigned long eid, void* clientData, void* callData);
static void DestroyTimer(vtkObject* source, unsigned long eid, void* clientData, void* callData);
void Timer(int platformId);
// Callback commands
vtkNew<vtkCallbackCommand> m_create_timer_callback;
vtkNew<vtkCallbackCommand> m_destroy_timer_callback;
vtkNew<vtkCallbackCommand> m_render_callback;
vtkNew<vtkCallbackCommand> m_make_current_callback;
vtkNew<vtkCallbackCommand> m_swap_buffers_callback;
DECLARE_EVENT_TABLE()
};
#endif // WXVTKWIDGET_HPP