@kitware/vtk.js 19.8.0 → 20.0.3

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.
Files changed (37) hide show
  1. package/BREAKING_CHANGES.md +10 -0
  2. package/Common/Core/Math/index.js +2 -0
  3. package/Common/Core/Math.d.ts +8 -8
  4. package/Common/DataModel/ImageData.js +2 -4
  5. package/Common/DataModel/Plane.d.ts +2 -2
  6. package/Filters/General/AppendPolyData.js +2 -2
  7. package/Interaction/Manipulators/MouseCameraTrackballZoomManipulator.js +1 -1
  8. package/Rendering/Core/Picker.js +3 -3
  9. package/Rendering/Core/RenderWindow.js +12 -0
  10. package/Rendering/OpenGL/HardwareSelector.js +4 -1
  11. package/Rendering/OpenGL/Renderer.js +0 -5
  12. package/Rendering/OpenGL/Texture.js +4 -76
  13. package/Rendering/WebGPU/HardwareSelector.js +17 -13
  14. package/Rendering/WebGPU/ImageMapper.js +13 -7
  15. package/Rendering/WebGPU/Renderer.js +0 -5
  16. package/Rendering/WebGPU/Texture.js +1 -1
  17. package/Widgets/Representations/CircleContextRepresentation.js +3 -5
  18. package/Widgets/Representations/ContextRepresentation.js +3 -0
  19. package/Widgets/Representations/RectangleContextRepresentation.js +2 -2
  20. package/Widgets/SVG/SVGLandmarkRepresentation/Constants.js +28 -0
  21. package/Widgets/SVG/SVGLandmarkRepresentation.js +39 -21
  22. package/Widgets/Widgets3D/EllipseWidget/behavior.js +6 -1
  23. package/Widgets/Widgets3D/EllipseWidget/state.js +22 -2
  24. package/Widgets/Widgets3D/EllipseWidget.js +29 -21
  25. package/Widgets/Widgets3D/LineWidget.js +5 -2
  26. package/Widgets/Widgets3D/PaintWidget/behavior.js +107 -0
  27. package/Widgets/Widgets3D/PaintWidget/state.js +29 -0
  28. package/Widgets/Widgets3D/PaintWidget.js +5 -134
  29. package/Widgets/Widgets3D/PolyLineWidget.js +6 -0
  30. package/Widgets/Widgets3D/RectangleWidget/behavior.js +6 -1
  31. package/Widgets/Widgets3D/RectangleWidget/state.js +22 -2
  32. package/Widgets/Widgets3D/RectangleWidget.js +28 -20
  33. package/Widgets/Widgets3D/ShapeWidget/Constants.js +5 -66
  34. package/Widgets/Widgets3D/ShapeWidget/behavior.js +131 -117
  35. package/Widgets/Widgets3D/ShapeWidget.js +37 -15
  36. package/macros.js +22 -4
  37. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import vtkStateBuilder from '../../Core/StateBuilder.js';
2
+ import { TextPosition } from '../ShapeWidget/Constants.js';
2
3
 
