gpt4 book ai didi

python - python 程序出错,可能与 vtk 有关。请帮助?

转载 作者:太空宇宙 更新时间:2023-11-03 18:08:45 24 4
gpt4 key购买 nike

我对 python 非常陌生,我正在运行这个程序,它给了我以下错误:

ERROR: In /builddir/build/BUILD/VTK6.0.0/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 715
vtkCompositeDataPipeline (0x2987f40): Input port 0 of algorithm vtkXMLStructuredGridWriter(0x2985d30) has 0 connections but is not optional.

这是完整的回溯

Traceback (most recent call last):
File "bvts.py", line 65, in <module>
writer.SetInput(grid)
AttributeError: SetInput

有人可以帮助我理解为什么会发生这种情况吗?

这是程序。预先感谢:)

import vtk
import math

nx = 4
ny = 4
nz = 40

def ijk_to_xyz(i,j,k):
z = 2*3.14159*k/(nz - 1.0)
x = math.sin(z) + (-1.0 + 2.0*i/(nx - 1.0))
y = -1.0 + 2.0*j/(ny - 1.0)
return (x,y,z)

def ijk_to_index(i,j,k):
return i*(ny*nz) + j*nz + k

grid = vtk.vtkStructuredGrid()
grid.SetDimensions(40,4,4)

pts = vtk.vtkPoints()
pts.SetNumberOfPoints(nx*ny*nz)

p = 0
for i in range(nx):
for j in range(ny):
for k in range(nz):
x,y,z = ijk_to_xyz(i,j,k)
pts.InsertPoint(p, x, y, z)
p = p + 1

grid.SetPoints(pts)

cdata = vtk.vtkFloatArray()
cdata.SetNumberOfComponents(1)
cdata.SetNumberOfTuples((nx-1)*(ny-1)*(nz-1))
cdata.SetName('cellData')

p = 0
for i in range(nx-1):
for j in range(ny-1):
for k in range(nz-1):
cdata.InsertValue(p, i+j+k)
p = p + 1

grid.GetCellData().SetScalars(cdata)

pdata = vtk.vtkFloatArray()
pdata.SetNumberOfComponents(1)
pdata.SetNumberOfTuples(nx*ny*nz)
pdata.SetName('pointData')

p = 0
for i in range(nx):
for j in range(ny):
for k in range(nz):
pdata.InsertValue(p, i+j+k)
p = p + 1

grid.GetPointData().SetScalars(pdata)

writer = vtk.vtkXMLStructuredGridWriter()
writer.SetFileName('grid.vts')
writer.SetInput(grid)
writer.Update()

最佳答案

SetInput 方法在 VTK6 上被替换,请参见 http://www.vtk.org/Wiki/VTK/VTK_6_Migration/Replacement_of_SetInput

你应该尝试这个而不是 SetInput:

writer->SetInputConnection(grid->GetProducerPort());

关于python - python 程序出错,可能与 vtk 有关。请帮助?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26369357/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com