[Insight-users] Problem of writing .png to .vtk volume
Yili Pan
pyl0420 at gmail.com
Thu Sep 10 11:11:45 EDT 2009
Hi everyone:
I have a series of .png lung data and I use ImageSeriesReadWrite example to
write the series into volume. Then I use VTK to display the volume.
The former part of the project seems to work well, since I got the .vtk
volume. However, the window shows nothing at last when I was trying to use
vtkContourFilter as the filter to display the lung.
I am not sure if I missed to set some data of the volume or this is the
visualization problem. Can you help me with this?
Thanks a lot!
Best,
Yili
This is the code I changed from the example:
int main( int argc, char ** argv )
{
if( argc < 4 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " firstSliceValue lastSliceValue
outputImageFile " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
const unsigned int Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageSeriesReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
const unsigned int first = atoi( argv[1] );
const unsigned int last = atoi( argv[2] );
const char * outputFilename = argv[3];
//============================================Reader
Part==============================================
typedef itk::NumericSeriesFileNames NameGeneratorType;
NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();
nameGenerator->SetSeriesFormat( "h1-1.%03d.png" );
nameGenerator->SetStartIndex( first );
nameGenerator->SetEndIndex( last );
nameGenerator->SetIncrementIndex( 1 );
system("pause");
itk::PNGImageIO::Pointer pngIO=itk::PNGImageIO::New();
pngIO->SetNumberOfDimensions(3);
pngIO->SetDimensions(0,512);
pngIO->SetDimensions(1,512);
pngIO->SetDimensions(2,259);
reader->SetImageIO( pngIO);
reader->SetFileNames( nameGenerator->GetFileNames() );
system("pause");
reader->Update();
system("pause");
std::cout<<pngIO->GetImageSizeInBytes()<<" "<<512*512<<std::endl;
std::cout<<pngIO->GetIORegion()<<std::endl;
//===============================================Writer
Part=============================================
itk::VTKImageIO::Pointer vtkIO=itk::VTKImageIO::New();
vtkIO->SetFileTypeToBinary();
vtkIO->SetNumberOfDimensions(3);
vtkIO->SetNumberOfComponents(1);
vtkIO->SetDimensions(0,512);
vtkIO->SetDimensions(1,512);
vtkIO->SetDimensions(2,259);
vtkIO->SetSpacing(0,1);
vtkIO->SetSpacing(1,1);
vtkIO->SetSpacing(2,2.23776);
writer->SetImageIO(vtkIO);
writer->SetFileName( outputFilename );
writer->SetInput( reader->GetOutput() );
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
std::cout<<vtkIO->GetIORegion()<<std::endl;
//==========================================Visualizing
Part===============================================
vtkStructuredPointsReader* vtkReader=vtkStructuredPointsReader::New();
vtkReader->SetFileName("h1-1.vtk");
vtkReader->Update();
vtkContourFilter *iso=vtkContourFilter::New();
iso->SetInputConnection(vtkReader->GetOutputPort());
iso->SetValue(0,128.0f);
vtkRenderer* ren=vtkRenderer::New();
vtkRenderWindow* renWin=vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkPolyDataMapper* volumeMapper=vtkPolyDataMapper::New();
volumeMapper->SetInputConnection(iso->GetOutputPort());
volumeMapper->ScalarVisibilityOff();
vtkRenderWindowInteractor* iren=vtkRenderWindowInteractor::New();
vtkActor* isoActor=vtkActor::New();
isoActor->SetMapper(volumeMapper);
vtkProperty* prop=vtkProperty::New();
prop->SetColor(0,1,0);
isoActor->SetProperty(prop);
isoActor->ApplyProperties();
ren->AddActor(isoActor);
iren->SetRenderWindow(renWin);
renWin->SetSize(400,400);
iren->Initialize();
iren->Start();
return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090910/987b6127/attachment-0001.htm>
More information about the Insight-users
mailing list