Hello, I am using the following code to create a cylinder shell, for segmentation. Running it causes the 3DSlicer to close. Any ideas on why is this happening?
Oh well, I ended up constructing the cylinder shell using vtkRotationalExtrusionFilter, but the segmentation result was not I was expecting. I’ll post a screenshot of what I got:
Unfortunately, Boolean operations in VTK do not work robustly. There have been a few alternatives developed but they are not yet in VTK master.
Probably you would need to use vktLinearExtrusionFilter instead (with appending two circles, one with clockwise and the other with counter-clockwise ordered points). But if you don’t need sharp edges then you can create a shell from a cylinder using vtkImplicitModeller:
This parameter was necessary to avoid clipping of sides when cylinder radius was 20, height 60, and thickness 5. If you have thinner wall or different aspect ratio then size adjustment may not be needed and/or you need to change other parameters from their default (e.g., resolution).
Hello Andras, I noticed that even if I increase the cylinder resolution a lot (using .SetResolution(…)), it still seems to reach a max resolution (I get rough edges, more than two pixels in some places). I would like a finer segmentation… is that possible?
The cylinder resolution should not matter much. You need to make fine enough the resolution of the segmentation’s labelmap representation. You can click on the segmentation geometry button (next to the master volume selector) to adjust this resolution.
I’ll place some pictures of what I am getting. I tried to set the resolution as you told, but no success. I could only downgrade the resolution, not get a finer one for the segmentation cylinder.
Here is the original volume rendered, it is smooth:
Hmm, interesting, I’ve seem to hit a bug. The steps are:
load a volume (DICOM);
create a segmentation and change the oversampling factor, of my volume as source geometry, to a value larger than 1.00 (I tried 1.25 and 1.5);
use the Scissors tool with a circle, to fill inside. The segmentation indeed becomes smoother than without setting the oversampling;
use this segmentation as a Mask, with some fill outside value. The resulting new volume doesn’t appear at all.
I repeated those steps without changing the oversampling factor, and got a resulting volume. These tests were done with Slicer 4.10.2 and Slicer 4.11.0-2019-09-01.
Thank you again Andras. One more question. How could I set the oversampling factor programmatically? I’ve tried this, but got no modifications to my segmentation:
Well, tried other path, I was sure it would work, but now I am kind of out of options. My code is as shown (note that despite telling to show the Segmentation Geometry Widget, it doesn’t appear):
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
# create segment editor to get access to effects
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorWidget.show() # just to check if everything is setup correctly
slicer.savedWidget = segmentEditorWidget
segmentEditorNode = slicer.vtkMRMLSegmentEditorNode()
slicer.mrmlScene.AddNode(segmentEditorNode)
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentationGeometryWidget = slicer.qMRMLSegmentationGeometryWidget()
segmentationGeometryWidget.setMRMLScene(slicer.mrmlScene)
segmentationGeometryWidget.setParent(segmentEditorWidget)
segmentEditorWidget.show() # just to check if everything is setup correctly
segmentationGeometryWidget.setOversamplingFactor(0.05)
segmentationGeometryWidget.setSegmentationNode(segmentationNode)
segmentationGeometryWidget.setSourceNode(inputVolume)
segmentationGeometryWidget.setParent(segmentEditorWidget)
segmentationGeometryWidget.setReferenceImageGeometryForSegmentationNode()
segmentationGeometryWidget.updateGeometry()
segmentationGeometryWidget.update()
I have called a lot of methods, in the hope they would apply the new Oversampling I wanted to test.
You never call show() for segmentationGeometryWidget, so it is not displayed. Anyway, you only need qMRMLSegmentationGeometryWidget if you want users to interactively change parameters on a GUI. If you just want to change the geometry from a script (without user interaction) then you can use vtkSlicerSegmentationGeometryLogic class instead.
My bad, indeed it was supposed to be a call to show the Geometry Widget… copy, paste and some tiredness I guess. I thought I was supposed to use the Geometry Widget because I am using the Segment Editor Widget to apply some effects, so I went the same route.
Despite that, my first solution, just above my last answer was what you told. The code snippet is:
This code is inserted before any segments are created, but it doesn’t take effect on my segments added later in the code. I don’t know what else I could set to make it work. I tried to find some example script and searched the forum, but nothing, so I am kinda lost on this matter.
If you just want to prescribe some fixed spacing then you can do it even simpler, just setting the reference image geometry directly. A complete example:
Segmentation internal labelmap representation geometry is unfortunately quite complicated. We are still improving the API to make common tasks easier to do. For example setting the segment resolution should be achievable by a single line of code (instead of the current 4 lines).