-
Notifications
You must be signed in to change notification settings - Fork 0
/
rendercone.h
122 lines (112 loc) · 3.53 KB
/
rendercone.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
115
116
117
118
119
120
121
122
#pragma once
#include <vtkCellLocator.h>
#include <vtkSmartPointer.h>
#include <vtkOBJReader.h>
#include <vtkPLYReader.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPointPicker.h>
#include <vtkSphereSource.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkInteractorStyleRubberBandPick.h>
#include <vtkConeSource.h>
#include <vtkProperty.h>
#include <vtkPLYWriter.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkCell.h>
#include <vtkPoints.h>
#include <vtkCellLocator.h>
class renderCone
{
public:
renderCone()
{
renderer =
vtkSmartPointer<vtkRenderer>::New();
}
vtkSmartPointer<vtkRenderWindowInteractor> Getrenderwindow() {
return this->renderWindowInteractor;
}
void SetChild(renderCone* child)
{
next = child;
}
void SetColor(double r, double g, double b)
{
renderer->SetBackground(r, g, b); // Background color dark red
}
void SetActor(vtkSmartPointer<vtkActor>& getactor)//ÉèÖÃactor
{
actor = getactor;
}
void SetPos(double* inputpos) {
double pos[3];
pos[0] = inputpos[0];
pos[1] = inputpos[1];
pos[2] = inputpos[2];
vtkSmartPointer<vtkSphereSource> sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->SetPosition(pos);
actor->SetScale(0.2);//ÉèÖÃÏÔʾµãµÄ´óС
actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
renderer->AddActor(actor);
}
void SetInteractor() {
renderWindowInteractor->SetPicker(pointPicker);
}
void Render()
{
//Create a cone
coneSource =
vtkSmartPointer<vtkConeSource>::New();
coneSource->Update();
//Create a mapper and actor
//mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
//mapper->SetInputConnection(coneSource->GetOutputPort());
//actor =
// vtkSmartPointer<vtkActor>::New();
//actor->SetMapper(mapper);
renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
//renderWindowInteractor =
// vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
//Add the actors to the scene
renderer->AddActor(actor);
//vtkSmartPointer<PointPickerInteractorStyle> interactorStyle =
// vtkSmartPointer<PointPickerInteractorStyle>::New();
//renderWindowInteractor->SetInteractorStyle(interactorStyle);
//vtkSmartPointer<vtkInteractorStyleRubberBandPick> interactorStyle = vtkSmartPointer<vtkInteractorStyleRubberBandPick>::New();
//renderWindowInteractor->SetInteractorStyle(interactorStyle);
//Render and interact
renderWindow->Render();
if (next == nullptr)
{
renderWindowInteractor->Start();
}
}
public:
vtkSmartPointer<vtkConeSource> coneSource;
vtkSmartPointer<vtkPolyDataMapper> mapper;
vtkSmartPointer<vtkActor> actor;
vtkSmartPointer<vtkRenderer> renderer;
vtkSmartPointer<vtkRenderWindow> renderWindow;
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor= vtkSmartPointer<vtkRenderWindowInteractor>::New();;
vtkSmartPointer<vtkPointPicker> pointPicker;
renderCone* next{ nullptr };
};