Vtk Canvas Example
An example of the VTKCanvas
widget.
Requires vtk to be installed.
Tip
To see this example in action, download it from
vtk_canvas
and run:
$ enaml-run vtk_canvas.enaml
Screenshot
Example Enaml Code
#------------------------------------------------------------------------------
# Copyright (c) 2013-2024, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
""" An example of the `VTKCanvas` widget.
Requires vtk to be installed.
<< autodoc-me >>
"""
from enaml.widgets.api import Window, Container, VTKCanvas
import vtk
def create_renderer():
quadric = vtk.vtkQuadric()
quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0)
sample = vtk.vtkSampleFunction()
sample.SetSampleDimensions(50, 50, 50)
sample.SetImplicitFunction(quadric)
contours = vtk.vtkContourFilter()
contours.SetInputConnection(sample.GetOutputPort())
contours.GenerateValues(5, 0.0, 1.2)
contour_mapper = vtk.vtkPolyDataMapper()
contour_mapper.SetInputConnection(contours.GetOutputPort())
contour_mapper.SetScalarRange(0.0, 1.2)
contour_actor = vtk.vtkActor()
contour_actor.SetMapper(contour_mapper)
outline = vtk.vtkOutlineFilter()
outline.SetInputConnection(sample.GetOutputPort())
outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())
outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(0, 0, 0)
renderer = vtk.vtkRenderer()
renderer.AddActor(contour_actor)
renderer.AddActor(outline_actor)
renderer.SetBackground(.75, .75, .75)
return renderer
enamldef Main(Window):
title = 'VTK Canvas'
Container:
padding = 0
VTKCanvas:
renderer = create_renderer()