-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKVS.min.js
86 lines (86 loc) · 42.9 KB
/
KVS.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
var KVS={REVISION:"0",StripLine:0,SegmentLine:1,XAxis:0,YAxis:1,ZAxis:2,Euler:0,RungeKutta2:1,RungeKutta4:2,ForwardDirection:1,BackwardDirection:-1,Min:function(a,b){var d=Math.min(a.x,b.x),c=Math.min(a.y,b.y),e=Math.min(a.z,b.z);return new KVS.Vec3(d,c,e)},Max:function(a,b){var d=Math.max(a.x,b.x),c=Math.max(a.y,b.y),e=Math.max(a.z,b.z);return new KVS.Vec3(d,c,e)},Mix:function(a,b,d){return a*(1-d)+b*d},Swap:function(a,b){},Clamp:function(a,b,d){return Math.max(b,Math.min(d,a))},HSV2RGB:function(a){var b=
a.x,d=a.y;a=a.z;if(0==d)return new KVS.Vec3(a,a,a);var c=6*(1>b?b:b-1),e=Math.floor(c),b=a*(1-d),f=a*(1-d*(c-e)),d=a*(1-d*(1-c+e));switch(e){case 0:e=a;c=d;a=b;break;case 1:e=f;c=a;a=b;break;case 2:e=b;c=a;a=d;break;case 3:e=b;c=f;break;case 4:e=d;c=b;break;default:e=a,c=b,a=f}return new KVS.Vec3(e,c,a)},RainbowColorMap:function(a,b,d){return KVS.HSV2RGB(new KVS.Vec3(.75*(1-(d-a)/(b-a)),1,1))}};KVS.HydrogenData=function(a,b,d){var c=new KVS.StructuredVolumeObject;c.resolution.set(a,b,d);for(var e=32/a,f=32/b,r=32/d,l=0;l<d;++l)for(var h=r*(l-d/2),g=0;g<b;++g)for(var q=f*(g-b/2),w=0;w<a;++w){var k=e*(w-a/2),k=Math.sqrt(k*k+q*q+h*h),p=h/k,k=6*k*k*Math.exp(-k/2)*(3*p*p-1),k=k*k;255<k&&(k=255);c.values.push([k])}c.updateMinMaxCoords();c.setMinMaxValues(0,255);return c};
KVS.CreateHydrogenData=function(a,b,d){var c=new KVS.StructuredVolumeObject;c.resolution.set(a,b,d);for(var e=32/a,f=32/b,r=32/d,l=0;l<d;++l)for(var h=r*(l-d/2),g=0;g<b;++g)for(var q=f*(g-b/2),w=0;w<a;++w){var k=e*(w-a/2),k=Math.sqrt(k*k+q*q+h*h),p=h/k,k=6*k*k*Math.exp(-k/2)*(3*p*p-1),k=k*k;255<k&&(k=255);c.values.push([k])}c.updateMinMaxCoords();c.setMinMaxValues(0,255);return c};KVS.TornadoData=function(a,b,d){var c=new KVS.StructuredVolumeObject;c.resolution.set(a,b,d);for(var e=1/(a-1),f=1/(b-1),r=1/(d-1),l=0;l<d;l++)for(var h=l*r,g=.5+.1*Math.sin(0+10*h),q=.5+.1*Math.cos(0+3*h),w=.1+.4*h*h+.1*h*Math.sin(8*h),k=.2+.1*h,p=0;p<b;p++)for(var t=p*f,v=0;v<a;v++){var u=v*e,m=Math.sqrt((t-q)*(t-q)+(u-g)*(u-g)),n=Math.abs(w-m),n=n>k?.8-n:1,s=.1*(.1-m*h);0>s&&(s=0);m=Math.sqrt(m*m+s*s);n=(w+k-m)*n/(m+1E-11);n/=1+h;c.values.push([n*(t-q)+.1*(u-g),n*-(u-g)+.1*(t-q),n*s])}c.updateMinMaxCoords();
c.updateMinMaxValues();return c};
KVS.CreateTornadoData=function(a,b,d){var c=new KVS.StructuredVolumeObject;c.resolution.set(a,b,d);for(var e=1/(a-1),f=1/(b-1),r=1/(d-1),l=0;l<d;l++)for(var h=l*r,g=.5+.1*Math.sin(0+10*h),q=.5+.1*Math.cos(0+3*h),w=.1+.4*h*h+.1*h*Math.sin(8*h),k=.2+.1*h,p=0;p<b;p++)for(var t=p*f,v=0;v<a;v++){var u=v*e,m=Math.sqrt((t-q)*(t-q)+(u-g)*(u-g)),n=Math.abs(w-m),n=n>k?.8-n:1,s=.1*(.1-m*h);0>s&&(s=0);m=Math.sqrt(m*m+s*s);n=(w+k-m)*n/(m+1E-11);n/=1+h;c.values.push([n*(t-q)+.1*(u-g),n*-(u-g)+.1*(t-q),n*s])}c.updateMinMaxCoords();
c.updateMinMaxValues();return c};KVS.JSONLoader=function(a){function b(a,b){var c=new KVS.PointObject;if(void 0==a.coords)return console.error(b+": Cannot find 'coords' in the input file."),c;c.coords=a.coords;c.colors=void 0==(void 0).colors?[[0,0,0]]:(void 0).colors;set_min_max_coord(c,a);return c}function d(a,b){var c=new KVS.LineObject;if(void 0==a.coords)return console.error(b+": Cannot find 'coords' in the input file."),c;c.coords=a.coords;c.line_type=void 0==a.line_type?KVS.StripLine:"SegmentLine"==a.line_type?KVS.SegmentLine:
KVS.StripLine;c.width=void 0==a.width?1:a.width;c.colors=void 0==(void 0).colors?[[0,0,0]]:(void 0).colors;set_min_max_coord(c,a);return c}function c(a,b){var c=new KVS.PolygonObject;if(void 0==a.coords)return console.error(b+": Cannot find 'coords' in the input file."),c;if(void 0==a.connections)return console.error(b+": Cannot find 'connections' in the input file."),c;c.coords=a.coords;c.connections=a.connections;c.colors=void 0==(void 0).colors?[[0,0,0]]:(void 0).colors;set_min_max_coord(c,a);
return c}function e(a,b){var c=new KVS.StructuredVolumeObject;if(void 0==a.resolution)return console.error(b+": Cannot find 'resolution' in the input file."),c;if(void 0==a.values)return console.error(b+": Cannot find 'values' in the input file."),c;c.resolution=(new KVS.Vec3).fromArray(a.resolution);c.values=a.values;c.updateMinMaxCoords();r(c,a);return c}function f(a,b){var c=new KVS.UnstructuredVolumeObject;if(void 0==a.coords)return console.error(b+": Cannot find 'coords' in the input file."),
c;if(void 0==a.connections)return console.error(b+": Cannot find 'connections' in the input file."),c;if(void 0==a.values)return console.error(b+": Cannot find 'values' in the input file."),c;c.coords=a.coords;c.connections=a.connections;c.values=a.values;if(void 0==a.min_coord&&void 0!=a.max_coord){var d=(new KVS.Vec3).fromArray(a.max_coord);c.updateMinMaxCoords();c.setMinMaxCoords(c.min_coord,d)}else if(void 0!=a.min_coord&&void 0==a.max_coord){var e=(new KVS.Vec3).fromArray(a.min_coord);c.updateMinMaxCoords();
c.setMinMaxCoords(e,c.max_coord)}else void 0!=a.min_coord&&void 0!=a.max_coord?(e=(new KVS.Vec3).fromArray(a.min_coord),d=(new KVS.Vec3).fromArray(a.max_coord),c.setMinMaxCoords(e,d)):c.updateMinMaxCoords();r(c,a);return c}function r(a,b){if(void 0==b.min_value&&void 0!=b.max_value){var c=b.max_value;a.updateMinMaxValues();a.setMinMaxValues(a.min_value,c)}else if(void 0!=b.min_value&&void 0==b.max_value){var d=b.min_value;a.updateMinMaxValues();a.setMinMaxValues(d,a.max_value)}else void 0!=b.min_value&&
void 0!=b.max_value?(d=b.min_value,c=b.max_value,a.setMinMaxValues(d,c)):a.updateMinMaxValues()}a=JSON.parse(a);switch(a.object){case "PointObject":return b(a,"KVS.JSONLoader");case "LineObject":return d(a,"KVS.JSONLoader");case "PolygonObject":return c(a,"KVS.JSONLoader");case "StructuredVolumeObject":return e(a,"KVS.JSONLoader");case "UnstructuredVolumeObject":return f(a,"KVS.JSONLoader")}console.error("KVS.JSONLoader: Unknown object type is specified in the input file.");return null};KVS.BoundingBox=function(){this.color=new KVS.Vec3;this.width=1};
KVS.BoundingBox.prototype={constructor:KVS.BoundingBox,setColor:function(a){this.color=a},setWidth:function(a){this.width=a},exec:function(a){var b=a.min_coord.x,d=a.min_coord.y,c=a.min_coord.z,e=a.max_coord.x,f=a.max_coord.y,r=a.max_coord.z,l=[b,d,c],h=[e,d,c],g=[e,d,r],d=[b,d,r],q=[b,f,c],c=[e,f,c],e=[e,f,r],b=[b,f,r],f=new KVS.LineObject;f.coords.push(l);f.coords.push(h);f.coords.push(h);f.coords.push(g);f.coords.push(g);f.coords.push(d);f.coords.push(d);f.coords.push(l);f.coords.push(q);f.coords.push(c);
f.coords.push(c);f.coords.push(e);f.coords.push(e);f.coords.push(b);f.coords.push(b);f.coords.push(q);f.coords.push(l);f.coords.push(q);f.coords.push(h);f.coords.push(c);f.coords.push(g);f.coords.push(e);f.coords.push(d);f.coords.push(b);f.line_type=KVS.SegmentLine;f.width=this.width;f.colors.push(this.color.toArray());f.setMinMaxCoords(a.min_coord,a.max_coord);return f}};KVS.ExtractEdge=function(){this.color=new KVS.Vec3;this.width=1};
KVS.ExtractEdge.prototype={constructor:KVS.ExtractEdge,setColor:function(a){this.color=a},setWidth:function(a){this.width=a},exec:function(a){var b=new KVS.LineObject;if(!(a instanceof KVS.UnstructuredVolumeObject)||4!=a.numberOfNodesPerCell())return b;for(var d=a.numberOfCells(),c=0;c<d;c++){var e=a.connections[c],f=a.coords[e[0]],r=a.coords[e[1]],l=a.coords[e[2]],e=a.coords[e[3]];b.coords.push(f);b.coords.push(r);b.coords.push(f);b.coords.push(l);b.coords.push(f);b.coords.push(e);b.coords.push(r);
b.coords.push(l);b.coords.push(l);b.coords.push(e);b.coords.push(e);b.coords.push(r)}b.line_type=KVS.SegmentLine;b.width=this.width;b.colors.push(this.color.toArray());b.setMinMaxCoords(a.min_coord,a.max_coord);return b}};KVS.Isosurface=function(){this.isovalue=0};
KVS.Isosurface.prototype={constructor:KVS.Isosurface,setIsovalue:function(a){this.isovalue=a},exec:function(a){function b(a,b){function d(b){var e=a.numberOfNodesPerLine(),k=a.numberOfNodesPerSlice(),f=b+1,m=f+e,e=b+e;return[b,f,m,e,b+k,f+k,m+k,e+k]}function r(d){var k=a.values[d[1]][0],f=a.values[d[2]][0],m=a.values[d[3]][0],h=a.values[d[4]][0],n=a.values[d[5]][0],p=a.values[d[6]][0],l=a.values[d[7]][0],g=0;a.values[d[0]][0]>b&&(g|=1);k>b&&(g|=2);f>b&&(g|=4);m>b&&(g|=8);h>b&&(g|=16);n>b&&(g|=32);
p>b&&(g|=64);l>b&&(g|=128);return g}function l(b,d,e){function k(b,d,e){var f=a.numberOfNodesPerLine(),g=a.numberOfNodesPerSlice();return b+d*f+e*g}var f=k(b.x,b.y,b.z),g=k(d.x,d.y,d.z),f=a.values[f],f=(e-f)/(a.values[g]-f);e=KVS.Mix(b.x,d.x,f);g=KVS.Mix(b.y,d.y,f);b=KVS.Mix(b.z,d.z,f);return[e,g,b]}var h=new KVS.PolygonObject,g=new KVS.MarchingCubesTable,q=a.min_value,w=a.max_value;b=KVS.Clamp(b,q,w);for(var k=0,p=0;p<a.resolution.z-1;p++){for(var t=0;t<a.resolution.y-1;t++){for(var v=0;v<a.resolution.x-
1;v++){var u=d(k++),u=r(u);if(0!=u&&255!=u)for(var m=0;-1!=g.edgeID[u][m];m+=3){var n=g.edgeID[u][m],s=g.edgeID[u][m+2],x=g.edgeID[u][m+1],y=g.vertexID[n][0],z=g.vertexID[n][1],n=g.vertexID[s][0],A=g.vertexID[s][1],s=g.vertexID[x][0],x=g.vertexID[x][1],y=new KVS.Vec3(v+y[0],t+y[1],p+y[2]),z=new KVS.Vec3(v+z[0],t+z[1],p+z[2]),n=new KVS.Vec3(v+n[0],t+n[1],p+n[2]),A=new KVS.Vec3(v+A[0],t+A[1],p+A[2]),s=new KVS.Vec3(v+s[0],t+s[1],p+s[2]),x=new KVS.Vec3(v+x[0],t+x[1],p+x[2]),y=l(y,z,b),n=l(n,A,b),s=l(s,
x,b);h.coords.push(y);h.coords.push(n);h.coords.push(s)}}k++}k+=a.numberOfNodesPerLine()}g=KVS.RainbowColorMap(q,w,b);h.colors.push(g.toArray());g=h.coords.length/3;for(q=0;q<g;q++)u=[3*q,3*q+1,3*q+2],h.connections.push(u);return h}function d(a,b){function d(k){var f=a.values[k[1]][0],g=a.values[k[2]][0],m=a.values[k[3]][0],h=0;a.values[k[0]][0]>b&&(h|=1);f>b&&(h|=2);g>b&&(h|=4);m>b&&(h|=8);return h}function r(b,d,e){var k=a.coords[b],f=a.coords[d];b=a.values[b][0];b=(e-b)/(a.values[d][0]-b);d=KVS.Mix(k[0],
f[0],b);e=KVS.Mix(k[1],f[1],b);k=KVS.Mix(k[2],f[2],b);return[d,e,k]}var l=new KVS.PolygonObject,h=new KVS.MarchingTetrahedraTable,g=a.min_value,q=a.max_value;b=KVS.Clamp(b,g,q);for(var w=a.connections.length,k=0;k<w;k++){var p=a.connections[k],t=d(p);if(0!=t&&15!=t)for(var v=0;-1!=h.edgeID[t][v];v+=3){var u=h.edgeID[t][v],m=h.edgeID[t][v+1],n=h.edgeID[t][v+2],s=p[h.vertexID[m][0]],x=p[h.vertexID[m][1]],m=p[h.vertexID[n][0]],n=p[h.vertexID[n][1]],u=r(p[h.vertexID[u][0]],p[h.vertexID[u][1]],b),s=r(s,
x,b),m=r(m,n,b);l.coords.push(u);l.coords.push(s);l.coords.push(m)}}p=KVS.RainbowColorMap(g,q,b);l.colors.push(p.toArray());h=l.coords.length/3;for(g=0;g<h;g++)p=[3*g,3*g+1,3*g+2],l.connections.push(p);return l}return a instanceof KVS.StructuredVolumeObject?b(a,this.isovalue):a instanceof KVS.UnstructuredVolumeObject?d(a,this.isovalue):new KVS.PolygonObject}};KVS.MarchingCubesTable=function(){this.edgeID=[[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,8,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,1,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[1,8,3,9,8,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,8,3,1,2,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[9,2,10,0,2,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[2,8,3,2,10,8,10,9,8,-1,-1,-1,-1,-1,-1,-1],[3,11,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,11,2,8,11,0,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1],[1,9,0,2,3,11,-1,-1,-1,-1,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-1,-1,-1,-1,-1,-1,-1],[3,2,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[2,3,8,2,8,10,10,8,9,-1,-1,-1,-1,-1,-1,-1],[9,10,2,0,9,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[2,3,8,2,8,10,0,1,8,1,10,8,
-1,-1,-1,-1],[1,10,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[1,3,8,9,1,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,9,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[0,3,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1]];this.vertexID=[[[0,0,0],[1,0,0]],[[1,0,0],[1,1,0]],[[1,1,0],[0,1,0]],[[0,1,0],[0,0,0]],[[0,0,1],[1,0,1]],[[1,0,1],[1,1,1]],[[1,1,1],[0,1,1]],[[0,1,1],[0,0,1]],[[0,0,0],[0,0,1]],[[1,0,0],[1,0,1]],[[1,1,0],[1,1,1]],[[0,1,0],[0,1,1]]]};KVS.MarchingTetrahedraTable=function(){this.edgeID=[[-1,-1,-1,-1,-1,-1,-1],[2,1,0,-1,-1,-1,-1],[0,3,5,-1,-1,-1,-1],[2,1,3,3,5,2,-1],[4,3,1,-1,-1,-1,-1],[0,2,4,4,3,0,-1],[1,4,5,5,0,1,-1],[4,5,2,-1,-1,-1,-1],[2,5,4,-1,-1,-1,-1],[1,0,5,5,4,1,-1],[0,3,4,4,2,0,-1],[1,3,4,-1,-1,-1,-1],[2,5,3,3,1,2,-1],[5,3,0,-1,-1,-1,-1],[0,1,2,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1,-1]];this.vertexID=[[0,1],[0,2],[0,3],[1,2],[2,3],[3,1]]};KVS.OrthoSlice=function(){this.module=new KVS.SlicePlane};KVS.OrthoSlice.prototype={constructor:KVS.OrthoSlice,setPlane:function(a,b){var d=(new KVS.Mat3).identity().row[b];this.module.setPlaneWithPointAndNormal(d.clone().mul(a),d)},exec:function(a){return this.module.exec(a)}};KVS.SlicePlane=function(){this.coef=new KVS.Vec4};
KVS.SlicePlane.prototype={constructor:KVS.SlicePlane,setPlane:function(){4==arguments.length?this.setPlaneWithCoefficients(arguments[0],arguments[1],arguments[2],arguments[3]):2==arguments.length&&this.setPlaneWithPointAndNormal(arguments[0],arguments[1])},setPlaneWithCoefficients:function(a,b,d,c){this.coef=new KVS.Vec4(a,b,d,c)},setPlaneWithPointAndNormal:function(a,b){var d=a.clone().mulScalar(-1).dot(b);this.coef=new KVS.Vec4(b.x,b.y,b.z,d)},exec:function(a){function b(a,b){function e(a,b,c){var d=
l(a,b,c),e=l(a+1,b,c),k=l(a+1,b+1,c),f=l(a,b+1,c),g=l(a,b,c+1),h=l(a+1,b,c+1),m=l(a+1,b+1,c+1);a=l(a,b+1,c+1);b=0;0<d&&(b|=1);0<e&&(b|=2);0<k&&(b|=4);0<f&&(b|=8);0<g&&(b|=16);0<h&&(b|=32);0<m&&(b|=64);0<a&&(b|=128);return b}function f(a,b){var c=l(a.x,a.y,a.z),d=l(b.x,b.y,b.z),e=Math.abs(c/(d-c)),c=KVS.Mix(a.x,b.x,e),d=KVS.Mix(a.y,b.y,e),e=KVS.Mix(a.z,b.z,e);return[c,d,e]}function r(b,c){var e=l(b.x,b.y,b.z),k=l(c.x,c.y,c.z),e=Math.abs(e/(k-e)),k=a.numberOfNodesPerLine(),f=a.numberOfNodesPerSlice();
return KVS.Mix(a.values[Math.floor(b.x+b.y*k+b.z*f)][0],a.values[Math.floor(c.x+c.y*k+c.z*f)][0],e)}function l(a,d,e){return b.x*a+b.y*d+b.z*e+b.w}for(var h=new KVS.PolygonObject,g=new KVS.MarchingCubesTable,q=a.min_value,w=a.max_value,k=0;k<a.resolution.z-1;k++)for(var p=0;p<a.resolution.y-1;p++)for(var t=0;t<a.resolution.x-1;t++){var v=e(t,p,k);if(0!=v&&255!=v)for(var u=0;-1!=g.edgeID[v][u];u+=3){var m=g.edgeID[v][u],n=g.edgeID[v][u+2],s=g.edgeID[v][u+1],x=g.vertexID[m][0],m=g.vertexID[m][1],y=
g.vertexID[n][0],n=g.vertexID[n][1],z=g.vertexID[s][0],s=g.vertexID[s][1],x=new KVS.Vec3(t+x[0],p+x[1],k+x[2]),m=new KVS.Vec3(t+m[0],p+m[1],k+m[2]),y=new KVS.Vec3(t+y[0],p+y[1],k+y[2]),n=new KVS.Vec3(t+n[0],p+n[1],k+n[2]),z=new KVS.Vec3(t+z[0],p+z[1],k+z[2]),s=new KVS.Vec3(t+s[0],p+s[1],k+s[2]),A=f(x,m),B=f(y,n),C=f(z,s);h.coords.push(A);h.coords.push(B);h.coords.push(C);x=r(x,m);m=r(y,n);y=r(z,s);x=KVS.RainbowColorMap(q,w,x);m=KVS.RainbowColorMap(q,w,m);y=KVS.RainbowColorMap(q,w,y);h.colors.push(x.toArray());
h.colors.push(m.toArray());h.colors.push(y.toArray())}}g=h.coords.length/3;for(q=0;q<g;q++)h.connections.push([3*q,3*q+1,3*q+2]);return h}return a instanceof KVS.StructuredVolumeObject?b(a,this.coef):new KVS.PolygonObject}};KVS.Streamline=function(){this.line_width=1;this.seed_point=new KVS.Vec3;this.integration_step_length=.5;this.integration_time=300;this.integration_method=KVS.RungeKutta4;this.integration_direction=KVS.ForwardDirection};
KVS.Streamline.prototype={constructor:KVS.Streamline,setLineWidth:function(a){this.line_width=a},setSeedPoint:function(a){this.seed_point.set(a.x,a.y,a.z)},setIntegrationStepLength:function(a){this.integration_step_length=a},setIntegrationTime:function(a){this.integration_time=a},setIntegrationMethod:function(a){this.integration_method=a},setIntegrationDirection:function(a){this.integration_direction=a},exec:function(a){function b(b){var c=new KVS.Vec3(Math.floor(b.x),Math.floor(b.y),Math.floor(b.z)),
d=function(b){var c=a.numberOfNodesPerLine(),d=a.numberOfNodesPerSlice(),e=b+1,f=e+c,c=b+c;return[b,e,f,c,b+d,e+d,f+d,c+d]}(function(b){var c=a.resolution;return b.x+c.x*b.y+c.x*c.y*b.z}(c));b=function(a){var b=a.x,c=a.y;a=a.z;return[(1-b)*(1-c)*a,b*(1-c)*a,b*c*a,(1-b)*c*a,(1-b)*(1-c)*(1-a),b*(1-c)*(1-a),b*c*(1-a),(1-b)*c*(1-a)]}(b.clone().sub(c));for(var c=new KVS.Vec3,e=0;8>e;e++){var f=(new KVS.Vec3).fromArray(a.values[d[e]]);c.add(f.mulScalar(b[e]))}return c}function d(b){var c=a.resolution.x,
d=a.resolution.y,e=a.resolution.z;return 0>b.x||c-1<b.x||0>b.y||d-1<b.y||0>b.z||e-1<b.z?!1:!0}var c=new KVS.LineObject;if(!(a instanceof KVS.StructuredVolumeObject&&3==a.vectorLength()&&d(this.seed_point)))return c;var e=this.seed_point,f=[],r=[],l=b(e),l=KVS.RainbowColorMap(a.min_value,a.max_value,l.length());f.push(e.toArray());r.push(l.toArray());for(var h=this.integration_method,g=[function(a,c){var d=b(a).normalize().mulScalar(c);return a.clone().add(d)},function(a,c){var e=b(a).normalize().mulScalar(c),
e=a.clone().add(e.clone().divScalar(2));if(!d(e))return a;e=b(e).normalize().mulScalar(c);return a.clone().add(e)},function(a,c){var e=b(a).normalize().mulScalar(c),f=a.clone().add(e.clone().divScalar(2));if(!d(f))return a;var f=b(f).normalize().mulScalar(c),g=a.clone().add(f.clone().divScalar(2));if(!d(g))return a;var g=b(g).normalize().mulScalar(c),h=a.clone().add(g);if(!d(h))return a;h=b(h).normalize().mulScalar(c);f=f.clone().add(g).mulScalar(2);e=e.clone().add(f).add(h).divScalar(6);return a.clone().add(e)}],
q=this.integration_step_length*this.integration_direction,w=0;w<this.integration_time;w++){e=(0,g[h])(e,q);if(!d(e))break;l=b(e);l=KVS.RainbowColorMap(a.min_value,a.max_value,l.length());f.push(e.toArray());r.push(l.toArray())}c.line_type=KVS.StripLine;c.width=this.line_width;c.coords=f;c.colors=r;c.min_coord=a.min_coord;c.max_coord=a.max_coord;return c}};KVS.TetrahedraCell=function(a,b){this.volume=a;this.cell_coords=[];this.cell_values=[];this.interpolation_functions=[];void 0!=b&&this.bind(b)};
KVS.TetrahedraCell.prototype={constructor:KVS.TetrahedraCell,bind:function(a){this.cell_coords=[];this.cell_values=[];this.interpolation_functions=[];a=this.volume.connections[a];for(var b=0;b<a.length;b++)this.cell_coords.push(this.volume.coords[a[b]]),this.cell_values.push(this.volume.values[a[b]]),this.interpolation_functions.push(0)},setLocalPoint:function(a){this.updateInterpolationFunctions(a)},localToGlobal:function(a){this.setLocalPoint(a);for(var b=a=0,d=0,c=this.interpolation_functions,
e=0;e<this.cell_coords.length;e++)a+=this.cell_coords[e][0]*c[e],b+=this.cell_coords[e][1]*c[e],d+=this.cell_coords[e][2]*c[e];return new KVS.Vec3(a,b,d)},globalToLocal:function(a){var b=(new KVS.Vec3).fromArray(this.cell_coords[3]);return this.jacobian().inverted().mulVec(a.clone().sub(b))},volume:function(){return Math.Abs(this.jacobian().determinant())/6},value:function(){for(var a=this.interpolation_functions,b=this.cell_values.length,d=this.cell_values[0].length,c=[],e=0;e<d;e++)for(var f=c[e]=
0;f<b;f++)c[e]+=this.cell_values[f][e]*a[f];return c},gradient:function(){var a=new KVS.Vec3(this.cells_values[0][0]-this.cells_values[3][0],this.cells_values[1][0]-this.cells_values[3][0],this.cells_values[2][0]-this.cells_values[3][0]);return this.jacobian().inverted().transposed().mulVec(a)},randomSampling:function(){var a=Math.random(),b=Math.random(),d=Math.random(),c,e;1>=a+b+d?(c=a,e=b,a=d):1<=a-b+d?(c=-d+1,e=-a+1,a=b):1<=a+b-d?(c=-a+1,e=-b+1,a=d):1<=-a+b+d?(c=-d+1,e=a,a=-b+1):(c=.5*a-.5*b-
.5*d+.5,e=-.5*a+.5*b-.5*d+.5,a=-.5*a-.5*b+.5*d+.5);c=new KVS.Vec3(c,e,a);return this.localToGlobal(c)},updateInterpolationFunctions:function(a){var b=a.x,d=a.y;a=a.z;var c=this.interpolation_functions;c[0]=b;c[1]=d;c[2]=a;c[3]=1-b-d-a},jacobian:function(){var a=(new KVS.Vec3).fromArray(this.cell_coords[0]),b=(new KVS.Vec3).fromArray(this.cell_coords[1]),d=(new KVS.Vec3).fromArray(this.cell_coords[2]),c=(new KVS.Vec3).fromArray(this.cell_coords[3]),a=a.sub(c).toArray(),b=b.sub(c).toArray(),d=d.sub(c).toArray();
return(new KVS.Mat3).fromArray2D([a,b,d])}};KVS.UniformGrid=function(a,b){this.volume=a;this.base_indices=new KVS.Vec3(-1,-1,-1);this.values=[[],[],[],[],[],[],[],[]];this.interpolation_functions=[0,0,0,0,0,0,0,0];void 0!=b&&this.bind(b)};
KVS.UniformGrid.prototype={constructor:KVS.UniformGrid,bind:function(a){this.base_indices=this.baseIndicesOf(a);var b=this.volume.numberOfNodesPerLine(),d=this.volume.numberOfNodesPerSlice();a=[0,0,0,0,0,0,0,0];a[0]=this.base_indices.x+this.base_indices.y*b+this.base_indices.z*d;a[1]=a[0]+1;a[2]=a[1]+b;a[3]=a[0]+b;a[4]=a[0]+d;a[5]=a[1]+d;a[6]=a[2]+d;a[7]=a[3]+d;for(b=0;b<a.length;b++)this.values[b]=this.volume.values[a[b]],this.interpolation_functions[b]=0},setLocalPoint:function(a){this.updateInterpolationFunctions(a)},
globalToLocal:function(a){return new KVS.Vec3(a.x-this.base_indices.x,a.y-this.base_indices.y,a.z-this.base_indices.z)},value:function(){for(var a=this.interpolation_functions,b=this.values.length,d=this.values[0].length,c=[],e=0;e<d;e++)for(var f=c[e]=0;f<b;f++)c[e]+=this.values[f][e]*a[f];return c},updateInterpolationFunctions:function(a){var b=a.x,d=a.y;a=a.z;var c=this.interpolation_functions;c[0]=(1-b)*(1-d)*a;c[1]=b*(1-d)*a;c[2]=b*d*a;c[3]=(1-b)*d*a;c[4]=(1-b)*(1-d)*(1-a);c[5]=b*(1-d)*(1-a);
c[6]=b*d*(1-a);c[7]=(1-b)*d*(1-a)},findGrid:function(a){var b=this.volume.resolution;return 0>a.x||a.x>=b.x-1||0>a.y||a.y>=b.y-1||0>a.z||a.z>=b.z-1?-1:this.gridIndexOf(new KVS.Vec3(Math.floor(a.x),Math.floor(a.y),Math.floor(a.z)))},gridIndexOf:function(a){var b=this.volume.resolution.x-1;return a.x+a.y*b+a.z*b*(this.volume.resolution.y-1)},baseIndicesOf:function(a){var b=this.volume.resolution.x-1,d=b*(this.volume.resolution.y-1);return new KVS.Vec3(Math.floor(a%d%b),Math.floor(a%d/b),Math.floor(a/
d))}};KVS.VectorMagnitude=function(){};KVS.VectorMagnitude.prototype={constructor:KVS.VectorMagnitude,exec:function(a){if(3!=a.vectorLength())return a;var b=new KVS.StructuredVolumeObject;b.resolution=a.resolution;for(var d=[],c=a.numberOfNodes(),e=0;e<c;e++){var f=(new KVS.Vec3).fromArray(a.values[e]).length();d.push([f])}b.values=d;b.min_coord=a.min_coord;b.max_coord=a.max_coord;b.min_value=a.min_value;b.max_value=a.max_value;return b}};KVS.Mat3=function(a,b,d,c,e,f,r,l,h){this.row=[];this.row[0]=new KVS.Vec3(a,b,d);this.row[1]=new KVS.Vec3(c,e,f);this.row[2]=new KVS.Vec3(r,l,h)};
KVS.Mat3.prototype={constructor:KVS.Mat3,clone:function(){return new KVS.Mat3(this.row[0].x,this.row[0].y,this.row[0].z,this.row[1].x,this.row[1].y,this.row[1].z,this.row[2].x,this.row[2].y,this.row[2].z)},copy:function(a){this.row[0].copy(a.row[0]);this.row[1].copy(a.row[1]);this.row[2].copy(a.row[2])},swap:function(a){this.row[0].swap(a.row[0]);this.row[1].swap(a.row[1]);this.row[2].swap(a.row[2]);return this},set:function(a,b,d,c,e,f,r,l,h){this.row[0].set(a,b,d);this.row[1].set(c,e,f);this.row[2].set(r,
l,h);return this},fromArray:function(a){this.row[0].set(a[0],a[1],a[2]);this.row[1].set(a[3],a[4],a[5]);this.row[2].set(a[6],a[7],a[8]);return this},fromArray2D:function(a){this.row[0].fromArray(a[0]);this.row[1].fromArray(a[1]);this.row[2].fromArray(a[2])},toArray:function(){return[this.row[0].x,this.row[0].y,this.row[0].z,this.row[1].x,this.row[1].y,this.row[1].z,this.row[2].x,this.row[2].y,this.row[2].z]},toArray2D:function(){return[this.row[0].toArray(),this.row[1].toArray(),this.row[2].toArray()]},
add:function(a){this.row[0].add(a.row[0]);this.row[1].add(a.row[1]);this.row[2].add(a.row[2]);return this},sub:function(a){this.row[0].sub(a.row[0]);this.row[1].sub(a.row[1]);this.row[2].sub(a.row[2]);return this},mul:function(a){this.row[0].x=this.row[0].x*a.row[0].x+this.row[0].y*a.row[1].x+this.row[0].z*a.row[2].x;this.row[0].y=this.row[0].x*a.row[0].y+this.row[0].y*a.row[1].y+this.row[0].z*a.row[2].y;this.row[0].z=this.row[0].x*a.row[0].z+this.row[0].y*a.row[1].z+this.row[0].z*a.row[2].z;this.row[1].x=
this.row[1].x*a.row[0].x+this.row[1].y*a.row[1].x+this.row[1].z*a.row[2].x;this.row[1].y=this.row[1].x*a.row[0].y+this.row[1].y*a.row[1].y+this.row[1].z*a.row[2].y;this.row[1].z=this.row[1].x*a.row[0].z+this.row[1].y*a.row[1].z+this.row[1].z*a.row[2].z;this.row[2].x=this.row[2].x*a.row[0].x+this.row[2].y*a.row[1].x+this.row[2].z*a.row[2].x;this.row[2].y=this.row[2].x*a.row[0].y+this.row[2].y*a.row[1].y+this.row[2].z*a.row[2].y;this.row[2].z=this.row[2].x*a.row[0].z+this.row[2].y*a.row[1].z+this.row[2].z*
a.row[2].z;return this},mulVec:function(a){return new KVS.Vec3(this.row[0].dot(a),this.row[1].dot(a),this.row[2].dot(a))},mulScalar:function(a){this.row[0].mulScalar(a);this.row[1].mulScalar(a);this.row[2].mulScalar(a);return this},divScalar:function(a){this.row[0].divScalar(a);this.row[1].divScalar(a);this.row[2].divScalar(a);return this},zero:function(){this.row[0].set(0,0,0);this.row[1].set(0,0,0);this.row[2].set(0,0,0);return this},identity:function(){this.row[0].set(1,0,0);this.row[1].set(0,
1,0);this.row[2].set(0,0,1);return this},transpose:function(){KVS.Swap(this.row[0].y,this.row[1].x);KVS.Swap(this.row[0].z,this.row[2].x);KVS.Swap(this.row[1].z,this.row[2].y);return this},invert:function(a){a=[this.row[1].y*this.row[2].z-this.row[1].z*this.row[2].y,this.row[1].x*this.row[2].z-this.row[1].z*this.row[2].x,this.row[1].x*this.row[2].y-this.row[1].y*this.row[2].x,this.row[0].y*this.row[2].z-this.row[0].z*this.row[2].y,this.row[0].x*this.row[2].z-this.row[0].z*this.row[2].x,this.row[0].x*
this.row[2].y-this.row[0].y*this.row[2].x,this.row[0].y*this.row[1].z-this.row[0].z*this.row[1].y,this.row[0].x*this.row[1].z-this.row[0].z*this.row[1].x,this.row[0].x*this.row[1].y-this.row[0].y*this.row[1].x];var b=this.row[0].x*a[0]-this.row[0].y*a[1]+this.row[0].z*a[2];this.set(a[0],-a[3],a[6],-a[1],a[4],-a[7],a[2],-a[5],a[8]);this.divScalar(b);return this},trace:function(){return this.row[0].x+this.row[1].y+this.row[2].z},determinant:function(){return this.row[0].clone().cross(this.row[1]).dot(this.row[2])},
transposed:function(){return this.clone().transpose()},inverted:function(){return this.clone().invert()},min:function(){return Math.min(this.row[0].min(),Math.min(this.row[1].min(),this.row[2].min()))},max:function(){return Math.max(this.row[0].max(),Math.max(this.row[1].max(),this.row[2].max()))}};KVS.Vec3=function(a,b,d){this.x=a||0;this.y=b||0;this.z=d||0};
KVS.Vec3.prototype={constructor:KVS.Vec3,clone:function(){return new KVS.Vec3(this.x,this.y,this.z)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},swap:function(a){KVS.Swap(this.x,a.x);KVS.Swap(this.y,a.y);KVS.Swap(this.z,a.z);return this},set:function(a,b,d){this.x=a;this.y=b;this.z=d;return this},fromArray:function(a){this.x=a[0];this.y=a[1];this.z=a[2];return this},toArray:function(){return[this.x,this.y,this.z]},add:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},
sub:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},mul:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},mulScalar:function(a){this.x*=a;this.y*=a;this.z*=a;return this},div:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divScalar:function(a){this.x/=a;this.y/=a;this.z/=a;return this},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},normalize:function(){return this.divScalar(this.length())},min:function(){return Math.min(this.x,
Math.min(this.y,this.z))},max:function(){return Math.max(this.x,Math.max(this.y,this.z))},cross:function(a){var b=this.x,d=this.y,c=this.z;this.x=d*a.z-c*a.y;this.y=c*a.x-b*a.z;this.z=b*a.y-d*a.x;return this},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z}};KVS.Vec4=function(a,b,d,c){this.x=a||0;this.y=b||0;this.z=d||0;this.w=c||0};
KVS.Vec4.prototype={constructor:KVS.Vec4,clone:function(){return new KVS.Vec4(this.x,this.y,this.z,this.w)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;this.w=a.w;return this},swap:function(a){KVS.Swap(this.x,a.x);KVS.Swap(this.y,a.y);KVS.Swap(this.z,a.z);KVS.Swap(this.w,a.w);return this},set:function(a,b,d,c){this.x=a;this.y=b;this.z=d;this.w=c;return this},fromArray:function(a){this.x=a[0];this.y=a[1];this.z=a[2];this.w=a[3];return this},toArray:function(){return[this.x,this.y,this.z,this.w]},
add:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;this.w+=a.w;return this},sub:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;this.w-=a.w;return this},mul:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;this.w*=a.w;return this},mulScalar:function(a){this.x*=a;this.y*=a;this.z*=a;this.w*=a;return this},div:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;this.w/=a.w;return this},divScalar:function(a){this.x/=a;this.y/=a;this.z/=a;this.w/=a;return this},length:function(){return Math.sqrt(this.x*this.x+
this.y*this.y+this.z*this.z+this.w*this.w)},normalize:function(){return this.divScalar(this.length())},min:function(){return Math.min(this.x,Math.min(this.y,Math.min(this.z,this.w)))},max:function(){return Math.max(this.x,Math.max(this.y,Math.max(this.z,this.w)))},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z+this.w*a.w}};KVS.LineObject=function(){this.line_type=KVS.StripLine;this.width=1;this.coords=[];this.colors=[];this.min_coord=new KVS.Vec3;this.max_coord=new KVS.Vec3};
KVS.LineObject.prototype={constructor:KVS.LineObject,numberOfVertices:function(){return this.coords.length},updateMinMaxCoords:function(){for(var a=(new KVS.Vec3).fromArray(this.coords[0]),b=(new KVS.Vec3).fromArray(this.coords[0]),d=this.numberOfVertices(),c=0;c<d;c++)var e=(new KVS.Vec3).fromArray(this.coords[c]),a=KVS.Min(a,e),b=KVS.Max(b,e);this.min_coord=a;this.max_coord=b},objectCenter:function(){return this.min_coord.clone().add(this.max_coord).divScalar(2)},setMinMaxCoords:function(a,b){this.min_coord=
a;this.max_coord=b}};KVS.PointObject=function(){this.size=1;this.coords=[];this.colors=[];this.min_coord=new KVS.Vec3;this.max_coord=new KVS.Vec3};
KVS.PointObject.prototype={constructor:KVS.PointObject,numberOfVertices:function(){return this.coords.length},updateMinMaxCoords:function(){for(var a=(new KVS.Vec3).fromArray(this.coords[0]),b=(new KVS.Vec3).fromArray(this.coords[0]),d=this.numberOfVertices(),c=0;c<d;c++)var e=(new KVS.Vec3).fromArray(this.coords[c]),a=KVS.Min(a,e),b=KVS.Max(b,e);this.min_coord=a;this.max_coord=b},objectCenter:function(){return this.min_coord.clone().add(this.max_coord).divScalar(2)}};KVS.PolygonObject=function(){this.coords=[];this.colors=[];this.connections=[];this.min_coord=new KVS.Vec3;this.max_coord=new KVS.Vec3};
KVS.PolygonObject.prototype={constructor:KVS.PolygonObject,numberOfVertices:function(){return this.coords.length},updateMinMaxCoords:function(){for(var a=(new KVS.Vec3).fromArray(this.coords[0]),b=(new KVS.Vec3).fromArray(this.coords[0]),d=this.numberOfVertices(),c=0;c<d;c++)var e=(new KVS.Vec3).fromArray(this.coords[c]),a=KVS.Min(a,e),b=KVS.Max(b,e);this.min_coord=a;this.max_coord=b},objectCenter:function(){return this.min_coord.clone().add(this.max_coord).divScalar(2)},setMinMaxCoords:function(a,
b){this.min_coord=a;this.max_coord=b}};KVS.StructuredVolumeObject=function(){this.resolution=new KVS.Vec3;this.values=[];this.min_coord=new KVS.Vec3;this.max_coord=new KVS.Vec3;this.max_value=this.min_value=0};
KVS.StructuredVolumeObject.prototype={constructor:KVS.StructuredVolumeObject,vectorLength:function(){return this.values[0].length},numberOfNodes:function(){return this.resolution.x*this.resolution.y*this.resolution.z},numberOfNodesPerLine:function(){return this.resolution.x},numberOfNodesPerSlice:function(){return this.resolution.x*this.resolution.y},numberOfNodesPerCell:function(){return 8},numberOfCells:function(){return(this.resolution.x-1)*(this.resolution.y-1)*(this.resolution.z-1)},updateMinMaxCoords:function(){var a=
new KVS.Vec3(0,0,0),b=this.resolution.clone().sub(new KVS.Vec3(1,1,1));this.min_coord=a;this.max_coord=b},updateMinMaxValues:function(){var a=0,b=0;if(1==this.vectorLength())for(var a=this.values[0][0],b=this.values[0][0],d=this.numberOfNodes(),c=0;c<d;c++)var e=this.values[c][0],a=Math.min(a,e),b=Math.max(b,e);else if(3==this.vectorLength())for(a=(new KVS.Vec3).fromArray(this.values[0]).length(),b=(new KVS.Vec3).fromArray(this.values[0]).length(),d=this.numberOfNodes(),c=0;c<d;c++)e=(new KVS.Vec3).fromArray(this.values[c]).length(),
a=Math.min(a,e),b=Math.max(b,e);this.min_value=a;this.max_value=b},objectCenter:function(){return this.min_coord.clone().add(this.max_coord).divScalar(2)},setMinMaxCoords:function(a,b){this.min_coord=a;this.max_coord=b},setMinMaxValues:function(a,b){this.min_value=a;this.max_value=b}};KVS.UnstructuredVolumeObject=function(){this.coords=[];this.connections=[];this.values=[];this.min_coord=new KVS.Vec3;this.max_coord=new KVS.Vec3;this.max_value=this.min_value=0};
KVS.UnstructuredVolumeObject.prototype={constructor:KVS.UnstructuredVolumeObject,vectorLength:function(){return this.values[0].length},numberOfNodes:function(){return this.coords.length},numberOfNodesPerCell:function(){return this.connections[0].length},numberOfCells:function(){return this.connections.length},updateMinMaxCoords:function(){for(var a=(new KVS.Vec3).fromArray(this.coords[0]),b=(new KVS.Vec3).fromArray(this.coords[0]),d=this.numberOfNodes(),c=0;c<d;c++)var e=(new KVS.Vec3).fromArray(this.coords[c]),
a=KVS.Min(a,e),b=KVS.Max(b,e);this.min_coord=a;this.max_coord=b},updateMinMaxValues:function(){var a=0,b=0;if(1==this.vectorLength())for(var a=this.values[0][0],b=this.values[0][0],d=this.numberOfNodes(),c=0;c<d;c++)var e=this.values[c][0],a=Math.min(a,e),b=Math.max(b,e);else if(3==this.vectorLength())for(a=(new KVS.Vec3).fromArray(this.values[0]).length(),b=(new KVS.Vec3).fromArray(this.values[0]).length(),d=this.numberOfNodes(),c=0;c<d;c++)e=(new KVS.Vec3).fromArray(this.values[c]).length(),a=Math.min(a,
e),b=Math.max(b,e);this.min_value=a;this.max_value=b},objectCenter:function(){return this.min_coord.clone().add(this.max_coord).divScalar(2)},setMinMaxCoords:function(a,b){this.min_coord=a;this.max_coord=b},setMinMaxValues:function(a,b){this.min_value=a;this.max_value=b}};KVS.Hash=function(){this.bucket={}};KVS.Hash.prototype={constructor:KVS.Hash,insert:function(a,b){this.bucket[a]=b},find:function(a){return this.bucket[a]},remove:function(a){delete this.bucket[a]},contains:function(a){return this.bucket.hasOwnProperty(a)},each:function(a){for(var b in this.bucket)a(b)}};KVS.Queue=function(){this.bucket=[]};KVS.Queue.prototype={constructor:KVS.Queue,enqueue:function(a){this.bucket.push(a)},dequeue:function(){return this.bucket.shift()},size:function(){return this.bucket.length},peek:function(){return 0<this.bucket.length?this.bucket[0]:null},empty:function(){return 0==this.bucket.length}};