Skip to content

Commit 8fb9e8d

Browse files
committed
fix(renderer,viewnode,renderwindow,...): fix refactoring
coherence in choices
1 parent 114330e commit 8fb9e8d

File tree

20 files changed

+218
-238
lines changed

20 files changed

+218
-238
lines changed

Sources/Rendering/Core/Mapper2D/index.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ function defaultValues(initialValues) {
166166

167167
transformCoordinate: null,
168168

169-
viewSpecificProperties: null,
169+
viewSpecificProperties: {},
170170
customShaderAttributes: [],
171171
...initialValues,
172172
};
@@ -196,10 +196,6 @@ export function extend(publicAPI, model, initialValues = {}) {
196196
]);
197197
macro.setGetArray(publicAPI, model, ['scalarRange'], 2);
198198

199-
if (!initialValues.viewSpecificProperties) {
200-
initialValues.viewSpecificProperties = {};
201-
}
202-
203199
// Object methods
204200
vtkMapper2D(publicAPI, model);
205201
}

Sources/Rendering/Core/Prop3D/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ function vtkProp3D(publicAPI, model) {
9191
return false;
9292
}
9393
model.orientation = [x, y, z];
94-
if (!model.rotation) model.rotation = mat4.identity(new Float64Array(16));
94+
// Instanciation time
95+
if (model.rotation === undefined)
96+
model.rotation = mat4.identity(new Float64Array(16));
9597
mat4.identity(model.rotation);
9698
publicAPI.rotateZ(z);
9799
publicAPI.rotateX(x);
@@ -101,13 +103,10 @@ function vtkProp3D(publicAPI, model) {
101103
};
102104

103105
publicAPI.setUserMatrix = (matrix) => {
104-
if (!matrix) {
105-
model.userMatrix = null;
106-
} else {
107-
if (!model.userMatrix)
108-
model.userMatrix = mat4.identity(new Float64Array(16));
109-
mat4.copy(model.userMatrix, matrix);
110-
}
106+
if (model.userMatrix === undefined)
107+
model.userMatrix = mat4.identity(new Float64Array(16));
108+
mat4.copy(model.userMatrix, matrix);
109+
111110
publicAPI.modified();
112111
};
113112

