本文主要是介绍PVGeo Append Cell Centers,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
将单元中心作为属性添加到数据当中
"""
Append Cell Centers
~~~~~~~~~~~~~~~~~~~This example will demonstrate how to append a dataset's cell centers as a length 3 tuple array.This example demonstrates :class:`PVGeo.filters.AppendCellCenters`
"""import pyvista
from PVGeo.filters import AppendCellCenters###############################################################################
# Use an example mesh from pyvista
mesh = pyvista.RectilinearGrid("rectilinear.vtk")
print(mesh)###############################################################################
# Run the PVGeo algorithm
centers = AppendCellCenters().apply(mesh)
print(centers)###############################################################################
centers.plot()
RectilinearGrid (0x21462eca588)N Cells: 16146N Points: 18144X Bounds: -3.500e+02, 1.350e+03Y Bounds: -4.000e+02, 1.350e+03Z Bounds: -8.500e+02, 0.000e+00Dimensions: 27, 28, 24N Arrays: 1RectilinearGrid (0x21463fa2048)N Cells: 16146N Points: 18144X Bounds: -3.500e+02, 1.350e+03Y Bounds: -4.000e+02, 1.350e+03Z Bounds: -8.500e+02, 0.000e+00Dimensions: 27, 28, 24N Arrays: 2
Append Cell Centers 源码:
- 获取中心点
vtkCellCenters
- 将中心点转换为
numy
数组 - 将数组作为单元属性添加到源数据当中
所以从打印的结果可以看出N Arrays: 2
pdi = self.GetInputData(inInfo, 0, 0)pdo = self.GetOutputData(outInfo, 0)# Find cell centersfilt = vtk.vtkCellCenters()filt.SetInputDataObject(pdi)filt.Update()# I use the dataset adapter/numpy interface because its easycenters = dsa.WrapDataObject(filt.GetOutput()).Pointscenters = interface.convert_array(centers)centers.SetName('Cell Centers')# Copy input data and add cell centers as tuple arraypdo.DeepCopy(pdi)pdo.GetCellData().AddArray(centers)
这篇关于PVGeo Append Cell Centers的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!