skeletor icon indicating copy to clipboard operation
skeletor copied to clipboard

KeyErrors in by_vertex_clusters

Open Skylion007 opened this issue 2 years ago • 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

Skylion007 avatar Jan 24 '22 21:01 Skylion007

Sorry for missing this issue until now. I can't reproduce the issue. Could you perhaps share your c_mesh?

schlegelp avatar Mar 21 '22 09:03 schlegelp

@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

Skylion007 avatar Jun 07 '22 18:06 Skylion007

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

Skylion007 avatar Jun 07 '22 18:06 Skylion007

Tag @schlegelp

Skylion007 avatar Jun 08 '22 19:06 Skylion007

Will look into into - a bit swamped at the moment.

schlegelp avatar Jun 09 '22 08:06 schlegelp

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).

schlegelp avatar Jun 19 '22 21:06 schlegelp