@kitware/vtk.js 23.2.0 → 23.3.0-beta.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
2
|
import macro from '../../macros.js';
|
|
3
3
|
import vtkAbstractImageInterpolator from './AbstractImageInterpolator.js';
|
|
4
|
-
import { vtkInterpolationMathRound, vtkInterpolationMathClamp, vtkInterpolationMathMirror, vtkInterpolationMathWrap,
|
|
4
|
+
import { vtkInterpolationMathRound, vtkInterpolationMathClamp, vtkInterpolationMathMirror, vtkInterpolationMathWrap, vtkInterpolationMathFloor, vtkInterpolationWeights } from './AbstractImageInterpolator/InterpolationInfo.js';
|
|
5
5
|
import { InterpolationMode, ImageBorderMode } from './AbstractImageInterpolator/Constants.js';
|
|
6
6
|
|
|
7
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
@@ -92,10 +92,80 @@ function vtkImageInterpolator(publicAPI, model) {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
+
publicAPI.interpolateLinear = function (interpolationInfo, point, value) {
|
|
96
|
+
var inExt = interpolationInfo.extent;
|
|
97
|
+
var inInc = interpolationInfo.increments;
|
|
98
|
+
var numscalars = interpolationInfo.numberOfComponents;
|
|
99
|
+
var floorX = vtkInterpolationMathFloor(point[0]);
|
|
100
|
+
var floorY = vtkInterpolationMathFloor(point[1]);
|
|
101
|
+
var floorZ = vtkInterpolationMathFloor(point[2]);
|
|
102
|
+
var inIdX0 = floorX.floored;
|
|
103
|
+
var inIdY0 = floorY.floored;
|
|
104
|
+
var inIdZ0 = floorZ.floored;
|
|
105
|
+
var fx = floorX.error;
|
|
106
|
+
var fy = floorY.error;
|
|
107
|
+
var fz = floorZ.error;
|
|
108
|
+
var inIdX1 = inIdX0 + (fx !== 0);
|
|
109
|
+
var inIdY1 = inIdY0 + (fy !== 0);
|
|
110
|
+
var inIdZ1 = inIdZ0 + (fz !== 0);
|
|
111
|
+
|
|
112
|
+
switch (interpolationInfo.borderMode) {
|
|
113
|
+
case ImageBorderMode.REPEAT:
|
|
114
|
+
inIdX0 = vtkInterpolationMathWrap(inIdX0, inExt[0], inExt[1]);
|
|
115
|
+
inIdY0 = vtkInterpolationMathWrap(inIdY0, inExt[2], inExt[3]);
|
|
116
|
+
inIdZ0 = vtkInterpolationMathWrap(inIdZ0, inExt[4], inExt[5]);
|
|
117
|
+
inIdX1 = vtkInterpolationMathWrap(inIdX1, inExt[0], inExt[1]);
|
|
118
|
+
inIdY1 = vtkInterpolationMathWrap(inIdY1, inExt[2], inExt[3]);
|
|
119
|
+
inIdZ1 = vtkInterpolationMathWrap(inIdZ1, inExt[4], inExt[5]);
|
|
120
|
+
break;
|
|
121
|
+
|
|
122
|
+
case ImageBorderMode.MIRROR:
|
|
123
|
+
inIdX0 = vtkInterpolationMathMirror(inIdX0, inExt[0], inExt[1]);
|
|
124
|
+
inIdY0 = vtkInterpolationMathMirror(inIdY0, inExt[2], inExt[3]);
|
|
125
|
+
inIdZ0 = vtkInterpolationMathMirror(inIdZ0, inExt[4], inExt[5]);
|
|
126
|
+
inIdX1 = vtkInterpolationMathMirror(inIdX1, inExt[0], inExt[1]);
|
|
127
|
+
inIdY1 = vtkInterpolationMathMirror(inIdY1, inExt[2], inExt[3]);
|
|
128
|
+
inIdZ1 = vtkInterpolationMathMirror(inIdZ1, inExt[4], inExt[5]);
|
|
129
|
+
break;
|
|
130
|
+
|
|
131
|
+
default:
|
|
132
|
+
inIdX0 = vtkInterpolationMathClamp(inIdX0, inExt[0], inExt[1]);
|
|
133
|
+
inIdY0 = vtkInterpolationMathClamp(inIdY0, inExt[2], inExt[3]);
|
|
134
|
+
inIdZ0 = vtkInterpolationMathClamp(inIdZ0, inExt[4], inExt[5]);
|
|
135
|
+
inIdX1 = vtkInterpolationMathClamp(inIdX1, inExt[0], inExt[1]);
|
|
136
|
+
inIdY1 = vtkInterpolationMathClamp(inIdY1, inExt[2], inExt[3]);
|
|
137
|
+
inIdZ1 = vtkInterpolationMathClamp(inIdZ1, inExt[4], inExt[5]);
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
var factX0 = inIdX0 * inInc[0];
|
|
142
|
+
var factX1 = inIdX1 * inInc[0];
|
|
143
|
+
var factY0 = inIdY0 * inInc[1];
|
|
144
|
+
var factY1 = inIdY1 * inInc[1];
|
|
145
|
+
var factZ0 = inIdZ0 * inInc[2];
|
|
146
|
+
var factZ1 = inIdZ1 * inInc[2];
|
|
147
|
+
var i00 = factY0 + factZ0;
|
|
148
|
+
var i01 = factY0 + factZ1;
|
|
149
|
+
var i10 = factY1 + factZ0;
|
|
150
|
+
var i11 = factY1 + factZ1;
|
|
151
|
+
var rx = 1 - fx;
|
|
152
|
+
var ry = 1 - fy;
|
|
153
|
+
var rz = 1 - fz;
|
|
154
|
+
var ryrz = ry * rz;
|
|
155
|
+
var fyrz = fy * rz;
|
|
156
|
+
var ryfz = ry * fz;
|
|
157
|
+
var fyfz = fy * fz;
|
|
158
|
+
var inPtr = interpolationInfo.pointer;
|
|
159
|
+
|
|
160
|
+
for (var i = 0; i < numscalars; ++i) {
|
|
161
|
+
value[i] = rx * (ryrz * inPtr[factX0 + i00 + i * 4] + ryfz * inPtr[factX0 + i01 + i * 4] + fyrz * inPtr[factX0 + i10 + i * 4] + fyfz * inPtr[factX0 + i11 + i * 4]) + fx * (ryrz * inPtr[factX1 + i00 + i * 4] + ryfz * inPtr[factX1 + i01 + i * 4] + fyrz * inPtr[factX1 + i10 + i * 4] + fyfz * inPtr[factX1 + i11 + i * 4]);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
95
165
|
publicAPI.interpolatePoint = function (interpolationInfo, point, value) {
|
|
96
166
|
switch (model.interpolationMode) {
|
|
97
167
|
case InterpolationMode.LINEAR:
|
|
98
|
-
|
|
168
|
+
publicAPI.interpolateLinear(interpolationInfo, point, value);
|
|
99
169
|
break;
|
|
100
170
|
|
|
101
171
|
case InterpolationMode.CUBIC:
|
|
@@ -123,10 +193,115 @@ function vtkImageInterpolator(publicAPI, model) {
|
|
|
123
193
|
}
|
|
124
194
|
};
|
|
125
195
|
|
|
196
|
+
publicAPI.interpolateRowLinear = function (weights, idX, idY, idZ, outPtr, n) {
|
|
197
|
+
var stepX = weights.kernelSize[0];
|
|
198
|
+
var stepY = weights.kernelSize[1];
|
|
199
|
+
var stepZ = weights.kernelSize[2];
|
|
200
|
+
var idXtemp = idX * stepX;
|
|
201
|
+
var idYtemp = idY * stepY;
|
|
202
|
+
var idZtemp = idZ * stepZ;
|
|
203
|
+
var fX = weights.weights[0].subarray(idXtemp);
|
|
204
|
+
var fY = weights.weights[1].subarray(idYtemp);
|
|
205
|
+
var fZ = weights.weights[2].subarray(idZtemp);
|
|
206
|
+
var iX = weights.positions[0].subarray(idXtemp);
|
|
207
|
+
var iY = weights.positions[1].subarray(idYtemp);
|
|
208
|
+
var iZ = weights.positions[2].subarray(idZtemp);
|
|
209
|
+
var inPtr = weights.pointer; // get the number of components per pixel
|
|
210
|
+
|
|
211
|
+
var numscalars = weights.numberOfComponents; // create a 2x2 bilinear kernel in local variables
|
|
212
|
+
|
|
213
|
+
var i00 = iY.subarray(iZ[0]);
|
|
214
|
+
var i01 = i00;
|
|
215
|
+
var i10 = i00;
|
|
216
|
+
var i11 = i00;
|
|
217
|
+
var ry = 1;
|
|
218
|
+
var fy = 0;
|
|
219
|
+
var rz = 1;
|
|
220
|
+
var fz = 0;
|
|
221
|
+
|
|
222
|
+
if (stepY === 2) {
|
|
223
|
+
i10 = iY[1].subarray(iZ[0]);
|
|
224
|
+
i11 = i10;
|
|
225
|
+
ry = fY[0];
|
|
226
|
+
fy = fY[1];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (stepZ === 2) {
|
|
230
|
+
i01 = iY[0].subarray(iZ[1]);
|
|
231
|
+
i11 = i01;
|
|
232
|
+
rz = fZ[0];
|
|
233
|
+
fz = fZ[1];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (stepY + stepZ === 4) {
|
|
237
|
+
i11 = iY[1].subarray(iZ[1]);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var ryrz = ry * rz;
|
|
241
|
+
var ryfz = ry * fz;
|
|
242
|
+
var fyrz = fy * rz;
|
|
243
|
+
var fyfz = fy * fz;
|
|
244
|
+
|
|
245
|
+
if (stepX === 1) {
|
|
246
|
+
if (fy === 0 && fz === 0) {
|
|
247
|
+
// no interpolation needed at all
|
|
248
|
+
for (var i = n; i > 0; --i) {
|
|
249
|
+
for (var j = 0; j < numscalars; j++) {
|
|
250
|
+
outPtr[j + n - i] = inPtr[i00 + iX[n - i] + j];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
} else if (fy === 0) {
|
|
254
|
+
// only need linear z interpolation
|
|
255
|
+
for (var _i = n; _i > 0; --_i) {
|
|
256
|
+
for (var _j = 0; _j < numscalars; _j++) {
|
|
257
|
+
outPtr[_j + n - _i] = rz * inPtr[iX[n - _i] + i00 + _j * 4] + fz * inPtr[iX[n - _i] + i01 + _j * 4];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
261
|
+
// interpolate in y and z but not in x
|
|
262
|
+
for (var _i2 = n; _i2 > 0; --_i2) {
|
|
263
|
+
for (var _j2 = 0; _j2 < numscalars; _j2++) {
|
|
264
|
+
outPtr[_j2 + n - _i2] = ryrz * inPtr[iX[n - _i2] + i00 + _j2 * 4] + ryfz * inPtr[iX[n - _i2] + i01 + _j2 * 4] + fyrz * inPtr[iX[n - _i2] + i10 + _j2 * 4] + fyfz * inPtr[iX[n - _i2] + i11 + _j2 * 4];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
} else if (fz === 0) {
|
|
269
|
+
var x = 0; // bilinear interpolation in x,y
|
|
270
|
+
|
|
271
|
+
for (var _i3 = n; _i3 > 0; --_i3) {
|
|
272
|
+
var rx = fX[0 + 2 * x];
|
|
273
|
+
var fx = fX[1 + 2 * x];
|
|
274
|
+
var t0 = iX[0 + 2 * x];
|
|
275
|
+
var t1 = iX[1 + 2 * x];
|
|
276
|
+
|
|
277
|
+
for (var _j3 = 0; _j3 < numscalars; _j3++) {
|
|
278
|
+
outPtr[_j3 + n - _i3] = rx * (ry * inPtr[t0 + i00 + _j3 * 4] + fy * inPtr[t0 + i10 + _j3 * 4]) + fx * (ry * inPtr[t1 + i00 + _j3 * 4] + fy * inPtr[t1 + i10 + _j3 * 4]);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
x++;
|
|
282
|
+
}
|
|
283
|
+
} else {
|
|
284
|
+
var _x = 0; // do full trilinear interpolation
|
|
285
|
+
|
|
286
|
+
for (var _i4 = n; _i4 > 0; --_i4) {
|
|
287
|
+
var _rx = fX[0 + 2 * _x];
|
|
288
|
+
var _fx = fX[1 + 2 * _x];
|
|
289
|
+
var _t = iX[0 + 2 * _x];
|
|
290
|
+
var _t2 = iX[1 + 2 * _x];
|
|
291
|
+
|
|
292
|
+
for (var _j4 = 0; _j4 < numscalars; _j4++) {
|
|
293
|
+
outPtr[_j4] = _rx * (ryrz * inPtr[_t + i00 + _j4 * 4] + ryfz * inPtr[_t + i01 + _j4 * 4] + fyrz * inPtr[_t + i10 + _j4 * 4] + fyfz * inPtr[_t + i11 + _j4 * 4]) + _fx * (ryrz * inPtr[_t2 + i00 + _j4 * 4] + ryfz * inPtr[_t2 + i01 + _j4 * 4] + fyrz * inPtr[_t2 + i10 + _j4 * 4] + fyfz * inPtr[_t2 + i11 + _j4 * 4]);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
_x++;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
|
|
126
301
|
publicAPI.interpolateRow = function (weights, xIdx, yIdx, zIdx, value, n) {
|
|
127
302
|
switch (model.interpolationMode) {
|
|
128
303
|
case InterpolationMode.LINEAR:
|
|
129
|
-
|
|
304
|
+
publicAPI.interpolateRowLinear(weights, xIdx, yIdx, zIdx, value, n);
|
|
130
305
|
break;
|
|
131
306
|
|
|
132
307
|
case InterpolationMode.CUBIC:
|
|
@@ -311,9 +486,9 @@ function vtkImageInterpolator(publicAPI, model) {
|
|
|
311
486
|
|
|
312
487
|
if (!validClip) {
|
|
313
488
|
// output extent doesn't itersect input extent
|
|
314
|
-
for (var
|
|
315
|
-
clipExt[2 *
|
|
316
|
-
clipExt[2 *
|
|
489
|
+
for (var _j5 = 0; _j5 < 3; _j5++) {
|
|
490
|
+
clipExt[2 * _j5] = outExt[2 * _j5];
|
|
491
|
+
clipExt[2 * _j5 + 1] = outExt[2 * _j5] - 1;
|
|
317
492
|
}
|
|
318
493
|
}
|
|
319
494
|
};
|
|
@@ -1000,7 +1000,7 @@ function extend(publicAPI, model) {
|
|
|
1000
1000
|
macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
|
|
1001
1001
|
|
|
1002
1002
|
macro.algo(publicAPI, model, 1, 1);
|
|
1003
|
-
macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
|
|
1003
|
+
macro.setGet(publicAPI, model, ['outputDimensionality', 'outputScalarType', 'scalarShift', 'scalarScale', 'transformInputSampling', 'autoCropOutput', 'wrap', 'mirror', 'border', 'backgroundColor', 'interpolationMode', 'slabMode', 'slabTrapezoidIntegration', 'slabNumberOfSlices', 'slabSliceSpacingFraction']);
|
|
1004
1004
|
macro.setGetArray(publicAPI, model, ['outputOrigin', 'outputSpacing'], 3);
|
|
1005
1005
|
macro.setGetArray(publicAPI, model, ['outputExtent'], 6);
|
|
1006
1006
|
setNullArray(publicAPI, model, ['outputOrigin', 'outputSpacing', 'outputExtent']);
|