Skip to content

meshtools

PolydataBuilder

add_array(polydata, np_array, name) staticmethod

add_cell_array(polydata, np_array, name) staticmethod

add_polyline(polydata, point_ids) staticmethod

Add polyline to polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata.

required
point_ids list

List of point indexes.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Polydata with added polyline.

append(polydata_list) staticmethod

Build signle polydata from list.

Parameters:

Name Type Description Default
polydata_list list

List of vtkPolyData.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Single polydata.

as_vtk_array(np_array, name) staticmethod

build(coords, polygons=None) staticmethod

build_polyline(coords, closed=False) staticmethod

Build polyline from sequence of points.

Parameters:

Name Type Description Default
coords ndarray[N, 3]

An array of coordinates.

required
closed bool

If True closed Line will be added. Defaults to False.

False

Returns:

Name Type Description
vtkPolyData vtkPolyData

vtkPolyData object with Lines built from array of coordinates.

clone(polydata) staticmethod

Make deepcopy of polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Deepcopy of input polydata.

extract_array(polydata, array_name) staticmethod

extract_cell_array(polydata, array_name) staticmethod

Get cell array from polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

vtkPolyData object.

required
array_name str

name of vtkPolyData array.

required

Returns:

Name Type Description
ndarray ndarray

numpy array of values.

extract_lines(polydata) staticmethod

Extract lines point indexes.

Parameters:

Name Type Description Default
polydata vtkPolyData

Polydata with lines.

required

Returns:

Name Type Description
list list[int]

List of line indexes.

extract_points(polydata) staticmethod

Get points coordinates from polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

vtkPolyData object.

required

Returns:

Name Type Description
ndarray ndarray

numpy array of points coordinates.

mask_points(polydata, selected_ids, scalar_name='OriginalPointIds') staticmethod

Select polydata by point indexes.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata.

required
selected_ids list

List of point indexes which will be selected.

required
scalar_name str

New array will be add to the output. Defaults to "OriginalPointIds".

'OriginalPointIds'

Returns:

Name Type Description
vtkPolyData vtkPolyData

Selected polydata.

Note

All Polygons, Triangle strips etc., will be removed from output.

PolydataFilter

Tool class containing filters for polydata.

__init__()

center_of_mass(polydata) staticmethod

generate_global_ids(polydata) staticmethod

Generate global ids for points and cells of the polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Polydata with global ids.

generate_ids(polydata, point_ids_name='vtkIdFilter_Ids') staticmethod

Generate ids for points and cells of the polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Polydata with point and cell ids arrays.

gradient(polydata, scalar_name) staticmethod

Construct gradient filter for target data.

Parameters:

Name Type Description Default
scalar_name str

name of the target data array.

required

Returns:

Name Type Description
vtkGradientFilter vtkGradientFilter

initialized filter object.

pca_normals(polydata, radius=1, sample_size=10) staticmethod

Construct filter for normal calculation. Estimator uses PCA for normals calculation.

For more info see: https://vtk.org/doc/nightly/html/classvtkPCANormalEstimation.html#details

Parameters:

Name Type Description Default
radius int

Defaults to 1.

1
sample_size int

Number of points for computing normals. Defaults to 10.

10

Returns:

Name Type Description
vtkPCANormalEstimation vtkPCANormalEstimation

estimator object for normals computation.

point_scalar_to_cell_scalar(polydata, categorical=False) staticmethod

Converts point scalar value to cell scalar.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata

required
categorical bool

If true "majority rules" applied with ties going to the smaller point data value. Defaults to False.

False

Returns:

Name Type Description
vtkPointDataToCellData vtkPointDataToCellData

filter mapping point scalar to cell scalar.

scale(polydata, scale_factor, center) staticmethod

Construct filter to scale polydata. Scaled data has to be centered first to apply transition matrix correctly.

Parameters:

Name Type Description Default
scale_factor float

scale factor to increase/decrease the object geometry.

required
center list

center coordiantes of the object.

required

Returns:

