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:      16146
  N Points:     18144
  X Bounds:     -3.500e+02, 1.350e+03
  Y Bounds:     -4.000e+02, 1.350e+03
  Z Bounds:     -8.500e+02, 0.000e+00
  Dimensions:   27, 28, 24
  N Arrays:     1

RectilinearGrid (0x21463fa2048)
  N Cells:      16146
  N Points:     18144
  X Bounds:     -3.500e+02, 1.350e+03
  Y Bounds:     -4.000e+02, 1.350e+03
  Z Bounds:     -8.500e+02, 0.000e+00
  Dimensions:   27, 28, 24
  N Arrays:     2

Append Cell Centers 源码:

  1. 获取中心点 vtkCellCenters
  2. 将中心点转换为numy数组
  3. 将数组作为单元属性添加到源数据当中
    所以从打印的结果可以看出N Arrays: 2
		pdi = self.GetInputData(inInfo, 0, 0)
        pdo = self.GetOutputData(outInfo, 0)
        # Find cell centers
        filt = vtk.vtkCellCenters()
        filt.SetInputDataObject(pdi)
        filt.Update()

        # I use the dataset adapter/numpy interface because its easy
        centers = dsa.WrapDataObject(filt.GetOutput()).Points
        centers = interface.convert_array(centers)
        centers.SetName('Cell Centers')

        # Copy input data and add cell centers as tuple array
        pdo.DeepCopy(pdi)
        pdo.GetCellData().AddArray(centers)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值