Approximate anatomical axis (curve) of long bone

Hi devs.

I developed a script to parcelate a long bone. This parcells can then be used to calculate their centroids and with that points create the anatomical axis (curve).

Right now the script is missing somo thresholds and consideration of special cases to find the centroids of the parcelated pieces and create the curve from them.

Do you think I should finish it? or there is some limitations I’m not considering that would make this algorithm not work?

It searches the surface’s first principal component vector and uses it as normal of a plane with origin in the centroid of the bone to cut it and use that intersection as input for the geodesicDistanceFilter.

Here are some pictures:

Here is the script:

# find anatomical axis curve of bone

import numpy as np

model = getNode('mymodel')
parcelationLength = 9

numberOfSampledPointsOfModel = 2000
if model.GetPolyData().GetNumberOfPoints() > numberOfSampledPointsOfModel:
  maskPointsFilter = vtk.vtkMaskPoints()
  ratio = round(model.GetPolyData().GetNumberOfPoints()/numberOfSampledPointsOfModel)
  # This works but the sampling could be biased spatially I think
  # If you have vtk9 you should use UNIFORM_SPATIAL_SURFACE option
  polydata = vtk.vtkPolyData()
  # Calculate the SVD and mean
  from vtk.util.numpy_support import vtk_to_numpy
  modelPoints = vtk_to_numpy(polydata.GetPoints().GetData())
  from vtk.util.numpy_support import vtk_to_numpy
  modelPoints = vtk_to_numpy(model.GetPolyData().GetPoints().GetData())

# Calculate the mean of the points, i.e. the 'center' of the cloud
modelPointsMean = modelPoints.mean(axis=0)

# Do an SVD on the mean-centered data.
uu, dd, rightSingularVectors = np.linalg.svd(modelPoints - modelPointsMean)

# Create a frame for the model
modelZ = np.zeros(3)
modelX = rightSingularVectors[0]

# Cut the bone at the half and find the centroid
plane = vtk.vtkPlane()

cutter = vtk.vtkCutter()

pointData = cutter.GetOutput().GetPoints().GetData()
from vtk.util.numpy_support import vtk_to_numpy
seedPoints = vtk_to_numpy(pointData)

meshLocator = vtk.vtkPointLocator()

seeds = vtk.vtkIdList()
for i in range(len(seedPoints)):
  pointIDOfClosestPoint = meshLocator.FindClosestPoint(seedPoints[i]);

geodesicDistance = slicer.vtkFastMarchingGeodesicDistance()

parcelatedRegions = vtk.vtkPolyData()

pointScalars = parcelatedRegions.GetPointData()
distanceArray = pointScalars.GetArray("GeodesicDistance")

tempParcelationArray = vtk.vtkIntArray()
numberOfPoints = parcelatedRegions.GetNumberOfPoints()

for i in range(parcelatedRegions.GetNumberOfPoints()):
  distance = distanceArray.GetTuple1(i)
  if distance < (parcelationLength/2):
    parcellID = 0
    parcellID = int((distance-parcelationLength/2) // parcelationLength) +1



# Set up coloring by selection array
model.GetDisplayNode().SetActiveScalar("TempParcelationArray", vtk.vtkAssignAttribute.POINT_DATA)
scalarRange = model.GetDisplayNode().GetScalarRange()

I wonder how it would work with deformed bones because if it works well it could be used by researchers.

I was thinking that maybe the geodesic distance should be weighted by the inverse of the curvature (there is an option for this in the filter) but I’m not sure it would give me a usable result. I think the propagation speed may vary too much. What do you think?

For long curved structures I would use VMTK for simple geometry based or Voronoi diagram based centerline extraction. The resulting curve can be used to reslice and quantify the cross-sections using Cross-section analysis module.

Maybe you could also discuss applications with @jmhuie (developer of SegmentGeometry extension), who so far worked with straight axes but might be interested in curved axes as well.

This seems like a neat feature.

Ultimately, it could be cool to implement the ability to slice through a curve structure, while following the trajectory curvature. Although, I am not sure that this the way to do it. It could be used to measure the length of a curved structure for sure.

You can already do this using SlicerVMTK extension. You can even straighten a curved structure (preserving length and cross-section shape) using Sandbox extension’s Curved Planar Reformat module.

I was attempting to give this script a try, but I get an error that slicer.vtkFastMarchingGeodesicDistance() does not exist. Might I be missing a needed extension? If so, which one?

You just need latest Slicer Preview Release.
It’s the same filter used by DynamicModeler’s SelectByPoints tool

1 Like

OK, thanks, I have been using 2021-10-14, so I’ll update again.