[Yt-svn] commit/yt: 2 new changesets
Bitbucket
commits-noreply at bitbucket.org
Sat Oct 29 05:18:21 PDT 2011
2 new commits in yt:
https://bitbucket.org/yt_analysis/yt/changeset/d939517e4aec/
changeset: d939517e4aec
branch: yt
user: MatthewTurk
date: 2011-10-28 22:15:30
summary: Re-enable Grid viewing, update for PhiloGL 1.4.2.
affected #: 3 files
diff -r 0eb936dbc3431bb5fce2e42aba1796d3ad38d1ef -r d939517e4aecf5615a8caf32d76619587a6a2d5c yt/gui/reason/html/js/reason.js
--- a/yt/gui/reason/html/js/reason.js
+++ b/yt/gui/reason/html/js/reason.js
@@ -186,10 +186,10 @@
} else if (node.attributes.objdata.type == 'pf') {
rightClickMenu = new Ext.menu.Menu({
items: [
- /*{
+ {
text: 'View Grids',
handler: getGridViewerHandler(node),
- },*/ {
+ }, {
text: 'View Grid Data',
handler: getGridDataViewerHandler(node),
}, {
diff -r 0eb936dbc3431bb5fce2e42aba1796d3ad38d1ef -r d939517e4aecf5615a8caf32d76619587a6a2d5c yt/gui/reason/html/js/widget_gridviewer.js
--- a/yt/gui/reason/html/js/widget_gridviewer.js
+++ b/yt/gui/reason/html/js/widget_gridviewer.js
@@ -165,7 +165,6 @@
//gl.disable(gl.DEPTH_TEST);
program.setUniform('alpha',0.8);
gl.depthFunc(gl.LEQUAL);
- examine = camera;
program.setBuffers({
'shapeset': {
attribute: 'aVertexPosition',
@@ -180,18 +179,14 @@
});
- camera.modelView.id();
+ examine = camera;
+ camera.view.id();
camera.update();
- /*(function animloop(){
- draw();
- requestAnimFrame(animloop, canvas);
- })();*/
-
//Draw the scene
draw = function() {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
- program.setUniform('uMVMatrix', camera.modelView);
+ program.setUniform('uMVMatrix', camera.view);
program.setUniform('uPMatrix', camera.projection);
program.setBuffer('shapeset');
program.setBuffer('shapesetColors');
diff -r 0eb936dbc3431bb5fce2e42aba1796d3ad38d1ef -r d939517e4aecf5615a8caf32d76619587a6a2d5c yt/gui/reason/html/js/widget_streamlineviewer.js
--- a/yt/gui/reason/html/js/widget_streamlineviewer.js
+++ b/yt/gui/reason/html/js/widget_streamlineviewer.js
@@ -159,7 +159,7 @@
});
- camera.modelView.id();
+ camera.view.id();
setInterval(draw, 30/60);
var stream_counter =0;
//Draw the scene
@@ -167,7 +167,7 @@
stream_counter = 0;
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
//Draw Triangle
- program.setUniform('uMVMatrix', camera.modelView);
+ program.setUniform('uMVMatrix', camera.view);
program.setUniform('uPMatrix', camera.projection);
program.setBuffer('shapeset');
program.setBuffer('shapesetColors');
https://bitbucket.org/yt_analysis/yt/changeset/e04463e1db6b/
changeset: e04463e1db6b
branch: yt
user: MatthewTurk
date: 2011-10-29 00:23:23
summary: Initial pass at an isocontour viewer in WebGL.
affected #: 8 files
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/data_objects/data_containers.py
--- a/yt/data_objects/data_containers.py
+++ b/yt/data_objects/data_containers.py
@@ -2492,7 +2492,9 @@
"""
verts = []
samples = []
- for g in self._grids:
+ pb = get_pbar("Extracting Isocontours", len(self._grids))
+ for i, g in enumerate(self._grids):
+ pb.update(i)
mask = self._get_cut_mask(g) * g.child_mask
vals = g.get_vertex_centered_data(field)
if sample_values is not None:
@@ -2505,6 +2507,7 @@
my_verts, svals = my_verts
samples.append(svals)
verts.append(my_verts)
+ pb.finish()
verts = na.concatenate(verts)
if sample_values is not None:
samples = na.concatenate(samples)
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -458,3 +458,6 @@
class NoCUDAException(Exception):
pass
+
+class YTEmptyClass(object):
+ pass
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/gui/reason/extdirect_repl.py
--- a/yt/gui/reason/extdirect_repl.py
+++ b/yt/gui/reason/extdirect_repl.py
@@ -555,6 +555,38 @@
'widget_data_name': '_twidget_data'})
@lockit
+ def create_isocontours(self, pfname, field, value, sampling_field):
+ funccall = """
+ _tpf = %(pfname)s
+ _tfield = "%(field)s"
+ _tvalue = %(value)s
+ _tsample_values = "%(sampling_field)s"
+ _tdd = _tpf.h.all_data()
+ _tiso = _tdd.extract_isocontours(_tfield, _tvalue, rescale = True,
+ sample_values = _tsample_values)
+ from yt.funcs import YTEmptyClass
+ _tpw = YTEmptyClass()
+ print "GOT TPW"
+ _tpw._widget_name = 'isocontour_viewer'
+ _tpw._ext_widget_id = None
+ _tverts = _tiso[0].ravel().tolist()
+ _tc = (apply_colormap(na.log10(_tiso[1]))).squeeze()
+ _tcolors = na.empty((_tc.shape[0] * 3, 4), dtype='float32')
+ _tcolors[0::3,:] = _tc
+ _tcolors[1::3,:] = _tc
+ _tcolors[2::3,:] = _tc
+ _tcolors = (_tcolors.ravel()/255.0).tolist()
+ _twidget_data = {'vertex_positions': _tverts, 'vertex_colors': _tcolors}
+ """ % dict(pfname=pfname, value=value, sampling_field=sampling_field, field=field)
+ # There is a call to do this, but I have forgotten it ...
+ funccall = "\n".join((line.strip() for line in funccall.splitlines()))
+ self.execute(funccall, hide = True)
+ self.execution_thread.queue.put({'type': 'add_widget',
+ 'name' : '_tpw',
+ 'widget_data_name': '_twidget_data'})
+
+
+ @lockit
def create_grid_dataview(self, pfname):
funccall = """
_tpf = %(pfname)s
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/gui/reason/html/index.html
--- a/yt/gui/reason/html/index.html
+++ b/yt/gui/reason/html/index.html
@@ -116,6 +116,9 @@
<!-- THE PHASE PLOT VIEWER FUNCTIONS --><script type="text/javascript" src="js/widget_phaseplot.js"></script>
+ <!-- THE GRID VIEWER FUNCTIONS -->
+ <script type="text/javascript" src="js/widget_isocontour.js"></script>
+
<script id="gv-shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/gui/reason/html/js/functions.js
--- a/yt/gui/reason/html/js/functions.js
+++ b/yt/gui/reason/html/js/functions.js
@@ -252,6 +252,76 @@
return streamlineViewerHandler;
}
+function getIsocontourViewerHandler(node){
+function isocontourViewerHandler(item,pressed){
+ var win = new Ext.Window({
+ layout:'fit',
+ width:320,
+ height:250,
+ modal:true,
+ resizable:false,
+ draggable:false,
+ border:false,
+ title:'Isocontour Extraction in' + node,
+ items: [{
+ xtype: 'form', // FormPanel
+ labelWidth:80,
+ frame:true,
+ items: [{
+ xtype:'combo',
+ fieldLabel: 'Field',
+ id: 'field',
+ store:node.attributes.objdata.field_list,
+ width: 200,
+ allowBlank:false,
+ value: 'Density',
+ triggerAction: 'all',
+ },{
+ xtype:'combo',
+ fieldLabel: 'Sampling Field',
+ id: 'extract_field',
+ store:node.attributes.objdata.field_list,
+ width: 200,
+ allowBlank:false,
+ value: 'Temperature',
+ triggerAction: 'all',
+ },{
+ xtype:'textfield',
+ fieldLabel: 'Value',
+ id: 'value',
+ value: '1e-25',
+ width: 90,
+ allowBlank:false,
+ }],
+ buttons: [
+ {
+ text: 'Extract',
+ handler: function(b, e){
+ var field = Ext.get("field").getValue();
+ var value = Ext.get("value").getValue();
+ var sampling_field = Ext.get("extract_field").getValue();
+ yt_rpc.ExtDirectREPL.create_isocontours({
+ pfname:node.attributes.objdata.varname,
+ field:field, value:value,
+ sampling_field:sampling_field},
+ handle_result);
+ disable_input();
+ win.close();
+ }
+ },{
+ text: 'Cancel',
+ handler: function(b, e){
+ win.close();
+ }
+ }
+ ]
+ }]
+ });
+ win.show(this);
+}
+return isocontourViewerHandler;
+}
+
function getSliceHandler(node){
function sliceHandler(item,pressed){
var win = new Ext.Window({
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/gui/reason/html/js/reason.js
--- a/yt/gui/reason/html/js/reason.js
+++ b/yt/gui/reason/html/js/reason.js
@@ -190,6 +190,9 @@
text: 'View Grids',
handler: getGridViewerHandler(node),
}, {
+ text: 'View Isocontour',
+ handler: getIsocontourViewerHandler(node),
+ }, {
text: 'View Grid Data',
handler: getGridDataViewerHandler(node),
}, {
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/gui/reason/html/js/widget_gridviewer.js
--- a/yt/gui/reason/html/js/widget_gridviewer.js
+++ b/yt/gui/reason/html/js/widget_gridviewer.js
@@ -64,11 +64,6 @@
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 = {
@@ -156,41 +151,23 @@
program = app.program,
scene = app.scene,
camera = app.camera;
-
+ var grids = new PhiloGL.O3D.Model({
+ vertices : widget_data['vertex_positions'],
+ drawType : "LINES",
+ colors : widget_data['vertex_colors'],
+ });
+ scene.add(grids);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.clearColor(0, 0, 0, 1);
- //gl.clearDepth(1);
- gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
- gl.enable(gl.BLEND);
- //gl.disable(gl.DEPTH_TEST);
- program.setUniform('alpha',0.8);
- gl.depthFunc(gl.LEQUAL);
- program.setBuffers({
- 'shapeset': {
- attribute: 'aVertexPosition',
- value: new Float32Array(widget_data['vertex_positions']),
- size: 3
- },
- 'shapesetColors': {
- attribute: 'aVertexColor',
- value: new Float32Array(widget_data['vertex_colors']),
- size: 4
- },
-
- });
- examine = camera;
+ //examine = camera;
camera.view.id();
camera.update();
//Draw the scene
draw = function() {
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
- program.setUniform('uMVMatrix', camera.view);
- program.setUniform('uPMatrix', camera.projection);
- program.setBuffer('shapeset');
- program.setBuffer('shapesetColors');
- gl.drawArrays(gl.LINES, 0, widget_data['n_vertices']);
+ scene.render();
}
draw();
diff -r d939517e4aecf5615a8caf32d76619587a6a2d5c -r e04463e1db6b47f81ff39ce25f0a8f984ecf050e yt/gui/reason/html/js/widget_isocontour.js
--- /dev/null
+++ b/yt/gui/reason/html/js/widget_isocontour.js
@@ -0,0 +1,213 @@
+/**********************************************************************
+The isocontour viewer widget
+
+Author: Samuel Skillman <samskillman at gmail.com>
+Affiliation: University of Colorado at Boulder
+Author: Matthew Turk <matthewturk at gmail.com>
+Affiliation: Columbia University
+Homepage: http://yt-project.org/
+License:
+ Copyright (C) 2011 Matthew Turk. All Rights Reserved.
+
+ This file is part of yt.
+
+ yt is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+***********************************************************************/
+
+// shim layer with setTimeout fallback
+window.requestAnimFrame = (function(){
+ return window.requestAnimationFrame ||
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function(/* function */ callback, /* DOMElement */ element){
+ window.setTimeout(callback, 1000 / 60);
+ };
+})();
+
+var exagain;
+var WidgetIsocontourViewer = function(python_varname, widget_data) {
+ this.id = python_varname;
+ this.widget_data = widget_data;
+ examine = "canvas_" + python_varname;
+ var draw;
+ 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;
+ draw();
+ }
+ 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
+ },
+ },
+ 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);
+ this.camera.near = this.dist/100000.0;
+ this.camera.far = this.dist*2.0;
+ c.update();
+ } else if (e.event.button = 2){ // Right click - transpose
+ var tscale = 1.0*off.norm()/512.;
+ var move_up = c.up.scale(-(e.y-this.curY)*tscale);
+ var move_over = horiz.scale(-(e.x-this.curX)*tscale);
+ 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;
+ this.dist = off.norm();
+ this.camera.near = this.dist/100000.0;
+ this.camera.far = this.dist*2.0;
+ c.update();
+ }
+ draw();
+ },
+ onMouseWheel: function(e){
+ e.stop();
+ var offset = PhiloGL.Vec3.scale(camGetOffset(this.camera),
+ 1.0 - e.wheel/10.);
+ updateBasedOnOffset(this.camera, offset);
+ var dist = offset.norm()
+ this.camera.near = offset.norm()/100000.0;
+ this.camera.far = offset.norm()*2.0;
+ this.camera.update();
+ draw();
+ }
+ },
+ 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;
+ var grids = new PhiloGL.O3D.Model({
+ vertices : widget_data['vertex_positions'],
+ drawType : "TRIANGLES",
+ colors : widget_data['vertex_colors'],
+ });
+ exagain = grids;
+ scene.add(grids);
+ gl.viewport(0, 0, canvas.width, canvas.height);
+ gl.clearColor(0, 0, 0, 1);
+
+ //examine = camera;
+ camera.view.id();
+ camera.update();
+
+ //Draw the scene
+ draw = function() {
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+ scene.render();
+ }
+
+ draw();
+
+ }
+ });
+ }
+
+ viewport.get("center-panel").add(
+ {
+ xtype: 'panel',
+ id: "iv_" + python_varname,
+ title: "WebGL Isocontour 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("iv_" + this.id);
+ viewport.doLayout();
+ this.panel = viewport.get("center-panel").get("iv_" + python_varname);
+ this.panel.doLayout();
+
+ this.accept_results = function(payload) { }
+}
+
+widget_types['isocontour_viewer'] = WidgetIsocontourViewer;
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