[vtkusers] vtkImagePermute without copying the data
dgobbi at irus.rri.on.ca
Sat Mar 10 18:12:29 EST 2001
On 10 Mar 2001, Alexandre Guimond wrote:
> Hi there. Would anybody out there have a class that does the same
> thing vtkImagePermute does, but that only changes the attributes
> (extents,dimensions,etc.) and references the input data for it's own?
This isn't possible. You can't rearrange the x,y,z of vtkImageData
without re-ordering the data in memory.
> I'm building a viewer with 3 views for each data set (x,y,z) and the
> unnecessary 2*NumDataSets*permute simply takes too much memory. I'm
> sure some of you have done this before so there must be a better way
> than what I'm doing now...
Usually when you use vtkImagePermute, it doesn't actually permute the
entire volume... it only extracts the single slice that you are viewing.
However, for extracting axial/sagitall/coronal slices from a volume I
find that it is best to use three copies of vtkImageReslice, each with
a different permutation matrix for the ResliceMatrix.
pmatrix = vtkMatrix4x4()
pmatrix.DeepCopy(( 0, 0, 1, 0,
0, 1, 0, 0,
-1, 0, 0, 0,
0, 0, 0, 1))
# width, height are window dimensions
# zoom is the zoom factor
# displayX, displayY can be used to pan through the volume
# displayZ can be used to display different slices
reslice = vtkImageReslice()
reslice.SetOutputExtent(0, width-1, 0, height-1, 0, 0)
reslice.SetOutputSpacing(1.0/zoom, 1.0/zoom, 1.0/zoom)
examples of how to compute displayX, displayY, displayZ
in order to display the desired slice of the image are
provided in contrib/examplesPython/SliceViewer.py
Another option, if you're good at working with transformations,
is to instead use
and then, instead of making 'pmatrix' a simple permutation matrix,
create a matrix that will convert directly from the window
display coordinates to the volume data coordinates, i.e. the
matrix will map the four corners of the window (0,0,width-1,height-1)
to the four corners of the volume slice that you want to view.
More information about the vtkusers