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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章