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

how to speed up cut_with_mesh? #1004

Open
zhang-qiang-github opened this issue Jan 4, 2024 · 8 comments
Open

how to speed up cut_with_mesh? #1004

zhang-qiang-github opened this issue Jan 4, 2024 · 8 comments

Comments

@zhang-qiang-github
Copy link

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?

@marcomusy
Copy link
Owner

@zhang-qiang-github
Copy link
Author

Yes: https://vedo.embl.es/autodocs/content/vedo/vedo/pointcloud.html#Points.cut_with_box

Thank you very much. I will try it.

@zhang-qiang-github
Copy link
Author

zhang-qiang-github commented Jan 5, 2024

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?

@zhang-qiang-github
Copy link
Author

zhang-qiang-github commented Jan 8, 2024

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:

before.zip

The result of code is:

image

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~~~

@marcomusy
Copy link
Owner

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)

Screenshot from 2024-01-08 12-14-30

but to be honest I don't understand why flipping the normals is not equivalent to setting invert flag.

@zhang-qiang-github
Copy link
Author

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.

@zhang-qiang-github
Copy link
Author

I have posted it in vtk forum: https://discourse.vtk.org/t/vtkclippolydata-incorrectly-work/13046

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants