-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclip_cow.cpp
97 lines (78 loc) · 2.65 KB
/
clip_cow.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 "vtkBYUReader.h"
#include "vtkClipPolyData.h"
#include "vtkCutter.h"
#include "vtkNew.h"
#include "vtkPlane.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataNormals.h"
#include "vtkProperty.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkStripper.h"
#include "vtkTriangleFilter.h"
#include "platform.h"
#include <filesystem>
int main() {
vtkNew<vtkBYUReader> reader;
reader->SetGeometryFileName(
(fs::canonical("Data").string() + "/Viewpoint/cow.g").c_str());
vtkNew<vtkPolyDataNormals> normals;
normals->SetInputConnection(reader->GetOutputPort());
vtkNew<vtkPlane> plane;
plane->SetOrigin(0.25, 0, 0);
plane->SetNormal(-1, -1, 0);
vtkNew<vtkClipPolyData> clip;
clip->SetInputConnection(normals->GetOutputPort());
clip->SetClipFunction(plane);
clip->GenerateClipScalarsOn();
clip->GenerateClippedOutputOn();
clip->SetValue(0.9);
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(clip->GetOutputPort());
mapper->ScalarVisibilityOff();
vtkNew<vtkProperty> property;
property->SetDiffuseColor(1, 0, 0);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(0, 1, 0);
actor->SetBackfaceProperty(property);
vtkNew<vtkCutter> cutter;
cutter->SetInputConnection(normals->GetOutputPort());
cutter->SetCutFunction(plane);
cutter->GenerateCutScalarsOn();
cutter->SetValue(0, 0.9);
vtkNew<vtkStripper> stripper;
stripper->SetInputConnection(cutter->GetOutputPort());
stripper->Update();
vtkNew<vtkPolyData> cut_poly;
cut_poly->SetPoints(stripper->GetOutput()->GetPoints());
cut_poly->SetPolys(stripper->GetOutput()->GetPolys());
vtkNew<vtkTriangleFilter> cut_triangles;
cut_triangles->SetInputData(cut_poly);
vtkNew<vtkPolyDataMapper> cut_mapper;
cut_mapper->SetInputConnection(cut_triangles->GetOutputPort());
cut_mapper->SetInputData(cut_poly);
vtkNew<vtkActor> cut_actor;
cut_actor->SetMapper(cut_mapper);
vtkNew<vtkPolyDataMapper> rest_mapper;
rest_mapper->SetInputConnection(clip->GetClippedOutputPort());
rest_mapper->ScalarVisibilityOff();
vtkNew<vtkActor> rest_actor;
rest_actor->SetMapper(rest_mapper);
rest_actor->GetProperty()->SetRepresentationToWireframe();
vtkNew<vtkRenderer> render;
render->AddActor(actor);
render->AddActor(cut_actor);
render->AddActor(rest_actor);
render->SetBackground(1, 1, 1);
vtkNew<vtkRenderWindow> window;
window->AddRenderer(render);
window->Render();
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(window);
interactor->Initialize();
interactor->Start();
}