Skip to content

Commit 40640d9

Browse files
committed
refactor: Enable multi properties on all vtkProp3D
1 parent 533797c commit 40640d9

File tree

7 files changed

+89
-87
lines changed

7 files changed

+89
-87
lines changed

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,6 @@ export interface vtkActor extends vtkProp3D {
5757
*/
5858
getMapper(): Nullable<vtkMapper>;
5959

60-
/**
61-
* Get the property object that controls this actors surface
62-
* properties. This should be an instance of a vtkProperty object. Every
63-
* actor must have a property associated with it. If one isn’t specified,
64-
* then one will be generated automatically. Multiple actors can share one
65-
* property object.
66-
* @return {vtkProperty} The property object
67-
*/
68-
getProperty(): vtkProperty;
69-
7060
/**
7161
* Check whether if the actor supports selection
7262
* @return {Boolean} true if the actor support selection.
@@ -105,11 +95,12 @@ export interface vtkActor extends vtkProp3D {
10595
*/
10696
setMapper(mapper: vtkMapper): boolean;
10797

108-
/**
109-
* Set the property object that controls this actors surface properties.
110-
* @param {vtkProperty} property The vtkProperty instance.
111-
*/
98+
// Inherited from vtkProp3D, but takes a vtkProperty instead of a generic vtkObject
99+
getProperty(mapperInputPort?: number): vtkProperty;
100+
getProperties(): vtkProperty[];
101+
setProperty(mapperInputPort: number, property: vtkProperty): boolean;
112102
setProperty(property: vtkProperty): boolean;
103+
setProperties(properties: vtkProperty[]): boolean;
113104
}
114105

115106
/**

Sources/Rendering/Core/Actor/index.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ function vtkActor(publicAPI, model) {
2323
return false;
2424
}
2525
// make sure we have a property
26-
if (!model.property) {
26+
if (!model.properties[0]) {
2727
// force creation of a property
2828
publicAPI.getProperty();
2929
}
3030

31-
let isOpaque = model.property.getOpacity() >= 1.0;
31+
let isOpaque = model.properties[0].getOpacity() >= 1.0;
3232

3333
// are we using an opaque texture, if any?
3434
isOpaque = isOpaque && (!model.texture || !model.texture.isTranslucent());
@@ -44,9 +44,9 @@ function vtkActor(publicAPI, model) {
4444
return false;
4545
}
4646
// make sure we have a property
47-
if (model.property === null) {
47+
if (!model.properties[0]) {
4848
// force creation of a property
49-
publicAPI.setProperty(publicAPI.makeProperty());
49+
publicAPI.getProperty();
5050
}
5151

5252
// is this actor opaque ?
@@ -55,19 +55,8 @@ function vtkActor(publicAPI, model) {
5555

5656
publicAPI.makeProperty = vtkProperty.newInstance;
5757

58-
publicAPI.getProperty = () => {
59-
if (model.property === null) {
60-
model.property = publicAPI.makeProperty();
61-
}
62-
return model.property;
63-
};
64-
6558
publicAPI.getMTime = () => {
6659
let mt = superClass.getMTime();
67-
if (model.property !== null) {
68-
const time = model.property.getMTime();
69-
mt = time > mt ? time : mt;
70-
}
7160

7261
if (model.backfaceProperty !== null) {
7362
const time = model.backfaceProperty.getMTime();
@@ -108,7 +97,6 @@ function vtkActor(publicAPI, model) {
10897

10998
const DEFAULT_VALUES = {
11099
mapper: null,
111-
property: null,
112100
backfaceProperty: null,
113101

114102
forceOpaque: false,
@@ -128,7 +116,6 @@ export function extend(publicAPI, model, initialValues = {}) {
128116
macro.obj(model.boundsMTime);
129117

130118
// Build VTK API
131-
macro.set(publicAPI, model, ['property']);
132119
macro.setGet(publicAPI, model, [
133120
'backfaceProperty',
134121
'forceOpaque',

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ export interface vtkImageSlice extends vtkProp3D {
4040
*/
4141
getProperty(): vtkImageProperty;
4242

