0

I am working on the medical GUI development with QT and VTK. I have made MPR (MultiPlanar reformation) in VTK alone, but it does not display when I show it in QT (basically I add the renderwindow and renderer to QVTKWidget). I also tried QVTKOpenGLNativeWidget as an option, but it does not work as well. I knew it needs vtkGenericOpenGLRenderWindow where for display.

coding environment:

QT5.9 VS2017 VTK8.2.0

alone:

enter image description here

in QT:

enter image description here

here is my code

void BorderWidgetQt::openMPRwindow(QVTKWidget* qvtkwidget) {
    QVTKInteractor* iren = qvtkwidget->GetInteractor();
    vtkRenderWindow* renWin = qvtkwidget->GetRenderWindow();

    vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
    reader->SetDirectoryName("C:\\Users\\u\\source\\repos\\myrobotapp\\DICOM");
    reader->Update();

    vtkSmartPointer<vtkRenderer> ren; //vtksmartpointer 
    //vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
    renWin->SetMultiSamples(0);

    ren = vtkSmartPointer<vtkRenderer>::New();
    renWin->AddRenderer(ren);

    //vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    iren->SetRenderWindow(renWin);


    //renWin->SetInteractor(iren);
    vtkSmartPointer<vtkProperty> ipwProp = vtkSmartPointer<vtkProperty>::New();

    int imageDims[3];
    reader->GetOutput()->GetDimensions(imageDims);
    for (int i = 0; i < 3; i++) {
        std::cout << "imagesize L X W X H: " << imageDims[i] << std::endl;
    }

    vtkSmartPointer< vtkResliceCursor > resliceCursor = vtkSmartPointer< vtkResliceCursor >::New();
    resliceCursor->SetCenter(reader->GetOutput()->GetCenter());
    resliceCursor->SetThickMode(1);// mode 1 or more and thickness can be viewed 
    //set image that are resliced
    resliceCursor->SetImage(reader->GetOutput());

    vtkSmartPointer< vtkResliceCursorWidget > resliceCursorWidget;
    vtkSmartPointer< vtkResliceCursorLineRepresentation > resliceCursorRep;
    //camera viewup
    double viewUp[3][3] = { { 1, 0, -1 }, { 0, 0, 1 }, { 0, 1, 0 } };
    /************************/
    resliceCursorWidget = vtkSmartPointer< vtkResliceCursorWidget >::New();
    resliceCursorWidget->SetInteractor(iren);

    resliceCursorRep = vtkSmartPointer< vtkResliceCursorLineRepresentation >::New();
    resliceCursorWidget->SetRepresentation(resliceCursorRep);
    resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->SetResliceCursor(resliceCursor);
    //thickness text is ediable and can turn off
    //resliceCursorRep->DisplayTextOff();
    resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->SetReslicePlaneNormal(0);
    cout << "number of input port: " << resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm() << endl;
    const double minVal = reader->GetOutput()->GetScalarRange()[0];
    std::cout << "minVal: " << minVal << " maxVal: " << reader->GetOutput()->GetScalarRange()[1] << endl; //0~1059

    if (vtkImageReslice *reslice = vtkImageReslice::SafeDownCast(resliceCursorRep->GetReslice()))
    {
        reslice->SetBackgroundColor(minVal, minVal, minVal, minVal);
    }

    resliceCursorWidget->SetDefaultRenderer(ren);
    resliceCursorWidget->SetEnabled(1);
    ren->GetActiveCamera()->SetFocalPoint(0, 0, 0);
    double camPos[3] = { 1, 0, 0 };
    ren->GetActiveCamera()->SetPosition(camPos);
    ren->GetActiveCamera()->ParallelProjectionOn();
    ren->GetActiveCamera()->SetViewUp(viewUp[0][0], viewUp[0][1], viewUp[0][2]);
    ren->ResetCamera();


    double range[2];
    reader->GetOutput()->GetScalarRange(range);
    std::cout << "range[0]: " << range[0] << " range[1]: " << range[1] << endl; // 0~1059
    //cover full range of window
    resliceCursorRep->SetWindowLevel(range[1] - range[0], (range[0] + range[1]) / 2.0);
    //resliceCursorRep->SetLookupTable(resliceCursorRep->GetLookupTable());
    //reslice cursor center
    vtkResliceCursor *rc = resliceCursorRep->GetResliceCursorActor()->GetCursorAlgorithm()->GetResliceCursor();
    double *center = rc->GetCenter();
    std::cout << "cursor center: " << " [x]: "
        << center[0] << " [y]: " << center[1] << " [z]: " << center[2] << endl;
    /************************/


    //background of window
    ren->SetBackground(0.3, 0.1, 0.1);

    //whether it is a hole in the center of two cross hair
    resliceCursor->SetHole(0);
    resliceCursor->SetThickness(2, 2, 2);
    cout << "thickness is : " << resliceCursor->GetThickness()[0] << endl;

    vtkSmartPointer< vtkInteractorStyleImage > style = vtkSmartPointer< vtkInteractorStyleImage >::New();
    iren->SetInteractorStyle(style);
    renWin->Render();
    //iren->Initialize();
    //iren->Start();

}
Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
Yinan Liu
  • 1
  • 1

1 Answers1

0

it was solved when I just claim the following in head file and make corresponding change in cpp:

private:
vtkSmartPointer< vtkResliceCursorWidget > resliceCursorWidget;

I don't know the depth of the solution. Maybe the QT cannot read the source file if it is not claimed, and also it needs timely render the source.

enter image description here

E_net4
  • 27,810
  • 13
  • 101
  • 139
Yinan Liu
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 24 '22 at 11:49