[Yt-svn] commit/yt: MatthewTurk: Adding some support for the grid viewer. Requires $YT_DEST/src/PhiloGL to

Bitbucket commits-noreply at bitbucket.org
Fri Apr 15 13:57:14 PDT 2011


1 new changeset in yt:

http://bitbucket.org/yt_analysis/yt/changeset/4f93fc75fae6/
changeset:   r4141:4f93fc75fae6
branch:      yt
user:        MatthewTurk
date:        2011-04-15 22:57:01
summary:     Adding some support for the grid viewer.  Requires $YT_DEST/src/PhiloGL to
exist to work.  Also doesn't quite work, and I don't know why.
affected #:  5 files (3.2 KB)

--- a/yt/gui/reason/extdirect_repl.py	Fri Apr 15 16:12:12 2011 -0400
+++ b/yt/gui/reason/extdirect_repl.py	Fri Apr 15 16:57:01 2011 -0400
@@ -99,6 +99,7 @@
         # First we do the standard initialization
         self.extjs_path = os.path.join(base_extjs_path, "ext-resources")
         self.extjs_theme_path = os.path.join(base_extjs_path, "ext-theme")
+        self.philogl_path = os.path.join(base_extjs_path, "PhiloGL")
         ProgrammaticREPL.__init__(self, locals)
         # Now, since we want to only preroute functions we know about, and
         # since they have different arguments, and most of all because we only
@@ -109,6 +110,7 @@
                               _help_html = ("/help.html", "GET"),
                               _myapi = ("/resources/ext-repl-api.js", "GET"),
                               _resources = ("/resources/:path#.+#", "GET"),
+                              _philogl = ("/philogl/:path#.+#", "GET"),
                               _js = ("/js/:path#.+#", "GET"),
                               _images = ("/images/:path#.+#", "GET"),
                               _theme = ("/theme/:path#.+#", "GET"),
@@ -128,7 +130,6 @@
         self.execute("from yt.mods import *")
         self.execute("from yt.data_objects.static_output import _cached_pfs", hide = True)
         self.locals['load_script'] = ext_load_script
-        self.locals['_widgets'] = {}
         self._setup_logging_handlers()
 
         # Setup our heartbeat
@@ -185,6 +186,13 @@
             return
         return open(pp).read()
 
+    def _philogl(self, path):
+        pp = os.path.join(self.philogl_path, path)
+        if not os.path.exists(pp):
+            response.status = 404
+            return
+        return open(pp).read()
+
     def _theme(self, path):
         pp = os.path.join(self.extjs_theme_path, path)
         if not os.path.exists(pp):
@@ -375,7 +383,12 @@
 
     @lockit
     def create_grid_viewer(self, pfname):
-        pf = self.locals[pfname]
+        funccall = """
+        _tpf = %(pfname)s
+        """ % dict(pfname = pfname)
+        funccall = "\n".join((line.strip() for line in funccall.splitlines()))
+        self.execute(funccall, hide = True)
+        pf = self.locals['_tpf']
         corners = pf.h.grid_corners
         vertices = []
 
@@ -389,7 +402,16 @@
                 ci = trans[c]
                 vertices.append(corners[ci,:,g])
         vertices = na.concatenate(vertices).tolist()
-        return {'vertices': vertices}
+        uu = str(uuid.uuid1()).replace("-","_")
+        varname = "gv_%s" % (uu)
+        payload = {'type': 'widget',
+                   'widget_type': 'grid_viewer',
+                   'varname': varname, # Is just "None"
+                   'data': dict(n_vertices = len(vertices),
+                                vertex_positions = vertices)
+                  }
+        self.execute("%s = None\n" % (varname), hide=True)
+        self.payload_handler.add_payload(payload)
 
 class ExtDirectParameterFileList(BottleDirectRouter):
     my_name = "ExtDirectParameterFileList"


--- a/yt/gui/reason/html/index.html	Fri Apr 15 16:12:12 2011 -0400
+++ b/yt/gui/reason/html/index.html	Fri Apr 15 16:57:01 2011 -0400
@@ -75,6 +75,7 @@
     <!-- LIBS --><script type="text/javascript" src="resources/adapter/ext/ext-base.js"></script><script type="text/javascript" src="resources/ext-all.js"></script>
+    <script type="text/javascript" src="philogl/build/PhiloGL.js"></script><!-- INTERACTIVE --><script type="text/javascript" src="resources/ext-repl-api.js"></script>
@@ -91,6 +92,30 @@
 
     <!-- THE PLOT WINDOW FUNCTIONS --><script type="text/javascript" src="js/widget_plotwindow.js"></script>
