Skip to content

Commit

Permalink
fix(renderer,viewnode,renderwindow,...): fix refactoring
Browse files Browse the repository at this point in the history
coherence in choices
  • Loading branch information
joannacirillo committed Jun 15, 2022
1 parent f8156f3 commit 6e65814
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 238 deletions.
6 changes: 1 addition & 5 deletions Sources/Rendering/Core/Mapper2D/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function defaultValues(initialValues) {

transformCoordinate: null,

viewSpecificProperties: null,
viewSpecificProperties: {},
customShaderAttributes: [],
...initialValues,
};
Expand Down Expand Up @@ -196,10 +196,6 @@ export function extend(publicAPI, model, initialValues = {}) {
]);
macro.setGetArray(publicAPI, model, ['scalarRange'], 2);

if (!initialValues.viewSpecificProperties) {
initialValues.viewSpecificProperties = {};
}

// Object methods
vtkMapper2D(publicAPI, model);
}
Expand Down
17 changes: 8 additions & 9 deletions Sources/Rendering/Core/Prop3D/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ function vtkProp3D(publicAPI, model) {
return false;
}
model.orientation = [x, y, z];
if (!model.rotation) model.rotation = mat4.identity(new Float64Array(16));
// Instanciation time
if (model.rotation === undefined)
model.rotation = mat4.identity(new Float64Array(16));
mat4.identity(model.rotation);
publicAPI.rotateZ(z);
publicAPI.rotateX(x);
Expand All @@ -101,13 +103,10 @@ function vtkProp3D(publicAPI, model) {
};

publicAPI.setUserMatrix = (matrix) => {
if (!matrix) {
model.userMatrix = null;
} else {
if (!model.userMatrix)
model.userMatrix = mat4.identity(new Float64Array(16));
mat4.copy(model.userMatrix, matrix);
}
if (model.userMatrix === undefined)
model.userMatrix = mat4.identity(new Float64Array(16));
mat4.copy(model.userMatrix, matrix);

publicAPI.modified();
};

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

publicAPI.computeMatrix = () => {
// check whether or not need to rebuild the matrix
if (!model.matrixMTime) {
if (model.matrixMTime === undefined) {
return;
}
if (publicAPI.getMTime() > model.matrixMTime.getMTime()) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/Core/Property/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function vtkProperty(publicAPI, model) {
model.classHierarchy.push('vtkProperty');

publicAPI.setColor = (r, g, b) => {
if (!model.color) {
// Instanciation time
if (model.color === undefined) {
model.color = [0, 0, 0];
}
if (Array.isArray(r)) {
Expand Down
32 changes: 16 additions & 16 deletions Sources/Rendering/Core/RenderWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ export function newAPISpecificView(name, initialValues = {}, toSet = true) {
);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
defaultViewAPI: DEFAULT_VIEW_API,
renderers: [],
views: [],
interactor: null,
neverRendered: true,
numberOfLayers: 1,
...initialValues,
};
}

// ----------------------------------------------------------------------------
// vtkRenderWindow methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -151,6 +135,22 @@ function vtkRenderWindow(publicAPI, model) {
};
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
defaultViewAPI: DEFAULT_VIEW_API,
renderers: [],
views: [],
interactor: null,
neverRendered: true,
numberOfLayers: 1,
...initialValues,
};
}

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/Rendering/Core/Renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,8 @@ function vtkRenderer(publicAPI, model) {

function defaultValues(initialValues) {
return {
background: [0, 0, 0, 1],

pickedProp: null,
activeCamera: null,

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

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

Expand Down
38 changes: 19 additions & 19 deletions Sources/Rendering/Core/Viewport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,6 @@ function notImplemented(method) {
return () => vtkErrorMacro(`vtkViewport::${method} - NOT IMPLEMENTED`);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
// _vtkWindow: null,
background: [0, 0, 0],
background2: [0.2, 0.2, 0.2],
gradientBackground: false,
viewport: [0, 0, 1, 1],
aspect: [1, 1],
pixelAspect: [1, 1],
props: [],
actors2D: [],
...initialValues,
};
}

// ----------------------------------------------------------------------------
// vtkViewport methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -153,6 +134,25 @@ function vtkViewport(publicAPI, model) {
publicAPI.PickPropFrom = notImplemented('PickPropFrom');
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
// _vtkWindow: null,
background: [0, 0, 0],
background2: [0.2, 0.2, 0.2],
gradientBackground: false,
viewport: [0, 0, 1, 1],
aspect: [1, 1],
pixelAspect: [1, 1],
props: [],
actors2D: [],
...initialValues,
};
}

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Expand Down
50 changes: 22 additions & 28 deletions Sources/Rendering/OpenGL/HardwareSelector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,26 +329,6 @@ function generateSelectionWithData(buffdata, fx1, fy1, fx2, fy2) {
);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
area: undefined,
// _renderer: null,
// _openGLRenderWindow: null,
// _openGLRenderer: null,
currentPass: -1,
propColorValue: null,
props: null,
maximumPointId: 0,
maximumCellId: 0,
idOffset: 1,
...initialValues,
};
}

