@kitware/vtk.js 34.3.1 → 34.4.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.
@@ -0,0 +1,154 @@
1
+ import { vtkAlgorithm, vtkObject } from './../../interfaces';
2
+ import { Vector3 } from './../../types';
3
+
4
+ /**
5
+ *
6
+ */
7
+ export interface IDiskSourceInitialValues {
8
+ innerRadius?: number;
9
+ outerRadius?: number;
10
+ center?: Vector3;
11
+ normal?: Vector3;
12
+ radialResolution?: number;
13
+ circumferentialResolution?: number;
14
+ pointType?: string;
15
+ }
16
+
17
+ type vtkDiskSourceBase = vtkObject &
18
+ Omit<
19
+ vtkAlgorithm,
20
+ | 'getInputData'
21
+ | 'setInputData'
22
+ | 'setInputConnection'
23
+ | 'getInputConnection'
24
+ | 'addInputConnection'
25
+ | 'addInputData'
26
+ >;
27
+
28
+ export interface vtkDiskSource extends vtkDiskSourceBase {
29
+ /**
30
+ * Get the center of the disk.
31
+ */
32
+ getCenter(): Vector3;
33
+
34
+ /**
35
+ * Get the circumferential resolution of the disk.
36
+ */
37
+ getCircumferentialResolution(): number;
38
+
39
+ /**
40
+ * Get the inner radius of the disk.
41
+ */
42
+ getInnerRadius(): number;
43
+
44
+ /**
45
+ * Get the normal of the disk.
46
+ */
47
+ getNormal(): Vector3;
48
+
49
+ /**
50
+ * Get the outer radius of the disk.
51
+ */
52
+ getOuterRadius(): number;
53
+
54
+ /**
55
+ * Get the point type used for the disk.
56
+ */
57
+ getPointType(): string;
58
+
59
+ /**
60
+ * Get the radial resolution of the disk.
61
+ */
62
+ getRadialResolution(): number;
63
+
64
+ /**
65
+ * Expose methods
66
+ * @param inData
67
+ * @param outData
68
+ */
69
+ requestData(inData: any, outData: any): void;
70
+
71
+ /**
72
+ * Set the center of the disk.
73
+ * @param {Vector3} center
74
+ */
75
+ setCenter(center: Vector3): boolean;
76
+
77
+ /**
78
+ * Set the circumferential resolution of the disk.
79
+ * @param {number} resolution
80
+ */
81
+ setCircumferentialResolution(resolution: number): boolean;
82
+
83
+ /**
84
+ * Set the inner radius of the disk.
85
+ * @param {number} radius
86
+ */
87
+ setInnerRadius(radius: number): boolean;
88
+
89
+ /**
90
+ * Set the normal of the disk.
91
+ * @param {Vector3} normal
92
+ */
93
+ setNormal(normal: Vector3): boolean;
94
+
95
+ /**
96
+ * Set the outer radius of the disk.
97
+ * @param {number} radius
98
+ */
99
+ setOuterRadius(radius: number): boolean;
100
+
101
+ /**
102
+ * Set the point type used for the disk.
103
+ * @param {string} type
104
+ */
105
+ setPointType(type: string): boolean;
106
+
107
+ /**
108
+ * Set the radial resolution of the disk.
109
+ * @param {number} resolution
110
+ */
111
+ setRadialResolution(resolution: number): boolean;
112
+ }
113
+
114
+ /**
115
+ * Method used to decorate a given object (publicAPI+model) with vtkDiskSource characteristics.
116
+ *
117
+ * @param publicAPI object on which methods will be bounds (public)
118
+ * @param model object on which data structure will be bounds (protected)
119
+ * @param {IDiskSourceInitialValues} [initialValues] (default: {})
120
+ */
121
+ export function extend(
122
+ publicAPI: object,
123
+ model: object,
124
+ initialValues?: IDiskSourceInitialValues
125
+ ): void;
126
+
127
+ /**
128
+ * Method used to create a new instance of vtkDiskSource.
129
+ * @param {IDiskSourceInitialValues} [initialValues] for pre-setting some of its content
130
+ */
131
+ export function newInstance(
132
+ initialValues?: IDiskSourceInitialValues
133
+ ): vtkDiskSource;
134
+
135
+ /**
136
+ * vtkDiskSource creates a polygonal disk with a hole in the center. The disk
137
+ * has zero height. The user can specify the inner and outer radius of the disk,
138
+ * the radial and circumferential resolution of the polygonal representation,
139
+ * and the center and plane normal of the disk (i.e., the center and disk normal
140
+ * control the position and orientation of the disk).
141
+ *
142
+ * @example
143
+ * ```js
144
+ * import vtkDiskSource from '@kitware/vtk.js/Filters/Sources/DiskSource';
145
+ *
146
+ * const disk = vtkDiskSource.newInstance({ radius: 1, resolution: 80 });
147
+ * const polydata = disk.getOutputData();
148
+ * ```
149
+ */
150
+ export declare const vtkDiskSource: {
151
+ newInstance: typeof newInstance;
152
+ extend: typeof extend;
153
+ };
154
+ export default vtkDiskSource;
@@ -0,0 +1,137 @@
1
+ import { m as macro } from '../../macros2.js';
2
+ import vtkCellArray from '../../Common/Core/CellArray.js';
3
+ import vtkPolyData from '../../Common/DataModel/PolyData.js';
4
+ import vtkPoints from '../../Common/Core/Points.js';
5
+ import vtkMatrixBuilder from '../../Common/Core/MatrixBuilder.js';
6
+
7
+ const {
8
+ vtkErrorMacro
9
+ } = macro;
10
+
11
+ // ----------------------------------------------------------------------------
12
+ // vtkDiskSource methods
13
+ // ----------------------------------------------------------------------------
14
+
15
+ function vtkDiskSource(publicAPI, model) {
16
+ // Set our classname
17
+ model.classHierarchy.push('vtkDiskSource');
18
+ publicAPI.requestData = (inData, outData) => {
19
+ const {
20
+ innerRadius,
21
+ outerRadius,
22
+ center,
23
+ normal,
24
+ radialResolution,
25
+ circumferentialResolution,
26
+ pointType
27
+ } = model;
28
+ if (model.deleted) {
29
+ return;
30
+ }
31
+ let dataset = outData[0];
32
+
33
+ // Points
34
+ const points = vtkPoints.newInstance({
35
+ dataType: pointType
36
+ });
37
+ const n = [normal[0], normal[1], normal[2]];
38
+ const length = Math.hypot(n[0], n[1], n[2]);
39
+ if (length === 0) {
40
+ vtkErrorMacro('Normal vector cannot be zero-length');
41
+ return;
42
+ }
43
+ n[0] /= length;
44
+ n[1] /= length;
45
+ n[2] /= length;
46
+ const matrix = vtkMatrixBuilder.buildFromDegree().identity().translate(-center[0], -center[1], -center[2]).rotateFromDirections([0, 0, 1], n).translate(center[0], center[1], center[2]).getMatrix();
47
+ const polys = vtkCellArray.newInstance();
48
+
49
+ // Generate points
50
+ const deltaR = (outerRadius - innerRadius) / radialResolution;
51
+ const thetaStep = 2.0 * Math.PI / circumferentialResolution;
52
+ for (let i = 0; i < circumferentialResolution; i++) {
53
+ const theta = i * thetaStep;
54
+ const cosT = Math.cos(theta);
55
+ const sinT = Math.sin(theta);
56
+ for (let j = 0; j <= radialResolution; j++) {
57
+ const r = innerRadius + j * deltaR;
58
+ // point in XY plane before transform
59
+ const localPoint = [center[0] + r * cosT, center[1] + r * sinT, center[2]];
60
+ // apply matrix transform
61
+ const x = matrix[0] * localPoint[0] + matrix[4] * localPoint[1] + matrix[8] * localPoint[2] + matrix[12];
62
+ const y = matrix[1] * localPoint[0] + matrix[5] * localPoint[1] + matrix[9] * localPoint[2] + matrix[13];
63
+ const z = matrix[2] * localPoint[0] + matrix[6] * localPoint[1] + matrix[10] * localPoint[2] + matrix[14];
64
+ points.insertNextPoint(x, y, z);
65
+ }
66
+ }
67
+
68
+ // Generate cell connectivity (quads)
69
+ const cellCount = radialResolution * circumferentialResolution;
70
+ const cellData = new Uint8Array(cellCount * 5);
71
+ let offset = 0;
72
+ for (let i = 0; i < model.circumferentialResolution; i++) {
73
+ for (let j = 0; j < model.radialResolution; j++) {
74
+ const p0 = i * (model.radialResolution + 1) + j;
75
+ const p1 = p0 + 1;
76
+ const p2 = i < model.circumferentialResolution - 1 ? p1 + (model.radialResolution + 1) : j + 1; // wrap around
77
+ const p3 = p2 - 1;
78
+ cellData[offset++] = 4;
79
+ cellData[offset++] = p0;
80
+ cellData[offset++] = p1;
81
+ cellData[offset++] = p2;
82
+ cellData[offset++] = p3;
83
+ }
84
+ }
85
+ polys.setData(cellData, cellCount, 1);
86
+ dataset = vtkPolyData.newInstance();
87
+ dataset.setPoints(points);
88
+ dataset.setPolys(polys);
89
+
90
+ // Update output
91
+ outData[0] = dataset;
92
+ };
93
+ }
94
+
95
+ // ----------------------------------------------------------------------------
96
+ // Object factory
97
+ // ----------------------------------------------------------------------------
98
+
99
+ function defaultValues(initialValues) {
100
+ return {
101
+ innerRadius: 0.25,
102
+ outerRadius: 0.5,
103
+ center: [0, 0, 0],
104
+ normal: [0, 0, 1],
105
+ radialResolution: 1,
106
+ circumferentialResolution: 6,
107
+ pointType: 'Float64Array',
108
+ ...initialValues
109
+ };
110
+ }
111
+
112
+ // ----------------------------------------------------------------------------
113
+
114
+ function extend(publicAPI, model) {
115
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
116
+ Object.assign(model, defaultValues(initialValues));
117
+
118
+ // Build VTK API
119
+ macro.obj(publicAPI, model);
120
+ macro.setGet(publicAPI, model, ['innerRadius', 'outerRadius', 'radialResolution', 'circumferentialResolution', 'pointType']);
121
+ macro.setGetArray(publicAPI, model, ['center', 'normal'], 3);
122
+ macro.algo(publicAPI, model, 0, 1);
123
+ vtkDiskSource(publicAPI, model);
124
+ }
125
+
126
+ // ----------------------------------------------------------------------------
127
+
128
+ const newInstance = macro.newInstance(extend, 'vtkDiskSource');
129
+
130
+ // ----------------------------------------------------------------------------
131
+
132
+ var vtkDiskSource$1 = {
133
+ newInstance,
134
+ extend
135
+ };
136
+
137
+ export { vtkDiskSource$1 as default, extend, newInstance };
@@ -5,6 +5,7 @@ import vtkConeSource from './Sources/ConeSource.js';
5
5
  import vtkCubeSource from './Sources/CubeSource.js';
