Mathieu,
I have found a solution to my problem with two different options. I will share here in case it is useful for anyone else in the future. I suspect that my code is not the most efficient approach, but it works…
First I export the data from EDEM to vtu files using pointsToVTK. I export the 4 elements of the quaternion as:
pointsToVTK(vtkFileName, x, y, z, data = {“pID” : ids, “Length” : los, “Quatw” : qw,“Quatx” : qx,“Quaty” : qy,“Quatz” : qz})
next in Paraview I combine the the 4 elements of the quaternion together [Quatw, Quatx, Quaty, Quartz]
Option 1 - Programmable Filter
The programmable filter Script is as follows (it may not be the most efficient implementation but it works…):
#combine all 4 elements of the Quaternion into one structure
import numpy as np
print("Quaternion creation started")
#store 4 Quat elements in arrays
input0 = inputs[0]
dataArray = input0.PointData["Quatw"]
dataArray1 = input0.PointData["Quatx"]
dataArray2 = input0.PointData["Quaty"]
dataArray3 = input0.PointData["Quatz"]
#stack the arrays together to create 4 element Quat
All_Data2=np.vstack((dataArray,dataArray1))
All_Data2=np.vstack((All_Data2,dataArray2))
All_Data2=np.vstack((All_Data2,dataArray3))
#transpose the array to create the form (number point X 4)
All_Data2=np.transpose(All_Data2)
print("Quaternion of sphere")
print(All_Data2)
output.PointData.append(All_Data2, "Quaternion")
print("done")
Alternatively, I created a py script that can be imported as a ParaView Plugin (which makes it easier to share with others that will use the tool). The Python script is as follows:
Option 2 - Plugin Filter
from vtkmodules.vtkCommonDataModel import vtkDataSet, vtkUnstructuredGrid
from vtkmodules.util.vtkAlgorithm import VTKPythonAlgorithmBase
from vtkmodules.numpy_interface import dataset_adapter as dsa
import numpy as np
#module for ParaView-specific decorators.
from paraview.util.vtkAlgorithm import smproxy, smproperty, smdomain
@smproxy.filter(label="Custom_Quaternion")
@smproperty.input(name="Input")
class CustomQuatFilter(VTKPythonAlgorithmBase):
# define output data type - vtkUnstructuredGrid .
def __init__(self):
VTKPythonAlgorithmBase.__init__(self,
nInputPorts=1,
nOutputPorts=1,
outputType="vtkUnstructuredGrid")
def RequestData(self, request, inInfo, outInfo):
print("Started Custom Quaternion")
#store 4 Quat elements in arrays
input0 = dsa.WrapDataObject(vtkUnstructuredGrid.GetData(inInfo[0]))
#read in data in ParaView
dataArray = input0.PointData["Quatw"]
dataArray1 = input0.PointData["Quatx"]
dataArray2 = input0.PointData["Quaty"]
dataArray3 = input0.PointData["Quatz"]
#stack the arrays together to create 4 element Quat
All_Data2=np.vstack((dataArray,dataArray1))
All_Data2=np.vstack((All_Data2,dataArray2))
All_Data2=np.vstack((All_Data2,dataArray3))
#transpose the array to create the form (number point X 4)
All_Data2=np.transpose(All_Data2)
# add to output
output = dsa.WrapDataObject(vtkUnstructuredGrid.GetData(outInfo))
output.ShallowCopy(vtkUnstructuredGrid.GetData(inInfo[0]))
output.PointData.append(All_Data2, "Quaternion");
print("Completed Custom Quaternion")
return 1
The .py file is added to the ParaView filters by going to the Tools-> Manage Plugins-> Load New
Regards,
Eric