@kitware/vtk.js 28.2.3 → 28.2.5

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.
@@ -68,13 +68,14 @@ function vtkLookupTable(publicAPI, model) {
68
68
 
69
69
  publicAPI.linearIndexLookup = function (v, p) {
70
70
  var dIndex = 0;
71
+ var nv = Number(v);
71
72
 
72
- if (v < p.range[0]) {
73
+ if (nv < p.range[0]) {
73
74
  dIndex = p.maxIndex + BELOW_RANGE_COLOR_INDEX + 1.5;
74
- } else if (v > p.range[1]) {
75
+ } else if (nv > p.range[1]) {
75
76
  dIndex = p.maxIndex + ABOVE_RANGE_COLOR_INDEX + 1.5;
76
77
  } else {
77
- dIndex = (v + p.shift) * p.scale; // This conditional is needed because when v is very close to
78
+ dIndex = (nv + p.shift) * p.scale; // This conditional is needed because when v is very close to
78
79
  // p.Range[1], it may map above p.MaxIndex in the linear mapping
79
80
  // above.
80
81
 
@@ -202,27 +203,59 @@ function vtkLookupTable(publicAPI, model) {
202
203
  };
203
204
 
204
205
  publicAPI.setTable = function (table) {
206
+ // Handle JS array (assume 2D array)
207
+ if (Array.isArray(table)) {
208
+ var nbComponents = table[0].length;
209
+ model.numberOfColors = table.length;
210
+ var colorOffset = 4 - nbComponents;
211
+ var offset = 0; // fill table
212
+
213
+ for (var i = 0; i < model.numberOfColors; i++) {
214
+ model.table[i * 4] = 255;
215
+ model.table[i * 4 + 1] = 255;
216
+ model.table[i * 4 + 2] = 255;
217
+ model.table[i * 4 + 3] = 255;
218
+ } // extract colors
219
+
220
+
221
+ for (var _i2 = 0; _i2 < table.length; _i2++) {
222
+ var color = table[_i2];
223
+
224
+ for (var j = 0; j < nbComponents; j++) {
225
+ model.table[offset++] = color[j];
226
+ }
227
+
228
+ offset += colorOffset;
229
+ }
230
+
231
+ publicAPI.buildSpecialColors();
232
+ model.insertTime.modified();
233
+ publicAPI.modified();
234
+ return true;
235
+ }
236
+
205
237
  if (table.getNumberOfComponents() !== 4) {
206
238
  vtkErrorMacro('Expected 4 components for RGBA colors');
207
- return;
239
+ return false;
208
240
  }
209
241
 
210
242
  if (table.getDataType() !== VtkDataTypes.UNSIGNED_CHAR) {
211
243
  vtkErrorMacro('Expected unsigned char values for RGBA colors');
212
- return;
244
+ return false;
213
245
  }
214
246
 
215
247
  model.numberOfColors = table.getNumberOfTuples();
216
248
  var data = table.getData();
217
249
  model.table.length = data.length;
218
250
 
219
- for (var i = 0; i < data.length; i++) {
220
- model.table[i] = data[i];
251
+ for (var _i3 = 0; _i3 < data.length; _i3++) {
252
+ model.table[_i3] = data[_i3];
221
253
  }
222
254
 
223
255
  publicAPI.buildSpecialColors();
224
256
  model.insertTime.modified();
225
257
  publicAPI.modified();
258
+ return true;
226
259
  };
227
260
 
228
261
  publicAPI.buildSpecialColors = function () {
@@ -275,8 +308,10 @@ function vtkLookupTable(publicAPI, model) {
275
308
  };
276
309
 
277
310
  if (model.table.length > 0) {
278
- // ensure insertTime is more recently modified than buildTime if
311
+ // Ensure that special colors are properly included in the table
312
+ publicAPI.buildSpecialColors(); // ensure insertTime is more recently modified than buildTime if
279
313
  // a table is provided via the constructor
314
+
280
315
  model.insertTime.modified();
281
316
  }
282
317
  } // ----------------------------------------------------------------------------
@@ -432,51 +432,61 @@ function vtkRenderWindowUpdater(instance, state, context) {
432
432
  function colorTransferFunctionUpdater(instance, state, context) {
433
433
  context.start(); // -> start(colorTransferFunctionUpdater)
434
434
 
435
- var nodes = state.properties.nodes.map(function (_ref) {
436
- var _ref2 = _slicedToArray(_ref, 6),
437
- x = _ref2[0],
438
- r = _ref2[1],
439
- g = _ref2[2],
440
- b = _ref2[3],
441
- midpoint = _ref2[4],
442
- sharpness = _ref2[5];
443
-
444
- return {
445
- x: x,
446
- r: r,
447
- g: g,
448
- b: b,
449
- midpoint: midpoint,
450
- sharpness: sharpness
451
- };
452
- });
453
- instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
454
- nodes: nodes
455
- }), true);
435
+ if (!state.properties.nodes) {
436
+ instance.set(state.properties);
437
+ } else {
438
+ var nodes = state.properties.nodes.map(function (_ref) {
439
+ var _ref2 = _slicedToArray(_ref, 6),
440
+ x = _ref2[0],
441
+ r = _ref2[1],
442
+ g = _ref2[2],
443
+ b = _ref2[3],
444
+ midpoint = _ref2[4],
445
+ sharpness = _ref2[5];
446
+
447
+ return {
448
+ x: x,
449
+ r: r,
450
+ g: g,
451
+ b: b,
452
+ midpoint: midpoint,
453
+ sharpness: sharpness
454
+ };
455
+ });
456
+ instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
457
+ nodes: nodes
458
+ }), true);
459
+ }
460
+
456
461
  context.end(); // -> end(colorTransferFunctionUpdater)
457
462
  }
458
463
 
459
464
  function piecewiseFunctionUpdater(instance, state, context) {
460
465
  context.start(); // -> start(piecewiseFunctionUpdater)
461
466
 
462
- var nodes = state.properties.nodes.map(function (_ref3) {
463
- var _ref4 = _slicedToArray(_ref3, 4),
464
- x = _ref4[0],
465
- y = _ref4[1],
466
- midpoint = _ref4[2],
467
- sharpness = _ref4[3];
468
-
469
- return {
470
- x: x,
471
- y: y,
472
- midpoint: midpoint,
473
- sharpness: sharpness
474
- };
475
- });
476
- instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
477
- nodes: nodes
478
- }), true);
479
- instance.sortAndUpdateRange(); // instance.modified();
467
+ if (!state.properties.nodes) {
468
+ instance.set(state.properties);
469
+ } else {
470
+ var nodes = state.properties.nodes.map(function (_ref3) {
471
+ var _ref4 = _slicedToArray(_ref3, 4),
472
+ x = _ref4[0],
473
+ y = _ref4[1],
474
+ midpoint = _ref4[2],
475
+ sharpness = _ref4[3];
476
+
477
+ return {
478
+ x: x,
479
+ y: y,
480
+ midpoint: midpoint,
481
+ sharpness: sharpness
482
+ };
483
+ });
484
+ instance.set(_objectSpread(_objectSpread({}, state.properties), {}, {
485
+ nodes: nodes
486
+ }), true);
487
+ instance.sortAndUpdateRange();
488
+ } // instance.modified();
489
+
480
490
 
481
491
  context.end(); // -> end(piecewiseFunctionUpdater)
482
492
  } // ----------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "28.2.3",
3
+ "version": "28.2.5",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",