pyvista / pyvista

3D plotting and mesh analysis through a streamlined interface for the Visualization Toolkit (VTK)

Home Page:https://docs.pyvista.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clipping with implicit function

christjul opened this issue · comments

Describe the feature you would like to be added.

When clipping with a function, using the clip_surface filter, only polydata can be used as input, and therefore dependent on the resolution of the input surface, as for example:

import pyvista as pv
import vtk

# make a gridded dataset
n = 21
xx = yy = zz = 1 - np.linspace(0, n, n) * 2 / (n - 1)
dataset = pv.RectilinearGrid(xx, yy, zz)

# create surface and clip dataset
surface = pv.Cylinder(direction=(0, 0, 1), height=3.0, radius=0.5, resolution=4, capping=False)
clipped = dataset.clip_surface(surface, invert=False)

# Visualize the results
p = pv.Plotter()
p.add_mesh(surface, color='w', opacity=0.75, label='Surface')
p.add_mesh(clipped, color='gold', show_edges=True, label="clipped", opacity=0.75)
p.add_legend()
p.show()

image

A high enough resolution is then needed for accurate clipping.
For simplified geometries, implicit functions avoid the necessity of discretising properly the surface.

import pyvista as pv
import vtk

# make a gridded dataset
n = 21
xx = yy = zz = 1 - np.linspace(0, n, n) * 2 / (n - 1)
dataset = pv.RectilinearGrid(xx, yy, zz)

# make VTK implicit filter
surface = vtk.vtkCylinder()
surface.SetRadius(0.5)
surface.SetAxis(0.0, 0.0, 1.0)

clipped = dataset._clip_with_function(surface, invert=False)

# Visualize the results
p = pv.Plotter()
p.add_mesh(clipped, color='gold', show_edges=True, label="clipped", opacity=0.75)
p.add_legend()
p.show()

image

As seen in the example above, the private method _clip_with_function() already implements the clipping with implicit functions, but there is no corresponding public method in the DataSetFilters class.

Links to VTK Documentation, Examples, or Class Definitions.

https://vtk.org/doc/nightly/html/classvtkImplicitFunction.html

Pseudocode or Screenshots

No response

For the practical implementation, is it better to have the pyvista.DataSetFilters.clip_surface() method taking both polydata and implicit functions as input OR to create a new pyvista.DataSetFilters.clip_implicit() method?

The latter is closer to the implementation for slicing (pyvista.DataSetFilters.slice_implicit) but slicing has no slice_surface() method, which could be also a nice feature :-)