[vtkusers] How to read a dicom and display in the in the windows

cvinllen cvinllen at gmail.com
Sat Dec 20 08:34:05 EST 2014


Hello:
     I use vtk 4 before, last week, i install vtk 6, it's looks like 
some class and function changed. I write a simple code, read dicom and 
display, it's can run success before i update the vtk to 6:

     //read dicom
     vtkDICOMImageReader   *reader =  vtkDICOMImageReader::New();
     reader->SetDataByteOrderToLittleEndian();
     reader->SetDirectoryName(path.c_str());
     reader->SetDataOrigin(0.0, 0.0, 0.0);

     //store in the vtkImageData
     vtkSmartPointer<vtkImageData> imageData = 
vtkSmartPointer<vtkImageData>::New();
     imageData = reader->GetOutput();

     //i think here has problem, because gdb show bug here
     vtkImageCast *cast = vtkImageCast::New();
     cast->SetInputData(imageData);
     cast->ClampOverflowOn();
     cast->SetOutputScalarTypeToUnsignedShort();

     vtkPiecewiseFunction *opacityTransferFunction = 
vtkPiecewiseFunction::New();
     opacityTransferFunction->RemoveAllPoints();
     opacityTransferFunction->AddPoint(0, 0.0);
     opacityTransferFunction->AddPoint(255, 1);

     vtkColorTransferFunction *colorTransferFunction = 
vtkColorTransferFunction::New();
     colorTransferFunction->RemoveAllPoints();
     colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
     colorTransferFunction->AddRGBPoint(255, 1.0, 1.0, 1.0);

     vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
     volumeProperty->SetColor(colorTransferFunction);
     volumeProperty->SetScalarOpacity(opacityTransferFunction);
     volumeProperty->ShadeOn();
     volumeProperty->SetInterpolationTypeToLinear();

     vtkVolumeRayCastCompositeFunction *compositeFunction = 
vtkVolumeRayCastCompositeFunction::New();
     vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
     volumeMapper->SetVolumeRayCastFunction(compositeFunction);
     volumeMapper->SetInputData(cast->GetOutput());

     vtkVolume *volume = vtkVolume::New();
     volume->SetMapper(volumeMapper);
     volume->SetProperty(volumeProperty);

     vtkCamera *aCamera = vtkCamera::New();
     aCamera->SetViewUp (0, 0, -1);
     aCamera->SetPosition (0, 1, 0);
     aCamera->SetFocalPoint (0, 0, 0);
     aCamera->ComputeViewPlaneNormal();
     aCamera->Dolly(1.0);

     vtkRenderer *renderer = vtkRenderer::New();
     renderer->RemoveAllViewProps();
     renderer->AddVolume(volume);
     renderer->SetActiveCamera(aCamera);
     renderer->SetBackground( 0,0,0 );
     renderer->ResetCamera ();
     //renderer->Render();

     vtkRenderWindow *renWin = vtkRenderWindow::New();
     renWin->AddRenderer(renderer);
     renWin->SetSize(500, 500);
     renWin->Start();
     renWin->Render();  // gdb show the bug occur

     vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
     iren->SetRenderWindow(renWin);
     iren->Initialize();
     iren->Start();

_the gdb show:_
[New Thread 0x7fffe1385700 (LWP 4012)]
[Thread 0x7fffe1385700 (LWP 4012) exited]
[New Thread 0x7fffe1385700 (LWP 4013)]
[Thread 0x7fffe1385700 (LWP 4013) exited]
[New Thread 0x7fffe1385700 (LWP 4014)]
[Thread 0x7fffe1385700 (LWP 4014) exited]

X Error of failed request:  BadMatch (invalid parameter attributes)
   Major opcode of failed request:  156 (GLX)
   Minor opcode of failed request:  11 (X_GLXSwapBuffers)
   Serial number of failed request:  687
   Current serial number in output stream:  687
[Inferior 1 (process 4006) exited with code 01]



I dont kown what the difference between the vtk 6 and vtk 4, greate 
appreciates for anyone's reply!



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141220/8b16a776/attachment.html>


More information about the vtkusers mailing list