Name Type Description
vtkTransformPolyDataFilter vtkTransformPolyDataFilter

initialized filter object.

scale_points(polydata, scale_factor=1.0) staticmethod

Scale polydata relative to the center of mass.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface polydata that has to be scaled.

required
scale_factor float

Fraction to scale.

1.0

Returns:

Name Type Description
vtkPolyData vtkPolyData

Scaled polydata.

translate(polydata, position) staticmethod

Construct filter to scale polydata. Scaled data has to be centered first to apply transition matrix correctly.

Parameters:

Name Type Description Default
position list

New coordiantes of the object.

required

Returns:

Name Type Description
vtkTransformPolyDataFilter vtkTransformPolyDataFilter

initialized filter object.

vertex_glyph(polydata) staticmethod

Add vertex to each point of polydata.

Returns:

Name Type Description
vtkVertexGlyphFilter vtkVertexGlyphFilter

initialized filter object.

warp_scale(polydata, distance, vector_name='Normals') staticmethod

Move polydata along normal vectors.

Parameters:

Name Type Description Default
distance float

scale factor.

required

SurfaceBuilder

Builder class for creating surface polydata from points or triangles.

Contains additional methods to manipulate surface polydata.

__init__()

build(coords, polygons) staticmethod

Build polydata from vertices and triangles (polygons).

Parameters:

Name Type Description Default
coords ndarray[N, 3]

Array of vertices coordinates.

required
polygons ndarray

Array of vertices indexes forming triangles.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

surface polydata created from triangles.

build_delaunay_2d(coords) staticmethod

Build surface using vtkDelaunay2D.

Parameters:

Name Type Description Default
coords ndarray[N, 3]

Coords of the points.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Triangulated surface.

build_from_elems(coords, elements) staticmethod

Build surface from elements (tetrahedron)

Parameters:

Name Type Description Default
coords ndarray[N, 3]

Coords of the points.

required
elements ndarray[M, 4]

Vertex indices.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Extracted element's faces.

build_from_points(coords, radius=10, space_step=1, normals=None) staticmethod

Build triangulated surface from point.

Parameters:

Name Type Description Default
coords ndarray[N, 3]

Cloud of points.

required
radius float

Points within radius will be included for creating distance maps. Defaults to 10.

10
space_step float or list

Space step given as value or list of values for each dimension. Defaults to 1.

1
normals str

Name of normals array. Defaults to None.

None

Returns:

Name Type Description
vtkPolyData vtkPolyData

Surface polydata.

clean(polydata) staticmethod

Remove all points that are not part of triangles.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

surface polydata that has to be filtered.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

filtered surface polydata.

erode_boundary(polydata, iterations=1) staticmethod

Erodes a VTK surface mesh by removing boundary triangles.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface mesh.

required
iterations int

Number of times to erode the boundary.

1

Returns:

Name Type Description
vtkPolyData vtkPolyData

The eroded surface mesh.

extract_edges(polydata) staticmethod

Extract boundary edges.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface polydata.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Polydata containing polylines.

extract_points(polydata) staticmethod

Extract all point coordinats from polydata surface.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface PolyData.

required

Returns:

Type Description
ndarray

np.npdarray[N, 3]: Extructed point coordinates.

extract_region(polydata, ind=0) staticmethod

Extract connected region from surface.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata

required
ind int

Index of the region. Indexes are in order from largest to smallest. Defaults to 0.

0

Returns:

Name Type Description
vtkPolyData vtkPolyData

Output surface polydata

Note

Returns largest region by default. If ind >= number of regions, None is returned.

extract_region_by_scalar(polydata, scalar_name, scalar_min, scalar_max, ind=0) staticmethod

Extract connected region from surface thresholding scalar.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata.

required
scalar_name str

Scalar array name for thresholding.

required
scalar_min float

Min scalar values.

required
scalar_max float

Max scalar values.

required
ind int

Index of the region. Indexes are in order from largest to smallest. Defaults to 0.

0

Returns:

