@kitware/vtk.js 29.6.0 → 29.7.1

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.
@@ -0,0 +1,79 @@
1
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
2
+ import vtkPolyData from './../../Common/DataModel/PolyData';
3
+ /**
4
+ * Initial configuration values for vtkContourLoopExtraction instances.
5
+ */
6
+ export interface IContourLoopExtractionInitialValues {}
7
+
8
+ type vtkContourLoopExtractionBase = vtkObject & vtkAlgorithm;
9
+
10
+ export interface vtkContourLoopExtraction extends vtkContourLoopExtractionBase {
11
+ /**
12
+ * Runs the contour extraction algorithm with the given input and output data.
13
+ * @param inData - The input data for the contour extraction.
14
+ * @param outData - The output data where the extracted contours will be stored.
15
+ */
16
+ requestData(inData: vtkPolyData[], outData: vtkPolyData[]): void;
17
+
18
+ /**
19
+ * Extracts contour loops from the given polydata input and populates the given output.
20
+ * @param input - The input polydata
21
+ * @param output - The output polydata
22
+ */
23
+ extractContours(input: vtkPolyData, output: vtkPolyData): void;
24
+
25
+ /**
26
+ * Traverses a loop starting from a given line and point, in a specified direction.
27
+ * @param pd - The polydata which to traverse.
28
+ * @param dir - The direction of traversal.
29
+ * @param startLineId - The ID of the starting line.
30
+ * @param startPtId - The ID of the starting point.
31
+ * @param loopPoints - The array to store the traversed points of the loop.
32
+ * @returns The last point ID after traversal.
33
+ */
34
+ traverseLoop(
35
+ pd: vtkPolyData,
36
+ dir: number,
37
+ startLineId: number,
38
+ startPtId: number,
39
+ loopPoints: Array<{ t: number; ptId: number }>
40
+ ): number;
41
+ }
42
+
43
+ // ----------------------------------------------------------------------------
44
+ // Static API
45
+ // ----------------------------------------------------------------------------
46
+
47
+ /**
48
+ * Method use to decorate a given object (publicAPI+model) with vtkContourLoopExtraction characteristics.
49
+ *
50
+ * @param publicAPI - Object on which methods will be bound (public).
51
+ * @param model - Object on which data structure will be bound (protected).
52
+ * @param initialValues - (Optional) Initial values to assign to the model.
53
+ */
54
+ export function extend(
55
+ publicAPI: object,
56
+ model: object,
57
+ initialValues?: IContourLoopExtractionInitialValues
58
+ ): void;
59
+
60
+ /**
61
+ * Method used to create a new instance of vtkContourLoopExtraction.
62
+ *
63
+ * @param initialValues - (Optional) Initial values for the instance.
64
+ */
65
+ export function newInstance(
66
+ initialValues?: IContourLoopExtractionInitialValues
67
+ ): vtkContourLoopExtraction;
68
+
69
+ // ----------------------------------------------------------------------------
70
+
71
+ /**
72
+ * vtkContourLoopExtraction specific static methods.
73
+ */
74
+ export declare const vtkContourLoopExtraction: {
75
+ newInstance: typeof newInstance;
76
+ extend: typeof extend;
77
+ };
78
+
79
+ export default vtkContourLoopExtraction;
@@ -0,0 +1,137 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
3
+
4
+ const Dir = {
5
+ Forward: 1,
6
+ Backward: -1
7
+ };
8
+ const visited = new Set();
9
+ function vtkContourLoopExtraction(publicAPI, model) {
10
+ publicAPI.requestData = (inData, outData) => {
11
+ const [input] = inData;
12
+ if (!outData[0]) {
13
+ outData[0] = vtkPolyData.newInstance();
14
+ }
15
+ const [output] = outData;
16
+ publicAPI.extractContours(input, output);
17
+ output.modified();
18
+ };
19
+ publicAPI.traverseLoop = (pd, dir, startLineId, startPtId, loopPoints) => {
20
+ let lineId = startLineId;
21
+ let lastPtId = startPtId;
22
+ let terminated = false;
23
+ let numInserted = 0;
24
+ while (!terminated) {
25
+ const {
26
+ cellPointIds
27
+ } = pd.getCellPoints(lineId);
28
+ if (!cellPointIds) {
29
+ // eslint-disable-next-line no-continue
30
+ continue;
31
+ }
32
+ lastPtId = cellPointIds[0] !== lastPtId ? cellPointIds[0] : cellPointIds[1];
33
+ numInserted++;
34
+
35
+ // parametric point value
36
+ const t = dir * numInserted;
37
+ loopPoints.push({
38
+ t,
39
+ ptId: lastPtId
40
+ });
41
+ const lineCell = pd.getPointCells(lastPtId);
42
+ if (lineCell.length !== 2 || lastPtId === startPtId) {
43
+ // looped
44
+ return lastPtId;
45
+ }
46
+ if (lineCell.length === 2) {
47
+ // continue along loop
48
+ lineId = lineCell[0] !== lineId ? lineCell[0] : lineCell[1];
49
+ visited.add(lineId);
50
+ } else {
51
+ // empty or invalid cell
52
+ terminated = true;
53
+ }
54
+ }
55
+ return lastPtId;
56
+ };
57
+ publicAPI.extractContours = (input, output) => {
58
+ const loops = [];
59
+ visited.clear();
60
+ const inLines = input.getLines();
61
+ output.getPoints().setData(Float32Array.from(input.getPoints().getData()));
62
+
63
+ // TODO skip if cached input mtime hasn't changed.
64
+ // iterate over input lines
65
+ for (let li = 0; li < inLines.getNumberOfCells(); li++) {
66
+ if (visited.has(li)) {
67
+ // eslint-disable-next-line no-continue
68
+ continue;
69
+ }
70
+ const {
71
+ cellPointIds
72
+ } = input.getCellPoints(li);
73
+ if (!cellPointIds) {
74
+ // eslint-disable-next-line no-continue
75
+ continue;
76
+ }
77
+ visited.add(li);
78
+ const startPtId = cellPointIds[0];
79
+ const loopPoints = [];
80
+ loopPoints.push({
81
+ t: 0,
82
+ ptId: startPtId
83
+ });
84
+ const endPtId = publicAPI.traverseLoop(input, Dir.Forward, li, startPtId, loopPoints);
85
+ if (startPtId !== endPtId) {
86
+ // didn't find a loop. Go other direction to see where we end up
87
+ publicAPI.traverseLoop(input, Dir.Backward, li, startPtId, loopPoints);
88
+ loopPoints.sort((a, b) => a.t < b.t ? -1 : 1);
89
+ // make closed contour
90
+ if (loopPoints.length && loopPoints[0].ptId !== loopPoints[loopPoints.length - 1]?.ptId) {
91
+ loopPoints.push({
92
+ ...loopPoints[loopPoints.length - 1]
93
+ });
94
+ }
95
+ }
96
+ if (loopPoints.length) {
97
+ loops.push(loopPoints);
98
+ }
99
+ }
100
+
101
+ // clear output lines
102
+ const outLines = output.getLines();
103
+ outLines.resize(0);
104
+ loops.forEach(loop => {
105
+ outLines.insertNextCell(loop.map(pt => pt.ptId));
106
+ });
107
+ };
108
+ }
109
+
110
+ // ----------------------------------------------------------------------------
111
+ // Object factory
112
+ // ----------------------------------------------------------------------------
113
+
114
+ const DEFAULT_VALUES = {};
115
+
116
+ // ----------------------------------------------------------------------------
117
+
118
+ function extend(publicAPI, model) {
119
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
120
+ Object.assign(model, DEFAULT_VALUES, initialValues);
121
+ macro.obj(publicAPI, model);
122
+ macro.algo(publicAPI, model, 1, 1);
123
+ vtkContourLoopExtraction(publicAPI);
124
+ }
125
+
126
+ // ----------------------------------------------------------------------------
127
+
128
+ const newInstance = macro.newInstance(extend, 'vtkContourLoopExtraction');
129
+
130
+ // ----------------------------------------------------------------------------
131
+
132
+ var index = {
133
+ newInstance,
134
+ extend
135
+ };
136
+
137
+ export { index as default, extend, newInstance };
@@ -1,11 +1,14 @@
1
1
  import vtkCompositeMouseManipulator, {
2
2
  ICompositeMouseManipulatorInitialValues,
3
3
  } from './CompositeMouseManipulator';