// ----------------------------------------------------------------------------
// vtkOpenGLHardwareSelector methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -897,7 +877,8 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
const superSetArea = publicAPI.setArea;
publicAPI.setArea = (...args) => {
if (!args[0]) return false;
if (!model.area) model.area = [0, 0, 0, 0];
// Instanciation time
if (model.area === undefined) model.area = [0, 0, 0, 0];
if (superSetArea(...args)) {
model.area[0] = Math.floor(model.area[0]);
model.area[1] = Math.floor(model.area[1]);
Expand All @@ -909,6 +890,26 @@ function vtkOpenGLHardwareSelector(publicAPI, model) {
};
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
area: [0, 0, 0, 0],
// _renderer: null,
// _openGLRenderWindow: null,
// _openGLRenderer: null,
currentPass: -1,
propColorValue: [0, 0, 0],
props: [],
maximumPointId: 0,
maximumCellId: 0,
idOffset: 1,
...initialValues,
};
}

// ----------------------------------------------------------------------------

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

initialValues.propColorValue = [0, 0, 0];
initialValues.props = [];

if (!initialValues.area) {
initialValues.area = [0, 0, 0, 0];
}

macro.setGetArray(publicAPI, model, ['area'], 4);
macro.setGet(publicAPI, model, [
'_renderer',
Expand Down
92 changes: 45 additions & 47 deletions Sources/Rendering/OpenGL/RenderWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,6 @@ export function popMonitorGLContextCount(cb) {
return GL_CONTEXT_LISTENERS.pop();
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
cullFaceEnabled: false,
initialized: false,
context: null,
cursorVisibility: true,
cursor: 'pointer',
textureUnitManager: null,
containerSize: null,
renderPasses: [],
notifyStartCaptureImage: false,
webgl2: false,
defaultToWebgl2: true, // attempt webgl2 on by default
activeFramebuffer: null,
xrSession: null,
xrSessionIsAR: false,
xrReferenceSpace: null,
xrSupported: true,
imageFormat: 'image/png',
useOffScreen: false,
useBackgroundImage: false,
...initialValues,
};
}

// ----------------------------------------------------------------------------
// vtkOpenGLRenderWindow methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -1238,6 +1209,41 @@ function vtkOpenGLRenderWindow(publicAPI, model) {
);
}

// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------

function defaultValues(initialValues) {
return {
// Internal
selector: vtkOpenGLHardwareSelector.newInstance(),
bgImage: new Image(),
_textureResourceIds: new Map(),
shaderCache: vtkShaderCache.newInstance(),

cullFaceEnabled: false,
initialized: false,
context: null,
cursorVisibility: true,
cursor: 'pointer',
textureUnitManager: null,
containerSize: null,
renderPasses: [],
notifyStartCaptureImage: false,
webgl2: false,
defaultToWebgl2: true, // attempt webgl2 on by default
activeFramebuffer: null,
xrSession: null,
xrSessionIsAR: false,
xrReferenceSpace: null,
xrSupported: true,
imageFormat: 'image/png',
useOffScreen: false,
useBackgroundImage: false,
...initialValues,
};
}

// ----------------------------------------------------------------------------

export function extend(publicAPI, model, initialValues = {}) {
Expand All @@ -1246,35 +1252,24 @@ export function extend(publicAPI, model, initialValues = {}) {
// Inheritance
vtkRenderWindowViewNode.extend(publicAPI, model, initialValues);

// Create internal instances
// model.canvas needs to be set to model before calling other setters
model.canvas = document.createElement('canvas');
model.canvas.style.width = '100%';
createGLContext();

if (!initialValues.selector) {
initialValues.selector = vtkOpenGLHardwareSelector.newInstance();
initialValues.selector.setOpenGLRenderWindow(publicAPI);
}

// Create internal bgImage
model.bgImage = new Image();
model.bgImage.style.position = 'absolute';
model.bgImage.style.left = '0';
model.bgImage.style.top = '0';
model.bgImage.style.width = '100%';
model.bgImage.style.height = '100%';
model.bgImage.style.zIndex = '-1';

model._textureResourceIds = new Map();
initialValues.bgImage.style.position = 'absolute';
initialValues.bgImage.style.left = '0';
initialValues.bgImage.style.top = '0';
initialValues.bgImage.style.width = '100%';
initialValues.bgImage.style.height = '100%';
initialValues.bgImage.style.zIndex = '-1';

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

initialValues.shaderCache = vtkShaderCache.newInstance();
initialValues.shaderCache.setOpenGLRenderWindow(publicAPI);

// setup default forward pass rendering
initialValues.renderPasses[0] = vtkForwardPass.newInstance();

Expand Down Expand Up @@ -1311,6 +1306,9 @@ export function extend(publicAPI, model, initialValues = {}) {

// Object methods
vtkOpenGLRenderWindow(publicAPI, model);

initialValues.selector.setOpenGLRenderWindow(publicAPI);
initialValues.shaderCache.setOpenGLRenderWindow(publicAPI);
}

// ----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 6e65814

Please sign in to comment.