How can I draw normal vectors of a centerline in the 3D slicer?

Dear respected experts,

Please teach me how to draw normal vectors in the 3D slicer.

I want to draw the normal vectors of the centerline of blood vessels obtained by VMTK’s “Extract centerline” module to visualize the torsions of blood vessels. However, despite googling the 3D slicer forum or other WEB resources, I don’t know how to do it.

I know the centerline markup created with VMTK contains a tangent vector, normal vector, and binormal vector at each control point, and they can be extracted as Numpy arrays. I want to display these vectors at each control point.

I would be deeply grateful if you could provide me with some hints on how to do it or where to look.

Regards,

A neurosurgeon from Japan

I have been curious enough about the ‘torsion’ you mentioned. The quick-and-dirty function below creates a Model node mapping the normals along a centerline curve generated by the ‘Extract centerline’ module.

The ‘torsion’ is not really apparent on the few centerlines I have tested. If you can, please post a demonstrative image.

def showCenterlineCurveNormals(curveNode):
    curve = curveNode.GetCurveWorld()
    normals = curve.GetPointData().GetArray("Normals")
    numberOfPoints = curve.GetNumberOfPoints()
    
    points = vtk.vtkPoints()
    visuals = vtk.vtkPolyData()
    visuals.AllocateEstimate(numberOfPoints, 2)
    visuals.SetPoints(points)
    
    for i in range(numberOfPoints):
        p1 = curve.GetPoint(i)
        p2 = [0.0] * 3
        normal = normals.GetTuple3(i)
        vtk.vtkMath().Add(normal, p1, p2)
        
        cellIds = vtk.vtkIdList()
        id = points.InsertNextPoint(p1)
        cellIds.InsertNextId(id)
        id = points.InsertNextPoint(p2)
        cellIds.InsertNextId(id)
        
        visuals.InsertNextCell(vtk.VTK_POLY_LINE, cellIds)
    
    visuals.Squeeze()
    model = slicer.modules.models.logic().AddModel(visuals)

Dear chir.set SET,

Than you very much for your help.
I am going to try your code.

I am attaching the image of a case of internal carotid artery with coloring according to curvature and torsion.

I would like to utilize the torsion of vessel in some way.

Regards,

Masaaki

You can easily draw the tangent, normal, and binormal vector directions for a curve. We normally use this for testing. How to get this feature:

  1. Open the Python console in Slicer (Ctrl+3)
  2. Copy-paste the vector drawing code from into the Python console
  3. Draw normals for the first curve in the scene by copy-pasting this code into the Python console:
curveNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsCurveNode")
addCoordinateSystemUpdater(createCoordinateSystemsModel(curveNode))

Dear Andras Lasso sensei,

Thanks a lot.

I tried the magic code right away. However, I got the error message as shown in the attached image.

Could you please help me again?

I also looked into “addCoordinateSystemUpdator”. For some reason, I couldn’t use it in my environment.

MacStudio, M2, MacOS Sonoma 14.6.1
Slicer 5.6.2 r32448 / f10cd8c

Regards,

Masaaki

By the way, when application is starting, such messages appears in the python console:

Python 3.9.10 (main, Apr 5 2024, 00:33:09)
[Clang 14.0.6 (https://github.com/tru/llvm-release-build 686807a176470032c208f2 on darwin

Failed to load vtkSlicerCrossSectionAnalysisModuleLogicPython: No module named vtkSlicerShapeModuleMRMLPython
Failed to load vtkSlicerStenosisMeasurement3DModuleLogicPython: No module named vtkSlicerShapeModuleMRMLPython
[Qt] Error(s):
[Qt] CLI executable: /Applications/Slicer.app/Contents/Extensions-32448/SlicerVMTK/lib/Slicer-5.6/qt-loadable-modules/vtkvmtk.py
[Qt] The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.
[Qt] Fail to instantiate module “vtkvmtk”
[Qt] The following modules failed to be instantiated:
[Qt] vtkvmtk
[Qt] Populating font family aliases took 92 ms. Replace uses of missing font family “.AppleSystemUIFont” with one that exists to avoid this cost.
[FD] 2024-08-19 17:49:10.513 Slicer[69837:4024985] NSEventModifierFlagFunction specified to -setKeyEquivalentModifierMask: for item <NSMenuItem: 0x600007cd9570 PopClipを表示, ke=‘Command-F15’>, but is only supported for system-provided menu items; will not be used

You need to copy the highlighted piece of code from github to the Slicer Python console. It will fix the ... not defined error in the screenshot. You can ignore the messages that are logged during startup.

Thank you so much.
You are working hard and helping many researchers. Take care !
Regards,

1 Like