Fill / Color area of closed polyline

Hello!
I am rendering DICOM contours (Yes, against advice to use existing implementations). At the moment, I am creating vtkPolyData using vtkPoints and vtkCellArray from the 3D-point data extracted from DICOM. Then, I put this data through vtkLinearExtrusionFilter, vtkPolyDataToImageStencil and vtkImageStencil to retrieve vtkImageData, which I render using a vtkImageViewer2. This works, but now I want to fill / color the area of this closed polyline.

I might be able to do so using an approach similar to vtkPolygon::PointInPolygon(), potentially using vtkContourLoopExtraction. Yet, I don’t have vtkPolygon-data but it might be extractable somewhere along the pipeline?

My question is different from How to color or fill the selected contour?, as I don’t use vtkContourWidget.

My question(s):

  • Where in my pipeline would I include the filling/coloring of the area enclosed by the contour?
  • How would I do that?

Any help is appreciated. Cheers!
Sebastian

I think that what you want is vtkContourTriangulator, which will fill the contour with triangles so that its interior can be rendered (rather than just the edges). Or do you want to color the vtkImageData voxels that lie within the contour?

Thank you for the suggestion. I indeed want to do the latter.

If you want to fill that part of the image, and leave the rest of the image alone, you can do that by reversing vtkImageStencil. For example,

fill_value = 0
imageStencil.ReverseStencil();
imageStencil.SetBackgroundValue(fill_value);

If you pass the image through vtkImageMapToColors first (so that it is RGB), then you can do this:

red = (1.0, 0.0, 0.0)
imageStencil.ReverseStencil();
imageStencil.SetBackgroundColor(red);

Or you can create a binary image with vtkImageStencilToImage

Thank you very much - this is exactly what I need!