Source

yt.kivy / vr_widget.py

Full commit
from yt.mods import *
import yt.utilities.amr_utils as au
import cStringIO
from kivy.lang import Builder
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.slider import Slider
from kivy.uix.image import Image
from kivy.app import App
from kivy.uix.scatter import Scatter
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty

class VolumeRendering(Scatter):
    g_width = ObjectProperty(0.01, allownone=False)
    g_center = ObjectProperty(0.5, allownone=False)
    cam = ObjectProperty(None, allowname = True)
    def render(self, *args, **kwargs):
        tf = ColorTransferFunction((mi, ma))
        v = (ma - mi) * self.g_center + mi
        w = self.g_width / 10
        print "Sampling", v, w
        tf.sample_colormap(v, w)
        self.cam.transfer_function = tf
        self.cam.snapshot("temp.png")
        self.children[0].children[2].source = ""
        self.children[0].children[2].source = "temp.png"

class YTApp(App):
    def build(self):
        root=self.root
        add_new = Button(text='Add New', pos_hint={'x':0.0, 'y':0.0},
                         width=96, height=96, size_hint=(None, None))
        root.add_widget(add_new)
        def new_widget(obj):
            cam = pf.h.camera([0.5, 0.5, 0.5], [1.0, 1.0, 1.0],
                              0.25, (512, 512), None)
            vr = VolumeRendering(cam = cam)
            root.add_widget(vr)
        new_widget(None)
        add_new.bind(on_release = new_widget)

pf = load("/home/mturk/data/JHK-DD0030/galaxy0030")
dd = pf.h.all_data()
mi, ma = na.log10(dd.quantities["Extrema"]("Density")[0])

if __name__ in ('__android__', '__main__'):
    YTApp().run()