File: camera.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 205,916 kB
  • sloc: cpp: 2,336,565; ansic: 327,116; python: 111,200; yacc: 4,104; java: 3,977; sh: 3,032; xml: 2,771; perl: 2,189; lex: 1,787; makefile: 178; javascript: 165; objc: 153; tcl: 59
file content (246 lines) | stat: -rwxr-xr-x 7,324 bytes parent folder | download | duplicates (5)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkCommonDataModel import (
    vtkCellArray,
    vtkPolyData,
)
from vtkmodules.vtkCommonTransforms import vtkTransform
from vtkmodules.vtkFiltersCore import (
    vtkAppendFilter,
    vtkContourFilter,
)
from vtkmodules.vtkFiltersGeneral import (
    vtkTransformFilter,
    vtkTransformPolyDataFilter,
    vtkWarpTo,
)
from vtkmodules.vtkFiltersHybrid import vtkImplicitModeller
from vtkmodules.vtkFiltersModeling import vtkRotationalExtrusionFilter
from vtkmodules.vtkFiltersSources import (
    vtkConeSource,
    vtkCubeSource,
    vtkSphereSource,
)
from vtkmodules.vtkRenderingCore import (
    vtkDataSetMapper,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
)
from vtkmodules.vtkRenderingLOD import vtkLODActor
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# create a camera model
camCS = vtkConeSource()
camCS.SetHeight(1.5)
camCS.SetResolution(12)
camCS.SetRadius(0.4)
camCBS = vtkCubeSource()
camCBS.SetXLength(1.5)
camCBS.SetZLength(0.8)
camCBS.SetCenter(0.4,0,0)
camAPD = vtkAppendFilter()
camAPD.AddInputConnection(camCS.GetOutputPort())
camAPD.AddInputConnection(camCBS.GetOutputPort())
camMapper = vtkDataSetMapper()
camMapper.SetInputConnection(camAPD.GetOutputPort())
camActor = vtkLODActor()
camActor.SetMapper(camMapper)
camActor.SetScale(2,2,2)
# draw the arrows
pd = vtkPolyData()
ca = vtkCellArray()
fp = vtkPoints()
fp.InsertNextPoint(0,1,0)
fp.InsertNextPoint(8,1,0)
fp.InsertNextPoint(8,2,0)
fp.InsertNextPoint(10,0.01,0)
fp.InsertNextPoint(8,-2,0)
fp.InsertNextPoint(8,-1,0)
fp.InsertNextPoint(0,-1,0)
ca.InsertNextCell(7)
ca.InsertCellPoint(0)
ca.InsertCellPoint(1)
ca.InsertCellPoint(2)
ca.InsertCellPoint(3)
ca.InsertCellPoint(4)
ca.InsertCellPoint(5)
ca.InsertCellPoint(6)
pd.SetPoints(fp)
pd.SetPolys(ca)
pd2 = vtkPolyData()
ca2 = vtkCellArray()
fp2 = vtkPoints()
fp2.InsertNextPoint(0,1,0)
fp2.InsertNextPoint(8,1,0)
fp2.InsertNextPoint(8,2,0)
fp2.InsertNextPoint(10,0.01,0)
#prevents degenerate triangles
ca2.InsertNextCell(4)
ca2.InsertCellPoint(0)
ca2.InsertCellPoint(1)
ca2.InsertCellPoint(2)
ca2.InsertCellPoint(3)
pd2.SetPoints(fp2)
pd2.SetLines(ca2)
arrowIM = vtkImplicitModeller()
arrowIM.SetInputData(pd)
arrowIM.SetSampleDimensions(50,20,8)
arrowCF = vtkContourFilter()
arrowCF.SetInputConnection(arrowIM.GetOutputPort())
arrowCF.SetValue(0,0.2)
arrowWT = vtkWarpTo()
arrowWT.SetInputConnection(arrowCF.GetOutputPort())
arrowWT.SetPosition(5,0,5)
arrowWT.SetScaleFactor(0.85)
arrowWT.AbsoluteOn()
arrowT = vtkTransform()
arrowT.RotateY(60)
arrowT.Translate(-1.33198,0,-1.479)
arrowT.Scale(1,0.5,1)
arrowTF = vtkTransformFilter()
arrowTF.SetInputConnection(arrowWT.GetOutputPort())
arrowTF.SetTransform(arrowT)
arrowMapper = vtkDataSetMapper()
arrowMapper.SetInputConnection(arrowTF.GetOutputPort())
arrowMapper.ScalarVisibilityOff()
# draw the azimuth arrows
a1Actor = vtkLODActor()
a1Actor.SetMapper(arrowMapper)
a1Actor.RotateZ(180)
a1Actor.SetPosition(1,0,-1)
a1Actor.GetProperty().SetColor(1,0.3,0.3)
a1Actor.GetProperty().SetSpecularColor(1,1,1)
a1Actor.GetProperty().SetSpecular(0.3)
a1Actor.GetProperty().SetSpecularPower(20)
a1Actor.GetProperty().SetAmbient(0.2)
a1Actor.GetProperty().SetDiffuse(0.8)
a2Actor = vtkLODActor()
a2Actor.SetMapper(arrowMapper)
a2Actor.RotateZ(180)
a2Actor.RotateX(180)
a2Actor.SetPosition(1,0,1)
a2Actor.GetProperty().SetColor(1,0.3,0.3)
a2Actor.GetProperty().SetSpecularColor(1,1,1)
a2Actor.GetProperty().SetSpecular(0.3)
a2Actor.GetProperty().SetSpecularPower(20)
a2Actor.GetProperty().SetAmbient(0.2)
a2Actor.GetProperty().SetDiffuse(0.8)
# draw the elevation arrows
a3Actor = vtkLODActor()
a3Actor.SetMapper(arrowMapper)
a3Actor.RotateZ(180)
a3Actor.RotateX(90)
a3Actor.SetPosition(1,-1,0)
a3Actor.GetProperty().SetColor(0.3,1,0.3)
a3Actor.GetProperty().SetSpecularColor(1,1,1)
a3Actor.GetProperty().SetSpecular(0.3)
a3Actor.GetProperty().SetSpecularPower(20)
a3Actor.GetProperty().SetAmbient(0.2)
a3Actor.GetProperty().SetDiffuse(0.8)
a4Actor = vtkLODActor()
a4Actor.SetMapper(arrowMapper)
a4Actor.RotateZ(180)
a4Actor.RotateX(-90)
a4Actor.SetPosition(1,1,0)
a4Actor.GetProperty().SetColor(0.3,1,0.3)
a4Actor.GetProperty().SetSpecularColor(1,1,1)
a4Actor.GetProperty().SetSpecular(0.3)
a4Actor.GetProperty().SetSpecularPower(20)
a4Actor.GetProperty().SetAmbient(0.2)
a4Actor.GetProperty().SetDiffuse(0.8)
# draw the DOP
arrowT2 = vtkTransform()
arrowT2.Scale(1,0.6,1)
arrowT2.RotateY(90)
arrowTF2 = vtkTransformPolyDataFilter()
arrowTF2.SetInputData(pd2)
arrowTF2.SetTransform(arrowT2)
arrowREF = vtkRotationalExtrusionFilter()
arrowREF.SetInputConnection(arrowTF2.GetOutputPort())
arrowREF.CappingOff()
arrowREF.SetResolution(30)
spikeMapper = vtkPolyDataMapper()
spikeMapper.SetInputConnection(arrowREF.GetOutputPort())
a5Actor = vtkLODActor()
a5Actor.SetMapper(spikeMapper)
a5Actor.SetScale(.3,.3,.6)
a5Actor.RotateY(90)
a5Actor.SetPosition(-2,0,0)
a5Actor.GetProperty().SetColor(1,0.3,1)
a5Actor.GetProperty().SetAmbient(0.2)
a5Actor.GetProperty().SetDiffuse(0.8)
# focal point
fps = vtkSphereSource()
fps.SetRadius(0.5)
fpMapper = vtkPolyDataMapper()
fpMapper.SetInputConnection(fps.GetOutputPort())
fpActor = vtkLODActor()
fpActor.SetMapper(fpMapper)
fpActor.SetPosition(-9,0,0)
fpActor.GetProperty().SetSpecularColor(1,1,1)
fpActor.GetProperty().SetSpecular(0.3)
fpActor.GetProperty().SetAmbient(0.2)
fpActor.GetProperty().SetDiffuse(0.8)
fpActor.GetProperty().SetSpecularPower(20)
# create the roll arrows
arrowWT2 = vtkWarpTo()
arrowWT2.SetInputConnection(arrowCF.GetOutputPort())
arrowWT2.SetPosition(5,0,2.5)
arrowWT2.SetScaleFactor(0.95)
arrowWT2.AbsoluteOn()
arrowT3 = vtkTransform()
arrowT3.Translate(-2.50358,0,-1.70408)
arrowT3.Scale(0.5,0.3,1)
arrowTF3 = vtkTransformFilter()
arrowTF3.SetInputConnection(arrowWT2.GetOutputPort())
arrowTF3.SetTransform(arrowT3)
arrowMapper2 = vtkDataSetMapper()
arrowMapper2.SetInputConnection(arrowTF3.GetOutputPort())
arrowMapper2.ScalarVisibilityOff()
# draw the roll arrows
a6Actor = vtkLODActor()
a6Actor.SetMapper(arrowMapper2)
a6Actor.RotateZ(90)
a6Actor.SetPosition(-4,0,0)
a6Actor.SetScale(1.5,1.5,1.5)
a6Actor.GetProperty().SetColor(1,1,0.3)
a6Actor.GetProperty().SetSpecularColor(1,1,1)
a6Actor.GetProperty().SetSpecular(0.3)
a6Actor.GetProperty().SetSpecularPower(20)
a6Actor.GetProperty().SetAmbient(0.2)
a6Actor.GetProperty().SetDiffuse(0.8)
# Add the actors to the renderer, set the background and size
ren1.AddActor(camActor)
ren1.AddActor(a1Actor)
ren1.AddActor(a2Actor)
ren1.AddActor(a3Actor)
ren1.AddActor(a4Actor)
ren1.AddActor(a5Actor)
ren1.AddActor(a6Actor)
ren1.AddActor(fpActor)
ren1.SetBackground(0.1,0.2,0.4)
renWin.SetSize(300,300)
# render the image
ren1.ResetCamera()
cam1 = ren1.GetActiveCamera()
cam1.Zoom(1.5)
cam1.Azimuth(150)
cam1.Elevation(30)
iren.Initialize()
# prevent the tk window from showing up then start the event loop
# for testing
threshold = 15
# --- end of script --