[vtkusers] Reading one slice of a volume from file

Richard Whitehead richard.whitehead at vivosight.com
Mon Mar 3 11:14:47 EST 2014


I am trying to update just one slice of a vtkImageData by reading it from
file, leaving the rest of the volume unchanged.  My code is below. I am
trying to limit the region updated by the filter by calling
SetUpdateExtent, but I don't think this is doing anything.  When I call
UpdateWholeExtent, **all** image slices contain a copy of the 2D image read
from file.  If instead I only call Update, then the volume now consists of
only one slice.
Note that I don't want to read a sequence of files with structured
filenames, I want to read one slice at a time for reasons too tedious to
explain here!
Please help!  Thanks in advance.



int SIZE_X = 722;
int SIZE_Y = 460;
int SIZE_Z = 100;

// create volume (16-bit)
m_imageVolume = vtkSmartPointer<vtkImageData>::New();
m_imageVolume->SetExtent(0, SIZE_X-1, 0, SIZE_Y-1, 0, SIZE_Z-1);
m_imageVolume->SetSpacing(1.0, 1.0, 1.0);
m_imageVolume->SetOrigin(0.0, 0.0, 0.0);
m_imageVolume->AllocateScalars(VTK_UNSIGNED_SHORT, 1);

// set it all mid-grey
unsigned short* volPtr = static_cast<unsigned short*>(
m_imageVolume->GetScalarPointer() );
memset(volPtr, 30000, SIZE_X * SIZE_Y * SIZE_Z * sizeof(unsigned short) );


int de[6];
m_imageVolume->GetExtent( de );

// read data into middle slice
vtkSmartPointer<vtkTIFFReader> reader =
vtkSmartPointer<vtkTIFFReader>::New();
reader->SetOutput( m_imageVolume );
reader->SetFileName("..... .tif");
reader->SetFileDimensionality(2);
reader->SetDataExtent( de );

int updateExtent[6];
updateExtent[0] = 0;
updateExtent[1] = SIZE_X-1;
updateExtent[2] = 0;
updateExtent[3] = SIZE_Y-1;
updateExtent[4] = SIZE_Z/2;
updateExtent[5] = SIZE_Z/2;
reader->SetUpdateExtent( updateExtent );

reader->SetOrientationType( ORIENTATION_BOTLEFT );  // otherwise it comes
out upside down
//reader->Update(); // volume has only one slice
reader->UpdateWholeExtent(); // volume has many slices all containing the
image read from file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140303/2888ed07/attachment.html>


More information about the vtkusers mailing list