43+
/**
44+
*
45+
*/
46+
getProperties(): vtkImageProperty[];
47+
4348
/**
4449
*
4550
*/
@@ -124,6 +129,13 @@ export interface vtkImageSlice extends vtkProp3D {
124129
*/
125130
setProperty(property: vtkImageProperty): boolean;
126131

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+
127139
/**
128140
*
129141
* @param {boolean} forceOpaque If true, render during opaque pass even if opacity value is below 1.0.

Sources/Rendering/Core/ImageSlice/index.js

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ function vtkImageSlice(publicAPI, model) {
2323
return false;
2424
}
2525
// make sure we have a property
26-
if (!model.property) {
26+
if (!model.properties[0]) {
2727
// force creation of a property
2828
publicAPI.getProperty();
2929
}
3030

31-
let isOpaque = model.property.getOpacity() >= 1.0;
31+
let isOpaque = model.properties[0].getOpacity() >= 1.0;
3232

3333
// are we using an opaque scalar array, if any?
3434
isOpaque = isOpaque && (!model.mapper || model.mapper.getIsOpaque());
@@ -45,13 +45,6 @@ function vtkImageSlice(publicAPI, model) {
4545

4646
publicAPI.makeProperty = vtkImageProperty.newInstance;
4747

48-
publicAPI.getProperty = () => {
49-
if (model.property === null) {
50-
model.property = publicAPI.makeProperty();
51-
}
52-
return model.property;
53-
};
54-
5548
publicAPI.getBoundsForSlice = (slice, thickness) => {
5649
// Check for the special case when the mapper's bounds are unknown
5750
const bds = model.mapper.getBoundsForSlice(slice, thickness);
@@ -86,16 +79,6 @@ function vtkImageSlice(publicAPI, model) {
8679
// Get the maximum Z bound
8780
publicAPI.getMaxZBound = () => publicAPI.getBounds()[5];
8881

89-
publicAPI.getMTime = () => {
90-
let mt = model.mtime;
91-
if (model.property !== null) {
92-
const time = model.property.getMTime();
93-
mt = time > mt ? time : mt;
94-
}
95-
96-
return mt;
97-
};
98-
9982
publicAPI.getRedrawMTime = () => {
10083
let mt = model.mtime;
10184
if (model.mapper !== null) {
@@ -108,14 +91,13 @@ function vtkImageSlice(publicAPI, model) {
10891
mt = time > mt ? time : mt;
10992
}
11093
}
111-
if (model.property !== null) {
112-
let time = model.property.getMTime();
113-
mt = time > mt ? time : mt;
114-
if (model.property.getRGBTransferFunction() !== null) {
115-
time = model.property.getRGBTransferFunction().getMTime();
116-
mt = time > mt ? time : mt;
94+
model.properties.forEach((property) => {
95+
mt = Math.max(mt, property.getMTime());
96+
const rgbFunc = property.getRGBTransferFunction();
97+
if (rgbFunc !== null) {
98+
mt = Math.max(mt, rgbFunc.getMTime());
11799
}
118-
}
100+
});
119101
return mt;
120102
};
121103

@@ -129,7 +111,6 @@ function vtkImageSlice(publicAPI, model) {
129111

130112
const DEFAULT_VALUES = {
131113
mapper: null,
132-
property: null,
133114
forceOpaque: false,
134115
forceTranslucent: false,
135116
};
@@ -147,7 +128,6 @@ export function extend(publicAPI, model, initialValues = {}) {
147128
macro.obj(model.boundsMTime);
148129

149130
// Build VTK API
150-
macro.set(publicAPI, model, ['property']);
151131
macro.setGet(publicAPI, model, ['mapper', 'forceOpaque', 'forceTranslucent']);
152132

153133
// Object methods

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mat4, quat } from 'gl-matrix';
22
import { Bounds, Vector3, Range } from '../../../types';
33
import vtkProp, { IPropInitialValues } from '../Prop';
4+
import { vtkObject } from '../../../interfaces';
45

56
export interface IProp3DInitialValues extends IPropInitialValues {
67
origin?: number[];
@@ -137,6 +138,21 @@ export interface vtkProp3D extends vtkProp {
137138
*/
138139
getUserMatrix(): mat4;
139140

141+
/**
142+
* Get the actor property for the specified mapper input port, which defaults to 0
143+
* It controls this actors rendering properties. If one isn’t specified,
144+
* then one will be generated automatically. Multiple actors can share one
145+
* property object.
146+
* @param {number} mapperInputPort Defaults to 0
147+
*/
148+
getProperty(mapperInputPort?: number): vtkObject;
149+
150+
/**
151+
* Get the actor properties array
152+
* Each element of the array corresponds to a mapper input port
153+
*/
154+
getProperties(): vtkObject[];
155+
140156
/**
141157
* Rotate the Prop3D in degrees about the X axis using the right hand
142158
* rule. The axis is the Prop3D’s X axis, which can change as other
@@ -262,6 +278,21 @@ export interface vtkProp3D extends vtkProp {
262278
* Generate the matrix based on internal model.
263279
*/
264280
computeMatrix(): void;
281+
282+
/**
283+
* Set the actor property for the specified mapper input port, which defaults to 0
284+
* @param {vtkObject} property
285+
* @param {number} mapperInputPort Is 0 when not given
286+
*/
287+
setProperty(mapperInputPort: number, property: vtkObject): boolean;
288+
setProperty(property: vtkObject): boolean;
289+
290+
/**
291+
* Set the actor properties array
292+
* Each element of the array corresponds to a mapper input port
293+
* @param {vtkObject[]} properties
294+
*/
295+
setProperties(properties: vtkObject[]): boolean;
265296
}
266297

