Stereo ray: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 18: Line 18:
  png big-left-image.png
  png big-left-image.png


== Script ==
== Example ==


A user on the PyMol list wrote a very nice little stereo ray tracing script.  Just copy this to a text file.  Then, in PyMol run
<syntaxhighlight lang="python">
run dirName/scriptName.pym
import stereo_ray
where '''dirName''' is where you put it, and '''scriptName''' is what you named the file then run one something like the example lines given:
stereo_ray output, 1000, 600
<source lang="python">
stereo_ray MyImages.png
EXAMPLE
</syntaxhighlight>
  stereo_ray output, 1000, 600
  stereo_ray secondImage.png
</source>
This will create to images, one with an L and one with an R suffix.  Just paste the two images next to each other (in some image editing program) and you're done.
This will create to images, one with an L and one with an R suffix.  Just paste the two images next to each other (in some image editing program) and you're done.


<source lang="python">
== Python Code ==
from pymol import cmd


def stereo_ray(output='', width='', height=''):
{{Template:PymolScriptRepoDownload|stereo_ray.py}}
  '''
DESCRIPTION
  "stereo_ray" ray-traces the current scene twice (separated by
  a six-degree rotation around the y axis)
  and saves a pair of images that can be combined in any image
  manipulation software to form a stereoimage.
  The first argument, the output file name, is mandatory.
  The second and third arguments, the size of the image, are not.
  If the width is given, the height will be calculated.


USAGE
  stereo_ray filename [, width [, height]]
EXAMPLE
  stereo_ray output, 1000, 600
  stereo_ray secondImage.png
  '''
  if output == '':
      print 'no output filename defined\n'
      print 'try: \'stereo_ray filename\''
      return -1
      # abort if no output file name given
  if width == '':
      width,height = cmd.get_session()['main'][0:2]
      # get dimensions from viewer if not given
  elif height == '':
      oldWidth,oldHeight = cmd.get_session()['main'][0:2]
      height = int(width)*oldHeight/oldWidth
      # calculate height from proportions of viewer if
      # only width is given
  cmd.ray(width, height, angle=-3)
  cmd.png(output+"_r")
  cmd.ray(width, height, angle=3)
  cmd.png(output+"_l")
cmd.extend('stereo_ray',stereo_ray)
</source>


[[Category:Script_Library|Stereo Ray]]
[[Category:Script_Library|Stereo Ray]]
[[Category:UI_Scripts]]
[[Category:UI_Scripts]]

Revision as of 18:06, 7 December 2011

Left Image
Right Image
Combined Images


Manually

To get a stereo diagram you need two images. The left image is rotated +3 degrees and the right image is rotated -3 degrees.

To obtain the left image, type:

ray angle=+3
png left-image.png

Likewise, to obtain the right image, type:

ray angle=-3
png right-image.png

You still use any other ray based modifications, such as:

ray 1600,1200,angle=+3
png big-left-image.png

Example

import stereo_ray 
stereo_ray output, 1000, 600
stereo_ray MyImages.png

This will create to images, one with an L and one with an R suffix. Just paste the two images next to each other (in some image editing program) and you're done.

Python Code

Download: stereo_ray.py
This code has been put under version control in the project Pymol-script-repo