我想使用Paraview绘制简单的2D网格,每个单元使用不同的颜色,或者每个顶点使用不同的颜色。据我所知,Paraview文档没有解释如何Show()
一个用户定义的VTK对象
我从Paraview guide了解了VTK数据模型的工作原理,从VTK User's Guide了解了如何生成vtkImageData
对象
据我所知,下面的代码应该生成一个10x5 2D网格的vtkImageData
对象,该网格跨越[0.-10.]x[0.-5.],包含50个蓝色元素
但现在我不知道如何在Paraview中实际绘制它
from paraview import vtk
import paraview.simple as ps
import numpy as np
from paraview.vtk.util.numpy_support import numpy_to_vtk
def main():
# create the vtkImageData object
myMesh = vtk.vtkImageData()
myMesh.SetOrigin(0.,0.,0.)
myMesh.SetExtent(0,10,0,5,0,0)
myMesh.SetSpacing(1.,1.,0.)
# create the numpy colors for each cell
blue = np.array([15, 82, 186], dtype=np.ubyte) # 8 bits each [0, 255]
npColors = np.tile(blue, (myMesh.GetNumberOfCells(), 1))
# transform them to a vtkUnsignedCharArray
# organized as 50 tuples of 3
vtkColors = numpy_to_vtk(npColors, deep=1, array_type=vtk.VTK_UNSIGNED_CHAR)
# allocate the sets of 3 scalars to each cell
myMesh.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 3) # set 3 scalars per cell
myMesh.GetCellData().SetScalars(vtkColors) # returns 0, the index to which
# vtkColors is assigned
# Something... generate a proxy using servermanager??
ps.Show(myMesh?)
ps.Interact() # or ps.Render()
if __name__ == "__main__":
main()
从我可以得到的是,我必须首先应用一个几何过滤器,比如vtkImageDataGeometryFilter()
。但是这在paraview.vtk
中不存在,只通过直接导入vtk
模块
根据this VTK C++ SO question的说法,另一种选择是使用vtkMarchingSquares
无论如何,显然paraview.simple.Show
只接受代理对象作为输入。这就引出了一个问题:如何从过滤的vtkImageData
对象中创建代理?老实说,尽管阅读了文档,但我还没有完全掌握可视化管道是如何工作的
到目前为止,我只找到了通过Kitware examples in GitHub直接使用vtk
可视化VTK对象的方法,而没有使用Paraview的更高级功能
ProgrammableSource
是您想要使用的。见this example或this我设法使用
TrivialProducer
对象和方法.GetClientSideObject()
渲染它。这将ParaView连接到服务器端对象来源:the source code和the tip given by Mathieu Westphal来自ParaView支持
相关问题 更多 >
编程相关推荐