+
+    <!-- THE GRID VIEWER FUNCTIONS -->
+    <script type="text/javascript" src="js/widget_gridviewer.js"></script>
+    <script id="gv-shader-fs" type="x-shader/x-fragment">
+      #ifdef GL_ES
+      precision highp float;
+      #endif
+
+      void main(void) {
+        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
+      }
+    </script>
+
+    <script id="gv-shader-vs" type="x-shader/x-vertex">
+      attribute vec3 aVertexPosition;
+
+      uniform mat4 uMVMatrix;
+      uniform mat4 uPMatrix;
+
+      void main(void) {
+        gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
+      }
+    </script>
+
 </head><body><!-- use class="x-hide-display" to prevent a brief flicker of the content -->


--- a/yt/gui/reason/html/js/functions.js	Fri Apr 15 16:12:12 2011 -0400
+++ b/yt/gui/reason/html/js/functions.js	Fri Apr 15 16:57:01 2011 -0400
@@ -160,6 +160,15 @@
     return CellPanel;
 }
 
+function getGridViewerHandler(node){
+function gridViewerHandler(item, pressed){
+    yt_rpc.ExtDirectREPL.create_grid_viewer(
+        {pfname:node.attributes.objdata.varname},
+        handle_result);
+}
+return gridViewerHandler;
+}
+
 function getSliceHandler(node){
 function sliceHandler(item,pressed){
     var win = new Ext.Window({


--- a/yt/gui/reason/html/js/reason.js	Fri Apr 15 16:12:12 2011 -0400
+++ b/yt/gui/reason/html/js/reason.js	Fri Apr 15 16:57:01 2011 -0400
@@ -178,6 +178,9 @@
                         var rightClickMenu = new Ext.menu.Menu({
                             items: [
                                 {
+                                    text: 'View Grids',
+                                    handler: getGridViewerHandler(node),
+                                }, {
                                     text: 'Open slice',
                                     handler: getSliceHandler(node),
                                 }, {


--- a/yt/gui/reason/html/js/widget_gridviewer.js	Fri Apr 15 16:12:12 2011 -0400
+++ b/yt/gui/reason/html/js/widget_gridviewer.js	Fri Apr 15 16:57:01 2011 -0400
@@ -1,12 +1,8 @@
 /**********************************************************************
 The Plot Window Widget
 
-Author: Cameron Hummels <chummels at gmail.com>
-Affiliation: Columbia
-Author: Jeffrey S. Oishi <jsoishi at gmail.com>
-Affiliation: KIPAC/SLAC/Stanford
-Author: Britton Smith <brittonsmith at gmail.com>
-Affiliation: MSU
+Author: Samuel Skillman <samskillman at gmail.com>
+Affiliation: University of Colorado at Boulder
 Author: Matthew Turk <matthewturk at gmail.com>
 Affiliation: NSF / Columbia
 Homepage: http://yt.enzotools.org/
@@ -31,173 +27,175 @@
 
 
 
-var WidgetPlotWindow = function(python_varname, widget_data) {
+var WidgetGridViewer = function(python_varname, widget_data) {
     this.id = python_varname;
     this.widget_data = widget_data;
+    examine = "canvas_" + python_varname;
+    var GridViewerStart = function() {
+        this.curX = 0;
+        this.curY = 0;
+        this.dist = 0;
+        function updateBasedOnOffset(camera, offset){
+        camera.position.x = camera.target.x + offset.x;
+        camera.position.y = camera.target.y + offset.y;
+        camera.position.z = camera.target.z + offset.z;
+        }
+        function camGetOffset(camera){
+        return PhiloGL.Vec3.sub(camera.position, camera.target)
+            }
+        PhiloGL('canvas_' + python_varname, {
+            camera: {
+            position: {
+                x: 0.5, y: 0.5, z: 5
+                },
+                target: {
+                x: 0.5, y: 0.5, z: 0.5
+                },
+                },
+            program: {
+            from: 'ids',
+                vs: 'gv-shader-vs',
+                fs: 'gv-shader-fs'
+                },    
+            events: {
+            onDragStart: function(e) {
+                pos = {
+                x: e.x,
+                y: e.y
+                };
+                this.curX = e.x;
+                this.curY = e.y;
+                this.dist = camGetOffset(this.camera).norm();
+            },
+                onDragEnd: function(e) {
+                pos = {
+                x: e.x,
+                y: e.y
+                };
+            },
+                onDragMove: function(e) {
+                var c = this.camera;
+                var off = camGetOffset(c);
+                // Get Horizontal vector
+                var horiz = PhiloGL.Vec3.cross(c.up, 
+                               camGetOffset(c))
+                horiz.$scale(1./horiz.norm());
+
+                if (e.event.button == 0){ // Rotation
+                // Do vertical rotation about horizontal vector
+                var vert_rot = new PhiloGL.Mat4();
+                vert_rot.id();
+                vert_rot.$rotateAxis((e.y-this.curY)/100., horiz);
+                PhiloGL.Mat4.$mulVec3(vert_rot, off);
+                PhiloGL.Mat4.$mulVec3(vert_rot, c.up);
+                c.up.$scale(1./c.up.norm());
+
+                // Do horizontal rotation about up vector
+                var side_rot = new PhiloGL.Mat4();
+                side_rot.id();
+                side_rot.$rotateAxis(-(e.x-this.curX)/100., c.up);
+                side_rot.$mulVec3(off);
+        
+                // Update current positions
+                this.curX = e.x;
+                this.curY = e.y;
+                this.dist = off.norm();
+                updateBasedOnOffset(c, off);
+                c.update();
+                } else if (e.event.button = 2){ // Right click - transpose
+                var move_up = c.up.scale(-(e.y-this.curY)/200.);
+                var move_over = horiz.scale(-(e.x-this.curX)/200.);
+                c.position.$add(move_up);
+                c.position.$add(move_over);
+                c.target.$add(move_up);
+                c.target.$add(move_over);
+                // Update current positions
+                this.curX = e.x;
+                this.curY = e.y;
+                c.update();
+                }
+    
+            },
+                onMouseWheel: function(e){
+                e.stop();
+                var offset = PhiloGL.Vec3.scale(camGetOffset(this.camera),
+                                1.0 - e.wheel/10.);
+                updateBasedOnOffset(this.camera, offset);
+                this.camera.update();
+            }
+            },
+            onError: function() {
+            alert("An error ocurred while loading the application");
+            },
+            onLoad: function(app) {
+            var gl = app.gl,
+                canvas = app.canvas,
+                program = app.program,
+                scene = app.scene,
+                camera = app.camera;
+    
+            gl.viewport(0, 0, canvas.width, canvas.height);
+            gl.clearColor(0, 0, 0, 1);
+            gl.clearDepth(1);
+            gl.enable(gl.DEPTH_TEST);
+            gl.depthFunc(gl.LEQUAL);
+
+            program.setBuffers({
+                'shapeset': {
+                    attribute: 'aVertexPosition',
+                    value: new Float32Array(widget_data['vertex_positions']),
+                    size: 3
+                    },
+    
+                    });
+            camera.modelView.id();
+            draw()
+    
+                setInterval(draw, 100/60);
+            //Draw the scene
+            function draw() {
+                gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+                //Draw Triangle
+                program.setUniform('uMVMatrix', camera.modelView);
+                program.setUniform('uPMatrix', camera.projection);
+                program.setBuffer('triangle');
+                gl.drawArrays(gl.LINES, 0, widget_data['n_vertices']);        
+                examine = camera
+                }
+            }
+        });  
+    }        
 
     viewport.get("center-panel").add(
         {
             xtype: 'panel',
-		id: "pw_" + this.id,
-		title: "WebGL Grid Viewer",
-		iconCls: 'graph',
-		autoScroll: true,
-		layout:'absolute',
-		closable: true,
-		
-		function webGLStart() {
-		    this.curX = 0;
-		    this.curY = 0;
-		    this.dist = 0;
-		    function updateBasedOnOffset(camera, offset){
-			camera.position.x = camera.target.x + offset.x;
-			camera.position.y = camera.target.y + offset.y;
-			camera.position.z = camera.target.z + offset.z;
-		    }
-		    function camGetOffset(camera){
-			return PhiloGL.Vec3.sub(camera.position, camera.target)
-			    }
-		    PhiloGL('lesson01-canvas', {
-			    camera: {
-				position: {
-				    x: 0.5, y: 0.5, z: 5
-					},
-				    target: {
-				    x: 0.5, y: 0.5, z: 0.5
-					},
-				    },
-				program: {
-				from: 'ids',
-				    vs: 'shader-vs',
-				    fs: 'shader-fs'
-				    },	
-				events: {
-				onDragStart: function(e) {
-				    pos = {
-					x: e.x,
-					y: e.y
-				    };
-				    this.curX = e.x;
-				    this.curY = e.y;
-				    this.dist = camGetOffset(this.camera).norm();
-				},
-				    onDragEnd: function(e) {
-				    pos = {
-					x: e.x,
-					y: e.y
-				    };
-				},
-				    onDragMove: function(e) {
-				    var c = this.camera;
-				    var off = camGetOffset(c);
-				    // Get Horizontal vector
-				    var horiz = PhiloGL.Vec3.cross(c.up, 
-								   camGetOffset(c))
-					horiz.$scale(1./horiz.norm());
-
-				    if (e.event.button == 0){ // Rotation
-					// Do vertical rotation about horizontal vector
-					var vert_rot = new PhiloGL.Mat4();
-					vert_rot.id();
-					vert_rot.$rotateAxis((e.y-this.curY)/100., horiz);
-					PhiloGL.Mat4.$mulVec3(vert_rot, off);
-					PhiloGL.Mat4.$mulVec3(vert_rot, c.up);
-					c.up.$scale(1./c.up.norm());
-
-					// Do horizontal rotation about up vector
-					var side_rot = new PhiloGL.Mat4();
-					side_rot.id();
-					side_rot.$rotateAxis(-(e.x-this.curX)/100., c.up);
-					side_rot.$mulVec3(off);
-		    
-					// Update current positions
-					this.curX = e.x;
-					this.curY = e.y;
-					this.dist = off.norm();
-					updateBasedOnOffset(c, off);
-					c.update();
-				    } else if (e.event.button = 2){ // Right click - transpose
-					var move_up = c.up.scale(-(e.y-this.curY)/200.);
-					var move_over = horiz.scale(-(e.x-this.curX)/200.);
-					c.position.$add(move_up);
-					c.position.$add(move_over);
-					c.target.$add(move_up);
-					c.target.$add(move_over);
-					// Update current positions
-					this.curX = e.x;
-					this.curY = e.y;
-					c.update();
-				    }
-		
-				},
-				    onMouseWheel: function(e){
-				    e.stop();
-				    var offset = PhiloGL.Vec3.scale(camGetOffset(this.camera),
-								    1.0 - e.wheel/10.);
-				    updateBasedOnOffset(this.camera, offset);
-				    this.camera.update();
-				}
-			    },
-				onError: function() {
-				alert("An error ocurred while loading the application");
-			    },
-				onLoad: function(app) {
-				var gl = app.gl,
-				    canvas = app.canvas,
-				    program = app.program,
-				    scene = app.scene,
-				    camera = app.camera;
-	    
-				gl.viewport(0, 0, canvas.width, canvas.height);
-				gl.clearColor(0, 0, 0, 1);
-				gl.clearDepth(1);
-				gl.enable(gl.DEPTH_TEST);
-				gl.depthFunc(gl.LEQUAL);
-
-				program.setBuffers({
-					'shapeset': {
-					    attribute: 'aVertexPosition',
-						value: new Float32Array(vertex_positions),
-						size: 3
-						},
-		
-					    });
-				camera.modelView.id();
-				draw()
-	    
-				    setInterval(draw, 100/60);
-				//Draw the scene
-				function draw() {
-				    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
-				    //Draw Triangle
-				    program.setUniform('uMVMatrix', camera.modelView);
-				    program.setUniform('uPMatrix', camera.projection);
-				    program.setBuffer('triangle');
-				    gl.drawArrays(gl.LINES, 0, n_vertices);	    
-				    examine = camera
-					}
-			    }
-			});  
-		}		
-	    
-	    
+            id: "gv_" + python_varname,
+            title: "WebGL Grid Viewer",
+            iconCls: 'graph',
+            autoScroll: true,
+            layout:'absolute',
+            closable: true,
+            items: [
+                { xtype:'panel',
+                  autoEl: {
+                    tag: 'canvas',
+                    id: 'canvas_' + python_varname,
+                    style: 'border: none;',
+                    width: 512, height:512
+                  },
+                  width: 512,
+                  height: 512
+                }],
+            listeners: { afterlayout: GridViewerStart },
         }
     );
 
-    viewport.get("center-panel").activate("pw_" + this.id);
+    viewport.get("center-panel").activate("gv_" + this.id);
     viewport.doLayout();
-    this.panel = viewport.get("center-panel").get("pw_" + python_varname);
+    this.panel = viewport.get("center-panel").get("gv_" + python_varname);
     this.panel.doLayout();
-    this.image_panel = this.panel.get("image_panel_"+python_varname);
-    var image_dom = this.image_panel.el.dom;
 
-    this.accept_results = function(payload) {
-        this.image_panel.el.dom.src = "data:image/png;base64," + payload['image_data'];
-    }
-
-    yt_rpc.ExtDirectREPL.execute(
-        {code:python_varname + '.zoom(1.0)'},
-        cell_finished);
+    this.accept_results = function(payload) { }
 }
 
-widget_types['plot_window'] = WidgetPlotWindow;
+widget_types['grid_viewer'] = WidgetGridViewer;

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list