6
6
  import vtkCursor3D from './Sources/Cursor3D.js';
7
7
  import vtkCylinderSource from './Sources/CylinderSource.js';
8
+ import vtkDiskSource from './Sources/DiskSource.js';
8
9
  import vtkImageGridSource from './Sources/ImageGridSource.js';
9
10
  import vtkLineSource from './Sources/LineSource.js';
10
11
  import vtkPlaneSource from './Sources/PlaneSource.js';
@@ -21,6 +22,7 @@ var Sources = {
21
22
  vtkCubeSource,
22
23
  vtkCursor3D,
23
24
  vtkCylinderSource,
25
+ vtkDiskSource,
24
26
  vtkImageGridSource,
25
27
  vtkLineSource,
26
28
  vtkPlaneSource,
@@ -14,6 +14,7 @@ import '../../Filters/Sources/ConeSource.js';
14
14
  import '../../Filters/Sources/CubeSource.js';
15
15
  import '../../Filters/Sources/Cursor3D.js';
16
16
  import '../../Filters/Sources/CylinderSource.js';
17
+ import '../../Filters/Sources/DiskSource.js';
17
18
  import '../../Filters/Sources/ImageGridSource.js';
18
19
  import '../../Filters/Sources/LineSource.js';
19
20
  import '../../Filters/Sources/PlaneSource.js';
package/index.d.ts CHANGED
@@ -75,6 +75,7 @@
75
75
  /// <reference path="./Filters/Sources/CubeSource.d.ts" />
76
76
  /// <reference path="./Filters/Sources/Cursor3D.d.ts" />
77
77
  /// <reference path="./Filters/Sources/CylinderSource.d.ts" />
78
+ /// <reference path="./Filters/Sources/DiskSource.d.ts" />
78
79
  /// <reference path="./Filters/Sources/LineSource.d.ts" />
79
80
  /// <reference path="./Filters/Sources/PlaneSource.d.ts" />
80
81
  /// <reference path="./Filters/Sources/PointSource.d.ts" />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitware/vtk.js",
3
- "version": "34.3.1",
3
+ "version": "34.4.0",
4
4
  "description": "Visualization Toolkit for the Web",
5
5
  "keywords": [
6
6
  "3d",