# Generate a filled contour from contour in SlicerRT

**URL:** <https://discourse.slicer.org/t/generate-a-filled-contour-from-contour-in-slicerrt/11621>\
**Category:** Development\
**Tags:** slicerrt\
**Created:** [May 19, 2020, 1:47pm UTC](https://discourse.slicer.org/t/generate-a-filled-contour-from-contour-in-slicerrt/11621 "2020-05-19T13:47:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![loubna](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@loubna](https://discourse.slicer.org/u/loubna)\
**Post date:** [May 19, 2020, 1:47pm UTC](https://discourse.slicer.org/t/generate-a-filled-contour-from-contour-in-slicerrt/11621/1 "2020-05-19T13:47:31Z")

</div>

Hi;

I want construct a filled contour (vtkimagedata) from contour points in Slicer RT.

This is the code i have implemented :

vtkPoints\* pointsSlice // the set of 3D points of the contour  
int nbpoints = pointsSlice-\>GetNumberOfPoints()-1; // number of points

int dimSlice[3]; dimSlice[0]= dim[0]; dimSlice[1] =dim[1]; dimSlice[2]=1; // set up vtkImagedata parameters

vtkSmartPointer imgSlice = vtkSmartPointer::New();  
int extent[6] = {0, dimSlice[0]-1, 0, dimSlice[1]-1, 0, 0};  
imgSlice-\>SetExtent(extent);  
imgSlice-\>SetOrigin(origin);  
imgSlice-\>SetDimensions(dimSlice);  
imgSlice-\>SetSpacing(1,1,1);  
imgSlice-\>AllocateScalars(VTK\_UNSIGNED\_CHAR,1);

for(int i=0; i\< nbpoints; i++) // store 3D points in double array  
{  
double \*p = pointsSlice-\>GetPoint(i);  
pts[i\*3+0] = p[0];  
pts[i\*3+1] = p[1];  
pts[i\*3+2] = p[2];

}

double \*boundSlice = pointsSlice-\>GetBounds(); // bounds of 3d Points  
double z\_coord = vtkMath::Round(pts[2]); //all 3d points of same contour have same z-coord

vtkPolygon::ComputeNormal(pointsSlice, normal); //compute normal of the contour

for(int j=0; j\<dim[1];j++)  
for(int i=0; i\<dim[0]; i++)  
{  
double x[3] = {i+origin[0], j+origin[1], z\_coord};  
in\_poly = vtkPolygon::PointInPolygon(x, nbpoints,pts,boundSlice,normal);  
if(in\_poly) // point belong to the contour  
pixel =255;  
else  
pixel= 0  
}

However this method display filled square instead of filled circle (contour) as shown in figure.  
I think because I have used vtkPolygon:: PointInPolygon test?

How can I get a filled contour instead of filled square.

thank’s in advance for your help

![square](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/6/665d3023bd322f0b756b8c05338b50c41e9f1338.png)

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [May 19, 2020, 3:00pm UTC](https://discourse.slicer.org/t/generate-a-filled-contour-from-contour-in-slicerrt/11621/2 "2020-05-19T15:00:50Z")

</div>

What you are trying to do is much harder than it looks, and we have been working for years to do it reliably. If you don’t believe it check out these publications:  
[http://perk.cs.queensu.ca/contents/reconstruction-surfaces-planar-contours-through-contour-interpolation](http://perk.cs.queensu.ca/contents/reconstruction-surfaces-planar-contours-through-contour-interpolation)  
[https://qspace.library.queensu.ca/handle/1974/26422](https://qspace.library.queensu.ca/handle/1974/26422)

So instead of reinventing everything I’d recommend using the infrastructure in place. Install the SlicerRT extension, import the structure set to the DICOM database, load it, convert the resulting segmentation node’s representation to binary labelmap, and extract the slice you want. There are tons of materials about the steps of this workflow in the documentation and the forum, so please start to look there if you have questions. Otherwise we’re happy to help.

---

<div class="post-metadata">

**Author:** ![loubna](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@loubna](https://discourse.slicer.org/u/loubna)\
**Post date:** [May 19, 2020, 4:04pm UTC](https://discourse.slicer.org/t/generate-a-filled-contour-from-contour-in-slicerrt/11621/3 "2020-05-19T16:04:48Z")

</div>

Thank’s for response. However my goal is not to use things that already exist. I have imlemented an implcit method “Contour-BasedSurfaceReconstructionusing MPU ImplicitModels” to convert planar contours to closed surface (it is not important if it is better or worse than the slicerRT method).

the only issue is to fill pixels that belong to the contour in order to construct binary volume by staking the 2D slices (filled contours). so I have used vtkPolygon::PointInPolygon(x, nbpoints,pts,boundSlice,normal).

Are there other solutions to keep the contour form?

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 19, 2020, 8:23pm UTC](https://discourse.slicer.org/t/generate-a-filled-contour-from-contour-in-slicerrt/11621/4 "2020-05-19T20:23:20Z")

</div>

> [@loubna](#):
>
> However my goal is not to use things that already exist.

Just out of curiosity, what do you mean here? Are you trying to learn it from scratch for educational purposes?
