[vtkusers] using both SetResliceTransform and SetResliceAxes

David Gobbi david.gobbi at gmail.com
Wed Jun 28 13:44:38 EDT 2017


Hi Clément,

The basic formula for the transformation in vtkImageReslice is as follows:

    p_in = T A p_out

where T is ResliceTransform, A is ResliceAxes, p_out is "output data
coords", and p_in is "input data coords".  In most cases, p_out is also
"world coords".

The documentation says "T is applied to the resampling grid that has been
defined by A", which is just another way of saying that "T is applied after
A".  As shown in the above equation, T is associated with p_in, not with
p_out.

In other words, you cannot use T to perform a transformation in world
coords.

Instead, the code would be something like this:

# define the desired translation in output (i.e. world) coords
t_world = (1.0, 0.0, 0.0, 0.0)
# convert to data coords
A = slice.GetResliceAxes()
t_data = A.MultiplyPoint(t_world)
# create a transformation for data coords
T.Translate(t_data[0:3])
slice.SetResliceTransform(T)

 - David


On Wed, Jun 28, 2017 at 10:12 AM, Clément D. <clement.douarre at gmail.com>
wrote:

> Hello everyone, new to VTK, etc etc.
>
> I wish to extract a  2D slice from a 3D volume, and then translate this
> slicing in the volume, following the axis of the slice
>
> So say I declare my slice this way (code is in Python) :
>
> -------------------------------------------
> oblique = vtk.vtkMatrix4x4()
> #Some oblique matrix, vectors are in fact normalised but here I just put
> random numbers for this example
> oblique.DeepCopy((0.3, 0   , 0   , 10,
>                   0  , 0.28, 0   , 10,
>                   0.8, 0   , 0.97, 10,
>                   0  , 0   , 0   , 1))
>
> slice=vtk.vtkImageReslice() #create the slice object
> slice.SetOutputExtent(0, 5, 0, 5, 0, 0)
> slice.SetOutputOrigin(-0.5 * 5, -0.5 * 5, 0)
>
> slice.SetResliceAxes(oblique) #set the resliceAxes matrix to it
> -----------------------------------------------
>
> So far so good, I get a slice oriented along the oblique matrix. It gets
> trickier when I want to translate it.
> Bear in mind that I would like a translation *along the axis of the
> oblique matrix* and not in world coordinates.
> I.E. i would like to translate along vectors (0.3,0,0.8), (0,0.28,0) and
> (0,0,0.97) (vectors of the oblique matrix)
>
> So if I do this :
>
> -------------------------------------------
> transformation = vtk.vtkTransform();
> slice.SetResliceTransform(transformation)
> transformation.Translate(1,0,0)
> slice.Update()
> -------------------------------------------
>
> I would expect reading documentation on setResliceTransform that my slice
> would move along one of these axis (the Z axis here).
> Because my understanding of setResliceTransform and setResliceAxes being
> used together is that the latter is used to set up a grid upon which the
> former will then act (so translating will "slide" along the axes of
> setResliceAxes)
> However, I do not observe this behaviour (I don't really how the slice is
> moving, but certainly not in the axes of oblique), did I get something
> wrong ?
>
> Many thanks,
> Clément
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170628/af76fb83/attachment.html>


More information about the vtkusers mailing list