Skip to content

Commit 4976534

Browse files
committed
refactor: Fix resource caching and signature of getProperty()
1 parent 4c481a0 commit 4976534

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

Examples/Volume/VolumeMapperLightAndShadow/index.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import HttpDataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpD
1313
import vtkVolumeController from '@kitware/vtk.js/Interaction/UI/VolumeController';
1414
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
1515
import vtkFPSMonitor from '@kitware/vtk.js/Interaction/UI/FPSMonitor';
16-
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';
1716

1817
import vtkActor from '@kitware/vtk.js/Rendering/Core/Actor';
1918
import vtkSphereSource from '@kitware/vtk.js/Filters/Sources/SphereSource';
@@ -87,18 +86,6 @@ function createVolumeShadowViewer(rootContainer, fileContents) {
8786
actor.setMapper(mapper);
8887
mapper.addInputData(source);
8988

90-
for (let i = 0; i < 0; ++i) {
91-
const otherImageData = vtkImageData.newInstance();
92-
otherImageData.setPointData(source.getPointData());
93-
otherImageData.setDimensions(...source.getDimensions());
94-
otherImageData.setSpacing(...source.getSpacing());
95-
otherImageData.setOrigin(...source.getOrigin());
96-
otherImageData.setDirection(...source.getDirection());
97-
otherImageData.setOrigin(...[120 * (i + 1), 0, 0]);
98-
mapper.addInputData(otherImageData);
99-
actor.setProperty(actorProperty, 1 + i);
100-
}
101-
10289
// Add one positional light
10390
const bounds = actor.getBounds();
10491
const center = vtkBoundingBox.getCenter(bounds);

Sources/Rendering/Core/ImageSlice/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ export interface vtkImageSlice extends vtkProp3D {
126126
/**
127127
*
128128
* @param {vtkImageProperty} property The vtkImageProperty instance.
129+
* @param {number} mapperInputPort Is 0 when not given
129130
*/
131+
setProperty(mapperInputPort: number, property: vtkImageProperty): boolean;
130132
setProperty(property: vtkImageProperty): boolean;
131133

132134
/**

Sources/Rendering/Core/Prop3D/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,15 @@ function vtkProp3D(publicAPI, model) {
238238
return model.properties[mapperInputPort];
239239
};
240240

241-
publicAPI.setProperty = (property, mapperInputPort = 0) => {
241+
publicAPI.setProperty = (firstArg, secondArg) => {
242+
// Two options for argument layout:
243+
// - (mapperInputPort, property)
244+
// - (property)
245+
const useInputPortArgument = Number.isInteger(firstArg);
246+
const [mapperInputPort, property] = useInputPortArgument
247+
? [firstArg, secondArg]
248+
: [0, firstArg];
249+
242250
if (model.properties[mapperInputPort] === property) {
243251
return false;
244252
}

Sources/Rendering/Core/Volume/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export interface vtkVolume extends vtkProp3D {
7474
/**
7575
* Set the volume property for the specified mapper input port, which defaults to 0
7676
* @param {vtkVolumeProperty} property
77-
* @param {number} mapperInputPort Defaults to 0
77+
* @param {number} mapperInputPort Is 0 when not given
7878
*/
79-
setProperty(property: vtkVolumeProperty, mapperInputPort?: number): boolean;
79+
setProperty(mapperInputPort: number, property: vtkVolumeProperty): boolean;
80+
setProperty(property: vtkVolumeProperty): boolean;
8081

8182
/**
8283
* Set the volume properties array

Sources/Rendering/OpenGL/RenderWindow/resourceSharingHelper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export function getTransferFunctionHash(
1111
}
1212

1313
export function getImageDataHash(image, scalars) {
14-
return `${image.getMTime()}A${scalars.getMTime()}`;
14+
// Don't use the image data, as the scalars will define the texture
15+
// If using the image data in the hash, it will cause issues when two image data
16+
// using the same scalars are in the same mapper (for example the VolumeMapper)
17+
return `${scalars.getMTime()}`;
1518
}
1619

1720
export default { getTransferFunctionHash, getImageDataHash };

0 commit comments

Comments
 (0)