How to extract both x-, y-, z-coordinates and normalvector at each point of centerline of airwaysegmentation

Hi. I want to extract a centerline of an airwaysegmentation. I have tried out different tools for this, among other SlicerVMTK extension, but always ending up in a situation with only the possibility of exporting x-, y-, z-coordinates but without corresponding normalvectors that indicate the actual curvature at each point.

It is possible to export the centerline with both the points and the corresponding normalvector at each point?

Tangent, normal, and binormal vectors can be easily computed from curve points anywhere, anytime, using a coordinate system generator class, such as vtkParallelTransportFrame, so we don’t need to save these vectors.

You can conveniently access these vectors in the world coordinate system in Slicer’s Python console as numpy arrays:

curveNode = getNode("OC")
curveNode.GetMeasurement("curvature mean").SetEnabled(True)
positions = slicer.util.arrayFromMarkupsCurvePoints(curveNode, True)
normals = slicer.util.arrayFromMarkupsCurveData(curveNode, "Normals", True)
curvatures = slicer.util.arrayFromMarkupsCurveData(curveNode, "Curvature", True)

If you prefer, you can access all these arrays as VTK polydata (to easily use in VTK filters or write to file):

curveNode.GetCurveCoordinateSystemGeneratorWorld().Update()
curvePolyData = curveNode.GetCurveCoordinateSystemGeneratorWorld().GetOutput()

Ahh thanks, that helped a lot, seems like the whole medical imaging industry can always rely on you lassoan :slight_smile:

1 Like

I got the normals exported and was just about using it for a program im developing, when i noticed that the normals is not exactly what i expected them to be. I want them to indicate the normal to the plane to each point facing towards the next point, instead they seem to indicate the normal from the side if that makes any sense. I have tried to extract the centerline in Simpleware SCANIP, where they indicate what i want them to, but i would rather use 3D slicer, since it is open-source! :smile: Here are some pictures (first 3d slicer, second scanip):

Do you think there is any way i can calculate and export them in way so they indicate what i want them to?

Okay figured out myself that extracting the tangents would achieve what i wanted. Now I have a new problem… :slight_smile:

When using the “Extract Centerline” module, i set the curve sampling distance to 0.1269mm (Image 1), this gives 517 controlpoints spread along the centerline (Image 2). But when I want to save the positions and corresponding tangents (using the commands you showed me) to a csv file, I end up with way more points, 5375 points (Image 3).

I want to extract points with the specific distance 0.1269mm and then the corresponding tangents. Is there a way to access the tangents at each controlpoint instead?

So far I have made a way to calculate the tangents between each controlpoint, but do think there is a way this should be done more precise or is it as good as it gets?