Discussion:
[Paraview] Python paraview.simple: Zoom To Data?
Nico Schlömer
2012-03-15 10:52:41 UTC
Permalink
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
Pat Marion
2012-03-15 14:40:08 UTC
Permalink
This post might be inappropriate. Click to display it.
Nico Schlömer
2012-03-15 16:59:44 UTC
Permalink
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
Post by Pat Marion
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>
Post by Nico Schlömer
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
http://paraview.org/Wiki/ParaView
http://www.paraview.org/mailman/listinfo/paraview
Burlen Loring
2012-03-15 17:19:32 UTC
Permalink
Post by Nico Schlömer
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)
Post by Nico Schlömer
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
Post by Pat Marion
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>
Post by Nico Schlömer
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
http://paraview.org/Wiki/ParaView
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
http://www.paraview.org/mailman/listinfo/paraview
Liam
2015-01-09 18:52:23 UTC
Permalink
Hey guys,

Just one more question. How do you define:

far = config.camFac

I cannot find in the code neither config nor camFac variable, so anybody
could explain me how to compute far variable?

This code has helped me so much.

Yhanks in advance,

Liam


_______________________________________________
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

Search the list archives at: http://markmail.org/search/?q=ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview
Burlen Loring
2015-01-11 19:48:29 UTC
Permalink
Hi Liam,
Just one more question. How do you define: far = config.camFac
your question is a follow up to the script about automatically
positioning the camera when viewing 2d axis aligned image data from thread
http://comments.gmane.org/gmane.comp.science.paraview.user/15091
in that post config.camFac was a variable for used for fine tuning the
camera position. It could be 1.0 to go with default, less than 1.0 to
move camera closer or greater than 1.0 to move the camera away.

Since I originally posted the script I had made improvements to it which
I'll paste below. To remind of the context of the script below: I have
2d axis aligned image data in the object named bovr. the script below
automatically positions the camera and sizes the view according to the
aspect ratio of the data. "config_camZoom" is a fine tuning parameter,
and is documented here
<http://www.vtk.org/doc/nightly/html/classvtkCamera.html#a64512cc87555856a84f6c7d00abe0da9>.
1.0 is the value to start with.

hope this helps
Burlen

# run the pipeline here to get the bounds
rep = Show(bovr)
rep.Representation = 'Outline'
Render()

bounds = bovr.GetDataInformation().GetBounds()
bounds_dx = fabs(bounds[1] - bounds[0])
bounds_dy = fabs(bounds[3] - bounds[2])
bounds_dz = fabs(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

# position the camera
camFar=1.0

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

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

elif (dimMode == 2):
# yz
camUp = [0.0, 0.0, 1.0]
camDir = 0
pos = max(bounds_dy, bounds_dz)
camPos = [ pos*camFar, bounds_cy, bounds_cz]
camFoc = [bounds_cx, bounds_cy, bounds_cz]

else:
# 3d
print '3d cam position is yet TODO'

# configure the view
width = 1024
height = int(width*aspect)

view = GetRenderView()
view.CameraViewUp = camUp
view.CameraPosition = camPos
view.CameraFocalPoint = camFoc
view.UseOffscreenRenderingForScreenshots = 0
view.CenterAxesVisibility = 0
view.OrientationAxesVisibility = 0
view.ViewSize = [width, height]
Render()
view.ResetCamera()

# for fine tuning
config_camZoom = 1.0
cam = GetActiveCamera()
cam.Zoom(config_camZoom)
Hey guys,
far = config.camFac
I cannot find in the code neither config nor camFac variable, so anybody
could explain me how to compute far variable?
This code has helped me so much.
Yhanks in advance,
Liam
_______________________________________________
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
Search the list archives at: http://markmail.org/search/?q=ParaView
http://public.kitware.com/mailman/listinfo/paraview
Loading...