请相信@CoryQuammen,因为这确实是他的解决方案
完整脚本,包括一些单元格和点数据,供将来参考
from paraview.simple import *
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'Programmable Source'
mesh = ProgrammableSource()
mesh.OutputDataSetType = 'vtkUnstructuredGrid'
mesh.ScriptRequestInformation = ''
mesh.PythonPath = ''
mesh.Script = '''
import numpy as np
coor = np.array([
[ 0.0 , 0.0 ],
[ 1.0 , 0.0 ],
[ 2.0 , 0.0 ],
[ 0.0 , 1.0 ],
[ 1.0 , 1.0 ],
[ 2.0 , 1.0 ],
])
conn = np.array([
[ 0 , 1 , 4 , 3 ],
[ 1 , 2 , 5 , 4 ],
])
celldata = [
1.0 ,
2.0
]
normals = np.array([
[ -1.0 , -1.0 ],
[ 0.0 , -1.0 ],
[ +1.0 , -1.0 ],
[ -1.0 , +1.0 ],
[ 0.0 , +1.0 ],
[ +1.0 , +1.0 ],
])
normals /= np.tile(np.sqrt(np.sum(normals**2.,axis=1)).reshape(-1,1),(1,2))
import vtk
grid = self.GetOutput()
points = vtk.vtkPoints()
for i,(x,y) in enumerate(coor):
points.InsertNextPoint(x,y,0.0)
grid.SetPoints(points)
grid.Allocate()
for el in conn:
cell = vtk.vtkQuad()
for i,ver in enumerate(el):
cell.GetPointIds().InsertId(i,ver)
grid.InsertNextCell(cell.GetCellType(),cell.GetPointIds())
data = vtk.vtkDoubleArray()
data.SetName("Example data")
for i in celldata:
data.InsertNextValue(i)
grid.GetCellData().AddArray(data)
data = vtk.vtkDoubleArray()
data.SetNumberOfComponents(3)
data.SetName("Normals")
for i in normals:
data.InsertNextTuple([i[0],i[1],0.0])
grid.GetPointData().AddArray(data)
'''
# show data from mesh
Mesh = Show(mesh)
Render()