【发布时间】:2019-03-17 17:25:48
【问题描述】:
我想读取 VTK 文件来做一些处理。 由于我必须在 Linux 和 Windows 上进行此处理,因此使用 Python3 更容易。 因此Linux和Windows都有Python3(3.6.0)及其模块VTK(8.1.2版本)。
我创建 MWE 来突出问题:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from vtk import *
import sys
import os
if __name__ == "__main__":
pathFile1 = os.getcwd()+'/Output_253.vtk'
print(pathFile1)
if os.path.exists(pathFile1):
# Creation of variables with the right type to read STRUCTURES_POINTS VTK files
readerVTK1 = vtk.vtkStructuredPointsReader()
# We put the content of our files in our variables
readerVTK1.SetFileName(pathFile1)
readerVTK1.Update()
# We read our variables datas, hence we have our VTK files datas in these variables
dataVTK1 = readerVTK1.GetOutput()
# We check if the dimensions are not zeros
if dataVTK1.GetDimensions()!=(0,0,0):
(dimX,dimY,dimZ) = dataVTK1.GetDimensions()
print((dimX,dimY,dimZ))
else :
print('dimensions are null... Problem !')
else:
print(' [WARN] ','the file you are looking for do not exist')
print(' pathFile1: ', pathFile1 )
脚本中引用的文件Output_253.vtk可以通过链接下载:here
然后,当我在 Linux 上运行此脚本时,我得到“(1000,1,1)”,它与文件头和我的其余处理一致。在 Windows 上我得到'dimensions are null... Problem !'。
我尝试在 Windows 上重新安装 VTK 模块,但我遇到了同样的问题。
这是一个错误吗?或者有什么办法可以解决吗?还是想法?
【问题讨论】:
标签: python python-3.x io vtk