Exemplo n.º 1
0
    def generateImage(self):
        myren = self.renderer
        xDim, yDim = imageDims
        myren.set_image_dims(xDim, yDim)
        myren.set_camera(self.camera)
        myren.set_transform(self.cball.getCumulativeViewTrans())
        myren.set_exposure_type(starsplatter.StarSplatter.ET_LOG_AUTO)
        myren.set_exposure_scale(0.5)
        myren.set_debug(debugFlag)

        print("The valid camera is %s" % self.camera)
        myren.clear_stars()
        for i in range(len(self.bunchList)):
            sb = self.bunchList[i]
            sbName = self.bunchNameList[i]
            #sys.stderr.write("#### bunch %s:\n"%sbName)
            #sb.dump(sys.stderr)
            myren.add_stars(sb)
        try:
            img = myren.render()
            black = starsplatter.rgbImage(img.xsize(), img.ysize())
            black.clear((0.0, 0.0, 0.0, 1.0))
            img.add_under(black)
            #img.save("test_over.png","png")
            return img
        except:
            print("Render failed!")
            return None
# For example, if positions are in kiloparsecs, velocities are in
# kilometers per second and times are in seconds, velscale would be
# 1.0/(30.86e15).
velscale = 1.0 / (30.86e15)

# alpha below is interpolated between these times
gas1_cropped.set_time(0.0)
gas2_cropped.set_time(1.0)
for i in range(10):
    alpha = float(i) / float(10)
    interpolatedGas = starsplatter.starbunch_interpolate(
        gas1_cropped, gas2_cropped, alpha, velscale)
    # But interpolated particles may not lie in the bounding box!
    # We need to crop them.
    cropBunchTo(interpolatedGas, "interpolatedGas", sliceBBox)

    # Render the particles with the given camera, and save the
    # image
    myren.add_stars(interpolatedGas)
    img = myren.render()
    black = starsplatter.rgbImage(img.xsize(), img.ysize())
    black.clear((0.0, 0.0, 0.0, 1.0))
    img.add_under(black)
    fname = "frame_%03d.png" % i
    img.save(fname, "png")
    print("wrote %s" % fname)

    # Clear the stars out of the renderer; we don't want them
    # to accumulate!
    myren.clear_stars()
# If this were not AUTO, we'd need to set bounds:
# myren.set_log_rescale_bounds(1.0e-5, 1.0)

# This splat type is appropriate for Gadget; it looks rather like
# a Gaussian splat with length scaled by 0.408 but has a sharp
# outer edge
myren.set_splat_type(starsplatter.StarSplatter.SPLAT_SPLINE)

# Uncomment this to see a histogram of pixel values
# myren.set_debug(1)

# Load particles into the renderer
for sb in [gas, disk, bulge, stars]:
    myren.add_stars(sb)

# black background image for compositing below
black = starsplatter.rgbImage(512, 512)
black.clear((0.0, 0.0, 0.0, 1.0))

# Render a series of images rotating the data about the world's Y
# axis.
for i in range(16):
    theta = 360.0 * (float(i) / 16.0)  # theta is in degrees
    rotTrans = starsplatter.gTransfm.rotation((0.0, 1.0, 0.0), theta)
    myren.set_transform(rotTrans)
    img = myren.render()
    img.add_under(black)
    fname = "frame_%03d.png" % i
    img.save(fname, "png")
    print("wrote %s" % fname)