Skip to content

Commit e6f589b

Browse files
committed
fix(prop3d): fix vtkProp3D bounds
vtkProp3D expects mapper GetBounds() - hence vtkPolyData::GetBounds() - to return a unique array each time GetBounds() is called. If a reference array is expected, then GetBoundsByReference() should be used instead.
1 parent 7188a57 commit e6f589b

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

Sources/Common/Core/Points/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ export interface vtkPoints extends vtkDataArray {
1717
computeBounds(): Bounds;
1818

1919
/**
20-
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
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.
2123
* @return {Bounds} The bounds for the mapper.
2224
*/
2325
getBounds(): Bounds;
2426

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+
2535
/**
2636
* Get the coordinate of a point.
2737
* @param {Number} idx The index of point.

Sources/Common/Core/Points/index.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import macro from 'vtk.js/Sources/macros';
22
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
33
import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants';
4+
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
45

56
const { vtkErrorMacro } = macro;
6-
7-
const INVALID_BOUNDS = [1, -1, 1, -1, 1, -1];
8-
97
// ----------------------------------------------------------------------------
108
// vtkPoints methods
119
// ----------------------------------------------------------------------------
1210

1311
function vtkPoints(publicAPI, model) {
12+
// Keep track of modified time for bounds computation
13+
let boundMTime = 0;
14+
1415
// Set our className
1516
model.classHierarchy.push('vtkPoints');
1617

@@ -37,7 +38,24 @@ function vtkPoints(publicAPI, model) {
3738

3839
publicAPI.insertPoint = (ptId, point) => publicAPI.insertTuple(ptId, point);
3940

41+
const superGetBounds = publicAPI.getBounds;
4042
publicAPI.getBounds = () => {
43+
if (boundMTime < model.mtime) {
44+
publicAPI.computeBounds();
45+
}
46+
return superGetBounds();
47+
};
48+
49+
const superGetBoundsByReference = publicAPI.getBoundsByReference;
50+
publicAPI.getBoundsByReference = () => {
51+
if (boundMTime < model.mtime) {
52+
publicAPI.computeBounds();
53+
}
54+
return superGetBoundsByReference();
55+
};
56+
57+
// Trigger the computation of bounds
58+
publicAPI.computeBounds = () => {
4159
if (publicAPI.getNumberOfComponents() === 3) {
4260
const xRange = publicAPI.getRange(0);
4361
model.bounds[0] = xRange[0];
@@ -48,31 +66,24 @@ function vtkPoints(publicAPI, model) {
4866
const zRange = publicAPI.getRange(2);
4967
model.bounds[4] = zRange[0];
5068
model.bounds[5] = zRange[1];
51-
return model.bounds;
52-
}
53-
54-
if (publicAPI.getNumberOfComponents() !== 2) {
69+
} else if (publicAPI.getNumberOfComponents() === 2) {
70+
const xRange = publicAPI.getRange(0);
71+
model.bounds[0] = xRange[0];
72+
model.bounds[1] = xRange[1];
73+
const yRange = publicAPI.getRange(1);
74+
model.bounds[2] = yRange[0];
75+
model.bounds[3] = yRange[1];
76+
model.bounds[4] = 0;
77+
model.bounds[5] = 0;
78+
} else {
5579
vtkErrorMacro(
5680
`getBounds called on an array with components of ${publicAPI.getNumberOfComponents()}`
5781
);
58-
return INVALID_BOUNDS;
82+
vtkMath.uninitializeBounds(model.bounds);
5983
}
60-
61-
const xRange = publicAPI.getRange(0);
62-
model.bounds[0] = xRange[0];
63-
model.bounds[1] = xRange[1];
64-
const yRange = publicAPI.getRange(1);
65-
model.bounds[2] = yRange[0];
66-
model.bounds[3] = yRange[1];
67-
model.bounds[4] = 0;
68-
model.bounds[5] = 0;
69-
70-
return model.bounds;
84+
boundMTime = macro.getCurrentGlobalMTime();
7185
};
7286

73-
// Trigger the computation of bounds
74-
publicAPI.computeBounds = publicAPI.getBounds;
75-
7687
// Initialize
7788
publicAPI.setNumberOfComponents(
7889
model.numberOfComponents < 2 ? 3 : model.numberOfComponents
@@ -96,6 +107,8 @@ export function extend(publicAPI, model, initialValues = {}) {
96107
Object.assign(model, DEFAULT_VALUES, initialValues);
97108

98109
vtkDataArray.extend(publicAPI, model, initialValues);
110+
111+
macro.getArray(publicAPI, model, ['bounds'], 6);
99112
vtkPoints(publicAPI, model);
100113
}
101114

0 commit comments

Comments
 (0)