# Use of python interactor and already built-in functions for workflow efficiency

**URL:** <https://discourse.slicer.org/t/use-of-python-interactor-and-already-built-in-functions-for-workflow-efficiency/23279>\
**Category:** Support\
**Tags:** python, file-export\
**Created:** [May 4, 2022, 2:31pm UTC](https://discourse.slicer.org/t/use-of-python-interactor-and-already-built-in-functions-for-workflow-efficiency/23279 "2022-05-04T14:31:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacktat](https://avatars.discourse-cdn.com/v4/letter/j/a9a28c/32.png) [@Jacktat](https://discourse.slicer.org/u/Jacktat)\
**Post date:** [May 4, 2022, 2:31pm UTC](https://discourse.slicer.org/t/use-of-python-interactor-and-already-built-in-functions-for-workflow-efficiency/23279/1 "2022-05-04T14:31:45Z")

</div>

Hi everyone,  
I have achieved what I want to do with slicer, which was segment a vessel, compute centerline, extract CE diameter, and compute the maximum Feret diameter of that cross-section (I want to do this for the whole vessel with a set spacing between each cross-section).  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/7/77629059c9d4d02c09cd15f1c65e8b985cf26d45.png)  
Segmentation, centerline computation and CE diameter computation were staightforward with Slicer. However, for the maximum feret diameter, I saw the cross section for a single slice in my Subject hierarchy tree, and exported the .vtk file, loaded it into MATLAB, calculated the furthest distance between all coordianates and I had it.

However, I want to do this for the whole vessel instead of only 1 cross-section, as well as for a couple more DICOM data sets. I am sure this is all programmed into the software, I’m just not sure how to do it / access these functions.

To do this I have two questions:

1. As mentioned, I currently manually calculated the feret diameter of the plane outside of Slicer, but I am pretty sure I can do this within the software. When looking through the code of e.g. CrossSectionAnalysis.py I see lines like (lines 1107-1131):

```auto
# Place a plane perpendicular to the centerline
    plane = vtk.vtkPlane()
    plane.SetOrigin(center)
    plane.SetNormal(normal)

```

…

```auto
# Cut through the closed surface and get the points of the contour.
    planeCut = vtk.vtkCutter()
    planeCut.SetInputData(closedSurfacePolyData)
    planeCut.SetCutFunction(plane)
    planeCut.Update()
    planePoints = vtk.vtkPoints()
    planePoints = planeCut.GetOutput().GetPoints()
    # 

```

So it looks like there are also built-in functions sort of doing what I want, the problem is that I dont really know how to access those functions or use the python interactor.

1. If this is not possible, can I then at least quickly export all the .vtk cross sections with a particular spacing. So that I can then do the computation myself with MATLAB?

Thanks a lot guys.  
Cheers,  
Jack

---

<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:** [May 6, 2022, 2:08pm UTC](https://discourse.slicer.org/t/use-of-python-interactor-and-already-built-in-functions-for-workflow-efficiency/23279/2 "2022-05-06T14:08:33Z")

</div>

If you are somewhat familiar with Python (and preferably with VTK library, and if you want to create GUI then also Qt) then the [PerkLab bootcamp Slicer programming tutorial](https://slicer.readthedocs.io/en/latest/developer_guide/api.html#tutorials) is a good way to learn about how to use Python scripting in Slicer.

After that you should be ready to modify the CrossSectionAnalysis.py script to allow plotting not just `MIS diameter`, `CE diameter`, and `Cross-section area` but also Feret’s diameter.
