meshpro / pygalmesh

:spider_web: A Python interface to CGAL's meshing tools
GNU General Public License v3.0
597 stars 57 forks source link

How can I import two .stl surfaces and then compute their difference? #135

Closed alexfoxfox closed 3 years ago

alexfoxfox commented 3 years ago

Dear All,

I need to compute the difference between two triangulated surfaces saved into .stl files.
My problem is that at the moment I am using the vtkIntersectionPolyData filter to accomplish this task however this VTK fitler is known to be not robust and goes into infinite loop when computing intersections of some surfaces I have deal with. I hoped the CGAL/pygalmesh intersection algorithm would be more robust.

How can I do it?

I tried:

import pygalmesh as pg

mesh1=meshio.read("mesh1.stl")
mesh2=meshio.read("mesh2.stl")
res=pg.Difference(mesh1,mesh2)

The last line (pg.Difference) produces the following exception:

res=pg.Difference(surface_mesh, roi_mesh)
TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. _pygalmesh.Difference(arg0: _pygalmesh.DomainBase, arg1: _pygalmesh.DomainBase)

Invoked with:

 <meshio mesh object>
  Number of points: 1335
  Number of cells:
    triangle: 2661, <meshio mesh object>
  Number of points: 44
  Number of cells:
    triangle: 84
  Cell data: facet_normals

What should I do to make it work? Do I need to convert the meshio mesh object to the pygalmesh.DomainBase object somehow (how?) or something else is needed? The example would be greatly appreciated.

Best Regards,

Alex

nschloe commented 3 years ago

Well, you can just plug a meshio mesh into pygalmesh routine and expect things to work. In fact, pygalmesh only supports set operations (diff, intersection etc.) with pygalmesh domain objects (as the error message says), so Ball, Cube etc. What you need to do is to somehow transform your meshes into domains, but pygalmesh is the wrong tool for the task I think.

alexfoxfox commented 3 years ago

Well, then I would think the usability of this is somehow limited IMO. Note that all C++ counterparts of GTS, CGAL and VTK can import meshes as native objects. People mostly work with CAD models and scanned meshes, not Balls, Cubes etc. In the meantime, I was able to fix the vtkIntersectionPolyData filter infinite loop bug and wrap it into Python, so I will continue using the VTK Python wrappings instead.

Best,

Alex

On Thu, Mar 25, 2021 at 5:34 PM Nico Schlömer @.***> wrote:

Closed #135 https://github.com/nschloe/pygalmesh/issues/135.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nschloe/pygalmesh/issues/135#event-4510503717, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF62RWJ7S3HB6WGH2NQWWETTFO27LANCNFSM4ZWFZ5VA .