# Update 2D image

**URL:** https://discourse.vtk.org/t/update-2d-image/7696
**Category:** Support
**Created:** [January 21, 2022, 6:02pm UTC](https://discourse.vtk.org/t/update-2d-image/7696 "2022-01-21T18:02:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jamsoft](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/j/97f17d/32.png) [@jamsoft](https://discourse.vtk.org/u/jamsoft)
#### Post date: [January 21, 2022, 6:02pm UTC](https://discourse.vtk.org/t/update-2d-image/7696/1 "2022-01-21T18:02:48Z")

</div>

Hello all,

In my project, I need to cut the volume by plane, move the plane by the keyboard arrows and show the slice content. Everything works well with the following (part of) code:

```
    planeSagittal_vtkPlane = vtk.vtkPlane()
    planeSagittal_vtkPlane.SetOrigin(volume.GetOutput().GetCenter())
    planeSagittal_vtkPlane.SetNormal(1, 0, 0)

```

#showing moving plane in the volume window  
planeSagittal\_vtkCutter = vtk.vtkCutter()  
planeSagittal\_vtkCutter.SetInputData(volume.GetOutput())  
planeSagittal\_vtkCutter.SetCutFunction(planeSagittal\_vtkPlane)

```
    planeSagittal_CutterMapper_vtkCompositePolyDataMapper = vtk.vtkCompositePolyDataMapper()
          planeSagittal_CutterMapper_vtkCompositePolyDataMapper.SetInputConnection(planeSagittal_vtkCutter.GetOutputPort())
    planeSagittal_CutterMapper_vtkCompositePolyDataMapper.SetScalarRange(volume.GetOutput().GetPointData().GetScalars().GetRange())

    planeSagittal_CutterMapper_vtkCompositePolyDataMapper.SetLookupTable(gsLut)
    planeSagittalCutterActor_vtkActor = vtk.vtkActor()
    planeSagittalCutterActor_vtkActor.SetMapper(planeSagittal_CutterMapper_vtkCompositePolyDataMapper)

```

#showing just the slice in the standalone window  
planeSagittal\_vtkResliceMapper = vtk.vtkImageResliceMapper()  
planeSagittal\_vtkResliceMapper.SetSlicePlane(planeSagittal\_vtkPlane)  
planeSagittal\_vtkResliceMapper.SetInputConnection(volume.GetOutputPort())

```
    planeSagittal_vtkImageSlice = vtk.vtkImageSlice()
    planeSagittal_vtkImageSlice.SetMapper(planeSagittal_vtkResliceMapper)

    planeSagittalCutterActor_vtkActor = vtk.vtkActor()
    planeSagittalCutterActor_vtkActor.SetMapper(planeSagittal_CutterMapper_vtkCompositePolyDataMapper)

    ren2 = vtk.vtkRenderer()
    ren4 = vtk.vtkRenderer()
    ren2.AddActor(planeSagittalCutterActor_vtkActor)        
    ren4.AddViewProp(planeSagittal_vtkImageSlice)

    renWin2 = vtk.vtkRenderWindow()
    renWin2.AddRenderer(ren2)
    renWin4 = vtk.vtkRenderWindow()
    renWin4.AddRenderer(ren4)

    renWin2.Render()
    renWin4.Render() 

    def Keypress(obj, event):
        key = obj.GetKeySym()

        if key == "q" or key == "Q":
            obj.InvokeEvent("DeleteAllObjects")
        elif key == "Up":
            planeAxial_vtkPlane.Push(-1.0)

       renWin2.Render()
       renWin3.Render() #see bellow
       renWin4.Render() 

```

(Actually, there is also camera position settings and some other code stuff irrelevant to my question)

If I press the up arrow, both windows are updated by the new slice and everything works fine.

What I need now is to use 2D slice (the above code is Prop3D).

I’ve tried the following:

```
    planeSagittalImageReslice_vtkImageReslice = vtk.vtkImageReslice()
    planeSagittalImageReslice_vtkImageReslice.SetInputConnection(volume.GetOutputPort())
    planeSagittalImageReslice_vtkImageReslice.SetOutputDimensionality(2)
    planeSagittalImageReslice_vtkImageReslice.SetResliceAxesOrigin(planeSagittal_vtkPlane.GetOrigin())
    planeSagittalImageReslice_vtkImageReslice.SetOutputScalarType(vtk.VTK_UNSIGNED_CHAR)
    planeSagittalImageReslice_vtkImageReslice.Update()

    imageMapperSagittal = vtk.vtkImageMapper()
    imageMapperSagittal.SetInputConnection(planeSagittalImageReslice_vtkImageReslice.GetOutputPort())
    imageMapperSagittal.Update()

    imageResliceActorSagittal = vtk.vtkActor2D()
    imageResliceActorSagittal.SetMapper(imageMapperSagittal)

   ren3 = vtk.vtkRenderer()
   ren3.AddActor(imageResliceActorSagittal) 
   renWin3 = vtk.vtkRenderWindow()
   renWin3.AddRenderer(ren3)
   renWin3.Render()

```

When I run the code, everything looks as intended. The 2D slice appears in the rendering window. But when I press the arrow key, the renWin3 windows does not get updated. I’ve tried to manually update the planeSagittalImageReslice\_vtkImageReslice and the imageMapperSagittal but with no result. No change in the rendering window. The “heavy” workarround is to delete the actor2D and create new one. Then the window gets updated.

Can you help me to find better way of updating the window with 2D image upon arrow up key press, please? I don’t understand why the cutting plane in 3D windows (renWin2 and renWin4) are correctly updated but the 2D image window (renWin3) is not. It shows correctly on the code load but it has no reaction for the plane position change…

Thank you for any advice,

Jirka
