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

Unexpected cleaning result #45

Open
MarcelHeu opened this issue Jul 28, 2022 · 2 comments
Open

Unexpected cleaning result #45

MarcelHeu opened this issue Jul 28, 2022 · 2 comments

Comments

@MarcelHeu
Copy link

Hey,

I try to repair the following mesh (a dental bridge):

1
2

Within the mesh are some holes and also intersecting triangles. I use the function tin.small_boundaries() and if i detect intersecting triangles also tin.clean(max_iters=10, inner_loops=3). Unfortunately, the dental bridge is split, leaving only one tooth in the end:

3

Do you maybe have some ideas how i can fix this issue? You can find the used source code and the *.stl file below:
ScriptAndModel.zip

# -*- coding: utf-8 -*-
import pymeshfix



def plotMesh(tin):
    
    # return vertices and faces
    vertices, faces = tin.return_arrays()
    
    # Create object from vertex and face arrays
    meshfix = pymeshfix.MeshFix(vertices, faces)

    # Plot input
    meshfix.plot()





# Create TMesh object
tin = pymeshfix.PyTMesh()

# load stl file
tin.load_file("bridge08.stl")

# visualize input Mesh
plotMesh(tin)



###############################################################################
# CLEANING ROUTINE

# Attempt to join nearby components
# tin.join_closest_components()

# Fill holes
tin.fill_small_boundaries()
print('There are {:d} boundaries'.format(tin.boundaries()))

# check for intersecting triangles
faces = [tin.select_intersecting_triangles()]

# if intersecting triangles are detected within the mesh
if faces:
    # Clean (removes self intersections)
    tin.clean(max_iters=10, inner_loops=3)
###############################################################################



# visualize output Mesh
plotMesh(tin)
@akaszynski
Copy link
Member

Got it partially working:

First, split the mesh into the three individual bodies. They're not connected at all.

import pymeshfix
import pyvista as pv

# we're going to subdivide, for whatever reason this helps meshfix
mesh = pv.read("bridge08.stl")
sub_div = mesh.subdivide(1)

bodies = pv.MultiBlock([body.extract_surface() for body in sub_div.split_bodies()])
bodies.plot(multi_colors=True)

sc0

Next, let's join the first and last body (the teeth I'm assuming?)

# join the bodies within pyvista
joined = bodies[0].boolean_union(bodies[2])
bodies[1] = bodies[1].compute_normals(flip_normals=True)
final = joined.compute_normals(auto_orient_normals=True).clean()

# clean
tin = pymeshfix.PyTMesh()
tin.load_array(final.points, final.faces.reshape(-1, 4)[:, 1:])
tin.clean()
mfix = pymeshfix.MeshFix(*tin.return_arrays())
mfix.plot()

sc1

The hard part is now the dental bridge. I'm not able to get pyvista to merge it using any boolean_* filter, nor will pymeshfix accept it; it keeps removing it and using join_closest_components just isn't working. I'm a bit at a loss how to proceed. There might be a way to do this by manually dropping faces from the "bridge" (bodies[1]), as I think PyVista and meshfix really don't like how that surface is configured as it sorta wraps in on itself:

bodies[1].plot_normals(mag=0.1)

sc2

I hope at least helps you out a bit!

@MarcelHeu
Copy link
Author

Thank you, this is helping me a lot! I now have a better understanding of why it doesn't work well.

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