Reputation: 31
I have two meshes that are centered in the origin of the axes, one inside the other. I have implemented an easy function in vtk to scale the internal mesh. The idea is to stop this cycle when the surface of the internal mesh comes into contact with the surface of the external one. I tried to use vtk libraries but I haven't found nothing. The vtk boolean intersection work well but seems to be useless.
Do you have any idea to solve this problem?
Is there a function in vtk that could do this?
Upvotes: 0
Views: 2207
Reputation: 1996
You can test for an intersection with vtkInterface
:
import numpy as np
import vtkInterface as vtki
# create a test sphere
sphere = vtki.Sphere(radius=1.0)
# generate a cylinder inside the sphere and change its height
# and test for an intersection
for height in np.linspace(1, 3, 50):
cylinder = vtki.Cylinder([0, 0, 0], [1, 0, 0],
0.2, height).TriFilter()
# test intersection
cut_mesh = cylinder.BooleanCut(sphere)
# cut_mesh will be empty when there's no intersection
if cut_mesh.GetNumberOfPoints():
break
plotter = vtki.PlotClass()
plotter.AddMesh(sphere, style='wireframe')
plotter.AddMesh(cylinder, 'b', opacity=0.2, showedges=False)
plotter.AddMesh(cut_mesh, 'r', showedges=False)
plotter.Plot()
This intersects when the cylinder has a height of 2.11 and generates the following plot:
I saw that you had trouble installing vtkInterface for Mac OS. I've since updated the source and uploaded 0.11.3 to PyPi. Please reinstall with:
pip install vtkInterface --upgrade
Upvotes: 1