267298
/**

Sources/Rendering/Core/Prop3D/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,32 @@ function vtkProp3D(publicAPI, model) {
230230
}
231231

232232
publicAPI.onModified(updateIdentityFlag);
233+
234+
publicAPI.getProperty = (mapperInputPort = 0) => {
235+
if (model.properties[mapperInputPort] == null) {
236+
model.properties[mapperInputPort] = publicAPI.makeProperty?.();
237+
}
238+
return model.properties[mapperInputPort];
239+
};
240+
241+
publicAPI.setProperty = (property, mapperInputPort = 0) => {
242+
if (model.properties[mapperInputPort] === property) {
243+
return false;
244+
}
245+
model.properties[mapperInputPort] = property;
246+
return true;
247+
};
248+
249+
publicAPI.getMTime = () => {
250+
let mt = model.mtime;
251+
model.properties.forEach((property) => {
252+
if (property !== null) {
253+
const time = property.getMTime();
254+
mt = time > mt ? time : mt;
255+
}
256+
});
257+
return mt;
258+
};
233259
}
234260

235261
// ----------------------------------------------------------------------------
@@ -243,6 +269,7 @@ const DEFAULT_VALUES = {
243269
rotation: null,
244270
scale: [1, 1, 1],
245271
bounds: [...vtkBoundingBox.INIT_BOUNDS],
272+
properties: [],
246273

247274
userMatrix: null,
248275
userMatrixMTime: null,
@@ -267,6 +294,7 @@ export function extend(publicAPI, model, initialValues = {}) {
267294
macro.get(publicAPI, model, ['isIdentity']);
268295
macro.getArray(publicAPI, model, ['orientation']);
269296
macro.setGetArray(publicAPI, model, ['origin', 'position', 'scale'], 3);
297+
macro.setGet(publicAPI, model, ['properties']);
270298

271299
// Object internal instance
272300
model.matrix = mat4.identity(new Float64Array(16));

Sources/Rendering/Core/Volume/index.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,6 @@ function vtkVolume(publicAPI, model) {
1414

1515
publicAPI.makeProperty = vtkVolumeProperty.newInstance;
1616

17-
publicAPI.getProperty = (mapperInputPort = 0) => {
18-
if (model.properties[mapperInputPort] == null) {
19-
model.properties[mapperInputPort] = publicAPI.makeProperty();
20-
}
21-
return model.properties[mapperInputPort];
22-
};
23-
24-
publicAPI.setProperty = (property, mapperInputPort = 0) => {
25-
if (model.properties[mapperInputPort] === property) {
26-
return false;
27-
}
28-
model.properties[mapperInputPort] = property;
29-
return true;
30-
};
31-
32-
publicAPI.getMTime = () => {
33-
let mt = model.mtime;
34-
model.properties.forEach((property) => {
35-
if (property !== null) {
36-
const time = property.getMTime();
37-
mt = time > mt ? time : mt;
38-
}
39-
});
40-
return mt;
41-
};
42-
4317
publicAPI.getRedrawMTime = () => {
4418
let mt = model.mtime;
4519
if (model.mapper !== null) {
@@ -62,7 +36,6 @@ function vtkVolume(publicAPI, model) {
6236

6337
const DEFAULT_VALUES = {
6438
mapper: null,
65-
properties: [],
6639
};
6740

6841
// ----------------------------------------------------------------------------
@@ -78,7 +51,7 @@ export function extend(publicAPI, model, initialValues = {}) {
7851
macro.obj(model.boundsMTime);
7952

8053
// Build VTK API
81-
macro.setGet(publicAPI, model, ['mapper', 'properties']);
54+
macro.setGet(publicAPI, model, ['mapper']);
8255

8356
// Object methods
8457
vtkVolume(publicAPI, model);

0 commit comments

Comments
 (0)