[vtkusers] Problem with vtkCamera::GetOrientationWXYZ
Paul A Hsieh
pahsieh at usgs.gov
Thu Oct 3 15:52:31 EDT 2002
After a relatively long hiatus from this mailing list, I hope to be back on
board. I am revising an application from using VTK 3.1 to 4.0 and I ran
into an inconsistency in the result returned by
vtkCamera::GetOrientationWXYZ. This is illustrated by the following C++
sample code:
#include "vtkCamera.h"
void main()
{
vtkCamera *cam = vtkCamera::New();
cam->SetPosition(40.5388, -58.1675, 36.4357);
cam->SetFocalPoint(12.5875, 11.3799, 10.3485);
cam->SetViewUp(-0.221512, 0.263181, 0.938972);
cam->ComputeViewPlaneNormal(); // Needed for VTK 3.1
cam->OrthogonalizeViewUp();
float *wxyz = cam->GetOrientationWXYZ();
cout << wxyz[0] << " " << wxyz[1] << " " << wxyz[2] << " " << wxyz[3];
}
When run using VTK 4.0 (nightly release, Oct 1, 2002), I get
284.514 0.937559 0.129517 0.322812
When run using VTK 3.1, I get
75.4863 0.937559 0.129517 0.322812
The first number (angle) differ in the two results.
I think the number returned by VTK 4.0 is incorrect for the following
reason. The method vtkCamera::GetOrientationXYZ() is used only in 2
classes, one of which is vtkVRMLExporter. In VTK3.1, vtkVRMLExporter
generates a correct vrml file. In VTK4.0, vtkVRMLExporter does not generat
a correct vrml file (the viewpoint is oriented in the wrong direction).
Tracking the computation through the source code of VTK 3.1 versus 4.0, the
main difference occurs in the row-column indexing of the matrix in the
class vtkTransform. In particular, the method
vtkTransform::GetOrientationWXYZ() is
void vtkTransform::GetOrientationWXYZ(double wxyz[4])
{
int i;
this->Update();
// convenient access to matrix
double (*matrix)[4] = this->Matrix->Element;
double ortho[3][3];
for (i = 0; i < 3; i++)
{
ortho[0][i] = matrix[0][i];
ortho[1][i] = matrix[1][i];
ortho[2][i] = matrix[2][i];
}
//...etc
where ortho is subsequently used to compute w,x,y,z. If I transpose the
ortho matrix, that is, change the above loop to
for (i = 0; i < 3; i++)
{
ortho[i][0] = matrix[0][i];
ortho[i][1] = matrix[1][i];
ortho[i][2] = matrix[2][i];
}
and rebuild VTK 4.0, then the above sample program gives the same result as
that of VTK3.1. Also, the vrml file exported by vtkVRMLExporter is correct
(viewpoint looks at the correct direction).
The above suggests that either (1) the elements in the matrix of
vtkTransform are stored in reversed row-column order, or (2) the row-column
index is reversed somewhere during the computation of wxyz.
Hope the above makes sense.
Paul Hsieh
More information about the vtkusers
mailing list