Matrix4x4::PointMultiply() prints warning
David Gobbi
dgobbi at irus.rri.on.ca
Fri Apr 14 18:29:21 EDT 2000
Hi All,
In the current nightlies, VTK will now print a warning whenever you call
vtkMatrix4x4::PointMultiply(), or whenever you call
vtkTransform::GetPoint() when the vtkTransform is in PreMultiply mode.
The vtkMatrix4x4::MultiplyPoint() has not been changed, only
PointMultiply().
The reason is this: when you multiply a vector by a matrix in VTK, 99%
of the time you want to treat the coordinate as a column vector, i.e.
(apologies to people using proportional fonts)
/ y[0] \ / A[0][0] A[0][1] A[0][2] A[0][3] \ / x[0] \
| y[1] | = | A[1][0] A[1][1] A[1][2] A[1][3] | * | x[1] |
| y[2] | | A[2][0] A[2][1] A[2][2] A[2][3] | | x[2] |
\ y[3] / \ A[3][0] A[3][1] A[3][2] A[3][3] / \ x[3] /
whereas vtkMatrix4x4::PointMultiply() will treat the coordinate as a
row vector,
( y[0] y[1] y[2] y[3] ) = ( x[0] x[1] x[2] x[3] ) * A
This is mathematically equivalent to multiplying a column vector by
the transpose of the matrix. The times when you really want to do
this are very rare, in both my own code and the VTK code I found
that every time PointMultiply was being called, the multiplication
was _meant_ to be done with a column vector but some mistake had
transposed the matrix! Note that for rotation-only matrices,
an inversion of the matrix is equivalent to a transpose.
The frightening part is this: vtkTransform::GetPoint() uses
vtkMatrix4x4::PointMultiply() whenever the transform is in
PreMultiply mode. This means that, the default behaviour of
GetPoint() is to multiply your coordinate by the _transpose_ of
the matrix, which you almost never want! Hence the warning
message.
I would advocate that people avoid SetPoint(), GetPoint()
altogether -- either use MultiplyPoint or, if you are using
VTK 3.1 or later, use TransformPoint(). Recent nightlies
also have TransformNormal() and TransformVector(). The
vtkPerspectiveTransform class will allow you to avoid using
homogenous coordinates even when you are performing
perspective transformations.
- 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