Repository navigation
Expand file tree
/
Copy pathvisualization.cpp
More file actions
59 lines (54 loc) · 2.3 KB
/
Copy pathvisualization.cpp
File metadata and controls
59 lines (54 loc) · 2.3 KB
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
#include "visualization.h"
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkSphereSource.h>
#include <vtkLineSource.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkProperty.h>
Visualizer::Visualizer() {
m_renderer = vtkSmartPointer<vtkRenderer>::New();
m_renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
m_interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
m_renderWindow->AddRenderer(m_renderer);
m_interactor->SetRenderWindow(m_renderWindow);
m_renderer->SetBackground(1.0, 1.0, 1.0); // 白色背景
}
void Visualizer::addModel(vtkSmartPointer<vtkPolyData> polyData, const Vector3D& color) {
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(polyData);
auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(color.x, color.y, color.z);
m_renderer->AddActor(actor);
}
void Visualizer::addSphereMarker(const Vector3D& center, double radius, const Vector3D& color) {
auto sphere = vtkSmartPointer<vtkSphereSource>::New();
sphere->SetCenter(center.x, center.y, center.z);
sphere->SetRadius(radius);
sphere->SetThetaResolution(20);
sphere->SetPhiResolution(20);
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphere->GetOutputPort());
auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(color.x, color.y, color.z);
m_renderer->AddActor(actor);
}
void Visualizer::addLineMarker(const Vector3D& p1, const Vector3D& p2, const Vector3D& color, double lineWidth) {
auto line = vtkSmartPointer<vtkLineSource>::New();
line->SetPoint1(p1.x, p1.y, p1.z);
line->SetPoint2(p2.x, p2.y, p2.z);
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(line->GetOutputPort());
auto actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(color.x, color.y, color.z);
actor->GetProperty()->SetLineWidth(lineWidth);
m_renderer->AddActor(actor);
}
void Visualizer::show() {
auto style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
m_interactor->SetInteractorStyle(style);
m_renderWindow->Render();
m_interactor->Start();
}