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

**URL:** <https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [February 13, 2020, 11:22am UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238 "2020-02-13T11:22:30Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 13, 2020, 11:22am UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/1 "2020-02-13T11:22:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 13, 2020, 1:39pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/2 "2020-02-13T13:39:52Z")

</div>

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](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/MigrationGuide/Slicer#Export_segments_to_models)

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 13, 2020, 2:30pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/3 "2020-02-13T14:30:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 13, 2020, 2:42pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/4 "2020-02-13T14:42:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 13, 2020, 2:45pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/5 "2020-02-13T14:45:55Z")

</div>

> ```
> 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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 13, 2020, 3:01pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/6 "2020-02-13T15:01:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 13, 2020, 3:19pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/7 "2020-02-13T15:19:32Z")

</div>

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

> modelActor.GetProperty().SetColor(…)

here

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 13, 2020, 7:42pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/8 "2020-02-13T19:42:55Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 14, 2020, 7:52am UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/9 "2020-02-14T07:52:46Z")

</div>

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.?

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 17, 2020, 2:34pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/10 "2020-02-17T14:34:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 17, 2020, 4:00pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/11 "2020-02-17T16:00:27Z")

</div>

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.).

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 18, 2020, 7:38am UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/12 "2020-02-18T07:38:03Z")

</div>

@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](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/8/28bce76c1088bb026607026fdccfbb40e43c4a7f.png)

output model in windows 3D viewer  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/3/439f6d0b77bf0951f76204c7287d9ee659fb6ba4.png)

And the renderwindow output After upgrading the slicer version to 4.11.  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/c/ec57ee523c1f07634484d438668748df41a1c10f.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 18, 2020, 2:16pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/13 "2020-02-18T14:16:38Z")

</div>

Does the rendering show up correctly on the screen?

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

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 18, 2020, 2:27pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/14 "2020-02-18T14:27:36Z")

</div>

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()
> 
> ```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 18, 2020, 2:34pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/15 "2020-02-18T14:34:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![prorai](https://avatars.discourse-cdn.com/v4/letter/p/e8c25b/32.png) [@prorai](https://discourse.slicer.org/u/prorai)\
**Post date:** [February 18, 2020, 2:39pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/16 "2020-02-18T14:39:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 18, 2020, 3:21pm UTC](https://discourse.slicer.org/t/class-syntax-change-for-segmentation-slicer-4-10-4-11/10238/17 "2020-02-18T15:21:31Z")

</div>

> 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](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Show_a_3D_view_outside_the_view_layout) then capture a screenshot like this:

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

```
