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 4, 2024
1 parent 40640d9 commit 6d54ca0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 62 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
30 changes: 7 additions & 23 deletions Sources/Rendering/Core/ImageSlice/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,6 @@ export interface vtkImageSlice extends vtkProp3D {
*/
getIsOpaque(): boolean;

/**
*
*/
getProperty(): vtkImageProperty;

/**
*
*/
getProperties(): vtkImageProperty[];

/**
*
*/
Expand Down Expand Up @@ -123,19 +113,6 @@ export interface vtkImageSlice extends vtkProp3D {
*/
setMapper(mapper: vtkAbstractImageMapper): boolean;

/**
*
* @param {vtkImageProperty} property The vtkImageProperty instance.
*/
setProperty(property: vtkImageProperty): boolean;

/**
* Set the actor properties array
* Each element of the array corresponds to a mapper input port
* @param {vtkImageProperty[]} properties
*/
setProperties(properties: vtkImageProperty[]): boolean;

/**
*
* @param {boolean} forceOpaque If true, render during opaque pass even if opacity value is below 1.0.
Expand All @@ -147,6 +124,13 @@ export interface vtkImageSlice extends vtkProp3D {
* @param {boolean} forceTranslucent If true, render during translucent pass even if opacity value is 1.0.
*/
setForceTranslucent(forceTranslucent: boolean): boolean;

// Inherited from vtkProp3D, but takes a vtkImageProperty instead of a generic vtkObject
getProperty(mapperInputPort?: number): vtkImageProperty;
getProperties(): vtkImageProperty[];
setProperty(mapperInputPort: number, property: vtkImageProperty): boolean;
setProperty(property: vtkImageProperty): boolean;
setProperties(properties: 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
29 changes: 5 additions & 24 deletions Sources/Rendering/Core/Volume/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ export interface vtkVolume extends vtkProp3D {
*/
getVolumes(): vtkVolume[];

/**
* Get the volume property for the specified mapper input port, which defaults to 0
* @param {number} mapperInputPort Defaults to 0
*/
getProperty(mapperInputPort?: number): vtkVolumeProperty;

/**
* Get the volume properties array
* Each element of the array corresponds to a mapper input port
*/
getProperties(): vtkVolumeProperty[];

/**
* Get the `Modified Time` which is a monotonic increasing integer
* global for all vtkObjects.
Expand Down Expand Up @@ -71,18 +59,11 @@ export interface vtkVolume extends vtkProp3D {
*/
setMapper(mapper: vtkVolumeMapper): boolean;

/**
* Set the volume property for the specified mapper input port, which defaults to 0
* @param {vtkVolumeProperty} property
* @param {number} mapperInputPort Defaults to 0
*/
setProperty(property: vtkVolumeProperty, mapperInputPort?: number): boolean;

/**
* Set the volume properties array
* Each element of the array corresponds to a mapper input port
* @param {vtkVolumeProperty[]} properties
*/
// Inherited from vtkProp3D, but takes a vtkVolumeProperty instead of a generic vtkObject
getProperty(mapperInputPort?: number): vtkVolumeProperty;
getProperties(): vtkVolumeProperty[];
setProperty(mapperInputPort: number, property: vtkVolumeProperty): boolean;
setProperty(property: vtkVolumeProperty): boolean;
setProperties(properties: vtkVolumeProperty[]): boolean;
}

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 6d54ca0

Please sign in to comment.