[yt-users] volume rendering handedness

Michael Zingale michael.zingale at stonybrook.edu
Tue Jul 22 09:00:04 PDT 2014


I've been having trouble understanding the parameters that specify the
orientation of the camera for volume rendering.  To help, I made a test
dataset.  On [-1,1]^3, there is a sphere at the origin, a single cube on
the +x axis, two cubes on the +y axis, and three cubes on the +z axis.
 When I do a simple volume-render, I see this:

http://bender.astro.sunysb.edu/random/yt-test.png

Note that it looks left-handed.

I've attached my script.  There are a few hacks that I needed to do that I
don't completely understand.  In particular, if I turn on the
coordinate_vectors, the image is blank.  I've seen this a lot.  Also, I had
to make the north vector negative of what I would think.

Mike

--

#!/usr/bin/env python

import matplotlib
matplotlib.use('agg')

# this example comes from
# http://yt-project.org/doc/visualizing/volume_rendering.html

import math
import sys
import pylab

from yt.mods import *
import yt.visualization.volume_rendering.api as vr

def doit(plotfile):

    ds = load(plotfile)

    cm = "gist_rainbow"


    field = ('gas', 'density')
    use_log = False
    vals = [0.1, 1]
    sigma = 0.1

    dd = ds.h.all_data()

    ds.field_info[field].take_log = use_log


    mi = min(vals)
    ma = max(vals)

    if use_log:
        mi, ma = np.log10(mi), np.log10(ma)


    # Instantiate the ColorTransferfunction.
    tf =  vr.ColorTransferFunction((mi, ma))

    # Set up the camera parameters: center, looking direction, width,
resolution
    c = np.array([0.0, 0.0, 0.0])
    L = np.array([1.0, 1.0, 1.0])
    L = np.array([1.0, 1.0, 1.2])
    W = 1.5*ds.domain_width
    N = 720

    north=[0.0,0.0,-1.0]

    for v in vals:
        if (use_log):
            tf.sample_colormap(math.log10(v), sigma**2, colormap=cm) #,
alpha=0.2)
        else:
            tf.sample_colormap(v, sigma**2, colormap=cm) #, alpha=0.2)


    # alternate attempt
    ds.periodicity = (True, True, True)

    # Create a camera object
    cam = vr.Camera(c, L, W, N, transfer_function=tf, ds=ds,
                    no_ghost=False, #data_source=reg,
                    north_vector=north,
                    fields = [field], log_fields = [use_log])

    #cam.rotate(3.0*np.pi/2., rot_vector=rot_vector)


    # make an image
    im = cam.snapshot()


    # add an axes triad -- note if we do this, we HAVE to do draw
    # domain, otherwise the image is blank (likely a bug)
    #cam.draw_coordinate_vectors(im)

    # add the domain box to the image:
    nim = cam.draw_domain(im)

    # increase the contrast -- for some reason, the enhance default
    # to save_annotated doesn't do the trick (likely a bug)
    max_val = im[:,:,:3].std() * 4.0
    nim[:,:,:3] /= max_val

    f = pylab.figure()

    pylab.text(0.2, 0.85, "{:.3g} s".format(float(ds.current_time.d)),
               transform=f.transFigure, color="white")

    cam._render_figure = f

    # save annotated -- this added the transfer function values,
    # but this messes up our image size defined above
    cam.save_annotated("yt-test.png", nim,
                       dpi=145, clear_fig=False)



if __name__ == "__main__":

    # Choose a field
    plotfile = ""


    try: plotfile = sys.argv[1]
    except: sys.exit("ERROR: no plotfile specified")

    doit(plotfile)



-- 
Michael Zingale
Associate Professor

Dept. of Physics & Astronomy • Stony Brook University • Stony Brook, NY
11794-3800
*phone*:  631-632-8225
*e-mail*: Michael.Zingale at stonybrook.edu
*web*: http://www.astro.sunysb.edu/mzingale
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20140722/87d51d94/attachment.htm>


More information about the yt-users mailing list