-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathEllipticalCylinder.cxx
More file actions
127 lines (105 loc) · 3.61 KB
/
EllipticalCylinder.cxx
File metadata and controls
127 lines (105 loc) · 3.61 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
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
123
124
125
126
127
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkLinearExtrusionFilter.h>
#include <vtkMath.h>
#include <vtkNamedColors.h>
#include <vtkPoints.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyLine.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
int main(int /* argc */, char * /* argv */ [])
{
double angle = 0;
double r1, r2;
double centerX, centerY;
r1 = 50;
r2 = 30;
centerX = 10.0;
centerY = 5.0;
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
int id = 0;
while (angle <= 2.0 * vtkMath::Pi() + (vtkMath::Pi() / 60.0))
{
points->InsertNextPoint(r1 * cos(angle) + centerX,
r2 * sin(angle) + centerY,
0.0);
angle = angle + (vtkMath::Pi() / 60.0);
++id;
}
vtkSmartPointer<vtkPolyLine> line =
vtkSmartPointer<vtkPolyLine>::New();
line->GetPointIds()->SetNumberOfIds(id);
for(unsigned int i = 0; i < static_cast<unsigned int>(id); ++i)
{
line->GetPointIds()->SetId(i,i);
}
vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
lines->InsertNextCell(line);
vtkSmartPointer<vtkPolyData> polyData =
vtkSmartPointer<vtkPolyData>::New();
polyData->SetPoints(points);
polyData->SetLines(lines);
vtkSmartPointer<vtkLinearExtrusionFilter> extrude =
vtkSmartPointer<vtkLinearExtrusionFilter>::New();
extrude->SetInputData(polyData);
extrude->SetExtrusionTypeToNormalExtrusion();
extrude->SetVector(0, 0, 100.0);
extrude->Update();
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();
vtkSmartPointer<vtkPolyDataMapper> lineMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
lineMapper->SetInputData(polyData);
vtkSmartPointer<vtkActor> lineActor =
vtkSmartPointer<vtkActor>::New();
lineActor->SetMapper(lineMapper);
lineActor->GetProperty()->SetColor(colors->GetColor3d("Peacock").GetData());
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(extrude->GetOutputPort());
vtkSmartPointer<vtkProperty> back =
vtkSmartPointer<vtkProperty>::New();
back->SetColor(colors->GetColor3d("Tomato").GetData());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Banana").GetData());
actor->SetBackfaceProperty(back);
vtkSmartPointer<vtkRenderer> ren =
vtkSmartPointer<vtkRenderer>::New();
ren->SetBackground(colors->GetColor3d("SlateGray").GetData());
ren->AddActor(actor);
ren->AddActor(lineActor);
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->SetWindowName("Elliptical Cylinder");
renWin->AddRenderer(ren);
renWin->SetSize(600, 600);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style =
vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
vtkSmartPointer<vtkCamera> camera =
vtkSmartPointer<vtkCamera>::New();
camera->SetPosition (0, 1, 0);
camera->SetFocalPoint (0, 0, 0);
camera->SetViewUp (0, 0, 1);
camera->Azimuth(30);
camera->Elevation(30);
ren->SetActiveCamera(camera);
ren->ResetCamera();
ren->ResetCameraClippingRange();
renWin->Render();
iren->Start();
return EXIT_SUCCESS;
}