Hi all,
I am trying to convert a rotations tensor into a quaternion using a programmable filter. However, the actual conversion function from VTK refuses to cooperate…
The code:
from paraview.vtk.vtkCommonCore import vtkMath, vtkArray
from paraview.vtk.numpy_interface import dataset_adapter as dsa
import numpy as np
def make_quat(TENSOR):
quatlist = []
for t in TENSOR:
quat = np.zeros(4)
tens = np.asarray(t)
#tens = np.asarray([[1,0,0],[0,1,0],[0,0,1]])
print(type(tens), tens)
vtkMath.Matrix3x3ToQuaternion(tens, quat)
quatlist.append(quat)
o = np.asarray(quatlist).view(dsa.VTKArray)
o.DataSet = TENSOR.DataSet
o.Association = TENSOR.Association
return o
tensor = inputs[0].PointData["TENSOR"]
output.PointData.append(make_quat(tensor), "test")
What I get is the following error message and output (yes, in that order):
Traceback (most recent call last):
File "<string>", line 22, in <module>
File "<string>", line 19, in RequestData
File "<string>", line 12, in make_quat
TypeError: Matrix3x3ToQuaternion argument 1: expected a sequence of 3 values, got -1 values
<class 'numpy.ndarray'> [VTKArray([[ 0.70710678, -0.70710678, 0. ], [ 0.70710678, 0.70710678, 0. ], [ 0. , 0. , 1. ]])]
Using the handcrafted tensor (commented), the whole filter works and give the expected results. Using that approach tens
is also a “pure” numpy.ndarray
, without nested VTKArray
.
How do I correctly convert that VTKArray
to be accepted by the conversion function?
Is that the actual problem or am I severely misunderstanding something else?