vtk_poly_data#
- k3d.factory.vtk_poly_data(poly_data: Any, color: int | None = None, color_attribute: Tuple[str, float, float] | None = None, color_map: List[List[float]] | Dict[str, Any] | ndarray | None = None, side: str = 'front', slice_planes: List | ndarray | Tuple = None, wireframe: bool = False, opacity: float = 1.0, volume: List | ndarray | Tuple = None, volume_bounds: List | ndarray | Tuple = None, opacity_function: List[float] = None, color_range: List[float] = None, cell_color_attribute: Tuple[str, float, float] | None = None, flat_shading: bool = True, roughness: float = 0.4, metalness: float = 0.0, shininess: float = None, name: str | None = None, group: str | None = None, custom_data: Dict[str, Any] | None = None, compression_level: int = 0, visible: bool = True, click_callback: Callable | None = None, hover_callback: Callable | None = None, **kwargs: Any) Mesh[source]#
Create a Mesh drawable from a vtkPolyData object.
- Parameters:
poly_data (vtkPolyData) – The polygonal data to convert. Cells with more than three points, and triangle strips, are triangulated first.
color (int, optional) – Packed RGB color of the mesh (0xff0000 is red, 0xff is blue). It multiplies the colormap. Default is 255, or white when a color attribute is given.
color_attribute (tuple, optional) – Attribute to colour by, as (array name, min, max) read from the point data. Default is None.
color_map (list, optional) – A list of float quadruplets (attribute value, R, G, B), sorted by attribute value. 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. Default is None.
side (str, optional) – Which faces of the mesh are drawn: ‘front’, ‘back’ or ‘double’. Default is ‘front’.
slice_planes (list, optional) – Planes [a, b, c, d] the section outline is drawn along, up to eight of them. The outline is drawn in the object colour. Default is None.
wireframe (bool, optional) – Whether mesh should display as wireframe. Default is False.
opacity (float, optional) – Opacity of mesh. Default is 1.0.
volume (array_like, optional) – 3D array sampled for the colour of each fragment, with volume_bounds giving the box it spans. Default is None.
volume_bounds (array_like, optional) – Bounding box [xmin, xmax, ymin, ymax, zmin, zmax] of volume. Default is None.
opacity_function (list, optional) – A list of float tuples (attribute value, opacity), sorted by attribute value. The first tuple should have value 0.0, the last 1.0; opacity is in the range 0.0 to 1.0. Default is None.
color_range (list, optional) – A pair [min_value, max_value], which determines the levels of color attribute mapped to 0 and 1 in the color map respectively. Default is None.
cell_color_attribute (tuple, optional) – Attribute to colour by, as (array name, min, max) read from the cell data. Default is None.
flat_shading (bool, optional) – Whether mesh should display with flat shading. Default is True.
roughness (float, optional) – Roughness of object material. Default is 0.4.
metalness (float, optional) – Metalness of object material. Default is 0.0.
shininess (float, optional) – Removed in 3.0.0; passing it raises. Use roughness and metalness. Default is None.
name (str, optional) – A name of the object. Default is None.
group (str, optional) – A name of a group. Default is None.
custom_data (dict, optional) – An object with custom data attached to object. Default is None.
compression_level (int, optional) – Level of compression [-1, 9]. Default is 0.
visible (bool, optional) – Whether the object is drawn. Default is True.
click_callback (callable, optional) – Called with the picking parameters when the object is clicked, while the plot is in mode=’callback’. Default is None.
hover_callback (callable, optional) – Called with the picking parameters when the cursor is over the object, while the plot is in mode=’callback’. Default is None.
**kwargs – Additional keyword arguments passed to process_transform_arguments.
- Returns:
The created Mesh object.
- Return type:
Mesh
Examples#
Basic#
# 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.read('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#
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()