calc_skeleton_mesh_intersect - jaybgager/tracertools GitHub Wiki
This function calculates all the points at which a skeleton intersects a mesh. The point coordinates for bones and mesh triangles must be in the same voxel resolution.
Arguments:
bones((n,2,3)-shape numpy array of floats, mandatory)- an array of pairs of point coordinates that define the edges ("bones") of the skeleton
mesh_triangles((n,3,3)-shape numpy array of floats)- an array of trios of point coordinates for the vertices of the triangles of the mesh
Returns:
intersections(varies, see description)- a list of the intersection points between the skeleton and the mesh as a (3)-shape numpy arrays of floats if any were found
- if no intersections were found, returns
Noneinstead
Example
Since this code requires a skeleton's bones and a mesh's triangles, here's an example of how you could get those using other tracertools functions.
INPUT:
import tracertools as tt
# this part gets the skeleton for a given segment
skel = tt.get_seg_skeletons(
datastack = "brain_and_nerve_cord",
seg_ids = [720575941526718564],
)[0]
# this part gets the list of individual skeleton edges, or "bones", from the skeleton
bone_list = tt.get_bones(
datastack = "brain_and_nerve_cord",
skeleton = skel,
)
# this part gets a list of all the mesh's faces, or "triangles"
triangles = tt.get_mesh_triangles(
volume_path = "https://c10s.pni.princeton.edu/tracers/examples/banc_mesh_01|neuroglancer-precomputed:"
)
Now that you have a list of bones and triangles, you can use the following code to check if any of the bones intersect any of the triangles:
INPUT:
intersections = tt.calc_skeleton_mesh_intersect(
bones = bone_list,
mesh_triangles = triangles,
)
print(intersections)
OUTPUT:
[array([121305., 181906., 4627.]),
array([123200., 172384., 4720.]),
array([124027., 174945., 5243.]),
array([124240., 176101., 5346.]),
array([123934., 175092., 5244.]),
array([127158., 175525., 4693.]),
array([125175., 175250., 5344.]),
array([125127., 174504., 5263.]),
array([125315., 175057., 5311.]),
array([122142., 175971., 4855.])]
[!NOTE] This function uses the
NumbaPython package to bypass the Python interpreter and compile directly to machine code using theJITcompiler to dramatically speed up the calculation time for segments/meshes with large numbers of bones/faces. Although no issues with this have yet been encountered, there are anecdotal reports online of occasional memory leakage with Numba. If you encounter this, please let us know by submitting an Issue.