seung-lab / zmesh

Marching Cubes & Mesh Simplification on multi-label 3D images.
GNU General Public License v3.0
58 stars 8 forks source link

Problems simplifying meshes #15

Closed schlegelp closed 2 years ago

schlegelp commented 4 years ago

Hi Will,

I somewhat randomly stumbled on your library in search of something to simplify a flywire mesh. The example code seems pretty straight forward yet I don't get the expected results:

>>> from cloudvolume import CloudVolume
>>> vol = CloudVolume('graphene://[...]/fly_v26')
>>> mesh = vol.mesh.get(720575940610453042)[720575940610453042]
>>> # Very large mesh -> hard to work with
>>> mesh
Mesh(vertices<990112>, faces<1887184>, normals<0>, segid=720575940610453042, encoding_type=<draco>)

>>> from zmesh import Mesher
>>> # Assuming isotropy since mesh has coordinates in nm
>>> mesher = Mesher( (1,1,1) )
>>> # Tried ramping up max error
>>> simp = mesher.simplify(mesh, 100, max_error=4e6, compute_normals=False)
>>> # Lost some vertices but no faces
>>> simp
Mesh(vertices<938272>, faces<1887184>, normals<None>)

Any pointers?

Thanks a bunch! :)

william-silversmith commented 4 years ago

Hi Philipp, this is pretty odd. I'm going to look into this some more as I wasn't able to understand why this is happening on first inspection. It's possible the lack of deduplication in the graphene downloads has something to do with it, but one would think that would be the sort of thing a simplifier would be good at handling.

schlegelp commented 4 years ago

Thanks Will - I very much appreciate you looking into this. By "deduplication", do you mean merging of duplicate vertices, etc? I tried that too (using trimesh) but that didn't appear to make the difference.

william-silversmith commented 4 years ago

I'm planning on looking into this next week now that I'm back from break!

william-silversmith commented 4 years ago

It looks like the optimizer is aborting after a single cycle. The top value of the heap_ variable is NaN. That's our first breadcrumb.

nkemnitz commented 4 years ago

I have seen warnings about degenerate triangles in Meshlab before when trying to import some of our Neuroglancer meshes. Could be that there are some triangles that got collapsed to lines or points, i.e. have 0 area...

william-silversmith commented 4 years ago

That's a good point. I'll keep that in mind as I investigate. It's entirely possible that there's a missing check somewhere.

william-silversmith commented 3 years ago

Hi Philipp,

It's taking me some time to figure this out. I'm gonna have to read some of the papers as it wasn't simple to identify the problem. In the mean time, I found some alternative implementations of mesh simplification. I haven't been able to try them out yet, but if you have time give them a shot and let me know how they did.

https://github.com/jannessm/quadric-mesh-simplification
https://github.com/3DLIRIOUS/MeshLabXML

schlegelp commented 3 years ago

Thanks Will! I'll have a look at these libraries. The first one looks very interesting at first glance. Inconveniently they only provide wheels for Linux (thinking about lay users). Makes me appreciate you always making wheels for all major platforms all the more :)

For the record: I ended up piggy-backing on trimesh's interfaces with Blender 3D for now.

william-silversmith commented 2 years ago

As an alternative, I worked with the authors of pyfqmr to get a binary released: https://github.com/Kramer84/pyfqmr-Fast-Quadric-Mesh-Reduction

schlegelp commented 2 years ago

Nice! pyfqmr is 5-8 times faster than open3d and Blender!

william-silversmith commented 2 years ago

FYI this issue was fixed in https://github.com/seung-lab/zmesh/commit/f6097dfc2632ddde49da938764f5c42ed73092e8 (I believe). Let me know if it isn't!