1
2 """
3 This example demonstrates the use of the contour filter, and the use of
4 the vtkSampleFunction to generate a volume of data samples from an
5 implicit function.
6
7 Conversion of VisQuad.py of the VTK example to tvtk
8 (and some additions).
9 """
10
11 from enthought.tvtk import tvtk
12
13
14 quadric = tvtk.Quadric(coefficients=(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0))
15
16
17
18 sample = tvtk.SampleFunction(implicit_function=quadric,
19 sample_dimensions=(30, 30, 30))
20
21
22 contours = tvtk.ContourFilter(input=sample.output)
23 contours.generate_values(5, 0.0, 1.2)
24
25 contMapper = tvtk.PolyDataMapper(input=contours.output, scalar_range=(0.0, 1.2))
26 contActor = tvtk.Actor(mapper=contMapper)
27
28
29 outline = tvtk.OutlineFilter(input=sample.output)
30 outlineMapper = tvtk.PolyDataMapper(input=outline.output)
31 outlineActor = tvtk.Actor(mapper=outlineMapper)
32 outlineActor.property.color=(0, 0, 0)
33
34
35 ren = tvtk.Renderer(background=(0.95, 0.95, 1.0))
36 renWin = tvtk.RenderWindow()
37 renWin.add_renderer(ren)
38 iren = tvtk.RenderWindowInteractor(render_window=renWin)
39 ren.add_actor(contActor)
40 ren.add_actor(outlineActor)
41
42
43 ren.active_camera.elevation(10)
44
45 iren.initialize()
46 renWin.render()
47
48
49 renderLarge = tvtk.RenderLargeImage(input=ren, magnification=1)
50 writer = tvtk.PNGWriter(input=renderLarge.output, file_name="vis_quad.png")
51 writer.write()
52
53
54 iren.start()
, as shown below in the list of files. Do
link, since this is subject to change and can break easily.