全景 python 'Zoom to Box'
Paraview python 'Zoom to Box'
我正在尝试制作一个 脚本,它基本上可以完成工具 'Zoom to Box' 的功能。跟踪选项是不可能的,因为它不跟踪相机移动。
I've found this online,修复它可以工作,但不断出现“3d 凸轮位置尚未完成”这已经很老了,也许有新的选项可以做到这一点?感谢您的提示...
我也可以尝试使用经典的相机命令来做到这一点,例如:
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()
但我不确定是否有缩放的方法?
来自上面 the link 的固定脚本:
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)
所以我继续这样做:
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()
我正在尝试制作一个 脚本,它基本上可以完成工具 'Zoom to Box' 的功能。跟踪选项是不可能的,因为它不跟踪相机移动。
I've found this online,修复它可以工作,但不断出现“3d 凸轮位置尚未完成”这已经很老了,也许有新的选项可以做到这一点?感谢您的提示...
我也可以尝试使用经典的相机命令来做到这一点,例如:
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()
但我不确定是否有缩放的方法?
来自上面 the link 的固定脚本:
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)
所以我继续这样做:
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()