Source

yt.kivy / vr_widget.py

Full commit
from yt.mods import *

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

Builder.load_file('vr_widget.kv')

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")
        print self.children[0].children
        self.children[0].children[2].source = "temp.png"

class MyApp(App):
    def build(self):
        parent = FloatLayout()
        add_new = Button(text='Add New', pos_hint={'x':0.0, 'y':0.0},
                         width=96, height=96, size_hint=(None, None))
        parent.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)
            parent.add_widget(vr)
        new_widget(None)
        add_new.bind(on_release = new_widget)
        return parent

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__'):
    MyApp().run()