Creating a 3D image from a stack of contours

I’m trying to create a 3D labelMa from a stack of 2D contours in SlicerRT. . My idea is to binarize the contours, and to run a marching cubes on the resulting binary volume. Before do that. I have Added some treatments which I have inspired from SlicerRT before convert set of contours to binary image (like sort contours based on z value, remove keyholes from contours and Set all of the lines to be oriented in the clockwise direction)

I convert the set of planar contours based on the Following example:

the imagedata is well reconstructed but it seems like there are two missing slices (it contains holes) "see attached figure

con you tell me where is the problem please?

here is a sample code of extrusion filter that i have employed:

// sweep polygonal data (this is the important thing with contours!)
vtkSmartPointer extruder =
extruder->SetVector(0, 0, lineSpacing); //lineSpacing is the space between contours


thank’s in advance

Implementing such conversions in a way that it is robust and generic is extremely hard, and we spent years on doing that. Now it is part of the Segmentations infrastructure, and all you need to do is add your polydata to a segment taht you put in a segmentation node, and then you can have it converted in the Segmentations module (with SlicerRT installed). Is there a specific reason to reimplement this conversion from scratch?

Thank you very much for reply. But I do not understand how can I add polydata to a segment and how can I get vtkImage data ? To my knowleadge, vtk image data is computed from reconstructed surface in slicerRT.

I would reimplement that in order to be able to Apply marching cube and other methods then compare them. I know that is more easier if i reconstruct surface from imagedata in slicer (using fro example flying edges or vtkDiscreteMarchingcubes) however I must reipmlement it in slicerRT (from contours ) using the basic marching cube for other purposes of education.

Polydata in my case are the planar contours (3D points)

I have another question. If I keep the shown model, how can deduce the corresponding point position of polydata on vtkImageData without rounding the point coordinates.

Thank you very much in advance