Changeset 19912
- Timestamp:
- 12/23/15 13:39:09 (9 years ago)
- Location:
- issm/trunk-jpl/src/m/plot
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plot_manager.js
r19910 r19912 95 95 break; 96 96 case 'mesh': 97 //plot_mesh(md,options,nlines,ncols,i);97 console.log('hello'); 98 98 plot_mesh(md,options,canvas,gl,nodes["main"]); 99 99 break; -
issm/trunk-jpl/src/m/plot/plot_mesh.js
r19873 r19912 14 14 var zmin,zmax; 15 15 var scale; 16 16 17 //Process data and model 17 18 var x = md.mesh.x; 18 19 var y = md.mesh.y; 19 var z = [ 0.0];20 var z = [].fill(md.mesh.x.length); 20 21 var elements = md.mesh.elements; 22 23 if (md.geometry.surface) { 24 z = md.geometry.surface; 25 } 21 26 //}}} 22 27 … … 43 48 node["modelMatrix"] = recalculateModelMatrix(node); 44 49 node["drawMode"] = gl.LINES; 45 //node["alpha"] = options.getfieldvalue('alpha',1.0);46 50 node["overlay"] = false; 47 51 node["drawOrder"] = 0; … … 54 58 var edgecolor=options.getfieldvalue('edgecolor','black'); 55 59 56 // populate arrays57 60 //node plot {{{ 58 61 if (elements[0].length==6){ //prisms 59 /*A=elements(:,1); B=elements(:,2); C=elements(:,3); D=elements(:,4); E=elements(:,5); F=elements(:,6);60 patch( 'Faces', [A B C], 'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);61 patch( 'Faces', [D E F], 'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);62 patch( 'Faces', [A B E D],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);63 patch( 'Faces', [B E F C],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);64 patch( 'Faces', [C A D F],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);65 */66 62 } 67 63 else if (elements[0].length==4){ //tetras 68 /*A=elements(:,1); B=elements(:,2); C=elements(:,3); D=elements(:,4);69 patch( 'Faces',[A B C],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);70 patch( 'Faces',[A B D],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);71 patch( 'Faces',[B C D],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);72 patch( 'Faces',[C A D],'Vertices', [x y z],'FaceVertexCData',zeros(size(x)),'FaceColor','none','EdgeColor',edgecolor,'linewidth',linewidth);73 */74 64 } 75 65 else{ //2D triangular elements … … 78 68 vertices[vertices.length] = x[i]; 79 69 vertices[vertices.length] = y[i]; 80 //vertices[vertices.length] = z[i]; 81 vertices[vertices.length] = 0; 70 vertices[vertices.length] = z[i]; 82 71 83 //handle mesh/qinterest size mismatch84 72 rgbcolor = [0.0, 0.0, 0.0]; 85 73 colors[colors.length] = rgbcolor[0]; … … 90 78 91 79 //linearize the elements array: 92 93 80 for(var i = 0; i < elements.length; i++){ 94 81 //convert tris to line edges; generates more edges than necessary, should optimize using node connectivity … … 105 92 //}}} 106 93 107 /*//apply options108 options=addfielddefault(options,'title','Mesh');109 options=addfielddefault(options,'colorbar',0);110 applyoptions(md,[],options);111 */112 113 94 /*Initalize buffers: */ 114 95 node["arrays"] = [vertices, colors, indices]; -
issm/trunk-jpl/src/m/plot/plot_overlay.js
r19910 r19912 24 24 var is2d = meshresults[4]; 25 25 var isplanet = meshresults[5]; 26 27 if (md.geometry.surface) { 28 z = md.geometry.surface; 29 } 26 30 //}}} 27 31 … … 46 50 node["scale"] = [scale, scale, scale]; 47 51 node["rotation"] = options.getfieldvalue('view',[0,0,0]); 48 node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zm in + zmax) / (-2/ scale)];52 node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmax) / (-1 / scale)]; 49 53 node["modelMatrix"] = recalculateModelMatrix(node); 50 54 node["texture"] = initTexture(gl,options.getfieldvalue('image')); … … 70 74 z = [].concat(z, md.radaroverlay.outerheight); 71 75 elements = [].concat(elements, newelements); 76 77 node["translation"] = [node["translation"][0], node["translation"][1], (ArrayMax(z)) / (-1 / scale)]; 72 78 } 73 79 -
issm/trunk-jpl/src/m/plot/plot_unit.js
r19905 r19912 30 30 var data2 = dataresults[0]; 31 31 var datatype = dataresults[1]; 32 33 if (md.geometry.surface) { 34 z = md.geometry.surface; 35 } 32 36 //}}} 33 37 … … 53 57 node["scale"] = [scale, scale, scale]; 54 58 node["rotation"] = options.getfieldvalue('view',[0,0,0]); 55 node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zm in + zmax) / (-2/ scale)];59 node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmax) / (-1 / scale)]; 56 60 node["modelMatrix"] = recalculateModelMatrix(node); 57 61 node["alpha"] = options.getfieldvalue('alpha',1.0); 58 62 node["overlay"] = options.getfieldvalue('overlay','off') == 'on'; 59 63 node["drawOrder"] = 0; 64 60 65 switch(datatype){ 61 62 66 //element plot {{{ 63 67 case 1: … … 107 111 //quiver plot {{{ 108 112 case 3: 109 110 113 if (is2d){ 111 114 //plot_quiver(x,y,data(:,1),data(:,2),options); … … 115 118 } 116 119 break; 117 118 120 //}}} 119 121 //node transient plot {{{ … … 182 184 break; 183 185 //}}} 184 185 186 default: 186 187 throw Error(sprintf("%s%i%s\n",'case ',datatype,' not supported')); -
issm/trunk-jpl/src/m/plot/webgl.js
r19907 r19912 36 36 canvas.zoomFactor = Math.max(canvas.zoomBounds[1], Math.min(options.getfieldvalue('zoomfactor',canvas.zoomBounds[1]), canvas.zoomBounds[0])); 37 37 canvas.cameraMatrix = mat4.create(); 38 canvas.translation = [0,0]; 39 canvas.controlsensitivity = 1; 38 40 39 41 // Add event listeners for canvas 40 42 if (canvas.addEventListener) { 41 43 // IE9, Chrome, Safari, Opera 42 canvas.addEventListener("mousewheel", function (e) { MouseWheelHandler(e,canvas)}, false);44 canvas.addEventListener("mousewheel", function (e) {handleZoom(e,canvas)}, false); 43 45 // Firefox 44 canvas.addEventListener("DOMMouseScroll", function (e) { MouseWheelHandler(e,canvas)}, false);46 canvas.addEventListener("DOMMouseScroll", function (e) {handleZoom(e,canvas)}, false); 45 47 // Mobile 46 canvas.addEventListener("gesturechange", MouseWheelHandler, false);48 canvas.addEventListener("gesturechange", handleZoom, false); 47 49 } 48 50 … … 71 73 var texture = gl.createTexture(); 72 74 texture.image = new Image(); 75 texture.isLoaded = false; 73 76 texture.image.onload = function () { 74 77 handleLoadedTexture(gl,texture); 75 78 } 76 79 texture.image.src = imageSource; 77 texture.isLoaded = true;78 80 return texture; 79 81 } //}}} … … 89 91 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 90 92 gl.bindTexture(gl.TEXTURE_2D, null); 93 texture.isLoaded = true; 91 94 } //}}} 92 95 function Node(gl,options) { //{{{ … … 262 265 //}}} 263 266 //{{{ Interface Functions 264 function MouseWheelHandler(e,canvas) { //{{{267 function handleZoom(e,canvas) { //{{{ 265 268 // prevent scrolling when over canvas 266 269 e.preventDefault(); … … 268 271 var delta = 1/10 * Math.max(-1, Math.min(e.scale || e.wheelDelta || -e.detail, 1)); 269 272 canvas.zoomFactor = Math.max(canvas.zoomBounds[1], Math.min(canvas.zoomFactor - delta * canvas.zoomFactor, canvas.zoomBounds[0])); 273 } //}}} 274 function handlePointerDown(e,canvas) { //{{{ 275 canvas.lastX = e.clientX; 276 canvas.lastY = e.clientY; 277 } //}}} 278 function handlePointerUp(e,canvas) { //{{{ 279 } //}}} 280 function handlePointerMove(e,canvas) { //{{{ 281 var deltaX = canvas.controlsensitivity * (e.clientX - canvas.lastX); 282 var deltaY = canvas.controlsensitivity * (e.clientY - canvas.lastY); 283 284 lastMouseX = e.clientX; 285 lastMouseY = e.clientY; 286 287 canvas.translation[0] -= deltaX; 288 canvas.translation[0] += deltaY; 289 290 updateCameraMatrix(canvas); 270 291 } //}}} 271 292 //}}} … … 276 297 var pMatrix = mat4.create(); 277 298 278 mat4.perspective(pMatrix, 90 * Math.PI / 180, canvas.width / canvas.height, 0.001, 10000.0); 279 299 mat4.perspective(pMatrix, 90 * Math.PI / 180, canvas.clientWidth / canvas.clientHeight, 0.001, 10000.0); 280 300 //Apply screenspace relative translation 281 301 var translateMatrix = mat4.create(); 282 mat4.translate(translateMatrix, translateMatrix, [ 0.0, 0.0, canvas.zoomFactor]);302 mat4.translate(translateMatrix, translateMatrix, [canvas.translation[0], canvas.translation[1], canvas.zoomFactor]); 283 303 mat4.multiply(vMatrix, translateMatrix, vMatrix); 284 304 … … 288 308 }//}}} 289 309 function drawSceneGraphNode(gl,canvas,node) { //{{{ 310 if (node["texture"]) { 311 if (!node["texture"]["isLoaded"]) { 312 return; 313 } 314 } 290 315 bindAttributes(gl, node["shader"], node["buffers"]); 291 316 var mvpMatrix = mat4.create(); … … 338 363 else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out background color for curent canvas ",canvas)); 339 364 340 // Clear the color as well as the depth buffer. 365 // Skip drawing of new frame if any texture is not yet loaded 366 for (var node in nodes) { 367 if (nodes[node]["texture"] && !nodes[node]["texture"]["isLoaded"]) { 368 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)}); 369 return; 370 } 371 } 372 // Else, clear the color as well as the depth buffer for new frame 341 373 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 342 343 374 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,nodes)}); 375 344 376 updateCameraMatrix(canvas); 345 377
Note:
See TracChangeset
for help on using the changeset viewer.