[英]Python: How to avoid the loops in building this matrix and to calculate the determinant of it faster?
[英]How to avoid loops when building a vtkUnstructuredGrid with python?
我想使用 vtk python 模塊構建一個vtkUnstructuredGrid
對象。
我發現的每個代碼片段都使用像InsertNextPoint()
和InsertNextCell()
這樣的方法,它們需要像這里這樣的點和單元格上的循環。
有一個名為tvtk的 vtk python 模塊的覆蓋層,它實現了一些有趣的東西:
ug = tvtk.UnstructuredGrid(nodes)
ug.set_cells(cell_type, cells)
其中nodes
是包含節點坐標的二維 numpy 數組, cells
是包含元素連接性的二維 numpy 數組(根據 cell_type)。 tvtk
比更Python的vtk
模塊,但不幸的是沒有流行,是在集群上更很少使用。
我的問題是:使用vtk
python 模塊,有什么方法可以像 tvtk 一樣使用 numpy 數組設置 vtkUnstructuredGrid 從而避免昂貴的循環?
您可以查看vtk_numpy 。 例如:
import vtk
from vtk.util.numpy_support import numpy_to_vtk, vtk_to_numpy
varr = numpy_to_vtk(myarray.ravel(order='F'), deep=True, array_type=vtk.VTK_FLOAT)
varr.SetName('myarray')
ugrid.GetPointData().SetScalars(varr)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.