[Insight-users] problems using ImageToVTKImageFilter

Iván Macía imacia at vicomtech.es
Fri Oct 1 09:33:45 EDT 2004


Hola Carmen,

Give it a try with this. Have a look at the GetExporter() and GetImporter()
methods. With these you access respectively to the underlaying
itk::VTKImageExport<> and vtkImageImport objects that are members of the
ImageToVTKImageFilter class. Be careful also with deallocating memory for
the vtk objects (see below) because your code had memory leaks.

Hope that helps

Iván Macía



int main (void)
{

typedef unsigned short myPixelType;
typedef itk::Image< myPixelType, 3 > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageToVTKImageFilter< ImageType > ConnectorFilterType;

ReaderType::Pointer reader = ReaderType::New();
ConnectorFilterType::Pointer connector = ConnectorFilterType::New();

reader->SetFileName( "liver323seg.hdr" );
reader->Update();
reader->GetOutput()->Print(std::cout);

connector->GetExporter()->SetInput( reader->GetOutput() );
connector->GetImporter()->Update();
connector->GetImporter()->GetOutput()->Print(std::cout);

vtkImageViewer * viewer =vtkImageViewer::New();
vtkRenderWindowInteractor * renderWindowInteractor =
vtkRenderWindowInteractor::New();
viewer->SetupInteractor( renderWindowInteractor );
viewer->SetInput( connector->GetImporter()->GetOutput() );
viewer->SetZSlice( 0 ); // <-- Slice selection
viewer->Render();
renderWindowInteractor->Start();

viewer->Delete();
renderWindowInteractor->Delete();
connector->GetImporter()->Delete();
return 0;
}
-----Mensaje original-----
De: insight-users-bounces at itk.org [mailto:insight-users-bounces at itk.org]En
nombre de Carmen Olmos
Enviado el: viernes, 01 de octubre de 2004 14:47
Para: insight-users at itk.org
Asunto: [Insight-users] problems using ImageToVTKImageFilter


Hi,
I'm trying unsuccessfully to plot a slice of a volume. I read properly the
image but I get nothing at the connector output. Maybe somebody can help


Thank you,
Carmen

typedef unsigned char myPixelType;
typedef itk::Image< myPixelType, 3 > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageToVTKImageFilter< ImageType > ConnectorFilterType;
ReaderType::Pointer reader = ReaderType::New();
ConnectorFilterType::Pointer connector = ConnectorFilterType::New();
reader->SetFileName( "liver323seg.hdr" );
reader->Update();
reader->GetOutput()->Print(std::cout);
connector->SetInput( reader->GetOutput() );
connector->Update();
connector->GetOutput()->Print(std::cout);
vtkImageViewer * viewer =vtkImageViewer::New();
vtkRenderWindowInteractor * renderWindowInteractor =
vtkRenderWindowInteractor::New();
viewer->SetupInteractor( renderWindowInteractor );
viewer->SetInput( connector->GetOutput() );
viewer->SetZSlice( 50 ); // <-- Slice selection
renderWindowInteractor->Start();



More information about the Insight-users mailing list