File: TestConvexPointSet.py

package info (click to toggle)
vtk9 9.5.2%2Bdfsg3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 205,984 kB
  • sloc: cpp: 2,336,570; 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: 181; javascript: 165; objc: 153; tcl: 59
file content (131 lines) | stat: -rwxr-xr-x 3,293 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python
from vtkmodules.vtkCommonCore import vtkPoints
from vtkmodules.vtkCommonDataModel import (
    vtkConvexPointSet,
    vtkUnstructuredGrid,
)
from vtkmodules.vtkFiltersCore import (
    vtkContourFilter,
    vtkElevationFilter,
)
from vtkmodules.vtkFiltersGeneral import vtkClipDataSet
from vtkmodules.vtkFiltersGeometry import vtkDataSetSurfaceFilter
from vtkmodules.vtkRenderingCore import (
    vtkActor,
    vtkCamera,
    vtkDataSetMapper,
    vtkPolyDataMapper,
    vtkRenderWindow,
    vtkRenderWindowInteractor,
    vtkRenderer,
)
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingFreeType
import vtkmodules.vtkRenderingOpenGL2

# create points in the configuration of an octant with one 2:1 face
#
points = vtkPoints()
aConvex = vtkConvexPointSet()
points.InsertPoint(0, 0, 0, 0)
points.InsertPoint(1, 1, 0, 0)
points.InsertPoint(2, 1, 1, 0)
points.InsertPoint(3, 0, 1, 0)
points.InsertPoint(4, 0, 0, 1)
points.InsertPoint(5, 1, 0, 1)
points.InsertPoint(6, 1, 1, 1)
points.InsertPoint(7, 0, 1, 1)
points.InsertPoint(8, 0.5, 0, 0)
points.InsertPoint(9, 1, 0.5, 0)
points.InsertPoint(10, 0.5, 1, 0)
points.InsertPoint(11, 0, 0.5, 0)
points.InsertPoint(12, 0.5, 0.5, 0)
i = 0
while i < 13:
    aConvex.GetPointIds().InsertId(i, i)
    i += 1

aConvexGrid = vtkUnstructuredGrid()
aConvexGrid.Allocate(1, 1)
aConvexGrid.InsertNextCell(aConvex.GetCellType(), aConvex.GetPointIds())
aConvexGrid.SetPoints(points)

# Display the cell
dsm = vtkDataSetMapper()
dsm.SetInputData(aConvexGrid)
a = vtkActor()
a.SetMapper(dsm)
a.GetProperty().SetColor(0, 1, 0)

# Contour and clip the cell with elevation scalars
ele = vtkElevationFilter()
ele.SetInputData(aConvexGrid)
ele.SetLowPoint(-1, -1, -1)
ele.SetHighPoint(1, 1, 1)
ele.SetScalarRange(-1, 1)

# Clip
#
clip = vtkClipDataSet()
clip.SetInputConnection(ele.GetOutputPort())
clip.SetValue(0.5)
g = vtkDataSetSurfaceFilter()
g.SetInputConnection(clip.GetOutputPort())
map = vtkPolyDataMapper()
map.SetInputConnection(g.GetOutputPort())
map.ScalarVisibilityOff()
clipActor = vtkActor()
clipActor.SetMapper(map)
clipActor.GetProperty().SetColor(1, 0, 0)
clipActor.AddPosition(2, 0, 0)

# Contour
#
contour = vtkContourFilter()
contour.SetInputConnection(ele.GetOutputPort())
contour.SetValue(0, 0.5)
g2 = vtkDataSetSurfaceFilter()
g2.SetInputConnection(contour.GetOutputPort())
map2 = vtkPolyDataMapper()
map2.SetInputConnection(g2.GetOutputPort())
map2.ScalarVisibilityOff()
contourActor = vtkActor()
contourActor.SetMapper(map2)
contourActor.GetProperty().SetColor(1, 0, 0)
contourActor.AddPosition(1, 2, 0)

# Create graphics stuff
#
ren1 = vtkRenderer()
renWin = vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Add the actors to the renderer, set the background and size
#
ren1.AddActor(a)
ren1.AddActor(clipActor)
ren1.AddActor(contourActor)
ren1.SetBackground(1, 1, 1)

renWin.SetSize(250, 150)

aCam = vtkCamera()
aCam.SetFocalPoint(1.38705, 1.37031, 0.639901)
aCam.SetPosition(1.89458, -5.07106, -4.17439)
aCam.SetViewUp(0.00355726, 0.598843, -0.800858)
aCam.SetClippingRange(4.82121, 12.1805)

ren1.SetActiveCamera(aCam)

renWin.Render()

cam1 = ren1.GetActiveCamera()
cam1.Zoom(1.5)

# render the image
#
renWin.Render()

#iren.Start()