Changeset 19739
- Timestamp:
- 11/17/15 14:58:52 (9 years ago)
- Location:
- issm/trunk-jpl/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plot_manager.js
r19724 r19739 13 13 data=options.getfieldvalue('data'); 14 14 15 //standard plot: initialize open Gl for each canvas: 16 var canvas=document.getElementById(options.getfieldvalue('canvasid')); 17 18 // Initialize the GL context: 19 var gl=initWebGL(canvas,options); 20 if(!gl){ 21 throw Error("plotmodel error message: could not initialize open Gl!"); 22 } 23 15 24 //figure out if this is a special plot 16 25 if (typeof data === 'string'){ … … 210 219 var datatype = dataresults[1]; 211 220 212 213 //standard plot:214 if (options.exist('asymsubplot')){215 id=options.getfieldvalue('asymsubplot',i);216 //subplot(nlines,ncols,id);217 }218 else{219 //subplot(nlines,ncols,i);220 }221 222 221 //plot unit 223 plot_unit(x,y,z,elements,data2,is2d,isplanet,datatype,options );222 plot_unit(x,y,z,elements,data2,is2d,isplanet,datatype,options,canvas,gl); 224 223 225 224 //apply all options -
issm/trunk-jpl/src/m/plot/plot_unit.js
r19732 r19739 1 function plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options ) {1 function plot_unit(x,y,z,elements,data,is2d,isplanet,datatype,options,canvas,gl) { 2 2 //PLOT_UNIT - unit plot, display data 3 3 // … … 7 7 // See also: PLOTMODEL, PLOT_MANAGER 8 8 9 //edgecolor 10 edgecolor=options.getfieldvalue('edgecolor','none'); 9 //declare variables: {{{ 10 var node; 11 var vertices = []; 12 var indices = []; 13 var colors = []; 14 var rgbcolor = []; 15 var xmin,xmax; 16 var ymin,ymax; 17 var zmin,zmax; 18 var datamin,datamax; 19 var scale; 20 //}}} 21 22 loadShaders(gl); 11 23 12 / *First initialize webgl for the corresponding canvas: */13 var canvas=document.getElementById(options.getfieldvalue('canvasid'));24 //Initialize the buffer structure: 25 node = Node(gl,options); 14 26 15 // Initialize the GL context: 16 var gl=initWebGL(canvas,options); 27 //Compute coordinates and data range: 28 xmin = ArrayMin(x); 29 xmax = ArrayMax(x); 30 ymin = ArrayMin(y); 31 ymax = ArrayMax(y); 32 zmin = ArrayMin(z); 33 zmax = ArrayMax(z); 34 datamin = ArrayMin(data); 35 datamax = ArrayMax(data); 17 36 18 // Only continue if WebGL is available and working 19 if (gl) { 20 loadShaders(gl); 21 var node=loadModel(gl,x,y,z,elements,data); 22 draw(gl,canvas,node); 23 } 37 //Compute scaling: 38 var scale = 1 / (xmax - xmin); 39 node["scale"] = [scale, scale, scale]; 40 node["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (-2 / scale)]; 41 node["modelMatrix"] = recalculateModelMatrix(node); 42 43 //some defaults: 44 colors.itemSize = 4; 24 45 25 46 switch(datatype){ … … 46 67 patch( 'Faces',[C A D],'Vertices', [x y z],'CData',data(pos),'FaceColor','flat','EdgeColor',edgecolor);*/ 47 68 } 48 else{ 69 else{ //2D triangular elements 70 49 71 /*A=elements(pos,1); B=elements(pos,2); C=elements(pos,3); 50 72 patch( 'Faces', [A B C], 'Vertices', [x y z],'CData', data(pos),'FaceColor','flat','EdgeColor',edgecolor);*/ … … 70 92 patch( 'Faces',[C A D],'Vertices', [x y z],'FaceVertexCData',data(:),'FaceColor','interp','EdgeColor',edgecolor);*/ 71 93 } 72 else{ 73 74 /*A=elements(:,1); B=elements(:,2); C=elements(:,3); 75 patch( 'Faces', [A B C], 'Vertices', [x y z],'FaceVertexCData', data(:),'FaceColor','interp','EdgeColor',edgecolor); 76 */ 94 else{ //triangular elements 95 96 vertices.itemSize = 3; 97 for(var i = 0; i < x.length; i++){ 98 vertices[vertices.length] = x[i]; 99 vertices[vertices.length] = y[i]; 100 //vertices[vertices.length] = z[i]; 101 vertices[vertices.length] = 0; 102 103 //handle mesh/qinterest size mismatch 104 rgbcolor = rgb(data[i], datamin, datamax); 105 colors[colors.length] = rgbcolor[0]; 106 colors[colors.length] = rgbcolor[1]; 107 colors[colors.length] = rgbcolor[2]; 108 colors[colors.length] = 1.0; 109 } 110 111 //linearize the elements array: 112 indices = indices.concat.apply(indices, elements); 113 indices.itemSize = 1; 114 for(var i=0;i<indices.length;i++)indices[i]--; //matlab indices from 1, so decrement. 115 77 116 } 78 117 break; … … 91 130 throw Error(sprintf("%s%i%s\n",'case ',datatype,' not supported')); 92 131 } 132 133 /*Initalize buffers: */ 134 node["buffers"] = initBuffers(gl,[vertices, colors, indices]); 135 136 /*Draw into the canvas:*/ 137 draw(gl,options,canvas,node); 93 138 } -
issm/trunk-jpl/src/m/plot/plotmodel.js
r19721 r19739 11 11 12 12 //Get figure number and number of plots 13 figurenumber=options.figurenumber;14 13 numberofplots=options.numberofplots; 15 14 … … 35 34 if (numberofplots){ 36 35 37 //Create figure : to be replaced by Dan's code here for the <div> segment of the html code?38 //f=figure(figurenumber);clf;39 //deal with visible off or on, figure position, etc...40 41 36 //Go through all data plottable and close window if an error occurs 42 37 for (var i=0;i<numberofplots;i++){ -
issm/trunk-jpl/src/m/plot/webgl.js
r19734 r19739 16 16 gl = null; 17 17 } 18 19 20 // Set clear color to black, fully opaque21 var backgroundcolor=new RGBColor(options.getfieldvalue('backgroundcolor','white'));22 if(backgroundcolor.ok){23 gl.clearColor(backgroundcolor.r/255.0, backgroundcolor.g/255.0, backgroundcolor.b/255.0, 1.0);24 }25 else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out background color for curent canvas ",canvas));26 18 27 19 // Enable depth testing … … 51 43 52 44 return gl; 53 } //}}}54 function loadModel(gl,x,y,z,elements,data){ //{{{55 colorbar=colorbars["rainbow"];56 model={"x":x,"y":y,"z":z,"elements":elements};57 sceneGraph={};58 sceneGraph["model"] = sceneGraphNode(gl);59 sceneGraph["model"]["shaderName"] = "colored";60 sceneGraph["model"]["shader"] = shaders["colored"]["program"];61 sceneGraph["model"]["useIndexBuffer"] = true;62 63 var meshVertices = [];64 var meshColors = [];65 var meshNormals = [];66 var color = [];67 68 var qmin = Math.min.apply(null,data);69 var qmax = Math.max.apply(null,data);70 var xmin = Math.min.apply(null,model["x"]);71 var xmax = Math.max.apply(null,model["x"]);72 var ymin = Math.min.apply(null,model["y"]);73 var ymax = Math.max.apply(null,model["y"]);74 var zmin = Math.min.apply(null,[0]);75 var zmax = Math.max.apply(null,[0]);76 77 var scale = 1 / (xmax - xmin);78 sceneGraph["model"]["scale"] = [scale, scale, scale];79 sceneGraph["model"]["translation"] = [(xmin + xmax) / (-2 / scale), (ymin + ymax) / (-2 / scale), (zmin + zmax) / (-2 / scale)];80 sceneGraph["model"]["modelMatrix"] = recalculateModelMatrix(sceneGraph["model"]);81 82 for(var i = 0; i < model["x"].length; i++){83 meshVertices[meshVertices.length] = model["x"][i];84 meshVertices[meshVertices.length] = model["y"][i];85 meshVertices[meshVertices.length] = 0.0;86 87 //initialize vertex normals88 meshNormals[meshNormals.length] = 0.0;89 meshNormals[meshNormals.length] = 0.0;90 meshNormals[meshNormals.length] = 0.0;91 92 //handle mesh/qinterest size mismatch93 color = rgb(data[i], qmin, qmax);94 meshColors[meshColors.length] = color[0];95 meshColors[meshColors.length] = color[1];96 meshColors[meshColors.length] = color[2];97 meshColors[meshColors.length] = 1.0;98 }99 100 var indices = [];101 indices = indices.concat.apply(indices, model["elements"]);102 103 for (var i = 0; i < indices.length; i += 3){104 indices[i] -= 1;105 indices[i + 1] -= 1;106 indices[i + 2] -= 1;107 }108 109 meshVertices.itemSize = 3;110 meshColors.itemSize = 4;111 indices.itemSize = 1;112 113 sceneGraph["model"]["buffers"] = initBuffers(gl,[meshVertices, meshColors, indices]);114 return sceneGraph["model"];115 45 } //}}} 116 46 function initBuffers(gl,arrays) { //{{{ … … 133 63 return bufferArray; 134 64 } //}}} 135 function sceneGraphNode(gl) { //{{{ 136 //Primary object for storing common rendering information. 137 return {buffers:[], 138 shader:null, 65 function Node(gl,options) { //{{{ 66 67 var node; 68 69 node= {buffers:[], 70 shader:shaders["colored"]["program"], 139 71 draw:null, 140 72 hideOcean:false, 141 73 level:0, 142 useIndexBuffer: false,74 useIndexBuffer:true, 143 75 useOrthographic:false, 144 76 transparency:1.0, 145 77 disableDepthTest:false, 146 78 enableCullFace:false, … … 151 83 rotation:vec3.create(), 152 84 scale:vec3.fromValues(1, 1, 1), 153 modelMatrix:mat4.create()}; 85 modelMatrix:mat4.create(), 86 shaderName:"colored", 87 }; 88 89 return node; 90 154 91 } //}}} 155 92 function recalculateModelMatrix(node) { //{{{ … … 177 114 } //}}} 178 115 function rgb(value, min, max) { //{{{ 116 117 colorbar=colorbars["rainbow"]; 118 179 119 value = clamp(value, min + 1.0, max); 180 120 var use_log_scale = false; … … 347 287 } 348 288 } //}}} 349 function draw(gl,canvas,node) { //{{{ 350 window.requestAnimationFrame(function(time) {draw(gl,canvas,node)}); 351 gl.viewport(0, 0, canvas.width, canvas.height); 352 gl.clear(gl.COLOR_BUFFER_BIT); 289 function draw(gl,options,canvas,node) { //{{{ 290 291 // Set clear color to black, fully opaque 292 var backgroundcolor=new RGBColor(options.getfieldvalue('backgroundcolor','white')); 293 if(backgroundcolor.ok){ 294 gl.clearColor(backgroundcolor.r/255.0, backgroundcolor.g/255.0, backgroundcolor.b/255.0, 1.0); 295 } 296 else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out background color for curent canvas ",canvas)); 297 298 // Clear the color as well as the depth buffer. 299 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 300 301 window.requestAnimationFrame(function(time) {draw(gl,options,canvas,node)}); 353 302 updateCameraMatrix(canvas); 354 355 303 drawSceneGraphNode(gl, canvas, node); 304 356 305 } //}}} 357 306 //}}} -
issm/trunk-jpl/src/wrappers/javascript/Makefile.am
r19716 r19739 77 77 ../ElementConnectivity/ElementConnectivity.cpp 78 78 79 IssmModule_CXXFLAGS= -fPIC -D_DO_NOT_LOAD_GLOBALS_ --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_TriMeshModule','_NodeConnectivityModule','_ElementConnectivityModule']" -s DISABLE_EXCEPTION_CATCHING=0 79 IssmModule_CXXFLAGS= -fPIC -D_DO_NOT_LOAD_GLOBALS_ --memory-init-file 0 $(AM_CXXFLAGS) $(CXXFLAGS) $(CXXOPTFLAGS) $(COPTFLAGS) -s EXPORTED_FUNCTIONS="['_TriMeshModule','_NodeConnectivityModule','_ElementConnectivityModule']" -s DISABLE_EXCEPTION_CATCHING=0 -s ALLOW_MEMORY_GROWTH=1 80 80 IssmModule_LDADD = ${deps} $(TRIANGLELIB) 81 81 #}}}
Note:
See TracChangeset
for help on using the changeset viewer.