在Paraview中,如何更改状态的数据文件名,以从给定的数据文件和状态创建快照?

2024-09-28 21:51:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前能够在ParaView中正确地可视化一个.vtp文件中模拟的每个时间步,并为每个时间步打印一个屏幕截图。我希望成批处理,但是我希望为每一个都保持相同的状态(视图点、应用的过滤器等)。我已经将状态保存到了一个.psvm文件中,我试图编写一个python脚本,在pvbatch运行之后,它将(希望)打印屏幕截图。但是,不幸的是,它不起作用。我试图通过处理状态文件并进行搜索和替换来更改状态中的文件名,但它仍然不起作用。例如,它只绘制第一个数据输入,即使当前文件不同(altough GetSources()显示的源列表总是不断增加)。我在雪豹中使用ParaView 3.14.0。我确信这很简单,但是我被大量关于python和paraview的信息淹没了,没有提到这个特殊问题。请,请,任何建议都是非常欢迎的,我很抱歉,如果这已经被回答了(我看了谷歌,paraview邮件列表,和这里)。下面是我的脚本,也可以在http://pastebin.com/4xiLNrS0找到。此外,您可以在http://goo.gl/XjPpE中找到一些示例文件和状态。在

#!/bin/python
import glob, string, os, commands
from paraview.simple import *

#help(servermanager)
# vtp files are inside the local subdir DISPLAY
files = (commands.getoutput("ls DISPLAY/data-*.vtp | grep -v contacts")).split()

# process each file
for filename in files:
    fullfn = commands.getoutput("ls $PWD/" + filename)
    fn = filename.replace('DISPLAY/', '')
    #os.system("cp ../dem_git/addons/paraview_state.pvsm tmp.pvsm")
    os.system("cp ~/Desktop/state.pvsm tmp.pvsm")
    os.system("sed -i.bck 's/DATA.vtp/" + fullfn.replace('/','\/') + "/1' tmp.pvsm") # replace first intance with full path
    os.system("sed -i.bck 's/DATA.vtp/" + fullfn.replace('/','\/') + "/1' tmp.pvsm") # replace second intance with full path
    os.system("sed -i.bck 's/DATA.vtp/" + fn + "/1' tmp.pvsm") # replace third with just the filename path
    servermanager.LoadState("tmp.pvsm")
    pm = servermanager.ProxyManager()
    reader = pm.GetProxy('sources', fullfn)
    reader.FileName = fullfn
    reader.FileNameChanged()
    reader.UpdatePipeline()

    view = servermanager.GetRenderView()
    SetActiveView(view)
    view.StillRender()

    WriteImage(filename.replace(".vtp", ".png"))
    os.system("rm -f tmp.pvsm")
    os.system("rm -f tmp.pvsm.bck")

    Delete(reader)

Tags: 文件os状态filenamesystemtmpreplacecommands
1条回答
网友
1楼 · 发布于 2024-09-28 21:51:22

我知道这是一个老问题,但我最近也遇到了同样的问题,也找不到任何答案。您只需在Delete(reader)之后添加Delete(view),脚本才能正常工作。在

相关问题 更多 >