3
4
  function generateState() {
4
5
  return vtkStateBuilder.createBuilder().addStateFromMixin({
@@ -7,7 +8,7 @@ function generateState() {
7
8
  name: 'point1Handle',
8
9
  initialValues: {
9
10
  scale1: 10,
10
- origin: [0, 0, 0],
11
+ origin: [undefined, undefined, undefined],
11
12
  visible: false
12
13
  }
13
14
  }).addStateFromMixin({
@@ -16,7 +17,7 @@ function generateState() {
16
17
  name: 'point2Handle',
17
18
  initialValues: {
18
19
  scale1: 10,
19
- origin: [0, 0, 0],
20
+ origin: [undefined, undefined, undefined],
20
21
  visible: false
21
22
  }
22
23
  }).addStateFromMixin({
@@ -27,6 +28,25 @@ function generateState() {
27
28
  visible: false,
28
29
  scale3: [1, 1, 1]
29
30
  }
31
+ }) // FIXME: How to not duplicate with RectangleWidget
32
+ .addStateFromMixin({
33
+ labels: ['SVGtext'],
34
+ mixins: ['origin', 'color', 'text', 'visible'],
35
+ name: 'text',
36
+ initialValues: {
37
+ /* text is empty to set a text filed in the SVGLayer and to avoid
38
+ * displaying text before positioning the handles */
39
+ text: '',
40
+ visible: false,
41
+ origin: [0, 0, 0]
42
+ }
43
+ }) // FIXME: to move in text handle sub state
44
+ .addField({
45
+ name: 'textPosition',
46
+ initialValue: [TextPosition.CENTER, TextPosition.CENTER, TextPosition.CENTER]
47
+ }).addField({
48
+ name: 'textWorldMargin',
49
+ initialValue: 0
30
50
  }).build();
31
51
  }
32
52
 
@@ -1,17 +1,16 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
3
  import macro from '../../macros.js';
3
- import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
4
+ import vtkCircleContextRepresentation from '../Representations/CircleContextRepresentation.js';
4
5
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
6
+ import vtkShapeWidget from './ShapeWidget.js';
5
7
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
6
- import vtkCircleContextRepresentation from '../Representations/CircleContextRepresentation.js';
8
+ import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
7
9
  import widgetBehavior from './EllipseWidget/behavior.js';
8
10
  import generateState from './EllipseWidget/state.js';
9
- import vtkShapeWidget from './ShapeWidget.js';
10
11
  import { BehaviorCategory, ShapeBehavior } from './ShapeWidget/Constants.js';
11
12
  import { ViewTypes } from '../Core/WidgetManager/Constants.js';
12
13
 
13
- var _None;
14
-
15
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
16
15
 
17
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -21,7 +20,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
21
20
  function vtkEllipseWidget(publicAPI, model) {
22
21
  model.classHierarchy.push('vtkEllipseWidget'); // --- Widget Requirement ---------------------------------------------------
23
22
 
24
- model.methodsToLink = ['activeScaleFactor', 'activeColor', 'useActiveColor', 'glyphResolution', 'defaultScale', 'drawBorder', 'drawFace', 'opacity'];
23
+ model.methodsToLink = [].concat(_toConsumableArray(model.methodsToLink), ['activeScaleFactor', 'activeColor', 'useActiveColor', 'glyphResolution', 'defaultScale', 'drawBorder', 'drawFace', 'opacity']);
25
24
  model.behavior = widgetBehavior;
26
25
 
27
26
  publicAPI.getRepresentationsForViewType = function (viewType) {
@@ -33,10 +32,20 @@ function vtkEllipseWidget(publicAPI, model) {
33
32
  default:
34
33
  return [{
35
34
  builder: vtkSphereHandleRepresentation,
36
- labels: ['moveHandle']
35
+ labels: ['moveHandle'],
36
+ initialValues: {
37
+ scaleInPixels: true
38
+ }
37
39
  }, {
38
40
  builder: vtkCircleContextRepresentation,
39
41
  labels: ['ellipseHandle']
42
+ }, {
43
+ builder: vtkSVGLandmarkRepresentation,
44
+ initialValues: {
45
+ showCircle: false,
46
+ text: ''
47
+ },
48
+ labels: ['SVGtext']
40
49
  }];
41
50
  }
42
51
  }; // --------------------------------------------------------------------------
@@ -47,26 +56,25 @@ function vtkEllipseWidget(publicAPI, model) {
47
56
 
48
57
  model.manipulator = vtkPlanePointManipulator.newInstance();
49
58
  model.widgetState = generateState();
50
- model.shapeHandle = model.widgetState.getEllipseHandle();
51
- model.point1Handle = model.widgetState.getPoint1Handle();
52
- model.point2Handle = model.widgetState.getPoint2Handle();
53
- model.point1Handle.setManipulator(model.manipulator);
54
- model.point2Handle.setManipulator(model.manipulator);
55
59
  } // ----------------------------------------------------------------------------
56
60
 
57
61
 
58
- var DEFAULT_VALUES = {
59
- modifierBehavior: {
60
- None: (_None = {}, _defineProperty(_None, BehaviorCategory.PLACEMENT, ShapeBehavior[BehaviorCategory.PLACEMENT].CLICK_AND_DRAG), _defineProperty(_None, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CENTER_TO_CORNER), _defineProperty(_None, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FREE), _None),
61
- Shift: _defineProperty({}, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FIXED),
62
- Control: _defineProperty({}, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CORNER_TO_CORNER)
63
- }
64
- }; // ----------------------------------------------------------------------------
62
+ function defaultValues(initialValues) {
63
+ var _None;
64
+
65
+ return _objectSpread({
66
+ modifierBehavior: {
67
+ None: (_None = {}, _defineProperty(_None, BehaviorCategory.PLACEMENT, ShapeBehavior[BehaviorCategory.PLACEMENT].CLICK_AND_DRAG), _defineProperty(_None, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CENTER_TO_CORNER), _defineProperty(_None, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FREE), _None),
68
+ Shift: _defineProperty({}, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FIXED),
69
+ Control: _defineProperty({}, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CORNER_TO_CORNER)
70
+ }
71
+ }, initialValues);
72
+ } // ----------------------------------------------------------------------------
73
+
65
74
 
66
75
  function extend(publicAPI, model) {
67
76
  var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
68
- Object.assign(model, _objectSpread(_objectSpread({}, vtkShapeWidget.DEFAULT_VALUES), DEFAULT_VALUES), initialValues);
69
- vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
77
+ vtkShapeWidget.extend(publicAPI, model, defaultValues(initialValues));
70
78
  macro.setGet(publicAPI, model, ['manipulator', 'widgetState']);
71
79
  vtkEllipseWidget(publicAPI, model);
72
80
  } // ----------------------------------------------------------------------------
@@ -114,8 +114,11 @@ function vtkLineWidget(publicAPI, model) {
114
114
  initialValues: {
115
115
  showCircle: false,
116
116
  isVisible: false,
117
- offsetText: true,
118
- text: ''
117
+ text: '',
118
+ textProps: {
119
+ dx: 12,
120
+ dy: -12
121
+ }
119
122
  },
120
123
  labels: ['SVGtext']
121
124
  }, {
@@ -0,0 +1,107 @@
1
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
+ import macro from '../../../macros.js';
3
+ import { c as cross } from '../../../vendor/gl-matrix/esm/vec3.js';
4
+
5
+ function widgetBehavior(publicAPI, model) {
6
+ publicAPI.handleLeftButtonPress = function (callData) {
7
+ if (!model.activeState || !model.activeState.getActive()) {
8
+ return macro.VOID;
9
+ }
10
+
11
+ model.painting = true;
12
+ var trailCircle = model.widgetState.addTrail();
13
+ trailCircle.set(model.activeState.get('origin', 'up', 'right', 'direction', 'scale1'));
14
+ publicAPI.invokeStartInteractionEvent();
15
+ return macro.EVENT_ABORT;
16
+ };
17
+
18
+ publicAPI.handleMouseMove = function (callData) {
19
+ return publicAPI.handleEvent(callData);
20
+ };
21
+
22
+ publicAPI.handleLeftButtonRelease = function () {
23
+ if (model.painting) {
24
+ publicAPI.invokeEndInteractionEvent();
25
+ model.widgetState.clearTrailList();
26
+ }
27
+
28
+ model.painting = false;
29
+ return model.hasFocus ? macro.EVENT_ABORT : macro.VOID;
30
+ };
31
+
32
+ publicAPI.handleEvent = function (callData) {
33
+ if (model.manipulator && model.activeState && model.activeState.getActive()) {
34
+ var _model$activeState, _model$activeState2, _model$activeState3;
35
+
36
+ var normal = model.camera.getDirectionOfProjection();
37
+ var up = model.camera.getViewUp();
38
+ var right = [];
39
+ cross(right, up, normal);
40
+
41
+ (_model$activeState = model.activeState).setUp.apply(_model$activeState, _toConsumableArray(up));
42
+
43
+ (_model$activeState2 = model.activeState).setRight.apply(_model$activeState2, right);
44
+
45
+ (_model$activeState3 = model.activeState).setDirection.apply(_model$activeState3, _toConsumableArray(normal));
46
+
47
+ model.manipulator.setNormal(normal);
48
+ var worldCoords = model.manipulator.handleEvent(callData, model.apiSpecificRenderWindow);
49
+
50
+ if (worldCoords.length) {
51
+ var _model$widgetState, _model$activeState4;
52
+
53
+ (_model$widgetState = model.widgetState).setTrueOrigin.apply(_model$widgetState, _toConsumableArray(worldCoords));
54
+
55
+ (_model$activeState4 = model.activeState).setOrigin.apply(_model$activeState4, _toConsumableArray(worldCoords));
56
+
57
+ if (model.painting) {
58
+ var trailCircle = model.widgetState.addTrail();
59
+ trailCircle.set(model.activeState.get('origin', 'up', 'right', 'direction', 'scale1'));
60
+ }
61
+ }
62
+
63
+ publicAPI.invokeInteractionEvent();
64
+ return macro.EVENT_ABORT;
65
+ }
66
+
67
+ return macro.VOID;
68
+ };
69
+
70
+ publicAPI.grabFocus = function () {
71
+ if (!model.hasFocus) {
72
+ model.activeState = model.widgetState.getHandle();
73
+ model.activeState.activate();
74
+ model.interactor.requestAnimation(publicAPI);
75
+ var canvas = model.apiSpecificRenderWindow.getCanvas();
76
+
77
+ canvas.onmouseenter = function () {
78
+ if (model.hasFocus && model.activeState === model.widgetState.getHandle()) {
79
+ model.activeState.setVisible(true);
80
+ }
81
+ };
82
+
83
+ canvas.onmouseleave = function () {
84
+ if (model.hasFocus && model.activeState === model.widgetState.getHandle()) {
85
+ model.activeState.setVisible(false);
86
+ }
87
+ };
88
+ }
89
+
90
+ model.hasFocus = true;
91
+ };
92
+
93
+ publicAPI.loseFocus = function () {
94
+ if (model.hasFocus) {
95
+ model.interactor.cancelAnimation(publicAPI);
96
+ }
97
+
98
+ model.widgetState.deactivate();
99
+ model.widgetState.getHandle().deactivate();
100
+ model.activeState = null;
101
+ model.hasFocus = false;
102
+ };
103
+
104
+ macro.get(publicAPI, model, ['painting']);
105
+ }
106
+
107
+ export { widgetBehavior as default };
@@ -0,0 +1,29 @@
1
+ import vtkStateBuilder from '../../Core/StateBuilder.js';
2
+
3
+ function generateState(radius) {
4
+ return vtkStateBuilder.createBuilder().addField({
5
+ name: 'trueOrigin',
6
+ initialValue: [0, 0, 0]
7
+ }).addStateFromMixin({
8
+ labels: ['handle'],
9
+ mixins: ['origin', 'color', 'scale1', 'orientation', 'manipulator', 'visible'],
10
+ name: 'handle',
11
+ initialValues: {
12
+ scale1: radius * 2,
13
+ origin: [0, 0, 0],
14
+ orientation: [1, 0, 0, 0, 1, 0, 0, 0, 1],
15
+ visible: true
16
+ }
17
+ }).addDynamicMixinState({
18
+ labels: ['trail'],
19
+ mixins: ['origin', 'color', 'scale1', 'orientation'],
20
+ name: 'trail',
21
+ initialValues: {
22
+ scale1: radius * 2,
23
+ origin: [0, 0, 0],
24
+ orientation: [1, 0, 0, 0, 1, 0, 0, 0, 1]
25
+ }
26
+ }).build();
27
+ }
28
+
29
+ export { generateState as default };
@@ -1,125 +1,20 @@
1
- import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
1
  import macro from '../../macros.js';
3
2
  import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
4
3
  import vtkCircleContextRepresentation from '../Representations/CircleContextRepresentation.js';
5
4
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
6
5
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
7
- import vtkStateBuilder from '../Core/StateBuilder.js';
6
+ import widgetBehavior from './PaintWidget/behavior.js';
7
+ import generateState from './PaintWidget/state.js';
8
8
  import { ViewTypes } from '../Core/WidgetManager/Constants.js';
9
- import { c as cross } from '../../vendor/gl-matrix/esm/vec3.js';
10
9
 
11
- // Widget linked to a view
12
- // ----------------------------------------------------------------------------
13
-
14
- function widgetBehavior(publicAPI, model) {
15
- publicAPI.handleLeftButtonPress = function (callData) {
16
- if (!model.activeState || !model.activeState.getActive()) {
17
- return macro.VOID;
18
- }
19
-
20
- model.painting = true;
21
- var trailCircle = model.widgetState.addTrail();
22
- trailCircle.set(model.activeState.get('origin', 'up', 'right', 'direction', 'scale1'));
23
- publicAPI.invokeStartInteractionEvent();
24
- return macro.EVENT_ABORT;
25
- };
26
-
27
- publicAPI.handleMouseMove = function (callData) {
28
- return publicAPI.handleEvent(callData);
29
- };
30
-
31
- publicAPI.handleLeftButtonRelease = function () {
32
- if (model.painting) {
33
- publicAPI.invokeEndInteractionEvent();
34
- model.widgetState.clearTrailList();
35
- }
36
-
37
- model.painting = false;
38
- return model.hasFocus ? macro.EVENT_ABORT : macro.VOID;
39
- };
40
-
41
- publicAPI.handleEvent = function (callData) {
42
- if (model.manipulator && model.activeState && model.activeState.getActive()) {
43
- var _model$activeState, _model$activeState2, _model$activeState3;
44
-
45
- var normal = model.camera.getDirectionOfProjection();
46
- var up = model.camera.getViewUp();
47
- var right = [];
48
- cross(right, up, normal);
49
-
50
- (_model$activeState = model.activeState).setUp.apply(_model$activeState, _toConsumableArray(up));
51
-
52
- (_model$activeState2 = model.activeState).setRight.apply(_model$activeState2, right);
53
-
54
- (_model$activeState3 = model.activeState).setDirection.apply(_model$activeState3, _toConsumableArray(normal));
55
-
56
- model.manipulator.setNormal(normal);
57
- var worldCoords = model.manipulator.handleEvent(callData, model.apiSpecificRenderWindow);
58
-
59
- if (worldCoords.length) {
60
- var _model$widgetState, _model$activeState4;
61
-
62
- (_model$widgetState = model.widgetState).setTrueOrigin.apply(_model$widgetState, _toConsumableArray(worldCoords));
63
-
64
- (_model$activeState4 = model.activeState).setOrigin.apply(_model$activeState4, _toConsumableArray(worldCoords));
65
-
66
- if (model.painting) {
67
- var trailCircle = model.widgetState.addTrail();
68
- trailCircle.set(model.activeState.get('origin', 'up', 'right', 'direction', 'scale1'));
69
- }
70
- }
71
-
72
- publicAPI.invokeInteractionEvent();
73
- return macro.EVENT_ABORT;
74
- }
75
-
76
- return macro.VOID;
77
- };
78
-
79
- publicAPI.grabFocus = function () {
80
- if (!model.hasFocus) {
81
- model.activeState = model.widgetState.getHandle();
82
- model.activeState.activate();
83
- model.interactor.requestAnimation(publicAPI);
84
- var canvas = model.apiSpecificRenderWindow.getCanvas();
85
-
86
- canvas.onmouseenter = function () {
87
- if (model.hasFocus && model.activeState === model.widgetState.getHandle()) {
88
- model.activeState.setVisible(true);
89
- }
90
- };
91
-
92
- canvas.onmouseleave = function () {
93
- if (model.hasFocus && model.activeState === model.widgetState.getHandle()) {
94
- model.activeState.setVisible(false);
95
- }
96
- };
97
- }
98
-
99
- model.hasFocus = true;
100
- };
101
-
102
- publicAPI.loseFocus = function () {
103
- if (model.hasFocus) {
104
- model.interactor.cancelAnimation(publicAPI);
105
- }
106
-
107
- model.widgetState.deactivate();
108
- model.widgetState.getHandle().deactivate();
109
- model.activeState = null;
110
- model.hasFocus = false;
111
- };
112
-
113
- macro.get(publicAPI, model, ['painting']);
114
- } // ----------------------------------------------------------------------------
115
10
  // Factory
116
11
  // ----------------------------------------------------------------------------
117
12
 
118
-
119
13
  function vtkPaintWidget(publicAPI, model) {
120
14
  model.classHierarchy.push('vtkPaintWidget'); // --- Widget Requirement ---------------------------------------------------
121
15
 
122
16
  model.behavior = widgetBehavior;
17
+ model.widgetState = generateState(model.radius);
123
18
 
124
19
  publicAPI.getRepresentationsForViewType = function (viewType) {
125
20
  switch (viewType) {
@@ -139,32 +34,8 @@ function vtkPaintWidget(publicAPI, model) {
139
34
  }];
140
35
  }
141
36
  }; // --- Widget Requirement ---------------------------------------------------
142
- // Default state
143
-
144
-
145
- model.widgetState = vtkStateBuilder.createBuilder().addField({
146
- name: 'trueOrigin',
147
- initialValue: [0, 0, 0]
148
- }).addStateFromMixin({
149
- labels: ['handle'],
150
- mixins: ['origin', 'color', 'scale1', 'orientation', 'manipulator', 'visible'],
151
- name: 'handle',
152
- initialValues: {
153
- scale1: model.radius * 2,
154
- origin: [0, 0, 0],
155
- orientation: [1, 0, 0, 0, 1, 0, 0, 0, 1],
156
- visible: true
157
- }
158
- }).addDynamicMixinState({
159
- labels: ['trail'],
160
- mixins: ['origin', 'color', 'scale1', 'orientation'],
161
- name: 'trail',
162
- initialValues: {
163
- scale1: model.radius * 2,
164
- origin: [0, 0, 0],
165
- orientation: [1, 0, 0, 0, 1, 0, 0, 0, 1]
166
- }
167
- }).build();
37
+
38
+
168
39
  var handle = model.widgetState.getHandle(); // Default manipulator
169
40
 
170
41
  model.manipulator = vtkPlanePointManipulator.newInstance();
@@ -39,6 +39,12 @@ function vtkPolyLineWidget(publicAPI, model) {
39
39
  }
40
40
  }, {
41
41
  builder: vtkSVGLandmarkRepresentation,
42
+ initialValues: {
43
+ textProps: {
44
+ dx: 12,
45
+ dy: -12
46
+ }
47
+ },
42
48
  labels: ['handles']
43
49
  }, {
44
50
  builder: vtkPolyLineRepresentation,
@@ -5,7 +5,12 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
5
5
 
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
7
7
  function widgetBehavior(publicAPI, model) {
8
- // We inherit shapeBehavior
8
+ model.shapeHandle = model.widgetState.getRectangleHandle();
9
+ model.point1Handle = model.widgetState.getPoint1Handle();
10
+ model.point2Handle = model.widgetState.getPoint2Handle();
11
+ model.point1Handle.setManipulator(model.manipulator);
12
+ model.point2Handle.setManipulator(model.manipulator); // We inherit shapeBehavior
13
+
9
14
  widgetBehavior$1(publicAPI, model);
10
15
 
11
16
  var superClass = _objectSpread({}, publicAPI);
@@ -1,4 +1,5 @@
1
1
  import vtkStateBuilder from '../../Core/StateBuilder.js';
2
+ import { TextPosition } from '../ShapeWidget/Constants.js';
2
3
 
3
4
  function generateState() {
4
5
  return vtkStateBuilder.createBuilder().addStateFromMixin({
@@ -7,7 +8,7 @@ function generateState() {
7
8
  name: 'point1Handle',
8
9
  initialValues: {
9
10
  scale1: 10,
10
- origin: [1, 0, 0],
11
+ origin: [undefined, undefined, undefined],
11
12
  visible: false
12
13
  }
13
14
  }).addStateFromMixin({
@@ -16,7 +17,7 @@ function generateState() {
16
17
  name: 'point2Handle',
17
18
  initialValues: {
18
19
  scale1: 10,
19
- origin: [1, 0, 0],
20
+ origin: [undefined, undefined, undefined],
20
21
  visible: false
21
22
  }
22
23
  }).addStateFromMixin({
@@ -26,6 +27,25 @@ function generateState() {
26
27
  initialValues: {
27
28
  visible: false
28
29
  }
30
+ }) // FIXME: How to not duplicate with EllipseWidget
31
+ .addStateFromMixin({
32
+ labels: ['SVGtext'],
33
+ mixins: ['origin', 'color', 'text', 'visible'],
34
+ name: 'text',
35
+ initialValues: {
36
+ /* text is empty to set a text filed in the SVGLayer and to avoid
37
+ * displaying text before positioning the handles */
38
+ text: '',
39
+ visible: false,
40
+ origin: [0, 0, 0]
41
+ }
42
+ }) // FIXME: to move in text handle sub state
43
+ .addField({
44
+ name: 'textPosition',
45
+ initialValue: [TextPosition.CENTER, TextPosition.CENTER, TextPosition.CENTER]
46
+ }).addField({
47
+ name: 'textWorldMargin',
48
+ initialValue: 0
29
49
  }).build();
30
50
  }
31
51
 
@@ -1,17 +1,16 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
2
3
  import macro from '../../macros.js';
3
- import vtkAbstractWidgetFactory from '../Core/AbstractWidgetFactory.js';
4
4
  import vtkPlanePointManipulator from '../Manipulators/PlaneManipulator.js';
5
+ import vtkShapeWidget from './ShapeWidget.js';
5
6
  import vtkSphereHandleRepresentation from '../Representations/SphereHandleRepresentation.js';
6
7
  import vtkRectangleContextRepresentation from '../Representations/RectangleContextRepresentation.js';
8
+ import vtkSVGLandmarkRepresentation from '../SVG/SVGLandmarkRepresentation.js';
7
9
  import widgetBehavior from './RectangleWidget/behavior.js';
8
10
  import generateState from './RectangleWidget/state.js';
9
- import vtkShapeWidget from './ShapeWidget.js';
10
11
  import { BehaviorCategory, ShapeBehavior } from './ShapeWidget/Constants.js';
11
12
  import { ViewTypes } from '../Core/WidgetManager/Constants.js';
12
13
 
13
- var _None;
14
-
15
14
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
16
15
 
17
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
@@ -20,7 +19,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
20
19
 
21
20
  function vtkRectangleWidget(publicAPI, model) {
22
21
  model.classHierarchy.push('vtkRectangleWidget');
23
- model.methodsToLink = ['activeScaleFactor', 'activeColor', 'useActiveColor', 'drawBorder', 'drawFace', 'opacity']; // --- Widget Requirement ---------------------------------------------------
22
+ model.methodsToLink = [].concat(_toConsumableArray(model.methodsToLink), ['activeScaleFactor', 'activeColor', 'useActiveColor', 'drawBorder', 'drawFace', 'opacity']); // --- Widget Requirement ---------------------------------------------------
24
23
 
25
24
  model.behavior = widgetBehavior;
26
25
 
@@ -33,10 +32,20 @@ function vtkRectangleWidget(publicAPI, model) {
33
32
  default:
34
33
  return [{
35
34
  builder: vtkSphereHandleRepresentation,
36
- labels: ['moveHandle']
35
+ labels: ['moveHandle'],
36
+ initialValues: {
37
+ scaleInPixels: true
38
+ }
37
39
  }, {
38
40
  builder: vtkRectangleContextRepresentation,
39
41
  labels: ['rectangleHandle']
42
+ }, {
43
+ builder: vtkSVGLandmarkRepresentation,
44
+ initialValues: {
45
+ showCircle: false,
46
+ text: ''
47
+ },
48
+ labels: ['SVGtext']
40
49
  }];
41
50
  }
42
51
  }; // --------------------------------------------------------------------------
@@ -47,26 +56,25 @@ function vtkRectangleWidget(publicAPI, model) {
47
56
 
48
57
  model.manipulator = vtkPlanePointManipulator.newInstance();
49
58
  model.widgetState = generateState();
50
- model.shapeHandle = model.widgetState.getRectangleHandle();
51
- model.point1Handle = model.widgetState.getPoint1Handle();
52
- model.point2Handle = model.widgetState.getPoint2Handle();
53
- model.point1Handle.setManipulator(model.manipulator);
54
- model.point2Handle.setManipulator(model.manipulator);
55
59
  } // ----------------------------------------------------------------------------
56
60
 
57
61
 
58
- var DEFAULT_VALUES = {
59
- modifierBehavior: {
60
- None: (_None = {}, _defineProperty(_None, BehaviorCategory.PLACEMENT, ShapeBehavior[BehaviorCategory.PLACEMENT].CLICK_AND_DRAG), _defineProperty(_None, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CORNER_TO_CORNER), _defineProperty(_None, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FREE), _None),
61
- Shift: _defineProperty({}, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FIXED),
62
- Control: _defineProperty({}, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CENTER_TO_CORNER)
63
- }
64
- }; // ----------------------------------------------------------------------------
62
+ function defaultValues(initalValues) {
63
+ var _None;
64
+
65
+ return _objectSpread({
66
+ modifierBehavior: {
67
+ None: (_None = {}, _defineProperty(_None, BehaviorCategory.PLACEMENT, ShapeBehavior[BehaviorCategory.PLACEMENT].CLICK_AND_DRAG), _defineProperty(_None, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CORNER_TO_CORNER), _defineProperty(_None, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FREE), _None),
68
+ Shift: _defineProperty({}, BehaviorCategory.RATIO, ShapeBehavior[BehaviorCategory.RATIO].FIXED),
69
+ Control: _defineProperty({}, BehaviorCategory.POINTS, ShapeBehavior[BehaviorCategory.POINTS].CENTER_TO_CORNER)
70
+ }
71
+ }, initalValues);
72
+ } // ----------------------------------------------------------------------------
73
+
65
74
 
66
75
  function extend(publicAPI, model) {
67
76
  var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
68
- Object.assign(model, _objectSpread(_objectSpread({}, vtkShapeWidget.DEFAULT_VALUES), DEFAULT_VALUES), initialValues);
69
- vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
77
+ vtkShapeWidget.extend(publicAPI, model, defaultValues(initialValues));
70
78
  macro.setGet(publicAPI, model, ['manipulator', 'widgetState']);
71
79
  vtkRectangleWidget(publicAPI, model);
72
80
  } // ----------------------------------------------------------------------------