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

**URL:** <https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933>\
**Category:** Support\
**Tags:** centerlines, vmtk-centerline\
**Created:** [August 18, 2024, 5:11pm UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933 "2024-08-18T17:11:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mssm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mssm/32/76622_2.png) [@mssm](https://discourse.slicer.org/u/mssm)\
**Post date:** [August 18, 2024, 5:11pm UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/1 "2024-08-18T17:11:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chir.set](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/chir.set/32/66982_2.png) [@chir.set](https://discourse.slicer.org/u/chir.set)\
**Post date:** [August 18, 2024, 8:33pm UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/2 "2024-08-18T20:33:20Z")

</div>

> [@mssm](#):
>
> draw the normal vectors of the centerline

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.

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![mssm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mssm/32/76622_2.png) [@mssm](https://discourse.slicer.org/u/mssm)\
**Post date:** [August 18, 2024, 11:39pm UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/3 "2024-08-18T23:39:25Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/6/66ab3585b1f41b82844134f9474fff6c9e50639c.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 19, 2024, 8:17am UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/4 "2024-08-19T08:17:01Z")

</div>

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](https://github.com/Slicer/Slicer/blob/bf4af8a947a6bf080ce09a199c379cdb4394e7ae/Modules/Loadable/Markups/Testing/Python/MarkupsCurveCoordinateFrameTest.py#L14-L76) from into the Python console
3. Draw normals for the first curve in the scene by copy-pasting this code into the Python console:

```python
curveNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLMarkupsCurveNode")
addCoordinateSystemUpdater(createCoordinateSystemsModel(curveNode))

```

---

<div class="post-metadata">

**Author:** ![mssm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mssm/32/76622_2.png) [@mssm](https://discourse.slicer.org/u/mssm)\
**Post date:** [August 19, 2024, 8:38am UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/5 "2024-08-19T08:38:51Z")

</div>

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](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

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/6/76bbf89393e57e02fe5efc08f118dda476ebf3e2.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 19, 2024, 9:54am UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/6 "2024-08-19T09:54:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mssm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mssm/32/76622_2.png) [@mssm](https://discourse.slicer.org/u/mssm)\
**Post date:** [August 19, 2024, 11:00pm UTC](https://discourse.slicer.org/t/how-can-i-draw-normal-vectors-of-a-centerline-in-the-3d-slicer/37933/7 "2024-08-19T23:00:54Z")

</div>

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