meshpro / optimesh

:spider_web: Mesh optimization, mesh smoothing.
575 stars 56 forks source link

Degenerate triangles too high threshold #52

Closed AlbertoMQ closed 4 years ago

AlbertoMQ commented 4 years ago

Using Optimesh 0.6.3

Identified degenerate triangle of area 0 with the following vertices which do not give an area of 0.

[ 80.45627594 -37.35506439 -34.14894485] [ 80.27935791 -37.60939026 -34.39572525] [ 80.77883911 -37.62064743 -34.39271545]

nschloe commented 4 years ago

I need an MWE to reproduce.

AlbertoMQ commented 4 years ago

My code. Still happens without all the remove functions. 5mm-groove-0.5mm-scan-mm-cropped-2.zip

import numpy as np
import open3d as o3d
import optimesh

myfile = "above file ^"
mesh = o3d.io.read_triangle_mesh(myfile)
mesh = mesh.remove_duplicated_vertices() 
mesh = mesh.remove_unreferenced_vertices() 
mesh = mesh.remove_duplicated_triangles() 
mesh = mesh.remove_degenerate_triangles() 
xyz = np.asarray(mesh.vertices) 
faces = np.asarray(mesh.triangles)
mymesh, cells = optimesh.odt.fixed_point_uniform(xyz, faces, 1.0e-4, 100)
nschloe commented 4 years ago

This code is not complete.

AlbertoMQ commented 4 years ago

Just added the import statements. Everything else should be there

nschloe commented 4 years ago

Yeah, seems like the imports were missing. For me, it was impossible to tell it really was only imports though, so thanks for adding them.

Unfortunately, I still can't run the code. I'm using Python 3.8 which isn't supported by open3d yet. Is it possible to create an MWE without open3d? Otherwise let's just wait.

AlbertoMQ commented 4 years ago

I can do with pymesh as well. Not sure if it works in 3.8. I know it works for 3.6. There are probably other ways to import the data.

import numpy as np
import pymesh
import optimesh

myfile = "above file ^"
mesh = pymesh.load_mesh(myfile)
xyz = np.copy(np.asarray(mesh.vertices))
faces = np.copy(np.asarray(mesh.faces))
mymesh, cells = optimesh.odt.fixed_point_uniform(xyz, faces, 1.0e-4, 100)
nschloe commented 4 years ago

This doesn't work. Error:

AttributeError: module 'pymesh' has no attribute 'load_mesh'
AlbertoMQ commented 4 years ago

Ah that might have to do with how pymesh was installed, looks like the pip version only takes in .sty and .obj files. I installed using anaconda. conda install -c conda-forge pymesh2

Thanks for trying. I can try and find another package that will load .ply files

nschloe commented 4 years ago

https://github.com/nschloe/meshio does. Edit: Fixing a PLY read bug in meshio right now.

AlbertoMQ commented 4 years ago

I'm getting an error with meshio. Wonder if it has to do with that read bug

AttributeError: 'NoneType' object has no attribute 'groups'

in

line 96, in read_buffer types = m.groups()[:2]

nschloe commented 4 years ago

That's what I'm talking about.

AlbertoMQ commented 4 years ago

I can also load

import trimesh
mesh = trimesh.load(filename)
xyz = np.asarray(mesh.vertices)
faces = np.asarray(mesh.faces)
mymesh, cells = optimesh.odt.fixed_point_uniform(xyz, faces, 1.0e-4, 100)
nschloe commented 4 years ago

meshio 4.0.9 can now read it:

import meshio
import optimesh

mesh = meshio.read("5mm-groove-0.5mm-scan-mm-cropped-2.ply")
xyz = mesh.points
faces = mesh.get_cells_type("triangle")
mymesh, cells = optimesh.odt.fixed_point_uniform(xyz, faces, 1.0e-4, 100)

This gives the error

AssertionError: Degenerate cell.

Looking into it.

nschloe commented 4 years ago

Okay, that was easy. It seems that you have a proper 3D surface: 3d But since this is a scan, there is no implicit surface as it is here https://github.com/nschloe/optimesh#surface-mesh-smoothing. optimesh is bound to fail then; in your case, after an iteration or so, it produces a degenerate triangle.

AlbertoMQ commented 4 years ago

I see, so the optimal shape and its gradient needs to be know in order to smooth the mesh.

nschloe commented 4 years ago

Indeed. If this is not provided, it may be possible to invent some heuristics, but this is outside the scope of optimesh.