[vtkusers] vtkImageViewer2 with QVTKWidget

Clinton Stimpson clinton at elemtech.com
Thu Jul 27 15:09:15 EDT 2006


Because the vtkImageViewer2::Render functions checks that the width of 
the window is zero, before it initializes the placement of the image.
And because Qt is being used, the width of the window is not zero, and 
the necessary code in vtkImageViewer2 doesn't get called.
So you don't see the image correctly.

As a side note:
vtkImageViewer and vtkImageViewer2 provide & internally use SetSize(), 
which is usually incorrect in the context of a GUI.
In a GUI, the GUI controls the window sizes with its own size policies.

Clint

> Hi everyone,
>
> So I cut down the code but still cannot display a DICOM image inside of
> vtkImageViewer2 object. The normal vtkImageViewer works fine.
>
> Here is the updated code:
>
> QApplication app(argc, argv);
>
> QVTKWidget widget;
>
> #if QT_VERSION < 0x040000
>     app.setMainWidget(&mainWin);
> #endif
>
> vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
>
> reader->SetDirectoryName("/home/luca/data/dicom/11088");
> reader->Update();
>
> vtkImageViewer2 * view2 = vtkImageViewer2::New();
> view2->SetInputConnection(reader->GetOutputPort());
>
> double * range = reader->GetOutput()->GetScalarRange();
> view2->SetColorLevel (0.5 * (range[1] + range[0]));
> view2->SetColorWindow (range[1] - range[0]);
>
> widget.SetRenderWindow(view2->GetRenderWindow());
>
> // Put these 2 lines....just in case...
> view2->SetSlice(0);
> view2->GetRenderer()->ResetCameraClippingRange();
>
> view2->Render();
>
> widget.show();
>
> // Run our application loop.
> app.exec();
>
> I really am lost as to why it would not show me the image. Again,
> substituting vtkImageViewer2 with vtkImageViewer works fine. Is there some
> trick with the camera or the renderer that I am forgetting??? I am running
> SuSe 10.1 on a 64 bit machine.
>
> If someone can try this code and let me know if it works on their machine,
> it would be great.
>
> Cheers,
>
> Luca
>   




More information about the vtkusers mailing list