-
Notifications
You must be signed in to change notification settings - Fork 4
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
Boolean difference feature error #447
Comments
Hello @eduvillasr. You may need to triangulate the surface of your cube. Per the examples, both surfaces must be triangulated for the operation to work (see Boolean Operations). Try this: import pyvista as pv
cube = pv.PolyData('cube.stl').extract_surface().triangulate()
sphere = pv.PolyData('sphere.stl').extract_surface().triangulate() # In case not already triangulated
diff = cube.boolean_difference(sphere)
diff.save('diff.stl') |
Hello,
I appreciate the response. I tried to triangulate the cube as well as the
sphere and got the following error:
------------------------------------------------
ERROR:root:No points to subdivide
ERROR:root:No points/cells to operate on
ERROR:root:No points/cells to operate on
------------------------------------------------
…------------------------------------------------
Here is my code:
import pyvista as pv
cube = pv.PolyData('testcube.stl').extract_surface().triangulate()
sphere = pv.PolyData('testsphere.stl').extract_surface().triangulate()
diff = cube.boolean_difference(sphere)
diff.save('diff.stl')
p = pv.Plotter()
p.add_mesh(diff, opacity=0.5, show_edges=True, color=True)
p.show()
------------------------------------------------
We get this error when trying to boolean the sphere completely inside the
cube.
Is it possible to do this? Also, If more convenient I would love to set up
a zoom call where we can work this out? I am currently working on a
research project and would love to get this program working.
Thank you so much!
Eduardo
On Mon, Jul 12, 2021 at 12:21 PM Adam Hendry ***@***.***> wrote:
Hello @eduvillasr <https://github.com/eduvillasr>. You may need to
triangulate the surface of your cube. Per the examples, both surfaces must
be triangulated for the operation to work (see Boolean Operations
<https://docs.pyvista.org/examples/01-filter/boolean-operations.html?highlight=boolean>).
Try this:
import pyvista as pv
cube = pv.PolyData('cube.stl').extract_surface().triangulate()sphere = pv.PolyData('sphere.stl').extract_surface().triangulate() # In case not already triangulated
diff = cube.boolean_difference(sphere)diff.save('diff.stl')
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVOZHM2E4U7X2ODLU7LTXMQCVANCNFSM47EUA5BA>
.
|
Hello, Take a look at our latest development docs at https://dev.pyvista.org/api/core/_autosummary/_autosummary/pyvista.PolyDataFilters.boolean_difference.html There are quite a few enhancements to pyvista that will be released soon. To try these out, install the latest development version with: pip install git+https://github.com/pyvista/pyvista.git |
Thank you for the response. I have tried using the new development version and I receive the same errors. Thank you! |
Both meshes are triangulated as well as subdivided several times. |
There are severe limitations on VTK's Boolean filters. One thing you might try is flipping the normals on one or both of the meshes, but it might just come down to the inability for vtk to deal with this geometry. Another issue might be if your meshes aren't manifold. If you're completely sure there shouldn't be an issue, upload your meshes here and I'll look at them. |
Thank you,
I've tried to flip the normals and still have not been able to figure it
out. Attached are the two models, I would really appreciate the help!
…On Mon, Jul 12, 2021 at 5:54 PM Alex Kaszynski ***@***.***> wrote:
There are severe limitations on VTK's Boolean filters. One thing you might
try is flipping the normals on one or both of the meshes, but it might just
come down to the inability for vtk to deal with this geometry.
Another issue might be if your meshes aren't manifold. If you're
completely sure there shouldn't be an issue, upload your meshes here and
I'll look at them.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVK7SB3QQF2ISSQYHK3TXNXAXANCNFSM47EUA5BA>
.
|
@eduvillasr Hi, yes, I also get the same errors you are getting with several different geometries regardless of how much I've subdivided a mesh or how the normals are pointing. I'm sorry it's not working for you. It's also not working for me. I wish the boolean filters would work better. @akaszynski Does VTK have a boolean filter for voxel data? Perhaps the algorithms would succeed when using volumes rather than surfaces? |
@eduvillasr FYI, I will look in Kitware's C++ source code to see if I can understand how the boolean operations work for PolyData. The source code can be found on GitHub here. I've found comparing |
Sounds good to me, I'll be doing the same then. Thank you for your help. If you are able to figure it out please let me know! |
@eduvillasr I haven't found out what's happening with the boolean operators, but using |
I am getting the following error: ValueError: Empty meshes cannot be plotted. Input mesh has zero points. I am not sure if this is just a graphing error and if it has performed the operation. How could I save the result as an stl file? Thanks again! |
Here is my code^ import pyvista as pv mesh = pv.PolyData('testcube.stl') dargs = dict(show_edges=True) Rotate the mesh to have a second meshrot = pv.PolyData('testsphere.stl') ############################################################################### Mark points inside with 1 and outside with a 0select = mesh.select_enclosed_points(rot) select Extract two meshes, one completely inside and one completely outside theenclosing surface.inside = select.threshold(0.5) p = pv.Plotter() |
@eduvillasr You can save the mesh directly as an stl like so: inside.save('inside.stl')
outside.save('outside.stl') If you are getting that error though, it probably means your print(inside)
print(outside) If it shows 0 verticies or 0 cells for either, then something is up and your surfaces might not actually be intersecting. |
Well, it says it only supports .vtu and .vtk. ValueError: Invalid file extension for this data type. Must be one of: dict_keys(['.vtu', '.vtk']) inside = select.threshold(0.5) print(inside) inside.save('inside.stl') |
@eduvillasr Oh, that might be because it's not polydata yet (might be inside = select.threshold(0.5).extract_surface()
outside = select.threshold(0.5, invert=True).extract_surface()
print(inside)
print(outside)
inside.save('inside.stl')
outside.save('outside.stl') |
I tried this and the stl file is not able to be loaded. To clarify, will
this be a substitute for the boolean operation?
…On Tue, Jul 13, 2021 at 12:18 AM Adam Hendry ***@***.***> wrote:
@eduvillasr <https://github.com/eduvillasr> Oh, that might be because
it's not polydata yet (might be UnstructuredGrid data). Try using
extract_surface() before saving:
inside = select.threshold(0.5).extract_surface()outside = select.threshold(0.5, invert=True).extract_surface()
print(inside)print(outside)
inside.save('inside.stl')outside.save('outside.stl')
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVLG7DPKLMKJ4FVGD23TXPEB5ANCNFSM47EUA5BA>
.
|
@eduvillasr Yes, this is a substitute. I'm not able to recreate your problem as I can save files as stl's directly. What version of pyvista are you using? @akaszynski Can you assist? |
I am able to save them as stl files but when I open them using a 3D viewer
I get the following error:
Couldn't load that.
Error code: 0x80004005
…On Tue, Jul 13, 2021 at 1:02 PM Adam Hendry ***@***.***> wrote:
@eduvillasr <https://github.com/eduvillasr> Yes, this is a substitute.
I'm not able to recreate your problem as I can save files as stl's
directly. What version of pyvista are you using?
@akaszynski <https://github.com/akaszynski> Can you assist?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVKBKBJYAMAOA26OFQ3TXR5VHANCNFSM47EUA5BA>
.
|
@eduvillasr Show me the printout of |
First one corresponds to outside |
@eduvillasr Plot it with import pyvista as pv
mesh = pv.read('inside.stl')
p = pv.Plotter()
p.add_mesh(mesh)
p.show() and show us the output. |
Here is the output:
[image: image.png]
…On Tue, Jul 13, 2021 at 1:12 PM Adam Hendry ***@***.***> wrote:
@eduvillasr <https://github.com/eduvillasr> Plot it with pyvista. Don't
use another reader. Run:
import pyvista as pv
mesh = pv.read('inside.stl')
p = pv.Plotter()p.add_mesh(mesh)p.show()
and show us the output.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVM4Q2DUMBFPIVTCXSTTXR6ZLANCNFSM47EUA5BA>
.
|
@eduvillasr The image doesn't render. Can you please retry to add it or provide us a link to somewhere we can see it? |
@eduvillasr No problem. Looks like you got your stl! |
Well I am using this same process with a sphere inside a cube and am getting the following image The boolean function has not been performed here I visualized the model in blender to confirm that there is no hole inside the cube |
@eduvillasr Oh I see. It may be something to do with the ordering of the points and faces returned. I would use MeshLab. It's a great program and also written with VTK. |
Okay thank you, I’ll have to look into it then
On Tue, Jul 13, 2021 at 1:44 PM Adam Hendry ***@***.***> wrote:
@eduvillasr <https://github.com/eduvillasr> Oh I see. It may be something
to do with the ordering of the points and faces returned. I would use
MeshLab <https://www.meshlab.net/>. It's a great program and also written
with VTK.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVO7HXRIJXNVAAKR52DTXSCRPANCNFSM47EUA5BA>
.
--
|
I have used MeshLab and the model still does not include the operation in it. It just shows a cube like the one in the link I sent. Maybe we just can't replicate what I am trying to do using PyVista yet? |
@eduvillasr Hmmm, I'm really sorry to hear that. Perhaps that is the case. @akaszynski mentioned VTK's builtin boolean operations were troublesome. I wonder if a better algorithm is required. I was able to find the paper on which the boolean operations are based: here. Click the "Download Paper" link under the resources. There's also source code, though I believe it's in C++. I hope this will provide you some guidance that will drive you to a successful solution. I'll do my best to continue to see if there's a way to fix the common issues that occur in |
@eduvillasr Also, FWIW, I found the Mister P. MeshLab Tutorials on youtube very helpful when I was first learning MeshLab. It's been a long while since I've used it, so I couldn't tell you how to perform boolean operations in it and your needs may be more advanced than what's included in the tutorials here. However, python also has a binding for MeshLab, appropriately called pymeshlab. Since both |
Perfect I will look into these options, thank you for your help!
…On Wed, Jul 21, 2021 at 3:50 PM Adam Hendry ***@***.***> wrote:
@eduvillasr <https://github.com/eduvillasr> Also, FWIW, I found the Mister
P. MeshLab Tutorials
<https://www.youtube.com/c/MrPMeshLabTutorials/playlists> on youtube very
helpful when I was first learning MeshLab. It's been a long while since
I've used it, so I couldn't tell you how to perform boolean operations in
it and your needs may be more advanced than what's included in the
tutorials here. However, python also has a binding for MeshLab,
appropriately called pymeshlab
<https://pymeshlab.readthedocs.io/en/latest/>. Since both pyvista and
meshlab use vtk under the hood, you might have some success with pymeshlab.
Full disclosure though, I haven't used pymeshlab. Other vtk alternatives
include itk and SimpleITK, but those are also by KitWare and use VTK
under the hood.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUE5WVKXJH2DBAFHGIM6WB3TY4XHVANCNFSM47EUA5BA>
.
|
@eduvillasr Very happy to help! I enjoy it 👍🏻 |
Has this issue been resolved? I have been having a similar issue |
Unfortunately (AFAIK), not yet. I have not had time to look into this further since last year. |
I was able to create a visualization using
Not quite what I need it to do yet but it is a start. |
Hello,
This is my first time using pyvista and am running into the following error:
MY CODE:
I am trying to take the boolean difference of a small sphere located in the middle of a larger cube. The sphere is inside the cube completely and I am trying to make a small hole within the cube. When I run my command the boolean difference function is not working. I am unsure as to whether or not I can actually take the difference of one model completely inside another.
Thank you!!!
Example Data
The text was updated successfully, but these errors were encountered: