Cut of AMR dataset

I have a simulation code that write out an hierarchical octree grid structure. The coarsest level is filled, and then comes finer levels on top where refinement is needed. Each level is built of small Cartesian grids of the same size, typically 24^3-32^3. The coarse grids are not removed when a fine grid is inserted. I believe a possible data representation in VTK is vtkOverlappingAMR.

I want to read this dataset into VTK and create slices through the dataset, and create PNG images of this slice. The equicalent operation in Paraview would have been to load the dataset and use the “Slice” filter and save the resulting image as PNG.

To achieve this in VTK, I started with the OverlappingAMR.py example from vtk-examples, and tried to cut through that sphere, however, I am not successful. The resulting rendering is blank. I tried to use the vtkAMRCutPlane class, but I am not sure if I got the usage correct. I cannot find any examples for how to cut through such a dataset at all…

I’m quite sure I overlooked something essential. Is there anyone that can lead me in the right direction?

My non-working code is currently:

colors = vtk.vtkNamedColors()

# Create and populate the AMR dataset
# The dataset should look like
# Level 0
#   uniform grid, dimensions 11, 11, 11, AMR box (0, 0, 0) - (9, 9, 9)
# Level 1 - refinement ratio : 2
#   uniform grid, dimensions 11, 11, 11, AMR box (0, 0, 0) - (9, 9, 9)
#   uniform grid, dimensions 11, 11, 11, AMR box (10, 10, 10) - (19, 19, 19)
# Use MakeScalars() above to fill the scalar arrays

amr = vtk.vtkOverlappingAMR()
blocksPerLevel = [1, 2]
amr.Initialize(2, blocksPerLevel)

origin = [0.0, 0.0, 0.0]
spacing = [1.0, 1.0, 1.0]
dims = [11, 11, 11]

ug1 = vtk.vtkUniformGrid()
# Geometry
ug1.SetOrigin(origin)
ug1.SetSpacing(spacing)
ug1.SetDimensions(dims)

# Data
scalars = vtk.vtkFloatArray()
ug1.GetPointData().SetScalars(scalars)
MakeScalars(dims, origin, spacing, scalars)

lo = [0, 0, 0]
hi = [9, 9, 9]
box1 = vtk.vtkAMRBox()
amr.SetAMRBox(0, 0, box1)
amr.SetDataSet(0, 0, ug1)

spacing2 = [0.5, 0.5, 0.5]
ug2 = vtk.vtkUniformGrid()
# Geometry
ug2.SetOrigin(origin)
ug2.SetSpacing(spacing2)
ug2.SetDimensions(dims)

# Data
scalars2 = vtk.vtkFloatArray()
ug2.GetPointData().SetScalars(scalars2)
MakeScalars(dims, origin, spacing2, scalars2)

lo2 = [0, 0, 0]
hi2 = [9, 9, 9]
box2 = vtk.vtkAMRBox()
amr.SetAMRBox(1, 0, box2)
amr.SetDataSet(1, 0, ug2)

origin3 = [5, 5, 5]
ug3 = vtk.vtkUniformGrid()

# Geometry
ug3.SetOrigin(origin3)
ug3.SetSpacing(spacing2)
ug3.SetDimensions(dims)

# Data
scalars3 = vtk.vtkFloatArray()
ug3.GetPointData().SetScalars(scalars3)
MakeScalars(dims, origin3, spacing2, scalars3)

lo3 = [10, 10, 10]
hi3 = [19, 19, 19]
box3 = vtk.vtkAMRBox()
amr.SetAMRBox(1, 1, box3)
amr.SetDataSet(1, 1, ug3)
amr.SetRefinementRatio(0, 2)

# Cut AMR dataset
cutter = vtk.vtkAMRCutPlane()
cutter.SetInputData(amr)
cutter.SetCenter([5.0, 5.0, 5.0])
cutter.SetNormal([1.0, 1.0, 1.0])
cutter.SetLevelOfResolution(1)

# Mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(cutter.GetOutputPort())

# Create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)

# Assign actor to the renderer
ren.AddActor(actor)

renWin.SetWindowName('sphereClip')
renWin.Render()

# Write PNG
windowto_image_filter = vtk.vtkWindowToImageFilter()
windowto_image_filter.SetInput(renWin)
windowto_image_filter.SetScale(1)
windowto_image_filter.SetInputBufferTypeToRGBA()

writer = vtk.vtkPNGWriter()
writer.SetFileName("sphereClip.png")
writer.SetInputConnection(windowto_image_filter.GetOutputPort())
writer.Write()

#iren.Start()

Thanks in advance.