Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## From 34.x to 35

- **vtkMapper**: mappers should overwrite `computeBounds()` instead of `getBounds` that now calls `computeBounds()` before returning a copy of the mapper bounds.


## From 33.x to 34

- **vtkMapper**: many properties have moved to `vtkVolumeProperty`. The full list of changed methods is: `getAnisotropy`, `getComputeNormalFromOpacity`, `getFilterMode`, `getFilterModeAsString`, `getGlobalIlluminationReach`, `getIpScalarRange`, `getIpScalarRangeByReference`, `getLAOKernelRadius`, `getLAOKernelSize`, `getLocalAmbientOcclusion`, `getPreferSizeOverAccuracy`, `getVolumetricScatteringBlending`, `setAnisotropy`, `setAverageIPScalarRange`, `setComputeNormalFromOpacity`, `setFilterMode`, `setFilterModeToNormalized`, `setFilterModeToOff`, `setFilterModeToRaw`, `setGlobalIlluminationReach`, `setIpScalarRange`, `setIpScalarRangeFrom`, `setLAOKernelRadius`, `setLAOKernelSize`, `setLocalAmbientOcclusion`, `setPreferSizeOverAccuracy`, `setVolumetricScatteringBlending`.
Expand Down
11 changes: 8 additions & 3 deletions Sources/Common/DataModel/BoundingBox/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mat4 } from 'gl-matrix';
import { Bounds, Vector2, Vector3 } from '../../../types';
import { Bounds, TypedArray, Vector2, Vector3 } from '../../../types';
import vtkPoints from '../../Core/Points';
import { Nullable } from '../../../types';

