vtk.js 29.6.0 → 29.7.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.
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @project vtk.js
3
- * @build Thu, Feb 8, 2024 8:13 PM ET
3
+ * @build Thu, Feb 8, 2024 10:05 PM ET
4
4
  * @copyright Copyright (c) 2024 Kitware, Inc.
5
5
  *
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @project vtk.js
3
- * @build Thu, Feb 8, 2024 8:13 PM ET
3
+ * @build Thu, Feb 8, 2024 10:05 PM ET
4
4
  * @copyright Copyright (c) 2024 Kitware, Inc.
5
5
  *
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @project vtk.js
3
- * @build Thu, Feb 8, 2024 8:13 PM ET
3
+ * @build Thu, Feb 8, 2024 10:05 PM ET
4
4
  * @copyright Copyright (c) 2024 Kitware, Inc.
5
5
  *
6
6
  */
@@ -1,6 +1,6 @@
1
1
  /*!
2
2
  * @project vtk.js
3
- * @build Thu, Feb 8, 2024 8:13 PM ET
3
+ * @build Thu, Feb 8, 2024 10:05 PM ET
4
4
  * @copyright Copyright (c) 2024 Kitware, Inc.
5
5
  *
6
6
  */
@@ -0,0 +1,79 @@
1
+ import { vtkAlgorithm, vtkObject } from 'vtk.js/Sources/interfaces';
2
+ import vtkPolyData from 'vtk.js/Sources/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,153 @@
1
+ import macro from 'vtk.js/Sources/macros';
2
+ import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
3
+
4
+ const Dir = {
5
+ Forward: 1,
6
+ Backward: -1,
7
+ };
8
+
9
+ const visited = new Set();
10
+
11
+ function vtkContourLoopExtraction(publicAPI, model) {
12
+ publicAPI.requestData = (inData, outData) => {
13
+ const [input] = inData;
14
+
15
+ if (!outData[0]) {
16
+ outData[0] = vtkPolyData.newInstance();
17
+ }
18
+ const [output] = outData;
19
+ publicAPI.extractContours(input, output);
20
+ output.modified();
21
+ };
22
+
23
+ publicAPI.traverseLoop = (pd, dir, startLineId, startPtId, loopPoints) => {
24
+ let lineId = startLineId;
25
+ let lastPtId = startPtId;
26
+ let terminated = false;
27
+ let numInserted = 0;
28
+
29
+ while (!terminated) {
30
+ const { cellPointIds } = pd.getCellPoints(lineId);
31
+ if (!cellPointIds) {
32
+ // eslint-disable-next-line no-continue
33
+ continue;
34
+ }
35
+
36
+ lastPtId =
37
+ cellPointIds[0] !== lastPtId ? cellPointIds[0] : cellPointIds[1];
38
+ numInserted++;
39
+
40
+ // parametric point value
41
+ const t = dir * numInserted;
42
+ loopPoints.push({ t, ptId: lastPtId });
43
+
44
+ const lineCell = pd.getPointCells(lastPtId);
45
+
46
+ if (lineCell.length !== 2 || lastPtId === startPtId) {
47
+ // looped
48
+ return lastPtId;
49
+ }
50
+
51
+ if (lineCell.length === 2) {
52
+ // continue along loop
53
+ lineId = lineCell[0] !== lineId ? lineCell[0] : lineCell[1];
54
+ visited.add(lineId);
55
+ } else {
56
+ // empty or invalid cell
57
+ terminated = true;
58
+ }
59
+ }
60
+
61
+ return lastPtId;
62
+ };
63
+
64
+ publicAPI.extractContours = (input, output) => {
65
+ const loops = [];
66
+ visited.clear();
67
+
68
+ const inLines = input.getLines();
69
+ output.getPoints().setData(Float32Array.from(input.getPoints().getData()));
70
+
71
+ // TODO skip if cached input mtime hasn't changed.
72
+ // iterate over input lines
73
+ for (let li = 0; li < inLines.getNumberOfCells(); li++) {
74
+ if (visited.has(li)) {
75
+ // eslint-disable-next-line no-continue
76
+ continue;
77
+ }
78
+
79
+ const { cellPointIds } = input.getCellPoints(li);
80
+ if (!cellPointIds) {
81
+ // eslint-disable-next-line no-continue
82
+ continue;
83
+ }
84
+
85
+ visited.add(li);
86
+ const startPtId = cellPointIds[0];
87
+
88
+ const loopPoints = [];
89
+ loopPoints.push({ t: 0, ptId: startPtId });
90
+
91
+ const endPtId = publicAPI.traverseLoop(
92
+ input,
93
+ Dir.Forward,
94
+ li,
95
+ startPtId,
96
+ loopPoints
97
+ );
98
+
99
+ if (startPtId !== endPtId) {
100
+ // didn't find a loop. Go other direction to see where we end up
101
+ publicAPI.traverseLoop(input, Dir.Backward, li, startPtId, loopPoints);
102
+ loopPoints.sort((a, b) => (a.t < b.t ? -1 : 1));
103
+ // make closed contour
104
+ if (
105
+ loopPoints.length &&
106
+ loopPoints[0].ptId !== loopPoints[loopPoints.length - 1]?.ptId
107
+ ) {
108
+ loopPoints.push({ ...loopPoints[loopPoints.length - 1] });
109
+ }
110
+ }
111
+
112
+ if (loopPoints.length) {
113
+ loops.push(loopPoints);
114
+ }
115
+ }
116
+
117
+ // clear output lines
118
+ const outLines = output.getLines();
119
+ outLines.resize(0);
120
+
121
+ loops.forEach((loop) => {
122
+ outLines.insertNextCell(loop.map((pt) => pt.ptId));
123
+ });
124
+ };
125
+ }
126
+
127
+ // ----------------------------------------------------------------------------
128
+ // Object factory
129
+ // ----------------------------------------------------------------------------
130
+
131
+ const DEFAULT_VALUES = {};
132
+
133
+ // ----------------------------------------------------------------------------
134
+
135
+ export function extend(publicAPI, model, initialValues = {}) {
136
+ Object.assign(model, DEFAULT_VALUES, initialValues);
137
+
138
+ macro.obj(publicAPI, model);
139
+ macro.algo(publicAPI, model, 1, 1);
140
+
141
+ vtkContourLoopExtraction(publicAPI, model);
142
+ }
143
+
144
+ // ----------------------------------------------------------------------------
145
+
146
+ export const newInstance = macro.newInstance(
147
+ extend,
148
+ 'vtkContourLoopExtraction'
149
+ );
150
+
151
+ // ----------------------------------------------------------------------------
152
+
153
+ export default { newInstance, extend };
@@ -1,11 +1,14 @@
1
1
  import vtkCompositeMouseManipulator, {
2
2
  ICompositeMouseManipulatorInitialValues,
3
3
  } from 'vtk.js/Sources/Interaction/Manipulators/CompositeMouseManipulator';
