[Insight-users] How to show dicoms with vtk (ImageToVTKImageFilter)

soheilghafurian soheilghafurian at yahoo.com
Sun Jul 17 22:25:04 EDT 2011


My problem is I load a dicom file and I try to show it through vtk by
ImageToVTKImageFilter. But the result is kind of distorted. I think the
problem is because the pixeltype is not good, but when I use another type, I
get this message when the program is running: 

ERROR: In ..\..\Rendering\vtkImageActor.cxx, line 267
vtkOpenGLImageActor (058C5340): This filter requires unsigned char scalars
as input

Could anyone help me on how I should solve this problem? here is the code:

int main()
{ 
	char *fName = fl_file_chooser("Pick the fixed dicom Image", "*.dcm", ".");
      if(fName == NULL) return 0;

	  typedef itk::Image< unsigned char, 2> ImageType;
  typedef itk::ImageFileReader<ImageType>             ReaderType;
  typedef itk::ImageToVTKImageFilter<ImageType>       ConnectorType;
 
  ReaderType::Pointer reader = ReaderType::New();
  ConnectorType::Pointer connector = ConnectorType::New();
 
  reader->SetFileName(fName);
  reader->Update();
  connector->SetInput(reader->GetOutput());


 
  vtkSmartPointer<vtkImageActor> actor =
    vtkSmartPointer<vtkImageActor>::New();
//  actor->SetInput(connector->GetOutput());
  actor->SetInput(connector->GetOutput());
 
  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  renderer->AddActor(actor);
  renderer->ResetCamera();
 
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
 
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  vtkSmartPointer<vtkInteractorStyleImage> style =
    vtkSmartPointer<vtkInteractorStyleImage>::New();
 
  renderWindowInteractor->SetInteractorStyle(style);
 
  renderWindowInteractor->SetRenderWindow(renderWindow);
  renderWindowInteractor->Initialize();
 
  renderWindowInteractor->Start();
 
  return EXIT_SUCCESS;
}



--
View this message in context: http://itk-insight-users.2283740.n2.nabble.com/How-to-show-dicoms-with-vtk-ImageToVTKImageFilter-tp6593222p6593222.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list