meshpro / pygalmesh

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

Non manifold interface between two meshes #209

Open SalvishGoomanee opened 1 year ago

SalvishGoomanee commented 1 year ago

I would like to know if it is possible to create the non-manifold interface when two surface meshes merge together?

Is this implemented in PyGalmesh or do we have to code it by hand?

Here is my code which results in the merging of two Balls whose surfaces are both meshed:


import pygalmesh
import pyvista as pv 

# Merge two meshes PyGalmesh
radius = 1.0
displacement = 0.5
s0 = pygalmesh.Ball([displacement, 0, 0], radius)
s1 = pygalmesh.Ball([-displacement, 0, 0], radius)
u = pygalmesh.Difference(s0, s1)

# add circle
a = np.sqrt(radius ** 2 - displacement ** 2)
max_edge_size_at_feature_edges = 0.15
n = int(2 * np.pi * a / max_edge_size_at_feature_edges)
alpha = np.linspace(0.0, 2 * np.pi, n + 1)
alpha[-1] = alpha[0]
circ = a * np.column_stack([np.zeros(n + 1), np.cos(alpha), np.sin(alpha)])

mesh = pygalmesh.generate_surface_mesh(
    u,
    # extra_feature_edges=[circ],
    # max_cell_circumradius=0.15,
    # max_edge_size_at_feature_edges=max_edge_size_at_feature_edges,
    min_facet_angle=25,
    max_radius_surface_delaunay_ball=0.15,
    # max_circumradius_edge_ratio=2.0,
)

mesh.write('double_mesh.mesh')
display = pv.read('double_mesh.mesh')
display.plot(style='wireframe', color='tan', show_scalar_bar=False, show_axes=False, show_edges=True)

# display the two meshes merged together - this should normally create a non-manifold interface...?
union = pygalmesh.Union([u, s1])
mesh_union = pygalmesh.generate_surface_mesh(union,
                                             # max_cell_circumradius=0.15,
                                             # max_edge_size_at_feature_edges=max_edge_size_at_feature_edges,
                                             min_facet_angle=25,
                                             max_radius_surface_delaunay_ball=0.15,
                                             # max_circumradius_edge_ratio=2.0
                                             )

mesh_union.write('double_mesh_union.mesh')
display = pv.read('double_mesh_union.mesh')
display.plot(style='wireframe', color='tan', show_scalar_bar=False, show_axes=False, show_edges=True)

Thank you for any input.