Ignore:
Timestamp:
05/10/18 10:24:27 (7 years ago)
Author:
Mathieu Morlighem
Message:

merged trunk-jpl and trunk for revision 22757

Location:
issm/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk

  • issm/trunk/src

  • issm/trunk/src/m/plot/plot_quiver.js

    r21729 r22758  
    1 function plot_quiver(md, options, canvas, updateVel) { //{{{
     1function plot_quiver(md, options, canvas, noCacheNodesOverride) { //{{{
    22        //PLOT_QUIVER - quiver plot with colors
    33        //
     
    77        //   See also: PLOTMODEL, PLOT_MANAGER
    88
     9        //Disabling for now, since quivers are "sticky" - once turned on, they won't turn off. This is due to cachenodes, but should find better way to handle it.
     10        return;
     11       
     12        if ('quiver' in  canvas.nodes && noCacheNodesOverride && options.getfieldvalue('cachenodes','on') === 'on') return;
     13       
    914        //{{{ declare variables:
    10         var vertices = [];
    11         var indices = [];
    12         var colors = [];
    13         var xmin, xmax;
    14         var ymin, ymax;
    15         var zmin, zmax;
    16         var scale, matrixscale, vertexscale;
    17        
    1815        //Process data and model
    19         var meshresults = processmesh(md,[], options);
    20 
     16        var meshresults = processmesh(md, [], options);
    2117        var x = meshresults[0];
    2218        var y = meshresults[1];
     
    2521        var is2d = meshresults[4];
    2622        var isplanet = meshresults[5];
    27         var v = updateVel != undefined ? updateVel.vel : md.initialization.vel;
    28         var vx = updateVel != undefined ? updateVel.vx : md.initialization.vx;
    29         var vy = updateVel != undefined ? updateVel.vy : md.initialization.vy;
     23        if (md.mesh.classname() !== 'mesh3dsurface') z = md.geometry.surface;
    3024               
    31         //Compue scaling through matrices for 2d meshes and vertices for 3d meshes
    32         if (!md.geometry.surface) {
    33                 md.geometry.surface=NewArrayFill(md.mesh.x.length, 0);
    34         }
    35         if (md.mesh.classname() == 'mesh3dsurface') {
    36                 matrixscale = 1;
    37                 vertexscale = options.getfieldvalue('heightscale', 1);
     25        //Compute coordinates and data range:
     26        var xlim = options.getfieldvalue('xlim', [ArrayMin(x), ArrayMax(x)]);
     27        var ylim = options.getfieldvalue('ylim', [ArrayMin(y), ArrayMax(y)]);
     28        var zlim = options.getfieldvalue('zlim', [ArrayMin(z), ArrayMax(z)]);
     29
     30        //Only displaying velocity fields for now
     31        var v = VESL.Helpers.isEmptyOrUndefined(md.results) ?  md.initialization.vel : md.results[canvas.animation.frame].Vel;
     32        var vx = VESL.Helpers.isEmptyOrUndefined(md.results) ? md.initialization.vx : md.results[canvas.animation.frame].Vx;
     33        var vy = VESL.Helpers.isEmptyOrUndefined(md.results) ? md.initialization.vy : md.results[canvas.animation.frame].Vy;
     34
     35        //Handle heightscale
     36        var vertices, scale;
     37        if (md.mesh.classname() !== 'mesh3dsurface') {
     38                vertices = [x, y, z];
     39                scale = [1, 1, options.getfieldvalue('heightscale', 1)];
    3840        }
    3941        else {
    40                 if (md.geometry.surface) {
    41                         z=md.geometry.surface;
    42                 }       
    43                 matrixscale = options.getfieldvalue('heightscale', 1);
    44                 vertexscale = 0;
     42                vertices = Node.prototype.scaleVertices(md, x, y, z, elements, options.getfieldvalue('heightscale', 1), options.getfieldvalue('maskregion',{'enabled':false}));
     43                scale = [1, 1, 1];
    4544        }
    46         //}}}
    47 
    48         //Compute coordinates and data range:
    49         var modelxlim = [ArrayMin(x), ArrayMax(x)];
    50         var modelylim = [ArrayMin(y), ArrayMax(y)];
    51         var modelzlim = [ArrayMin(z), ArrayMax(z)];
    52         var xlim = options.getfieldvalue('xlim', modelxlim);
    53         var ylim = options.getfieldvalue('ylim', modelylim);
    54         var zlim = options.getfieldvalue('zlim', modelzlim);
    55         xmin = xlim[0];
    56         xmax = xlim[1];
    57         ymin = ylim[0];
    58         ymax = ylim[1];
    59         zmin = zlim[0];
    60         zmax = zlim[1];
    61 
     45       
    6246        //Compute gl variables:
    63         var gl = canvas.gl;
    64         var node = Node(gl);
    65         canvas.nodes["velocity"] = node;
    66         node.name = "quiver";
    67         node.shaderName = "Colored";
    68         node.shader = gl.shaders[node.shaderName];
    69         node.lineWidth = options.getfieldvalue('linewidth', 1);
    70         node.scale = [1, 1, matrixscale];
    71         node.rotation = [-90, 0, 0];
    72         node.translation = [0, 0, 0];
    73         node.center = [(xmin + xmax) / 2, (ymin + ymax) / 2, (zmin + zmax) / 2];
    74         node.drawMode = gl.LINES;
    75         node.useIndexBuffer = false;
    76         node.drawOrder = 0;
    77         node.maskEnabled = options.getfieldvalue('innermask','off') == 'on';
    78         node.maskHeight = options.getfieldvalue('innermaskheight', 150.0)*options.getfieldvalue('heightscale', 1);
    79         node.maskColor = options.getfieldvalue('innermaskcolor',[0.0, 0.0, 1.0, 1.0]);
    80         updateModelMatrix(node);
    81 
    82         //retrieve some options
    83         var edgecolor=new RGBColor(options.getfieldvalue('edgecolor','black'));
    84         if (edgecolor.ok) edgecolor = [edgecolor.r/255.0, edgecolor.g/255.0, edgecolor.b/255.0, 1.0];
    85         else throw Error(sprintf("s%s%s\n","initWebGL error message: cound not find out edgecolor color for curent canvas ", canvas));
    86 
     47        var edgecolor = options.getfieldvalue('edgecolor', 'black');
     48        var node = new Node(
     49                'canvas', canvas,
     50                'options', options,
     51                'name', 'quiver',
     52                'shaderName', 'Colored',
     53                'alpha', options.getfieldvalue('alpha', 1.0),
     54                //'center', [(xlim[0] + xlim[1]) / 2, (ylim[0] + ylim[1]) / 2, md.mesh.classname() === 'mesh3dsurface' ? (zlim[0] + zlim[1]) / 2 : zlim[0]],
     55                'center', [(xlim[0] + xlim[1]) / 2, (ylim[0] + ylim[1]) / 2, (zlim[0] + zlim[1]) / 2],
     56                'drawMode', canvas.gl.LINES,
     57                'diffuseColor', edgecolor,
     58                'lineWidth', options.getfieldvalue('linewidth', 1),
     59                'maskEnabled', options.getfieldvalue('innermask','off') == 'on',
     60                'maskHeight', options.getfieldvalue('innermaskheight', 150.0) / options.getfieldvalue('heightscale', 1),
     61                'maskColor', options.getfieldvalue('innermaskcolor',[0.0, 0.0, 1.0, 1.0]),
     62                'rotation', [-90, 0, 0],
     63                'scale', scale
     64        );
     65       
     66       
    8767        //{{{ node plot
    8868        if (elements[0].length==6){ //prisms
     
    9171        }
    9272        else{ //2D triangular elements
     73                //Create arow vertices, and use vx/vy to determine rotation before adding to quiver mesh.
     74                var verticesArrow = [vec3.fromValues(0.0, 0.0, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, -0.167, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, 0.166, 0.0), vec3.fromValues(1.0, 0.0, 0.0)];
     75               
     76                var newX = [];
     77                var newY = [];
     78                var newZ = [];
    9379                var xyz = vec3.create();
    94                 var xyz = vec3.create();
    95                 var direction = vec3.create();
    9680                var vertex = vec3.create();
    97                 var vertexBase = vec3.create();
    98                 var verticesArrow = [vec3.fromValues(0.0, 0.0, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, -0.167, 0.0), vec3.fromValues(1.0, 0.0, 0.0), vec3.fromValues(0.667, 0.166, 0.0), vec3.fromValues(1.0, 0.0, 0.0)];
    99                 var magnitude;
    100                 var color = edgecolor;
    10181                var scaling = options.getfieldvalue('scaling', 1);
    102                 var scale;
    103                 for(var i = 0; i < x.length; i++){
    104                         //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
    105                         if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) continue;
    106                         //Scale vertices
     82                var heightScale = options.getfieldvalue('heightscale', 1);
     83                var arrowScale;
     84                var modelMatrix = mat4.create();
     85                var scaleMatrix = mat4.create();
     86                var rotationMatrix = mat4.create();
     87               
     88                for(var i = 0, iX = 0, iY = 0, iZ = 0; i < x.length; i++){
    10789                        xyz = vec3.fromValues(x[i], y[i], z[i]);
    108                         magnitude = vec3.length(xyz) + md.geometry.surface[i] * vertexscale;
    109                         vec3.normalize(direction, xyz);
    110                         vec3.scale(vertex, direction, magnitude);
    111                         vec3.copy(vertexBase, vertex);
    112                        
    113                         scale = scaling*v[i];
    114                         var modelMatrix = mat4.create();
    115                         var scaleMatrix = mat4.create();
    116                         var rotationMatrix = mat4.create();
    117                         mat4.scale(scaleMatrix, scaleMatrix, vec3.fromValues(scale, scale, scale));
    118                         mat4.rotate(rotationMatrix, rotationMatrix, Math.atan2(vy[i], vx[i]), [0.0, 0.0, 1.0]);
     90                        arrowScale = v[i] * scaling;
     91                        scaleMatrix = mat4.create();
     92                        mat4.scale(scaleMatrix, mat4.create(), vec3.fromValues(arrowScale, arrowScale, arrowScale));
     93                        mat4.rotate(rotationMatrix, mat4.create(), Math.atan2(vy[i], vx[i]), [0.0, 0.0, 1.0]);
    11994                        mat4.multiply(modelMatrix, rotationMatrix, scaleMatrix);
    120 
    121                         var temp = vec3.fromValues(0.0, 0.0, 0.0);
    12295                        for (var j = 0; j < 6; j++){
    12396                                vec3.transformMat4(vertex, verticesArrow[j], modelMatrix);
    124                                 vec3.add(vertex, vertex, vertexBase);
    125                                 vertices[vertices.length] = vertex[0];
    126                                 vertices[vertices.length] = vertex[1];
    127                                 vertices[vertices.length] = vertex[2];
    128                                
    129                                 colors[colors.length] = color[0];
    130                                 colors[colors.length] = color[1];
    131                                 colors[colors.length] = color[2];
    132                                 colors[colors.length] = color[3];
     97                                vec3.add(vertex, vertex, xyz);
     98                                newX[iX++] = vertex[0];
     99                                newY[iY++] = vertex[1];
     100                                newZ[iZ++] = vertex[2];
    133101                        }
    134102                }
     103                node.patch('Vertices', [newX, newY, newZ], 'FaceColor', 'none');
    135104        }
    136105        //}}}
    137         node.mesh = GL.Mesh.load({vertices: vertices, colors: colors}, null, null, gl);
    138106} //}}}
Note: See TracChangeset for help on using the changeset viewer.