Drawing shapes in Volume Node

Hello 3D Slicer forum,

I’d like to draw shapes in the Volume node where the MRI image is located. I’m relatively new to Slicer and have been learning to use the Python interactor, and specifically, interfacing with the VTK module. For example, I’ve drawn a circle using vtkRegularPolygonSource and am able to display it as a model, but this is independent of any imaging volume node, just a strict geometric object. I’d like to center that circle at a specific coordinate location within the imaging volume node. I’m assuming a transformation node needs to be set up? If so, how can I set up the transform between the VTK object and the imaging node?

Thanks for your help!

Hi Vinny,

I could answer in several different ways, but let’s narrow down the issue first:

  • Is it important for you to use poly data for “drawing”?
  • Are you trying to automate something by python scripting? (i.e. What’s your overall goal?)

Thanks!

I’d like to delineate regions of interest (ROIs), either cubic or spherical, based on known anatomical landmarks, such as anterior/posterior commissures (AC/PC). I’ve done some basic Python scripting (in Spyder) to determine the center coordinate that I’d like place in relation to these landmarks. From this center coordinate, I’d like to construct a circle (2 mm radius) on that particular slice, and also a cubic ROI. I guess if I want certain dimensions to construct these objects then I should construct them directly in the volume imaging node? So, it’s not important that I use poly data for ‘drawing’ objects.

Thanks!

Have you looked at the segmentation examples in the script repository?

I think this example does exactly what you need - defines segments by “drawing” spheres as segments and use those as seeds for “Grow from seeds” effect:

Great, I did not come across this example. I’ll go through it and give it a try.

Thanks for your help!

Hi Andras,

I tried the code you gave and it worked wonderfully. Also, instead of a sphere, I constructed a circle outline using vtkRegularPolygonSource() and was able to view it in the 3d viewer; however, I’m wondering why the circle outline does not appear in any of the slice views but the cross section of the sphere can be viewed in both the slice views and 3d viewer.

Closed surface representation must contain closed 3D surface mesh (for example, because slice view is computed by cutting the mesh with the slice plane, but cutting a 2D polygon with a plane the result is nothing or a few points).

If you define your segment by a set of planar contours then you need to store it in planar contour representation:

planarContour = vtkSegmentationCore.vtkSegmentationConverter.GetSegmentationPlanarContourRepresentationName()
segment.AddRepresentation(planarContour, polygonSource.GetOutput())

If you do this, then Slicer will show the segmentation correctly in both 2D and 3D views and it can also correctly compute closed surface and binary labelmap representations.

1 Like