@kitware/vtk.js 34.10.0 → 34.11.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.
- package/Common/Core/DataArray.js +2 -1
- package/Common/Core/Points.d.ts +19 -1
- package/Common/Core/Points.js +35 -20
- package/Common/DataModel/AbstractPointLocator.d.ts +2 -2
- package/Common/DataModel/BoundingBox.d.ts +60 -7
- package/Common/DataModel/BoundingBox.js +190 -3
- package/Common/DataModel/Cell.js +4 -34
- package/Common/DataModel/DataSet.d.ts +7 -0
- package/Common/DataModel/DataSet.js +6 -0
- package/Common/DataModel/DataSetAttributes/FieldData.d.ts +6 -2
- package/Common/DataModel/DataSetAttributes.d.ts +2 -1
- package/Common/DataModel/ImageData.d.ts +7 -0
- package/Common/DataModel/ImageData.js +11 -0
- package/Common/DataModel/Locator.d.ts +97 -5
- package/Common/DataModel/MergePoints.d.ts +64 -0
- package/Common/DataModel/MergePoints.js +130 -0
- package/Common/DataModel/PointLocator.d.ts +217 -0
- package/Common/DataModel/PointLocator.js +751 -0
- package/Common/DataModel/PointSet.d.ts +6 -0
- package/Common/DataModel/PointSet.js +10 -0
- package/Common/DataModel/PolyData.d.ts +6 -0
- package/Common/DataModel/PolyData.js +7 -0
- package/Filters/Core/Cutter.js +1 -1
- package/Filters/Core/PolyDataNormals.js +1 -1
- package/Filters/Core/ThresholdPoints.js +1 -2
- package/Filters/General/AppendPolyData.js +1 -1
- package/Filters/General/Calculator.js +1 -1
- package/Filters/General/ClipClosedSurface.js +2 -2
- package/Filters/General/ClosedPolyLineToSurfaceFilter.js +1 -1
- package/Filters/General/ContourLoopExtraction.js +2 -4
- package/Filters/General/ContourTriangulator.js +1 -2
- package/Filters/General/ImageCropFilter.js +7 -10
- package/Filters/General/ImageMarchingCubes.js +1 -1
- package/Filters/General/ImageMarchingSquares.js +1 -1
- package/Filters/General/ImageOutlineFilter.js +2 -1
- package/Filters/General/ImageSliceFilter.js +2 -1
- package/Filters/General/ImageStreamline.js +1 -1
- package/Filters/General/LineFilter.js +1 -1
- package/Filters/General/MoleculeToRepresentation.js +2 -2
- package/Filters/General/OutlineFilter.js +1 -1
- package/Filters/General/ScalarToRGBA.js +2 -1
- package/Filters/General/ShrinkPolyData.js +1 -1
- package/Filters/General/TransformPolyDataFilter.js +1 -1
- package/Filters/General/TriangleFilter.js +1 -1
- package/Filters/General/TubeFilter.js +1 -2
- package/Filters/General/WarpScalar.js +1 -1
- package/Filters/General/WindowedSincPolyDataFilter.js +1 -1
- package/Filters/Sources/ArcSource.js +1 -1
- package/Filters/Sources/Arrow2DSource.js +6 -9
- package/Filters/Sources/ArrowSource.js +2 -8
- package/Filters/Sources/CircleSource.js +3 -10
- package/Filters/Sources/ConcentricCylinderSource.js +5 -8
- package/Filters/Sources/ConeSource.js +3 -10
- package/Filters/Sources/CubeSource.js +3 -9
- package/Filters/Sources/Cursor3D.js +1 -4
- package/Filters/Sources/CylinderSource.js +3 -10
- package/Filters/Sources/DiskSource.js +1 -5
- package/Filters/Sources/EllipseArcSource.js +1 -1
- package/Filters/Sources/FrustumSource.d.ts +111 -0
- package/Filters/Sources/FrustumSource.js +248 -0
- package/Filters/Sources/ImageGridSource.js +0 -3
- package/Filters/Sources/LineSource.js +1 -4
- package/Filters/Sources/PlaneSource.js +1 -4
- package/Filters/Sources/PlatonicSolidSource.js +1 -1
- package/Filters/Sources/PointSource.js +1 -4
- package/Filters/Sources/RTAnalyticSource.js +0 -3
- package/Filters/Sources/SLICSource.js +1 -4
- package/Filters/Sources/SphereSource.js +1 -4
- package/Filters/Sources/ViewFinderSource.js +1 -1
- package/Filters/Texture/TextureMapToPlane.js +1 -4
- package/Filters/Texture/TextureMapToSphere.js +1 -4
- package/Imaging/Core/ImageReslice.js +1 -1
- package/Imaging/Hybrid/SampleFunction.js +1 -1
- package/Rendering/Core/VectorText.js +4 -3
- package/Rendering/OpenGL/Glyph3DMapper.js +16 -0
- package/Rendering/OpenGL/glsl/vtkVolumeVS.glsl.js +1 -1
- package/Widgets/Representations/ImplicitPlaneRepresentation.js +1 -1
- package/Widgets/Representations/RectangleContextRepresentation.js +0 -3
- package/Widgets/Representations/SplineContextRepresentation.js +1 -5
- package/index.d.ts +3 -0
- package/macros2.js +1 -1
- package/package.json +1 -1
package/Common/Core/DataArray.js
CHANGED
|
@@ -196,9 +196,10 @@ function vtkDataArray(publicAPI, model) {
|
|
|
196
196
|
return false;
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
//
|
|
199
|
+
// Restore the array to initial state
|
|
200
200
|
publicAPI.initialize = () => {
|
|
201
201
|
publicAPI.resize(0);
|
|
202
|
+
return publicAPI;
|
|
202
203
|
};
|
|
203
204
|
publicAPI.getElementComponentSize = () => model.values.BYTES_PER_ELEMENT;
|
|
204
205
|
|
package/Common/Core/Points.d.ts
CHANGED
|
@@ -17,11 +17,21 @@ export interface vtkPoints extends vtkDataArray {
|
|
|
17
17
|
computeBounds(): Bounds;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Get
|
|
20
|
+
* Get a copy of the bounds of the array.
|
|
21
|
+
* Bounds are [xmin, xmax, ymin, ymax,zmin, zmax].
|
|
22
|
+
* Will recompute the bounds if necessary.
|
|
21
23
|
* @return {Bounds} The bounds for the mapper.
|
|
22
24
|
*/
|
|
23
25
|
getBounds(): Bounds;
|
|
24
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Get a reference to the model bounds of the array.
|
|
29
|
+
* Bounds are [xmin, xmax, ymin, ymax,zmin, zmax].
|
|
30
|
+
* Will recompute the bounds if necessary.
|
|
31
|
+
* @return {Bounds} The bounds for the mapper.
|
|
32
|
+
*/
|
|
33
|
+
getBoundsByReference(): Bounds;
|
|
34
|
+
|
|
25
35
|
/**
|
|
26
36
|
* Get the coordinate of a point.
|
|
27
37
|
* @param {Number} idx The index of point.
|
|
@@ -81,6 +91,14 @@ export interface vtkPoints extends vtkDataArray {
|
|
|
81
91
|
* @returns {Number} Index of the inserted point.
|
|
82
92
|
*/
|
|
83
93
|
insertNextPoint(x: number, y: number, z: number): number;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Insert the [x,y,z] coordinates of a point at the given index.
|
|
97
|
+
* @param {Number} ptId The index of point.
|
|
98
|
+
* @param {Number[]} point The [x, y, z] coordinates of the point.
|
|
99
|
+
* @returns {Number} The index of the inserted point.
|
|
100
|
+
*/
|
|
101
|
+
insertPoint(ptId: number, point: number[]): number;
|
|
84
102
|
}
|
|
85
103
|
|
|
86
104
|
/**
|
package/Common/Core/Points.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { m as macro } from '../../macros2.js';
|
|
2
2
|
import vtkDataArray from './DataArray.js';
|
|
3
3
|
import { VtkDataTypes } from './DataArray/Constants.js';
|
|
4
|
+
import { u as uninitializeBounds } from './Math/index.js';
|
|
4
5
|
|
|
5
6
|
const {
|
|
6
7
|
vtkErrorMacro
|
|
7
8
|
} = macro;
|
|
8
|
-
const INVALID_BOUNDS = [1, -1, 1, -1, 1, -1];
|
|
9
|
-
|
|
10
9
|
// ----------------------------------------------------------------------------
|
|
11
10
|
// vtkPoints methods
|
|
12
11
|
// ----------------------------------------------------------------------------
|
|
13
12
|
|
|
14
13
|
function vtkPoints(publicAPI, model) {
|
|
14
|
+
// Keep track of modified time for bounds computation
|
|
15
|
+
let boundMTime = 0;
|
|
16
|
+
|
|
15
17
|
// Set our className
|
|
16
18
|
model.classHierarchy.push('vtkPoints');
|
|
17
19
|
|
|
@@ -35,7 +37,24 @@ function vtkPoints(publicAPI, model) {
|
|
|
35
37
|
publicAPI.getPoint = publicAPI.getTuple;
|
|
36
38
|
publicAPI.findPoint = publicAPI.findTuple;
|
|
37
39
|
publicAPI.insertNextPoint = (x, y, z) => publicAPI.insertNextTuple([x, y, z]);
|
|
40
|
+
publicAPI.insertPoint = (ptId, point) => publicAPI.insertTuple(ptId, point);
|
|
41
|
+
const superGetBounds = publicAPI.getBounds;
|
|
38
42
|
publicAPI.getBounds = () => {
|
|
43
|
+
if (boundMTime < model.mtime) {
|
|
44
|
+
publicAPI.computeBounds();
|
|
45
|
+
}
|
|
46
|
+
return superGetBounds();
|
|
47
|
+
};
|
|
48
|
+
const superGetBoundsByReference = publicAPI.getBoundsByReference;
|
|
49
|
+
publicAPI.getBoundsByReference = () => {
|
|
50
|
+
if (boundMTime < model.mtime) {
|
|
51
|
+
publicAPI.computeBounds();
|
|
52
|
+
}
|
|
53
|
+
return superGetBoundsByReference();
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// Trigger the computation of bounds
|
|
57
|
+
publicAPI.computeBounds = () => {
|
|
39
58
|
if (publicAPI.getNumberOfComponents() === 3) {
|
|
40
59
|
const xRange = publicAPI.getRange(0);
|
|
41
60
|
model.bounds[0] = xRange[0];
|
|
@@ -46,27 +65,22 @@ function vtkPoints(publicAPI, model) {
|
|
|
46
65
|
const zRange = publicAPI.getRange(2);
|
|
47
66
|
model.bounds[4] = zRange[0];
|
|
48
67
|
model.bounds[5] = zRange[1];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
} else if (publicAPI.getNumberOfComponents() === 2) {
|
|
69
|
+
const xRange = publicAPI.getRange(0);
|
|
70
|
+
model.bounds[0] = xRange[0];
|
|
71
|
+
model.bounds[1] = xRange[1];
|
|
72
|
+
const yRange = publicAPI.getRange(1);
|
|
73
|
+
model.bounds[2] = yRange[0];
|
|
74
|
+
model.bounds[3] = yRange[1];
|
|
75
|
+
model.bounds[4] = 0;
|
|
76
|
+
model.bounds[5] = 0;
|
|
77
|
+
} else {
|
|
78
|
+
vtkErrorMacro(`getBounds called on an array with components of ${publicAPI.getNumberOfComponents()}`);
|
|
79
|
+
uninitializeBounds(model.bounds);
|
|
55
80
|
}
|
|
56
|
-
|
|
57
|
-
model.bounds[0] = xRange[0];
|
|
58
|
-
model.bounds[1] = xRange[1];
|
|
59
|
-
const yRange = publicAPI.getRange(1);
|
|
60
|
-
model.bounds[2] = yRange[0];
|
|
61
|
-
model.bounds[3] = yRange[1];
|
|
62
|
-
model.bounds[4] = 0;
|
|
63
|
-
model.bounds[5] = 0;
|
|
64
|
-
return model.bounds;
|
|
81
|
+
boundMTime = macro.getCurrentGlobalMTime();
|
|
65
82
|
};
|
|
66
83
|
|
|
67
|
-
// Trigger the computation of bounds
|
|
68
|
-
publicAPI.computeBounds = publicAPI.getBounds;
|
|
69
|
-
|
|
70
84
|
// Initialize
|
|
71
85
|
publicAPI.setNumberOfComponents(model.numberOfComponents < 2 ? 3 : model.numberOfComponents);
|
|
72
86
|
}
|
|
@@ -88,6 +102,7 @@ function extend(publicAPI, model) {
|
|
|
88
102
|
let initialValues = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
89
103
|
Object.assign(model, DEFAULT_VALUES, initialValues);
|
|
90
104
|
vtkDataArray.extend(publicAPI, model, initialValues);
|
|
105
|
+
macro.getArray(publicAPI, model, ['bounds'], 6);
|
|
91
106
|
vtkPoints(publicAPI, model);
|
|
92
107
|
}
|
|
93
108
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { vtkObject } from './../../interfaces';
|
|
2
2
|
import { Bounds } from './../../types';
|
|
3
|
-
import { ILocatorInitialValues } from './Locator';
|
|
3
|
+
import vtkLocator, { ILocatorInitialValues } from './Locator';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
*
|
|
@@ -11,7 +11,7 @@ export interface IAbstractPointLocatorInitialValues
|
|
|
11
11
|
numberOfBuckets: number;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export interface vtkAbstractPointLocator extends
|
|
14
|
+
export interface vtkAbstractPointLocator extends vtkLocator {
|
|
15
15
|
/**
|
|
16
16
|
* Set the bounds of this object.
|
|
17
17
|
* @param {Bounds} input
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { mat4 } from 'gl-matrix';
|
|
2
2
|
import { Bounds, Vector2, Vector3 } from './../../types';
|
|
3
3
|
import vtkPoints from './../Core/Points';
|
|
4
|
+
import { Nullable } from './../../types';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Tests whether two bounds equal.
|
|
@@ -176,10 +177,16 @@ export function getZRange(bounds: Bounds): Vector2;
|
|
|
176
177
|
export function getMaxLength(bounds: Bounds): number;
|
|
177
178
|
|
|
178
179
|
/**
|
|
179
|
-
* Gets the diagonal of the bounding box.
|
|
180
|
+
* Gets the diagonal length of the bounding box.
|
|
180
181
|
* @param {Bounds} bounds
|
|
181
182
|
*/
|
|
182
|
-
export function getDiagonalLength(bounds: Bounds): number
|
|
183
|
+
export function getDiagonalLength(bounds: Bounds): Nullable<number>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Gets the squared diagonal length of the bounding box.
|
|
187
|
+
* @param {Bounds} bounds
|
|
188
|
+
*/
|
|
189
|
+
export function getDiagonalLength2(bounds: Bounds): Nullable<number>;
|
|
183
190
|
|
|
184
191
|
/**
|
|
185
192
|
* Gets the min point.
|
|
@@ -325,6 +332,37 @@ export function cutWithPlane(
|
|
|
325
332
|
normal: Vector3
|
|
326
333
|
): boolean;
|
|
327
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Clamp the divisions to ensure the total number doesn't exceed targetBins
|
|
337
|
+
* @param {Number} targetBins - Maximum number of bins allowed
|
|
338
|
+
* @param {Number[]} divs - Divisions array to adjust [divX, divY, divZ]
|
|
339
|
+
*/
|
|
340
|
+
export function clampDivisions(targetBins: number, divs: number[]): void;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Compute the number of divisions given the current bounding box and a
|
|
344
|
+
* target number of buckets/bins. Handles degenerate bounding boxes properly.
|
|
345
|
+
* @param {Bounds} bounds - The bounding box
|
|
346
|
+
* @param {Number} totalBins - Target number of bins
|
|
347
|
+
* @param {Number[]} divs - Output array to store divisions [divX, divY, divZ]
|
|
348
|
+
* @param {Bounds} [adjustedBounds] - Output array to store adjusted bounds if needed
|
|
349
|
+
* @returns {Number} The actual total number of bins
|
|
350
|
+
*/
|
|
351
|
+
export function computeDivisions(
|
|
352
|
+
bounds: Bounds,
|
|
353
|
+
totalBins: number,
|
|
354
|
+
divs: number[],
|
|
355
|
+
adjustedBounds?: Bounds
|
|
356
|
+
): number;
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Calculate the squared distance from point x to the specified bounds.
|
|
360
|
+
* @param {Vector3} x The point coordinates
|
|
361
|
+
* @param {Bounds} bounds The bounding box coordinates
|
|
362
|
+
* @returns {Number} The squared distance to the bounds
|
|
363
|
+
*/
|
|
364
|
+
export function distance2ToBounds(x: Vector3, bounds: Bounds): number;
|
|
365
|
+
|
|
328
366
|
declare class BoundingBox {
|
|
329
367
|
getBounds(): Bounds;
|
|
330
368
|
/**
|
|
@@ -409,10 +447,9 @@ declare class BoundingBox {
|
|
|
409
447
|
|
|
410
448
|
/**
|
|
411
449
|
* Inflates a bounding box.
|
|
412
|
-
* @param {
|
|
413
|
-
* @param {number} delta
|
|
450
|
+
* @param {number} [delta] The amount to inflate the bounding box by.
|
|
414
451
|
*/
|
|
415
|
-
inflate(
|
|
452
|
+
inflate(delta?: number): Bounds;
|
|
416
453
|
|
|
417
454
|
/**
|
|
418
455
|
* Scales a bounding box.
|
|
@@ -476,10 +513,16 @@ declare class BoundingBox {
|
|
|
476
513
|
getMaxLength(bounds: Bounds): number;
|
|
477
514
|
|
|
478
515
|
/**
|
|
479
|
-
* Gets the diagonal of the bounding box.
|
|
516
|
+
* Gets the diagonal length of the bounding box.
|
|
480
517
|
* @param {Bounds} bounds
|
|
481
518
|
*/
|
|
482
|
-
getDiagonalLength(bounds: Bounds): number
|
|
519
|
+
getDiagonalLength(bounds: Bounds): Nullable<number>;
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* Gets the squared diagonal length of the bounding box.
|
|
523
|
+
* @param {Bounds} bounds
|
|
524
|
+
*/
|
|
525
|
+
getDiagonalLength2(bounds: Bounds): Nullable<number>;
|
|
483
526
|
|
|
484
527
|
/**
|
|
485
528
|
* Gets the min point.
|
|
@@ -611,6 +654,14 @@ declare class BoundingBox {
|
|
|
611
654
|
* @param {Vector3} normal
|
|
612
655
|
*/
|
|
613
656
|
cutWithPlane(bounds: Bounds, origin: Vector3, normal: Vector3): boolean;
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* Calculate the squared distance from point x to the specified bounds.
|
|
660
|
+
* @param {Vector3} x The point coordinates
|
|
661
|
+
* @param {Bounds} bounds The bounding box coordinates
|
|
662
|
+
* @returns {Number} The squared distance to the bounds
|
|
663
|
+
*/
|
|
664
|
+
distance2ToBounds(x: Vector3, bounds: Bounds): number;
|
|
614
665
|
}
|
|
615
666
|
|
|
616
667
|
export interface IBoundingBoxInitialValues {
|
|
@@ -636,6 +687,7 @@ declare const vtkBoundingBox: {
|
|
|
636
687
|
getLengths: typeof getLengths;
|
|
637
688
|
getMaxLength: typeof getMaxLength;
|
|
638
689
|
getDiagonalLength: typeof getDiagonalLength;
|
|
690
|
+
getDiagonalLength2: typeof getDiagonalLength2;
|
|
639
691
|
getMinPoint: typeof getMinPoint;
|
|
640
692
|
getMaxPoint: typeof getMaxPoint;
|
|
641
693
|
getXRange: typeof getXRange;
|
|
@@ -653,6 +705,7 @@ declare const vtkBoundingBox: {
|
|
|
653
705
|
intersects: typeof intersects;
|
|
654
706
|
containsPoint: typeof containsPoint;
|
|
655
707
|
contains: typeof contains;
|
|
708
|
+
distance2ToBounds: typeof distance2ToBounds;
|
|
656
709
|
INIT_BOUNDS: Bounds;
|
|
657
710
|
};
|
|
658
711
|
|
|
@@ -96,6 +96,10 @@ function setMaxPoint(bounds, x, y, z) {
|
|
|
96
96
|
return xMax !== x || yMax !== y || zMax !== z;
|
|
97
97
|
}
|
|
98
98
|
function inflate(bounds, delta) {
|
|
99
|
+
if (delta == null) {
|
|
100
|
+
// eslint-disable-next-line no-use-before-define
|
|
101
|
+
return minInflate(bounds);
|
|
102
|
+
}
|
|
99
103
|
bounds[0] -= delta;
|
|
100
104
|
bounds[1] += delta;
|
|
101
105
|
bounds[2] -= delta;
|
|
@@ -104,6 +108,33 @@ function inflate(bounds, delta) {
|
|
|
104
108
|
bounds[5] += delta;
|
|
105
109
|
return bounds;
|
|
106
110
|
}
|
|
111
|
+
function minInflate(bounds) {
|
|
112
|
+
const nonZero = [0, 0, 0];
|
|
113
|
+
let maxIdx = -1;
|
|
114
|
+
let max = 0.0;
|
|
115
|
+
let w = 0.0;
|
|
116
|
+
for (let i = 0; i < 3; ++i) {
|
|
117
|
+
w = bounds[i * 2 + 1] - bounds[i * 2];
|
|
118
|
+
if (w > max) {
|
|
119
|
+
max = w;
|
|
120
|
+
maxIdx = i;
|
|
121
|
+
}
|
|
122
|
+
nonZero[i] = w > 0.0 ? 1 : 0;
|
|
123
|
+
}
|
|
124
|
+
if (maxIdx < 0) {
|
|
125
|
+
return inflate(bounds, 0.5);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Any zero width sides are bumped out 1% of max side
|
|
129
|
+
for (let i = 0; i < 3; ++i) {
|
|
130
|
+
if (!nonZero[i]) {
|
|
131
|
+
const d = 0.005 * max;
|
|
132
|
+
bounds[i * 2] -= d;
|
|
133
|
+
bounds[i * 2 + 1] += d;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return bounds;
|
|
137
|
+
}
|
|
107
138
|
function scale(bounds, sx, sy, sz) {
|
|
108
139
|
if (!isValid(bounds)) {
|
|
109
140
|
return false;
|
|
@@ -182,13 +213,17 @@ function getMaxLength(bounds) {
|
|
|
182
213
|
}
|
|
183
214
|
return l[2];
|
|
184
215
|
}
|
|
185
|
-
function
|
|
216
|
+
function getDiagonalLength2(bounds) {
|
|
186
217
|
if (isValid(bounds)) {
|
|
187
218
|
const l = getLengths(bounds);
|
|
188
|
-
return
|
|
219
|
+
return l[0] * l[0] + l[1] * l[1] + l[2] * l[2];
|
|
189
220
|
}
|
|
190
221
|
return null;
|
|
191
222
|
}
|
|
223
|
+
function getDiagonalLength(bounds) {
|
|
224
|
+
const lenght2 = getDiagonalLength2(bounds);
|
|
225
|
+
return lenght2 !== null ? Math.sqrt(lenght2) : null;
|
|
226
|
+
}
|
|
192
227
|
function getMinPoint(bounds) {
|
|
193
228
|
return [bounds[0], bounds[2], bounds[4]];
|
|
194
229
|
}
|
|
@@ -513,6 +548,145 @@ function cutWithPlane(bounds, origin, normal) {
|
|
|
513
548
|
return true;
|
|
514
549
|
}
|
|
515
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Clamp the divisions to ensure the total number doesn't exceed targetBins
|
|
553
|
+
* @param {Number} targetBins - Maximum number of bins allowed
|
|
554
|
+
* @param {Array} divs - Divisions array to adjust [divX, divY, divZ]
|
|
555
|
+
*/
|
|
556
|
+
function clampDivisions(targetBins, divs) {
|
|
557
|
+
for (let i = 0; i < 3; ++i) {
|
|
558
|
+
divs[i] = divs[i] < 1 ? 1 : divs[i];
|
|
559
|
+
}
|
|
560
|
+
let numBins = divs[0] * divs[1] * divs[2];
|
|
561
|
+
while (numBins > targetBins) {
|
|
562
|
+
for (let i = 0; i < 3; ++i) {
|
|
563
|
+
divs[i] = divs[i] > 1 ? divs[i] - 1 : 1;
|
|
564
|
+
}
|
|
565
|
+
numBins = divs[0] * divs[1] * divs[2];
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Compute the number of divisions given the current bounding box and a
|
|
571
|
+
* target number of buckets/bins. Handles degenerate bounding boxes properly.
|
|
572
|
+
* @param {Bounds} bounds - The bounding box
|
|
573
|
+
* @param {Number} totalBins - Target number of bins
|
|
574
|
+
* @param {Array} divs - Output array to store divisions [divX, divY, divZ]
|
|
575
|
+
* @param {Array} [adjustedBounds] - Output array to store adjusted bounds if needed
|
|
576
|
+
* @returns {Number} The actual total number of bins
|
|
577
|
+
*/
|
|
578
|
+
function computeDivisions(bounds, totalBins, divs) {
|
|
579
|
+
let adjustedBounds = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
580
|
+
// This will always produce at least one bin
|
|
581
|
+
// eslint-disable-next-line no-param-reassign
|
|
582
|
+
totalBins = totalBins <= 0 ? 1 : totalBins;
|
|
583
|
+
|
|
584
|
+
// First determine the maximum length of the side of the bounds. Keep track
|
|
585
|
+
// of zero width sides of the bounding box.
|
|
586
|
+
let numNonZero = 0;
|
|
587
|
+
const nonZero = [0, 0, 0];
|
|
588
|
+
let maxIdx = -1;
|
|
589
|
+
let max = 0.0;
|
|
590
|
+
const lengths = getLengths(bounds);
|
|
591
|
+
|
|
592
|
+
// Use a finite tolerance when detecting zero width sides
|
|
593
|
+
const totLen = lengths[0] + lengths[1] + lengths[2];
|
|
594
|
+
const zeroDetectionTolerance = totLen * (0.001 / 3.0);
|
|
595
|
+
for (let i = 0; i < 3; ++i) {
|
|
596
|
+
if (lengths[i] > max) {
|
|
597
|
+
maxIdx = i;
|
|
598
|
+
max = lengths[i];
|
|
599
|
+
}
|
|
600
|
+
if (lengths[i] > zeroDetectionTolerance) {
|
|
601
|
+
nonZero[i] = 1;
|
|
602
|
+
numNonZero++;
|
|
603
|
+
} else {
|
|
604
|
+
nonZero[i] = 0;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// Get min and max points
|
|
609
|
+
const minPoint = getMinPoint(bounds);
|
|
610
|
+
const maxPoint = getMaxPoint(bounds);
|
|
611
|
+
|
|
612
|
+
// If the bounding box is degenerate, then one bin of arbitrary size
|
|
613
|
+
if (numNonZero < 1) {
|
|
614
|
+
divs[0] = 1;
|
|
615
|
+
divs[1] = 1;
|
|
616
|
+
divs[2] = 1;
|
|
617
|
+
adjustedBounds[0] = minPoint[0] - 0.5;
|
|
618
|
+
adjustedBounds[1] = maxPoint[0] + 0.5;
|
|
619
|
+
adjustedBounds[2] = minPoint[1] - 0.5;
|
|
620
|
+
adjustedBounds[3] = maxPoint[1] + 0.5;
|
|
621
|
+
adjustedBounds[4] = minPoint[2] - 0.5;
|
|
622
|
+
adjustedBounds[5] = maxPoint[2] + 0.5;
|
|
623
|
+
return 1;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Compute the divisions roughly in proportion to the bounding box edge lengths
|
|
627
|
+
let f = totalBins;
|
|
628
|
+
f /= nonZero[0] ? lengths[0] / totLen : 1.0;
|
|
629
|
+
f /= nonZero[1] ? lengths[1] / totLen : 1.0;
|
|
630
|
+
f /= nonZero[2] ? lengths[2] / totLen : 1.0;
|
|
631
|
+
f **= 1.0 / numNonZero;
|
|
632
|
+
for (let i = 0; i < 3; ++i) {
|
|
633
|
+
divs[i] = nonZero[i] ? Math.floor(f * lengths[i] / totLen) : 1;
|
|
634
|
+
divs[i] = divs[i] < 1 ? 1 : divs[i];
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// Make sure that we do not exceed the totalBins
|
|
638
|
+
clampDivisions(totalBins, divs);
|
|
639
|
+
|
|
640
|
+
// Now compute the final bounds, making sure it is a non-zero volume
|
|
641
|
+
const delta = 0.5 * lengths[maxIdx] / divs[maxIdx];
|
|
642
|
+
for (let i = 0; i < 3; ++i) {
|
|
643
|
+
if (nonZero[i]) {
|
|
644
|
+
adjustedBounds[2 * i] = minPoint[i];
|
|
645
|
+
adjustedBounds[2 * i + 1] = maxPoint[i];
|
|
646
|
+
} else {
|
|
647
|
+
adjustedBounds[2 * i] = minPoint[i] - delta;
|
|
648
|
+
adjustedBounds[2 * i + 1] = maxPoint[i] + delta;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
return divs[0] * divs[1] * divs[2];
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* Calculate the squared distance from point x to the specified bounds.
|
|
656
|
+
* @param {Vector3} x The point coordinates
|
|
657
|
+
* @param {Bounds} bounds The bounding box coordinates
|
|
658
|
+
* @returns {Number} The squared distance to the bounds
|
|
659
|
+
*/
|
|
660
|
+
function distance2ToBounds(x, bounds) {
|
|
661
|
+
// Are we within the bounds?
|
|
662
|
+
if (x[0] >= bounds[0] && x[0] <= bounds[1] && x[1] >= bounds[2] && x[1] <= bounds[3] && x[2] >= bounds[4] && x[2] <= bounds[5]) {
|
|
663
|
+
return 0.0;
|
|
664
|
+
}
|
|
665
|
+
const deltas = [0.0, 0.0, 0.0];
|
|
666
|
+
|
|
667
|
+
// dx
|
|
668
|
+
if (x[0] < bounds[0]) {
|
|
669
|
+
deltas[0] = bounds[0] - x[0];
|
|
670
|
+
} else if (x[0] > bounds[1]) {
|
|
671
|
+
deltas[0] = x[0] - bounds[1];
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// dy
|
|
675
|
+
if (x[1] < bounds[2]) {
|
|
676
|
+
deltas[1] = bounds[2] - x[1];
|
|
677
|
+
} else if (x[1] > bounds[3]) {
|
|
678
|
+
deltas[1] = x[1] - bounds[3];
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// dz
|
|
682
|
+
if (x[2] < bounds[4]) {
|
|
683
|
+
deltas[2] = bounds[4] - x[2];
|
|
684
|
+
} else if (x[2] > bounds[5]) {
|
|
685
|
+
deltas[2] = x[2] - bounds[5];
|
|
686
|
+
}
|
|
687
|
+
return dot(deltas, deltas);
|
|
688
|
+
}
|
|
689
|
+
|
|
516
690
|
// ----------------------------------------------------------------------------
|
|
517
691
|
// Light Weight class
|
|
518
692
|
// ----------------------------------------------------------------------------
|
|
@@ -578,6 +752,9 @@ class BoundingBox {
|
|
|
578
752
|
getDiagonalLength() {
|
|
579
753
|
return getDiagonalLength(this.bounds);
|
|
580
754
|
}
|
|
755
|
+
getDiagonalLength2() {
|
|
756
|
+
return getDiagonalLength2(this.bounds);
|
|
757
|
+
}
|
|
581
758
|
getMinPoint() {
|
|
582
759
|
return getMinPoint(this.bounds);
|
|
583
760
|
}
|
|
@@ -630,6 +807,13 @@ class BoundingBox {
|
|
|
630
807
|
contains(otherBounds) {
|
|
631
808
|
return intersects(this.bounds, otherBounds);
|
|
632
809
|
}
|
|
810
|
+
computeDivisions(totalBins, divs) {
|
|
811
|
+
let adjustedBounds = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
812
|
+
return computeDivisions(this.bounds, totalBins, divs, adjustedBounds);
|
|
813
|
+
}
|
|
814
|
+
distance2ToBounds(x) {
|
|
815
|
+
return distance2ToBounds(x, this.bounds);
|
|
816
|
+
}
|
|
633
817
|
}
|
|
634
818
|
function newInstance(initialValues) {
|
|
635
819
|
const bounds = initialValues && initialValues.bounds;
|
|
@@ -675,6 +859,9 @@ const STATIC = {
|
|
|
675
859
|
intersects,
|
|
676
860
|
containsPoint,
|
|
677
861
|
contains,
|
|
862
|
+
computeDivisions,
|
|
863
|
+
clampDivisions,
|
|
864
|
+
distance2ToBounds,
|
|
678
865
|
INIT_BOUNDS
|
|
679
866
|
};
|
|
680
867
|
var vtkBoundingBox = {
|
|
@@ -682,4 +869,4 @@ var vtkBoundingBox = {
|
|
|
682
869
|
...STATIC
|
|
683
870
|
};
|
|
684
871
|
|
|
685
|
-
export { STATIC, addBounds, addPoint, addPoints, computeCornerPoints, computeLocalBounds, computeScale3, contains, containsPoint, cutWithPlane, vtkBoundingBox as default, equals, getCenter, getCorners, getDiagonalLength, getLength, getLengths, getMaxLength, getMaxPoint, getMinPoint, getXRange, getYRange, getZRange,
|
|
872
|
+
export { STATIC, addBounds, addPoint, addPoints, clampDivisions, computeCornerPoints, computeDivisions, computeLocalBounds, computeScale3, contains, containsPoint, cutWithPlane, vtkBoundingBox as default, distance2ToBounds, equals, getCenter, getCorners, getDiagonalLength, getDiagonalLength2, getLength, getLengths, getMaxLength, getMaxPoint, getMinPoint, getXRange, getYRange, getZRange, intersect, intersectBox, intersectPlane, intersects, isValid, reset, scale, scaleAboutCenter, setBounds, setMaxPoint, setMinPoint, transformBounds };
|
package/Common/DataModel/Cell.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { m as macro } from '../../macros2.js';
|
|
2
|
-
import
|
|
2
|
+
import vtkBoundingBox from './BoundingBox.js';
|
|
3
3
|
import vtkPoints from '../Core/Points.js';
|
|
4
4
|
|
|
5
5
|
// ----------------------------------------------------------------------------
|
|
@@ -36,40 +36,10 @@ function vtkCell(publicAPI, model) {
|
|
|
36
36
|
model.points.setData(triangleData);
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
publicAPI.getBounds = () =>
|
|
40
|
-
const nbPoints = model.points.getNumberOfPoints();
|
|
41
|
-
const x = [];
|
|
42
|
-
if (nbPoints) {
|
|
43
|
-
model.points.getPoint(0, x);
|
|
44
|
-
model.bounds[0] = x[0];
|
|
45
|
-
model.bounds[1] = x[0];
|
|
46
|
-
model.bounds[2] = x[1];
|
|
47
|
-
model.bounds[3] = x[1];
|
|
48
|
-
model.bounds[4] = x[2];
|
|
49
|
-
model.bounds[5] = x[2];
|
|
50
|
-
for (let i = 1; i < nbPoints; i++) {
|
|
51
|
-
model.points.getPoint(i, x);
|
|
52
|
-
model.bounds[0] = x[0] < model.bounds[0] ? x[0] : model.bounds[0];
|
|
53
|
-
model.bounds[1] = x[0] > model.bounds[1] ? x[0] : model.bounds[1];
|
|
54
|
-
model.bounds[2] = x[1] < model.bounds[2] ? x[1] : model.bounds[2];
|
|
55
|
-
model.bounds[3] = x[1] > model.bounds[3] ? x[1] : model.bounds[3];
|
|
56
|
-
model.bounds[4] = x[2] < model.bounds[4] ? x[2] : model.bounds[4];
|
|
57
|
-
model.bounds[5] = x[2] > model.bounds[5] ? x[2] : model.bounds[5];
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
uninitializeBounds(model.bounds);
|
|
61
|
-
}
|
|
62
|
-
return model.bounds;
|
|
63
|
-
};
|
|
39
|
+
publicAPI.getBounds = () => model.points.getBounds();
|
|
64
40
|
publicAPI.getLength2 = () => {
|
|
65
|
-
publicAPI.getBounds();
|
|
66
|
-
|
|
67
|
-
let diff = 0;
|
|
68
|
-
for (let i = 0; i < 3; i++) {
|
|
69
|
-
diff = model.bounds[2 * i + 1] - model.bounds[2 * i];
|
|
70
|
-
length += diff * diff;
|
|
71
|
-
}
|
|
72
|
-
return length;
|
|
41
|
+
const lengths = vtkBoundingBox.getLengths(publicAPI.getBounds());
|
|
42
|
+
return lengths[0] * lengths[0] + lengths[1] * lengths[1] + lengths[2] * lengths[2];
|
|
73
43
|
};
|
|
74
44
|
publicAPI.getParametricDistance = pcoords => {
|
|
75
45
|
let pDist;
|
|
@@ -8,6 +8,13 @@ import { FieldAssociations, FieldDataTypes } from './DataSet/Constants';
|
|
|
8
8
|
export interface IDataSetInitialValues {}
|
|
9
9
|
|
|
10
10
|
export interface vtkDataSet extends vtkObject {
|
|
11
|
+
/**
|
|
12
|
+
* Initialize the field, cell and point data.
|
|
13
|
+
* @see vtkDataSetAttributes::initialize()
|
|
14
|
+
* @see vtkFieldData::initialize()
|
|
15
|
+
*/
|
|
16
|
+
initialize(): void;
|
|
17
|
+
|
|
11
18
|
/**
|
|
12
19
|
* Get dataset's cell data
|
|
13
20
|
*/
|
|
@@ -65,6 +65,12 @@ function vtkDataSet(publicAPI, model) {
|
|
|
65
65
|
model[fieldName].shallowCopy(other.getReferenceByName(fieldName));
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
|
+
const superGetMTime = publicAPI.getMTime;
|
|
69
|
+
publicAPI.getMTime = () => DATASET_FIELDS.reduce((mTime, fieldName) => Math.max(mTime, model[fieldName]?.getMTime() ?? mTime), superGetMTime());
|
|
70
|
+
publicAPI.initialize = () => {
|
|
71
|
+
DATASET_FIELDS.forEach(fieldName => model[fieldName]?.initialize());
|
|
72
|
+
return publicAPI;
|
|
73
|
+
};
|
|
68
74
|
}
|
|
69
75
|
|
|
70
76
|
// ----------------------------------------------------------------------------
|
|
@@ -22,12 +22,16 @@ interface IArrayWithIndex {
|
|
|
22
22
|
|
|
23
23
|
export interface vtkFieldData extends vtkObject {
|
|
24
24
|
/**
|
|
25
|
-
*
|
|
25
|
+
* Initialize fields, clear flags and restore copy beahvior.
|
|
26
|
+
* @see initializeFields
|
|
27
|
+
* @see clearFieldFlags
|
|
28
|
+
* @see copyAllOn
|
|
26
29
|
*/
|
|
27
30
|
initialize(): void;
|
|
28
31
|
|
|
29
32
|
/**
|
|
30
|
-
*
|
|
33
|
+
* Delete all arrays and clear flags.
|
|
34
|
+
* @see initialize
|
|
31
35
|
*/
|
|
32
36
|
initializeFields(): void;
|
|
33
37
|
|
|
@@ -20,6 +20,13 @@ interface IComputeHistogram {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface vtkImageData extends vtkDataSet {
|
|
23
|
+
/**
|
|
24
|
+
* Reinitialize the state (direction, spacing, origin, extent, etc.)
|
|
25
|
+
* and the data set.
|
|
26
|
+
* @see vtkDataSet::initialize()
|
|
27
|
+
*/
|
|
28
|
+
initialize(): void;
|
|
29
|
+
|
|
23
30
|
/**
|
|
24
31
|
* Returns an object with `{ minimum, maximum, average, variance, sigma, count }`
|
|
25
32
|
* of the imageData points found within the provided `worldBounds`.
|
|
@@ -314,6 +314,17 @@ function vtkImageData(publicAPI, model) {
|
|
|
314
314
|
}
|
|
315
315
|
return publicAPI.getPointData().getScalars().getComponent(offsetIndex, comp);
|
|
316
316
|
};
|
|
317
|
+
const superInitialize = publicAPI.initialize;
|
|
318
|
+
publicAPI.initialize = () => {
|
|
319
|
+
publicAPI.set({
|
|
320
|
+
direction: mat3.identity(model.direction),
|
|
321
|
+
spacing: [1.0, 1.0, 1.0],
|
|
322
|
+
origin: [0.0, 0.0, 0.0],
|
|
323
|
+
extent: [0, -1, 0, -1, 0, -1],
|
|
324
|
+
dataDescription: StructuredType.EMPTY
|
|
325
|
+
});
|
|
326
|
+
return superInitialize();
|
|
327
|
+
};
|
|
317
328
|
}
|
|
318
329
|
|
|
319
330
|
// ----------------------------------------------------------------------------
|