@kitware/vtk.js 24.18.7 → 24.18.10

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.
@@ -254,14 +254,19 @@ function vtkCellPicker(publicAPI, model) {
254
254
  var tempCellMap = createCellMap();
255
255
  var minCellMap = createCellMap();
256
256
  var numberOfCells = data.getNumberOfCells();
257
+ /* eslint-disable no-continue */
257
258
 
258
259
  for (var cellId = 0; cellId < numberOfCells; cellId++) {
259
260
  var pCoords = [0, 0, 0];
260
- minCellType = data.getCellType(cellId);
261
+ minCellType = data.getCellType(cellId); // Skip cells that are marked as empty
262
+
263
+ if (minCellType === CellType.VTK_EMPTY_CELL) {
264
+ continue;
265
+ }
266
+
261
267
  var cell = tempCellMap[minCellType];
262
268
 
263
269
  if (cell == null) {
264
- // eslint-disable-next-line no-continue
265
270
  continue;
266
271
  }
267
272
 
@@ -294,6 +299,8 @@ function vtkCellPicker(publicAPI, model) {
294
299
  }
295
300
  }
296
301
  }
302
+ /* eslint-enable no-continue */
303
+
297
304
  }
298
305
 
299
306
  if (minCellId >= 0 && tMin < model.globalTMin) {
@@ -2,7 +2,7 @@ import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import macro from '../../macros.js';
3
3
  import vtkActor from '../../Rendering/Core/Actor.js';
4
4
  import vtkMapper from '../../Rendering/Core/Mapper.js';
5
- import { B as areEquals, f as distance2BetweenPoints } from '../../Common/Core/Math/index.js';
5
+ import { B as areEquals } from '../../Common/Core/Math/index.js';
6
6
  import vtkBoundingBox from '../../Common/DataModel/BoundingBox.js';
7
7
  import vtkPolyData from '../../Common/DataModel/PolyData.js';
8
8
  import vtkTubeFilter from '../../Filters/General/TubeFilter.js';
@@ -104,21 +104,7 @@ function vtkPolyLineRepresentation(publicAPI, model) {
104
104
  subStates.push(subState);
105
105
  return subStates;
106
106
  }, []);
107
- var size = list.length; // Do not render last point if not visible or too close from previous point.
108
-
109
- if (size > 1) {
110
- var lastState = list[list.length - 1];
111
- var last = lastState.getOrigin();
112
- var prevLast = list[list.length - 2].getOrigin();
113
- var delta = distance2BetweenPoints(last, prevLast) > model.threshold ? 0 : 1;
114
-
115
- if (!delta && lastState.isVisible && !lastState.isVisible()) {
116
- delta++;
117
- }
118
-
119
- size -= delta;
120
- }
121
-
107
+ var size = list.length;
122
108
  var points = allocateSize(size, model.closePolyLine && size > 2);
123
109
 
