[vtkusers] Saving the image generated by vtkImageViewer
Michael Györffy
4mg19 at qlink.queensu.ca
Mon May 27 17:23:30 EDT 2002
Hello:
I have a data set which I'm trying to slice up at an angle and save each
new section. I can reslice it but I can't save the individual slices. What
am
I doing wrong?
I'm trying to save the results of vtkImageViewer as tiffs in the loop at
the end of
the following script.
Thank you for any help,
Mike
int main (void)
{
int i;
char filename[2000];
vtkPNMReader *reader = vtkPNMReader::New();
reader-> ReleaseDataFlagOff();
reader-> SetDataByteOrderToLittleEndian();
reader-> SetDataExtent (0,343, 0,512, 1,287);
reader-> SetDataOrigin (-171.5, -256, -143.5);
reader-> SetFilePrefix ("/Temp");
reader-> SetDataMask (0x7fff);
vtkTransform *transform = vtkTransform::New();
transform-> RotateX (45);
transform-> RotateY (45);
transform-> RotateZ (0);
vtkImageReslice *reslice = vtkImageReslice::New();
reslice-> SetInput (reader->GetOutput());
reslice-> SetResliceTransform(transform);
reslice-> InterpolateOn();
reslice-> SetBackgroundLevel (1);
vtkImageViewer *viewer = vtkImageViewer::New();
viewer-> SetInput (reslice->GetOutput());
viewer-> SetColorWindow(200);
viewer-> SetColorLevel(100);
vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New();
vtkPNMWriter *pnmwriter=vtkPNMWriter::New();
for (i=1; i<287; i++)
{
sprintf(filename, "anim.%d.pnm", i);
viewer-> SetZSlice(i);
viewer-> Render();
printf("Image number %d. \n", i);
w2if->SetInput(viewer);
w2if->Modified();
pnmwriter->SetInput(w2if->GetOutput());
pnmwriter->SetFileName(filename);
pnmwriter->Write();
}
reader->Delete();
transform->Delete();
reslice->Delete();
viewer->Delete();
w2if->Delete();
pnmwriter->Delete();
}
More information about the vtkusers
mailing list