Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clipping with implicit function #5772

Open
christjul opened this issue Mar 14, 2024 · 1 comment
Open

Clipping with implicit function #5772

christjul opened this issue Mar 14, 2024 · 1 comment
Labels
feature-request Please add this cool feature!

Comments

@christjul
Copy link
Contributor

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

@christjul christjul added the feature-request Please add this cool feature! label Mar 14, 2024
@christjul
Copy link
Contributor Author

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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Please add this cool feature!
Projects
None yet
Development

No branches or pull requests

1 participant