vtkResliceImageViewer doesn't work with QQuickVTKItem

Hi all.
I use the QQuickVTKItem module in my QtQuick pet-project, simple object rendering and even voxel rendering work fine!
But the trouble with 2d DICOM images :frowning:
I tried different solutions, and replacing the interactor and replacing the style itself, everything leads to a large list of warnings
Here is code below for reading DICOM files and rendering via vtkResliceImageViewer:

#ifndef MYVTKITEM_H
#define MYVTKITEM_H

#include "QQuickVTKItem.h"

class MyVtkItem : public QQuickVTKItem
{
public:
    vtkUserData initializeVTK(vtkRenderWindow *renderWindow) override;
};

#endif // MYVTKITEM_H

#include "MyVtkItem.h"

#include <vtkActor.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkMinimalStandardRandomSequence.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkObjectFactory.h>
#include <vtkPolyDataMapper.h>
#include <vtkPropPicker.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>

#include <vtkResliceImageViewer.h>
#include <vtkImageReader2.h>
#include <vtkDICOMDirectory.h>
#include <vtkGlobFileNames.h>
#include <vtkDICOMReader.h>

#include <vtkColorTransferFunction.h>
#include <vtkPiecewiseFunction.h>
#include <vtkVolumeProperty.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkImageActor.h>
#include <vtkInteractorStyleRubberBandZoom.h>
#include <vtkInteractorStyleImage.h>
namespace 
{
    struct MyVtkData : vtkObject
    {
        static MyVtkData* New();
        vtkTypeMacro(MyVtkData, vtkObject);
    
        // Place all your persistant VTK objects here
    };

vtkStandardNewMacro(MyVtkData);
}

QQuickVTKItem::vtkUserData MyVtkItem::initializeVTK(vtkRenderWindow *renderWindow)
{
    auto vtk = vtkNew<MyVtkData>();

    vtkNew<vtkRenderer> renderer;
    renderWindow->SetSize(renderWindow->GetScreenSize());
    renderWindow->SetWindowName("DICOM Images");
    renderer->SetBackground(0,0.3,0);
    renderWindow->AddRenderer(renderer);
    
    vtkSmartPointer<vtkImageReader2> dataSet = nullptr;

    auto globFileNames = vtkSmartPointer<vtkGlobFileNames>::New();
    globFileNames->SetDirectory("directory path");
    globFileNames->AddFileNames("*.dcm");

    auto directoryReader = vtkSmartPointer<vtkDICOMDirectory>::New();
    directoryReader->RequirePixelDataOn();
    directoryReader->SetInputFileNames(globFileNames->GetFileNames());
    directoryReader->Update();


    vtkNew<vtkDICOMReader> reader;
    reader->SetFileNames(directoryReader->GetFileNamesForSeries(0));
    reader->SetMemoryRowOrderToFileNative();
    reader->Update();

    dataSet = reader;
    
    vtkNew<vtkResliceImageViewer> _reslicer;
    _reslicer->SetupInteractor(renderWindow->GetInteractor());
    _reslicer->SetInputData(dataSet->GetOutput());
    _reslicer->SetRenderWindow(renderWindow);
    _reslicer->SetSliceOrientationToXY();
    _reslicer->SliceScrollOnMouseWheelOff();
    _reslicer->SetRenderer(renderer);
    _reslicer->SetResliceModeToAxisAligned();
    _reslicer->SetColorLevel(40.0);
    _reslicer->SetSlice(_reslicer->GetSliceMax() / 2);
    _reslicer->SetColorWindow(4000.0);
    _reslicer->SetResliceMode(0);

    return vtk;
}

Src module:

https://gitlab.kitware.com/john-stone/vtk/-/tree/john-stone/QML/GUISupport/QtQuick

Everything works in the app Qt widgets, but not in QtQuick.Can you suggest what could be causing this?

Hello,

Are using QQuickVTKRenderWindow for your render window?

best,

PC

No, they use vtkGenericOpenGLRenderWindow:

@Paulo_Carvalho

I’d advise against using that. There are specific render windows for each GUI framework for a reason.

QQuickVTKRenderWindow is deprecated.

If you’re working on a production software, I’d give it a try any way. It won’t be gone anytime soon given depecreation was set very recently (v. 9.3).