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.
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)
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.