@@ -118,7 +117,7 @@ function vtkProp3D(publicAPI, model) {
118117

119118
publicAPI.computeMatrix = () => {
120119
// check whether or not need to rebuild the matrix
121-
if (!model.matrixMTime) {
120+
if (model.matrixMTime === undefined) {
122121
return;
123122
}
124123
if (publicAPI.getMTime() > model.matrixMTime.getMTime()) {

Sources/Rendering/Core/Property/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function vtkProperty(publicAPI, model) {
1616
model.classHierarchy.push('vtkProperty');
1717

1818
publicAPI.setColor = (r, g, b) => {
19-
if (!model.color) {
19+
// Instanciation time
20+
if (model.color === undefined) {
2021
model.color = [0, 0, 0];
2122
}
2223
if (Array.isArray(r)) {

Sources/Rendering/Core/RenderWindow/index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ export function newAPISpecificView(name, initialValues = {}, toSet = true) {
2121
);
2222
}
2323

24-
// ----------------------------------------------------------------------------
25-
// Object factory
26-
// ----------------------------------------------------------------------------
27-
28-
function defaultValues(initialValues) {
29-
return {
30-
defaultViewAPI: DEFAULT_VIEW_API,
31-
renderers: [],
32-
views: [],
33-
interactor: null,
34-
neverRendered: true,
35-
numberOfLayers: 1,
36-
...initialValues,
37-
};
38-
}
39-
4024
// ----------------------------------------------------------------------------
4125
// vtkRenderWindow methods
4226
// ----------------------------------------------------------------------------
@@ -151,6 +135,22 @@ function vtkRenderWindow(publicAPI, model) {
151135
};
152136
}
153137

138+
// ----------------------------------------------------------------------------
139+
// Object factory
140+
// ----------------------------------------------------------------------------
141+
142+
function defaultValues(initialValues) {
143+
return {
144+
defaultViewAPI: DEFAULT_VIEW_API,
145+
renderers: [],
146+
views: [],
147+
interactor: null,
148+
neverRendered: true,
149+
numberOfLayers: 1,
150+
...initialValues,
151+
};
152+
}
153+
154154
// ----------------------------------------------------------------------------
155155

156156
export function extend(publicAPI, model, initialValues = {}) {

Sources/Rendering/Core/Renderer/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,8 @@ function vtkRenderer(publicAPI, model) {
565565

566566
function defaultValues(initialValues) {
567567
return {
568+
background: [0, 0, 0, 1],
569+
568570
pickedProp: null,
569571
activeCamera: null,
570572

@@ -633,7 +635,6 @@ export function extend(publicAPI, model, initialValues = {}) {
633635
vtkViewport.extend(publicAPI, model, initialValues);
634636

635637
// make sure background has 4 entries. Default to opaque black
636-
if (!initialValues.background) initialValues.background = [0, 0, 0, 1];
637638
while (initialValues.background.length < 3) initialValues.background.push(0);
638639
if (initialValues.background.length === 3) initialValues.background.push(1);
639640

Sources/Rendering/Core/Viewport/index.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,6 @@ function notImplemented(method) {
66
return () => vtkErrorMacro(`vtkViewport::${method} - NOT IMPLEMENTED`);
77
}
88

9-
// ----------------------------------------------------------------------------
10-
// Object factory
11-
// ----------------------------------------------------------------------------
12-
13-
function defaultValues(initialValues) {
14-
return {
15-
// _vtkWindow: null,
16-
background: [0, 0, 0],
17-
background2: [0.2, 0.2, 0.2],
18-
gradientBackground: false,
19-
viewport: [0, 0, 1, 1],
20-
aspect: [1, 1],
21-
pixelAspect: [1, 1],
22-
props: [],
23-
actors2D: [],
24-
...initialValues,
25-
};
26-
}
27-
289
// ----------------------------------------------------------------------------
2910
// vtkViewport methods
3011
// ----------------------------------------------------------------------------
@@ -153,6 +134,25 @@ function vtkViewport(publicAPI, model) {
153134
publicAPI.PickPropFrom = notImplemented('PickPropFrom');
154135
}
155136

137+
// ----------------------------------------------------------------------------
138+
// Object factory
139+
// ----------------------------------------------------------------------------
140+
141+
function defaultValues(initialValues) {
142+
return {
143+
// _vtkWindow: null,
144+
background: [0, 0, 0],
145+
background2: [0.2, 0.2, 0.2],
146+
gradientBackground: false,
147+
viewport: [0, 0, 1, 1],
148+
aspect: [1, 1],
149+
pixelAspect: [1, 1],
150+
props: [],
151+
actors2D: [],
152+
...initialValues,
153+
};
154+
}
155+
156156
// ----------------------------------------------------------------------------
157157

158158
export function extend(publicAPI, model, initialValues = {}) {

Sources/Rendering/OpenGL/HardwareSelector/index.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -329,26 +329,6 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) {
329329
);
330330
}
331331

332-
// ----------------------------------------------------------------------------
333-
// Object factory
334-
// ----------------------------------------------------------------------------
335-
336-
function defaultValues(initialValues) {
337-
return {
338-
area: undefined,
339-
// _renderer: null,
340-
// _openGLRenderWindow: null,
341-
// _openGLRenderer: null,
342-
currentPass: -1,
343-
propColorValue: null,
344-
props: null,
345-
maximumPointId: 0,
346-
maximumCellId: 0,
347-
idOffset: 1,
348-
...initialValues,
349-
};
350-
}
351-
352332
// ----------------------------------------------------------------------------
353333
// vtkOpenGLHardwareSelector methods
354334
// ----------------------------------------------------------------------------
@@ -897,7 +877,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
897877
const superSetArea = publicAPI.setArea;
898878
publicAPI.setArea = (...args) => {
899879
if (!args[0]) return false;
900-
if (!model.area) model.area = [0, 0, 0, 0];
880+
// Instanciation time
881+
if (model.area === undefined) model.area = [0, 0, 0, 0];
901882
if (superSetArea(...args)) {
902883
model.area[0] = Math.floor(model.area[0]);
903884
model.area[1] = Math.floor(model.area[1]);
@@ -909,6 +890,26 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
909890
};
910891
}
911892

893+
// ----------------------------------------------------------------------------
894+
// Object factory
895+
// ----------------------------------------------------------------------------
896+
897+
function defaultValues(initialValues) {
898+
return {
899+
area: [0, 0, 0, 0],
900+
// _renderer: null,
901+
// _openGLRenderWindow: null,
902+
// _openGLRenderer: null,
903+
currentPass: -1,
904+
propColorValue: [0, 0, 0],
905+
props: [],
906+
maximumPointId: 0,
907+
maximumCellId: 0,
908+
idOffset: 1,
909+
...initialValues,
910+
};
911+
}
912+
912913
// ----------------------------------------------------------------------------
913914

914915
export function extend(publicAPI, model, initialValues = {}) {
@@ -921,13 +922,6 @@ export function extend(publicAPI, model, initialValues = {}) {
921922
// Build VTK API
922923
vtkHardwareSelector.extend(publicAPI, model, initialValues);
923924

924-
initialValues.propColorValue = [0, 0, 0];
925-
initialValues.props = [];
926-
927-
if (!initialValues.area) {
928-
initialValues.area = [0, 0, 0, 0];
929-
}
930-
931925
macro.setGetArray(publicAPI, model, ['area'], 4);
932926
macro.setGet(publicAPI, model, [
933927
'_renderer',

Sources/Rendering/OpenGL/RenderWindow/index.js

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -82,35 +82,6 @@ export function popMonitorGLContextCount(cb) {
8282
return GL_CONTEXT_LISTENERS.pop();
8383
}
8484

85-
// ----------------------------------------------------------------------------
86-
// Object factory
87-
// ----------------------------------------------------------------------------
88-
89-
function defaultValues(initialValues) {
90-
return {
91-
cullFaceEnabled: false,
92-
initialized: false,
93-
context: null,
94-
cursorVisibility: true,
95-
cursor: 'pointer',
96-
textureUnitManager: null,
97-
containerSize: null,
98-
renderPasses: [],
99-
notifyStartCaptureImage: false,
100-
webgl2: false,
101-
defaultToWebgl2: true, // attempt webgl2 on by default
102-
activeFramebuffer: null,
103-
xrSession: null,
104-
xrSessionIsAR: false,
105-
xrReferenceSpace: null,
106-
xrSupported: true,
107-
imageFormat: 'image/png',
108-
useOffScreen: false,
109-
useBackgroundImage: false,
110-
...initialValues,
111-
};
112-
}
113-
11485
// ----------------------------------------------------------------------------
11586
// vtkOpenGLRenderWindow methods
11687
// ----------------------------------------------------------------------------
@@ -1249,6 +1220,41 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
12491220
);
12501221
}
12511222

1223+
// ----------------------------------------------------------------------------
1224+
// Object factory
1225+
// ----------------------------------------------------------------------------
1226+
1227+
function defaultValues(initialValues) {
1228+
return {
1229+
// Internal
1230+
selector: vtkOpenGLHardwareSelector.newInstance(),
1231+
bgImage: new Image(),
1232+
_textureResourceIds: new Map(),
1233+
shaderCache: vtkShaderCache.newInstance(),
1234+
1235+
cullFaceEnabled: false,
1236+
initialized: false,
1237+
context: null,
1238+
cursorVisibility: true,
1239+
cursor: 'pointer',
1240+
textureUnitManager: null,
1241+
containerSize: null,
1242+
renderPasses: [],
1243+
notifyStartCaptureImage: false,
1244+
webgl2: false,
1245+
defaultToWebgl2: true, // attempt webgl2 on by default
1246+
activeFramebuffer: null,
1247+
xrSession: null,
1248+
xrSessionIsAR: false,
1249+
xrReferenceSpace: null,
1250+
xrSupported: true,
1251+
imageFormat: 'image/png',
1252+
useOffScreen: false,
1253+
useBackgroundImage: false,
1254+
...initialValues,
1255+
};
1256+
}
1257+
12521258
// ----------------------------------------------------------------------------
12531259

12541260
export function extend(publicAPI, model, initialValues = {}) {
@@ -1257,35 +1263,24 @@ export function extend(publicAPI, model, initialValues = {}) {
12571263
// Inheritance
12581264
vtkRenderWindowViewNode.extend(publicAPI, model, initialValues);
12591265

1260-
// Create internal instances
1266+
// model.canvas needs to be set to model before calling other setters
12611267
model.canvas = document.createElement('canvas');
12621268
model.canvas.style.width = '100%';
12631269
createGLContext();
12641270

1265-
if (!initialValues.selector) {
1266-
initialValues.selector = vtkOpenGLHardwareSelector.newInstance();
1267-
initialValues.selector.setOpenGLRenderWindow(publicAPI);
1268-
}
1269-
12701271
// Create internal bgImage
1271-
model.bgImage = new Image();
1272-
model.bgImage.style.position = 'absolute';
1273-
model.bgImage.style.left = '0';
1274-
model.bgImage.style.top = '0';
1275-
model.bgImage.style.width = '100%';
1276-
model.bgImage.style.height = '100%';
1277-
model.bgImage.style.zIndex = '-1';
1278-
1279-
model._textureResourceIds = new Map();
1272+
initialValues.bgImage.style.position = 'absolute';
1273+
initialValues.bgImage.style.left = '0';
1274+
initialValues.bgImage.style.top = '0';
1275+
initialValues.bgImage.style.width = '100%';
1276+
initialValues.bgImage.style.height = '100%';
1277+
initialValues.bgImage.style.zIndex = '-1';
12801278

12811279
initialValues.myFactory = vtkOpenGLViewNodeFactory.newInstance();
12821280
/* eslint-disable no-use-before-define */
12831281
initialValues.myFactory.registerOverride('vtkRenderWindow', newInstance);
12841282
/* eslint-enable no-use-before-define */
12851283

1286-
initialValues.shaderCache = vtkShaderCache.newInstance();
1287-
initialValues.shaderCache.setOpenGLRenderWindow(publicAPI);
1288-
12891284
// setup default forward pass rendering
12901285
initialValues.renderPasses[0] = vtkForwardPass.newInstance();
12911286

@@ -1322,6 +1317,9 @@ export function extend(publicAPI, model, initialValues = {}) {
13221317

13231318
// Object methods
13241319
vtkOpenGLRenderWindow(publicAPI, model);
1320+
1321+
initialValues.selector.setOpenGLRenderWindow(publicAPI);
1322+
initialValues.shaderCache.setOpenGLRenderWindow(publicAPI);
13251323
}
13261324

13271325
// ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)