@kitware/vtk.js 30.1.2 → 30.3.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.
@@ -4,6 +4,8 @@
4
4
  - **ResliceCursorWidget.invokeInternalInteractionEvent(methodName)**: has been removed and should be replaced by `ResliceCursorWidget.invokeInteractionEvent(methodName)`.
5
5
  - **ResliceCursorWidget.updateCameraPoints(renderer, viewType, resetFocalPoint, keepCenterFocalDistance, computeFocalPointOffset)** has lost the `keepCenterFocalDistance` parameter (because it was ALWAYS the negate of `computeFocalPointOffset`). The new signature is `ResliceCursorWidget.updateCameraPoints(renderer, viewType, resetFocalPoint, keepCenterFocalDistance, computeFocalPointOffset)`
6
6
 
7
+ - **vtkAxesActor**: `setXAxisColor`, `setYAxisColor`, `setZAxisColor` now take a single `RGBColor` (array of 3 numbers) instead of 3 numbers for each color component. The `get*AxisColor` methods now return an array of 3 numbers instead of an object with `r`, `g`, `b` properties.
8
+
7
9
  ## From 28.x to 29
8
10
 
9
11
  - **getOpenGLRenderWindow**: `getOpenGLRenderWindow` has been renamed to `getApiSpecificRenderWindow` in `vtkFullScreenRenderWindow`, `vtkGenericRenderWindow` and `vtkViewProxy` to support WebGL and WebGPU backend. ([#2816](https://github.com/Kitware/vtk-js/pull/2816))
@@ -83,9 +85,9 @@ SplineWidget's handles now scale up automatically.
83
85
 
84
86
  ## From 19.x to 20
85
87
 
86
- In ShapeWidget:
87
- - `setLabelTextCallback` is replaced by `text` substate.
88
- - `setPixelScale` has been removed. It should be replaced by point handle `scale1` mixin and `scaleInPixels`.
88
+ In ShapeWidget:
89
+ - `setLabelTextCallback` is replaced by `text` substate.
90
+ - `setPixelScale` has been removed. It should be replaced by point handle `scale1` mixin and `scaleInPixels`.
89
91
  - `useHandles` has been removed. It should be replaced by `setHandleVisibility`.
90
92
  - `resetAfterPointPlacement` is now false by default.
91
93
 
@@ -1,99 +1,102 @@
1
1
  import vtkActor, { IActorInitialValues } from './Actor';
2
+ import { RGBColor } from './../../types';
2
3
 
3
4
  /**
4
- *
5
+ * Represents the initial values for the AxesActor.
5
6
  */
6
7
  export interface IAxesActorInitialValues extends IActorInitialValues {}
7
8
 
9
+ /**
10
+ * Represents an actor that displays axes in a 3D scene.
11
+ */
8
12
  export interface vtkAxesActor extends vtkActor {
9
-
10
- /**
11
- *
12
- */
13
- getConfig(): object;
14
-
15
- /**
16
- *
17
- */
18
- getXConfig(): object;
19
-
20
- /**
21
- *
22
- */
23
- getYConfig(): object;
24
-
25
- /**
26
- *
27
- */
28
- getZConfig(): object;
29
-
30
- /**
31
- *
32
- */
33
- getXAxisColor(): number[];
34
-
35
- /**
36
- *
37
- */
38
- getYAxisColor(): number[];
39
-
40
- /**
41
- *
42
- */
43
- getZAxisColor(): number[];
44
-
45
- /**
46
- *
47
- * @param config
48
- */
49
- setConfig(config: object): boolean;
50
-
51
- /**
52
- *
53
- * @param config
54
- */
55
- setXConfig(config: object): boolean;
56
-
57
- /**
58
- *
59
- * @param config
60
- */
61
- setYConfig(config: object): boolean;
62
-
63
- /**
64
- *
65
- * @param config
66
- */
67
- setZConfig(config: object): boolean;
68
-
69
- /**
70
- * Set X axis color.
71
- * @param {Number} r Defines the red component (between 0 and 1).
72
- * @param {Number} g Defines the green component (between 0 and 1).
73
- * @param {Number} b Defines the blue component (between 0 and 1).
74
- */
75
- setXAxisColor(r: number, g: number, b: number): boolean;
76
-
77
- /**
78
- * Set Y axis color.
79
- * @param {Number} r Defines the red component (between 0 and 1).
80
- * @param {Number} g Defines the green component (between 0 and 1).
81
- * @param {Number} b Defines the blue component (between 0 and 1).
82
- */
83
- setYAxisColor(r: number, g: number, b: number): boolean;
84
-
85
- /**
86
- * Set Z axis color.
87
- * @param {Number} r Defines the red component (between 0 and 1).
88
- * @param {Number} g Defines the green component (between 0 and 1).
89
- * @param {Number} b Defines the blue component (between 0 and 1).
90
- */
91
- setZAxisColor(r: number, g: number, b: number): boolean;
92
-
93
- /**
94
- *
95
- */
96
- update(): void;
13
+ /**
14
+ * Get config object of the actor.
15
+ */
16
+ getConfig(): object;
17
+
18
+ /**
19
+ * Get config object of the X axis.
20
+ */
21
+ getXConfig(): object;
22
+
23
+ /**
24
+ * Get config object of the Y axis.
25
+ */
26
+ getYConfig(): object;
27
+
28
+ /**
29
+ * Get config object of the Z axis.
30
+ */
31
+ getZConfig(): object;
32
+
33
+ /**
34
+ * Retrieves the color of the X-axis.
35
+ *
36
+ * @return {RGBColor} The color of the X-axis.
37
+ */
38
+ getXAxisColor(): RGBColor;
39
+
40
+ /**
41
+ * Retrieves the color of the Y-axis.
42
+ *
43
+ * @return {RGBColor} The color of the Y-axis.
44
+ */
45
+ getYAxisColor(): RGBColor;
46
+
47
+ /**
48
+ * Retrieves the color of the Z-axis.
49
+ *
50
+ * @return {RGBColor} The color of the Z-axis.
51
+ */
52
+ getZAxisColor(): RGBColor;
53
+
54
+ /**
55
+ * Set config object of the actor.
56
+ * @param config
57
+ */
58
+ setConfig(config: object): boolean;
59
+
60
+ /**
61
+ * Set config object of the X axis.
62
+ * @param config
63
+ */
64
+ setXConfig(config: object): boolean;
65
+
66
+ /**
67
+ * Set config object of the Y axis.
68
+ * @param config
69
+ */
70
+ setYConfig(config: object): boolean;
71
+
72
+ /**
73
+ * Set config object of the Z axis.
74
+ * @param config
75
+ */
76
+ setZConfig(config: object): boolean;
77
+
78
+ /**
79
+ * Set X axis color.
80
+ * @param {RGBColor} rgb An Array of the RGB color.
81
+ */
82
+ setXAxisColor(rgb: RGBColor): boolean;
83
+
84
+ /**
85
+ * Set Y axis color.
86
+ * @param {RGBColor} rgb An Array of the RGB color.
87
+ */
88
+ setYAxisColor(rgb: RGBColor): boolean;
89
+
90
+ /**
91
+ * Set Z axis color.
92
+ * @param {RGBColor} rgb An Array of the RGB color.
93
+ */
94
+ setZAxisColor(rgb: RGBColor): boolean;
95
+
96
+ /**
97
+ * Update the actor.
98
+ */
99
+ update(): void;
97
100
  }
98
101
 
99
102
  /**
@@ -111,15 +114,15 @@ export function extend(publicAPI: object, model: object, initialValues?: IAxesAc
111
114
  */
112
115
  export function newInstance(initialValues?: IAxesActorInitialValues): vtkAxesActor;
113
116
 
114
- /**
115
- * vtkAxesActor is a hybrid 2D/3D actor used to represent 3D axes in a scene.
116
- * The user can define the geometry to use for the shaft or the tip,
117
- * and the user can set the text for the three axes. The text will appear
118
- * to follow the camera since it is implemented by means of vtkCaptionActor2D.
119
- * All of the functionality of the underlying vtkCaptionActor2D objects are accessible so that,
120
- * for instance, the font attributes of the axes text can be manipulated through vtkTextProperty.
121
- * Since this class inherits from vtkProp3D, one can apply a user transform to the underlying
122
- * geometry and the positioning of the labels. For example, a rotation transform could be used to
117
+ /**
118
+ * vtkAxesActor is a hybrid 2D/3D actor used to represent 3D axes in a scene.
119
+ * The user can define the geometry to use for the shaft or the tip,
120
+ * and the user can set the text for the three axes. The text will appear
121
+ * to follow the camera since it is implemented by means of vtkCaptionActor2D.
122
+ * All of the functionality of the underlying vtkCaptionActor2D objects are accessible so that,
123
+ * for instance, the font attributes of the axes text can be manipulated through vtkTextProperty.
124
+ * Since this class inherits from vtkProp3D, one can apply a user transform to the underlying
125
+ * geometry and the positioning of the labels. For example, a rotation transform could be used to
123
126
  * generate a left-handed axes representation.
124
127
  * @see [vtkAnnotatedCubeActor](./Rendering_Core_AnnotatedCubeActor.html)
125
128
  * @see [vtkOrientationMarkerWidget](./Interaction_Widgets_OrientationMarkerWidget.html)
@@ -45,6 +45,22 @@ function applyTextStyle(ctx, style) {
45
45
  ctx.fillStyle = style.fontColor;
46
46
  ctx.font = `${style.fontStyle} ${style.fontSize}px ${style.fontFamily}`;
47
47
  }
48
+ function defaultGenerateTicks(publicApi, model) {
49
+ return dataBounds => {
50
+ const ticks = [];
51
+ const tickStrings = [];
52
+ for (let i = 0; i < 3; i++) {
53
+ const scale = d3.scaleLinear().domain([dataBounds[i * 2], dataBounds[i * 2 + 1]]);
54
+ ticks[i] = scale.ticks(5);
55
+ const format = scale.tickFormat(5);
56
+ tickStrings[i] = ticks[i].map(format);
57
+ }
58
+ return {
59
+ ticks,
60
+ tickStrings
61
+ };
62
+ };
63
+ }
48
64
 
49
65
  // many properties of this actor depend on the API specific view The main
50
66
  // dependency being the resolution as that drives what font sizes to use.
@@ -534,25 +550,18 @@ function vtkCubeAxesActor(publicAPI, model) {
534
550
  }
535
551
 
536
552
  // compute tick marks for axes
537
- const ticks = [];
538
- const tickStrings = [];
539
- for (let i = 0; i < 3; i++) {
540
- const scale = d3.scaleLinear().domain([model.dataBounds[i * 2], model.dataBounds[i * 2 + 1]]);
541
- ticks[i] = scale.ticks(5);
542
- const format = scale.tickFormat(5);
543
- tickStrings[i] = ticks[i].map(format);
544
- }
553
+ const t = model.generateTicks(model.dataBounds);
545
554
 
546
555
  // update gridlines / edge lines
547
- publicAPI.updatePolyData(facesToDraw, edgesToDraw, ticks);
556
+ publicAPI.updatePolyData(facesToDraw, edgesToDraw, t.ticks);
548
557
 
549
558
  // compute label world coords and text
550
- publicAPI.updateTextData(facesToDraw, edgesToDraw, ticks, tickStrings);
559
+ publicAPI.updateTextData(facesToDraw, edgesToDraw, t.ticks, t.tickStrings);
551
560
 
552
561
  // rebuild the texture only when force or changed bounds, face
553
562
  // visibility changes do to change the atlas
554
563
  if (boundsChanged || model.forceUpdate) {
555
- publicAPI.updateTextureAtlas(tickStrings);
564
+ publicAPI.updateTextureAtlas(t.tickStrings);
556
565
  }
557
566
  }
558
567
  model.forceUpdate = false;
@@ -675,7 +684,7 @@ function vtkCubeAxesActor(publicAPI, model) {
675
684
  // Object factory
676
685
  // ----------------------------------------------------------------------------
677
686
 
678
- function defaultValues(initialValues) {
687
+ function defaultValues(publicAPI, model, initialValues) {
679
688
  return {
680
689
  boundsScaleFactor: 1.3,
681
690
  camera: null,
@@ -684,20 +693,23 @@ function defaultValues(initialValues) {
684
693
  gridLines: true,
685
694
  axisLabels: null,
686
695
  axisTitlePixelOffset: 35.0,
696
+ tickLabelPixelOffset: 12.0,
697
+ generateTicks: defaultGenerateTicks(),
698
+ ...initialValues,
687
699
  axisTextStyle: {
688
700
  fontColor: 'white',
689
701
  fontStyle: 'normal',
690
702
  fontSize: 18,
691
- fontFamily: 'serif'
703
+ fontFamily: 'serif',
704
+ ...initialValues?.axisTextStyle
692
705
  },
693
- tickLabelPixelOffset: 12.0,
694
706
  tickTextStyle: {
695
707
  fontColor: 'white',
696
708
  fontStyle: 'normal',
697
709
  fontSize: 14,
698
- fontFamily: 'serif'
699
- },
700
- ...initialValues
710
+ fontFamily: 'serif',
711
+ ...initialValues?.tickTextStyle
712
+ }
701
713
  };
702
714
  }
703
715
 
@@ -705,10 +717,8 @@ function defaultValues(initialValues) {
705
717
 
706
718
  function extend(publicAPI, model) {
707
719
  let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
708
- Object.assign(model, defaultValues(initialValues));
709
-
710
720
  // Inheritance
711
- vtkActor.extend(publicAPI, model, initialValues);
721
+ vtkActor.extend(publicAPI, model, defaultValues(publicAPI, model, initialValues));
712
722
 
713
723
  // internal variables
714
724
  model.lastFacesToDraw = [false, false, false, false, false, false];
@@ -733,7 +743,7 @@ function extend(publicAPI, model) {
733
743
  model.gridActor.setProperty(publicAPI.getProperty());
734
744
  model.gridActor.setParentProp(publicAPI);
735
745
  model.textPolyData = vtkPolyData.newInstance();
736
- macro.setGet(publicAPI, model, ['axisTitlePixelOffset', 'boundsScaleFactor', 'faceVisibilityAngle', 'gridLines', 'tickLabelPixelOffset']);
746
+ macro.setGet(publicAPI, model, ['axisTitlePixelOffset', 'boundsScaleFactor', 'faceVisibilityAngle', 'gridLines', 'tickLabelPixelOffset', 'generateTicks']);
737
747
  macro.setGetArray(publicAPI, model, ['dataBounds'], 6);
738
748
  macro.setGetArray(publicAPI, model, ['axisLabels'], 3);
739
749
  macro.get(publicAPI, model, ['axisTextStyle', 'tickTextStyle', 'camera', 'tmTexture', 'textValues', 'textPolyData', 'tickCounts', 'gridActor']);
@@ -171,6 +171,23 @@ export interface vtkWidgetManager extends vtkObject {
171
171
  * Release the focus.
172
172
  */
173
173
  releaseFocus(): void;
174
+
175
+ /**
176
+ * Sets the default cursor styles.
177
+ *
178
+ * Known style keys:
179
+ * - default: when not interacting with a widget
180
+ * - hover: when hovering over a widget.
181
+ *
182
+ * If a known style key is not present, the cursor style will not be changed.
183
+ * @param {Record<string, string>} cursorStyles
184
+ */
185
+ setCursorStyles(cursorStyles: Record<string, string>): boolean;
186
+
187
+ /**
188
+ * Retrieves the current cursor styles.
189
+ */
190
+ getCursorStyles(): Record<string, string>;
174
191
  }
175
192
 
176
193
  export interface IWidgetManagerInitialValues {
@@ -157,7 +157,12 @@ function vtkWidgetManager(publicAPI, model) {
157
157
  }
158
158
 
159
159
  // Default cursor behavior
160
- model._apiSpecificRenderWindow.setCursor(widget ? 'pointer' : 'default');
160
+ const cursorStyles = publicAPI.getCursorStyles();
161
+ const style = widget ? 'hover' : 'default';
162
+ const cursor = cursorStyles[style];
163
+ if (cursor) {
164
+ model._apiSpecificRenderWindow.setCursor(cursor);
165
+ }
161
166
  model.activeWidget = null;
162
167
  let wantRender = false;
163
168
  if (model.widgetInFocus === widget && widget.hasFocus()) {
@@ -407,30 +412,40 @@ function vtkWidgetManager(publicAPI, model) {
407
412
  // Object factory
408
413
  // ----------------------------------------------------------------------------
409
414
 
410
- const DEFAULT_VALUES = {
411
- // _camera: null,
412
- // _selector: null,
413
- // _currentUpdateSelectionCallID: null,
414
- viewId: null,
415
- widgets: [],
416
- activeWidget: null,
417
- renderer: null,
418
- viewType: ViewTypes.DEFAULT,
419
- isAnimating: false,
420
- pickingEnabled: true,
421
- selections: null,
422
- previousSelectedData: null,
423
- widgetInFocus: null,
424
- captureOn: CaptureOn.MOUSE_MOVE
415
+ const defaultValues = function () {
416
+ let initialValues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
417
+ return {
418
+ // _camera: null,
419
+ // _selector: null,
420
+ // _currentUpdateSelectionCallID: null,
421
+ viewId: null,
422
+ widgets: [],
423
+ activeWidget: null,
424
+ renderer: null,
425
+ viewType: ViewTypes.DEFAULT,
426
+ isAnimating: false,
427
+ pickingEnabled: true,
428
+ selections: null,
429
+ previousSelectedData: null,
430
+ widgetInFocus: null,
431
+ captureOn: CaptureOn.MOUSE_MOVE,
432
+ ...initialValues,
433
+ cursorStyles: initialValues.cursorStyles ? {
434
+ ...initialValues.cursorStyles
435
+ } : {
436
+ default: 'default',
437
+ hover: 'pointer'
438
+ }
439
+ };
425
440
  };
426
441
 
427
442
  // ----------------------------------------------------------------------------
428
443
 
429
444
  function extend(publicAPI, model) {
430
445
  let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
431
- Object.assign(model, DEFAULT_VALUES, initialValues);
446
+ Object.assign(model, defaultValues(initialValues));
432
447
  macro.obj(publicAPI, model);
433
- macro.setGet(publicAPI, model, ['captureOn', {
448
+ macro.setGet(publicAPI, model, ['captureOn', 'cursorStyles', {
434
449
  type: 'enum',
435
450
  name: 'viewType',
436
451
  enum: ViewTypes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "30.1.2",
3
+ "version": "30.3.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",
package/types.d.ts CHANGED
@@ -56,7 +56,7 @@ declare type Matrix3x3 = [
56
56
  number
57
57
  ];
58
58
  /**
59
- * @deprecated The `Point` type is depracted, please use `Vector3` instead.
59
+ * @deprecated The `Point` type is deprecated, please use `Vector3` instead.
60
60
  */
61
61
  declare type Point = Vector3;
62
62
  declare type HSLColor = [number, number, number];