4
+ import { vtkObject } from './../../interfaces';
4
5
 
5
6
  export interface IMouseRangeManipulatorInitialValues
6
7
  extends ICompositeMouseManipulatorInitialValues {}
7
8
 
8
- export interface vtkMouseRangeManipulator extends vtkCompositeMouseManipulator {
9
+ export interface vtkMouseRangeManipulator
10
+ extends vtkCompositeMouseManipulator,
11
+ vtkObject {
9
12
  setHorizontalListener(
10
13
  min: number,
11
14
  max: number,
@@ -8,4 +8,4 @@ var Constants = {
8
8
  Corners
9
9
  };
10
10
 
11
- export { Constants as default };
11
+ export { Corners, Constants as default };
@@ -1,6 +1,5 @@
1
1
  import { vtkObject } from './../../interfaces';
2
- import vtkAnnotatedCubeActor from './../../Rendering/Core/AnnotatedCubeActor';
3
- import vtkAxesActor from './../../Rendering/Core/AxesActor';
2
+ import vtkActor from './../../Rendering/Core/Actor';
4
3
  import vtkRenderer from './../../Rendering/Core/Renderer';
5
4
  import vtkRenderWindowInteractor from './../../Rendering/Core/RenderWindowInteractor';
6
5
  import { Nullable } from './../../types';
@@ -11,7 +10,7 @@ import { Corners } from './OrientationMarkerWidget/Constants';
11
10
  *
12
11
  */
13
12
  export interface IOrientationMarkerWidgetInitialValues {
14
- actor?: vtkAnnotatedCubeActor | vtkAxesActor,
13
+ actor?: vtkActor,
15
14
  interactor?: vtkRenderWindowInteractor,
16
15
  parentRenderer?: vtkRenderer,
17
16
  viewportCorner?: Corners,
@@ -39,7 +38,7 @@ export interface vtkOrientationMarkerWidget extends vtkObject {
39
38
  /**
40
39
  *
41
40
  */
42
- getActor(): vtkAnnotatedCubeActor | vtkAxesActor;
41
+ getActor(): vtkActor;
43
42
 
44
43
  /**
45
44
  * Gets the parent renderer, if any.
@@ -85,9 +84,9 @@ export interface vtkOrientationMarkerWidget extends vtkObject {
85
84
 
86
85
  /**
87
86
  * Get the actor associated with the widget.
88
- * @param {vtkAnnotatedCubeActor | vtkAxesActor} actor The actor instance.
87
+ * @param {vtkActor} actor The actor instance.
89
88
  */
90
- setActor(actor: vtkAnnotatedCubeActor | vtkAxesActor): void;
89
+ setActor(actor: vtkActor): void;
91
90
 
92
91
  /**
93
92
  * Sets the parent renderer
@@ -396,6 +396,11 @@ export interface vtkRenderWindowInteractor extends vtkObject {
396
396
  */
397
397
  invokeEndInteractionEvent(callData: IRenderWindowInteractorEvent): void;
398
398
 
399
+ /**
400
+ *
401
+ */
402
+ invokeRenderEvent(): void;
403
+
399
404
  /**
400
405
  *
401
406
  * @param cb The callback to be called
@@ -659,6 +664,13 @@ export interface vtkRenderWindowInteractor extends vtkObject {
659
664
  */
660
665
  onEndInteractionEvent(cb: InteractorEventCallback, priority?: number): Readonly<vtkSubscription>;
661
666
 
667
+ /**
668
+ *
669
+ * @param {Function} cb The callback to be called.
670
+ * @param {Number} [priority] The priority of the event.
671
+ */
672
+ onRenderEvent(cb: () => void, priority?: number): Readonly<vtkSubscription>;
673
+
662
674
  /**
663
675
  *
664
676
  * @param args
@@ -1,5 +1,6 @@
1
1
  import vtkPiecewiseFunction from './../../Common/DataModel/PiecewiseFunction';
2
2
  import { vtkObject } from './../../interfaces';
3
+ import { Nullable } from './../../types';
3
4
  import vtkColorTransferFunction from './ColorTransferFunction';
4
5
  import { InterpolationType, OpacityMode } from './VolumeProperty/Constants';
5
6
 
@@ -279,14 +280,14 @@ export interface vtkVolumeProperty extends vtkObject {
279
280
  * @param {Number} index
280
281
  * @param {vtkColorTransferFunction} func
281
282
  */
282
- setRGBTransferFunction(index: number, func: vtkColorTransferFunction): boolean;
283
+ setRGBTransferFunction(index: number, func?: Nullable<vtkColorTransferFunction>): boolean;
283
284
 
284
285
  /**
285
286
  * Set the scalar opacity of a volume to a transfer function
286
287
  * @param {Number} index
287
288
  * @param {vtkPiecewiseFunction} func
288
289
  */
289
- setScalarOpacity(index: number, func: vtkPiecewiseFunction): boolean;
290
+ setScalarOpacity(index: number, func?: Nullable<vtkPiecewiseFunction>): boolean;
290
291
 
291
292
  /**
292
293
  * Set the scalar component weights.
@@ -80,7 +80,7 @@ export interface vtkOpenGLRenderWindow extends vtkOpenGLRenderWindowBase {
80
80
  *
81
81
  * @param {HTMLElement} el The container element.
82
82
  */
83
- setContainer(el: HTMLElement): void;
83
+ setContainer(el: Nullable<HTMLElement>): void;
84
84
 
85
85
  /**
86
86
  * Get the container element.
@@ -102,7 +102,9 @@ function extend(publicAPI, model) {
102
102
  vtkProp.extend(publicAPI, model, initialValues);
103
103
  vtkInteractorObserver.extend(publicAPI, model, initialValues);
104
104
  macro.setGet(publicAPI, model, ['contextVisibility', 'handleVisibility', '_widgetManager']);
105
- macro.get(publicAPI, model, ['representations', 'widgetState', 'activeState']);
105
+ macro.get(publicAPI, model, ['representations', 'widgetState', 'activeState' // stores the last activated sub state(handle)
106
+ ]);
107
+
106
108
  macro.moveToProtected(publicAPI, model, ['widgetManager']);
107
109
  macro.event(publicAPI, model, 'ActivateHandle');
108
110
  vtkAbstractWidget(publicAPI, model);
@@ -164,7 +164,9 @@ function widgetBehavior(publicAPI, model) {
164
164
  const step = calldata.spinY;
165
165
  isScrolling = true;
166
166
  publicAPI.translateCenterOnPlaneDirection(step);
167
- publicAPI.invokeInternalInteractionEvent();
167
+ publicAPI.invokeInternalInteractionEvent(
168
+ // Force interaction mode because mouse cursor could be above rotation handle
169
+ InteractionMethodsName.TranslateCenter);
168
170
  isScrolling = false;
169
171
  return macro.EVENT_ABORT;
170
172
  };
@@ -183,14 +185,15 @@ function widgetBehavior(publicAPI, model) {
183
185
  };
184
186
  publicAPI.handleEvent = callData => {
185
187
  if (model.activeState.getActive()) {
186
- publicAPI[publicAPI.getActiveInteraction()](callData);
187
- publicAPI.invokeInternalInteractionEvent();
188
+ const methodName = publicAPI.getActiveInteraction();
189
+ publicAPI[methodName](callData);
190
+ publicAPI.invokeInternalInteractionEvent(methodName);
188
191
  return macro.EVENT_ABORT;
189
192
  }
190
193
  return macro.VOID;
191
194
  };
192
- publicAPI.invokeInternalInteractionEvent = () => {
193
- const methodName = publicAPI.getActiveInteraction();
195
+ publicAPI.invokeInternalInteractionEvent = function () {
196
+ let methodName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : publicAPI.getActiveInteraction();
194
197
  const computeFocalPointOffset = methodName !== InteractionMethodsName.RotateLine;
195
198
  const canUpdateFocalPoint = methodName === InteractionMethodsName.RotateLine;
196
199
  publicAPI.invokeInteractionEvent({
package/index.d.ts CHANGED
@@ -55,6 +55,7 @@
55
55
  /// <reference path="./Common/Transform/Transform.d.ts" />
56
56
  /// <reference path="./Filters/General/AppendPolyData.d.ts" />
57
57
  /// <reference path="./Filters/General/ClipClosedSurface.d.ts" />
58
+ /// <reference path="./Filters/General/ContourLoopExtraction.d.ts" />
58
59
  /// <reference path="./Filters/General/ContourTriangulator.d.ts" />
59
60
  /// <reference path="./Filters/General/ImageCropFilter.d.ts" />
60
61
  /// <reference path="./Filters/General/ImageDataOutlineFilter.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "29.6.0",
3
+ "version": "29.7.1",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",