我正在用Python编写Paraview(5.6.0)脚本,从VTU文件创建球形字形。脚本的相关部分如下所示。脚本完成后,将创建字形并使用适当的参数显示字形,但UI不会反映所有设置。
更具体地说,脚本显示sphGlyph.ScaleArray=['POINTS','diameter']
,并且视图正确显示了diameter
数组缩放的球体;但是,UI仍然显示No scale array
(在下图中)。如果单击“应用”,则会丢失diameter
设置,并且视图将更新为No scale array
。
在用户界面和视图中都应遵守某些其他设置,例如sphGlyph.ScaleFactor=1.
。
手动构建管道时,我看不出脚本和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()
编辑:这是@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)
答案 0 :(得分:1)
确保在创建字形之前调用UpdatePipeline。
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)