Hi everyone:<div><br></div><div><br></div><div>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.</div><div><br></div><div>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.</div>
<div><br></div><div>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?</div><div><br></div><div>Thanks a lot!</div><div><br></div><div>Best,</div><div>
Yili </div><div><br></div><div>This is the code I changed from the example:</div><div><br></div><div><div>int main( int argc, char ** argv )</div><div>{</div><div> </div><div> if( argc < 4 )</div><div> {</div><div>
std::cerr << "Usage: " << std::endl;</div><div> std::cerr << argv[0] << " firstSliceValue lastSliceValue outputImageFile " << std::endl;</div><div> return EXIT_FAILURE;</div>
<div> }</div><div><br></div><div><br></div><div><br></div><div> typedef unsigned char PixelType;</div><div> const unsigned int Dimension = 3;</div><div><br></div><div> typedef itk::Image< PixelType, Dimension > ImageType;</div>
<div><br></div><div> typedef itk::ImageSeriesReader< ImageType > ReaderType;</div><div> typedef itk::ImageFileWriter< ImageType > WriterType;</div><div><br></div><div> ReaderType::Pointer reader = ReaderType::New();</div>
<div> WriterType::Pointer writer = WriterType::New();</div><div><br></div><div><br></div><div> const unsigned int first = atoi( argv[1] );</div><div> const unsigned int last = atoi( argv[2] );</div><div><br></div><div>
const char * outputFilename = argv[3];</div><div><br></div><div>//============================================Reader Part==============================================</div><div><br></div><div> typedef itk::NumericSeriesFileNames NameGeneratorType;</div>
<div><br></div><div> NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();</div><div><br></div><div><br></div><div> </div><div><br></div><div> nameGenerator->SetSeriesFormat( "h1-1.%03d.png" );</div>
<div><br></div><div> nameGenerator->SetStartIndex( first );</div><div> nameGenerator->SetEndIndex( last );</div><div> nameGenerator->SetIncrementIndex( 1 );</div><div><br></div><div> system("pause");</div>
<div> itk::PNGImageIO::Pointer pngIO=itk::PNGImageIO::New();</div><div> pngIO->SetNumberOfDimensions(3);</div><div><br></div><div><br></div><div> pngIO->SetDimensions(0,512);</div><div> pngIO->SetDimensions(1,512);</div>
<div> pngIO->SetDimensions(2,259);</div><div><br></div><div> reader->SetImageIO( pngIO);</div><div><br></div><div><br></div><div><br></div><div><br></div><div> reader->SetFileNames( nameGenerator->GetFileNames() );</div>
<div> system("pause");</div><div> reader->Update();</div><div> system("pause");</div><div><br></div><div> std::cout<<pngIO->GetImageSizeInBytes()<<" "<<512*512<<std::endl;</div>
<div> std::cout<<pngIO->GetIORegion()<<std::endl;</div><div><br></div><div>//===============================================Writer Part=============================================</div><div><br></div><div>
itk::VTKImageIO::Pointer vtkIO=itk::VTKImageIO::New();</div><div><br></div><div> vtkIO->SetFileTypeToBinary();</div><div><br></div><div> vtkIO->SetNumberOfDimensions(3);</div><div> vtkIO->SetNumberOfComponents(1);</div>
<div><br></div><div> vtkIO->SetDimensions(0,512);</div><div> vtkIO->SetDimensions(1,512);</div><div> vtkIO->SetDimensions(2,259);</div><div><br></div><div> vtkIO->SetSpacing(0,1);</div><div> vtkIO->SetSpacing(1,1);</div>
<div> vtkIO->SetSpacing(2,2.23776);</div><div><br></div><div> writer->SetImageIO(vtkIO);</div><div><br></div><div><br></div><div> writer->SetFileName( outputFilename );</div><div><br></div><div> writer->SetInput( reader->GetOutput() );</div>
<div><br></div><div> try </div><div> { </div><div> writer->Update(); </div><div> } </div><div> catch( itk::ExceptionObject & err ) </div><div> { </div><div> std::cerr << "ExceptionObject caught !" << std::endl; </div>
<div> std::cerr << err << std::endl; </div><div> return EXIT_FAILURE;</div><div> } </div><div><br></div><div> std::cout<<vtkIO->GetIORegion()<<std::endl;</div><div><br></div><div>//==========================================Visualizing Part===============================================</div>
<div><br></div><div><br></div><div> vtkStructuredPointsReader* vtkReader=vtkStructuredPointsReader::New();</div><div><br></div><div> vtkReader->SetFileName("h1-1.vtk");</div><div> vtkReader->Update();</div>
<div> </div><div> vtkContourFilter *iso=vtkContourFilter::New();</div><div> iso->SetInputConnection(vtkReader->GetOutputPort());</div><div> iso->SetValue(0,128.0f);</div><div><br></div><div> </div><div> vtkRenderer* ren=vtkRenderer::New();</div>
<div> vtkRenderWindow* renWin=vtkRenderWindow::New();</div><div> renWin->AddRenderer(ren);</div><div><br></div><div> </div><div> vtkPolyDataMapper* volumeMapper=vtkPolyDataMapper::New();</div><div> volumeMapper->SetInputConnection(iso->GetOutputPort());</div>
<div> volumeMapper->ScalarVisibilityOff();</div><div><br></div><div> </div><div> vtkRenderWindowInteractor* iren=vtkRenderWindowInteractor::New();</div><div><br></div><div> vtkActor* isoActor=vtkActor::New();</div><div>
isoActor->SetMapper(volumeMapper);</div><div><br></div><div><br></div><div> vtkProperty* prop=vtkProperty::New();</div><div> prop->SetColor(0,1,0);</div><div><br></div><div> </div><div> isoActor->SetProperty(prop);</div>
<div> isoActor->ApplyProperties();</div><div><br></div><div><br></div><div> ren->AddActor(isoActor);</div><div> </div><div> iren->SetRenderWindow(renWin);</div><div> renWin->SetSize(400,400);</div><div> iren->Initialize();</div>
<div> iren->Start();</div><div><br></div><div><br></div><div> return EXIT_SUCCESS;</div><div>}</div><div><br></div><div><br></div><div><br></div></div>