Expand Down Expand Up @@ -394,11 +394,16 @@ declare class BoundingBox {
/**
* Adds points to a bounding box.
* @param {Bounds} bounds
* @param {number} x
* @param {number|Number[]|TypedArray} xOrPoint
* @param {number} y
* @param {number} z
*/
addPoint(bounds: Bounds, x: number, y: number, z: number): Bounds;
addPoint(
bounds: Bounds,
xOrPoint: number | number[] | TypedArray,
y?: number,
z?: number
): Bounds;

/**
* Adds points to a bounding box.
Expand Down
23 changes: 16 additions & 7 deletions Sources/Common/DataModel/BoundingBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,23 @@ export function reset(bounds) {
return setBounds(bounds, INIT_BOUNDS);
}

export function addPoint(bounds, x, y, z) {
export function addPoint(bounds, xOrPoint, y, z) {
const [xMin, xMax, yMin, yMax, zMin, zMax] = bounds;
bounds[0] = xMin < x ? xMin : x;
bounds[1] = xMax > x ? xMax : x;
bounds[2] = yMin < y ? yMin : y;
bounds[3] = yMax > y ? yMax : y;
bounds[4] = zMin < z ? zMin : z;
bounds[5] = zMax > z ? zMax : z;
if (arguments.length === 4) {
bounds[0] = xMin < xOrPoint ? xMin : xOrPoint;
bounds[1] = xMax > xOrPoint ? xMax : xOrPoint;
bounds[2] = yMin < y ? yMin : y;
bounds[3] = yMax > y ? yMax : y;
bounds[4] = zMin < z ? zMin : z;
bounds[5] = zMax > z ? zMax : z;
} else {
bounds[0] = xMin < xOrPoint[0] ? xMin : xOrPoint[0];
bounds[1] = xMax > xOrPoint[0] ? xMax : xOrPoint[0];
bounds[2] = yMin < xOrPoint[1] ? yMin : xOrPoint[1];
bounds[3] = yMax > xOrPoint[1] ? yMax : xOrPoint[1];
bounds[4] = zMin < xOrPoint[2] ? zMin : xOrPoint[2];
bounds[5] = zMax > xOrPoint[2] ? zMax : xOrPoint[2];
}
return bounds;
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/DataModel/Box/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function vtkBox(publicAPI, model) {
vtkBoundingBox.setBounds(model.bbox, boundsArray);
};

publicAPI.getBounds = () => model.bbox;
publicAPI.getBounds = () => [...model.bbox];

publicAPI.evaluateFunction = (x, y, z) => {
const point = Array.isArray(x) ? x : [x, y, z];
Expand Down
9 changes: 5 additions & 4 deletions Sources/Proxy/Core/ViewProxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,11 @@ function vtkViewProxy(publicAPI, model) {

// --------------------------------------------------------------------------

publicAPI.setBackground = macro.chain(
model.renderer.setBackground,
updateAnnotationColor
);
publicAPI.setBackground = (...args) => {
const res = model.renderer.setBackground(...args);
updateAnnotationColor();
return res;
};

// --------------------------------------------------------------------------

Expand Down
23 changes: 21 additions & 2 deletions Sources/Rendering/Core/AbstractMapper3D/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@ export interface IAbstractMapper3DInitialValues
export interface vtkAbstractMapper3D extends vtkAbstractMapper {
/**
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
* @default 0
* @return {Bounds} The bounds for the mapper.
* Bounds are (re)computed if needed.
* @return {Bounds} A copy of the bounds for the mapper.
* @see getBoundsByReference
* @see computeBounds
*/
getBounds(): Bounds;

/**
* Get the bounds for this mapper as [xmin, xmax, ymin, ymax,zmin, zmax].
* Bounds are (re)computed if needed.
* @return {Bounds} The bounds array of the mapper.
* @see getBounds
* @see computeBounds
*/
getBoundsByReference(): Bounds;

/**
* Compute the bounds for this mapper.
* Must be implemented by sub-classes. Called by getBounds methods.
* @see getBoundsByReference
* @see getBounds
*/
computeBounds(): void;

/**
* Get the center of this mapper’s data.
* @return {Vector3} The center of the mapper's data.
Expand Down
21 changes: 16 additions & 5 deletions Sources/Rendering/Core/AbstractMapper3D/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
import macro from 'vtk.js/Sources/macros';
import vtkAbstractMapper from 'vtk.js/Sources/Rendering/Core/AbstractMapper';
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import { createUninitializedBounds } from 'vtk.js/Sources/Common/Core/Math';

// ----------------------------------------------------------------------------
// vtkAbstractMapper methods
// ----------------------------------------------------------------------------

function vtkAbstractMapper3D(publicAPI, model) {
publicAPI.computeBounds = () => {
macro.vtkErrorMacro(`vtkAbstractMapper3D.computeBounds - NOT IMPLEMENTED`);
};

const superGetBounds = publicAPI.getBounds;
publicAPI.getBounds = () => {
macro.vtkErrorMacro(`vtkAbstractMapper3D.getBounds - NOT IMPLEMENTED`);
return createUninitializedBounds();
publicAPI.computeBounds();
return superGetBounds();
};

const superGetBoundsByReference = publicAPI.getBoundsByReference;
publicAPI.getBoundsByReference = () => {
publicAPI.computeBounds();
return superGetBoundsByReference();
};

publicAPI.getCenter = () => {
const bounds = publicAPI.getBounds();
const bounds = publicAPI.getBoundsByReference();
model.center = vtkBoundingBox.isValid(bounds)
? vtkBoundingBox.getCenter(bounds)
: null;
return model.center?.slice();
};

publicAPI.getLength = () => {
const bounds = publicAPI.getBounds();
const bounds = publicAPI.getBoundsByReference();
return vtkBoundingBox.getDiagonalLength(bounds);
};
}
Expand All @@ -46,6 +56,7 @@ export function extend(publicAPI, model, initialValues = {}) {
vtkAbstractMapper.extend(publicAPI, model, initialValues);

macro.setGet(publicAPI, model, ['viewSpecificProperties']);
macro.getArray(publicAPI, model, ['bounds'], 6);

vtkAbstractMapper3D(publicAPI, model);
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/Rendering/Core/CubeAxesActor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ function vtkCubeAxesActor(publicAPI, model) {
// as it relies on the pixel size of the window. Every time the camera
// changes the bounds change. This method simplifies by just expanding
// the grid bounds by a user specified factor.
publicAPI.getBounds = () => {
publicAPI.computeBounds = () => {
publicAPI.update();
vtkBoundingBox.setBounds(model.bounds, model.gridActor.getBounds());
vtkBoundingBox.scaleAboutCenter(
Expand All @@ -797,15 +797,15 @@ function vtkCubeAxesActor(publicAPI, model) {
model.boundsScaleFactor,
model.boundsScaleFactor
);
return model.bounds;
};

// Make sure the grid share the actor property
const _setProp = macro.chain(
publicAPI.setProperty,
model.gridActor.setProperty
);
publicAPI.setProperty = (p) => _setProp(p)[0];
const superSetProp = publicAPI.setProperty;
publicAPI.setProperty = (p) => {
const res = superSetProp(p);
model.gridActor.setProperty(p);
return res;
};
}

// ----------------------------------------------------------------------------
Expand Down
45 changes: 7 additions & 38 deletions Sources/Rendering/Core/Glyph3DMapper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,16 @@ function vtkGlyph3DMapper(publicAPI, model) {
return idata.getPointData().getArray(model.scaleArray);
};

publicAPI.getBounds = () => {
const idata = publicAPI.getInputData(0);
const gdata = publicAPI.getInputData(1);
if (!idata || !gdata) {
return vtkMath.createUninitializedBounds();
}

// first we build the arrays used for the glyphing
publicAPI.buildArrays();
return model.bounds;
};
publicAPI.computeBounds = () => publicAPI.buildArrays();

publicAPI.buildArrays = () => {
// if the mtgime requires it, rebuild
const idata = publicAPI.getInputData(0);
const gdata = publicAPI.getInputData(1);
if (!idata || !gdata) {
vtkBoundingBox.reset(model.bounds);
return;
}
if (
model.buildTime.getMTime() < gdata.getMTime() ||
model.buildTime.getMTime() < idata.getMTime() ||
Expand Down Expand Up @@ -114,12 +108,7 @@ function vtkGlyph3DMapper(publicAPI, model) {
// overall bounds while building the arrays
const corners = [];
vtkBoundingBox.getCorners(gbounds, corners);
model.bounds[0] = vtkBoundingBox.INIT_BOUNDS[0];
model.bounds[1] = vtkBoundingBox.INIT_BOUNDS[1];
model.bounds[2] = vtkBoundingBox.INIT_BOUNDS[2];
model.bounds[3] = vtkBoundingBox.INIT_BOUNDS[3];
model.bounds[4] = vtkBoundingBox.INIT_BOUNDS[4];
model.bounds[5] = vtkBoundingBox.INIT_BOUNDS[5];
vtkBoundingBox.reset(model.bounds);

const tcorner = new Float64Array(3);

Expand Down Expand Up @@ -225,24 +214,7 @@ function vtkGlyph3DMapper(publicAPI, model) {
// update bounds
for (let p = 0; p < 8; ++p) {
vec3.transformMat4(tcorner, corners[p], z);
if (tcorner[0] < model.bounds[0]) {
model.bounds[0] = tcorner[0];
}
if (tcorner[1] < model.bounds[2]) {
model.bounds[2] = tcorner[1];
}
if (tcorner[2] < model.bounds[4]) {
model.bounds[4] = tcorner[2];
}
if (tcorner[0] > model.bounds[1]) {
model.bounds[1] = tcorner[0];
}
if (tcorner[1] > model.bounds[3]) {
model.bounds[3] = tcorner[1];
}
if (tcorner[2] > model.bounds[5]) {
model.bounds[5] = tcorner[2];
}
vtkBoundingBox.addPoint(model.bounds, tcorner);
}

const n = new Float32Array(nbuff, i * 36, 9);
Expand Down Expand Up @@ -333,9 +305,6 @@ export function extend(publicAPI, model, initialValues = {}) {
model.buildTime = {};
macro.obj(model.buildTime, { mtime: 0 });

model.boundsTime = {};
macro.obj(model.boundsTime, { mtime: 0 });

macro.setGet(publicAPI, model, [
'orient',
'orientationMode',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,16 @@ test('Test HardwareSelectorGlyph', (tapeContext) => {
sel.setFieldAssociation(FieldAssociations.FIELD_ASSOCIATION_POINTS);

return sel.selectAsync(renderer, 200, 200, 250, 300).then((res) => {
const allGood = res.length === 7 && res[0].getProperties().prop === actor;

tapeContext.ok(res.length === 7, 'Seven glyphs selected');
tapeContext.equal(res.length, 7, 'Seven glyphs selected');
tapeContext.ok(
res[0].getProperties().compositeID === 71,
'glyph 71 was the first selected'
);
tapeContext.ok(allGood, 'Correct prop was selected');
tapeContext.equal(
res[0].getProperties().prop,
actor,
'Correct prop was selected'
);

gc.releaseResources();
});
Expand Down
12 changes: 8 additions & 4 deletions Sources/Rendering/Core/ImageArrayMapper/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import macro from 'vtk.js/Sources/macros';
import vtkAbstractImageMapper from 'vtk.js/Sources/Rendering/Core/AbstractImageMapper';
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import vtkImageMapper from 'vtk.js/Sources/Rendering/Core/ImageMapper';
import * as vtkMath from 'vtk.js/Sources/Common/Core/Math';
import * as pickingHelper from 'vtk.js/Sources/Rendering/Core/AbstractImageMapper/helper';
Expand Down Expand Up @@ -80,13 +81,16 @@ function vtkImageArrayMapper(publicAPI, model) {
return null;
};

publicAPI.getBounds = () => {
// reimplemented from AbstractMapper3D
publicAPI.computeBounds = () => {
const image = publicAPI.getCurrentImage();
if (!image) {
return vtkMath.createUninitializedBounds();
vtkBoundingBox.reset(model.bounds);
return;
}
if (!model.useCustomExtents) {
return image.getBounds();
vtkBoundingBox.setBounds(model.bounds, image.getBounds());
return;
}

const ex = model.customDisplayExtent.slice();
Expand All @@ -95,7 +99,7 @@ function vtkImageArrayMapper(publicAPI, model) {
const nSlice = publicAPI.getSubSlice();
ex[4] = nSlice;
ex[5] = nSlice;
return image.extentToBounds(ex);
vtkBoundingBox.setBounds(model.bounds, image.extentToBounds(ex));
};

publicAPI.getBoundsForSlice = (
Expand Down
14 changes: 11 additions & 3 deletions Sources/Rendering/Core/ImageCPRMapper/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mat4, quat, vec3 } from 'gl-matrix';
import vtkBoundingBox from 'vtk.js/Sources/Common/DataModel/BoundingBox';
import CoincidentTopologyHelper from 'vtk.js/Sources/Rendering/Core/Mapper/CoincidentTopologyHelper';
import vtkAbstractImageMapper from 'vtk.js/Sources/Rendering/Core/AbstractImageMapper';
import macro from 'vtk.js/Sources/macros';
Expand All @@ -21,12 +22,19 @@ function vtkImageCPRMapper(publicAPI, model) {
const superClass = { ...publicAPI };

/**
* Public methods
* Reimplemented from AbstractMapper3D
*/
publicAPI.getBounds = () => {
publicAPI.computeBounds = () => {
const imageWidth = publicAPI.getWidth();
const imageHeight = publicAPI.getHeight();
return [0, imageWidth, 0, imageHeight, 0, 0];
vtkBoundingBox.setBounds(model.bounds, [
0,
imageWidth,
0,
imageHeight,
0,
0,
]);
};

publicAPI.getOrientationDataArray = () => {
Expand Down
Loading