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

Mesh.volume() and Mesh.is_closed() don't work with Boxes and Cylinders #1171

Open
jkunimune opened this issue Aug 8, 2024 · 1 comment
Open

Comments

@jkunimune
Copy link
Contributor

Calculating the volume of a Box or a Cylinder seems to always return zero for Box and Cylinder objects, even though they plot just fine and seem overall well-formed. Similarly, is_closed() seems to always return False. Pyramids and Spheres work fine. I'm thinking it may be related to the fact that Boxes and Cylinders are wholly composed of non-triangular cells, since calling triangulate() causes them to give nonzero volumes (but they still don't register as closed).

import vedo

box = vedo.Box()
print("Box:", box.volume(), box.is_closed())

box = box.triangulate()
print("Triangulated box:", box.volume(), box.is_closed())

cylinder = vedo.Cylinder()
print("Cylinder:", cylinder.volume(), cylinder.is_closed())

cylinder = cylinder.triangulate()
print("Triangulated cylinder:", cylinder.volume(), cylinder.is_closed())

pyramid = vedo.Pyramid()
print("Pyramid:", pyramid.volume(), pyramid.is_closed())

sphere = vedo.Sphere()
print("Sphere:", sphere.volume(), sphere.is_closed())

# expected result: all volumes are nonzero and all booleans are True
# actual result:
# Box: 0.0 False
# Triangulated box: 6.000000000000002 False
# Cylinder: 0.0 False
# Triangulated cylinder: 6.211656935437641 False
# Pyramid: 0.43333333333333357 True
# Sphere: 4.157386497443854 True
@marcomusy
Copy link
Owner

Thanks for reporting.
I've added documentation for this behavior in both is_closed() and volume() methods, but also in Box and Cylinder.
Checking whether the mesh is triangular in volume() might be computationally expensive if these methods are called in loops or for large meshes.

import vedo

box = vedo.Box().triangulate().clean()
print("Box     :", box.volume(), box.is_closed(), box.is_manifold())

cylinder = vedo.Cylinder().triangulate().clean()
print("Cylinder:", cylinder.volume(), cylinder.is_closed(), cylinder.is_manifold())

pyramid = vedo.Pyramid() # not necessary, already triangulated
print("Pyramid :", pyramid.volume(), pyramid.is_closed(), pyramid.is_manifold())

sphere = vedo.Sphere()
print("Sphere  :", sphere.volume(), sphere.is_closed(), sphere.is_manifold())

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