using both SetResliceTransform and SetResliceAxes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

using both SetResliceTransform and SetResliceAxes

Clément D.
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

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using both SetResliceTransform and SetResliceAxes

David Gobbi
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. <[hidden email]> 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


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: using both SetResliceTransform and SetResliceAxes

Clément D.
Great David, I understand and it works now ! Thanks

2017-06-28 19:44 GMT+02:00 David Gobbi <[hidden email]>:
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. <[hidden email]> 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



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Loading...