@kitware/vtk.js 32.0.1 → 32.1.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,5 +1,6 @@
1
1
  import { vtkObject } from './../../interfaces';
2
2
  import { Bounds, Vector3 } from './../../types';
3
+ import vtkImplicitFunction from './ImplicitFunction';
3
4
 
4
5
  export interface IBoxInitialValues {
5
6
  bbox?: Bounds;
@@ -12,7 +13,7 @@ export interface IBoxIntersections {
12
13
  x2: Vector3;
13
14
  }
14
15
 
15
- export interface vtkBox extends vtkObject {
16
+ export interface vtkBox extends vtkImplicitFunction {
16
17
  /**
17
18
  * Add the bounds for the box.
18
19
  * @param {Bounds} bounds
@@ -1,5 +1,6 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import vtkBoundingBox from './BoundingBox.js';
3
+ import vtkImplicitFunction from './ImplicitFunction.js';
3
4
 
4
5
  // ----------------------------------------------------------------------------
5
6
  // Global methods
@@ -202,7 +203,7 @@ function extend(publicAPI, model) {
202
203
  Object.assign(model, DEFAULT_VALUES, initialValues);
203
204
 
204
205
  // Object methods
205
- macro.obj(publicAPI, model);
206
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
206
207
  vtkBox(publicAPI, model);
207
208
  }
208
209
 
@@ -13,7 +13,7 @@ export interface vtkCone extends vtkObject {
13
13
  * Given the point x evaluate the cone equation.
14
14
  * @param {Vector3} x The point coordinate.
15
15
  */
16
- evaluateFunction(x: Vector3): number[];
16
+ evaluateFunction(x: Vector3): number;
17
17
 
18
18
  /**
19
19
  * Given the point x evaluate the equation for the cone gradient.
@@ -54,11 +54,7 @@ export function newInstance(initialValues?: IConeInitialValues): vtkCone;
54
54
 
55
55
  /**
56
56
  * vtkCone computes the implicit function and/or gradient for a cone. vtkCone is
57
- * a concrete implementation of vtkImplicitFunction. TODO: Currently the cone's
58
- * axis of rotation is along the x-axis with the apex at the origin. To
59
- * transform this to a different location requires the application of a
60
- * transformation matrix. This can be performed by supporting transforms at the
61
- * implicit function level, and should be added.
57
+ * a concrete implementation of vtkImplicitFunction.
62
58
  */
63
59
  export declare const vtkCone: {
64
60
  newInstance: typeof newInstance;
@@ -1,5 +1,6 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import { r as radiansFromDegrees } from '../Core/Math/index.js';
3
+ import vtkImplicitFunction from './ImplicitFunction.js';
3
4
 
4
5
  // ----------------------------------------------------------------------------
5
6
  // Global methods
@@ -42,7 +43,7 @@ function extend(publicAPI, model) {
42
43
  Object.assign(model, DEFAULT_VALUES, initialValues);
43
44
 
44
45
  // Object methods
45
- macro.obj(publicAPI, model);
46
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
46
47
  macro.setGet(publicAPI, model, ['angle']);
47
48
  vtkCone(publicAPI, model);
48
49
  }
@@ -1,5 +1,6 @@
1
1
  import { vtkObject } from './../../interfaces';
2
2
  import { Vector3 } from './../../types';
3
+ import vtkImplicitFunction from './ImplicitFunction';
3
4
 
4
5
  /**
5
6
  *
@@ -10,13 +11,13 @@ export interface ICylinderInitialValues {
10
11
  axis?: number[];
11
12
  }
12
13
 
13
- export interface vtkCylinder extends vtkObject {
14
+ export interface vtkCylinder extends vtkImplicitFunction {
14
15
  /**
15
16
  * Given the point xyz (three floating value) evaluate the cylinder
16
17
  * equation.
17
18
  * @param {Vector3} xyz The point coordinate.
18
19
  */
19
- evaluateFunction(xyz: Vector3): number[];
20
+ evaluateFunction(xyz: Vector3): number;
20
21
 
21
22
  /**
22
23
  * Given the point xyz (three floating values) evaluate the equation for the
@@ -1,5 +1,6 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import { d as dot } from '../Core/Math/index.js';
3
+ import vtkImplicitFunction from './ImplicitFunction.js';
3
4
 
4
5
  // ----------------------------------------------------------------------------
5
6
  // Global methods
@@ -60,7 +61,7 @@ function extend(publicAPI, model) {
60
61
  Object.assign(model, DEFAULT_VALUES, initialValues);
61
62
 
62
63
  // Object methods
63
- macro.obj(publicAPI, model);
64
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
64
65
  macro.setGet(publicAPI, model, ['radius']);
65
66
  macro.setGetArray(publicAPI, model, ['center', 'axis'], 3);
66
67
  vtkCylinder(publicAPI, model);
@@ -27,7 +27,6 @@ export interface vtkImageData extends vtkDataSet {
27
27
  * `voxelFunc(index, bounds)` is an optional function that is called with
28
28
  * the `[i,j,k]` index and index `bounds`, expected to return truthy if the
29
29
  * data point should be counted in the histogram, and falsey if not.
30
- * @param {Bounds} worldBounds The bounds of the world.
31
30
  * @param [voxelFunc]
32
31
  */
33
32
  computeHistogram(worldBounds: Bounds, voxelFunc?: any): IComputeHistogram;
@@ -197,7 +197,7 @@ function vtkImageData(publicAPI, model) {
197
197
  publicAPI.computeTransforms();
198
198
  publicAPI.getCenter = () => vtkBoundingBox.getCenter(publicAPI.getBounds());
199
199
  publicAPI.computeHistogram = function (worldBounds) {
200
- let voxelFunc = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
200
+ let voxelFunction = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
201
201
  const bounds = [0, 0, 0, 0, 0, 0];
202
202
  publicAPI.worldToIndexBounds(worldBounds, bounds);
203
203
  const point1 = [0, 0, 0];
@@ -220,7 +220,7 @@ function vtkImageData(publicAPI, model) {
220
220
  for (let y = point1[1]; y <= point2[1]; y++) {
221
221
  let index = point1[0] + y * yStride + z * zStride;
222
222
  for (let x = point1[0]; x <= point2[0]; x++) {
223
- if (!voxelFunc || voxelFunc([x, y, z], bounds)) {
223
+ if (!voxelFunction || voxelFunction([x, y, z], bounds)) {
224
224
  const pixel = pixels[index];
225
225
  if (pixel > maximum) maximum = pixel;
226
226
  if (pixel < minimum) minimum = pixel;
@@ -1,5 +1,6 @@
1
1
  import { m as macro } from '../../macros2.js';
2
2
  import Constants from './ImplicitBoolean/Constants.js';
3
+ import vtkImplicitFunction from './ImplicitFunction.js';
3
4
 
4
5
  const {
5
6
  Operation
@@ -64,7 +65,7 @@ function vtkImplicitBoolean(publicAPI, model) {
64
65
  value = Number.MAX_VALUE;
65
66
  for (let i = 0; i < model.functions.length; ++i) {
66
67
  const f = model.functions[i];
67
- const v = f.evaluateFunction(xyz);
68
+ const v = f.functionValue(xyz);
68
69
  if (v < value) {
69
70
  value = v;
70
71
  }
@@ -73,14 +74,14 @@ function vtkImplicitBoolean(publicAPI, model) {
73
74
  value = -Number.MAX_VALUE;
74
75
  for (let i = 0; i < model.functions.length; ++i) {
75
76
  const f = model.functions[i];
76
- const v = f.evaluateFunction(xyz);
77
+ const v = f.functionValue(xyz);
77
78
  if (v > value) {
78
79
  value = v;
79
80
  }
80
81
  }
81
82
  } else {
82
83
  const firstF = model.functions[0];
83
- value = firstF.evaluateFunction(xyz);
84
+ value = firstF.functionValue(xyz);
84
85
  for (let i = 1; i < model.functions.length; ++i) {
85
86
  const f = model.functions[i];
86
87
  const v = -1.0 * f.evaluateFunction(xyz);
@@ -117,7 +118,7 @@ function extend(publicAPI, model) {
117
118
  Object.assign(model, DEFAULT_VALUES, initialValues);
118
119
 
119
120
  // Object methods
120
- macro.obj(publicAPI, model);
121
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
121
122
  macro.setGet(publicAPI, model, ['operation']);
122
123
  vtkImplicitBoolean(publicAPI, model);
123
124
  }
@@ -0,0 +1,68 @@
1
+ import { vtkObject } from './../../interfaces';
2
+ import { Vector3 } from './../../types';
3
+ import { vtkTransform } from './../Transform/Transform';
4
+
5
+ /**
6
+ *
7
+ */
8
+ export interface IImplicitFunctionInitialValues {
9
+ transform?: vtkTransform;
10
+ }
11
+
12
+ export interface vtkImplicitFunction extends vtkObject {
13
+ /**
14
+ * Given the point x evaluate the function.
15
+ * @see functionValue
16
+ * @param {Vector3} x The point coordinate.
17
+ */
18
+ evaluateFunction(x: Vector3): number;
19
+
20
+ /**
21
+ * Evaluate function at position x-y-z and return value. Point x[3] is
22
+ * transformed through transform (if provided).
23
+ * @see evaluateFunction
24
+ * @param {Vector3} x The point coordinate.
25
+ */
26
+ functionValue(x: Vector3): number;
27
+
28
+ /**
29
+ * Get the transform. undefined by default
30
+ */
31
+ getTransform(): vtkTransform;
32
+
33
+ /**
34
+ * Set the transform to apply on all points.
35
+ * @param {vtkTransform} transform The transform to apply
36
+ */
37
+ setTransform(transform: vtkTransform): boolean;
38
+ }
39
+
40
+ /**
41
+ * Method used to decorate a given object (publicAPI+model) with vtkImplicitFunction characteristics.
42
+ *
43
+ * @param publicAPI object on which methods will be bounds (public)
44
+ * @param model object on which data structure will be bounds (protected)
45
+ * @param {IImplicitFunctionInitialValues} [initialValues] (default: {})
46
+ */
47
+ export function extend(
48
+ publicAPI: object,
49
+ model: object,
50
+ initialValues?: IImplicitFunctionInitialValues
51
+ ): void;
52
+
53
+ /**
54
+ * Method used to create a new instance of vtkImplicitFunction.
55
+ * @param {IImplicitFunctionInitialValues} [initialValues] for pre-setting some of its content
56
+ */
57
+ export function newInstance(
58
+ initialValues?: IImplicitFunctionInitialValues
59
+ ): vtkImplicitFunction;
60
+
61
+ /**
62
+ * vtkImplicitFunction computes the implicit function and/or gradient for a function.
63
+ */
64
+ export declare const vtkImplicitFunction: {
65
+ newInstance: typeof newInstance;
66
+ extend: typeof extend;
67
+ };
68
+ export default vtkImplicitFunction;
@@ -0,0 +1,60 @@
1
+ import { m as macro } from '../../macros2.js';
2
+
3
+ // ----------------------------------------------------------------------------
4
+ // Global methods
5
+ // ----------------------------------------------------------------------------
6
+
7
+ // ----------------------------------------------------------------------------
8
+ // Static API
9
+ // ----------------------------------------------------------------------------
10
+
11
+ // ----------------------------------------------------------------------------
12
+ // vtkImplicitFunction methods
13
+ // ----------------------------------------------------------------------------
14
+
15
+ function vtkImplicitFunction(publicAPI, model) {
16
+ model.classHierarchy.push('vtkImplicitFunction');
17
+ publicAPI.functionValue = xyz => {
18
+ if (!model.transform) {
19
+ return publicAPI.evaluateFunction(xyz);
20
+ }
21
+ const transformedXYZ = [];
22
+ model.transform.transformPoint(xyz, transformedXYZ);
23
+ return publicAPI.evaluateFunction(transformedXYZ);
24
+ };
25
+ publicAPI.evaluateFunction = _xyz => {
26
+ macro.vtkErrorMacro('not implemented');
27
+ };
28
+ }
29
+
30
+ // ----------------------------------------------------------------------------
31
+ // Object factory
32
+ // ----------------------------------------------------------------------------
33
+ const DEFAULT_VALUES = {
34
+ // transform : null
35
+ };
36
+
37
+ // ----------------------------------------------------------------------------
38
+
39
+ function extend(publicAPI, model) {
40
+ let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
41
+ Object.assign(model, DEFAULT_VALUES, initialValues);
42
+
43
+ // Object methods
44
+ macro.obj(publicAPI, model);
45
+ macro.setGet(publicAPI, model, ['transform']);
46
+ vtkImplicitFunction(publicAPI, model);
47
+ }
48
+
49
+ // ----------------------------------------------------------------------------
50
+
51
+ const newInstance = macro.newInstance(extend, 'vtkImplicitFunction');
52
+
53
+ // ----------------------------------------------------------------------------
54
+
55
+ var vtkImplicitFunction$1 = {
56
+ newInstance,
57
+ extend
58
+ };
59
+
60
+ export { vtkImplicitFunction$1 as default, extend, newInstance };
@@ -1,5 +1,6 @@
1
1
  import { vtkObject } from './../../interfaces';
2
2
  import { Vector3 } from './../../types';
3
+ import vtkImplicitFunction from './ImplicitFunction';
3
4
 
4
5
  /**
5
6
  *
@@ -16,7 +17,7 @@ interface IIntersectWithLine {
16
17
  x: Vector3;
17
18
  }
18
19
 
19
- export interface vtkPlane extends vtkObject {
20
+ export interface vtkPlane extends vtkImplicitFunction {
20
21
  /**
21
22
  * Get the distance of a point x to a plane defined by n (x-p0) = 0.
22
23
  * The normal n must be magnitude = 1.
@@ -1,5 +1,6 @@
1
1
  import { s as subtract, d as dot, j as cross, k as add } from '../Core/Math/index.js';
2
2
  import { m as macro } from '../../macros2.js';
3
+ import vtkImplicitFunction from './ImplicitFunction.js';
3
4
 
4
5
  const PLANE_TOLERANCE = 1.0e-6;
5
6
  const COINCIDE = 'coincide';
@@ -235,7 +236,7 @@ function extend(publicAPI, model) {
235
236
  Object.assign(model, DEFAULT_VALUES, initialValues);
236
237
 
237
238
  // Object methods
238
- macro.obj(publicAPI, model);
239
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
239
240
  macro.setGetArray(publicAPI, model, ['normal', 'origin'], 3);
240
241
  vtkPlane(publicAPI, model);
241
242
  }
@@ -1,18 +1,18 @@
1
- import { vtkObject } from './../../interfaces';
2
- import { Bounds, Vector3 } from './../../types';
1
+ import { Vector3 } from './../../types';
2
+ import vtkImplicitFunction from './ImplicitFunction';
3
3
 
4
4
  export interface ISphereInitialValues {
5
- radius?: number;
5
+ radius?: number | Vector3;
6
6
  center?: Vector3;
7
7
  }
8
8
 
9
- export interface vtkSphere extends vtkObject {
9
+ export interface vtkSphere extends vtkImplicitFunction {
10
10
  /**
11
11
  * Given the point xyz (three floating value) evaluate the sphere
12
12
  * equation.
13
13
  * @param {Vector3} xyz The point coordinate.
14
14
  */
15
- evaluateFunction(xyz: Vector3): number[];
15
+ evaluateFunction(xyz: Vector3): number;
16
16
 
17
17
  /**
18
18
  * Given the point xyz (three floating values) evaluate the equation for the
@@ -34,7 +34,7 @@ export interface vtkSphere extends vtkObject {
34
34
  /**
35
35
  * Get the radius of the sphere.
36
36
  */
37
- getRadius(): number;
37
+ getRadius(): number | Vector3;
38
38
 
39
39
  /**
40
40
  * Set the center of the sphere.
@@ -57,10 +57,11 @@ export interface vtkSphere extends vtkObject {
57
57
  setCenterFrom(center: Vector3): boolean;
58
58
 
59
59
  /**
60
- * Set the radius of the sphere.
61
- * @param {Number} radius The radius of the sphere.
60
+ * Set the radius of the sphere. Radius must be > 0.
61
+ * It can also be an array of 3 positive values for ellipsoids
62
+ * @param {Number|Vector3} radius The radius of the sphere.
62
63
  */
63
- setRadius(radius: number): boolean;
64
+ setRadius(radius: number | Vector3): boolean;
64
65
  }
65
66
 
66
67
  /**
@@ -89,13 +90,6 @@ export function newInstance(initialValues?: ISphereInitialValues): vtkSphere;
89
90
  */
90
91
  declare function evaluate(radius: number, center: Vector3, x: Vector3): number;
91
92
 
92
- /**
93
- *
94
- * @param {Vector3} point
95
- * @param {Bounds} bounds
96
- */
97
- declare function isPointIn3DEllipse(point: Vector3, bounds: Bounds): boolean;
98
-
99
93
  /**
100
94
  * vtkSphere provides methods for creating a 1D cubic spline object from given
101
95
  * parameters, and allows for the calculation of the spline value and derivative
@@ -105,6 +99,5 @@ export declare const vtkSphere: {
105
99
  newInstance: typeof newInstance;
106
100
  extend: typeof extend;
107
101
  evaluate: typeof evaluate;
108
- isPointIn3DEllipse: typeof isPointIn3DEllipse;
109
102
  };
110
103
  export default vtkSphere;
@@ -1,21 +1,17 @@
1
1
  import { m as macro } from '../../macros2.js';
2
- import vtkBoundingBox from './BoundingBox.js';
3
-
4
- const VTK_SMALL_NUMBER = 1e-12;
2
+ import vtkImplicitFunction from './ImplicitFunction.js';
5
3
 
6
4
  // ----------------------------------------------------------------------------
7
5
  // Global methods
8
6
  // ----------------------------------------------------------------------------
9
7
 
10
- function evaluate(radius, center, x) {
11
- return (x[0] - center[0]) * (x[0] - center[0]) + (x[1] - center[1]) * (x[1] - center[1]) + (x[2] - center[2]) * (x[2] - center[2]) - radius * radius;
12
- }
13
- function isPointIn3DEllipse(point, bounds) {
14
- const center = vtkBoundingBox.getCenter(bounds);
15
- let scale3 = vtkBoundingBox.computeScale3(bounds);
16
- scale3 = scale3.map(x => Math.max(Math.abs(x), VTK_SMALL_NUMBER));
17
- const radius = [(point[0] - center[0]) / scale3[0], (point[1] - center[1]) / scale3[1], (point[2] - center[2]) / scale3[2]];
18
- return radius[0] * radius[0] + radius[1] * radius[1] + radius[2] * radius[2] <= 1;
8
+ function evaluate(radius, center, xyz) {
9
+ if (!Array.isArray(radius)) {
10
+ const retVal = (xyz[0] - center[0]) * (xyz[0] - center[0]) + (xyz[1] - center[1]) * (xyz[1] - center[1]) + (xyz[2] - center[2]) * (xyz[2] - center[2]) - radius * radius;
11
+ return retVal;
12
+ }
13
+ const r = [(xyz[0] - center[0]) / radius[0], (xyz[1] - center[1]) / radius[1], (xyz[2] - center[2]) / radius[2]];
14
+ return r[0] * r[0] + r[1] * r[1] + r[2] * r[2] - 1;
19
15
  }
20
16
 
21
17
  // ----------------------------------------------------------------------------
@@ -23,8 +19,7 @@ function isPointIn3DEllipse(point, bounds) {
23
19
  // ----------------------------------------------------------------------------
24
20
 
25
21
  const STATIC = {
26
- evaluate,
27
- isPointIn3DEllipse
22
+ evaluate
28
23
  };
29
24
 
30
25
  // ----------------------------------------------------------------------------
@@ -34,10 +29,7 @@ const STATIC = {
34
29
  function vtkSphere(publicAPI, model) {
35
30
  // Set our className
36
31
  model.classHierarchy.push('vtkSphere');
37
- publicAPI.evaluateFunction = xyz => {
38
- const retVal = (xyz[0] - model.center[0]) * (xyz[0] - model.center[0]) + (xyz[1] - model.center[1]) * (xyz[1] - model.center[1]) + (xyz[2] - model.center[2]) * (xyz[2] - model.center[2]) - model.radius * model.radius;
39
- return retVal;
40
- };
32
+ publicAPI.evaluateFunction = xyz => evaluate(model.radius, model.center, xyz);
41
33
  publicAPI.evaluateGradient = xyz => {
42
34
  const retVal = [2.0 - (xyz[0] - model.center[0]), 2.0 - (xyz[1] - model.center[1]), 2.0 - (xyz[2] - model.center[2])];
43
35
  return retVal;
@@ -60,7 +52,7 @@ function extend(publicAPI, model) {
60
52
  Object.assign(model, DEFAULT_VALUES, initialValues);
61
53
 
62
54
  // Object methods
63
- macro.obj(publicAPI, model);
55
+ vtkImplicitFunction.extend(publicAPI, model, initialValues);
64
56
  macro.setGet(publicAPI, model, ['radius']);
65
57
  macro.setGetArray(publicAPI, model, ['center'], 3);
66
58
  vtkSphere(publicAPI, model);