KeyErrors in by_vertex_clusters
Skylion007 opened this issue · 8 comments
I noticed that sk.skeletonize.by_vertex_clusters can generate KeyErrors when the sampling_dist at certain values like 0.01. Changing the sampling distance to a value that can be represented better by floating point works fine though.
Example Traceback:
Traceback (most recent call last):
File "skeletor_data/contract_mesh.py", line 12, in <module>
skele = sk.skeletonize.by_vertex_clusters(c_mesh, sampling_dist=0.01)
File "skeletor/skeletonize/vertex_cluster.py", line 193, in by_vertex_clusters
vertex_to_node_map = np.array([new_ids[n] for n in vertex_to_node_map])
File "skeletor/skeletonize/vertex_cluster.py", line 193, in <listcomp>
vertex_to_node_map = np.array([new_ids[n] for n in vertex_to_node_map])
KeyError: 413
Sorry for missing this issue until now. I can't reproduce the issue. Could you perhaps share your c_mesh
?
@schlegelp
Here is a reproducer:
import sys
import trimesh as tm
import skeletor as sk
mesh_filename = sys.argv[1]
tm_mesh = tm.load(mesh_filename)
tm_mesh.show()
tm_mesh = sk.pre.simplify(tm_mesh, ratio=0.1)
sk.pre.fix_mesh(tm_mesh, remove_disconnected=5, inplace=True)
c_mesh = sk.pre.contract(tm_mesh, epsilon=0.1)
c_mesh.show()
print("Contracted")
skele = sk.skeletonize.by_vertex_clusters(c_mesh, sampling_dist=0.175)
skele.mesh = tm_mesh
sk.post.clean_up(skele)
sk.post.radii(skele, method='knn')
skele.show(mesh=True)
On the Stanford Armadillo Mesh: http://graphics.stanford.edu/pub/3Dscanrep/armadillo/Armadillo.ply.gz
Traceback:
Traceback (most recent call last):
File "skele_mesh.py", line 12, in <module>
skele = sk.skeletonize.by_vertex_clusters(c_mesh, sampling_dist=0.175)
File "/Users/agokaslan/venvs/ai_habitat_sys_py3/lib/python3.8/site-packages/skeletor/skeletonize/vertex_cluster.py", line 191, in by_vertex_clusters
vertex_to_node_map = np.array([new_ids[n] for n in vertex_to_node_map])
File "/Users/agokaslan/venvs/ai_habitat_sys_py3/lib/python3.8/site-packages/skeletor/skeletonize/vertex_cluster.py", line 191, in <listcomp>
vertex_to_node_map = np.array([new_ids[n] for n in vertex_to_node_map])
KeyError: 2925
Tag @schlegelp
Will look into into - a bit swamped at the moment.
Strangely, this works just fine for me. You could perhaps share the c_mesh
you feed into the skeletonization?
On a side note: you might want to use the inplace=True
parameter when you run sk.post.clean_up(skele)
.