-
Notifications
You must be signed in to change notification settings - Fork 1
/
implicit_plane.cpp
97 lines (81 loc) · 3.12 KB
/
implicit_plane.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
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
#include "vtkActor.h"
#include "vtkAppendPolyData.h"
#include "vtkClipPolyData.h"
#include "vtkCommand.h"
#include "vtkConeSource.h"
#include "vtkGlyph3D.h"
#include "vtkImplicitPlaneWidget.h"
#include "vtkLODActor.h"
#include "vtkPlane.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkSphereSource.h"
namespace {
vtkSmartPointer<vtkPlane> plane;
vtkSmartPointer<vtkLODActor> select_actor;
vtkSmartPointer<vtkImplicitPlaneWidget> implicit_plane;
} // namespace
class MyCallback : public vtkCommand {
public:
static MyCallback* New() {
return new MyCallback();
}
void
Execute(vtkObject* caller, unsigned long eventId, void* callData) override {
implicit_plane->GetPlane(plane);
select_actor->VisibilityOn();
}
};
int main() {
const auto sphere = vtkSmartPointer<vtkSphereSource>::New();
const auto cone = vtkSmartPointer<vtkConeSource>::New();
const auto glyph = vtkSmartPointer<vtkGlyph3D>::New();
glyph->SetInputConnection(sphere->GetOutputPort());
glyph->SetSourceConnection(cone->GetOutputPort());
glyph->SetVectorModeToUseNormal();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.25);
const auto append = vtkSmartPointer<vtkAppendPolyData>::New();
append->AddInputConnection(glyph->GetOutputPort());
append->AddInputConnection(sphere->GetOutputPort());
const auto mace_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mace_mapper->SetInputConnection(append->GetOutputPort());
const auto mace_actor = vtkSmartPointer<vtkActor>::New();
mace_actor->SetMapper(mace_mapper);
mace_actor->VisibilityOn();
plane = vtkSmartPointer<vtkPlane>::New();
const auto clipper = vtkSmartPointer<vtkClipPolyData>::New();
clipper->SetInputConnection(append->GetOutputPort());
clipper->SetClipFunction(plane);
clipper->InsideOutOn();
const auto select_mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
select_mapper->SetInputConnection(clipper->GetOutputPort());
select_actor = vtkSmartPointer<vtkLODActor>::New();
select_actor->SetMapper(select_mapper);
select_actor->GetProperty()->SetColor(0, 1, 0);
select_actor->VisibilityOff();
select_actor->SetScale(1.01, 1.01, 1.01);
const auto render = vtkSmartPointer<vtkRenderer>::New();
render->AddActor(mace_actor);
render->AddActor(select_actor);
render->SetBackground(0.1, 0.2, 0.4);
const auto render_window = vtkSmartPointer<vtkRenderWindow>::New();
render_window->AddRenderer(render);
const auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(render_window);
const auto callback = vtkSmartPointer<MyCallback>::New();
interactor->AddObserver(vtkCommand::InteractionEvent, callback);
implicit_plane = vtkSmartPointer<vtkImplicitPlaneWidget>::New();
implicit_plane->SetInteractor(interactor);
implicit_plane->SetPlaceFactor(1.25);
implicit_plane->SetInputConnection(glyph->GetOutputPort());
implicit_plane->PlaceWidget();
implicit_plane->EnabledOn();
interactor->Initialize();
render_window->Render();
interactor->Start();
}