vtkTransform::GetOrientation()

David Gobbi dgobbi at irus.rri.on.ca
Sun Apr 30 00:32:35 EDT 2000


This email is just mathematical nitpicking, so people who aren't
concerned about absolute mathematical correctness in VTK can safely
delete it.

I've been looking over vtkTransform in some detail, and the following
three methods are not always guaranteed to give the correct answer:

vtkTransform::GetOrientation()
vtkTransform::GetOrientationWXYZ()
vtkTransform::GetScale()


The reason for the incorrect behaviour is that GetScale() computes
the scale factors by simply computing the norm of each row of the
matrix.  This is valid if the Scale(sx,sy,sz) transform was the first
transform applied to the matrix, but if a Rotate() was applied before
the scale, then GetScale() returns a meaningless answer.

Because the GetOrientation() and GetOrientationWXYZ() methods use
GetScale() internally, these methods will return the wrong answers
under the same circumstances.


Here is a brief example, in Python:

>>> t = vtkTransform()
>>> t.Identity()  
>>> t.PostMultiply()
>>> t.RotateY(10)
>>> t.RotateX(20)
>>> t.RotateZ(30)
>>> t.Scale(3,4,5)
>>> t.GetScale()
(3.39062547684, 3.93795776367, 4.79542970657) # MEANINGLESS ANSWER
>>> t.GetOrientation()
(23.5902271271, 14.0029554367, 33.2617263794) # WRONG ANSWER


>>> t = vtkTransform()
>>> t.Identity()  
>>> t.PostMultiply()
>>> t.Scale(3,4,5)
>>> t.RotateY(10)
>>> t.RotateX(20)
>>> t.RotateZ(30)
>>> t.GetScale()
(3.0, 4.0, 5.0)           # RIGHT ANSWER
>>> t.GetOrientation()
(20.0, 10.0, 30.0)        # RIGHT ANSWER


Fortunately, most places that these methods are applied within the
VTK code, the transforms either have uniform scaling (i.e. the 
view matrix of the camera) or the scaling was applied before the
rotation (i.e. actor matrices).  The only time that problems
will occur are if you supply a UserMatrix for an actor that has 
the composite actor transformation does not fit into these two
categories.


The correct method for finding the orientation of a matrix is to
apply singular value decomposition.  Unfortunately, VTK doesn't have
an SVD routine (and they are not easy to write!).  It would be greqt
if VTK did have an SVD routine, because it would then be possible to
correctly decompose any non-perspective 4x4 matrix into its component
transformations: 

1) three scale factors, and a matrix specifying three orthonornal 
   axes along which the scale factors are applied

2) a rotation matrix

3) a translation vector

Right now, the decomposition only works if the scale factors are along
the x,y,z axes.

Apologies to the non-nitpickers out there.

 - David
 
--
  David Gobbi, MSc                    dgobbi at irus.rri.on.ca
  Advanced Imaging Research Group
  Robarts Research Institute, University of Western Ontario


--------------------------------------------------------------------
This is the private VTK discussion list. Please keep messages on-topic.
Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at public.kitware.com>. For help, send message body containing
"info vtkusers" to the same address.
--------------------------------------------------------------------



More information about the vtkusers mailing list