124
110
  if (points) {
@@ -5,7 +5,7 @@ import vtkPointPicker from '../../../Rendering/Core/PointPicker.js';
5
5
  var MAX_POINTS = 3;
6
6
  function widgetBehavior(publicAPI, model) {
7
7
  model.classHierarchy.push('vtkAngleWidgetProp');
8
- var isDragging = null;
8
+ model._isDragging = false;
9
9
  var picker = vtkPointPicker.newInstance();
10
10
  picker.setPickFromList(1); // --------------------------------------------------------------------------
11
11
  // Display 2D
@@ -46,8 +46,8 @@ function widgetBehavior(publicAPI, model) {
46
46
  newHandle.setColor(moveHandle.getColor());
47
47
  newHandle.setScale1(moveHandle.getScale1());
48
48
  newHandle.setManipulator(manipulator);
49
- } else {
50
- isDragging = true;
49
+ } else if (model.dragable) {
50
+ model._isDragging = true;
51
51
 
52
52
  model._apiSpecificRenderWindow.setCursor('grabbing');
53
53
 
@@ -69,7 +69,8 @@ function widgetBehavior(publicAPI, model) {
69
69
  if (manipulator && model.pickable && model.dragable && model.activeState && model.activeState.getActive() && !ignoreKey(callData)) {
70
70
  var worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
71
71
 
72
- if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || isDragging)) {
72
+ if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || model._isDragging) && model.activeState.setOrigin // e.g. the line is pickable but not draggable
73
+ ) {
73
74
  model.activeState.setOrigin(worldCoords);
74
75
  publicAPI.invokeInteractionEvent();
75
76
  return macro.EVENT_ABORT;
@@ -87,32 +88,35 @@ function widgetBehavior(publicAPI, model) {
87
88
 
88
89
 
89
90
  publicAPI.handleLeftButtonRelease = function () {
90
- if (isDragging && model.pickable) {
91
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
92
+ return macro.VOID;
93
+ }
94
+
95
+ if (model.hasFocus && model.widgetState.getHandleList().length === MAX_POINTS) {
96
+ publicAPI.loseFocus();
97
+ return macro.VOID;
98
+ }
99
+
100
+ if (model._isDragging) {
91
101
  model._apiSpecificRenderWindow.setCursor('pointer');
92
102
 
93
103
  model.widgetState.deactivate();
94
104
 
95
105
  model._interactor.cancelAnimation(publicAPI);
96
106
 
97
- publicAPI.invokeEndInteractionEvent();
107
+ model._isDragging = false;
98
108
  } else if (model.activeState !== model.widgetState.getMoveHandle()) {
99
109
  model.widgetState.deactivate();
100
110
  }
101
111
 
102
112
  if (model.hasFocus && !model.activeState || model.activeState && !model.activeState.getActive()) {
103
- publicAPI.invokeEndInteractionEvent();
104
-
105
113
  model._widgetManager.enablePicking();
106
114
 
107
115
  model._interactor.render();
108
- } // Don't make any more points
109
-
110
-
111
- if (model.widgetState.getHandleList().length === MAX_POINTS) {
112
- publicAPI.loseFocus();
113
116
  }
114
117
 
115
- isDragging = false;
118
+ publicAPI.invokeEndInteractionEvent();
119
+ return macro.EVENT_ABORT;
116
120
  }; // --------------------------------------------------------------------------
117
121
  // Focus API - modeHandle follow mouse when widget has focus
118
122
  // --------------------------------------------------------------------------
@@ -143,6 +147,7 @@ function widgetBehavior(publicAPI, model) {
143
147
  model.widgetState.deactivate();
144
148
  model.widgetState.getMoveHandle().deactivate();
145
149
  model.widgetState.getMoveHandle().setVisible(false);
150
+ model.widgetState.getMoveHandle().setOrigin(null);
146
151
  model.activeState = null;
147
152
  model.hasFocus = false;
148
153
 
@@ -4,7 +4,7 @@ import macro from '../../../macros.js';
4
4
  var MAX_POINTS = 2;
5
5
  function widgetBehavior(publicAPI, model) {
6
6
  model.classHierarchy.push('vtkDistanceWidgetProp');
7
- var isDragging = null; // --------------------------------------------------------------------------
7
+ model._isDragging = false; // --------------------------------------------------------------------------
8
8
  // Display 2D
9
9
  // --------------------------------------------------------------------------
10
10
 
@@ -41,8 +41,8 @@ function widgetBehavior(publicAPI, model) {
41
41
  newHandle.setColor(moveHandle.getColor());
42
42
  newHandle.setScale1(moveHandle.getScale1());
43
43
  newHandle.setManipulator(manipulator);
44
- } else {
45
- isDragging = true;
44
+ } else if (model.dragable) {
45
+ model._isDragging = true;
46
46
 
47
47
  model._apiSpecificRenderWindow.setCursor('grabbing');
48
48
 
@@ -59,17 +59,13 @@ function widgetBehavior(publicAPI, model) {
59
59
  publicAPI.handleMouseMove = function (callData) {
60
60
  var _model$activeState$ge3, _model$activeState2, _model$activeState2$g;
61
61
 
62
- if (model.hasFocus && model.widgetState.getHandleList().length === MAX_POINTS) {
63
- publicAPI.loseFocus();
64
- return macro.VOID;
65
- }
66
-
67
62
  var manipulator = (_model$activeState$ge3 = (_model$activeState2 = model.activeState) === null || _model$activeState2 === void 0 ? void 0 : (_model$activeState2$g = _model$activeState2.getManipulator) === null || _model$activeState2$g === void 0 ? void 0 : _model$activeState2$g.call(_model$activeState2)) !== null && _model$activeState$ge3 !== void 0 ? _model$activeState$ge3 : model.manipulator;
68
63
 
69
64
  if (manipulator && model.pickable && model.dragable && model.activeState && model.activeState.getActive() && !ignoreKey(callData)) {
70
65
  var worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
71
66
 
72
- if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || isDragging)) {
67
+ if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || model._isDragging) && model.activeState.setOrigin // e.g. the line is pickable but not draggable
68
+ ) {
73
69
  model.activeState.setOrigin(worldCoords);
74
70
  publicAPI.invokeInteractionEvent();
75
71
  return macro.EVENT_ABORT;
@@ -83,27 +79,35 @@ function widgetBehavior(publicAPI, model) {
83
79
 
84
80
 
85
81
  publicAPI.handleLeftButtonRelease = function () {
86
- if (isDragging && model.pickable) {
82
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
83
+ return macro.VOID;
84
+ }
85
+
86
+ if (model.hasFocus && model.widgetState.getHandleList().length === MAX_POINTS) {
87
+ publicAPI.loseFocus();
88
+ return macro.VOID;
89
+ }
90
+
91
+ if (model._isDragging) {
87
92
  model._apiSpecificRenderWindow.setCursor('pointer');
88
93
 
89
94
  model.widgetState.deactivate();
90
95
 
91
96
  model._interactor.cancelAnimation(publicAPI);
92
97
 
93
- publicAPI.invokeEndInteractionEvent();
98
+ model._isDragging = false;
94
99
  } else if (model.activeState !== model.widgetState.getMoveHandle()) {
95
100
  model.widgetState.deactivate();
96
101
  }
97
102
 
98
103
  if (model.hasFocus && !model.activeState || model.activeState && !model.activeState.getActive()) {
99
- publicAPI.invokeEndInteractionEvent();
100
-
101
104
  model._widgetManager.enablePicking();
102
105
 
103
106
  model._interactor.render();
104
107
  }
105
108
 
106
- isDragging = false;
109
+ publicAPI.invokeEndInteractionEvent();
110
+ return macro.EVENT_ABORT;
107
111
  }; // --------------------------------------------------------------------------
108
112
  // Focus API - modeHandle follow mouse when widget has focus
109
113
  // --------------------------------------------------------------------------
@@ -134,6 +138,7 @@ function widgetBehavior(publicAPI, model) {
134
138
  model.widgetState.deactivate();
135
139
  model.widgetState.getMoveHandle().deactivate();
136
140
  model.widgetState.getMoveHandle().setVisible(false);
141
+ model.widgetState.getMoveHandle().setOrigin(null);
137
142
  model.activeState = null;
138
143
  model.hasFocus = false;
139
144
 
@@ -3,7 +3,7 @@ import macro from '../../../macros.js';
3
3
  import { handleTypeFromName, AXES, transformVec3, rotateVec3 } from './helpers.js';
4
4
 
5
5
  function widgetBehavior(publicAPI, model) {
6
- var isDragging = null;
6
+ model._isDragging = false;
7
7
 
8
8
  publicAPI.setDisplayCallback = function (callback) {
9
9
  return model.representations[0].setDisplayCallback(callback);
@@ -14,15 +14,19 @@ function widgetBehavior(publicAPI, model) {
14
14
  return macro.VOID;
15
15
  }
16
16
 
17
- isDragging = true;
17
+ if (model.dragable) {
18
+ model._isDragging = true;
18
19
 
19
- model._interactor.requestAnimation(publicAPI);
20
+ model._apiSpecificRenderWindow.setCursor('grabbing');
21
+
22
+ model._interactor.requestAnimation(publicAPI);
23
+ }
20
24
 
21
25
  return macro.EVENT_ABORT;
22
26
  };
23
27
 
24
28
  publicAPI.handleMouseMove = function (callData) {
25
- if (isDragging && model.pickable && model.dragable) {
29
+ if (model._isDragging) {
26
30
  return publicAPI.handleEvent(callData);
27
31
  }
28
32
 
@@ -30,13 +34,19 @@ function widgetBehavior(publicAPI, model) {
30
34
  };
31
35
 
32
36
  publicAPI.handleLeftButtonRelease = function () {
33
- if (isDragging && model.pickable) {
34
- isDragging = false;
37
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
38
+ return macro.VOID;
39
+ }
40
+
41
+ if (model._isDragging) {
42
+ model._isDragging = false;
35
43
 
36
44
  model._interactor.cancelAnimation(publicAPI);
37
45
 
38
46
  model.widgetState.deactivate();
39
47
  }
48
+
49
+ return macro.EVENT_ABORT;
40
50
  };
41
51
 
42
52
  publicAPI.handleEvent = function (callData) {
@@ -12,7 +12,7 @@ import { ViewTypes } from '../Core/WidgetManager/Constants.js';
12
12
 
13
13
  function widgetBehavior(publicAPI, model) {
14
14
  model.classHierarchy.push('vtkPlaneWidget');
15
- var isDragging = null;
15
+ model._isDragging = false;
16
16
 
17
17
  publicAPI.setDisplayCallback = function (callback) {
18
18
  return model.representations[0].setDisplayCallback(callback);
@@ -47,19 +47,24 @@ function widgetBehavior(publicAPI, model) {
47
47
  return macro.VOID;
48
48
  }
49
49
 
50
- isDragging = true;
51
50
  model.lineManipulator.setWidgetOrigin(model.widgetState.getOrigin());
52
51
  model.planeManipulator.setWidgetOrigin(model.widgetState.getOrigin());
53
52
  model.trackballManipulator.reset(callData); // setup trackball delta
54
53
 
55
- model._interactor.requestAnimation(publicAPI);
54
+ if (model.dragable) {
55
+ model._isDragging = true;
56
+
57
+ model._apiSpecificRenderWindow.setCursor('grabbing');
58
+
59
+ model._interactor.requestAnimation(publicAPI);
60
+ }
56
61
 
57
62
  publicAPI.invokeStartInteractionEvent();
58
63
  return macro.EVENT_ABORT;
59
64
  };
60
65
 
61
66
  publicAPI.handleMouseMove = function (callData) {
62
- if (isDragging && model.pickable) {
67
+ if (model._isDragging) {
63
68
  return publicAPI.handleEvent(callData);
64
69
  }
65
70
 
@@ -67,14 +72,19 @@ function widgetBehavior(publicAPI, model) {
67
72
  };
68
73
 
69
74
  publicAPI.handleLeftButtonRelease = function () {
70
- if (isDragging && model.pickable) {
71
- publicAPI.invokeEndInteractionEvent();
75
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
76
+ return macro.VOID;
77
+ }
72
78
 
79
+ if (model._isDragging) {
73
80
  model._interactor.cancelAnimation(publicAPI);
81
+
82
+ model._isDragging = false;
74
83
  }
75
84
 
76
- isDragging = false;
77
85
  model.widgetState.deactivate();
86
+ publicAPI.invokeEndInteractionEvent();
87
+ return macro.EVENT_ABORT;
78
88
  };
79
89
 
80
90
  publicAPI.handleEvent = function (callData) {
@@ -6,7 +6,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
7
  function widgetBehavior(publicAPI, model) {
8
8
  model.classHierarchy.push('vtkLabelWidgetProp');
9
- model.isDragging = null; // --------------------------------------------------------------------------
9
+ model._isDragging = false; // --------------------------------------------------------------------------
10
10
  // Public methods
11
11
  // --------------------------------------------------------------------------
12
12
 
@@ -56,8 +56,8 @@ function widgetBehavior(publicAPI, model) {
56
56
  moveHandle.setOrigin(worldCoords);
57
57
  model.widgetState.getText().setOrigin(moveHandle.getOrigin());
58
58
  publicAPI.loseFocus();
59
- } else {
60
- model.isDragging = true;
59
+ } else if (model.dragable) {
60
+ model._isDragging = true;
61
61
 
62
62
  model._apiSpecificRenderWindow.setCursor('grabbing');
63
63
 
@@ -72,27 +72,30 @@ function widgetBehavior(publicAPI, model) {
72
72
 
73
73
 
74
74
  publicAPI.handleLeftButtonRelease = function () {
75
- if (model.isDragging && model.pickable) {
75
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
76
+ return macro.VOID;
77
+ }
78
+
79
+ if (model._isDragging) {
76
80
  model._apiSpecificRenderWindow.setCursor('pointer');
77
81
 
78
82
  model.widgetState.deactivate();
79
83
 
80
84
  model._interactor.cancelAnimation(publicAPI);
81
85
 
82
- publicAPI.invokeEndInteractionEvent();
86
+ model._isDragging = false;
83
87
  } else if (model.activeState !== model.widgetState.getMoveHandle()) {
84
88
  model.widgetState.deactivate();
85
89
  }
86
90
 
87
91
  if (model.hasFocus && !model.activeState || model.activeState && !model.activeState.getActive()) {
88
- publicAPI.invokeEndInteractionEvent();
89
-
90
92
  model._widgetManager.enablePicking();
91
93
 
92
94
  model._interactor.render();
93
95
  }
94
96
 
95
- model.isDragging = false;
97
+ publicAPI.invokeEndInteractionEvent();
98
+ return macro.EVENT_ABORT;
96
99
  }; // --------------------------------------------------------------------------
97
100
  // Mouse move: Drag selected handle / Handle follow the mouse
98
101
  // --------------------------------------------------------------------------
@@ -106,7 +109,7 @@ function widgetBehavior(publicAPI, model) {
106
109
  if (manipulator && model.pickable && model.dragable && model.activeState && model.activeState.getActive() && !ignoreKey(callData)) {
107
110
  var worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
108
111
 
109
- if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || model.isDragging)) {
112
+ if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || model._isDragging)) {
110
113
  model.activeState.setOrigin(worldCoords);
111
114
  model.widgetState.getText().setOrigin(model.activeState.getOrigin());
112
115
  publicAPI.invokeInteractionEvent();
@@ -14,6 +14,7 @@ var MAX_POINTS = 2;
14
14
  var handleGetters = ['getHandle1', 'getHandle2', 'getMoveHandle'];
15
15
  function widgetBehavior(publicAPI, model) {
16
16
  model.classHierarchy.push('vtkLineWidgetProp');
17
+ model._isDragging = false;
17
18
  /**
18
19
  * Returns the handle at the handleIndex'th index.
19
20
  * @param {number} handleIndex 0, 1 or 2
@@ -22,6 +23,27 @@ function widgetBehavior(publicAPI, model) {
22
23
  publicAPI.getHandle = function (handleIndex) {
23
24
  return model.widgetState[handleGetters[handleIndex]]();
24
25
  };
26
+ /**
27
+ * Return the index in the of tbe handle in `representations` array,
28
+ * or -1 if the handle is not present in the widget state.
29
+ */
30
+
31
+
32
+ publicAPI.getHandleIndex = function (handle) {
33
+ switch (handle) {
34
+ case model.widgetState.getHandle1():
35
+ return 0;
36
+
37
+ case model.widgetState.getHandle2():
38
+ return 1;
39
+
40
+ case model.widgetState.getMoveHandle():
41
+ return 2;
42
+
43
+ default:
44
+ return -1;
45
+ }
46
+ };
25
47
 
26
48
  publicAPI.isPlaced = function () {
27
49
  return getNumberOfPlacedHandles(model.widgetState) === MAX_POINTS;
@@ -37,7 +59,7 @@ function widgetBehavior(publicAPI, model) {
37
59
  function updateCursor(callData) {
38
60
  var _model$activeState$ge, _model$activeState, _model$activeState$ge2;
39
61
 
40
- model.isDragging = true;
62
+ model._isDragging = true;
41
63
  var manipulator = (_model$activeState$ge = (_model$activeState = model.activeState) === null || _model$activeState === void 0 ? void 0 : (_model$activeState$ge2 = _model$activeState.getManipulator) === null || _model$activeState$ge2 === void 0 ? void 0 : _model$activeState$ge2.call(_model$activeState)) !== null && _model$activeState$ge !== void 0 ? _model$activeState$ge : model.manipulator;
42
64
  model.previousPosition = _toConsumableArray(manipulator.handleEvent(callData, model._apiSpecificRenderWindow));
43
65
 
@@ -145,12 +167,6 @@ function widgetBehavior(publicAPI, model) {
145
167
  model.representations[1].setViewMatrix(Array.from(model._camera.getViewMatrix()));
146
168
  }; // Handles visibility ---------------------------------------------------------
147
169
 
148
-
149
- publicAPI.setMoveHandleVisibility = function (visibility) {
150
- model.representations[2].setVisibilityFlagArray([visibility, visibility]);
151
- model.widgetState.getMoveHandle().setVisible(visibility);
152
- model.representations[2].updateActorVisibility();
153
- };
154
170
  /**
155
171
  * Set actor visibility to true unless it is a NONE handle
156
172
  * and uses state visibility variable for the displayActor visibility to
@@ -196,7 +212,7 @@ function widgetBehavior(publicAPI, model) {
196
212
 
197
213
  if (handleIndex === 1) {
198
214
  publicAPI.placeText();
199
- publicAPI.setMoveHandleVisibility(false);
215
+ publicAPI.loseFocus();
200
216
  }
201
217
  }; // --------------------------------------------------------------------------
202
218
  // Left press: Select handle to drag
@@ -212,7 +228,7 @@ function widgetBehavior(publicAPI, model) {
212
228
  publicAPI.placeHandle(0);
213
229
  } else if (model.widgetState.getMoveHandle().getActive() && getNumberOfPlacedHandles(model.widgetState) === 1) {
214
230
  publicAPI.placeHandle(1);
215
- } else if (!model.widgetState.getText().getActive()) {
231
+ } else if (model.dragable && !model.widgetState.getText().getActive()) {
216
232
  // Grab handle1, handle2 or whole widget
217
233
  updateCursor(e);
218
234
  }
@@ -227,11 +243,6 @@ function widgetBehavior(publicAPI, model) {
227
243
  publicAPI.handleMouseMove = function (callData) {
228
244
  var _model$activeState$ge3, _model$activeState2, _model$activeState2$g;
229
245
 
230
- if (model.hasFocus && publicAPI.isPlaced() && !model.isDragging) {
231
- publicAPI.loseFocus();
232
- return macro.VOID;
233
- }
234
-
235
246
  var manipulator = (_model$activeState$ge3 = (_model$activeState2 = model.activeState) === null || _model$activeState2 === void 0 ? void 0 : (_model$activeState2$g = _model$activeState2.getManipulator) === null || _model$activeState2$g === void 0 ? void 0 : _model$activeState2$g.call(_model$activeState2)) !== null && _model$activeState$ge3 !== void 0 ? _model$activeState$ge3 : model.manipulator;
236
247
 
237
248
  if (manipulator && model.pickable && model.dragable && model.activeState && model.activeState.getActive() && !ignoreKey(callData)) {
@@ -241,9 +252,10 @@ function widgetBehavior(publicAPI, model) {
241
252
 
242
253
  if ( // is placing first or second handle
243
254
  model.activeState === model.widgetState.getMoveHandle() || // is dragging already placed first or second handle
244
- model.isDragging) {
255
+ model._isDragging) {
245
256
  if (model.activeState.setOrigin) {
246
257
  model.activeState.setOrigin(worldCoords);
258
+ publicAPI.updateHandleVisibility(publicAPI.getHandleIndex(model.activeState));
247
259
  } else {
248
260
  // Dragging line
249
261
  publicAPI.getHandle(0).setOrigin(add(publicAPI.getHandle(0).getOrigin(), translation, []));
@@ -259,18 +271,26 @@ function widgetBehavior(publicAPI, model) {
259
271
 
260
272
  return macro.VOID;
261
273
  }; // --------------------------------------------------------------------------
262
- // Left release: Finish drag / Create new handle
274
+ // Left release: Finish drag
263
275
  // --------------------------------------------------------------------------
264
276
 
265
277
 
266
278
  publicAPI.handleLeftButtonRelease = function () {
267
- // After dragging a point or placing all points
268
- if (model.activeState && model.activeState.getActive() && (model.isDragging || publicAPI.isPlaced())) {
279
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
280
+ publicAPI.rotateHandlesToFaceCamera();
281
+ return macro.VOID;
282
+ }
283
+
284
+ if (model.hasFocus && publicAPI.isPlaced()) {
285
+ publicAPI.loseFocus();
286
+ return macro.VOID;
287
+ }
288
+
289
+ if (model._isDragging && publicAPI.isPlaced()) {
269
290
  var wasTextActive = model.widgetState.getText().getActive(); // Recompute offsets
270
291
 
271
292
  publicAPI.placeText();
272
293
  model.widgetState.deactivate();
273
- model.widgetState.getMoveHandle().deactivate();
274
294
  model.activeState = null;
275
295
 
276
296
  if (!wasTextActive) {
@@ -280,18 +300,19 @@ function widgetBehavior(publicAPI, model) {
280
300
  model._apiSpecificRenderWindow.setCursor('pointer');
281
301
 
282
302
  model.hasFocus = false;
283
- publicAPI.invokeEndInteractionEvent();
303
+ model._isDragging = false;
304
+ } else if (model.activeState !== model.widgetState.getMoveHandle()) {
305
+ model.widgetState.deactivate();
306
+ }
284
307
 
308
+ if (model.hasFocus && !model.activeState || model.activeState && !model.activeState.getActive()) {
285
309
  model._widgetManager.enablePicking();
286
310
 
287
311
  model._interactor.render();
288
312
  }
289
313
 
290
- if (model.isDragging === false && (!model.activeState || !model.activeState.getActive())) {
291
- publicAPI.rotateHandlesToFaceCamera();
292
- }
293
-
294
- model.isDragging = false;
314
+ publicAPI.invokeEndInteractionEvent();
315
+ return macro.EVENT_ABORT;
295
316
  }; // --------------------------------------------------------------------------
296
317
  // Focus API - moveHandle follow mouse when widget has focus
297
318
  // --------------------------------------------------------------------------
@@ -301,7 +322,6 @@ function widgetBehavior(publicAPI, model) {
301
322
  if (!model.hasFocus && !publicAPI.isPlaced()) {
302
323
  model.activeState = model.widgetState.getMoveHandle();
303
324
  model.activeState.setShape(publicAPI.getHandle(0).getShape());
304
- publicAPI.setMoveHandleVisibility(true);
305
325
  model.activeState.activate();
306
326
 
307
327
  model._interactor.requestAnimation(publicAPI);
@@ -322,6 +342,7 @@ function widgetBehavior(publicAPI, model) {
322
342
 
323
343
  model.widgetState.deactivate();
324
344
  model.widgetState.getMoveHandle().deactivate();
345
+ model.widgetState.getMoveHandle().setOrigin(null);
325
346
  model.activeState = null;
326
347
  model.hasFocus = false;
327
348
 
@@ -21,6 +21,10 @@ function updateTextPosition(model) {
21
21
  SVGTextState.setOrigin(calculateTextPosition(model));
22
22
  }
23
23
  function isHandlePlaced(handleIndex, widgetState) {
24
+ if (handleIndex === 2) {
25
+ return widgetState.getMoveHandle().getOrigin() != null;
26
+ }
27
+
24
28
  var handle1Origin = widgetState.getHandle1().getOrigin();
25
29
 
26
30
  if (handleIndex === 0) {
@@ -172,16 +172,14 @@ function vtkLineWidget(publicAPI, model) {
172
172
  } // ----------------------------------------------------------------------------
173
173
 
174
174
 
175
- var DEFAULT_VALUES = {
176
- // manipulator: null,
177
- isDragging: false
175
+ var DEFAULT_VALUES = {// manipulator: null,
178
176
  }; // ----------------------------------------------------------------------------
179
177
 
180
178
  function extend(publicAPI, model) {
181
179
  var initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
182
180
  Object.assign(model, DEFAULT_VALUES, initialValues);
183
181
  vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
184
- macro.setGet(publicAPI, model, ['manipulator', 'isDragging']);
182
+ macro.setGet(publicAPI, model, ['manipulator']);
185
183
  vtkLineWidget(publicAPI, model);
186
184
  } // ----------------------------------------------------------------------------
187
185
 
@@ -2,7 +2,7 @@ import macro from '../../../macros.js';
2
2
 
3
3
  function widgetBehavior(publicAPI, model) {
4
4
  model.classHierarchy.push('vtkPolyLineWidgetProp');
5
- var isDragging = null; // --------------------------------------------------------------------------
5
+ model._isDragging = false; // --------------------------------------------------------------------------
6
6
  // Display 2D
7
7
  // --------------------------------------------------------------------------
8
8
 
@@ -28,7 +28,8 @@ function widgetBehavior(publicAPI, model) {
28
28
 
29
29
  var worldCoords = manipulator.handleEvent(callData, model._apiSpecificRenderWindow);
30
30
 
31
- if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || isDragging)) {
31
+ if (worldCoords.length && (model.activeState === model.widgetState.getMoveHandle() || model._isDragging) && model.activeState.setOrigin // e.g. the line is pickable but not draggable
32
+ ) {
32
33
  model.activeState.setOrigin(worldCoords);
33
34
  publicAPI.invokeInteractionEvent();
34
35
  return macro.EVENT_ABORT;
@@ -81,8 +82,8 @@ function widgetBehavior(publicAPI, model) {
81
82
  newHandle.setColor(moveHandle.getColor());
82
83
  newHandle.setScale1(moveHandle.getScale1());
83
84
  newHandle.setManipulator(manipulator);
84
- } else {
85
- isDragging = true;
85
+ } else if (model.dragable) {
86
+ model._isDragging = true;
86
87
 
87
88
  model._apiSpecificRenderWindow.setCursor('grabbing');
88
89
 
@@ -114,27 +115,30 @@ function widgetBehavior(publicAPI, model) {
114
115
 
115
116
 
116
117
  publicAPI.handleLeftButtonRelease = function () {
117
- if (isDragging && model.pickable) {
118
+ if (!model.activeState || !model.activeState.getActive() || !model.pickable) {
119
+ return macro.VOID;
120
+ }
121
+
122
+ if (model._isDragging) {
118
123
  model._apiSpecificRenderWindow.setCursor('pointer');
119
124
 
120
125
  model.widgetState.deactivate();
121
126
 
122
127
  model._interactor.cancelAnimation(publicAPI);
123
128
 
124
- publicAPI.invokeEndInteractionEvent();
129
+ model._isDragging = false;
125
130
  } else if (model.activeState !== model.widgetState.getMoveHandle()) {
126
131
  model.widgetState.deactivate();
127
132
  }
128
133
 
129
134
  if (model.hasFocus && !model.activeState || model.activeState && !model.activeState.getActive()) {
130
- publicAPI.invokeEndInteractionEvent();
131
-
132
135
  model._widgetManager.enablePicking();
133
136
 
134
137
  model._interactor.render();
135
138
  }
136
139
 
137
- isDragging = false;
140
+ publicAPI.invokeEndInteractionEvent();
141
+ return macro.EVENT_ABORT;
138
142
  }; // --------------------------------------------------------------------------
139
143
  // Escape key: Release focus to switch to drag mode
140
144
  // --------------------------------------------------------------------------
@@ -176,6 +180,7 @@ function widgetBehavior(publicAPI, model) {
176
180
  model.widgetState.deactivate();
177
181
  model.widgetState.getMoveHandle().deactivate();
178
182
  model.widgetState.getMoveHandle().setVisible(false);
183
+ model.widgetState.getMoveHandle().setOrigin(null);
179
184
  model.activeState = null;
180
185
  model.hasFocus = false;
181
186
 
@@ -3,12 +3,12 @@ import macro from '../../../macros.js';
3
3
  import vtkBoundingBox from '../../../Common/DataModel/BoundingBox.js';
4
4
  import vtkLine from '../../../Common/DataModel/Line.js';
5
5
  import vtkPlanePointManipulator from '../../Manipulators/PlaneManipulator.js';
6
- import { x as multiplyScalar, s as subtract, l as normalize, d as dot, j as cross, m as multiplyAccumulate, S as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
6
+ import { s as subtract, l as normalize, d as dot, j as cross, m as multiplyAccumulate, x as multiplyScalar, S as signedAngleBetweenVectors } from '../../../Common/Core/Math/index.js';
7
7
  import { updateState, getAssociatedLinesName, boundPointOnPlane, rotateVector } from './helpers.js';
8
8
  import { InteractionMethodsName, ScrollingMethods } from './Constants.js';
9
9
 
10
10
  function widgetBehavior(publicAPI, model) {
11
- var isDragging = null;
11
+ model._isDragging = false;
12
12
  var isScrolling = false; // Reset "updateMethodName" attribute when no actors are selected
13
13
  // Useful to update 'updateMethodeName' to the correct name which
14
14
  // will be TranslateCenter by default
@@ -60,7 +60,7 @@ function widgetBehavior(publicAPI, model) {
60
60
 
61
61
  publicAPI.handleLeftButtonPress = function (callData) {
62
62
  if (model.activeState && model.activeState.getActive()) {
63
- isDragging = true;
63
+ model._isDragging = true;
64
64
  var viewType = model.widgetState.getActiveViewType();
65
65
  var currentPlaneNormal = model.widgetState.getPlanes()[viewType].normal;
66
66
  model.planeManipulator.setWidgetOrigin(model.widgetState.getCenter());
@@ -76,14 +76,14 @@ function widgetBehavior(publicAPI, model) {
76
76
  };
77
77
 
78
78
  publicAPI.handleMouseMove = function (callData) {
79
- if (isDragging && model.pickable && model.dragable) {
79
+ if (model._isDragging) {
80
80
  return publicAPI.handleEvent(callData);
81
81
  }
82
82
 
83
83
  if (isScrolling) {
84
84
  if (model.previousPosition.y !== callData.position.y) {
85
85
  var step = model.previousPosition.y - callData.position.y;
86
- publicAPI.translateCenterOnCurrentDirection(step, callData.pokedRenderer);
86
+ publicAPI.translateCenterOnPlaneDirection(step);
87
87
  model.previousPosition = callData.position;
88
88
  publicAPI.invokeInternalInteractionEvent();
89
89
  }
@@ -93,11 +93,11 @@ function widgetBehavior(publicAPI, model) {
93
93
  };
94
94
 
95
95
  publicAPI.handleLeftButtonRelease = function () {
96
- if (isDragging || isScrolling) {
96
+ if (model._isDragging || isScrolling) {
97
97
  publicAPI.endScrolling();
98
98
  }
99
99
 
100
- isDragging = false;
100
+ model._isDragging = false;
101
101
  model.widgetState.deactivate();
102
102
  };
103
103
 
@@ -121,7 +121,7 @@ function widgetBehavior(publicAPI, model) {
121
121
  publicAPI.handleMouseWheel = function (calldata) {
122
122
  var step = calldata.spinY;
123
123
  isScrolling = true;
124
- publicAPI.translateCenterOnCurrentDirection(step, calldata.pokedRenderer);
124
+ publicAPI.translateCenterOnPlaneDirection(step);
125
125
  publicAPI.invokeInternalInteractionEvent();
126
126
  isScrolling = false;
127
127
  return macro.EVENT_ABORT;
@@ -178,10 +178,8 @@ function widgetBehavior(publicAPI, model) {
178
178
  });
179
179
  };
180
180
 
181
- publicAPI.translateCenterOnCurrentDirection = function (nbSteps, renderer) {
182
- var dirProj = renderer.getRenderWindow().getRenderers()[0].getActiveCamera().getDirectionOfProjection(); // Direction of the projection is the inverse of what we want
183
-
184
- var direction = multiplyScalar(dirProj, -1);
181
+ publicAPI.translateCenterOnPlaneDirection = function (nbSteps) {
182
+ var dirProj = model.widgetState.getPlanes()[model.viewType].normal;
185
183
  var oldCenter = model.widgetState.getCenter();
186
184
  var image = model.widgetState.getImage();
187
185
  var imageSpacing = image.getSpacing(); // Use Chebyshev norm
@@ -191,9 +189,9 @@ function widgetBehavior(publicAPI, model) {
191
189
  return Math.abs(value);
192
190
  });
193
191
  var index = absDirProj.indexOf(Math.max.apply(Math, _toConsumableArray(absDirProj)));
194
- var movingFactor = nbSteps * (imageSpacing[index] / dirProj[index]); // Define the potentially new center
192
+ var movingFactor = nbSteps * imageSpacing[index] / Math.abs(dirProj[index]); // Define the potentially new center
195
193
 
196
- var newCenter = [oldCenter[0] + movingFactor * direction[0], oldCenter[1] + movingFactor * direction[1], oldCenter[2] + movingFactor * direction[2]];
194
+ var newCenter = [oldCenter[0] + movingFactor * dirProj[0], oldCenter[1] + movingFactor * dirProj[1], oldCenter[2] + movingFactor * dirProj[2]];
197
195
  newCenter = publicAPI.getBoundedCenter(newCenter);
198
196
  model.widgetState.setCenter(newCenter);
199
197
  updateState(model.widgetState);
@@ -15,6 +15,7 @@ var vtkErrorMacro = macro.vtkErrorMacro;
15
15
  var EPSILON = 1e-6;
16
16
  function widgetBehavior(publicAPI, model) {
17
17
  model.classHierarchy.push('vtkShapeWidgetProp');
18
+ model._isDragging = false;
18
19
  model.keysDown = {};
19
20
 
20
21
  var superClass = _objectSpread({}, publicAPI); // --------------------------------------------------------------------------
@@ -383,7 +384,7 @@ function widgetBehavior(publicAPI, model) {
383
384
  publicAPI.updateShapeBounds();
384
385
  publicAPI.invokeInteractionEvent();
385
386
  }
386
- } else if (model.isDragging) {
387
+ } else if (model._isDragging) {
387
388
  if (model.activeState === model.point1Handle) {
388
389
  model.point1Handle.setOrigin(worldCoords);
389
390
  model.point1 = worldCoords;
@@ -396,7 +397,7 @@ function widgetBehavior(publicAPI, model) {
396
397
  publicAPI.invokeInteractionEvent();
397
398
  }
398
399
 
399
- return model.hasFocus || model.isDragging ? macro.EVENT_ABORT : macro.VOID;
400
+ return model.hasFocus || model._isDragging ? macro.EVENT_ABORT : macro.VOID;
400
401
  }; // --------------------------------------------------------------------------
401
402
  // Left click: Add point / End interaction
402
403
  // --------------------------------------------------------------------------
@@ -434,26 +435,24 @@ function widgetBehavior(publicAPI, model) {
434
435
  return macro.EVENT_ABORT;
435
436
  }
436
437
 
437
- if (model.point1 && (model.activeState === model.point1Handle || model.activeState === model.point2Handle)) {
438
- model.isDragging = true;
438
+ if (model.point1 && (model.activeState === model.point1Handle || model.activeState === model.point2Handle) && model.dragable) {
439
+ model._isDragging = true;
439
440
 
440
441
  model._apiSpecificRenderWindow.setCursor('grabbing');
441
442
 
442
443
  model._interactor.requestAnimation(publicAPI);
443
-
444
- publicAPI.invokeStartInteractionEvent();
445
- return macro.EVENT_ABORT;
446
444
  }
447
445
 
448
- return macro.VOID;
446
+ publicAPI.invokeStartInteractionEvent();
447
+ return macro.EVENT_ABORT;
449
448
  }; // --------------------------------------------------------------------------
450
449
  // Left release: Maybe end interaction
451
450
  // --------------------------------------------------------------------------
452
451
 
453
452
 
454
453
  publicAPI.handleLeftButtonRelease = function (e) {
455
- if (model.isDragging) {
456
- model.isDragging = false;
454
+ if (model._isDragging) {
455
+ model._isDragging = false;
457
456
 
458
457
  model._apiSpecificRenderWindow.setCursor('pointer');
459
458
 
@@ -9,7 +9,7 @@ function widgetBehavior(publicAPI, model) {
9
9
  var borderHandle = state.getBorderHandle();
10
10
  var shapeHandle = state.getSphereHandle(); // Set while moving the center or border handle.
11
11
 
12
- model.isDragging = false; // The last world coordinate of the mouse cursor during dragging.
12
+ model._isDragging = false; // The last world coordinate of the mouse cursor during dragging.
13
13
 
14
14
  model.previousPosition = null;
15
15
  model.classHierarchy.push('vtkSphereWidgetProp');
@@ -103,7 +103,7 @@ function widgetBehavior(publicAPI, model) {
103
103
  updateSphere();
104
104
  }
105
105
 
106
- model.isDragging = true;
106
+ model._isDragging = true;
107
107
 
108
108
  model._apiSpecificRenderWindow.setCursor('grabbing');
109
109
 
@@ -113,7 +113,7 @@ function widgetBehavior(publicAPI, model) {
113
113
  };
114
114
 
115
115
  publicAPI.handleLeftButtonRelease = function (e) {
116
- if (!model.isDragging) {
116
+ if (!model._isDragging) {
117
117
  model.activeState = null;
118
118
  return macro.VOID;
119
119
  }
@@ -125,7 +125,7 @@ function widgetBehavior(publicAPI, model) {
125
125
 
126
126
  model._apiSpecificRenderWindow.setCursor('pointer');
127
127
 
128
- model.isDragging = false;
128
+ model._isDragging = false;
129
129
  model.activeState = null;
130
130
  state.deactivate();
131
131
  }
@@ -135,7 +135,7 @@ function widgetBehavior(publicAPI, model) {
135
135
  };
136
136
 
137
137
  publicAPI.handleMouseMove = function (e) {
138
- if (!model.isDragging) {
138
+ if (!model._isDragging) {
139
139
  model.activeState = null;
140
140
  return macro.VOID;
141
141
  }
@@ -171,14 +171,14 @@ function widgetBehavior(publicAPI, model) {
171
171
  borderHandle.setVisible(false);
172
172
  centerHandle.setOrigin(null);
173
173
  borderHandle.setOrigin(null);
174
- model.isDragging = true;
174
+ model._isDragging = true;
175
175
  model.activeState = moveHandle;
176
176
 
177
177
  model._interactor.render();
178
178
  };
179
179
 
180
180
  publicAPI.loseFocus = function () {
181
- model.isDragging = false;
181
+ model._isDragging = false;
182
182
  model.activeState = null;
183
183
  };
184
184
  }
@@ -4,6 +4,7 @@ import { vec3 } from 'gl-matrix';
4
4
 
5
5
  function widgetBehavior(publicAPI, model) {
6
6
  model.classHierarchy.push('vtkSplineWidgetProp');
7
+ model._isDragging = false;
7
8
  model.keysDown = {};
8
9
  model.moveHandle = model.widgetState.getMoveHandle(); // --------------------------------------------------------------------------
9
10
  // Private methods
@@ -166,7 +167,6 @@ function widgetBehavior(publicAPI, model) {
166
167
 
167
168
  if (model.activeState === model.moveHandle) {
168
169
  if (model.widgetState.getHandleList().length === 0) {
169
- publicAPI.invokeStartInteractionEvent();
170
170
  addPoint();
171
171
  } else {
172
172
  var hoveredHandle = getHoveredHandle();
@@ -176,24 +176,23 @@ function widgetBehavior(publicAPI, model) {
176
176
  model.moveHandle.setVisible(false);
177
177
  model.activeState = hoveredHandle;
178
178
  hoveredHandle.activate();
179
- model.isDragging = true;
179
+ model._isDragging = true;
180
180
  model.lastHandle.setVisible(true);
181
181
  } else {
182
182
  addPoint();
183
183
  }
184
184
  }
185
185
 
186
- model.freeHand = publicAPI.getAllowFreehand() && !model.isDragging;
187
- } else {
188
- model.isDragging = true;
186
+ model.freeHand = publicAPI.getAllowFreehand() && !model._isDragging;
187
+ } else if (model.dragable) {
188
+ model._isDragging = true;
189
189
 
190
190
  model._apiSpecificRenderWindow.setCursor('grabbing');
191
191
 
192
192
  model._interactor.requestAnimation(publicAPI);
193
-
194
- publicAPI.invokeStartInteractionEvent();
195
193
  }
196
194
 
195
+ publicAPI.invokeStartInteractionEvent();
197
196
  return macro.EVENT_ABORT;
198
197
  }; // --------------------------------------------------------------------------
199
198
  // Left release
@@ -201,7 +200,7 @@ function widgetBehavior(publicAPI, model) {
201
200
 
202
201
 
203
202
  publicAPI.handleLeftButtonRelease = function (e) {
204
- if (model.isDragging) {
203
+ if (model._isDragging) {
205
204
  if (!model.hasFocus) {
206
205
  model._apiSpecificRenderWindow.setCursor(model.defaultCursor);
207
206
 
@@ -239,8 +238,8 @@ function widgetBehavior(publicAPI, model) {
239
238
  }
240
239
 
241
240
  model.freeHand = false;
242
- model.isDragging = false;
243
241
  model.draggedPoint = false;
242
+ model._isDragging = false;
244
243
  return model.hasFocus ? macro.EVENT_ABORT : macro.VOID;
245
244
  }; // --------------------------------------------------------------------------
246
245
  // Mouse move: Drag selected handle / Handle follow the mouse
@@ -265,7 +264,7 @@ function widgetBehavior(publicAPI, model) {
265
264
  if (hoveredHandle !== model.firstHandle) {
266
265
  model._apiSpecificRenderWindow.setCursor('grabbing');
267
266
  }
268
- } else if (!model.isDragging && model.hasFocus) {
267
+ } else if (!model._isDragging && model.hasFocus) {
269
268
  model.moveHandle.setVisible(true);
270
269
 
271
270
  model._apiSpecificRenderWindow.setCursor(model.defaultCursor);
@@ -275,10 +274,10 @@ function widgetBehavior(publicAPI, model) {
275
274
  model.lastHandle.setVisible(true);
276
275
  }
277
276
 
278
- if (worldCoords.length && (model.isDragging || model.activeState === model.moveHandle)) {
277
+ if (worldCoords.length && (model._isDragging || model.activeState === model.moveHandle)) {
279
278
  model.activeState.setOrigin(worldCoords);
280
279
 
281
- if (model.isDragging) {
280
+ if (model._isDragging) {
282
281
  model.draggedPoint = true;
283
282
  }
284
283
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "24.18.7",
3
+ "version": "24.18.10",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",