@niivue/niivue 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/niivue.es.js +60 -22
- package/dist/niivue.umd.js +13 -16
- package/package.json +1 -1
- package/src/niivue.js +11 -26
- package/src/nvimage.js +89 -1
- package/src/shader-srcs.js +4 -7
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ We host many NiiVue examples via github pages. These are updated and deployed au
|
|
|
38
38
|
|
|
39
39
|
## existing html page
|
|
40
40
|
```html
|
|
41
|
-
<script src="https://unpkg.com/@niivue/niivue@0.20.
|
|
41
|
+
<script src="https://unpkg.com/@niivue/niivue@0.20.1/dist/niivue.umd.js"></script>
|
|
42
42
|
|
|
43
43
|
<canvas id="gl" height=480 width=640></canvas>
|
|
44
44
|
|
package/dist/niivue.es.js
CHANGED
|
@@ -902,13 +902,11 @@ uniform lowp sampler3D blend3D;
|
|
|
902
902
|
uniform float opacity;
|
|
903
903
|
uniform mat4 mtx;
|
|
904
904
|
uniform bool hasAlpha;
|
|
905
|
-
|
|
906
905
|
void main(void) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
FragColor = vec4(float(aColor.r) / 255.0f, float(aColor.g) / 255.0f, float(aColor.b) / 255.0f, a);
|
|
906
|
+
uvec4 aColor = texture(intensityVol, vec3(TexCoord.xy, coordZ));
|
|
907
|
+
FragColor = vec4(float(aColor.r) / 255.0, float(aColor.g) / 255.0, float(aColor.b) / 255.0, float(aColor.a) / 255.0);
|
|
908
|
+
if (!hasAlpha)
|
|
909
|
+
FragColor.a = (FragColor.r * 0.21 + FragColor.g * 0.72 + FragColor.b * 0.07);
|
|
912
910
|
FragColor.a *= opacity;
|
|
913
911
|
}`;
|
|
914
912
|
var vertPassThroughShader = `#version 300 es
|
|
@@ -952,7 +950,6 @@ in vec3 texCoords;
|
|
|
952
950
|
uniform mat4 mvpMtx;
|
|
953
951
|
out vec3 posColor;
|
|
954
952
|
void main(void) {
|
|
955
|
-
// gl_Position = mvpMtx * vec4(pos, 1.0); // mvpMtx * vec4(2.0 * (pos.xyz - 0.5), 1.0);
|
|
956
953
|
gl_Position = mvpMtx * vec4(pos, 1.0);
|
|
957
954
|
posColor = texCoords;
|
|
958
955
|
}`;
|
|
@@ -10496,6 +10493,38 @@ var NVImage = function(dataBuffer, name = "", colorMap = "gray", opacity = 1, tr
|
|
|
10496
10493
|
case this.DT_RGBA32:
|
|
10497
10494
|
this.img = new Uint8Array(imgRaw);
|
|
10498
10495
|
break;
|
|
10496
|
+
case this.DT_INT8:
|
|
10497
|
+
let i8 = new Int8Array(imgRaw);
|
|
10498
|
+
var vx8 = i8.length;
|
|
10499
|
+
this.img = new Int16Array(vx8);
|
|
10500
|
+
for (var i = 0; i < vx8 - 1; i++)
|
|
10501
|
+
this.img[i] = i8[i];
|
|
10502
|
+
this.hdr.datatypeCode = this.DT_SIGNED_SHORT;
|
|
10503
|
+
break;
|
|
10504
|
+
case this.DT_UINT32:
|
|
10505
|
+
let u32 = new Uint32Array(imgRaw);
|
|
10506
|
+
var vx32 = u32.length;
|
|
10507
|
+
this.img = new Float64Array(vx32);
|
|
10508
|
+
for (var i = 0; i < vx32 - 1; i++)
|
|
10509
|
+
this.img[i] = u32[i];
|
|
10510
|
+
this.hdr.datatypeCode = this.DT_DOUBLE;
|
|
10511
|
+
break;
|
|
10512
|
+
case this.DT_SIGNED_INT:
|
|
10513
|
+
let i32 = new Int32Array(imgRaw);
|
|
10514
|
+
var vxi32 = i32.length;
|
|
10515
|
+
this.img = new Float64Array(vxi32);
|
|
10516
|
+
for (var i = 0; i < vxi32 - 1; i++)
|
|
10517
|
+
this.img[i] = i32[i];
|
|
10518
|
+
this.hdr.datatypeCode = this.DT_DOUBLE;
|
|
10519
|
+
break;
|
|
10520
|
+
case this.DT_INT64:
|
|
10521
|
+
let i64 = new BigInt64Array(imgRaw);
|
|
10522
|
+
let vx = i64.length;
|
|
10523
|
+
this.img = new Float64Array(vx);
|
|
10524
|
+
for (var i = 0; i < vx - 1; i++)
|
|
10525
|
+
this.img[i] = Number(i64[i]);
|
|
10526
|
+
this.hdr.datatypeCode = this.DT_DOUBLE;
|
|
10527
|
+
break;
|
|
10499
10528
|
default:
|
|
10500
10529
|
throw "datatype " + this.hdr.datatypeCode + " not supported";
|
|
10501
10530
|
}
|
|
@@ -10845,19 +10874,31 @@ String.prototype.getBytes = function() {
|
|
|
10845
10874
|
};
|
|
10846
10875
|
NVImage.prototype.getValue = function(x, y, z) {
|
|
10847
10876
|
const { nx, ny } = this.getImageMetadata();
|
|
10877
|
+
if (this.hdr.datatypeCode === this.DT_RGBA32) {
|
|
10878
|
+
let vx = 4 * (x + y * nx + z * nx * ny);
|
|
10879
|
+
return Math.round(this.img[vx] * 0.21 + this.img[vx + 1] * 0.72 + this.img[vx + 2] * 0.07);
|
|
10880
|
+
}
|
|
10881
|
+
if (this.hdr.datatypeCode === this.DT_RGB) {
|
|
10882
|
+
let vx = 3 * (x + y * nx + z * nx * ny);
|
|
10883
|
+
return Math.round(this.img[vx] * 0.21 + this.img[vx + 1] * 0.72 + this.img[vx + 2] * 0.07);
|
|
10884
|
+
}
|
|
10848
10885
|
return this.img[x + y * nx + z * nx * ny];
|
|
10849
10886
|
};
|
|
10850
10887
|
function getExtents(positions) {
|
|
10851
10888
|
const min2 = positions.slice(0, 3);
|
|
10852
10889
|
const max2 = positions.slice(0, 3);
|
|
10890
|
+
let mxDx = 0;
|
|
10853
10891
|
for (let i = 3; i < positions.length; i += 3) {
|
|
10854
10892
|
for (let j = 0; j < 3; ++j) {
|
|
10855
10893
|
const v = positions[i + j];
|
|
10856
10894
|
min2[j] = Math.min(v, min2[j]);
|
|
10857
10895
|
max2[j] = Math.max(v, max2[j]);
|
|
10858
10896
|
}
|
|
10897
|
+
let dx = positions[i] * positions[i] + positions[i + 1] * positions[i + 1] + positions[i + 2] * positions[i + 2];
|
|
10898
|
+
mxDx = Math.max(mxDx, dx);
|
|
10859
10899
|
}
|
|
10860
|
-
|
|
10900
|
+
let furthestVertexFromOrigin = Math.sqrt(mxDx);
|
|
10901
|
+
return { min: min2, max: max2, furthestVertexFromOrigin };
|
|
10861
10902
|
}
|
|
10862
10903
|
NVImage.prototype.method1 = function() {
|
|
10863
10904
|
return {
|
|
@@ -11099,6 +11140,7 @@ NVImage.prototype.toNiivueObject3D = function(id, gl) {
|
|
|
11099
11140
|
const extents = getExtents(positions);
|
|
11100
11141
|
obj3D.extentsMin = extents.min;
|
|
11101
11142
|
obj3D.extentsMax = extents.max;
|
|
11143
|
+
obj3D.furthestVertexFromOrigin = extents.furthestVertexFromOrigin;
|
|
11102
11144
|
return obj3D;
|
|
11103
11145
|
};
|
|
11104
11146
|
const Log = function(logLevel) {
|
|
@@ -12713,8 +12755,8 @@ const Niivue = function(options = {}) {
|
|
|
12713
12755
|
this.sliceTypeRender = 4;
|
|
12714
12756
|
this.sliceType = this.sliceTypeMultiplanar;
|
|
12715
12757
|
this.scene = {};
|
|
12716
|
-
this.scene.renderAzimuth =
|
|
12717
|
-
this.scene.renderElevation =
|
|
12758
|
+
this.scene.renderAzimuth = 110;
|
|
12759
|
+
this.scene.renderElevation = 15;
|
|
12718
12760
|
this.scene.crosshairPos = [0.5, 0.5, 0.5];
|
|
12719
12761
|
this.scene.clipPlane = [0, 0, 0, 0];
|
|
12720
12762
|
this.scene.mousedown = false;
|
|
@@ -13674,36 +13716,36 @@ Niivue.prototype.refreshLayers = function(overlayItem, layer, numLayers) {
|
|
|
13674
13716
|
this.gl.pixelStorei(this.gl.UNPACK_ALIGNMENT, 1);
|
|
13675
13717
|
let orientShader = this.orientShaderU;
|
|
13676
13718
|
if (hdr.datatypeCode === 2) {
|
|
13677
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13719
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.R8UI, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13678
13720
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RED_INTEGER, this.gl.UNSIGNED_BYTE, img);
|
|
13679
13721
|
} else if (hdr.datatypeCode === 4) {
|
|
13680
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13722
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.R16I, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13681
13723
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RED_INTEGER, this.gl.SHORT, img);
|
|
13682
13724
|
orientShader = this.orientShaderI;
|
|
13683
13725
|
} else if (hdr.datatypeCode === 16) {
|
|
13684
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13726
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.R32F, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13685
13727
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RED, this.gl.FLOAT, img);
|
|
13686
13728
|
orientShader = this.orientShaderF;
|
|
13687
13729
|
} else if (hdr.datatypeCode === 64) {
|
|
13688
13730
|
let img32f = new Float32Array();
|
|
13689
13731
|
img32f = Float32Array.from(img);
|
|
13690
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13732
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.R32F, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13691
13733
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RED, this.gl.FLOAT, img32f);
|
|
13692
13734
|
orientShader = this.orientShaderF;
|
|
13693
13735
|
} else if (hdr.datatypeCode === 128) {
|
|
13694
13736
|
orientShader = this.orientShaderRGBU;
|
|
13695
13737
|
orientShader.use(this.gl);
|
|
13696
13738
|
this.gl.uniform1i(orientShader.uniforms["hasAlpha"], false);
|
|
13697
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13739
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.RGB8UI, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13698
13740
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RGB_INTEGER, this.gl.UNSIGNED_BYTE, img);
|
|
13699
13741
|
} else if (hdr.datatypeCode === 512) {
|
|
13700
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13742
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.R16UI, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13701
13743
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RED_INTEGER, this.gl.UNSIGNED_SHORT, img);
|
|
13702
13744
|
} else if (hdr.datatypeCode === 2304) {
|
|
13703
13745
|
orientShader = this.orientShaderRGBU;
|
|
13704
13746
|
orientShader.use(this.gl);
|
|
13705
13747
|
this.gl.uniform1i(orientShader.uniforms["hasAlpha"], true);
|
|
13706
|
-
this.gl.texStorage3D(this.gl.TEXTURE_3D,
|
|
13748
|
+
this.gl.texStorage3D(this.gl.TEXTURE_3D, 1, this.gl.RGBA8UI, hdr.dims[1], hdr.dims[2], hdr.dims[3]);
|
|
13707
13749
|
this.gl.texSubImage3D(this.gl.TEXTURE_3D, 0, 0, 0, 0, hdr.dims[1], hdr.dims[2], hdr.dims[3], this.gl.RGBA_INTEGER, this.gl.UNSIGNED_BYTE, img);
|
|
13708
13750
|
}
|
|
13709
13751
|
if (overlayItem.global_min === void 0) {
|
|
@@ -14116,11 +14158,7 @@ Niivue.prototype.calculateMvpMatrix = function(object3D) {
|
|
|
14116
14158
|
}
|
|
14117
14159
|
let whratio = this.gl.canvas.clientWidth / this.gl.canvas.clientHeight;
|
|
14118
14160
|
let projectionMatrix = create$2();
|
|
14119
|
-
let
|
|
14120
|
-
let dy = Math.max(Math.abs(object3D.extentsMax[1]), Math.abs(object3D.extentsMin[1]));
|
|
14121
|
-
let dz = Math.max(Math.abs(object3D.extentsMax[2]), Math.abs(object3D.extentsMin[2]));
|
|
14122
|
-
let furthestVertexFromOrigin = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
|
14123
|
-
let scale = 0.7 * furthestVertexFromOrigin * 1 / this.volScaleMultiplier;
|
|
14161
|
+
let scale = 0.7 * object3D.furthestVertexFromOrigin * 1 / this.volScaleMultiplier;
|
|
14124
14162
|
if (whratio < 1)
|
|
14125
14163
|
ortho(projectionMatrix, -scale, scale, -scale / whratio, scale / whratio, 0.01, scale * 8);
|
|
14126
14164
|
else
|