# Can I extract the outline of a single closed segment?

**URL:** https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360
**Category:** Development
**Created:** [December 3, 2019, 10:24am UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360 "2019-12-03T10:24:18Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [December 3, 2019, 10:24am UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/1 "2019-12-03T10:24:18Z")

</div>

Can I extract the outline/contour of each slice of closed segment and then draw a closed curve from it with code?

---

<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: [December 3, 2019, 2:38pm UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/2 "2019-12-03T14:38:32Z")

</div>

Yes, sure. You can retrieve the closed surface representation of the segment, get intersection by using VTK cut filter, sort the points using vtkContourTriangulator, then add the polygon points as curve control points. This code may help: [https://github.com/Slicer/Slicer/pull/1075/files](https://github.com/Slicer/Slicer/pull/1075/files)

---

<div class="post-metadata">

### Author: ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)
#### Post date: [December 4, 2019, 2:38pm UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/3 "2019-12-04T14:38:42Z")

</div>

I donnot know how to get intersection and create a closed curve from points after covert the segment to a polygon data with python(just learned python). Could you help me?  
segmentationNode=getNode(‘Segmentation’)  
segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0)  
segmentPolyData=segmentationNode.GetClosedSurfaceRepresentation(segmentId)

---

<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: [December 4, 2019, 3:06pm UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/4 "2019-12-04T15:06:54Z")

</div>

Once you have the closed surface representation, use standard VTK filters, as they are used in the segmentation displayable manager (see relevant code in the pull request above). You can get learn about VTK by studying the [VTK textbook](https://lorensen.github.io/VTKExamples/site/VTKBook/01Chapter1/) and [VTK examples website](https://lorensen.github.io/VTKExamples/site/).

---

<div class="post-metadata">

### Author: ![Ge\_Tang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ge_tang/32/9935_2.png) [@Ge\_Tang](https://discourse.slicer.org/u/Ge_Tang)
#### Post date: [March 25, 2021, 5:20pm UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/5 "2021-03-25T17:20:41Z")

</div>

Hallo, Dr. Lassoan. I also want to get the outline from a reformat slice.  
I tried the vtk cutter. The problem is that the polydata I get from the segment do not have the attribute of GetOutputPort().

> n = getNode(nameSeg)  
> s = n.GetSegmentation()  
> ss = s.GetSegment(s.GetSegmentIdBySegmentName(nameRegion)).GetRepresentation(‘Closed surface’)  
> circleCutter = vtk.vtkCutter()
> 
> # I cannot get the GetOutputPort from ss
> 
> circleCutter.SetInputConnection(ss.GetOutputPort())

---

<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: [March 29, 2021, 1:43pm UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/6 "2021-03-29T13:43:31Z")

</div>

To set input data in a VTK filter, use `SetInputData` method.

---

<div class="post-metadata">

### Author: ![Ge\_Tang](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ge_tang/32/9935_2.png) [@Ge\_Tang](https://discourse.slicer.org/u/Ge_Tang)
#### Post date: [April 8, 2021, 8:46am UTC](https://discourse.slicer.org/t/can-i-extract-the-outline-of-a-single-closed-segment/9360/7 "2021-04-08T08:46:49Z")

</div>

Dear Dr. Lassoan  
Thank you so much!
