@kitware/vtk.js 34.9.1 → 34.11.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,120 @@
1
+ import { Bounds, Vector3 } from './../../types';
2
+ import vtkDataArray from './../Core/DataArray';
3
+ import vtkImplicitFunction, {
4
+ IImplicitFunctionInitialValues,
5
+ } from './ImplicitFunction';
6
+ import vtkPlane from './Plane';
7
+ import vtkPoints from './../Core/Points';
8
+
9
+ /**
10
+ *
11
+ */
12
+ export interface IPlanesInitialValues extends IImplicitFunctionInitialValues {
13
+ points?: vtkPoints;
14
+ normals?: vtkDataArray;
15
+ bounds?: Bounds;
16
+ planes?: number[];
17
+ }
18
+
19
+ export interface vtkPlanes extends vtkImplicitFunction {
20
+ /**
21
+ * Evaluate the function at a point x
22
+ * @param x The point at which to evaluate the function
23
+ * @returns The function value at the point x
24
+ */
25
+ evaluateFunction(x: Vector3): number;
26
+
27
+ /**
28
+ * Evaluate the gradient at a point x
29
+ * @param x The point at which to evaluate the gradient
30
+ * @returns The gradient at the point x
31
+ */
32
+ evaluateGradient(x: Vector3): Vector3;
33
+
34
+ /**
35
+ * Get the bounds of the planes.
36
+ * @returns {Bounds} The bounds of the planes.
37
+ */
38
+ getBounds(): Bounds;
39
+
40
+ /**
41
+ * Get the number of planes in the set of planes.
42
+ */
43
+ getNumberOfPlanes(): number;
44
+
45
+ /**
46
+ * Get the normals of the plane.
47
+ * @returns {vtkDataArray} The normals of the plane.
48
+ */
49
+ getNormals(): vtkDataArray;
50
+
51
+ /**
52
+ * Get the points of the plane.
53
+ * @returns {vtkPoints} The points of the plane.
54
+ */
55
+ getPoints(): vtkPoints;
56
+
57
+ /**
58
+ * Get the i-th plane
59
+ * @param {Number} i The index of the plane to get.
60
+ * @param {vtkPlane} [plane] The vtkPlane instance to fill (optional).
61
+ * @returns {vtkPlane} The plane instance at the specified index.
62
+ * If no plane is provided, a new vtkPlane instance will be created.
63
+ */
64
+ getPlane(i: number, plane?: vtkPlane): vtkPlane;
65
+
66
+ /**
67
+ * Set the bounds of the planes.
68
+ * @param {Bounds} bounds The bounds to set.
69
+ * @returns {Boolean} true if bounds were set, false if they were already set
70
+ * @see getBounds
71
+ */
72
+ setBounds(bounds: Bounds): boolean;
73
+
74
+ /**
75
+ * Set the Frustum planes.
76
+ * @param {Vector3[]} planes The coordinates of the frustum planes.
77
+ */
78
+ setFrustumPlanes(planes: Vector3[]): boolean;
79
+
80
+ /**
81
+ * Set the normals of the plane.
82
+ * @param {vtkDataArray} normals The normals to set.
83
+ */
84
+ setNormals(normals: vtkDataArray): boolean;
85
+
86
+ /**
87
+ * Set the points of the plane.
88
+ * @param points The points to set.
89
+ */
90
+ setPoints(points: vtkPoints): boolean;
91
+ }
92
+
93
+ /**
94
+ * Method used to decorate a given object (publicAPI+model) with vtkPlane characteristics.
95
+ *
96
+ * @param publicAPI object on which methods will be bounds (public)
97
+ * @param model object on which data structure will be bounds (protected)
98
+ * @param {IPlanesInitialValues} [initialValues] (default: {})
99
+ */
100
+ export function extend(
101
+ publicAPI: object,
102
+ model: object,
103
+ initialValues?: IPlanesInitialValues
104
+ ): void;
105
+
106
+ /**
107
+ * Method used to create a new instance of vtkPlane.
108
+ * @param {IPlanesInitialValues} [initialValues] for pre-setting some of its content
109
+ */
110
+ export function newInstance(initialValues?: IPlanesInitialValues): vtkPlanes;
111
+
112
+ /**
113
+ * vtkPlanes computes the implicit function and function gradient for a set of
114
+ * planes. The planes must define a convex space.
115
+ */
116
+ export declare const vtkPlanes: {
117
+ newInstance: typeof newInstance;
118
+ extend: typeof extend;
119
+ };
120
+ export default vtkPlanes;
@@ -0,0 +1,281 @@
1
+ import { m as macro, T as TYPED_ARRAYS } from '../../macros2.js';
2
+ import vtkDataArray from '../Core/DataArray.js';
3
+ import vtkImplicitFunction from './ImplicitFunction.js';
4
+ import { f as vtkMath } from '../Core/Math/index.js';
5
+ import vtkPlane from './Plane.js';
6
+ import vtkPoints from '../Core/Points.js';
7
+ import { VtkDataTypes } from '../Core/DataArray/Constants.js';
8
+
9
+ const {
10
+ vtkErrorMacro,
11
+ vtkWarningMacro
12
+ } = macro;
13
+
14
+ // ----------------------------------------------------------------------------
15
+ // vtkPlanes methods
16
+ // ----------------------------------------------------------------------------
17
+
18
+ function vtkPlanes(publicAPI, model) {
19
+ // Set our className
20
+ model.classHierarchy.push('vtkPlanes');
21
+
22
+ // Initialize internal variables
23
+ model.planes = model.planes || macro.newTypedArray(TYPED_ARRAYS.Float64Array, 24);
24
+ model.bounds = model.bounds || macro.newTypedArray(TYPED_ARRAYS.Float64Array, 6);
25
+ model.plane = vtkPlane.newInstance();
26
+
27
+ // Public API methods
28
+ publicAPI.setNormals = normals => {
29
+ if (normals && normals.getNumberOfComponents() !== 3) {
30
+ vtkWarningMacro('This array does not have 3 components. Ignoring normals.');
31
+ }
32
+ model.normals = normals;
33
+ publicAPI.modified();
34
+ return true;
35
+ };
36
+
37
+ /**
38
+ * Evaluate the function at a point x
39
+ * @param {*} x The point at which to evaluate the function
40
+ * @returns The function value at the point x
41
+ */
42
+ publicAPI.evaluateFunction = x => {
43
+ if (!model.points || !model.normals) {
44
+ vtkErrorMacro('Please define points and/or normals!');
45
+ return Number.MAX_VALUE;
46
+ }
47
+ const numPlanes = model.points.getNumberOfPoints();
48
+ if (numPlanes !== model.normals.getNumberOfTuples()) {
49
+ vtkErrorMacro('Number of normals/points inconsistent!');
50
+ return Number.MAX_VALUE;
51
+ }
52
+ let maxVal = -Number.MAX_VALUE;
53
+ const normal = [];
54
+ const point = [];
55
+ for (let i = 0; i < numPlanes; i++) {
56
+ model.normals.getTuple(i, normal);
57
+ model.points.getPoint(i, point);
58
+ const val = vtkPlane.evaluate(normal, point, x);
59
+ if (val > maxVal) {
60
+ maxVal = val;
61
+ }
62
+ }
63
+ return maxVal;
64
+ };
65
+
66
+ /**
67
+ * Evaluate the gradient at a point x
68
+ * @param {*} x The point at which to evaluate the gradient
69
+ * @returns The gradient at the point x
70
+ */
71
+ publicAPI.evaluateGradient = x => {
72
+ const retVal = [0, 0, 0];
73
+ if (!model.points || !model.normals) {
74
+ vtkErrorMacro('Define points and/or normals first!');
75
+ return retVal;
76
+ }
77
+ const numPlanes = model.points.getNumberOfPoints();
78
+ if (numPlanes !== model.normals.getNumberOfTuples()) {
79
+ vtkErrorMacro('The number of normals/points is inconsistent!');
80
+ return retVal;
81
+ }
82
+ let maxVal = -Number.MAX_VALUE;
83
+ const nTemp = [];
84
+ const pTemp = [];
85
+ for (let i = 0; i < numPlanes; i++) {
86
+ model.normals.getTuple(i, nTemp);
87
+ model.points.getPoint(i, pTemp);
88
+ const val = vtkPlane.evaluate(nTemp, pTemp, x);
89
+ if (val > maxVal) {
90
+ maxVal = val;
91
+ retVal[0] = nTemp[0];
92
+ retVal[1] = nTemp[1];
93
+ retVal[2] = nTemp[2];
94
+ }
95
+ }
96
+ return retVal;
97
+ };
98
+
99
+ /**
100
+ * Set the frustum planes
101
+ * @param {Number[]} planes The planes to set
102
+ * @returns {Boolean} true if planes were set, false if they were already set
103
+ */
104
+ publicAPI.setFrustumPlanes = planes => {
105
+ if (vtkMath.areEquals(model.planes, planes)) {
106
+ return false;
107
+ }
108
+ model.planes = [...planes];
109
+ const pts = vtkPoints.newInstance({
110
+ dataType: VtkDataTypes.DOUBLE
111
+ });
112
+ const normals = vtkDataArray.newInstance({
113
+ numberOfComponents: 3,
114
+ size: 6 * 3,
115
+ // 6 planes, each with a normal
116
+ dataType: VtkDataTypes.DOUBLE
117
+ });
118
+ pts.setNumberOfPoints(6);
119
+ publicAPI.setPoints(pts);
120
+ publicAPI.setNormals(normals);
121
+ const n = [];
122
+ const x = [];
123
+ for (let i = 0; i < 6; i++) {
124
+ const planeOffset = 4 * i;
125
+ n[0] = -planes[planeOffset];
126
+ n[1] = -planes[planeOffset + 1];
127
+ n[2] = -planes[planeOffset + 2];
128
+ x[0] = 0.0;
129
+ x[1] = 0.0;
130
+ x[2] = 0.0;
131
+ if (n[0] !== 0.0) {
132
+ x[0] = planes[planeOffset + 3] / n[0];
133
+ } else if (n[1] !== 0.0) {
134
+ x[1] = planes[planeOffset + 3] / n[1];
135
+ } else {
136
+ x[2] = planes[planeOffset + 3] / n[2];
137
+ }
138
+ pts.setPoint(i, ...x);
139
+ normals.setTuple(i, n);
140
+ }
141
+ publicAPI.modified();
142
+ return true;
143
+ };
144
+
145
+ /**
146
+ * Set the bounds of the planes
147
+ * @param {*} bounds The bounds to set
148
+ * @returns {Boolean} true if bounds were set, false if they were already set
149
+ */
150
+ publicAPI.setBounds = bounds => {
151
+ if (vtkMath.areEquals(model.bounds, bounds)) {
152
+ return false;
153
+ }
154
+ model.bounds = [...bounds];
155
+ const pts = vtkPoints.newInstance();
156
+ const normals = vtkDataArray.newInstance({
157
+ numberOfComponents: 3,
158
+ size: 6 * 3,
159
+ // 6 planes, each with a normal
160
+ dataType: VtkDataTypes.DOUBLE
161
+ });
162
+ pts.setNumberOfPoints(6);
163
+ publicAPI.setPoints(pts);
164
+ publicAPI.setNormals(normals);
165
+ const n = [];
166
+ const x = [];
167
+
168
+ // The x planes
169
+ n[0] = -1.0;
170
+ n[1] = 0.0;
171
+ n[2] = 0.0;
172
+ x[0] = bounds[0];
173
+ x[1] = 0.0;
174
+ x[2] = 0.0;
175
+ pts.setPoint(0, ...x);
176
+ normals.setTuple(0, n);
177
+ n[0] = 1.0;
178
+ x[0] = bounds[1];
179
+ pts.setPoint(1, ...x);
180
+ normals.setTuple(1, n);
181
+
182
+ // The y planes
183
+ n[0] = 0.0;
184
+ n[1] = -1.0;
185
+ n[2] = 0.0;
186
+ x[0] = 0.0;
187
+ x[1] = bounds[2];
188
+ x[2] = 0.0;
189
+ pts.setPoint(2, ...x);
190
+ normals.setTuple(2, n);
191
+ n[1] = 1.0;
192
+ x[1] = bounds[3];
193
+ pts.setPoint(3, ...x);
194
+ normals.setTuple(3, n);
195
+
196
+ // The z planes
197
+ n[0] = 0.0;
198
+ n[1] = 0.0;
199
+ n[2] = -1.0;
200
+ x[0] = 0.0;
201
+ x[1] = 0.0;
202
+ x[2] = bounds[4];
203
+ pts.setPoint(4, ...x);
204
+ normals.setTuple(4, n);
205
+ n[2] = 1.0;
206
+ x[2] = bounds[5];
207
+ pts.setPoint(5, ...x);
208
+ normals.setTuple(5, n);
209
+ publicAPI.modified();
210
+ return true;
211
+ };
212
+
213
+ /**
214
+ * Get the number of planes
215
+ * @returns {Number} the number of planes
216
+ */
217
+ publicAPI.getNumberOfPlanes = () => {
218
+ if (model.points && model.normals) {
219
+ const npts = model.points.getNumberOfPoints();
220
+ const nnormals = model.normals.getNumberOfTuples();
221
+ return Math.min(npts, nnormals);
222
+ }
223
+ return 0;
224
+ };
225
+
226
+ /**
227
+ * Get the i-th plane
228
+ * @param {*} i
229
+ * @param {vtkPlane} plane the vtkPlane instance to fill
230
+ * @returns {vtkPlane} the plane instance
231
+ */
232
+ publicAPI.getPlane = function (i) {
233
+ let plane = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : model.plane;
234
+ if (i >= 0 && i < publicAPI.getNumberOfPlanes()) {
235
+ const normal = model.normals.getTuple(i);
236
+ const point = model.points.getPoint(i);
237
+ plane.setNormal(normal);
238
+ plane.setOrigin(point);
239
+ }
240
+ return plane;
241
+ };
242
+ }
243
+
244
+ // ----------------------------------------------------------------------------
245
+ // Object factory
246
+ // ----------------------------------------------------------------------------
247
+
248
+ const DEFAULT_VALUES = {
249
+ points: null,
250
+ normals: null,
251
+ planes: null,
252
+ bounds: null
253
+ };
254
+
255
+ // ----------------------------------------------------------------------------
256
+
257
+ function extend(publicAPI, model) {
258
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
259
+ Object.assign(model, DEFAULT_VALUES, initialValues);
260
+
261
+ // Build VTK API
262
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
263
+ macro.setGet(publicAPI, model, ['points', 'normals']);
264
+ macro.get(publicAPI, model, ['bounds', 'planes']);
265
+
266
+ // Object methods
267
+ vtkPlanes(publicAPI, model);
268
+ }
269
+
270
+ // ----------------------------------------------------------------------------
271
+
272
+ const newInstance = macro.newInstance(extend, 'vtkPlanes');
273
+
274
+ // ----------------------------------------------------------------------------
275
+
276
+ var vtkPlanes$1 = {
277
+ newInstance,
278
+ extend
279
+ };
280
+
281
+ export { vtkPlanes$1 as default, extend, newInstance };
@@ -0,0 +1,217 @@
1
+ import { Bounds, Nullable, Vector3 } from './../../types';
2
+ import vtkPoints from './../Core/Points';
3
+ import vtkAbstractPointLocator, {
4
+ IAbstractPointLocatorInitialValues,
5
+ } from './AbstractPointLocator';
6
+ import vtkPolyData from './PolyData';
7
+
8
+ /**
9
+ *
10
+ */
11
+ export interface IPointLocatorInitialValues
12
+ extends IAbstractPointLocatorInitialValues {
13
+ numberOfPointsPerBucket?: number;
14
+ bucketSize?: number;
15
+ }
16
+
17
+ export interface IInsertPointResult {
18
+ inserted: boolean;
19
+ id: number;
20
+ }
21
+
22
+ interface IFindClosestPointResult {
23
+ id: number;
24
+ dist2: number;
25
+ }
26
+
27
+ export interface vtkPointLocator extends vtkAbstractPointLocator {
28
+ /**
29
+ * Find the closest inserted point to the given coordinates.
30
+ *
31
+ * @param {Vector3} x The query point
32
+ * @returns {Number} The id of the closest inserted point or -1 if not found
33
+ */
34
+ findClosestInsertedPoint(x: Vector3): number;
35
+
36
+ /**
37
+ * Find the closest point to a given point.
38
+ *
39
+ * @param {Vector3} x The point coordinates
40
+ * @returns The id of the closest point or -1 if not found
41
+ */
42
+ findClosestPoint(x: Vector3): number;
43
+
44
+ /**
45
+ * Find the closest point within a specified radius.
46
+ *
47
+ * @param {Number} radius The search radius
48
+ * @param {Vector3} x The point coordinates
49
+ * @param {Number} inputDataLength The length of the input data
50
+ * @returns {IFindClosestPointResult} The closest point result
51
+ */
52
+ findClosestPointWithinRadius(
53
+ radius: number,
54
+ x: Vector3,
55
+ inputDataLength?: number
56
+ ): IFindClosestPointResult;
57
+
58
+ /**
59
+ * Free the search structure and reset the locator.
60
+ */
61
+ freeSearchStructure(): void;
62
+
63
+ /**
64
+ * Generate a polydata representation of the point locator.
65
+ *
66
+ * @param {vtkPolyData} polydata The polydata to generate representation for
67
+ * @returns
68
+ */
69
+ generateRepresentation(polydata: vtkPolyData): boolean;
70
+
71
+ /**
72
+ * Get the number of points per bucket.
73
+ *
74
+ * @returns {Number} The number of points per bucket.
75
+ */
76
+ getNumberOfPointsPerBucket(): number;
77
+
78
+ /**
79
+ * Get the points in the specified bucket.
80
+ * @param {Vector3} x The point coordinates
81
+ * @returns {Number[]} The points in the bucket
82
+ */
83
+ getPointsInBucket(x: Vector3): number[];
84
+
85
+ /**
86
+ * Get the points stored in the point locator.
87
+ *
88
+ * @returns {Nullable<vtkPoints>} The vtkPoints object containing the points.
89
+ */
90
+ getPoints(): Nullable<vtkPoints>;
91
+
92
+ /**
93
+ * Initialize point insertion.
94
+ *
95
+ * @param {vtkPoints} points The points to insert
96
+ * @param {Bounds} bounds The bounds for the points
97
+ * @param {Number} estNumPts Estimated number of points for insertion
98
+ */
99
+ initPointInsertion(
100
+ points: vtkPoints,
101
+ bounds: Bounds,
102
+ estNumPts?: number
103
+ ): boolean;
104
+
105
+ /**
106
+ * Insert a point into the point locator.
107
+ * If the point is already present, it returns the existing ID.
108
+ * Otherwise, it inserts the point and returns a new ID.
109
+ *
110
+ * @param {Number} ptId The index of the point to insert.
111
+ * @param {Vector3} x The point to insert.
112
+ * @returns {IInsertPointResult} An object indicating if the point was inserted and its ID.
113
+ */
114
+ insertPoint(ptId: number, x: Vector3): IInsertPointResult;
115
+
116
+ /**
117
+ * Insert a point into the point locator.
118
+ * If the point is already present, it returns the existing ID.
119
+ * Otherwise, it inserts the point and returns a new ID.
120
+ *
121
+ * @param {Vector3} x The point to insert.
122
+ * @returns {IInsertPointResult} An object indicating if the point was inserted and its ID.
123
+ */
124
+ insertNextPoint(x: Vector3): IInsertPointResult;
125
+
126
+ /**
127
+ * Insert a point into the point locator.
128
+ * If the point is already present, it returns the existing ID.
129
+ * Otherwise, it inserts the point and returns a new ID.
130
+ *
131
+ * @param {Vector3} x The point to insert.
132
+ * @returns {IInsertPointResult} An object indicating if the point was inserted and its ID.
133
+ */
134
+ insertUniquePoint(x: Vector3): IInsertPointResult;
135
+
136
+ /**
137
+ * Check if a point is already inserted in the point locator.
138
+ *
139
+ * @param {Vector3} x The point to check.
140
+ * @returns {Number} The ID of the point if it exists, otherwise -1.
141
+ */
142
+ isInsertedPoint(x: Vector3): number;
143
+
144
+ /**
145
+ * Set the divisions of the point locator.
146
+ * @param {Vector3} divisions The number of divisions in each dimension.
147
+ * @returns {Boolean} True if the divisions were set successfully, false otherwise.
148
+ */
149
+ setDivisions(divisions: Vector3): boolean;
150
+
151
+ /**
152
+ * Set the divisions of the point locator.
153
+ * @param {Number} x The number of divisions in the x dimension.
154
+ * @param {Number} y The number of divisions in the y dimension.
155
+ * @param {Number} z The number of divisions in the z dimension.
156
+ * @returns {Boolean} True if the divisions were set successfully, false otherwise.
157
+ */
158
+ setDivisions(x: number, y: number, z: number): boolean;
159
+
160
+ /**
161
+ * Set the number of points per bucket.
162
+ *
163
+ * @param {Number} numberOfPointsPerBucket The number of points per bucket.
164
+ */
165
+ setNumberOfPointsPerBucket(numberOfPointsPerBucket: number): boolean;
166
+
167
+ /**
168
+ * Set the points for this point locator.
169
+ * This is typically used to initialize the locator with a set of points.
170
+ *
171
+ * @param {vtkPoints} points The vtkPoints object containing the points.
172
+ */
173
+ setPoints(points: vtkPoints): boolean;
174
+ }
175
+
176
+ /**
177
+ * Method use to decorate a given object (publicAPI+model) with vtkPointLocator characteristics.
178
+ *
179
+ * @param publicAPI object on which methods will be bounds (public)
180
+ * @param model object on which data structure will be bounds (protected)
181
+ * @param {object} [initialValues] (default: {})
182
+ */
183
+ export function extend(
184
+ publicAPI: object,
185
+ model: object,
186
+ initialValues?: IPointLocatorInitialValues
187
+ ): void;
188
+
189
+ // ----------------------------------------------------------------------------
190
+
191
+ /**
192
+ * Method use to create a new instance of vtkPointLocator
193
+ * @param {IPointLocatorInitialValues} [initialValues] for pre-setting some of its content
194
+ */
195
+ export function newInstance(
196
+ initialValues?: IPointLocatorInitialValues
197
+ ): vtkPointLocator;
198
+
199
+ /**
200
+ * vtkPointLocator is a spatial search object to quickly locate points in 3D.
201
+ *
202
+ * vtkPointLocator works by dividing a specified region of space into a regular
203
+ * array of "rectangular" buckets, and then keeping a list of points that lie in
204
+ * each bucket. Typical operation involves giving a position in 3D and finding
205
+ * the closest point.
206
+ *
207
+ * vtkPointLocator has two distinct methods of interaction. In the first method,
208
+ * you supply it with a dataset, and it operates on the points in the dataset.
209
+ * In the second method, you supply it with an array of points, and the object
210
+ * operates on the array.
211
+ */
212
+ export declare const vtkPointLocator: {
213
+ newInstance: typeof newInstance;
214
+ extend: typeof extend;
215
+ };
216
+
217
+ export default vtkPointLocator;