-
Notifications
You must be signed in to change notification settings - Fork 27
/
VtkViewer.h
114 lines (98 loc) · 3.17 KB
/
VtkViewer.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
#pragma once
#include <iostream>
#include <string>
#include <exception>
#include "imgui.h"
#include <vtkProp.h>
#include <vtkPropCollection.h>
#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkCallbackCommand.h>
#include <vtkCommand.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkOpenGLFramebufferObject.h>
#include <vtkGenericRenderWindowInteractor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderer.h>
// RGB Color in range [0.0, 1.0]
#define DEFAULT_BACKGROUND 0.39, 0.39, 0.39
// Alpha value in range [0.0, 1.0] where 1 = opaque
#define DEFAULT_ALPHA 1
class VtkViewerError : public std::runtime_error {
public:
explicit VtkViewerError(const std::string& message) throw() : std::runtime_error(message) {}
~VtkViewerError() = default;
public:
virtual char const* what() const throw() {
return exception::what();
}
};
class VtkViewer {
private:
static void isCurrentCallbackFn(vtkObject* caller, long unsigned int eventId, void* clientData, void* callData);
void processEvents();
private:
vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow;
vtkSmartPointer<vtkGenericRenderWindowInteractor> interactor;
vtkSmartPointer<vtkInteractorStyleTrackballCamera> interactorStyle;
vtkSmartPointer<vtkRenderer> renderer;
private:
unsigned int viewportWidth, viewportHeight;
unsigned int tex;
bool firstRender;
public:
VtkViewer();
VtkViewer(const VtkViewer& vtkViewer);
VtkViewer(VtkViewer&& vtkViewer) noexcept;
~VtkViewer();
VtkViewer& operator=(const VtkViewer& vtkViewer);
private:
IMGUI_IMPL_API void init();
public:
IMGUI_IMPL_API void render();
IMGUI_IMPL_API void render(const ImVec2 size);
IMGUI_IMPL_API void addActor(const vtkSmartPointer<vtkProp>& actor);
IMGUI_IMPL_API void addActors(const vtkSmartPointer<vtkPropCollection>& actors);
IMGUI_IMPL_API void removeActor(const vtkSmartPointer<vtkProp>& actor);
void setViewportSize(const ImVec2 newSize);
public:
static inline unsigned int NoScrollFlags(){
return ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse;
}
public:
inline void setRenderWindow(const vtkSmartPointer<vtkGenericOpenGLRenderWindow>& renderWindow) {
this->renderWindow = renderWindow;
}
inline void setInteractor(const vtkSmartPointer<vtkGenericRenderWindowInteractor>& interactor) {
this->interactor = interactor;
}
inline void setInteractorStyle(const vtkSmartPointer<vtkInteractorStyleTrackballCamera>& interactorStyle) {
this->interactorStyle = interactorStyle;
}
inline void setRenderer(const vtkSmartPointer<vtkRenderer>& renderer) {
this->renderer = renderer;
}
public:
inline vtkSmartPointer<vtkGenericOpenGLRenderWindow>& getRenderWindow() {
return renderWindow;
}
inline vtkSmartPointer<vtkGenericRenderWindowInteractor>& getInteractor() {
return interactor;
}
inline vtkSmartPointer<vtkInteractorStyleTrackballCamera>& getInteractorStyle() {
return interactorStyle;
}
inline vtkSmartPointer<vtkRenderer>& getRenderer() {
return renderer;
}
public:
inline unsigned int getViewportWidth() const {
return viewportWidth;
}
inline unsigned int getViewportHeight() const {
return viewportHeight;
}
inline unsigned int getTexture() const {
return tex;
}
};