@kitware/vtk.js 33.0.2 → 33.1.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.
@@ -13,77 +13,35 @@ function vtkMouseCameraTrackballFirstPersonManipulator(publicAPI, model) {
13
13
  model.classHierarchy.push('vtkMouseCameraTrackballFirstPersonManipulator');
14
14
  const internal = {
15
15
  interactor: null,
16
- renderer: null,
17
- previousPosition: null
16
+ renderer: null
18
17
  };
19
18
 
20
19
  //--------------------------------------------------------------------------
21
20
 
22
21
  publicAPI.onButtonDown = (interactor, renderer, position) => {
23
- internal.previousPosition = position;
24
22
  if (model.usePointerLock && !interactor.isPointerLocked()) {
25
23
  Object.assign(internal, {
26
24
  interactor,
27
25
  renderer
28
26
  });
29
27
  interactor.requestPointerLock();
30
- publicAPI.startPointerLockInteraction();
31
28
  }
32
29
  };
33
30
 
34
31
  //--------------------------------------------------------------------------
35
32
 
36
- publicAPI.startPointerLockInteraction = () => {
37
- const {
38
- interactor
39
- } = internal;
40
-
41
- // TODO: at some point, this should perhaps be done in
42
- // RenderWindowInteractor instead of here.
43
- // We need to hook into mousemove directly for two reasons:
44
- // 1. We need to keep receiving mouse move events after the mouse button
45
- // is released. This is currently not possible with
46
- // vtkInteractorStyleManipulator.
47
- // 2. Since the mouse is stationary in pointer lock mode, we need the
48
- // event.movementX and event.movementY info, which are not currently
49
- // passed via interactor.onMouseMove.
50
- document.addEventListener('mousemove', publicAPI.onPointerLockMove);
51
- let subscription = null;
52
- const endInteraction = () => {
53
- document.removeEventListener('mousemove', publicAPI.onPointerLockMove);
54
- subscription.unsubscribe();
55
- };
56
- subscription = interactor.onEndPointerLock(endInteraction);
57
- };
58
-
59
- //--------------------------------------------------------------------------
60
-
61
- publicAPI.onPointerLockMove = e => {
62
- const sensitivity = model.sensitivity;
63
- const yaw = -1 * e.movementX * sensitivity;
64
- const pitch = -1 * e.movementY * sensitivity;
65
- publicAPI.moveCamera(yaw, pitch);
66
- };
67
-
68
- //--------------------------------------------------------------------------
69
-
70
33
  publicAPI.onMouseMove = (interactor, renderer, position) => {
71
- // This is currently only being called for non pointer lock mode
72
34
  if (!position) {
73
35
  return;
74
36
  }
75
- const {
76
- previousPosition
77
- } = internal;
78
37
  const sensitivity = model.sensitivity;
79
- const yaw = (previousPosition.x - position.x) * sensitivity;
80
- const pitch = (position.y - previousPosition.y) * sensitivity;
38
+ const yaw = -position.movementX * sensitivity;
39
+ const pitch = -position.movementY * sensitivity;
81
40
  Object.assign(internal, {
82
41
  interactor,
83
42
  renderer
84
43
  });
85
44
  publicAPI.moveCamera(yaw, pitch);
86
- internal.previousPosition = position;
87
45
  };
88
46
 
89
47
  //--------------------------------------------------------------------------
@@ -6,6 +6,7 @@ import vtkInteractorStyle from './../../Rendering/Core/InteractorStyle';
6
6
  import {
7
7
  Device,
8
8
  Input,
9
+ MouseButton,
9
10
  } from './../../Rendering/Core/RenderWindowInteractor/Constants';
10
11
  import { Nullable, Vector3 } from './../../types';
11
12
 
@@ -120,7 +121,7 @@ export interface vtkInteractorStyleManipulator extends vtkInteractorStyle {
120
121
  * @param alt alt enabled
121
122
  */
122
123
  findMouseManipulator(
123
- button: number,
124
+ button: MouseButton,
124
125
  shift: boolean,
125
126
  scroll: boolean,
126
127
  alt: boolean
@@ -285,13 +286,13 @@ export interface vtkInteractorStyleManipulator extends vtkInteractorStyle {
285
286
  * @param button which button
286
287
  * @param callData event data
287
288
  */
288
- onButtonDown(button: number, callData: unknown): void;
289
+ onButtonDown(button: MouseButton, callData: unknown): void;
289
290
 
290
291
  /**
291
292
  * Handles a button up event.
292
293
  * @param button which button
293
294
  */
294
- onButtonUp(button: number): void;
295
+ onButtonUp(button: MouseButton): void;
295
296
 
296
297
  /**
297
298
  * Sets the rotation factor.
@@ -1,4 +1,5 @@
1
1
  import { m as macro } from '../../macros2.js';
2
+ import { MouseButton } from '../../Rendering/Core/RenderWindowInteractor/Constants.js';
2
3
  import vtkInteractorStyle from '../../Rendering/Core/InteractorStyle.js';
3
4
 
4
5
  const {
@@ -225,19 +226,19 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
225
226
  //-------------------------------------------------------------------------
226
227
  publicAPI.handleLeftButtonPress = callData => {
227
228
  model.previousPosition = callData.position;
228
- publicAPI.onButtonDown(1, callData);
229
+ publicAPI.onButtonDown(MouseButton.LeftButton, callData);
229
230
  };
230
231
 
231
232
  //-------------------------------------------------------------------------
232
233
  publicAPI.handleMiddleButtonPress = callData => {
233
234
  model.previousPosition = callData.position;
234
- publicAPI.onButtonDown(2, callData);
235
+ publicAPI.onButtonDown(MouseButton.MiddleButton, callData);
235
236
  };
236
237
 
237
238
  //-------------------------------------------------------------------------
238
239
  publicAPI.handleRightButtonPress = callData => {
239
240
  model.previousPosition = callData.position;
240
- publicAPI.onButtonDown(3, callData);
241
+ publicAPI.onButtonDown(MouseButton.RightButton, callData);
241
242
  };
242
243
 
243
244
  //-------------------------------------------------------------------------
@@ -330,17 +331,17 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
330
331
 
331
332
  //-------------------------------------------------------------------------
332
333
  publicAPI.handleLeftButtonRelease = () => {
333
- publicAPI.onButtonUp(1);
334
+ publicAPI.onButtonUp(MouseButton.LeftButton);
334
335
  };
335
336
 
336
337
  //-------------------------------------------------------------------------
337
338
  publicAPI.handleMiddleButtonRelease = () => {
338
- publicAPI.onButtonUp(2);
339
+ publicAPI.onButtonUp(MouseButton.MiddleButton);
339
340
  };
340
341
 
341
342
  //-------------------------------------------------------------------------
342
343
  publicAPI.handleRightButtonRelease = () => {
343
- publicAPI.onButtonUp(3);
344
+ publicAPI.onButtonUp(MouseButton.RightButton);
344
345
  };
345
346
 
346
347
  //-------------------------------------------------------------------------
@@ -351,12 +352,18 @@ function vtkInteractorStyleManipulator(publicAPI, model) {
351
352
  if (model.currentManipulator.getButton && model.currentManipulator.getButton() === button) {
352
353
  model.currentManipulator.onButtonUp(model._interactor);
353
354
  model.currentManipulator.endInteraction();
354
- model.currentManipulator = null;
355
- model._interactor.cancelAnimation(publicAPI.onButtonDown);
355
+ if (!model._interactor.isPointerLocked()) {
356
+ model.currentManipulator = null;
357
+ }
356
358
  publicAPI.invokeEndInteractionEvent(END_INTERACTION_EVENT);
357
359
  }
358
360
  };
359
361
 
362
+ //-------------------------------------------------------------------------
363
+ publicAPI.handleEndPointerLock = () => {
364
+ model.currentManipulator = null;
365
+ };
366
+
360
367
  //-------------------------------------------------------------------------
361
368
  publicAPI.handleStartMouseWheel = callData => {
362
369
  // Must not be processing a wheel interaction to start another.
@@ -312,6 +312,30 @@ export interface vtkColorTransferFunction extends vtkScalarsToColors {
312
312
  * @param colorMap
313
313
  */
314
314
  applyColorMap(colorMap: any): void;
315
+
316
+ /**
317
+ * Get the color space of the color transfer function.
318
+ * @returns {ColorSpace}
319
+ */
320
+ getColorSpace(): ColorSpace;
321
+
322
+ /**
323
+ * Set the color space of the color transfer function.
324
+ * @param {ColorSpace} colorSpace
325
+ */
326
+ setColorSpace(colorSpace: ColorSpace): void;
327
+
328
+ /**
329
+ * Get the scale of the color transfer function.
330
+ * @returns {Scale}
331
+ */
332
+ getScale(): Scale;
333
+
334
+ /**
335
+ * Set the scale of the color transfer function.
336
+ * @param {Scale} scale
337
+ */
338
+ setScale(scale: Scale): void;
315
339
  }
316
340
 
317
341
  /**
@@ -135,12 +135,13 @@ const colorTextureCoordinatesCache = new WeakMap();
135
135
  * @param {vtkDataArray} input The input data array used for coloring
136
136
  * @param {Number} component The component of the input data array that is used for coloring (-1 for magnitude of the vectors)
137
137
  * @param {Range} range The range of the scalars
138
+ * @param {boolean} useLogScale Should the values be transformed to logarithmic scale. When true, the range must already be in logarithmic scale.
138
139
  * @param {Number} numberOfColorsInRange The number of colors that are used in the range
139
140
  * @param {vec3} dimensions The dimensions of the texture
140
141
  * @param {boolean} useZigzagPattern If a zigzag pattern should be used. Otherwise 1 row for colors (including min and max) and 1 row for NaN are used.
141
142
  * @returns A vtkDataArray containing the texture coordinates (2D or 3D)
142
143
  */
143
- function getOrCreateColorTextureCoordinates(input, component, range, numberOfColorsInRange, dimensions, useZigzagPattern) {
144
+ function getOrCreateColorTextureCoordinates(input, component, range, useLogScale, numberOfColorsInRange, dimensions, useZigzagPattern) {
144
145
  // Caching using the "arguments" special object (because it is a pure function)
145
146
  const argStrings = new Array(arguments.length);
146
147
  for (let argIndex = 0; argIndex < arguments.length; ++argIndex) {
@@ -199,6 +200,9 @@ function getOrCreateColorTextureCoordinates(input, component, range, numberOfCol
199
200
  } else {
200
201
  scalarValue = inputV[inputIdx + component];
201
202
  }
203
+ if (useLogScale) {
204
+ scalarValue = Math.log10(scalarValue);
205
+ }
202
206
  inputIdx += numComps;
203
207
 
204
208
  // Convert to texture coordinates and update output
@@ -396,6 +400,7 @@ function vtkMapper(publicAPI, model) {
396
400
  const range = model.lookupTable.getRange();
397
401
  const useLogScale = model.lookupTable.usingLogScale();
398
402
  const origAlpha = model.lookupTable.getAlpha();
403
+ const scaledRange = useLogScale ? [Math.log10(range[0]), Math.log10(range[1])] : range;
399
404
 
400
405
  // Get rid of vertex color array. Only texture or vertex coloring
401
406
  // can be active at one time. The existence of the array is the
@@ -438,7 +443,6 @@ function vtkMapper(publicAPI, model) {
438
443
  const numberOfNonSpecialColors = model.numberOfColorsInRange;
439
444
  const numberOfNonNaNColors = numberOfNonSpecialColors + 2;
440
445
  const textureCoordinates = [0, 0, 0];
441
- const scaledRange = useLogScale ? [Math.log10(range[0]), Math.log10(range[1])] : range;
442
446
  const rangeMin = scaledRange[0];
443
447
  const rangeDifference = scaledRange[1] - scaledRange[0];
444
448
  for (let i = 0; i < numberOfNonNaNColors; ++i) {
@@ -472,7 +476,7 @@ function vtkMapper(publicAPI, model) {
472
476
  // A zigzag pattern can be used with cell data, as there will be no texture coordinates interpolation
473
477
  // The texture generated using a zigzag pattern in one dimension is the same as without zigzag
474
478
  // Therefore, the same code can be used for texture generation of point/cell data but not for texture coordinates
475
- model.colorCoordinates = getOrCreateColorTextureCoordinates(scalars, scalarComponent, range, model.numberOfColorsInRange, model.colorTextureMap.getDimensions(), cellFlag);
479
+ model.colorCoordinates = getOrCreateColorTextureCoordinates(scalars, scalarComponent, scaledRange, useLogScale, model.numberOfColorsInRange, model.colorTextureMap.getDimensions(), cellFlag);
476
480
  };
477
481
  publicAPI.getIsOpaque = () => {
478
482
  const input = publicAPI.getInputData();
@@ -23,9 +23,16 @@ export declare enum Axis {
23
23
  ThumbstickY = 4,
24
24
  }
25
25
 
26
+ export declare enum MouseButton {
27
+ LeftButton = 1,
28
+ MiddleButton = 2,
29
+ RightButton = 3,
30
+ }
31
+
26
32
  declare const _default: {
27
33
  Device: typeof Device;
28
34
  Input: typeof Input;
29
35
  Axis: typeof Axis;
36
+ MouseButton: typeof MouseButton;
30
37
  };
31
38
  export default _default;
@@ -21,10 +21,16 @@ const Axis = {
21
21
  ThumbstickX: 3,
22
22
  ThumbstickY: 4
23
23
  };
24
+ const MouseButton = {
25
+ LeftButton: 1,
26
+ MiddleButton: 2,
27
+ RightButton: 3
28
+ };
24
29
  var Constants = {
25
30
  Device,
26
31
  Input,
27
- Axis
32
+ Axis,
33
+ MouseButton
28
34
  };
29
35
 
30
- export { Axis, Device, Input, Constants as default };
36
+ export { Axis, Device, Input, MouseButton, Constants as default };
@@ -1,7 +1,7 @@
1
1
  import { vtkObject, vtkSubscription } from './../../interfaces';
2
2
  import { Nullable } from './../../types';
3
3
  import vtkRenderer from './Renderer';
4
- import { Axis, Device, Input } from './RenderWindowInteractor/Constants';
4
+ import { Axis, Device, Input, MouseButton } from './RenderWindowInteractor/Constants';
5
5
 
6
6
  declare enum handledEvents {
7
7
  'StartAnimation',
@@ -1397,5 +1397,6 @@ export declare const vtkRenderWindowInteractor: {
1397
1397
  Device: typeof Device;
1398
1398
  Input: typeof Input;
1399
1399
  Axis: typeof Axis;
1400
+ MouseButton: typeof MouseButton;
1400
1401
  };
1401
1402
  export default vtkRenderWindowInteractor;
@@ -136,7 +136,9 @@ function vtkRenderWindowInteractor(publicAPI, model) {
136
136
  const position = {
137
137
  x: scaleX * (source.clientX - bounds.left),
138
138
  y: scaleY * (bounds.height - source.clientY + bounds.top),
139
- z: 0
139
+ z: 0,
140
+ movementX: scaleX * source.movementX,
141
+ movementY: scaleY * source.movementY
140
142
  };
141
143
 
142
144
  // if multitouch, do not update the current renderer
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "33.0.2",
3
+ "version": "33.1.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",