Skip to content

Commit

Permalink
refactor: Fix resource caching and signature of getProperty()
Browse files Browse the repository at this point in the history
  • Loading branch information
bruyeret committed Oct 3, 2024
1 parent 4c481a0 commit 4976534
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
13 changes: 0 additions & 13 deletions Examples/Volume/VolumeMapperLightAndShadow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import HttpDataAccessHelper from '@kitware/vtk.js/IO/Core/DataAccessHelper/HttpD
import vtkVolumeController from '@kitware/vtk.js/Interaction/UI/VolumeController';
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
import vtkFPSMonitor from '@kitware/vtk.js/Interaction/UI/FPSMonitor';
import vtkImageData from '@kitware/vtk.js/Common/DataModel/ImageData';

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

for (let i = 0; i < 0; ++i) {
const otherImageData = vtkImageData.newInstance();
otherImageData.setPointData(source.getPointData());
otherImageData.setDimensions(...source.getDimensions());
otherImageData.setSpacing(...source.getSpacing());
otherImageData.setOrigin(...source.getOrigin());
otherImageData.setDirection(...source.getDirection());
otherImageData.setOrigin(...[120 * (i + 1), 0, 0]);
mapper.addInputData(otherImageData);
actor.setProperty(actorProperty, 1 + i);
}

// Add one positional light
const bounds = actor.getBounds();
const center = vtkBoundingBox.getCenter(bounds);
Expand Down
2 changes: 2 additions & 0 deletions Sources/Rendering/Core/ImageSlice/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export interface vtkImageSlice extends vtkProp3D {
/**
*
* @param {vtkImageProperty} property The vtkImageProperty instance.
* @param {number} mapperInputPort Is 0 when not given
*/
setProperty(mapperInputPort: number, property: vtkImageProperty): boolean;
setProperty(property: vtkImageProperty): boolean;

/**
Expand Down
10 changes: 9 additions & 1 deletion Sources/Rendering/Core/Prop3D/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@ function vtkProp3D(publicAPI, model) {
return model.properties[mapperInputPort];
};

publicAPI.setProperty = (property, mapperInputPort = 0) => {
publicAPI.setProperty = (firstArg, secondArg) => {
// Two options for argument layout:
// - (mapperInputPort, property)
// - (property)
const useInputPortArgument = Number.isInteger(firstArg);
const [mapperInputPort, property] = useInputPortArgument
? [firstArg, secondArg]
: [0, firstArg];

if (model.properties[mapperInputPort] === property) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/Rendering/Core/Volume/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ export interface vtkVolume extends vtkProp3D {
/**
* Set the volume property for the specified mapper input port, which defaults to 0
* @param {vtkVolumeProperty} property
* @param {number} mapperInputPort Defaults to 0
* @param {number} mapperInputPort Is 0 when not given
*/
setProperty(property: vtkVolumeProperty, mapperInputPort?: number): boolean;
setProperty(mapperInputPort: number, property: vtkVolumeProperty): boolean;
setProperty(property: vtkVolumeProperty): boolean;

/**
* Set the volume properties array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ export function getTransferFunctionHash(
}

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

export default { getTransferFunctionHash, getImageDataHash };

0 comments on commit 4976534

Please sign in to comment.