Repository navigation
Open
Description
Describe the bug
Given: The mesh is received from Speckle as a list of vertices and faces, but some of the vertices are duplicated.
The mesh was constructed and the following checks were performed:
mesh.is_manifold() -> True
mesh.is_connected() -> False # because some of the vertices are duplicated
mesh.is_valid() -> True
mesh.is_trimesh() -> TrueAfter the usage of a method, the results are following
mesh.remove_duplicate_vertices()
mesh.is_manifold() -> True
mesh.is_connected() -> True # The connectivity was fixed
mesh.is_valid() -> False
mesh.is_trimesh() -> False # Probably because of the TOL.geometric_key some collision happensInstead, if a comparison of equality of vertices is done in way when we compare sets of coordinates directly, doesn't cause this collision
def validate_mesh(input_mesh: Mesh) -> Mesh:
input_coordinates = [tuple(input_mesh.vertex_coordinates(vertex)) for vertex in input_mesh.vertices()]
no_duplicates_coordinates = list(set([tuple(input_mesh.vertex_coordinates(vertex)) for vertex in input_mesh.vertices()]))
all_updated_faces = []
for face in sorted(list(input_mesh.faces())):
vertices_lst = input_mesh.face_vertices(face) # vertices list like [12, 13, 14]
vertex0 = input_coordinates[vertices_lst[0]]
vertex1 = input_coordinates[vertices_lst[1]]
vertex2 = input_coordinates[vertices_lst[2]]
new_index0 = no_duplicates_coordinates.index(vertex0)
new_index1 = no_duplicates_coordinates.index(vertex1)
new_index2 = no_duplicates_coordinates.index(vertex2)
updated_faces = [new_index0, new_index1, new_index2]
# print(updated_faces)
all_updated_faces.append(updated_faces)
new_mesh = Mesh.from_vertices_and_faces(vertices = no_duplicates_coordinates,
faces = all_updated_faces)
return new_meshThe result
new_mesh = validate_mesh(mesh)
new_mesh.is_manifold() -> True
new_mesh.is_connected() -> True
new_mesh.is_valid() -> True
new_mesh.is_trimesh() -> TrueSince there are no specific tests for a mesh.remove_duplicate_vertices() function, I'd assume that it's reasonable to modify it a bit. If needed, I'd be happy to contribute.
To Reproduce
Steps to reproduce the behavior:
- Context [Jupyter Notebook, latest compas installed]
- Sample data
Mesh itself
[(1.624855, 4.584075, 3.408143), (1.624855, 4.470224, 3.4), (1.624855, 4.470224, 3.4)]
[(1.624855, 4.470224, 3.4), (1.624855, 4.470224, 3.8), (1.624855, 4.52715, 3.804071)]
[(1.624855, 4.866152, 4.143074), (1.624855, 4.870224, 4.2), (1.624855, 5.270224, 4.2)]
[(1.624855, 5.270224, 4.2), (1.624855, 5.262081, 4.086148), (1.624855, 5.237818, 3.974614)]
[(1.624855, 5.237818, 3.974614), (1.624855, 5.197929, 3.867668), (1.624855, 5.143226, 3.767487)]
[(1.624855, 5.143226, 3.767487), (1.624855, 5.074823, 3.676111), (1.624855, 4.994112, 3.5954)]
[(1.624855, 4.994112, 3.5954), (1.624855, 4.902736, 3.526997), (1.624855, 4.802556, 3.472294)]
[(1.624855, 4.802556, 3.472294), (1.624855, 4.69561, 3.432406), (1.624855, 4.584075, 3.408143)]
[(1.624855, 4.584075, 3.408143), (1.624855, 4.470224, 3.4), (1.624855, 4.52715, 3.804071)]
[(1.624855, 4.854021, 4.087307), (1.624855, 4.866152, 4.143074), (1.624855, 5.270224, 4.2)]
[(1.624855, 5.270224, 4.2), (1.624855, 5.237818, 3.974614), (1.624855, 5.143226, 3.767487)]
[(1.624855, 5.143226, 3.767487), (1.624855, 4.994112, 3.5954), (1.624855, 4.802556, 3.472294)]
[(1.624855, 4.802556, 3.472294), (1.624855, 4.584075, 3.408143), (1.624855, 4.52715, 3.804071)]
[(1.624855, 4.834076, 4.033834), (1.624855, 4.854021, 4.087307), (1.624855, 5.270224, 4.2)]
[(1.624855, 5.270224, 4.2), (1.624855, 5.143226, 3.767487), (1.624855, 4.802556, 3.472294)]
[(1.624855, 4.802556, 3.472294), (1.624855, 4.52715, 3.804071), (1.624855, 4.582917, 3.816203)]
[(1.624855, 4.806725, 3.983744), (1.624855, 4.834076, 4.033834), (1.624855, 5.270224, 4.2)]
[(1.624855, 4.802556, 3.472294), (1.624855, 4.582917, 3.816203), (1.624855, 4.63639, 3.836147)]
[(1.624855, 4.772523, 3.938056), (1.624855, 4.806725, 3.983744), (1.624855, 5.270224, 4.2)]
[(1.624855, 4.802556, 3.472294), (1.624855, 4.63639, 3.836147), (1.624855, 4.68648, 3.863499)]
[(1.624855, 4.732168, 3.8977), (1.624855, 4.772523, 3.938056), (1.624855, 5.270224, 4.2)]
[(1.624855, 5.270224, 4.2), (1.624855, 4.802556, 3.472294), (1.624855, 4.68648, 3.863499)]
[(1.624855, 4.68648, 3.863499), (1.624855, 4.732168, 3.8977), (1.624855, 5.270224, 4.2)]
[(2.024855, 4.584075, 3.408143), (2.024855, 4.470224, 3.4), (2.024855, 4.470224, 3.4)]
[(2.024855, 4.470224, 3.4), (2.024855, 4.52715, 3.804071), (2.024855, 4.470224, 3.8)]
[(2.024855, 4.866152, 4.143074), (2.024855, 5.270224, 4.2), (2.024855, 4.870224, 4.2)]
[(2.024855, 5.270224, 4.2), (2.024855, 5.237818, 3.974614), (2.024855, 5.262081, 4.086148)]
[(2.024855, 5.237818, 3.974614), (2.024855, 5.143226, 3.767487), (2.024855, 5.197929, 3.867668)]
[(2.024855, 5.143226, 3.767487), (2.024855, 4.994112, 3.5954), (2.024855, 5.074823, 3.676111)]
[(2.024855, 4.994112, 3.5954), (2.024855, 4.802556, 3.472294), (2.024855, 4.902736, 3.526997)]
[(2.024855, 4.802556, 3.472294), (2.024855, 4.584075, 3.408143), (2.024855, 4.69561, 3.432406)]
[(2.024855, 4.584075, 3.408143), (2.024855, 4.52715, 3.804071), (2.024855, 4.470224, 3.4)]
[(2.024855, 4.854021, 4.087307), (2.024855, 5.270224, 4.2), (2.024855, 4.866152, 4.143074)]
[(2.024855, 5.270224, 4.2), (2.024855, 5.143226, 3.767487), (2.024855, 5.237818, 3.974614)]
[(2.024855, 5.143226, 3.767487), (2.024855, 4.802556, 3.472294), (2.024855, 4.994112, 3.5954)]
[(2.024855, 4.802556, 3.472294), (2.024855, 4.52715, 3.804071), (2.024855, 4.584075, 3.408143)]
[(2.024855, 4.834076, 4.033834), (2.024855, 5.270224, 4.2), (2.024855, 4.854021, 4.087307)]
[(2.024855, 5.270224, 4.2), (2.024855, 4.802556, 3.472294), (2.024855, 5.143226, 3.767487)]
[(2.024855, 4.802556, 3.472294), (2.024855, 4.582917, 3.816203), (2.024855, 4.52715, 3.804071)]
[(2.024855, 4.806725, 3.983744), (2.024855, 5.270224, 4.2), (2.024855, 4.834076, 4.033834)]
[(2.024855, 4.802556, 3.472294), (2.024855, 4.63639, 3.836147), (2.024855, 4.582917, 3.816203)]
[(2.024855, 4.772523, 3.938056), (2.024855, 5.270224, 4.2), (2.024855, 4.806725, 3.983744)]
[(2.024855, 4.802556, 3.472294), (2.024855, 4.68648, 3.863499), (2.024855, 4.63639, 3.836147)]
[(2.024855, 4.732168, 3.8977), (2.024855, 5.270224, 4.2), (2.024855, 4.772523, 3.938056)]
[(2.024855, 5.270224, 4.2), (2.024855, 4.68648, 3.863499), (2.024855, 4.802556, 3.472294)]
[(2.024855, 4.68648, 3.863499), (2.024855, 5.270224, 4.2), (2.024855, 4.732168, 3.8977)]
[(2.024855, 4.470224, 3.4), (1.624855, 4.470224, 3.8), (1.624855, 4.470224, 3.4)]
[(2.024855, 4.470224, 3.4), (2.024855, 4.470224, 3.8), (1.624855, 4.470224, 3.8)]
[(2.024855, 4.470224, 3.8), (1.624855, 4.52715, 3.804071), (1.624855, 4.470224, 3.8)]
[(2.024855, 4.470224, 3.8), (2.024855, 4.52715, 3.804071), (1.624855, 4.52715, 3.804071)]
[(2.024855, 4.52715, 3.804071), (1.624855, 4.582917, 3.816203), (1.624855, 4.52715, 3.804071)]
[(2.024855, 4.52715, 3.804071), (2.024855, 4.582917, 3.816203), (1.624855, 4.582917, 3.816203)]
[(2.024855, 4.582917, 3.816203), (1.624855, 4.63639, 3.836147), (1.624855, 4.582917, 3.816203)]
[(2.024855, 4.582917, 3.816203), (2.024855, 4.63639, 3.836147), (1.624855, 4.63639, 3.836147)]
[(2.024855, 4.63639, 3.836147), (1.624855, 4.68648, 3.863499), (1.624855, 4.63639, 3.836147)]
[(2.024855, 4.63639, 3.836147), (2.024855, 4.68648, 3.863499), (1.624855, 4.68648, 3.863499)]
[(2.024855, 4.68648, 3.863499), (1.624855, 4.732168, 3.8977), (1.624855, 4.68648, 3.863499)]
[(2.024855, 4.68648, 3.863499), (2.024855, 4.732168, 3.8977), (1.624855, 4.732168, 3.8977)]
[(2.024855, 4.732168, 3.8977), (1.624855, 4.772523, 3.938056), (1.624855, 4.732168, 3.8977)]
[(2.024855, 4.732168, 3.8977), (2.024855, 4.772523, 3.938056), (1.624855, 4.772523, 3.938056)]
[(2.024855, 4.772523, 3.938056), (1.624855, 4.806725, 3.983744), (1.624855, 4.772523, 3.938056)]
[(2.024855, 4.772523, 3.938056), (2.024855, 4.806725, 3.983744), (1.624855, 4.806725, 3.983744)]
[(2.024855, 4.806725, 3.983744), (1.624855, 4.834076, 4.033834), (1.624855, 4.806725, 3.983744)]
[(2.024855, 4.806725, 3.983744), (2.024855, 4.834076, 4.033834), (1.624855, 4.834076, 4.033834)]
[(2.024855, 4.834076, 4.033834), (1.624855, 4.854021, 4.087307), (1.624855, 4.834076, 4.033834)]
[(2.024855, 4.834076, 4.033834), (2.024855, 4.854021, 4.087307), (1.624855, 4.854021, 4.087307)]
[(2.024855, 4.854021, 4.087307), (1.624855, 4.866152, 4.143074), (1.624855, 4.854021, 4.087307)]
[(2.024855, 4.854021, 4.087307), (2.024855, 4.866152, 4.143074), (1.624855, 4.866152, 4.143074)]
[(2.024855, 4.866152, 4.143074), (1.624855, 4.870224, 4.2), (1.624855, 4.866152, 4.143074)]
[(2.024855, 4.866152, 4.143074), (2.024855, 4.870224, 4.2), (1.624855, 4.870224, 4.2)]
[(2.024855, 4.870224, 4.2), (1.624855, 5.270224, 4.2), (1.624855, 4.870224, 4.2)]
[(2.024855, 4.870224, 4.2), (2.024855, 5.270224, 4.2), (1.624855, 5.270224, 4.2)]
[(2.024855, 5.270224, 4.2), (1.624855, 5.262081, 4.086148), (1.624855, 5.270224, 4.2)]
[(2.024855, 5.270224, 4.2), (2.024855, 5.262081, 4.086148), (1.624855, 5.262081, 4.086148)]
[(2.024855, 5.262081, 4.086148), (1.624855, 5.237818, 3.974614), (1.624855, 5.262081, 4.086148)]
[(2.024855, 5.262081, 4.086148), (2.024855, 5.237818, 3.974614), (1.624855, 5.237818, 3.974614)]
[(2.024855, 5.237818, 3.974614), (1.624855, 5.197929, 3.867668), (1.624855, 5.237818, 3.974614)]
[(2.024855, 5.237818, 3.974614), (2.024855, 5.197929, 3.867668), (1.624855, 5.197929, 3.867668)]
[(2.024855, 5.197929, 3.867668), (1.624855, 5.143226, 3.767487), (1.624855, 5.197929, 3.867668)]
[(2.024855, 5.197929, 3.867668), (2.024855, 5.143226, 3.767487), (1.624855, 5.143226, 3.767487)]
[(2.024855, 5.143226, 3.767487), (1.624855, 5.074823, 3.676111), (1.624855, 5.143226, 3.767487)]
[(2.024855, 5.143226, 3.767487), (2.024855, 5.074823, 3.676111), (1.624855, 5.074823, 3.676111)]
[(2.024855, 5.074823, 3.676111), (1.624855, 4.994112, 3.5954), (1.624855, 5.074823, 3.676111)]
[(2.024855, 5.074823, 3.676111), (2.024855, 4.994112, 3.5954), (1.624855, 4.994112, 3.5954)]
[(2.024855, 4.994112, 3.5954), (1.624855, 4.902736, 3.526997), (1.624855, 4.994112, 3.5954)]
[(2.024855, 4.994112, 3.5954), (2.024855, 4.902736, 3.526997), (1.624855, 4.902736, 3.526997)]
[(2.024855, 4.902736, 3.526997), (1.624855, 4.802556, 3.472294), (1.624855, 4.902736, 3.526997)]
[(2.024855, 4.902736, 3.526997), (2.024855, 4.802556, 3.472294), (1.624855, 4.802556, 3.472294)]
[(2.024855, 4.802556, 3.472294), (1.624855, 4.69561, 3.432406), (1.624855, 4.802556, 3.472294)]
[(2.024855, 4.802556, 3.472294), (2.024855, 4.69561, 3.432406), (1.624855, 4.69561, 3.432406)]
[(2.024855, 4.69561, 3.432406), (1.624855, 4.584075, 3.408143), (1.624855, 4.69561, 3.432406)]
[(2.024855, 4.69561, 3.432406), (2.024855, 4.584075, 3.408143), (1.624855, 4.584075, 3.408143)]
[(2.024855, 4.584075, 3.408143), (1.624855, 4.470224, 3.4), (1.624855, 4.584075, 3.408143)]
[(2.024855, 4.584075, 3.408143), (2.024855, 4.470224, 3.4), (1.624855, 4.470224, 3.4)]
- See error
Viewer fails to visualize because trimesh structure is broken
Screenshots
Desktop (please complete the following information):
- iOS M4
- Python version 3.12
- Python package manager Conda
Metadata
Metadata
Assignees
Labels
No labels
Activity
tomvanmele commentedon Mar 28, 2025
hi,
thanks for posting this!
have you tried changing the precision setting?
for example
tomvanmele commentedon Mar 28, 2025
perhaps we could also add a flag regrading the method of comparison:
hash(default) v.coordinatesor something like that
2twenity commentedon Mar 28, 2025
As for the precision parameter, sure. I just double-checked it and the result was the same.
tomvanmele commentedon Mar 28, 2025
the mesh is defined with the triplets of vertices above?
tomvanmele commentedon Mar 28, 2025
tomvanmele commentedon Mar 28, 2025
tomvanmele commentedon Mar 28, 2025
i get
Truefor all print statements.tomvanmele commentedon Mar 28, 2025
this is not what you're looking for?
2twenity commentedon Mar 28, 2025
Maybe I've pasted already cleaned mesh, let me double check
2twenity commentedon Mar 28, 2025
Interesting that rebuilding Mesh from coordinates only automatically removes duplicates.
from 194 to 48 vertices
Here's a list of faces, hope it helps to reproduce the initial mesh
Double checked vertices as well
2twenity commentedon Mar 28, 2025
Vertices as a 1d list
tomvanmele commentedon Mar 28, 2025
thanks, will have a look. tomorrow though :)
tomvanmele commentedon Mar 28, 2025
tomvanmele commentedon Mar 28, 2025
the problem is not with the removal of duplicates. it is just that there are two invalid faces. removing the faces with zero area results in a valid mesh...
tomvanmele commentedon Mar 28, 2025
from_triangles=> number of faces = 92from_vertices_and_faces=> number of faces = 94from_vertices_and_faces+ remove zero area faces => number of faces = 92tomvanmele commentedon Mar 28, 2025
tomvanmele commentedon Mar 28, 2025
remove_duplicate_vertices only welds vertices. it doesn't collapse edges and/or faces. perhaps this is a bit misleading. will see if i can reformulate this...
2twenity commentedon Mar 29, 2025
Should we consider development of some mesh validation functionality? Let's say automated rebuilding of mesh from triangles, so we get rid of duplicated vertices and zero area faces
jf--- commentedon Jun 26, 2025
@2twenity
compas_cgalhas strong cards for doing so