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

edges opening after merging of two meshes #120

Closed
mkondratyev85 opened this issue Feb 4, 2020 · 4 comments
Closed

edges opening after merging of two meshes #120

mkondratyev85 opened this issue Feb 4, 2020 · 4 comments
Labels
filtering General topics around filtering and usage of filters

Comments

@mkondratyev85
Copy link

If I merge two meshes the n_open_edges property of resulting mesh is increasing from 0 to 4.

import pyvista as pv

clipped = pv.read('clipped.vtk')
#clipped.plot()

mesh = pv.read('mesh.vtk')
#mesh.plot()

# n_open_edges is 0
print(mesh.extract_geometry().n_open_edges)

mesh += clipped

# n_open_edges is 4
print(mesh.extract_geometry().n_open_edges)

clipped
mesh

meshes.zip

I suspect that the issue might be with these 'leafs' on the edges of the mesh:
clipped

Am I right? And if I am, how can I remove them from the "clipped" mesh.

@banesullivan
Copy link
Member

banesullivan commented Feb 4, 2020

Hm, this is odd. To start, we can figure out where the edges of the mesh are via the extract_edges filter:

import pyvista as pv

clipped = pv.read('clipped.vtk')
print(clipped.extract_geometry().n_open_edges)

mesh = pv.read('mesh.vtk')
print(mesh.extract_geometry().n_open_edges)

merged = mesh + clipped
print(merged.extract_geometry().n_open_edges)

0
0
4

geom = merged.extract_geometry()
edges = geom.extract_edges(boundary_edges=True,
                   feature_edges=False,
                   manifold_edges=False)

p = pv.Plotter()
p.add_mesh(edges, color="red", line_width=5)
p.add_mesh(mesh, opacity=0.5, color="lightblue")
p.add_mesh(clipped, opacity=0.5, color="green")
p.camera_position = [(7.801336112237166, 251.0279128488682, 236.18977047349765),
 (47.05759233540398, 50.995165371104854, 24.41602276196233),
 (0.18847718989496154, -0.6962632417999844, 0.692599340894485)]
p.show()

download

but those edges are not open in the original meshes, just the merged mesh. I believe what. is happening here is that there are duplicated nodes and thee + operator is merging those points and opening edges. To avoid this, you should explicitly use the merge filter (the + operator is simply calling that filter with default parameters).

merged = mesh.merge(clipped, merge_points=False)
print(merged.extract_geometry().n_open_edges)

0

@banesullivan banesullivan added the filtering General topics around filtering and usage of filters label Feb 4, 2020
@banesullivan banesullivan changed the title n_open_edges after merging of two meshes due to strange cells on the edges of one of the mesh edges opening after merging of two meshes Feb 4, 2020
@mkondratyev85
Copy link
Author

Thank you for the answer. I've tried your suggestion and it has worked!

But when I increase the resolution of my meshes (I try to replicate simple geological structures) I meet the strange error.

meshes.zip

In the meshes.zip are two meshes I try to merge (but with slightly higher resolution). I successfully merge them with your approach. And when I read n_open_edges property of the result it is equal to 0.

Then, after I triangulate the result and save to the vtk file and check if with the Sfepy script that shows you if your mesh is OK it says me following:

sfepy: reading mesh [line2, tri3, quad4, tetra4, hexa8] (/tmp/question/merged.vtk)...
sfepy: ...done in 0.18 s
sfepy: CMesh: n_coor: 9692, dim 3, tdim: 3, n_el 25386
sfepy: element types: ['3_4']
sfepy: nodal BCs: []
sfepy: bounding box:
x: [ 0.0000000e+00,  1.0000000e+02]
y: [-1.7763568e-15,  1.0000000e+02]
z: [-1.4799686e+00,  5.4992756e+01]
sfepy: centre:           [ 5.0000000e+01,  5.0000000e+01,  2.6756394e+01]
sfepy: coordinates mean: [ 5.0114061e+01,  4.9927150e+01,  3.0189309e+01]
sfepy: warning: bad element orientation, trying to correct...
sfepy: ...corrected
sfepy: volumes of 44698 1D entities:
min: 0.0000000e+00 mean: 6.5867666e+00 median: 6.2928724e+00 max: 1.5499791e+01
sfepy: volumes of 60408 2D entities:
min: 0.0000000e+00 mean: 1.3895868e+01 median: 1.4366345e+01 max: 4.2905610e+01
sfepy: volumes of 25386 3D entities:
min: -0.0000000e+00 mean: 9.8874923e+00 median: 9.2336103e+00 max: 2.4642392e+01
sfepy: Euler characteristic: 16
sfepy: number of connected components: 27
sfepy: warning: mesh with topological dimension 2 lower than space dimension 3
sfepy: - element orientation not checked!
sfepy: surface Euler characteristic: 32
sfepy: surface genus: -15.0
sfepy: number of connected surface components: 27

The values of Euler characteristic and number of connected components for the volume mesh must both be equal to 1. In my case it's 16 and 27 for the volume. I don't now where to see these parameters in the pyvista, that's why I showed the result of Sfepy script.

What it could be?

@banesullivan
Copy link
Member

Huh, I had never heard of the Euler characteristic (and we do not have a way to compute that in PyVista).

As for the connected surface components... when you merge your meshes, you will have different non-connected components in the merged mesh... in order to not, you'd need to use point merging then repair the open edges with a tool like https://pymeshfix.pyvista.org

@adamgranthendry
Copy link

adamgranthendry commented Jul 14, 2021

@banesullivan The Euler Characteristic determines the type of surface in topology. In particular, it determines the number of holes an object has. In 3D, the Euler Characteristic is computed as V-E+F. For bodies of genus 0 (i.e. solid bodies without holes), V-E+F=2 (you get this for all the regular polyhedra, for example), where V=Vertices, E=Edges, and F=Faces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
filtering General topics around filtering and usage of filters
Projects
None yet
Development

No branches or pull requests

3 participants