fix_mesh does not support MeshNeuron
dokato opened this issue · 2 comments
Is there a reason why:
> mesh = navis.MeshNeuron("meshes/720575940577508022.ply")
> type(mesh1)
Out[5]: navis.core.neurons.MeshNeuron
> fixed = sk.pre.fix_mesh(mesh, remove_disconnected=5, inplace=False)
throws silent assertion error?
---> 68 assert isinstance(mesh, tm.Trimesh)
69
70 if not inplace:
AssertionError:
For convenience of using preprocessing functions it would be nice to support MeshNeuron objects.
The reason in this case is the inplace
parameter that allows you to have the fixes applied to the original mesh instead of making a copy and fixing + returning that:
The whole point of this setting is to save some memory and overhead by not making a copy. But editing inplace=True
would be a bit pointless if we had to first generate a trimesh (e.g. from a MeshNeuron
) anyway.
There were already a few ways to work around this:
Use skeletor.utilities.make_trimesh
- this function is very flexibly and will take pretty much anything with vertices and faces. Setting validate=True
will also automatically run fix_mesh
.
>>> fixed = sk.utilities.make_trimesh(mesh, validate=True)
Explicitly use the trimesh representation of your neuron: MeshNeuron.trimesh
>>> fixed = sk.pre.fix_mesh(mesh.trimesh, remove_disconnected=5, inplace=False)
On the code side, I just pushed a small update with aeb9112 that makes fix_mesh
more flexible: it now accepts any mesh-like object (including MeshNeuron
) but will ignore inplace=True
if the input is not already a trimesh. So your original code approach will now also work.
I'm closing this as the issue has been fixed with the release of skeletor 1.0.0