vtkImageReslice to change the slicing axis is too slow

Hi,

I am trying to implement a feature where the slicing axis can be changed in real time. I have made a proof of concept using the by using the vtkImageReslice, where I use ResliceAxes to change the rotation of the different axis (Add the source to the vtkImageReslice and have it output a 3D volume, add the output of the vtkImageReslice to a vtkImageMapper, and slice the mapper). It works as expected, but the performance is really slow in realtime.

Are there ways to improve this? Do you have other solutions in mind?

If you could show some of your code, even just the parts with vtkImageReslice and vtkImageMapper, that would help us provide you with an answer.

How I initialize the actor, mapper, etc:

    this.mapper = vtkImageMapper.newInstance();
    this.actor = vtkImageSlice.newInstance();
    this.actor.setMapper(this.mapper);

    this.filter = vtkImageReslice.newInstance();
    this.filter.setOutputDimensionality(3);
    const axes = mat4.create();
    this.filter.setResliceAxes(axes);
    this.filter.setInputData(source);

    this.getMapper().setInputConnection(this.filter.getOutputPort(0));

How I update the reslicer:

    const I = mat4.create();
    mat4.rotate(I, I, Math.PI/4, [1, 0, 0]);
    this.filter.setResliceAxes(I);

How I retrieve the correct slice:

    this.mapper.getSlice();

There are some fairly simple things that might speed up the execution.

Call this.filter.update() on vtkImageReslice. This should ensure that it updates the whole volume exactly once. If you don’t do this, then every time that the mapper shows a different slice, it will re-execute vtkImageReslice for that slice.

It will also help if you keep a separate vtkImageReslice for each direction, so that it isn’t necessary to re-execute the reslice when you want to switch from one direction to another. But if this isn’t possible, then make sure to call update() on vtkImageReslice after you change directions.

Or, you can use vtkImageResliceMapper instead of vtkImageReslice and vtkImageMapper.

How about applying a user matrix onto the image actor, i.e. actor.setUserMatrix(axes)

(and do not do vtkImageReslice)

Its actually the recalculation of the reslice axis after rotation that seems to be slow for me, not the actual calculation of the slices

Ah, yes, you mentioned specifically that you want to change the rotation in real time. Then definitely you don’t want to rotate the whole volume. You just want one rotated slice.

Blockquote How about applying a user matrix onto the image actor, i.e. actor.setUserMatrix(axes)

I tried this approach, but for me it does not seem to change the cutting plane of the mapper, it seems to tilt the slice compared to the camera

Then I agree with David, 2 options:

this.filter.setOutputDimensionality(2)

Or

1 Like

And would you then have a vtkImageReslice instance for the three orthogonal axes? Scrolling on a plane would then involve updating the resliceAxis for the vtImageReslice instance of the corresponding plane?

That’s right.

Okay, thanks a lot for the info! I will try out using the vtkImageResliceMapper

Hi, I’ve encountered a similar issue with setting the reslice axes being too slow. Have you discovered any solutions for this problem? It seems to work perfectly fine in the resliceCursorWidget without any noticeable slowdown.