Name Type Description
vtkPolyData vtkPolyData

Output surface polydata

Note

Returns largest region by default. If ind >= number of regions, None is returned.

extract_triangles(polydata) staticmethod

Extract triangle vertices from polydata surface.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface PolyData.

required

Returns:

Type Description
ndarray

np.npdarray[N, 3]: Extructed triangle indices.

point_data_to_cell_data(polydata, scalar_name, func=np.nanmin) staticmethod

Convert point scalar to cell scalar using func.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface polydata.

required
scalar_name str or list

Name of scalar(s) array to convert.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Surface polydata with new cell array.

remove_cells(polydata, point_ids=None, cell_ids=None, clean=True) staticmethod

Remove cells from polydata.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface polydata.

required
point_ids array_like

All cells containing this points will be removed. Defaults to None.

None
cell_ids array_like

Cell to be removed. Default to None.

None
clean bool

If True, hanging point will be removed. Defaults to True.

True

Returns:

Name Type Description
vtkPolyData vtkPolyData

Surface polydata w

select_regular_points(polydata, distance) staticmethod

Select regular points from surface. Unlike sample_regular_points, this method uses only points from input polydata.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata.

required
distance float

Distance between sampled points.

required

Returns:

Type Description
ndarray

np.ndarray: Array of selected points ids.

SurfaceFilter

Tool class for manipulating surface polydata.

Class usage is possible for:

  • surface smoothering.
  • building normals based on the data points/cells.
  • surface refinment (triangles subdivision).
  • surface extraction.

__init__()

clean(polydata, distance=0, merge_duplicate=True) staticmethod

Construct filter to sample points from surface polydata by removing points that are within the distance (duplicate points).

Parameters:

Name Type Description Default
distance float

points within distance will be merged. Defaults to 0.

0
merge_duplicate bool

If True dublicate points will be merged. Defaults to True.

True

Returns:

Name Type Description
vtkCleanPolyData vtkCleanPolyData

initialized filter object.

contours(polydata, num, vmin, vmax, scalar_name) staticmethod

Construct filter to find contours on surface.

Parameters:

Name Type Description Default
num int

Number of contours levels.

required
vmin float

Lowest contour value.

required
vmax float

Highest contour values.

required
scalar_name str

Name of the scalar array used for contouring.

required

Returns:

Name Type Description
vtkContourFilter vtkContourFilter

Initialized filter object.

extract_region(polydata, ind=0) staticmethod

Extract connected region from surface.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata

required
ind int

Index of the region. Indexes are in order from largest to smallest. Defaults to 0.

0

Returns:

Name Type Description
vtkPolyData vtkPolyData

Output surface polydata.

Note

Returns largest region by default. If ind >= number of regions, None is returned.

extract_region_by_scalar(polydata, scalar_name, scalar_min, scalar_max, ind=0) staticmethod

Extract connected region from surface thresholding scalar.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata

required
scalar_name str

Scalar array name for thresholding

required
scalar_min float

Min scalar values

required
scalar_max float

Max scalar values

required
ind int

Index of the region. Indexes are in order from largest to smallest. Defaults to 0.

0

Returns:

Name Type Description
vtkPolyData vtkPolyData

Output surface polydata.

Note

Returns largest region by default. If ind >= number of regions, None is returned.

laplacian_smoother(polydata, iters=15, relaxation=0.1) staticmethod

Smoothe surface polydata based on Laplacian smoothing.

For more info see: https://vtk.org/doc/nightly/html/classvtkSmoothPolyDataFilter.html

Parameters:

Name Type Description Default
iters int

Number of iterations. Defaults to 15.

15
relaxation float

Relaxation factor. Defaults to 0.1.

0.1

Returns:

Name Type Description
vtkSmoothPolyDataFilter vtkSmoothPolyDataFilter

initialized laplacian filter.

normals(polydata) staticmethod

Generate normals for points and triangles.

Returns:

Name Type Description
vtkPolyDataNormals vtkPolyDataNormals

initialized polydata normal.

