我刚刚接触Python,我似乎找不到解决我的问题的方法,因为它看起来很简单。我在 paraview 上有一个几何图形,我将其保存为 vtk 文件,并尝试使用 python 来计算它的体积。
这是我正在使用的代码:
import vtk
reader = vtk.vtkPolyDataReader()
reader.SetFileName("C:\Users\Pauuu\Google Drive\2016-01\SURF\Sim Vascular\Modelos\apoE183 Day 14 3D\AAA.vtk")
reader.Update()
polydata = reader.GetOutput()
Mass = vtk.vtkMassProperties()
Mass.SetInputConnection(polydata.GetOutput())
Mass.Update()
print "Volume = ", Mass.GetVolume()
print "Surface = ", Mass.GetSurfaceArea()
我认为加载数据的方式可能有问题,并且我收到 AttributeError: GetOutput
。
你知道可能会发生什么或者我做错了什么吗? 预先感谢您。
最佳答案
根据您的 vtk
软件包版本,如果您的版本 <= 5
,您可能需要测试以下语法:
Mass.SetInput(polydata.GetOutput());
否则,实际语法是:
Mass.SetInputData(polydata.GetOutputPort());
PS:您可以通过运行以下命令来检查 python 包装的 vtk
版本:
import vtk
print vtk.vtkVersion.GetVTKSourceVersion()
关于python - 如何计算vtk文件的体积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38000412/