4
+ import { vtkObject } from 'vtk.js/Sources/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,
@@ -1,4 +1,4 @@
1
- const Corners = {
1
+ export const Corners = {
2
2
  TOP_LEFT: 'TOP_LEFT',
3
3
  TOP_RIGHT: 'TOP_RIGHT',
4
4
  BOTTOM_LEFT: 'BOTTOM_LEFT',
@@ -1,6 +1,5 @@
1
1
  import { vtkObject } from 'vtk.js/Sources/interfaces';
2
- import vtkAnnotatedCubeActor from 'vtk.js/Sources/Rendering/Core/AnnotatedCubeActor';
3
- import vtkAxesActor from 'vtk.js/Sources/Rendering/Core/AxesActor';
2
+ import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
4
3
  import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer';
5
4
  import vtkRenderWindowInteractor from 'vtk.js/Sources/Rendering/Core/RenderWindowInteractor';
6
5
  import { Nullable } from 'vtk.js/Sources/types';
@@ -11,7 +10,7 @@ import { Corners } from 'vtk.js/Sources/Interaction/Widgets/OrientationMarkerWid
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 'vtk.js/Sources/Common/DataModel/PiecewiseFunction';
2
2
  import { vtkObject } from 'vtk.js/Sources/interfaces';
3
+ import { Nullable } from 'vtk.js/Sources/types';
3
4
  import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction';
4
5
  import { InterpolationType, OpacityMode } from 'vtk.js/Sources/Rendering/Core/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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vtk.js",
3
- "version": "29.6.0",
3
+ "version": "29.7.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",