[vtkusers] display dicom image in vtk

Hui Wang cougarhui at yahoo.com
Thu Apr 2 21:07:30 EDT 2009


Hi, all

I am new to vtk and want to read a dicom image from file and display it in a Qt GUI using qvtkWidget.

I used vtkDICOMImageReader to read the image, but when I used vtkImageViewer to display, it will show in another window, instead of qvtkWidget.

So I tried vtkImageActor, vtkRenderer and vtkRendererWindow pipeline, but an error happened saying 

ERROR: In /home/mandrake/rpm/BUILD/VTK/Rendering/vtkImageActor.cxx, line 182                        
vtkOpenGLImageActor (0x10ed8b0): This filter requires unsigned char scalars as input

Then I tried vtkImageCast, but the displayed image is not correct. Does anybody know the reason and how to fix it?  Thanks a lot.

Hui Wang


The following is the code I used:

        vtkDICOMImageReader *reader = vtkDICOMImageReader::New();
        reader->SetFileName(argv[1]);

        vtkImageCast *cast = vtkImageCast::New();
        cast->SetInputConnection(reader->GetOutputPort());
        cast->SetOutputScalarTypeToUnsignedChar();

        vtkImageActor *actor = vtkImageActor::New();
        actor->SetInput(cast->GetOutput());

        vtkRenderer *render = vtkRenderer::New();
        render->AddActor(actor);
        render->ResetCamera();

        vtkRenderWindow *window = vtkRenderWindow::New();
        window->AddRenderer(render);

        window->Render();


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090402/9891e981/attachment.htm>


More information about the vtkusers mailing list