@kitware/vtk.js 28.9.0 → 28.10.0

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 _slicedToArray from '@babel/runtime/helpers/slicedToArray';
1
2
  import macro from '../../macros.js';
2
3
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
3
4
  import vtkEdgeLocator from '../../Common/DataModel/EdgeLocator.js';
@@ -9,12 +10,41 @@ var vtkErrorMacro = macro.vtkErrorMacro,
9
10
  // ----------------------------------------------------------------------------
10
11
 
11
12
  function vtkImageMarchingSquares(publicAPI, model) {
12
- // Set our className
13
+ /**
14
+ * Get the X,Y kernels based on the set slicing mode.
15
+ * @returns {[number, number]}
16
+ */
17
+ function getKernels() {
18
+ var kernelX = 0; // default K slicing mode
19
+
20
+ var kernelY = 1;
21
+
22
+ if (model.slicingMode === 1) {
23
+ kernelX = 0;
24
+ kernelY = 2;
25
+ } else if (model.slicingMode === 0) {
26
+ kernelX = 1;
27
+ kernelY = 2;
28
+ }
29
+
30
+ return [kernelX, kernelY];
31
+ } // Set our className
32
+
33
+
13
34
  model.classHierarchy.push('vtkImageMarchingSquares');
35
+ /**
36
+ * Get the list of contour values.
37
+ * @returns {number[]}
38
+ */
14
39
 
15
40
  publicAPI.getContourValues = function () {
16
41
  return model.contourValues;
17
42
  };
43
+ /**
44
+ * Set the list contour values.
45
+ * @param {number[]} cValues
46
+ */
47
+
18
48
 
19
49
  publicAPI.setContourValues = function (cValues) {
20
50
  model.contourValues = cValues;
@@ -24,47 +54,87 @@ function vtkImageMarchingSquares(publicAPI, model) {
24
54
  var ids = [];
25
55
  var pixelScalars = [];
26
56
  var pixelPts = [];
27
- var edgeLocator = vtkEdgeLocator.newInstance(); // Retrieve scalars and pixel coordinates. i-j-k is origin of pixel.
57
+ var edgeLocator = vtkEdgeLocator.newInstance();
58
+ /**
59
+ * Retrieve scalars and pixel coordinates.
60
+ * @param {Vector3} ijk origin of the pixel
61
+ * @param {Vector3} dims dimensions of the image
62
+ * @param {TypedArray} scalars list of scalar values
63
+ * @param {Vector3} increments IJK slice increments
64
+ * @param {number} kernelX index of the X element
65
+ * @param {number} kernelY index of the Y element
66
+ */
28
67
 
29
- publicAPI.getPixelScalars = function (i, j, k, slice, dims, origin, spacing, s) {
30
- // First get the indices for the pixel
31
- ids[0] = k * slice + j * dims[0] + i; // i, j, k
68
+ publicAPI.getPixelScalars = function (ijk, dims, scalars, increments, kernelX, kernelY) {
69
+ var _ijk = _slicedToArray(ijk, 3),
70
+ i = _ijk[0],
71
+ j = _ijk[1],
72
+ k = _ijk[2]; // First get the indices for the pixel
32
73
 
33
- ids[1] = ids[0] + 1; // i+1, j, k
34
74
 
35
- ids[2] = ids[0] + dims[0]; // i, j+1, k
75
+ ids[0] = k * dims[1] * dims[0] + j * dims[0] + i; // i, j, k
36
76
 
37
- ids[3] = ids[2] + 1; // i+1, j+1, k
77
+ ids[1] = ids[0] + increments[kernelX]; // i+1, j, k
78
+
79
+ ids[2] = ids[0] + increments[kernelY]; // i, j+1, k
80
+
81
+ ids[3] = ids[2] + increments[kernelX]; // i+1, j+1, k
38
82
  // Now retrieve the scalars
39
83
 
40
84
  for (var ii = 0; ii < 4; ++ii) {
41
- pixelScalars[ii] = s[ids[ii]];
85
+ pixelScalars[ii] = scalars[ids[ii]];
42
86
  }
43
- }; // Retrieve pixel coordinates. i-j-k is origin of pixel.
87
+ };
88
+ /**
89
+ * Retrieve pixel coordinates.
90
+ * @param {Vector3} ijk origin of the pixel
91
+ * @param {Vector3} origin origin of the image
92
+ * @param {Vector3} spacing spacing of the image
93
+ * @param {number} kernelX index of the X element
94
+ * @param {number} kernelY index of the Y element
95
+ */
96
+
44
97
 
98
+ publicAPI.getPixelPoints = function (ijk, origin, spacing, kernelX, kernelY) {
99
+ var i = ijk[kernelX];
100
+ var j = ijk[kernelY]; // (i,i+1),(j,j+1),(k,k+1) - i varies fastest; then j; then k
45
101
 
46
- publicAPI.getPixelPoints = function (i, j, k, dims, origin, spacing) {
47
- // (i,i+1),(j,j+1),(k,k+1) - i varies fastest; then j; then k
48
- pixelPts[0] = origin[0] + i * spacing[0]; // 0
102
+ pixelPts[0] = origin[kernelX] + i * spacing[kernelX]; // 0
49
103
 
50
- pixelPts[1] = origin[1] + j * spacing[1];
51
- pixelPts[2] = pixelPts[0] + spacing[0]; // 1
104
+ pixelPts[1] = origin[kernelY] + j * spacing[kernelY];
105
+ pixelPts[2] = pixelPts[0] + spacing[kernelX]; // 1
52
106
 
53
107
  pixelPts[3] = pixelPts[1];
54
108
  pixelPts[4] = pixelPts[0]; // 2
55
109
 
56
- pixelPts[5] = pixelPts[1] + spacing[1];
110
+ pixelPts[5] = pixelPts[1] + spacing[kernelY];
57
111
  pixelPts[6] = pixelPts[2]; // 3
58
112
 
59
113
  pixelPts[7] = pixelPts[5];
60
114
  };
61
-
62
- publicAPI.produceLines = function (cVal, i, j, k, slice, dims, origin, spacing, scalars, points, lines) {
115
+ /**
116
+ * Produce points and lines for the polydata.
117
+ * @param {number[]} cVal list of contour values
118
+ * @param {Vector3} ijk origin of the pixel
119
+ * @param {Vector3} dims dimensions of the image
120
+ * @param {Vector3} origin origin of the image
121
+ * @param {Vector3} spacing sapcing of the image
122
+ * @param {TypedArray} scalars list of scalar values
123
+ * @param {number[]} points list of points
124
+ * @param {number[]} lines list of lines
125
+ * @param {Vector3} increments IJK slice increments
126
+ * @param {number} kernelX index of the X element
127
+ * @param {number} kernelY index of the Y element
128
+ */
129
+
130
+
131
+ publicAPI.produceLines = function (cVal, ijk, dims, origin, spacing, scalars, points, lines, increments, kernelX, kernelY) {
132
+ var k = ijk[model.slicingMode];
63
133
  var CASE_MASK = [1, 2, 8, 4]; // case table is actually for quad
64
134
 
65
135
  var xyz = [];
66
136
  var pId;
67
- publicAPI.getPixelScalars(i, j, k, slice, dims, origin, spacing, scalars);
137
+ publicAPI.getPixelScalars(ijk, dims, scalars, increments, kernelX, kernelY);
68
138
  var index = 0;
69
139
 
70
140
  for (var idx = 0; idx < 4; idx++) {
@@ -79,8 +149,8 @@ function vtkImageMarchingSquares(publicAPI, model) {
79
149
  return; // don't get the pixel coordinates, nothing to do
80
150
  }
81
151
 
82
- publicAPI.getPixelPoints(i, j, k, dims, origin, spacing);
83
- var z = origin[2] + k * spacing[2];
152
+ publicAPI.getPixelPoints(ijk, origin, spacing, kernelX, kernelY);
153
+ var z = origin[model.slicingMode] + k * spacing[model.slicingMode];
84
154
 
85
155
  for (var _idx = 0; pixelLines[_idx] >= 0; _idx += 2) {
86
156
  lines.push(2);
@@ -99,10 +169,11 @@ function vtkImageMarchingSquares(publicAPI, model) {
99
169
  var t = (cVal - pixelScalars[edgeVerts[0]]) / (pixelScalars[edgeVerts[1]] - pixelScalars[edgeVerts[0]]);
100
170
  var x0 = pixelPts.slice(edgeVerts[0] * 2, (edgeVerts[0] + 1) * 2);
101
171
  var x1 = pixelPts.slice(edgeVerts[1] * 2, (edgeVerts[1] + 1) * 2);
102
- xyz[0] = x0[0] + t * (x1[0] - x0[0]);
103
- xyz[1] = x0[1] + t * (x1[1] - x0[1]);
172
+ xyz[kernelX] = x0[0] + t * (x1[0] - x0[0]);
173
+ xyz[kernelY] = x0[1] + t * (x1[1] - x0[1]);
174
+ xyz[model.slicingMode] = z;
104
175
  pId = points.length / 3;
105
- points.push(xyz[0], xyz[1], z);
176
+ points.push(xyz[0], xyz[1], xyz[2]);
106
177
 
107
178
  if (model.mergePoints) {
108
179
  edgeLocator.insertEdge(ids[edgeVerts[0]], ids[edgeVerts[1]], pId);
@@ -123,29 +194,47 @@ function vtkImageMarchingSquares(publicAPI, model) {
123
194
  return;
124
195
  }
125
196
 
197
+ if (model.slicingMode == null || model.slicingMode < 0 || model.slicingMode > 2) {
198
+ vtkErrorMacro('Invalid or missing slicing mode');
199
+ return;
200
+ }
201
+
126
202
  console.time('msquares'); // Retrieve output and volume data
127
203
 
128
204
  var origin = input.getOrigin();
129
205
  var spacing = input.getSpacing();
130
206
  var dims = input.getDimensions();
131
- var s = input.getPointData().getScalars().getData(); // Points - dynamic array
207
+ var extent = input.getExtent();
208
+ var increments = input.computeIncrements(extent);
209
+ var scalars = input.getPointData().getScalars().getData();
132
210
 
133
- var pBuffer = []; // Cells - dynamic array
211
+ var _getKernels = getKernels(),
212
+ _getKernels2 = _slicedToArray(_getKernels, 2),
213
+ kernelX = _getKernels2[0],
214
+ kernelY = _getKernels2[1]; // Points - dynamic array
134
215
 
135
- var lBuffer = []; // Ensure slice is valid
136
216
 
137
- var slice = dims[0] * dims[1];
217
+ var points = []; // Cells - dynamic array
218
+
219
+ var lines = []; // Ensure slice is valid
220
+
138
221
  var k = Math.round(model.slice);
139
222
 
140
- if (k >= dims[2]) {
223
+ if (k >= dims[model.slicingMode]) {
141
224
  k = 0;
142
225
  } // Loop over all contour values, and then pixels, determine case and process
143
226
 
144
227
 
228
+ var ijk = [0, 0, 0];
229
+ ijk[model.slicingMode] = k;
230
+
145
231
  for (var cv = 0; cv < model.contourValues.length; ++cv) {
146
- for (var j = 0; j < dims[1] - 1; ++j) {
147
- for (var i = 0; i < dims[0] - 1; ++i) {
148
- publicAPI.produceLines(model.contourValues[cv], i, j, k, slice, dims, origin, spacing, s, pBuffer, lBuffer);
232
+ for (var j = 0; j < dims[kernelY] - 1; ++j) {
233
+ ijk[kernelY] = j;
234
+
235
+ for (var i = 0; i < dims[kernelX] - 1; ++i) {
236
+ ijk[kernelX] = i;
237
+ publicAPI.produceLines(model.contourValues[cv], ijk, dims, origin, spacing, scalars, points, lines, increments, kernelX, kernelY);
149
238
  }
150
239
  }
151
240
 
@@ -154,8 +243,8 @@ function vtkImageMarchingSquares(publicAPI, model) {
154
243
 
155
244
 
156
245
  var polydata = vtkPolyData.newInstance();
157
- polydata.getPoints().setData(new Float32Array(pBuffer), 3);
158
- polydata.getLines().setData(new Uint32Array(lBuffer));
246
+ polydata.getPoints().setData(new Float32Array(points), 3);
247
+ polydata.getLines().setData(new Uint32Array(lines));
159
248
  outData[0] = polydata;
160
249
  vtkDebugMacro('Produced output');
161
250
  console.timeEnd('msquares');
@@ -167,6 +256,7 @@ function vtkImageMarchingSquares(publicAPI, model) {
167
256
 
168
257
  var DEFAULT_VALUES = {
169
258
  contourValues: [],
259
+ slicingMode: 2,
170
260
  slice: 0,
171
261
  mergePoints: false
172
262
  }; // ----------------------------------------------------------------------------
@@ -178,7 +268,7 @@ function extend(publicAPI, model) {
178
268
  macro.obj(publicAPI, model); // Also make it an algorithm with one input and one output
179
269
 
180
270
  macro.algo(publicAPI, model, 1, 1);
181
- macro.setGet(publicAPI, model, ['slice', 'mergePoints']); // Object specific methods
271
+ macro.setGet(publicAPI, model, ['slicingMode', 'slice', 'mergePoints']); // Object specific methods
182
272
 
183
273
  macro.algo(publicAPI, model, 1, 1);
184
274
  vtkImageMarchingSquares(publicAPI, model);
@@ -137,12 +137,25 @@ function vtkInteractorStyleRemoteMouse(publicAPI, model) {
137
137
 
138
138
 
139
139
  publicAPI.handleMouseWheel = function (callData) {
140
- publicAPI.invokeRemoteWheelEvent(_objectSpread(_objectSpread({
141
- type: 'MouseWheel'
142
- }, createRemoteEvent(callData)), {}, {
143
- spinY: callData.spinY
144
- }));
145
- publicAPI.invokeInteractionEvent(INTERACTION_EVENT);
140
+ var needToSend = true;
141
+
142
+ if (model.wheelThrottleDelay) {
143
+ var ts = Date.now();
144
+ needToSend = model.wheelThrottleDelay < ts - model.wheelLastThrottleTime;
145
+
146
+ if (needToSend) {
147
+ model.wheelLastThrottleTime = ts;
148
+ }
149
+ }
150
+
151
+ if (needToSend) {
152
+ publicAPI.invokeRemoteWheelEvent(_objectSpread(_objectSpread({
153
+ type: 'MouseWheel'
154
+ }, createRemoteEvent(callData)), {}, {
155
+ spinY: callData.spinY
156
+ }));
157
+ publicAPI.invokeInteractionEvent(INTERACTION_EVENT);
158
+ }
146
159
  }; //-------------------------------------------------------------------------
147
160
 
148
161
 
@@ -290,7 +303,9 @@ var DEFAULT_VALUES = {
290
303
  sendMouseMove: false,
291
304
  throttleDelay: 33.3,
292
305
  // 33.3 millisecond <=> 30 events/second
293
- lastThrottleTime: 0 // remoteEventAddOn: null,
306
+ lastThrottleTime: 0,
307
+ wheelThrottleDelay: 0,
308
+ wheelLastThrottleTime: 0 // remoteEventAddOn: null,
294
309
 
295
310
  }; // ----------------------------------------------------------------------------
296
311
 
@@ -299,7 +314,7 @@ function extend(publicAPI, model) {
299
314
  Object.assign(model, DEFAULT_VALUES, initialValues); // Inheritance
300
315
 
301
316
  vtkInteractorStyle.extend(publicAPI, model, initialValues);
302
- macro.setGet(publicAPI, model, ['sendMouseMove', 'remoteEventAddOn', 'throttleDelay']);
317
+ macro.setGet(publicAPI, model, ['sendMouseMove', 'remoteEventAddOn', 'throttleDelay', 'wheelThrottleDelay']);
303
318
  macro.event(publicAPI, model, 'RemoteMouseEvent');
304
319
  macro.event(publicAPI, model, 'RemoteWheelEvent');
305
320
  macro.event(publicAPI, model, 'RemoteGestureEvent'); // Object specific methods
@@ -0,0 +1,35 @@
1
+ import { RGBColor } from './../../types';
2
+ import vtkAbstractRepresentationProxy from './../Core/AbstractRepresentationProxy';
3
+
4
+ export interface vtkGeometryRepresentationProxy
5
+ extends vtkAbstractRepresentationProxy {
6
+
7
+ /**
8
+ *
9
+ * @param representation a string that describes what representation to use for the explicit geometry.
10
+ * possible values are 'Surface with edges', 'Surface' (default), 'Wireframe',
11
+ * and 'Points'.
12
+ */
13
+ setRepresentation(representation: string): boolean;
14
+ getRepresentation(): string;
15
+
16
+ // proxy property mappings
17
+ getColor(): RGBColor;
18
+ setColor(color: RGBColor): boolean;
19
+ getInterpolateScalarsBeforeMapping(): boolean;
20
+ setInterpolateScalarsBeforeMapping(interpolateScalarsBeforeMapping: boolean): boolean;
21
+ setOpacity(opacity: boolean): boolean;
22
+ getOpacity(): boolean;
23
+ setVisibility(visible: boolean): boolean;
24
+ getVisibility(): boolean;
25
+ getPointSize(): number;
26
+ setPointSize(pointSize: number): boolean;
27
+ getUseShadow(): boolean;
28
+ setUseShadow(lighting: boolean): boolean;
29
+ getUseBounds(): boolean;
30
+ setUseBounds(useBounds: boolean): boolean;
31
+ getLineWidth(): number;
32
+ setLineWidth(width: number): boolean;
33
+ }
34
+
35
+ export default vtkGeometryRepresentationProxy;
@@ -96,6 +96,10 @@ function extend(publicAPI, model) {
96
96
  modelKey: 'property',
97
97
  property: 'lighting'
98
98
  },
99
+ lineWidth: {
100
+ modelKey: 'property',
101
+ property: 'lineWidth'
102
+ },
99
103
  useBounds: {
100
104
  modelKey: 'actor',
101
105
  property: 'useBounds'
package/index.d.ts CHANGED
@@ -131,6 +131,7 @@
131
131
  /// <reference path="./Proxy/Core/SourceProxy.d.ts" />
132
132
  /// <reference path="./Proxy/Core/View2DProxy.d.ts" />
133
133
  /// <reference path="./Proxy/Core/ViewProxy.d.ts" />
134
+ /// <reference path="./Proxy/Representations/GeometryRepresentationProxy.d.ts" />
134
135
  /// <reference path="./Proxy/Representations/ResliceRepresentationProxy.d.ts" />
135
136
  /// <reference path="./Proxy/Representations/SliceRepresentationProxy.d.ts" />
136
137
  /// <reference path="./Proxy/Representations/VolumeRepresentationProxy.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "28.9.0",
3
+ "version": "28.10.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",