vtk.vtkTransform.GetOrientation produces the incorrect orientation if the difference in scales is more than 100.
Running on
Elements:
40 0 0 0
0 0 -10 0
0 0.04 0 0
0 0 0 1
gives the correct: [90.0, -0.0, 0.0]
But changing the scale slightly
41 0 0 0
0 0 -10 0
0 0.04 0 0
0 0 0 1
results in [0.0, -0.0, 0.0] which is incorrect
The reason why I need this in the first place is because I need to set the transform matrix of an actor. And the only way to do that is using SetScale, SetPosition and SetOrientation separately.
m0 = mat1.GetElement(0, 0)
m1 = mat1.GetElement(0, 1)
m2 = mat1.GetElement(0, 2)
m4 = mat1.GetElement(1, 0)
m5 = mat1.GetElement(1, 1)
m6 = mat1.GetElement(1, 2)
m8 = mat1.GetElement(2, 0)
m9 = mat1.GetElement(2, 1)
m10 = mat1.GetElement(2, 2)
scale1 = (m0 * m0 + m4 * m4 + m8 * m8) ** 0.5
scale2 = (m1 * m1 + m5 * m5 + m9 * m9) ** 0.5
scale3 = (m2 * m2 + m6 * m6 + m10 * m10) ** 0.5
actor.SetScale(scale1, scale2, scale3)
x = mat1.GetElement(0, 3)
y = mat1.GetElement(1, 3)
z = mat1.GetElement(2, 3)
actor.SetOrigin(0, 0, 0)
actor.SetPosition(x, y, z)
out = [0, 0, 0]
vtk.vtkTransform.GetOrientation(out, mat1)
print("=======================================================")
print(mat1)
print(out)
actor.SetOrientation(*out)
A possible work-around is to remove the scaling from the matrix before calculating the orientation:
mat1.SetElement(0,0, m0 / scale1)
mat1.SetElement(0,1, m1 / scale2)
mat1.SetElement(0,2, m2 / scale3)
mat1.SetElement(1, 0, m4 / scale1)
mat1.SetElement(1, 1, m5 / scale2)
mat1.SetElement(1, 2, m6 / scale3)
mat1.SetElement(2, 0, m8 / scale1)
mat1.SetElement(2, 1, m9 / scale2)
mat1.SetElement(2, 2, m10 / scale3)