Commit d513d46b authored by David E. DeMarle's avatar David E. DeMarle

correct camera clip and provide initial camera position

parent b15e34ab
Pipeline #24099 passed with stage
......@@ -76,6 +76,30 @@ def record_visibility():
proxies.append(listElt)
return proxies
def max_bounds():
""" returns conservative min and max (over x y and z) bounds """
source_proxies = paraview.servermanager.ProxyManager().GetProxiesInGroup(
"sources")
minb = 0
maxb = -1
for key in source_proxies:
proxy = source_proxies[key]
bounds = proxy.GetDataInformation().GetBounds()
if bounds[0] < minb:
minb = bounds[0]
if bounds[2] < minb:
minb = bounds[2]
if bounds[4] < minb:
minb = bounds[4]
if bounds[1] > maxb:
maxb = bounds[1]
if bounds[3] > maxb:
maxb = bounds[3]
if bounds[5] > maxb:
maxb = bounds[5]
return minb, maxb
def restore_visibility(proxies):
"""at end of run, return to a previously recorded paraview state"""
view_proxy = paraview.simple.GetActiveView()
......@@ -356,9 +380,12 @@ def make_cinema_store(proxies,
cs.load()
tprop = cs.get_parameter('time')
tvalues = tprop['values']
eye_values = cs.metadata['camera_eye']
at_values = cs.metadata['camera_at']
up_values = cs.metadata['camera_up']
if 'camera_eye' in cs.metadata:
eye_values = cs.metadata['camera_eye']
if 'camera_at' in cs.metadata:
at_values = cs.metadata['camera_at']
if 'camera_up' in cs.metadata:
up_values = cs.metadata['camera_up']
#start with clean slate, other than time
cs = cinema_store.FileStore(ocsfname)
......@@ -447,7 +474,6 @@ def make_cinema_store(proxies,
poses = [] #holds phi, theta and roll angle tuples
matrices = [] #holds corresponding transform matrices
print "ASKED FOR", phis[0], thetas[0], rolls[0]
v = rolls[0]
rolls = []
if v < 2:
......@@ -484,6 +510,11 @@ def make_cinema_store(proxies,
poses.append((j,t,r))
j = j+360/(v*increment_Scale)
#default is one closest to 0,0,0
dist = math.sqrt((poses[0][0]*poses[0][0]) +
(poses[0][1]*poses[0][1]) +
(poses[0][2]*poses[0][2]))
default_mat = 0
for i in poses:
p,t,r = i
cP = math.cos(-math.pi*(p/180.0)) #phi is right to left
......@@ -500,8 +531,14 @@ def make_cinema_store(proxies,
m3 = MatrixMul(m2,rY)
m4 = MatrixMul(m3,rZ)
matrices.append(m4)
cs.add_parameter("pose", cinema_store.make_parameter('pos', matrices))
newdist = math.sqrt(p*p+t*t+r*r)
if newdist < dist:
default_mat = m4
dist = newdist
cs.add_parameter("pose",
cinema_store.make_parameter('pose', matrices,
default=default_mat))
fnp = fnp+"{pose}.png"
if specLevel == "A":
......@@ -542,6 +579,20 @@ def track_source(proxy, eye, at, up):
ret_at = [center[0], center[1], center[2]]
return ret_eye, ret_at, up
def project_to_at(eye, fp, cr):
"""project center of rotation onto focal point to keep gaze direction the same
while allowing both translate and zoom in and out to work"""
d_fp = [fp[0]-eye[0], fp[1]-eye[1], fp[2]-eye[2]]
d_cr = [cr[0]-eye[0], cr[1]-eye[1], cr[2]-eye[2]]
num = (d_fp[0]*d_cr[0] + d_fp[1]*d_cr[1] + d_fp[2]*d_cr[2])
den = (d_fp[0]*d_fp[0] + d_fp[1]*d_fp[1] + d_fp[2]*d_fp[2])
if den == 0:
return cr
rat = num/den
p_fp = [rat*d_fp[0], rat*d_fp[1], rat*d_fp[2]]
at = [p_fp[0]+eye[0], p_fp[1]+eye[1], p_fp[2]+eye[2]]
return at
def explore(cs, proxies, iSave=True, currentTime=None, userDefined = {},
specLevel = "A",
camType = 'phi-theta',
......@@ -640,8 +691,11 @@ def explore(cs, proxies, iSave=True, currentTime=None, userDefined = {},
eye_values = cs.metadata['camera_eye']
at_values = cs.metadata['camera_at']
up_values = cs.metadata['camera_up']
eye = [x for x in view_proxy.CameraPosition]
at = [x for x in view_proxy.CameraFocalPoint]
_fp = [x for x in view_proxy.CameraFocalPoint]
_cr = [x for x in view_proxy.CenterOfRotation]
at = project_to_at(eye, _fp, _cr)
up = [x for x in view_proxy.CameraViewUp]
times = paraview.simple.GetAnimationScene().TimeKeeper.TimestepValues
......@@ -668,6 +722,8 @@ def explore(cs, proxies, iSave=True, currentTime=None, userDefined = {},
else:
for t in times:
view_proxy.ViewTime=t
minbds, maxbds = max_bounds()
view_proxy.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds]
eye, at, up = track_source(tracked_source, eye, at, up)
eye_values.append([x for x in eye])
at_values.append([x for x in at])
......@@ -740,6 +796,9 @@ def export_scene(baseDirName, viewSelection, trackSelection, arraySelection):
initialView = paraview.simple.GetActiveView()
pvstate = record_visibility()
# a conservative global bounds for consistent z scaling
minbds, maxbds = max_bounds()
atLeastOneViewExported = False
for viewName, viewParams in viewSelection.iteritems():
......@@ -750,7 +809,6 @@ def export_scene(baseDirName, viewSelection, trackSelection, arraySelection):
continue
camType = "none"
print cinemaParams
if "camera" in cinemaParams and cinemaParams["camera"] != "none":
camType = cinemaParams["camera"]
if camType == "none":
......@@ -765,7 +823,9 @@ def export_scene(baseDirName, viewSelection, trackSelection, arraySelection):
view = paraview.simple.FindView(viewName)
paraview.simple.SetActiveView(view)
view.ViewSize = [viewParams[4], viewParams[5]]
paraview.simple.Render() # fully renders the scene (if not, some faces might be culled)
#paraview.simple.Render() # fully renders the scene (if not, some faces might be culled)
view.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds]
view.LockBounds = 1
#writeFreq = viewParams[1] # TODO where to get the timestamp in this case?
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment