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

Meshfix leaves only one triangle #23

Open
TroyWilliams3687 opened this issue Nov 7, 2020 · 4 comments
Open

Meshfix leaves only one triangle #23

TroyWilliams3687 opened this issue Nov 7, 2020 · 4 comments

Comments

@TroyWilliams3687
Copy link

I have a bad mesh generated from another piece of software. I am trying to figure out what exactly the problem is so that I can provide some feedback to the software developers. I thought I would try some independent solutions.

Here is the obj file:
section 5.zip

I am learning how to use PyVista and I have run it through mesh cleaning there. It seems to work fine and clean up the mesh to a state where it is consistent (if you translate the original mesh to the origin and determine the volume, it is different). After cleaning it is consistent. However the cleaning routine isn't verbose (or I haven't figured out) enough to tell me what problems it encountered during the cleaning process.

I decided to try this library.

I have the following code:

import pyvista as pv
import pyvistaqt as pvqt # allow for rendering in a background thread in a separate window

# pv.set_plot_theme('document')

bad_mesh_path = Path('./data/section 5.obj')
m = pv.read(bad_mesh_path)

print(f'volume = {m.volume}')
print(f'faces  = {m.n_faces}')
print(f'points = {m.n_points}')
print(f'bounds = {m.bounds}')
print()

meshfix = pymeshfix.MeshFix(m) # this fails directly
meshfix.repair(verbose=True)
repaired = meshfix.mesh

print()
print(f'volume = {repaired.volume}')
print(f'faces  = {repaired.n_faces}')
print(f'points = {repaired.n_points}')
print(f'bounds = {repaired.bounds}')
print()

repaired.plot()

It produces the following output:

volume = 149.95313299066808
faces  = 132
points = 396
bounds = [613887.6875, 613902.5, 8453912.0, 8453914.0, 2711.08740234375, 2722.792236328125]

Removed 131 small components
Patching holes...
Patched 1 holes
Fixing degeneracies and intersections
Patching holes...
Patched 1 holes
Performing final check...

volume = 289258.8383483886
faces  = 1
points = 3
bounds = [613888.0, 613888.4375, 8453913.0, 8453914.0, 2716.02978515625, 2716.990966796875]

The fixed mesh only has one triangle and 3 points, something is very wrong.

I do notice that running it through PyVista's clean routine the number of points it removes is quite large.

I would appreciate any insight. For what I am doing, I don't necessarily need a repair - that is nice, what I need is a detailed diagnosis of what is wrong with the mesh.

If you need any more wireframes, let me know. I have quite a few of them.

@TroyWilliams3687 TroyWilliams3687 changed the title Meshfix fails on mesh - Leaves only one triangle Meshfix leaves only one triangle Nov 7, 2020
@banesullivan
Copy link
Member

The PyVista clean filter simply removes duplicate points. Cells share points to provide connectivity and your original mesh does not let the cells share points. Effectively, the original mesh you provide is a set of 132 different, non-connected surfaces (1 surface is 1 cell). Using PyVista's clean filter, you merge the duplicated nodes to repair the connectivity of the mesh. This is why you see a more accurate calculation of the volume after cleaning the mesh.

The fixed mesh only has one triangle and 3 points, something is very wrong.

This makes sense. PyMeshFix extracts the first surface it sees and tries to repair it. Since your mesh is 132 different, non-connected surfaces, this is expected. PyMeshFix cannot handle this mesh in its original state, you must use the clean filter before feeding it to PyMeshFix.

@TroyWilliams3687
Copy link
Author

TroyWilliams3687 commented Nov 15, 2020

Hi Bane, thank you for the information. That is really helpful! I was wondering why the Pyvista.clean method could remove so many points.

Also, I didn't mean to lay any blame on the tools - I know there was something wrong with the mesh but I wasn't sure what the problem was.

How did you discover that it was a set of 132 non-connected surfaces? I would be very interested in understanding that. I tend to get a lot of terrible meshes from people. Outside of obvious problems (internal faces, duplicate points and faces), I am usually out of my depth.

Are you aware of any routines that can take a mesh and identify the issues like this without fixing them?

@banesullivan
Copy link
Member

banesullivan commented Dec 14, 2020

How did you discover that it was a set of 132 non-connected surfaces?

Intuition/experience. I had a hunch and took a look at the cell connectivity.

Also, PyVista has a connectivity filter for labeling the connected parts of a mesh. I'm not sure if I used that filter but it should definitely do this labeling for you to tell you it is indeed ~132 separated surfaces.

See https://docs.pyvista.org/core/filters.html#pyvista.DataSetFilters.connectivity

Are you aware of any routines that can take a mesh and identify the issues like this without fixing them?

Generally, I am not aware. Meshes can have any one of a million problems and I typically check a few like connectivity from experience working with meshes. Finding out what's wrong with a mesh isn't a very general problem but you could probably come up with a few checks and have PyVsita evaluate those checks. E.g.:

  • is it one connected surface?
  • is it a closed/watertight surface?
  • is it all triangles? (if that's what you expect)
  • etc.

If interested in creating a list of checks and how to evaluate them, please open a new support issue in https://github.com/pyvista/pyvista-support


FYI, apologies for the very slow response

@TroyWilliams3687
Copy link
Author

Hay Bane, thanks for the reply, it is helpful.

I am seeing a lot of those problems with meshes. I'll see what I can do. If I come up with anything useful I'll contribute back to the project.

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