Skip to content

Commit 6d54ca0

Browse files
committed
refactor: Fix resource caching and signature of getProperty()
1 parent 40640d9 commit 6d54ca0

File tree

5 files changed

+25
-62
lines changed

5 files changed

+25
-62
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: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ export interface vtkImageSlice extends vtkProp3D {
3535
*/
3636
getIsOpaque(): boolean;
3737

38-
/**
39-
*
40-
*/
41-
getProperty(): vtkImageProperty;
42-
43-
/**
44-
*
45-
*/
46-
getProperties(): vtkImageProperty[];
47-
4838
/**
4939
*
5040
*/
@@ -123,19 +113,6 @@ export interface vtkImageSlice extends vtkProp3D {
123113
*/
124114
setMapper(mapper: vtkAbstractImageMapper): boolean;
125115

126-
/**
127-
*
128-
* @param {vtkImageProperty} property The vtkImageProperty instance.
129-
*/
130-
setProperty(property: vtkImageProperty): boolean;
131-
132-
/**
133-
* Set the actor properties array
134-
* Each element of the array corresponds to a mapper input port
135-
* @param {vtkImageProperty[]} properties
136-
*/
137-
setProperties(properties: vtkImageProperty[]): boolean;
138-
139116
/**
140117
*
141118
* @param {boolean} forceOpaque If true, render during opaque pass even if opacity value is below 1.0.
@@ -147,6 +124,13 @@ export interface vtkImageSlice extends vtkProp3D {
147124
* @param {boolean} forceTranslucent If true, render during translucent pass even if opacity value is 1.0.
148125
*/
149126
setForceTranslucent(forceTranslucent: boolean): boolean;
127+
128+
// Inherited from vtkProp3D, but takes a vtkImageProperty instead of a generic vtkObject
129+
getProperty(mapperInputPort?: number): vtkImageProperty;
130+
getProperties(): vtkImageProperty[];
131+
setProperty(mapperInputPort: number, property: vtkImageProperty): boolean;
132+
setProperty(property: vtkImageProperty): boolean;
133+
setProperties(properties: vtkImageProperty[]): boolean;
150134
}
151135

152136
/**

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: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,6 @@ export interface vtkVolume extends vtkProp3D {
2929
*/
3030
getVolumes(): vtkVolume[];
3131

32-
/**
33-
* Get the volume property for the specified mapper input port, which defaults to 0
34-
* @param {number} mapperInputPort Defaults to 0
35-
*/
36-
getProperty(mapperInputPort?: number): vtkVolumeProperty;
37-
38-
/**
39-
* Get the volume properties array
40-
* Each element of the array corresponds to a mapper input port
41-
*/
42-
getProperties(): vtkVolumeProperty[];
43-
4432
/**
4533
* Get the `Modified Time` which is a monotonic increasing integer
4634
* global for all vtkObjects.
@@ -71,18 +59,11 @@ export interface vtkVolume extends vtkProp3D {
7159
*/
7260
setMapper(mapper: vtkVolumeMapper): boolean;
7361

74-
/**
75-
* Set the volume property for the specified mapper input port, which defaults to 0
76-
* @param {vtkVolumeProperty} property
77-
* @param {number} mapperInputPort Defaults to 0
78-
*/
79-
setProperty(property: vtkVolumeProperty, mapperInputPort?: number): boolean;
80-
81-
/**
82-
* Set the volume properties array
83-
* Each element of the array corresponds to a mapper input port
84-
* @param {vtkVolumeProperty[]} properties
85-
*/
62+
// Inherited from vtkProp3D, but takes a vtkVolumeProperty instead of a generic vtkObject
63+
getProperty(mapperInputPort?: number): vtkVolumeProperty;
64+
getProperties(): vtkVolumeProperty[];
65+
setProperty(mapperInputPort: number, property: vtkVolumeProperty): boolean;
66+
setProperty(property: vtkVolumeProperty): boolean;
8667
setProperties(properties: vtkVolumeProperty[]): boolean;
8768
}
8869

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)