vedo
vedo copied to clipboard
how to speed up cut_with_mesh?
I have a complicate mesh, and I want to cut some region with a cube. I use Mesh.cut_with_mesh to do it.
However, the mesh is very large so that the cut_with_mesh would cost 80s. Is it possible to speed up it? Or is there any other method which is faster?
Yes: https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_box
Yes: https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_box
Thank you very much. I will try it.
Yes: https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_box
If [xmin,xmax, ymin,ymax, zmin,zmax] is used to generate a cube, the direction is x=[1, 0, 0], y=[0, 1, 0], z=[0, 0, 1] . How can I generate a cube with specific direction?
Is it possible to create the box with topPoint1, topPoint2, topPoint3, topPoint4, bottomPoint1, bottomPoint2, bottomPoint3, bottomPoint4?
You may obtain the result by using 6 planes with https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_planes or https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_plane
You may obtain the result by using 6 planes with https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_planes or https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_plane
I have tried it, but the result is wrong. My code is:
import vedo
mesh1 = vedo.Mesh('before.obj').alpha(0.3).color('r')
a = mesh1.bounds()
print(a)
centers=[
[25.54791, 131.90236, 570.03764],
[46.95663, 83.99182, 511.02341],
[58.50379, 42.54272, 577.24325],
[37.09508, 90.45326, 636.25748]
]
normals = [
[0.34503, -0.93555, 0.07544],
[-0.07840, 0.05137, 0.99560],
[-0.34503, 0.93555, -0.07544],
[0.07840, -0.05137, -0.99560]
]
planes = []
for i in range(4):
p = vedo.Plane(pos=centers[i], normal=normals[i], s=[100, 100])
planes.append(p)
mesh2 = mesh1.clone().cut_with_planes(origins=centers, normals=normals).color('b').alpha(0.3)
vedo.show(mesh1, planes, mesh2)
The test data is:
The result of code is:
The four gray planes is used to cut the mesh. I hope the region included by the planes is cutted. But nothing is cutted.
Any suggestion is appreciated~~~
This seems to do the job:
import numpy as np
import vedo
mesh1 = vedo.Mesh("data/before.obj").color("r5", 0.3)
# print(mesh1)
centers = np.array([
[25.54791, 131.9023, 570.03764],
[46.95663, 83.99182, 511.02341],
[58.50379, 42.54272, 577.24325],
[37.09508, 90.45326, 636.25748],
])
normals = -np.array([ # NOTE THE MINUS SIGN
[0.34503, -0.93555, 0.07544],
[-0.07840, 0.05137, 0.99560],
[-0.34503, 0.93555, -0.07544],
[0.07840, -0.05137, -0.99560],
])
planes = []
for i in range(4):
p = vedo.Plane(centers[i], normals[i], s=[100, 100])
planes.append(p)
arrows = vedo.Arrows(centers, centers+normals*20, c="k")
mesh2 = mesh1.clone().cut_with_planes(centers, normals, invert=1)
mesh2.color("b5", 0.3)
vedo.show(planes, mesh2, arrows, axes=8)
but to be honest I don't understand why flipping the normals is not equivalent to setting invert flag.
but to be honest I don't understand why flipping the normals is not equivalent to setting invert flag.
It is really weird. After add minus sign, it works for invert=True/False.
I have posted it in vtk forum: https://discourse.vtk.org/t/vtkclippolydata-incorrectly-work/13046