zincjs 1.19.0 → 1.19.2
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/package.json
CHANGED
|
@@ -121,6 +121,89 @@ function readNIFTI(data) {
|
|
|
121
121
|
return {niftiHeader: undefined, niftiImage: undefined};
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
|
|
125
|
+
function createSources(niftiHeader, niftiImage, maskHeader, maskImage, options) {
|
|
126
|
+
if (niftiHeader?.dims && niftiHeader.dims[0] === 3) {
|
|
127
|
+
const width = niftiHeader.dims[1];
|
|
128
|
+
const height = niftiHeader.dims[2];
|
|
129
|
+
const depth = niftiHeader.dims[3];
|
|
130
|
+
const { typedData, dataType } = getTypedData(niftiHeader, niftiImage);
|
|
131
|
+
const sliceSize = width * height;
|
|
132
|
+
const length = sliceSize * depth * 4;
|
|
133
|
+
const fullArray = new Uint8Array(length);
|
|
134
|
+
let maskData = undefined;
|
|
135
|
+
if (maskHeader && maskImage) {
|
|
136
|
+
const maskWidth = maskHeader.dims[1];
|
|
137
|
+
const maskHeight = maskHeader.dims[2];
|
|
138
|
+
const maskDepth = maskHeader.dims[3];
|
|
139
|
+
if (maskWidth === width && maskHeight === height && maskDepth === depth) {
|
|
140
|
+
const maskedTypedData = getTypedData(maskHeader, maskImage);
|
|
141
|
+
maskData = maskedTypedData.typedData;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
let slope = niftiHeader.scl_slope || 1;
|
|
145
|
+
let intercept = niftiHeader.scl_inter || 0;
|
|
146
|
+
|
|
147
|
+
let min = Infinity;
|
|
148
|
+
let max = -Infinity;
|
|
149
|
+
|
|
150
|
+
const dataLength = typedData.length;
|
|
151
|
+
for (let i = 0; i < dataLength; i++) {
|
|
152
|
+
let val = (typedData[i] * slope) + intercept;
|
|
153
|
+
if (val < min) min = val;
|
|
154
|
+
if (val > max) max = val;
|
|
155
|
+
}
|
|
156
|
+
let range = max - min;
|
|
157
|
+
|
|
158
|
+
for (let slice = 0; slice < depth; slice++) {
|
|
159
|
+
const sliceOffset = sliceSize * slice;
|
|
160
|
+
for (let row = 0; row < height; row++) {
|
|
161
|
+
const rowOffset = row * width;
|
|
162
|
+
for (let col = 0; col < width; col++) {
|
|
163
|
+
const offset = sliceOffset + rowOffset + col;
|
|
164
|
+
let trueVal = typedData[offset] * slope + intercept;
|
|
165
|
+
let value = 0;
|
|
166
|
+
if (range !== 0) {
|
|
167
|
+
// Map [min, max] to [0, 255]
|
|
168
|
+
value = ((trueVal - min) / range) * 255;
|
|
169
|
+
}
|
|
170
|
+
fullArray[offset * 4] = value;
|
|
171
|
+
fullArray[offset * 4 + 1] = value;
|
|
172
|
+
fullArray[offset * 4 + 2] = value;
|
|
173
|
+
fullArray[offset * 4 + 3] = 255;
|
|
174
|
+
if (maskData) {
|
|
175
|
+
const maskedValue = maskData[offset];
|
|
176
|
+
if (options.hideBlackPixel) {
|
|
177
|
+
//if (maskedValue === 0 && 20 > value) {
|
|
178
|
+
if (maskedValue === 0) {
|
|
179
|
+
fullArray[offset * 4 + 3] = 0;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
} else if (options.filterByValue) {
|
|
183
|
+
if (options.hideWhitePixel && value === 255) {
|
|
184
|
+
fullArray[offset * 4 + 3] = 0;
|
|
185
|
+
}
|
|
186
|
+
if (options.hideBlackPixel && 2 >= value) {
|
|
187
|
+
fullArray[offset * 4] = 240;
|
|
188
|
+
fullArray[offset * 4 + 1] = 240;
|
|
189
|
+
fullArray[offset * 4 + 2] = 240;
|
|
190
|
+
fullArray[offset * 4 + 3] = 1.0;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return {
|
|
198
|
+
data: fullArray,
|
|
199
|
+
width,
|
|
200
|
+
height,
|
|
201
|
+
depth,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
/*
|
|
124
207
|
function createSources(niftiHeader, niftiImage, maskHeader, maskImage, options) {
|
|
125
208
|
if (niftiHeader?.dims && niftiHeader.dims[0] === 3) {
|
|
126
209
|
const width = niftiHeader.dims[1];
|
|
@@ -206,6 +289,8 @@ function createSources(niftiHeader, niftiImage, maskHeader, maskImage, options)
|
|
|
206
289
|
return undefined;
|
|
207
290
|
}
|
|
208
291
|
|
|
292
|
+
*/
|
|
293
|
+
|
|
209
294
|
function getTypedData(niftiHeader, niftiImage) {
|
|
210
295
|
if (niftiHeader.datatypeCode === nifti.NIFTI1.TYPE_UINT8) {
|
|
211
296
|
return { typedData: new Uint8Array(niftiImage), dataType: "uint" };
|
|
@@ -360,9 +445,7 @@ async function createPrimitivesFromNIFTI(url, useHeaderInfo, maskURL, textureSet
|
|
|
360
445
|
}
|
|
361
446
|
if (timeEnabled && textureP) {
|
|
362
447
|
for (let i = 1; i < url.length; i++) {
|
|
363
|
-
console.log(i, url[i])
|
|
364
448
|
const tArray = await createTextureFromNIFTI(url[i], maskURL, optionsIn);
|
|
365
|
-
console.log(tArray)
|
|
366
449
|
textureP.addTextureArray(tArray);
|
|
367
450
|
}
|
|
368
451
|
textureP.timeEnabled = true;
|
|
@@ -47,7 +47,6 @@ const TexturePrimitive = function (textureIn) {
|
|
|
47
47
|
if (this.textureList.length === 0 && this.texture) {
|
|
48
48
|
this.textureList.push(this.texture);
|
|
49
49
|
}
|
|
50
|
-
console.log("addTextureArray", tArray)
|
|
51
50
|
if (tArray && tArray.isTextureArray) {
|
|
52
51
|
this.textureList.push(tArray);
|
|
53
52
|
}
|
|
@@ -415,7 +415,6 @@ const TextureSlides = function (textureIn) {
|
|
|
415
415
|
const t0 = Math.floor(iTime);
|
|
416
416
|
const t1 = Math.ceil(iTime);
|
|
417
417
|
const ratio = iTime - t0;
|
|
418
|
-
console.log("update", t0, t1, ratio)
|
|
419
418
|
this.morph.children.forEach((mesh) => {
|
|
420
419
|
const material = mesh.material;
|
|
421
420
|
if (material.type === "ShaderMaterial") {
|