vtk_poly_data#

k3d.factory.vtk_poly_data(poly_data, color=255, color_attribute=None, color_map=None, side='front', wireframe=False, opacity=1.0, volume=[], volume_bounds=[], opacity_function=[], color_range=[], cell_color_attribute=None, flat_shading=True, name=None, group=None, custom_data=None, compression_level=0, **kwargs)[source]#

Create a Mesh drawable from given vtkPolyData.

Require the vtk module (from package VTK) to be installed.

Parameters
  • poly_data (vtkPolyData) – Native vtkPolyData geometry.

  • color (int, optional) – Hex color of the mesh when when not using color_map, by default _default_color.

  • color_attribute (tuple, optional) –

    (str, float, float) to determine which scalar should be used for the color_map and the color_range (attribute_name, min_value, max_value), by default None.

    A VTK mesh can have multiple named attributes in the vertices

    • min_value is the value mapped to 0 in the color_map

    • max_value is the value mapped to 1 in the color_map

  • cell_color_attribute (tuple, optional) –

    (str, float, float) to determine which scalar should be used for the color_map and the color_range (attribute_name, min_value, max_value), by default None.

    A VTK mesh can have multiple named attributes in the vertices

    • min_value is the value mapped to 0 in the color_map

    • max_value is the value mapped to 1 in the color_map

  • color_map (list, optional) – List of float quadruplets (attribute value, R, G, B) sorted by attribute value, by default None. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0.

  • color_range (list, optional) – [min_value, max_value] pair determining the levels of color attribute mapped to 0 and 1 in the colormap, by default [].

  • side ({"front", "back", "both"}, optional) – Side to render, by default “front”.

  • wireframe (bool, optional) – Display the mesh as wireframe, by default False.

  • opacity (float, optional) – Opacity of mesh, by default 1.0.

  • opacity_function (list, optional) –

    float tuples (attribute value, opacity) sorted by attribute value, by default [].

    The first tuples should have value 0.0, the last 1.0; opacity is in the range 0.0 to 1.0.

  • volume (list, optional) – 3D array of float, by default [].

  • volume_bounds (list, optional) – 6-element tuple specifying the bounds of the volume data (x0, x1, y0, y1, z0, z1), by default [].

  • flat_shading (bool, optional) – Display the mesh with flat shading, by default True.

  • name (str, optional) – Object name, by default None.

  • group (str, optional) – Name of a group, by default None.

  • custom_data (dict) – A object with custom data attached to object.

  • compression_level (int, optional) – Level of data compression [-1, 9], by default 0.

  • **kwargs – For other keyword-only arguments, see process_transform_arguments.

Returns

Mesh Drawable.

Return type

Mesh

Raises

RuntimeError – vtk module is not available.

Examples#

Basic#

cow.vtp

# VTP model from https://github.com/naucoin/VTKData/blob/master/Data/cow.vtp

import k3d
import numpy as np
import pyvista as pv

data = pv.raed('cow.vtp')

plt_vtk = k3d.vtk_poly_data(data,
                            color=0xc6884b,
                            model_matrix = (1.0, 0.0, 0.0, 0.0,
                                            0.0, 0.0, 1.0, 0.0,
                                            0.0, 1.0, 0.0, 0.0,
                                            0.0, 0.0, 0.0, 1.0))

plot = k3d.plot()
plot += plt_vtk
plot.display()

Colormap#

bunny.vtp

Attention

color_map must be used along with color_attribute in order to work correctly.

# VTP model from https://github.com/pyvista/vtk-data/blob/master/Data/Bunny.vtp

import k3d
import pyvista as pv
from k3d.colormaps import matplotlib_color_maps

data = pv.read('bunny.vtp')

plt_vtk = k3d.vtk_poly_data(data,
                            color_attribute=('Normals', 0, 1),
                            color_map=matplotlib_color_maps.Rainbow,
                            model_matrix = (1.0, 0.0, 0.0, 0.0,
                                            0.0, 0.0, 1.0, 0.0,
                                            0.0, 1.0, 0.0, 0.0,
                                            0.0, 0.0, 0.0, 1.0))

plot = k3d.plot()
plot += plt_vtk
plot.display()