シェルを法線方向に押し出し

VTK Multi-block Dataset中のシェル要素(VTK Unstructured Grid形式)を抽出し、要素値として定義されているシェル厚さ‘Thickness’に応じて押し出す。変数resolutionを変更することで、押し出し方向の層数を変更できる。現状では三角形1次要素および四角形1次要素の押し出しのみに対応している。

本スクリプト中では、VTKに用意されている各種フィルタを直接呼び出している。

動作確認バージョン

ParaView 4.2.0

Output Data Set Type

vtkUnstructuredGrid

Script

import vtk
resolution = 1

pdi = self.GetInput().GetBlock(0)

dss = vtk.vtkDataSetSurfaceFilter() # not included in paraview.vtk
dss.SetInputData(pdi)
dss.Update()

c2p = vtkCellDataToPointData()
c2p.SetInputData(dss.GetOutput())
c2p.Update()

pdn = vtkPolyDataNormals()
pdn.SetInputData(c2p.GetOutput())
pdn.Update()

pdo = self.GetOutput()

pts = vtk.vtkPoints()
np = pdi.GetNumberOfPoints()
for i in range(resolution + 1):
    for j in range(np):
        x, y, z = pdi.GetPoint(j)
        nx = pdn.GetOutput().GetPointData().GetArray('Normals').GetValue(i * 3) * pdn.GetOutput().GetPointData().GetArray('Thickness').GetValue(i * 3)
        ny = pdn.GetOutput().GetPointData().GetArray('Normals').GetValue(i * 3 + 1) * pdn.GetOutput().GetPointData().GetArray('Thickness').GetValue(i * 3 + 1)
        nz = pdn.GetOutput().GetPointData().GetArray('Normals').GetValue(i * 3 + 2) * pdn.GetOutput().GetPointData().GetArray('Thickness').GetValue(i * 3 + 2)
        pts.InsertNextPoint(x + nx * i / resolution, y + ny * i / resolution, z + nz * i / resolution)
pdo.SetPoints(pts)

nc = pdi.GetNumberOfCells()
pdo.Allocate(nc, 0)
for i in range(resolution):
    for j in range(nc):
        ids = vtk.vtkIdList()
        cell = pdi.GetCell(j)
        cnp = cell.GetNumberOfPoints()
        for k in range(cnp):
            ids.InsertId(k, np * i + cell.GetPointId(k))
        for k in range(cnp):
            ids.InsertId(k + cnp, np * (i + 1) + cell.GetPointId(k))
        if cnp == 3:
            pdo.InsertNextCell(13, ids)
        elif cnp == 4:
            pdo.InsertNextCell(12, ids)

arr = vtk.vtkDoubleArray()
pdo.GetCellData().AddArray(arr)
arr.SetNumberOfComponents(1)
arr.SetName('scalar')
for i in range(pdo.GetNumberOfCells()):
    arr.InsertNextValue(i)

arr = vtk.vtkDoubleArray()
pdo.GetPointData().AddArray(arr)
arr.SetNumberOfComponents(1)
arr.SetName('scalar_node')
for i in range(pdo.GetNumberOfPoints()):
    arr.InsertNextValue(i)

numPntArr = pdn.GetOutput().GetPointData().GetNumberOfArrays()
for i in range(numPntArr):
    arr_pnt = vtk.vtkDoubleArray()
    pdo.GetPointData().AddArray(arr_pnt)
    arr_val = pdn.GetOutput().GetPointData().GetArray(i)
    numComp = arr_val.GetNumberOfComponents()
    arr_pnt.SetNumberOfComponents(numComp)
    arr_pnt.SetName(pdn.GetOutput().GetPointData().GetArrayName(i))
    for r in range(resolution + 1):
        for j in range(pdn.GetOutput().GetNumberOfPoints()):
            for nc in range(numComp):
                arr_pnt.InsertNextValue(arr_val.GetValue(j * numComp + nc))
タグ: , , , , , ,

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*