首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Paraview python 'Zoom to Box‘

Paraview python 'Zoom to Box‘
EN

Stack Overflow用户
提问于 2020-07-24 12:12:30
回答 1查看 298关注 0票数 0

我正在尝试制作一个脚本,它基本上可以执行'Zoom‘所做的工具。跟踪选项是没有问题的,因为它不跟踪相机的运动。

我在网上找到了这个,修复它的工作,但不断得到‘三维凸轮位置还没有东东’这是非常古老的,也许有新的选择来这样做?谢谢你的建议..。

我也可以尝试使用经典的相机命令,比如:

代码语言:javascript
复制
source=GetActiveSource()
#view = GetRenderView()
#view.CameraFocalPoint = [1, 0, 0]
#view.CameraViewAngle = 90
#view.CameraViewUp = [0, 0, 0]
#view.CameraPosition = [0, 0, 0]
#view.ViewSize = [1528, 542]
#view.ResetCamera()

但我不确定有什么办法可以放大吗?

修正了上面链接的脚本:

代码语言:javascript
复制
source=GetActiveSource()
rep = Show(source)

# run the pipeline here to get the bounds
Render()

bounds = source.GetDataInformation().GetBounds()
bounds_dx = bounds[1] - bounds[0]
bounds_dy = bounds[3] - bounds[2]
bounds_dz = bounds[5] - bounds[4]
bounds_cx = (bounds[0] + bounds[1])/2.0
bounds_cy = (bounds[2] + bounds[3])/2.0
bounds_cz = (bounds[4] + bounds[5])/2.0

if bounds_dx == 0:
# yz
    dimMode = 2
    aspect = bounds_dz/bounds_dy

elif bounds_dy == 0:
# xz
    dimMode = 1
    aspect = bounds_dz/bounds_dx

elif bounds_dz == 0:
# xy
    dimMode = 0
    aspect = bounds_dy/bounds_dx

else:
# 3d
    dimMode = 3
    aspect = 1.0  # TODO

lastObj = source

view = GetRenderView()
# view.ViewTime = steps[step] # unwanted
# view.UseOffscreenRenderingForScreenshots = 0 # obsolete

rep = Show(lastObj)
# rep.Representation = 'Outline' # unwanted
Render()

# position the camera
# far  = config.camFac
far = 1
near = 0

if dimMode == 0:
   # xy
    pos = max(bounds_dx, bounds_dy)
    camUp = [0.0, 1.0, 0.0]
    camPos = [bounds_cx, bounds_cy,  pos*far]
    camFoc = [bounds_cx, bounds_cy, -pos*near]

elif dimMode == 1:
   # xz
    pos = max(bounds_dx, bounds_dz)
    camUp = [0.0, 0.0, 1.0]
    camPos = [bounds_cx, -pos*far,  bounds_cz]
    camFoc = [bounds_cx,  pos*near, bounds_cz]

elif dimMode == 2:
   # yz
    pos = max(bounds_dy, bounds_dz)
    camUp = [0.0, 0.0, 1.0]
    camPos = [ pos*far, bounds_cy, bounds_cz]
    camFoc = [-pos*near, bounds_cy, bounds_cz]

else:
   # 3d
    print('3d cam position is yet TODO')
    camUp=[0,0,0]
    camPos=[1,0,0]
    camFoc=[0,0,0]

view = GetRenderView()
view.CameraViewUp = camUp
view.CameraPosition = camPos
view.CameraFocalPoint = camFoc
#view.UseOffscreenRenderingForScreenshots = 0 # obsolete
view.CenterAxesVisibility = 0

ren = Render()

#width = int(config.outputWidth)
#height = int(config.outputWidth*aspect)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-24 14:01:15

所以我就这样做了:

代码语言:javascript
复制
import sys
from paraview.simple import *

# Camera Position
# positional coordinates of the camera
# zoom is achieved by adjusting x, y, z values (moving camera closer/further away) depending on focal point
# e. g. [10,0,4] - camera will be looking at object from this coordinate
CamPos = sys.argv[1]

# Camera Focal Point
# point of interest for the camera
# the point will be in the center of the screen and camera will rotate towards him in its position
# e. g. [0,0,0] - camera will focus its center on this coordinate
CamFocPoint = sys.argv[2]

# Camera View Up
# defining which way is up in the view
# uses values <-1;1> for each vector component
# to achieve angled view, use same value '1' for two vector components
# e. g. [0,0,1] - achieves having highest z component at the top
CamViewUp = sys.argv[3]

# getting active view
camera = GetActiveCamera()

# setting based on user definition
camera.SetPosition(CamPos[0], CamPos[1], CamPos[2])
camera.SetFocalPoint(CamFocPoint[0], CamFocPoint[1], CamFocPoint[2])
camera.SetViewUp(CamViewUp[0], CamViewUp[1], CamViewUp[2])

# making sure angle is right
camera.SetViewAngle(30)

# rendering view
Render()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63073322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档