py4sci

Previous topic

surface

Next topic

grid

This Page

vtkutils

Note

Functions for working with vtk

Module author: Adam Gagorik <adam.gagorik@gmail.com>

vtkutils.create_image_data(nx, ny, nz, dx=1.0, dy=1.0, dz=1.0, ox=0, oy=0, oz=0)[source]

Construct an empty vtkImageData. This data structure is a regular grid with constant spacing.

Parameters:
  • nx (int) – number of grid points along x-axis
  • ny (int) – number of grid points along y-axis
  • nz (int) – number of grid points along z-axis
  • dx (float) – spacing along x-axis
  • dy (float) – spacing along y-axis
  • dz (float) – spacing along z-axis
  • ox (float) – origin of x-axis
  • oy (float) – origin of y-axis
  • oz (float) – origin of z-axis
>>> image_data = create_image_data(32, 32, 32)
vtkutils.create_image_data_from_array(array, *args, **kwargs)[source]

Construct an empty vtkImageData and fill it with the array’s values.

Parameters:array (numpy.ndarray) – data with 3 dimensions.
>>> image_data = create_image_data_from_array(surf)
vtkutils.save_image_data(handle, image_data)[source]

Save vtkImageData to XML file.

Parameters:
  • handle (str) – file name
  • image_data (vtk.vtkImageData) – source
>>> image_data = create_image_data(32, 32, 32)
>>> save_image_data('test.vit', image_data)
vtkutils.load_image_data(handle)[source]

Load vtkImageData from XML file.

Parameters:handle (str) – file name
vtkutils.pipe(i, o)[source]

Pipes one vtkObject into another.

Parameters:
  • i (vtk.vtkObject) – input
  • o (vtk.vtkObject) – filter
>>> vtkImageData = create_image_data(32, 32, 32)
>>> vtkMarchingCubes = vtk.vtkMarchingCubes()
>>> pipe(vtkImageData, vtkMarchingCubes)
vtkutils.filter_marching_cubes(vtkObject, isovalue=1e-05)[source]

Create vtkMarchingCubes filter on vtkObject.

Parameters:
  • vtkObject (vtk.vtkObject) – input
  • isovalue (float) – contour value
>>> image_data = create_image_data_from_array(surf)
>>> cubes = filter_marching_cubes(image_data)
>>> show(cubes)
vtkutils.filter_marching_squares(vtkObject, isovalue=1e-05)[source]

Create vtkMarchingSquares filter on vtkObject.

Parameters:
  • vtkObject – input
  • isovalue (float) – contour value
  • vtkObjectvtk.vtkObject
>>> image_data = create_image_data_from_array(surf)
>>> squares = filter_marching_cubes(image_data)
>>> show(squares)
vtkutils.filter_marching(vtkObject, isovalue=1e-05)[source]

Applies marching cubes or squares based on number of dimensions.

Parameters:
  • vtkObject (vtk.vtkObject) – input
  • isovalue (float) – contour value
vtkutils.filter_curvature(vtkObject, mode='gaussian')[source]

Create vtkCurvatures filter on vtkObject.

Parameters:
  • vtkObject (vtk.vtkObject) – input
  • mode (str) – gaussian or mean
>>> image_data = create_image_data_from_array(surf)
>>> cubes = filter_marching_cubes(image_data)
>>> curve = filter_curvature(cubes)
>>> show(curve)
vtkutils.show(vtkObject, w=512, h=512)[source]

Show result of pipeline.

Parameters:
  • vtkObject (None) – anything VTK
  • w (int) – window width
  • h (int) – window height
>>> image_data = create_image_data_from_array(surf)
>>> cubes = filter_marching_cubes(image_data)
>>> show(cubes)