[Paraview] Python paraview.simple: Zoom To Data?
Burlen Loring
bloring at lbl.gov
Thu Mar 15 13:19:32 EDT 2012
> ResetCamera() still leaves a wide border around the object. Is it
> possible to rid of those, too?
Hey Nico,
I've had to fine tune the rendering in python scripts in the past and a
strategy that has worked passably for me where my data lies in an axis
aligned plane is to get the bounds of the object I want to focus on then
set the camera position, focal point , up, and view based on that. here
are some excerpts. I'm sure this could be improved, note I use a
variable called camFac to make adjustments. hope it helps.
rep = Show(bovr)
rep.Representation = 'Outline'
# run the pipeline here to get the bounds
Render()
bounds = bovr.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 = bovr
view = GetRenderView()
view.ViewTime = steps[step]
view.UseOffscreenRenderingForScreenshots = 0
rep = Show(lastObj)
rep.Representation = 'Outline'
Render()
# position the camera
far = config.camFac
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'
view = GetRenderView()
view.CameraViewUp = camUp
view.CameraPosition = camPos
view.CameraFocalPoint = camFoc
view.UseOffscreenRenderingForScreenshots = 0
view.CenterAxesVisibility = 0
ren = Render()
width = int(config.outputWidth)
height = int(config.outputWidth*aspect)
ren.ViewSize = [width, height]
outputFileName = '%s%06d.png'%(config.outputBaseFileName, step)
WriteImage(outputFileName)
On 03/15/2012 09:59 AM, Nico Schlömer wrote:
> I see.
> Well, ResetCamera() seems to deliver okay results only after Show()
> has been called -- OpenDataFile() doesn't suffice.
> Another misconception of mine was that CameraPosition and
> CameraFocalPoint could be set to anything. My data files contain flat
> surfaces in the x-y-plane, and ResetCamera() won't show anything if
> CameraPosition==[0,0,0] and CameraFocalPoint=[0,0,1]. This, again,
> makes sense. Setting CameraPosition to [0,0,1], for example, fixes
> this.
>
> ResetCamera() still leaves a wide border around the object. Is it
> possible to rid of those, too?
>
> Cheers,
> Nico
>
>
>
>
> On Thu, Mar 15, 2012 at 3:40 PM, Pat Marion<pat.marion at kitware.com> wrote:
>> ResetCamera() will position the camera so that all visible objects fit in
>> the view. You can control the view direction by setting the
>> view.CameraPosition and view.CameraFocalPoint properties. You don't have to
>> set the properties to any useful values, I usually set position to 0,0,0 and
>> CameraFocalPoint to the view direction, say [1,0,0] to look along the X
>> axis, then ResetCamera() will figure out where to put the camera while
>> keeping the view direction intact.
>>
>> Pat
>>
>>
>> On Thu, Mar 15, 2012 at 6:52 AM, Nico Schlömer<nico.schloemer at gmail.com>
>> wrote:
>>> Hi,
>>>
>>> the ParaView GUI has this nifty little button action "Zoom To Data"
>>> which displays the current object such that it somehow fits its
>>> window.
>>>
>>> Is there a similar thing for the Python paraview.simple module? I'm
>>> trying to get a hang on it with certain view options such as
>>>
>>> view = pv.GetRenderView()
>>> view.CameraFocalPoint = [0, 0, 0]
>>> view.CameraViewAngle = 90
>>> view.CameraPosition = [0, 0, 10]
>>> view.ViewSize = [600, 600]
>>>
>>> but what I would really like to have is to set the camera at a
>>> distance such that the object(s) just fit into the window they're
>>> displayed in.
>>>
>>> Any hints?
>>>
>>> Cheers,
>>> Nico
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the ParaView Wiki at:
>>> http://paraview.org/Wiki/ParaView
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.paraview.org/mailman/listinfo/paraview
>>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ParaView Wiki at: http://paraview.org/Wiki/ParaView
>
> Follow this link to subscribe/unsubscribe:
> http://www.paraview.org/mailman/listinfo/paraview
More information about the ParaView
mailing list