Changeset 20471


Ignore:
Timestamp:
04/07/16 22:46:19 (9 years ago)
Author:
dlcheng
Message:

CHG: Modifying plot routines to handle NaN values by removing them from draw calls. Tentative fix for bug involving too many recursive concatenations for large models/meshes. Addressing shallow copies affecting model in processmesh.

Location:
issm/trunk-jpl/src/m/plot
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/plot/plot_mesh.js

    r20401 r20471  
    99        var indices = [];
    1010        var colors = [];
    11         var rgbcolor = [];
     11        var nanindices = {};
    1212        var xmin,xmax;
    1313        var ymin,ymax;
     
    8585                var vertex = vec3.create();
    8686                var magnitude;
    87                 var color = [0.0, 0.0, 0.0, 1.0];
     87                var color = [0.0, 0.0, 0.0, 1.0];       
     88                                                x[0] = NaN;
     89                x[1] = NaN;
     90                x[2] = NaN;
     91                x[3] = NaN;
     92                x[4] = NaN;
     93                x[5] = NaN;
     94                x[6] = NaN;
     95                x[7] = NaN;
     96                x[8] = NaN;
     97                x[9] = NaN;
     98                x[10] = NaN;
     99                x[11] = NaN;
     100                x[12] = NaN;
     101                x[13] = NaN;
     102                x[14] = NaN;
     103                x[15] = NaN;
     104                x[16] = NaN;
     105                x[17] = NaN;
     106                x[18] = NaN;
     107                x[19] = NaN;
     108                x[20] = NaN;
     109                x[21] = NaN;
     110                x[22] = NaN;
     111                x[23] = NaN;
     112                x[24] = NaN;
     113                x[25] = NaN;
     114                x[26] = NaN;
     115                x[27] = NaN;
     116                x[28] = NaN;
     117                x[29] = NaN;
     118                x[30] = NaN;
     119                x[31] = NaN;
     120                x[32] = NaN;
     121                x[33] = NaN;
     122                x[34] = NaN;
     123                x[35] = NaN;
     124                x[36] = NaN;
     125                x[37] = NaN;
     126                x[38] = NaN;
     127                x[39] = NaN;
     128                x[310] = NaN;
     129                x[311] = NaN;
     130                x[312] = NaN;
     131                x[313] = NaN;
     132                x[314] = NaN;
     133                x[315] = NaN;
     134                x[316] = NaN;
     135                x[317] = NaN;
     136                x[318] = NaN;
     137                x[319] = NaN;
     138                x[320] = NaN;
     139                x[321] = NaN;
     140                x[322] = NaN;
     141                x[323] = NaN;
     142                x[324] = NaN;
     143                x[325] = NaN;
     144                x[326] = NaN;
     145                x[327] = NaN;
     146                x[328] = NaN;
     147                x[329] = NaN;   
    88148                for(var i = 0; i < x.length; i++){
     149                        //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
     150                        if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) {
     151                                nanindices[i] = i;
     152                                vertices.push.apply(vertices, vertex);
     153                                continue;
     154                        }
     155                        //Scale vertices
     156                        //Scale vertices
    89157                        xyz = vec3.fromValues(x[i], y[i], z[i]);
    90158                        magnitude = vec3.length(xyz) + md.geometry.surface[i] * surfacescale;
     
    97165               
    98166                //linearize the elements array:
     167                var element;
    99168                for(var i = 0; i < elements.length; i++){
    100                         //convert tris to line edges; generates more edges than necessary, should optimize using node connectivity matlab indices from 1, so decrement indices.
    101                         indices.push.apply(indices, [elements[i][0] - 1, elements[i][1] - 1, elements[i][1] - 1, elements[i][2] - 1, elements[i][2] - 1, elements[i][0] - 1]);
     169                        element = [elements[i][0] - 1, elements[i][1] - 1, elements[i][2] - 1];
     170                        if (element[0] in nanindices || element[1] in nanindices || element[2] in nanindices) continue;
     171                        indices = indices.concat([element[0], element[1], element[1], element[2], element[2], element[0]]);
    102172                }
    103173                indices.itemSize = 1;
  • issm/trunk-jpl/src/m/plot/plot_overlay.js

    r20401 r20471  
    1212        var indices = [];
    1313        var texcoords = [];
     14        var nanindices = {};
    1415        var xmin,xmax;
    1516        var ymin,ymax;
     
    109110        //generate mesh:
    110111        for(var i = 0; i < x.length; i++){
     112                //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
     113                if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) {
     114                        nanindices[i] = i;
     115                        vertices.push.apply(vertices, vertex);
     116                        continue;
     117                }
     118                //Scale vertices
     119                //Scale vertices
    111120                xyz = vec3.fromValues(x[i], y[i], z[i]);
    112121                magnitude = vec3.length(xyz);
     
    118127        }
    119128
    120         //linearize the elements array:
    121         indices = indices.concat.apply(indices, elements);
     129        //linearize the elements array:
     130        var element;
     131        for(var i = 0; i < elements.length; i++){
     132                element = [elements[i][0] - 1, elements[i][1] - 1, elements[i][2] - 1];
     133                if (element[0] in nanindices || element[1] in nanindices || element[2] in nanindices) continue;
     134                indices = indices.concat(element);
     135        }
    122136        indices.itemSize = 1;
    123         for(var i=0;i<indices.length;i++)indices[i]--; //matlab indices from 1, so decrement.
    124137       
    125138        /*Initalize buffers: */
  • issm/trunk-jpl/src/m/plot/plot_quiver.js

    r20401 r20471  
    9292                var color = edgecolor;
    9393                for(var i = 0; i < x.length; i++){
     94                        //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
     95                        if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) continue;
     96                        //Scale vertices
    9497                        xyz1 = vec3.fromValues(x[i], y[i], z[i]);
    9598                        magnitude = vec3.length(xyz1) + md.geometry.surface[i] * surfacescale;
  • issm/trunk-jpl/src/m/plot/plot_unit.js

    r20437 r20471  
    1111        var indices = [];
    1212        var texcoords = [];
    13         var rgbcolor = [];
     13        var nanindices = {};
    1414        var xmin,xmax;
    1515        var ymin,ymax;
     
    2323        var y = meshresults[1];
    2424        var z = meshresults[2];
    25         var elements = meshresults[3]; 
     25        var elements = meshresults[3];
    2626        var is2d = meshresults[4];
    2727        var isplanet = meshresults[5];
     
    107107                                var vertex = vec3.create();
    108108                                var magnitude;
    109        
     109
    110110                                for(var i = 0; i < x.length; i++){
     111                                        //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
     112                                        if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) {
     113                                                nanindices[i] = i;
     114                                                vertices.push.apply(vertices, vertex);
     115                                                continue;
     116                                        }
     117                                        //Scale vertices
    111118                                        xyz = vec3.fromValues(x[i], y[i], z[i]);
    112119                                        magnitude = vec3.length(xyz) + md.geometry.surface[i] * surfacescale;
     
    119126
    120127                                //linearize the elements array:
    121                                 indices = indices.concat.apply(indices, elements);
     128                                var element;
     129                                for(var i = 0; i < elements.length; i++){
     130                                        element = [elements[i][0] - 1, elements[i][1] - 1, elements[i][2] - 1];
     131                                        if (element[0] in nanindices || element[1] in nanindices || element[2] in nanindices) continue;
     132                                        indices = indices.concat(element);
     133                                }
    122134                                indices.itemSize = 1;
    123                                 for(var i=0;i<indices.length;i++)indices[i]--; //matlab indices from 1, so decrement.
    124135
    125136                        }
     
    155166
    156167                                for(var i = 0; i < x.length; i++){
     168                                        //Check for NaN values and remove from indices array as necessary, but preserve vertex array spacing
     169                                        if (isNaN(x[i]) || isNaN(y[i]) || isNaN(z[i])) {
     170                                                nanindices[i] = i;
     171                                                vertices.push.apply(vertices, vertex);
     172                                                continue;
     173                                        }
     174                                        //Scale vertices
    157175                                        xyz = vec3.fromValues(x[i], y[i], z[i]);
    158176                                        magnitude = vec3.length(xyz) + md.geometry.surface[i] * surfacescale;
     
    190208                                }
    191209                               
    192                                 //linearize the elements array:
    193                                 indices = indices.concat.apply(indices, elements);
     210                                //linearize the elements array:
     211                                var element;
     212                                for(var i = 0; i < elements.length; i++){
     213                                        element = [elements[i][0] - 1, elements[i][1] - 1, elements[i][2] - 1];
     214                                        if (element[0] in nanindices || element[1] in nanindices || element[2] in nanindices) continue;
     215                                        indices = indices.concat(element);
     216                                }
    194217                                indices.itemSize = 1;
    195                                 for(var i=0;i<indices.length;i++)indices[i]--; //matlab indices from 1, so decrement.
    196218                               
    197219                                //Initialize movie loop
  • issm/trunk-jpl/src/m/plot/processmesh.js

    r20195 r20471  
    2525
    2626        if (options.getfieldvalue('coord','xy') !== 'latlon'){
    27                 x=md.mesh.x;
    28                 if ('x2d' in md.mesh) x2d=md.mesh.x2d;
    29                 y=md.mesh.y;
    30                 if ('y2d' in md.mesh) y2d=md.mesh.y2d;
     27                x=md.mesh.x.slice();
     28                if ('x2d' in md.mesh) x2d=md.mesh.x2d.slice();
     29                y=md.mesh.y.slice();
     30                if ('y2d' in md.mesh) y2d=md.mesh.y2d.slice();
    3131        }
    3232        else{
    33                 x=md.mesh.long;
    34                 y=md.mesh.lat;
     33                x=md.mesh.long.slice();
     34                y=md.mesh.lat.slice();
    3535        }
    3636
    3737        if ('z' in md.mesh){
    38                 z=md.mesh.z;
     38                z=md.mesh.z.slice();
    3939        }
    4040        else{
     
    4545                z=md[z];
    4646        }
    47 
    48         if ('elements2d' in md.mesh) elements2d=md.mesh.elements2d;
    49         elements=md.mesh.elements;
     47       
     48        //TODO: Make deep copy of elements array to prevent unwanted modification of model (slice creates deep copies for primitive types, shallow copies for obejcts)
     49        if ('elements2d' in md.mesh) elements2d=md.mesh.elements2d.slice();
     50        elements=md.mesh.elements.slice();
    5051
    5152        //is it a 2d plot?
Note: See TracChangeset for help on using the changeset viewer.