Class/syntax change for segmentation (slicer 4.10- 4.11)

what are the changes in class and its parameters?

ExportAllSegmentsToModelHierarchy() is now ExportAllSegmentsToModels() , i believe its right.
But what is vtkIdType folderItemId ? what should i pass here?

The API is changed in Slicer-4.11 - see more information and link to code example in the migration guide: https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/MigrationGuide/Slicer#Export_segments_to_models

1 Like

is there any changes in camera and actor setting my snap image is getting black not the color i’m passing as a parameter ?

I don’t know what is a “snap image” and what color you pass as a parameter and where.

            modelNode = slicer.util.getNode(segment)
            pdMap = vtk.vtkPolyDataMapper()
            pdMap.SetInputData(modelNode.GetPolyData())
            modelActor = vtk.vtkLODActor()
            modelActor.SetMapper(pdMap)
            modelActor.GetProperty().SetColor(colors[segment])
            ren.AddActor(modelActor)
    pngName = 'Segment'
    ren.AddActor(camActor)

 
    # take a snap of new RenderWindow

    wti = vtk.vtkWindowToImageFilter()
    wti.SetInputBufferTypeToRGBA()
    wti.SetInput(renWin)
    writer = vtk.vtkPNGWriter()
    writer.SetFileName(str(self.opPath) + '/' + pngName + '.png')
    writer.SetInputConnection(wti.GetOutputPort())
    writer.Write()

Sorry for the less info, BTW this is my code , which works perfectly with slicer4.10 , but now with 4.11 the color ob the actor/object is black only

To capture screenshots, check out these examples in the script repository: https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Capture

cant see any changes in code , but the object color in PNG is not the color i’m setting

modelActor.GetProperty().SetColor(…)

here

Do you have any problem with models that Slicer puts in the scene or only those that you manually add? Why do you use LOD actor?

So the script is running in No window mode , that’s why i’m creating this setup to get a image of the model slicer generated.
so i believe i’m using LODActor to get the model in the scene. is there any other way to get this done.?

@lassoan i tried many ways even added light in that render window still 3D model didn’t coming in color.

LOD (level-od-detail) actor renders at low resolution first and at increasingly high resolution to make rendering of complex scenes more interactive. You don’t need this but instead simple rendering using vtkActor.

I don’t understand yet what the problem is (what you mean by “3D model didn’t coming in color”), but if you want to do off-screen rendering (render without creating a visible render window) then it can be very tricky. It is an advanced topic and the solution depends on many factors (operating system, driver, what OpenGL implementation Slicer was built with, etc.).

@lassoan , Thank you for your response. i’ve change LOD Actor to vtkActor. and also added a spot light.

Please have a look what actually happening here or what exactly my problem is-

i’ve removed the --no-main-window to check the model in editor and my model looks like this,
image

output model in windows 3D viewer
image

And the renderwindow output After upgrading the slicer version to 4.11.
image

Does the rendering show up correctly on the screen?

Did you use the scripts at https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Capture to capture the content of the view?

Yes i’m using same code to write PNG,
i tried to sleep/pause the render window to check and in render window model result is like last image(the black one)

My updated code:

             ren = vtk.vtkRenderer()
             renWin = vtk.vtkRenderWindow()
             self.modelNode = slicer.util.getNode(segment)
             pdMap = vtk.vtkPolyDataMapper()
             pdMap.SetInputData(self.modelNode.GetPolyData())
             modelActor = vtk.vtkActor()
             modelActor.SetMapper(pdMap)
             modelActor.GetProperty().SetColor(self.colors[ModelColor])
             ren.AddActor(modelActor)

            # light added
            light = vtk.vtkLight()
            light.SetConeAngle(10)
            light.SetFocalPoint(modelActor.GetPosition())
            light.SetPosition(-4.0, 4.0, 1.0)
            light.SetColor(1.0,1.0,1.0)
            # lightActor = vtk.vtkLightActor()
            # lightActor.SetLight(light)
            ren.AddLight(light)
            ren.SetBackground(1.0, 1.0, 1.0)
            # renderwindow
            renWin.AddRenderer(ren)
            renWin.SetSize(640, 480)
            iren = vtk.vtkRenderWindowInteractor()
            iren.SetRenderWindow(renWin)
            cam1 = (ren.GetActiveCamera())
            ren.ResetCamera()
            cam1.Azimuth(180)
            cam1.Elevation(90)
            ## cam1.Dolly(1.5)
            ren.ResetCameraClippingRange()

            # intialize new Render Window
            renWin.Render()
            renWin.SetWindowName("Model PNG Image")

            iren.Initialize()
            pngName = 'Segment'
            # take a snap of new RenderWindow
            wti = vtk.vtkWindowToImageFilter()
            wti.SetInputBufferTypeToRGBA()
            wti.SetInput(renWin)
            writer = vtk.vtkPNGWriter()
            writer.SetFileName(str(self.opPath) + '/' + pngName + '.png')
            writer.SetInputConnection(wti.GetOutputPort())
            writer.Write()

If you use such low-level classes as mappers, actors, and lights then we cannot help. Slicer cannot ensure that you do things right. Why don’t you rely on Slicer’s MRML classes to render your segment?

Which MRML class i can use for mapper, actors or light?
can you please give me few suggestions.

I really thankful for your help and response on this thread

Which MRML class i can use for mapper, actors or light?

I would suggest to let Slicer take care of the rendering. Create a view as described here then capture a screenshot like this:

import ScreenCapture
cap = ScreenCapture.ScreenCaptureLogic()
cap.captureImageFromView(viewWidget.threeDView(),'c:/tmp/test.png')
1 Like