Generate a filled contour from contour in SlicerRT


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};

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;
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


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:

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.

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?

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

1 Like