Paraview:python脚本中的一些管道设置没有反映在UI中

2024-09-26 22:53:56 发布

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

我正在用Python编写Paraview(5.6.0)脚本,从VTU文件创建球形glyph。脚本的相关部分如下所示。脚本完成后,将创建glyph并使用适当的参数显示,但UI不会反映所有设置。你知道吗

更具体地说,脚本说sphGlyph.ScaleArray=['POINTS','diameter'],视图正确地显示了由diameter数组缩放的球体;但是UI仍然说No scale array(在下图中)。如果单击“应用”,我将丢失diameter设置,视图将更新为No scale array。你知道吗

其他一些设置,如sphGlyph.ScaleFactor=1.,在UI和视图中都得到了尊重。你知道吗

在手工构建管道时,我看不出脚本和Python跟踪之间有什么明显的区别。你知道吗

问题出在哪里?你知道吗

# ....
vtuFile="/tmp/burnt.vtu"
view=GetActiveViewOrCreate('RenderView')
# ...
sph=XMLUnstructuredGridReader(FileName=[vtuFile])
RenameSource(vtuFile,sph)
sphGlyph=Glyph(Input=sph,GlyphType='Sphere',GlyphMode='All Points')
sphGlyph.ScaleFactor=1.
sphGlyph.ScaleArray=['POINTS','diameter']    ### <---- SET HERE
sphGlyph.GlyphType.ThetaResolution=32
sphGlyph.GlyphType.PhiResolution=32
sphGlyphShow=Show(sphGlyph,view)
sphGlyphShow.Opacity=0.5
sphGlyphShow.BackfaceRepresentation='Surface'

view.Update()

state after loading paraview

编辑:这是@MatthieuWespthal建议的脚本(下载的cube.vtu无法正确设置Scale Array

from paraview.simple import *
cubevtu=XMLUnstructuredGridReader(FileName=['cube.vtu'])
glyph1 = Glyph(Input=cubevtu,GlyphType='Arrow')
glyph1.OrientationArray = ['POINTS', 'No orientation array']
glyph1.ScaleArray = ['POINTS', 'f1']
glyph1.ScaleFactor = 0.1
glyph1.GlyphTransform = 'Transform2'
renderView1 = GetActiveViewOrCreate('RenderView')
glyph1Display = Show(glyph1, renderView1)

enter image description here


Tags: no脚本view视图uiarraypointsdiameter
1条回答
网友
1楼 · 发布于 2024-09-26 22:53:56

确保在创建glyph之前调用updatePiline。

下面的代码非常适合于这个dataset。你知道吗

from paraview.simple import *

# find source
cubevtu = FindSource('cube.vtu')
cubevtu.UpdatePipeline()


# create a new 'Glyph'
glyph1 = Glyph(Input=cubevtu,
    GlyphType='Arrow')
glyph1.OrientationArray = ['POINTS', 'No orientation array']
glyph1.ScaleArray = ['POINTS', 'f1']
glyph1.ScaleFactor = 0.1 
glyph1.GlyphTransform = 'Transform2'

# Properties modified on glyph1

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

glyph1Display = Show(glyph1, renderView1)

相关问题 更多 >

    热门问题