[Paraview] Python paraview.simple: Zoom To Data?

Burlen Loring burlen.loring at gmail.com
Sun Jan 11 14:48:29 EST 2015


Hi Liam,
> On 1/9/2015 10:52 AM, Liam wrote:
>> 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)

On 1/9/2015 10:52 AM, Liam wrote:
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20150111/b1a1f74c/attachment.html>


More information about the ParaView mailing list