# fill closed contours

**URL:** <https://discourse.vtk.org/t/fill-closed-contours/3343>\
**Category:** Development\
**Created:** [May 19, 2020, 5:47pm UTC](https://discourse.vtk.org/t/fill-closed-contours/3343 "2020-05-19T17:47:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@Nina](https://discourse.vtk.org/u/Nina)\
**Post date:** [May 19, 2020, 5:47pm UTC](https://discourse.vtk.org/t/fill-closed-contours/3343/1 "2020-05-19T17:47:57Z")

</div>

Hi,  
I want assing a 255 value for pixels inside a contour and 0 for outside pixels. the contour is composed of a set of 3D points that have same z-value. are there a vtk filters that allow to do that? vtkPolygon::PointinPolygon does not seem give good results (because a closed contour is transformed to a filled square). I want obtain result like in figure.

thank’s in advance

 ![img](https://discourse.vtk.org/uploads/default/original/2X/6/6dc0f51bdf7353c20c6a740357d860d952cf0927.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [May 19, 2020, 7:13pm UTC](https://discourse.vtk.org/t/fill-closed-contours/3343/2 "2020-05-19T19:13:13Z")

</div>

You can try [vtkPolyDataToImageStencil](https://vtk.org/doc/nightly/html/classvtkPolyDataToImageStencil.html), or create a polygon and use probe filter to sample on a regular grid.

Would you like to create a 3D volume from a DICOM RT structure set? That requires special techniques - these general-purpose rasterization methods would not work.

---

<div class="post-metadata">

**Author:** ![Nina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@Nina](https://discourse.vtk.org/u/Nina)\
**Post date:** [May 19, 2020, 7:24pm UTC](https://discourse.vtk.org/t/fill-closed-contours/3343/3 "2020-05-19T19:24:32Z")

</div>

Hi professor;

thank’s for the response. I have tried [vtkPolyDataToImageStencil but it seems not work.  
You are right, I would like create a 3D volume from Dicom RT series. you have montioned that there are special techniques to do that. can you give me more precision please?. It is still the only issue to implement the implicit models.

Thank’s in advance

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [May 19, 2020, 7:32pm UTC](https://discourse.vtk.org/t/fill-closed-contours/3343/4 "2020-05-19T19:32:45Z")

</div>

Converting DICOM RT structure set to binary labelmap is a very complex operation, as you need to handle inter-plane interpolation/splitting/merging, intra-plane splitting, end-capping, and keyhole resolution. These are all implemented and thoroughly tested on thousands of clinical data sets and made available for free in 3D Slicer’s SlicerRT extension. You can use Slicer’s GUI or convert in batch mode (a few lines of Python script). If you cannot figure out how to do something in Slicer then post your question to the [Slicer forum](https://discourse.slicer.org).

---

<div class="post-metadata">

**Author:** ![Nina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/e68b1a/32.png) [@Nina](https://discourse.vtk.org/u/Nina)\
**Post date:** [May 21, 2020, 12:27am UTC](https://discourse.vtk.org/t/fill-closed-contours/3343/5 "2020-05-21T00:27:56Z")

</div>

Hi professor.

How can create a polygon from a contour in slicerRT? can I use vtkContourTriangulator filter?

thank’s in advance

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)\
**Post date:** [May 21, 2020, 12:43am UTC](https://discourse.vtk.org/t/fill-closed-contours/3343/6 "2020-05-21T00:43:37Z")

</div>

vtkContourTriangulator is not applicable here, as it creates planar polygons from a set of contours on a single plane, while you need to reconstruct closed 3D surfaces from contours on many planes.

Among built-in VTK filters, vtkRuledSurfaceFilter is the closest to what you would need, but it does not work in this case, because its assumptions about the input and output data are not valid for DICOM RT structure sets (for example, it does not know about the keyhole technique at all and as far as I remember it does not cope well with splitting/merging of branches, and the distance factor heuristics does not work robustly either).
