@kitware/vtk.js 25.9.2 → 25.10.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,3 +1,4 @@
1
+ import vtkDataArray from './../../Common/Core/DataArray';
1
2
  import { vtkObject } from './../../interfaces';
2
3
  import { ColorSpace, Scale } from './ColorTransferFunction/Constants';
3
4
 
@@ -201,6 +202,25 @@ export interface vtkColorTransferFunction extends vtkObject {
201
202
  withAlpha: boolean
202
203
  ): Float32Array;
203
204
 
205
+ /**
206
+ * Construct a color transfer function from a vtkDataArray.
207
+ * The order of values depends on the number of components
208
+ * of the array.
209
+ * 3 -> RGB
210
+ * 4 -> XRGB
211
+ * 5 -> RGBMS
212
+ * 6 -> XRGBMS
213
+ *
214
+ * X represents the input value to a function
215
+ * RGB represents the red, green, and blue value output
216
+ * M represents the midpoint
217
+ * S represents sharpness
218
+ * @param {vtkDataArray} array
219
+ */
220
+ buildFunctionFromArray(
221
+ array: vtkDataArray,
222
+ ): void;
223
+
204
224
  /**
205
225
  * Construct a color transfer function from a table.
206
226
  * @param {Number} xStart The index of the first point.
@@ -849,6 +849,69 @@ function vtkColorTransferFunction(publicAPI, model) {
849
849
 
850
850
  model.buildTime.modified();
851
851
  return model.table;
852
+ };
853
+
854
+ publicAPI.buildFunctionFromArray = function (array) {
855
+ publicAPI.removeAllPoints();
856
+ var numComponents = array.getNumberOfComponents();
857
+
858
+ for (var i = 0; i < array.getNumberOfTuples(); i++) {
859
+ switch (numComponents) {
860
+ case 3:
861
+ {
862
+ model.nodes.push({
863
+ x: i,
864
+ r: array.getComponent(i, 0),
865
+ g: array.getComponent(i, 1),
866
+ b: array.getComponent(i, 2),
867
+ midpoint: 0.5,
868
+ sharpness: 0.0
869
+ });
870
+ break;
871
+ }
872
+
873
+ case 4:
874
+ {
875
+ model.nodes.push({
876
+ x: array.getComponent(i, 0),
877
+ r: array.getComponent(i, 1),
878
+ g: array.getComponent(i, 2),
879
+ b: array.getComponent(i, 3),
880
+ midpoint: 0.5,
881
+ sharpness: 0.0
882
+ });
883
+ break;
884
+ }
885
+
886
+ case 5:
887
+ {
888
+ model.nodes.push({
889
+ x: i,
890
+ r: array.getComponent(i, 0),
891
+ g: array.getComponent(i, 1),
892
+ b: array.getComponent(i, 2),
893
+ midpoint: array.getComponent(i, 4),
894
+ sharpness: array.getComponent(i, 5)
895
+ });
896
+ break;
897
+ }
898
+
899
+ case 6:
900
+ {
901
+ model.nodes.push({
902
+ x: array.getComponent(i, 0),
903
+ r: array.getComponent(i, 1),
904
+ g: array.getComponent(i, 2),
905
+ b: array.getComponent(i, 3),
906
+ midpoint: array.getComponent(i, 4),
907
+ sharpness: array.getComponent(i, 5)
908
+ });
909
+ break;
910
+ }
911
+ }
912
+ }
913
+
914
+ publicAPI.sortAndUpdateRange();
852
915
  }; //----------------------------------------------------------------------------
853
916
 
854
917
 
@@ -1125,6 +1188,8 @@ function vtkColorTransferFunction(publicAPI, model) {
1125
1188
 
1126
1189
 
1127
1190
  publicAPI.applyColorMap = function (colorMap) {
1191
+ var oldColorSpace = JSON.stringify(model.colorSpace);
1192
+
1128
1193
  if (colorMap.ColorSpace) {
1129
1194
  model.colorSpace = ColorSpace[colorMap.ColorSpace.toUpperCase()];
1130
1195
 
@@ -1134,6 +1199,9 @@ function vtkColorTransferFunction(publicAPI, model) {
1134
1199
  }
1135
1200
  }
1136
1201
 
1202
+ var isModified = oldColorSpace !== JSON.stringify(model.colorSpace);
1203
+ var oldNanColor = isModified || JSON.stringify(model.nanColor);
1204
+
1137
1205
  if (colorMap.NanColor) {
1138
1206
  model.nanColor = [].concat(colorMap.NanColor);
1139
1207
 
@@ -1142,6 +1210,9 @@ function vtkColorTransferFunction(publicAPI, model) {
1142
1210
  }
1143
1211
  }
1144
1212
 
1213
+ isModified = isModified || oldNanColor !== JSON.stringify(model.nanColor);
1214
+ var oldNodes = isModified || JSON.stringify(model.nodes);
1215
+
1145
1216
  if (colorMap.RGBPoints) {
1146
1217
  var size = colorMap.RGBPoints.length;
1147
1218
  model.nodes = [];
@@ -1158,14 +1229,12 @@ function vtkColorTransferFunction(publicAPI, model) {
1158
1229
  sharpness: sharpness
1159
1230
  });
1160
1231
  }
1161
- } // FIXME: not supported ?
1162
- // if (colorMap.IndexedColors) {
1163
- // }
1164
- // if (colorMap.Annotations) {
1165
- // }
1166
-
1232
+ }
1167
1233
 
1168
- publicAPI.sortAndUpdateRange();
1234
+ var modifiedInvoked = publicAPI.sortAndUpdateRange();
1235
+ var callModified = !modifiedInvoked && (isModified || oldNodes !== JSON.stringify(model.nodes));
1236
+ if (callModified) publicAPI.modified();
1237
+ return modifiedInvoked || callModified;
1169
1238
  };
1170
1239
  } // ----------------------------------------------------------------------------
1171
1240
  // Object factory
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "25.9.2",
3
+ "version": "25.10.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",