sample_regular_points(polydata, distance, resample_factor=0.1) staticmethod

Sample points from surface polydata. To sample point from polydata without cells - first apply vertex filter.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata.

required
distance float

Distance between sampled points.

required
resample_factor float

Points will be sampled from point cloud with distance multiplied by resample_factor. Defaults to 0.1.

0.1

Returns:

Name Type Description
vtkPolyData vtkPolyData

Surface polydata after the sampling.

select_regular_points(polydata, distance) staticmethod

Select regular points from surface. Unlike sample_regular_points, this method uses only points from input polydata.

If polydata does not contain 'OriginalPointIds' it will be generated.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input surface polydata.

required
distance float

Distance between sampled points.

required

Returns:

Name Type Description
vtkPointSet vtkPointSet

Selected points

subdivide(polydata, edge_length, iterations=10) staticmethod

Subdivide triangles into parts with edge_length parameter.

Parameters:

Name Type Description Default
edge_length float

max triangles edge length.

required

Returns:

Name Type Description
vtkAdaptiveSubdivisionFilter vtkAdaptiveSubdivisionFilter

Initialized subdivision filter.

triangulate_polygons(polydata) staticmethod

Apply vtkTriangleFilter to make triangles from polygons.

Parameters:

Name Type Description Default
polydata vtkPolyData

Input polydata with polygons.

required

Returns:

Name Type Description
vtkPolyData vtkPolyData

Surface polydata with Triangles.

windowed_sinc_smoother(polydata, iters=20, pass_band=0.001, feature_angle=60.0) staticmethod

Smoothe surface polydata using windowed sinc function interpolation kernel.

For more info see: https://vtk.org/doc/nightly/html/classvtkWindowedSincPolyDataFilter.html

Parameters:

Name Type Description Default
iters int

number of iterations.

20
pass_band float

for more info see vtk doc.

0.001
feature_angle float

for more info see vtk doc.

60.0

Returns:

Name Type Description
vtkWindowedSincPolyDataFilter vtkWindowedSincPolyDataFilter

Initialized windowed sinc filter.

SurfaceGraph

Class for building graph from surface points.

__init__()

add_geodesic_distance_array(polydata, sources, max_distance=None, name='GeodesicDistance') staticmethod

Add geodesic distance values computed from sources.

Parameters:

Name Type Description Default
polydata vtkPolyData

Polydata containing surface triangles

required
sources ndarray[N]

Indexes of the points.

required
max_distance None

Maximum distance for geodesic computation. Defaults to None.

None
name str

Name of the new array. Defaults to "GeodesicDistance".

'GeodesicDistance'

Returns:

Name Type Description
vtkPolyData vtkPolyData

Surface polydata with geodesic distance array.

build_voronoi_neighbors(points, point_ids, vertices, triangles) staticmethod

Build connection between neighbor points on the surface.

This function takes in the coordinates of the points on the surface, their corresponding indices, the coordinates of the surface points, and the triangle vertices. It builds connections between neighboring points on the surface using Voronoi diagrams.

Parameters:

Name Type Description Default
points ndarray[N, 3]

Coordinates of the points on the surface.

required
point_ids ndarray[N]

Indices of the points on the surface.

required
vertices ndarray[M, 3]

Coordinates of the surface points.

required
triangles ndarray[K, 3]

Triangle vertices.

required

Returns:

Type Description
ndarray

np.ndarray[L, 2]: Connection pairs representing the connections between neighboring points on the surface.

shortest_path(polydata, source, target) staticmethod

Find shortest path between source and target points on surface.

This function uses Dijkstra's algorithm to find the shortest path between two points on a surface represented by polydata.

Parameters:

Name Type Description Default
polydata vtkPolyData

Surface polydata.

required
source int

Source point id.

required
target int

Target point id.

required

Returns:

Type Description
ndarray

np.ndarray: A list of point ids forming the path.

generate_point_ids(func)

Decorate method that require 'OriginalPointIds' generation First argument of the func should be vtkPolyData.