forked from martijnkoopman/Qt-VTK-viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenewidget.cpp
63 lines (51 loc) · 1.7 KB
/
scenewidget.cpp
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
#include "scenewidget.h"
#include <vtkCamera.h>
#include <vtkDataSetMapper.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkProperty.h>
#include <vtkRenderWindowInteractor.h>
SceneWidget::SceneWidget(QWidget* parent)
: QVTKOpenGLNativeWidget(parent)
{
vtkNew<vtkGenericOpenGLRenderWindow> window;
setRenderWindow(window.Get());
// Camera
vtkSmartPointer<vtkCamera> camera = vtkSmartPointer<vtkCamera>::New();
camera->SetViewUp(0, 1, 0);
camera->SetPosition(0, 0, 10);
camera->SetFocalPoint(0, 0, 0);
// Renderer
m_renderer = vtkSmartPointer<vtkRenderer>::New();
m_renderer->SetActiveCamera(camera);
m_renderer->SetBackground(0.5, 0.5, 0.5);
renderWindow()->AddRenderer(m_renderer);
}
void SceneWidget::addDataSet(vtkSmartPointer<vtkDataSet> dataSet)
{
// Actor
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
// Mapper
vtkSmartPointer<vtkDataSetMapper> mapper = vtkSmartPointer<vtkDataSetMapper>::New();
mapper->SetInputData(dataSet);
actor->SetMapper(mapper);
m_renderer->AddActor(actor);
m_renderer->ResetCamera(dataSet->GetBounds());
renderWindow()->Render();
}
void SceneWidget::removeDataSet()
{
vtkActor* actor = m_renderer->GetActors()->GetLastActor();
if (actor != nullptr) {
m_renderer->RemoveActor(actor);
}
renderWindow()->Render();
}
void SceneWidget::zoomToExtent()
{
// Zoom to extent of last added actor
vtkSmartPointer<vtkActor> actor = m_renderer->GetActors()->GetLastActor();
if (actor != nullptr) {
m_renderer->ResetCamera(actor->GetBounds());
}
renderWindow()->Render();
}